LifeV
BCDataInterpolator.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3  *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23  *******************************************************************************
24  */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief File containing a class for interpolating boundary functions from scattered data
30  *
31  * @date 09-06-2011
32  * @author Toni Lassila <toni.lassila@epfl.ch>
33  *
34  * @maintainer Toni Lassila <toni.lassila@epfl.ch>
35  */
36 
37 #ifndef BCDATAINTERPOLATOR_H
38 #define BCDATAINTERPOLATOR 1
39 
40 
41 #include <boost/shared_array.hpp>
42 #include "Epetra_SerialDenseMatrix.h"
43 #include "Epetra_SerialDenseSolver.h"
44 #include "Epetra_SerialDenseVector.h"
45 
46 
47 #include <lifev/core/LifeV.hpp>
48 #include <lifev/core/util/Displayer.hpp>
49 #include <lifev/core/fem/BCBase.hpp>
50 #include <lifev/core/fem/BCFunction.hpp>
51 #include <lifev/core/fem/BCManage.hpp>
52 
53 namespace LifeV
54 {
55 
56 //! BCDataInterpolator - Class for interpolating boundary functions from scattered data
57 /*!
58  @author Toni Lassila
59  @see Radial basis function interpolation \cite Buhmann2004
60 
61  Implements Radial Basis Function (RBF) interpolation of pointwise scalar or vectorial functions defined
62  on a set of scattered interpolation points. Currently implements a variety of different basis functions
63  for interpolation. Temporal interpolation done with trigonometric polynomials.
64 
65  Inherits @c BCFunctionBase to facilitate use of interpolated data as boundary condition.
66 
67  If the interpolated data depends on time, the user must pass the data values at 2n specific time instances,
68  uniformly sampled at interval M_timeInterval and with period M_timePeriod. The values of the data between
69  these time instances is interpolated using Fourier interpolation, i.e. the interpolant is a trigonometric
70  polynomial of order 2n and periodic with period M_timePeriod.
71 
72  The format of the data file passed to readData() is the following: <BR>
73  <BR>
74  # HEADER LINE FOR PARAMETERS <BR>
75  nof_data_sites nof_data_dimensions t_interval t_period filtering_level <BR>
76  # HEADER LINE FOR DATA SITES <BR>
77  data_site_1_x_coord data_site_1_y_coord data_site_1_z_coord <BR>
78  ... <BR>
79  data_site_n_x_coord data_site_n_y_coord data_site_n_z_coord <BR>
80  # HEADER LINE FOR DATA VALUES <BR>
81  data_value_1_x_coord data_value_1_y_coord data_value_1_z_coord <BR>
82  ... <BR>
83  data_value_n_x_coord data_value_n_y_coord data_value_n_z_coord <BR>
84  # HEADER LINE FOR DATA VALUES <BR>
85  data_value_1_x_coord data_value_1_y_coord data_value_1_z_coord <BR>
86  ... <BR>
87  data_value_n_x_coord data_value_n_y_coord data_value_n_z_coord <BR>
88  <BR>
89  The variable nof_data_dimensions has to equal 1 or 3, depending on whether scalar or vectorial data
90  is being interpolated. The variable nof_data_sites has to equal the number of rows passed in
91  both the section involving the data_sites and the data values. The data value section has to be
92  repeated t_period / t_interval times. The value filtering_level >= 0 is used to drop the most
93  oscillatory terms in the trigonometric polynomial, and should be an integer.
94 
95  Warning: in the current implementation the data sites are assumed fixed in time and they do not move
96  with the mesh. Thus they should only be used in a Lagrangian frame of reference, i.e. with structural
97  BC's.
98  */
99 
101  public BCFunctionBase
102 {
103 public:
104 
105  //! @name Public Types
106  //@{
107 
113 
114 
115  /*! @enum BCInterpolation_Type
116  Interpolation methods: RBF_ThinPlateSpline
117  RBF_MultiQuadric
118  RBF_Cubic
119  RBF_Gaussian
120  RBF_InverseMultiQuadric
121  */
123  {
124  RBF_InverseMultiQuadric, /*!< Inverse multiquadrics */
125  RBF_Gaussian, /*!< Gaussians */
126  RBF_ThinPlateSpline, /*!< Thin plate splines */
127  RBF_MultiQuadric, /*!< Multiquadrics */
128  RBF_Cubic /*!< Cubics */
129  };
130 
131  //@}
132 
133 
134  //! @name Constructor & Destructor
135  //@{
136 
137  //! Constructors for an data interpolator
138  /*!
139 
140  */
141  explicit BCDataInterpolator();
142 
143  //! Destructor
144  virtual ~BCDataInterpolator();
145 
146  //@}
147 
148 
149  //! @name Operators
150  //@{
151 
152  //! Assignment operator
153  /*!
154  @param bdFunctionDirectional The BCFunctionDirectional object
155  @return Reference to a new BCFunctionDirectional object which is a copy of bcFunctionDirectional
156  */
157  //BCFunctionDirectional& operator=( const BCDataInterpolator& bcDataInterpolator );
158 
159  //@}
160 
161 
162  //! @name Methods
163  //@{
164 
165  //! Evaluate the interpolated function
166  /*!
167  \param t Time
168  \param x Coordinate
169  \param y Coordinate
170  \param z Coordinate
171  \param component The component of the vector function
172  \return The selected component of the vector function evaluated in (t,x,y,z)
173  */
175  const Real& x,
176  const Real& y,
177  const Real& z,
178  const ID& component );
179 
180  //! Display the content of the variables
181  /*!
182  @param verbose The verbosity (default: false)
183  @param out The ostream output (default: std::cout)
184  */
185  void showMe ( bool verbose = false,
186  std::ostream& out = std::cout ) const;
187 
188  //! Read control points and data from a file
189  /*!
190  @param filename The filename for the data sites and data values
191  */
192  void readData ( const std::string& fileName );
193 
194  //! Export the interpolation matrix for debugging purposes
195  /*!
196 
197  */
198  void exportInterpolationMatrix() const;
199 
200  //@}
201 
202 
203  //! @name Set Methods
204  //@{
205 
206  //! Set the interpolation method
207  /*!
208  @param bcInterpolationMethod The interpolation method
209  */
210  void setInterpolationMethod ( const BCInterpolationMethod& bcInterpolationMethod )
211  {
212  M_interpolationMethod = bcInterpolationMethod;
213  }
214 
215  //! Set the filtering level
216  /*!
217  @param filteringLevel The filtering level
218  */
219  void setFilteringLevel ( const Int& filteringLevel )
220  {
221  M_filteringLevel = filteringLevel;
222  }
223 
224 
225  //! @name Get Methods
226  //@{
227 
228  //! Returns the number of control points
229  /*!
230  * @return The number of control points
231  */
232  const UInt& nofControlPoints() const
233  {
234  return M_nofControlPoints;
235  }
236 
237  //@}
238 
239 private:
240 
242  {
246  };
247 
248  //! @name Private Methods
249  //@{
250 
251  void formRBFMatrix();
254  const Real& x,
255  const Real& y,
256  const Real& z );
258  const BCDataInterpolator_point point2 );
259  bool needSideConstraints() const;
260  void formRBFvectors();
261  void interpolateDataValuesInTime ( const Real t );
262 
263  Int indexInTime (const Int dataSite, const Int timeInstant) const
264  {
265  return M_nofControlPoints * timeInstant + dataSite;
266  }
267 
268  //@}
269 
271 
274 
276 
278 
282 
284 
286 
290 
292  bool M_verbose;
293 };
294 
295 } // namespace LifeV
296 
297 #endif /* BCDATAINTERPOLATOR_H */
void readData(const std::string &fileName)
Read control points and data from a file.
BCInterpolationMethod M_interpolationMethod
Real interpolatedDataFunction(const Real &t, const Real &x, const Real &y, const Real &z, const ID &component)
Evaluate the interpolated function.
Real evaluateRBF(const BCDataInterpolator_point point1, const BCDataInterpolator_point point2)
boost::shared_array< BCDataInterpolator_point > M_dataValues_timeSamples
void showMe(bool verbose=false, std::ostream &out=std::cout) const
Display the content of the variables.
std::shared_ptr< vector_Type > vectorPtr_Type
Epetra_SerialDenseVector vector_Type
BCDataInterpolator()
Constructors for an data interpolator.
Epetra_SerialDenseMatrix matrix_Type
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
void interpolateDataValuesInTime(const Real t)
void updateInverseJacobian(const UInt &iQuadPt)
Epetra_SerialDenseSolver solver_Type
BCFunctionBase - class that holds the function used for prescribing boundary conditions.
Definition: BCFunction.hpp:77
BCDataInterpolator_point interpolateVectorialFunction(const Real &t, const Real &x, const Real &y, const Real &z)
uint32_type ID
IDs.
Definition: LifeV.hpp:194
virtual ~BCDataInterpolator()
Destructor.
void setInterpolationMethod(const BCInterpolationMethod &bcInterpolationMethod)
Set the interpolation method.
boost::shared_array< BCDataInterpolator_point > M_dataValues
void exportInterpolationMatrix() const
Export the interpolation matrix for debugging purposes.
double Real
Generic real data.
Definition: LifeV.hpp:175
BCDataInterpolator - Class for interpolating boundary functions from scattered data.
const UInt & nofControlPoints() const
Returns the number of control points.
Int indexInTime(const Int dataSite, const Int timeInstant) const
void setFilteringLevel(const Int &filteringLevel)
Set the filtering level.
boost::shared_array< BCDataInterpolator_point > M_dataSites
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
std::shared_ptr< matrix_Type > matrixPtr_Type