~sophie-middleton08/maus/devel

« back to all changes in this revision

Viewing changes to src/legacy/Interface/Interpolation/VectorMap.hh

  • Committer: Chris Rogers
  • Date: 2012-10-03 07:19:33 UTC
  • mfrom: (659.1.40 release-candidate)
  • Revision ID: chris.rogers@stfc.ac.uk-20121003071933-kgrhvl1ec6w2jmug
Tags: MAUS-v0.3, MAUS-v0.3.3
MAUS-v0.3.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
 
2
 *
 
3
 * MAUS is free software: you can redistribute it and/or modify
 
4
 * it under the terms of the GNU General Public License as published by
 
5
 * the Free Software Foundation, either version 3 of the License, or
 
6
 * (at your option) any later version.
 
7
 *
 
8
 * MAUS is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with MAUS.  If not, see <http://  www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
#ifndef _SRC_LEGACY_INTERFACE_VECTORMAP_HH_
 
18
#define _SRC_LEGACY_INTERFACE_VECTORMAP_HH_
 
19
 
 
20
#include <vector>
 
21
 
 
22
#include "src/legacy/Interface/Mesh.hh"
 
23
 
 
24
/** VectorMap is an abstract class that defines mapping from one vector to
 
25
 *  another.
 
26
 *
 
27
 *  VectorMap is base class primarily envisaged for mesh interpolation that
 
28
 *  defines interfaces to get interpolated data at a given point, access the
 
29
 *  mesh, etc.
 
30
 *
 
31
 *  Input and output dimensions (vector lengths) are arbitrary.
 
32
 */
 
33
class VectorMap {
 
34
 public:
 
35
    /** Pure virtual function to fill the array value with data evaluated at
 
36
     *  point.
 
37
     */
 
38
    virtual void  F(const double*   point,       double* value) const = 0;
 
39
 
 
40
    /** Fill the array value with function data at a point on the mesh.
 
41
     *
 
42
     *  Implemented for default case where Mesh point dimension is the same as
 
43
     *  this point dimension (usual case). No default checking for array sizes.
 
44
     */
 
45
    inline virtual void  F(const Mesh::Iterator& point, double* value) const;
 
46
 
 
47
    /** Calculate F, appending output values to value_vec.
 
48
     *
 
49
     *  For each item in point_vec not in value_vec, calculate value_vec (urgh)
 
50
     */
 
51
    inline virtual void FAppend(
 
52
                           const std::vector< std::vector<double> >& point_vec,
 
53
                           std::vector< std::vector<double> >& value_vec
 
54
                      ) const;
 
55
 
 
56
    /** Return true if point.size() is the same as this->PointDimension() */
 
57
    inline virtual bool  CheckPoint(const std::vector<double>& point) const;
 
58
 
 
59
    /** Return true if value.size() is the same as this->ValueDimension() */
 
60
    inline virtual bool  CheckValue(const std::vector<double>& value) const;
 
61
 
 
62
    /** Return the dimension of the point (input) */
 
63
    virtual unsigned int PointDimension() const = 0;
 
64
    // would like to make static - but can't inherit static functions
 
65
 
 
66
    /** Return the dimension of the value (output) */
 
67
    virtual unsigned int ValueDimension() const = 0;
 
68
    // would like to make static - but can't inherit static functions
 
69
 
 
70
    /** Clone() is like a copy constructor - but copies the child class */
 
71
    virtual              VectorMap* Clone() const = 0;
 
72
 
 
73
    /** Destructor */
 
74
    virtual             ~VectorMap() {;}
 
75
 
 
76
    /** Return the mesh used by the vector map or NULL if no mesh */
 
77
    virtual Mesh*        GetMesh() const {return NULL;}
 
78
  private:
 
79
};
 
80
 
 
81
bool VectorMap::CheckPoint(const std::vector<double>& point) const {
 
82
  return (point.size() == this->PointDimension());
 
83
}
 
84
 
 
85
bool VectorMap::CheckValue(const std::vector<double>& value) const {
 
86
  return (value.size() == this->ValueDimension());
 
87
}
 
88
 
 
89
void VectorMap::F(const Mesh::Iterator& point, double* value) const {
 
90
  double* PointA = new double[this->PointDimension()];
 
91
  point.Position(PointA);
 
92
  F(PointA, value);
 
93
  delete PointA;
 
94
}
 
95
 
 
96
void VectorMap::FAppend(const std::vector< std::vector<double> >& point_vec,
 
97
                        std::vector< std::vector<double> >& value_vec) const {
 
98
  for (size_t i = value_vec.size(); i < point_vec.size(); i++) {
 
99
    value_vec.push_back(std::vector<double>(ValueDimension()));
 
100
    F(&point_vec[i][0], &value_vec[i][0]);
 
101
  }
 
102
}
 
103
 
 
104
#endif  // _SRC_LEGACY_INTERFACE_VECTORMAP_HH_
 
105