37 #include <lifev/core/fem/BCDataInterpolator.hpp> 40 #include <boost/shared_array.hpp> 41 #include <boost/bind.hpp> 76 M_userDefinedFunction = std::bind ( &BCDataInterpolator::interpolatedDataFunction,
this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
103 const ID& component )
118 std::ostringstream exception;
119 exception <<
"Invalid component: " << component << std::endl;
120 throw std::invalid_argument ( exception.str() );
126 out <<
" Boundary Conditions Data Interpolator ====>" << std::endl;
127 out <<
" Data sites:" << std::endl;
131 out <<
"(" << M_dataSites[i].x <<
", " << M_dataSites[i].y <<
", " << M_dataSites[i].z <<
")" << std::endl;
138 out <<
" Data values (at sites):" << std::endl;
141 out <<
"(" << M_dataValues_timeSamples[indexInTime (i, t)].x <<
", " << M_dataValues_timeSamples[indexInTime (i, t)].y <<
", " << M_dataValues_timeSamples[indexInTime (i, t)].z <<
")" << std::endl;
146 out <<
" Data values (interpolated):" << std::endl;
149 out <<
"(" << M_dataValues[i].x <<
", " << M_dataValues[i].y <<
", " << M_dataValues[i].z <<
")" << std::endl;
158 fin.open ( fileName.c_str() );
162 fin.ignore ( 80,
'\n' );
166 fin >> M_timeInterval;
170 if ( ( RDIM != 1 ) && ( RDIM != 3 ) )
172 std::ostringstream exception;
173 exception <<
"Interpolated data must be either scalar or a 3-vector: " << std::endl;
174 throw std::invalid_argument ( exception.str() );
179 std::ostringstream exception;
180 exception <<
"Interpolation time interval and/or period are inconsistent." << std::endl;
181 throw std::invalid_argument ( exception.str() );
186 M_dataSites = boost::shared_array<BCDataInterpolator_point> (
new BCDataInterpolator_point[M_nofControlPoints]);
187 M_dataValues = boost::shared_array<BCDataInterpolator_point> (
new BCDataInterpolator_point[M_nofControlPoints]);
188 M_dataValues_timeSamples = boost::shared_array<BCDataInterpolator_point> (
new BCDataInterpolator_point[M_nofControlPoints * (n + 1)]);
190 fin.ignore ( 80,
'\n' );
191 fin.ignore ( 80,
'\n' );
196 fin >> M_dataSites[i].x;
197 fin >> M_dataSites[i].y;
198 fin >> M_dataSites[i].z;
201 fin.ignore ( 80,
'\n' );
202 fin.ignore ( 80,
'\n' );
205 for (
Int t = 0; t <= n; t++)
210 fin >> M_dataValues_timeSamples[indexInTime (i, t)].x;
211 fin >> M_dataValues_timeSamples[indexInTime (i, t)].y;
212 fin >> M_dataValues_timeSamples[indexInTime (i, t)].z;
215 fin.ignore ( 80,
'\n' );
216 fin.ignore ( 80,
'\n' );
240 M_interpolationMatrix.Shape (
static_cast<
int > ( nofElementsPerRow ),
241 static_cast<
int > ( nofElementsPerRow ) );
248 for (
UInt j = 0; j <= i; j++ )
252 rbfEval = evaluateRBF ( M_dataSites[i], M_dataSites[j] );
253 M_interpolationMatrix (
static_cast<
int > ( i ),
static_cast<
int > ( j ) ) =
static_cast<
double > ( rbfEval );
254 M_interpolationMatrix (
static_cast<
int > ( j ),
static_cast<
int > ( i ) ) =
static_cast<
double > ( rbfEval );
269 M_interpolationMatrix ( i, M_nofControlPoints ) = M_dataSites[i].x;
270 M_interpolationMatrix ( i, M_nofControlPoints + 1 ) = M_dataSites[i].y;
271 M_interpolationMatrix ( i, M_nofControlPoints + 2 ) = M_dataSites[i].z;
273 M_interpolationMatrix ( M_nofControlPoints, i ) = M_dataSites[i].x;
274 M_interpolationMatrix ( M_nofControlPoints + 1, i ) = M_dataSites[i].y;
275 M_interpolationMatrix ( M_nofControlPoints + 2, i ) = M_dataSites[i].z;
278 M_interpolationMatrix ( i, M_nofControlPoints + 3 ) = 1;
279 M_interpolationMatrix ( M_nofControlPoints + 3, i ) = 1;
284 M_denseSolver.SetMatrix ( M_interpolationMatrix );
294 Real reciprocalCond = M_denseSolver.RCOND();
296 if (reciprocalCond < 1e-6)
298 debugStream ( 5000 ) <<
"Radial basis interpolation matrix is ill-conditioned.\n";
299 debugStream ( 5000 ) <<
"Estimated reciprocal of condition number: " << reciprocalCond <<
"\n";
305 M_denseSolver.SetVectors ( M_coeffs_x, M_rhs_x );
306 M_denseSolver.Solve();
308 M_denseSolver.SetVectors ( M_coeffs_y, M_rhs_y );
309 M_denseSolver.Solve();
311 M_denseSolver.SetVectors ( M_coeffs_z, M_rhs_z );
312 M_denseSolver.Solve();
347 rbfShape = evaluateRBF ( evalPoint, M_dataSites[i] );
350 rbfEval.x += M_coeffs_x ( i ) * rbfShape;
351 rbfEval.y += M_coeffs_y ( i ) * rbfShape;
352 rbfEval.z += M_coeffs_z ( i ) * rbfShape;
360 rbfEval.x += M_coeffs_x ( M_nofControlPoints ) * evalPoint.x;
361 rbfEval.x += M_coeffs_x ( 1 + M_nofControlPoints ) * evalPoint.y;
362 rbfEval.x += M_coeffs_x ( 2 + M_nofControlPoints ) * evalPoint.z;
364 rbfEval.y += M_coeffs_y ( M_nofControlPoints ) * evalPoint.x;
365 rbfEval.y += M_coeffs_y ( 1 + M_nofControlPoints ) * evalPoint.y;
366 rbfEval.y += M_coeffs_y ( 2 + M_nofControlPoints ) * evalPoint.z;
368 rbfEval.z += M_coeffs_z ( M_nofControlPoints ) * evalPoint.x;
369 rbfEval.z += M_coeffs_z ( 1 + M_nofControlPoints ) * evalPoint.y;
370 rbfEval.z += M_coeffs_z ( 2 + M_nofControlPoints ) * evalPoint.z;
373 rbfEval.x += M_coeffs_x ( 3 + M_nofControlPoints );
374 rbfEval.y += M_coeffs_y ( 3 + M_nofControlPoints );
375 rbfEval.z += M_coeffs_z ( 3 + M_nofControlPoints );
384 Real r = std::sqrt ( std::pow ( point1
.x - point2
.x, 2 ) + std::pow ( point1
.y - point2
.y, 2 ) + std::pow ( point1
.z - point2
.z, 2 ) );
390 return ( r < 1e-3 ? 0.0 : std::pow ( r, 2 ) * std::log ( r ) );
393 return std::sqrt ( std::pow ( r, 2 ) + 1 );
396 return std::pow ( r, 3 );
399 return std::exp ( -std::pow ( r, 2 ) );
402 return 1 / std::sqrt (std::pow ( r, 2 ) + 1);
428 M_rhs_x.Size (
static_cast<
int > ( nofElementsPerRow ) );
429 M_rhs_y.Size (
static_cast<
int > ( nofElementsPerRow ) );
430 M_rhs_z.Size (
static_cast<
int > ( nofElementsPerRow ) );
432 M_coeffs_x.Size (
static_cast<
int > ( nofElementsPerRow ) );
433 M_coeffs_y.Size (
static_cast<
int > ( nofElementsPerRow ) );
434 M_coeffs_z.Size (
static_cast<
int > ( nofElementsPerRow ) );
440 M_rhs_x ( i ) = M_dataValues[i].x;
441 M_rhs_y ( i ) = M_dataValues[i].y;
442 M_rhs_z ( i ) = M_dataValues[i].z;
465 M_dataValues[i].x = 0;
466 M_dataValues[i].y = 0;
467 M_dataValues[i].z = 0;
471 for (
Int k = 0; k <= 2 * n; k++)
476 c1.x += std::cos (-j * tk * 2 *
M_PI / M_timePeriod) * M_dataValues_timeSamples[index_ik].x;
477 c1.y += std::cos (-j * tk * 2 *
M_PI / M_timePeriod) * M_dataValues_timeSamples[index_ik].y;
478 c1.z += std::cos (-j * tk * 2 *
M_PI / M_timePeriod) * M_dataValues_timeSamples[index_ik].z;
480 c2.x += std::sin (-j * tk * 2 *
M_PI / M_timePeriod) * M_dataValues_timeSamples[index_ik].x;
481 c2.y += std::sin (-j * tk * 2 *
M_PI / M_timePeriod) * M_dataValues_timeSamples[index_ik].y;
482 c2.z += std::sin (-j * tk * 2 *
M_PI / M_timePeriod) * M_dataValues_timeSamples[index_ik].z;
485 c1
.x = c1
.x / (2 * n + 1);
486 c1
.y = c1
.y / (2 * n + 1);
487 c1
.z = c1
.z / (2 * n + 1);
488 c2
.x = c2
.x / (2 * n + 1);
489 c2
.y = c2
.y / (2 * n + 1);
490 c2
.z = c2
.z / (2 * n + 1);
492 M_dataValues[i].x += c1.x * std::cos (j * t * 2 *
M_PI / M_timePeriod) - c2.x * std::sin (j * t * 2 *
M_PI / M_timePeriod);
493 M_dataValues[i].y += c1.y * std::cos (j * t * 2 *
M_PI / M_timePeriod) - c2.y * std::sin (j * t * 2 *
M_PI / M_timePeriod);
494 M_dataValues[i].z += c1.z * std::cos (j * t * 2 *
M_PI / M_timePeriod) - c2.z * std::sin (j * t * 2 *
M_PI / M_timePeriod);
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)
void showMe(bool verbose=false, std::ostream &out=std::cout) const
Display the content of the variables.
void solveInterpolationSystem()
BCDataInterpolator()
Constructors for an data interpolator.
int32_type Int
Generic integer data.
void interpolateDataValuesInTime(const Real t)
void updateInverseJacobian(const UInt &iQuadPt)
BCDataInterpolator_point interpolateVectorialFunction(const Real &t, const Real &x, const Real &y, const Real &z)
virtual ~BCDataInterpolator()
Destructor.
bool needSideConstraints() const
void exportInterpolationMatrix() const
Export the interpolation matrix for debugging purposes.
double Real
Generic real data.
BCDataInterpolator - Class for interpolating boundary functions from scattered data.
solver_Type M_denseSolver
Int indexInTime(const Int dataSite, const Int timeInstant) const
Real M_lastInterpolatedAtTime
matrix_Type M_interpolationMatrix
uint32_type UInt
generic unsigned integer (used mainly for addressing)