BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
interpolated_function.hpp
1 // Copyright (C) 2011-2012 by the BEM++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 
22 #ifndef bempp_interpolated_function_hpp
23 #define bempp_interpolated_function_hpp
24 
25 #include "../common/common.hpp"
26 
27 #include "function.hpp"
28 
29 #include "../grid/vtk_writer.hpp"
30 #include "../fiber/scalar_traits.hpp"
31 
32 #include "../common/armadillo_fwd.hpp"
33 
34 namespace Bempp
35 {
36 
38 class Grid;
39 
40 template <typename ValueType> class InterpolatedFunction;
50 template <typename ValueType>
51 class InterpolatedFunction : public Function<ValueType>
52 {
53 public:
54  typedef typename Fiber::ScalarTraits<ValueType>::RealType CoordinateType;
55 
56  enum InterpolationMethod {
57  LINEAR
58  };
59 
62  const arma::Mat<ValueType>& vertexValues,
63  InterpolationMethod method = LINEAR);
64 
66  const Grid& grid() const;
67 
68  virtual int worldDimension() const;
69  virtual int codomainDimension() const;
70  virtual void addGeometricalDependencies(size_t& geomDeps) const;
71 
72  virtual void evaluate(const Fiber::GeometricalData<CoordinateType>& geomData,
73  arma::Mat<ValueType>& result) const;
74 
75 // virtual void evaluate(const arma::Mat<ValueType>& global,
76 // arma::Mat<ValueType>& values) const;
77 
94  void exportToVtk(const char* dataLabel,
95  const char* fileNamesBase, const char* filesPath = 0,
97 
98 // /** \brief Copy vertex values from a function defined on a subset of the
99 // surface of the interpolation grid. */
100 // void setSurfaceValues(const GridFunction<ValueType>& surfaceFunction);
101 
102 // /** \brief Copy vertex values from a function interpolated on a surface grid. */
103 // void setSurfaceValues(const InterpolatedFunction<ValueType>& surfaceFunction);
104 
109  InterpolatedFunction<ValueType>& operator*=(ValueType rhs);
110  InterpolatedFunction<ValueType>& operator/=(ValueType rhs);
111 
112  const InterpolatedFunction<ValueType> operator+(
113  const InterpolatedFunction<ValueType> &other) const;
114  const InterpolatedFunction<ValueType> operator-(
115  const InterpolatedFunction<ValueType> &other) const;
116 
117  const InterpolatedFunction<ValueType> operator/(
118  ValueType other) const;
119 
120 private:
121  void checkCompatibility(const InterpolatedFunction<ValueType>& other) const;
122 
123 private:
124  const Grid& m_grid;
125  arma::Mat<ValueType> m_vertexValues;
126  InterpolationMethod m_method;
127 };
128 
132 template <typename ValueType>
134  ValueType lhs, const InterpolatedFunction<ValueType>& rhs)
135 {
136  return InterpolatedFunction<ValueType>(rhs) *= lhs;
137 }
138 
142 template <typename ValueType>
144  const InterpolatedFunction<ValueType>& lhs, ValueType rhs)
145 {
146  return operator*(rhs, lhs);
147 }
148 
149 } // namespace Bempp
150 
151 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
const InterpolatedFunction< ValueType > operator*(const InterpolatedFunction< ValueType > &lhs, ValueType rhs)
Return an InterpolatedFunction representing the function lhs multiplied by the scalar rhs...
Definition: interpolated_function.hpp:143
OutputType
How data should be stored in a VTK file.
Definition: vtk_writer.hpp:46
InterpolatedFunction(const Grid &grid, const arma::Mat< ValueType > &vertexValues, InterpolationMethod method=LINEAR)
Construct function given its values at vertices of a grid.
Definition: interpolated_function.cpp:37
Storage of geometrical data.
Definition: geometrical_data.hpp:54
Function defined by its values at a set of interpolation points and an interpolation method...
Definition: interpolated_function.hpp:51
Abstract wrapper of a grid.
Definition: grid.hpp:50
Function to be used as a source term.
Definition: function.hpp:39
const InterpolatedFunction< ValueType > operator*(ValueType lhs, const InterpolatedFunction< ValueType > &rhs)
Return an InterpolatedFunction representing the function rhs multiplied by the scalar lhs...
Definition: interpolated_function.hpp:133
InterpolatedFunction< ValueType > & operator+=(const InterpolatedFunction< ValueType > &rhs)
Copy vertex values from a function defined on a subset of the surface of the interpolation grid...
Definition: interpolated_function.cpp:136
Output to the file is in ascii.
Definition: vtk_writer.hpp:48
const Grid & grid() const
Interpolation grid.
Definition: interpolated_function.cpp:54
void exportToVtk(const char *dataLabel, const char *fileNamesBase, const char *filesPath=0, VtkWriter::OutputType type=VtkWriter::ASCII) const
Definition: interpolated_function.cpp:95