37 #ifndef RBFLOCALLYRESCALEDSCALAR_H 38 #define RBFLOCALLYRESCALEDSCALAR_H 1
40 #include <lifev/core/interpolation/RBFInterpolation.hpp> 45 template <
typename mesh_Type>
100 double rbf (
double x1,
double y1,
double z1,
double x2,
double y2,
double z2,
double radius);
149 template <
typename mesh_Type>
153 template <
typename mesh_Type>
157 template <
typename mesh_Type>
166 M_kx.resize(M_fullMeshKnown->numVertices());
167 M_ky.resize(M_fullMeshKnown->numVertices());
168 M_kz.resize(M_fullMeshKnown->numVertices());
170 for (
int j = 0; j < M_fullMeshKnown->numVertices(); ++j)
172 M_kx[j] = M_fullMeshKnown->point(j).x();
173 M_ky[j] = M_fullMeshKnown->point(j).y();
174 M_kz[j] = M_fullMeshKnown->point(j).z();
177 M_ukx.resize(M_fullMeshUnknown->numVertices());
178 M_uky.resize(M_fullMeshUnknown->numVertices());
179 M_ukz.resize(M_fullMeshUnknown->numVertices());
181 for (
int j = 0; j < M_fullMeshUnknown->numVertices(); ++j)
183 M_ukx[j] = M_fullMeshUnknown->point(j).x();
184 M_uky[j] = M_fullMeshUnknown->point(j).y();
185 M_ukz[j] = M_fullMeshUnknown->point(j).z();
190 template <
typename mesh_Type>
195 M_datafile = datafile;
199 template <
typename mesh_Type>
205 template <
typename Mesh>
210 this->interpolationOperator();
211 this->projectionOperator();
213 if(M_knownField->mapPtr()->commPtr()->MyPID()==0)
214 std::cout <<
"Time to assembly operators = " << TimeBuilding.diff() << std::endl;
217 this->interpolateCostantField();
220 template <
typename Mesh>
224 M_neighbors.reset (
new neighbors_Type ( M_fullMeshKnown, M_localMeshKnown, M_knownField->mapPtr(), M_knownField->mapPtr()->commPtr() ) );
227 M_neighbors->setUpNeighbors();
231 M_neighbors->createPointPointNeighborsList (M_flags);
234 int LocalNodesNumber = M_GIdsKnownMesh.size();
236 std::vector<
double> RBF_radius (LocalNodesNumber);
237 std::vector<std::unordered_set<ID> > MatrixGraph (LocalNodesNumber);
238 int* ElementsPerRow =
new int[LocalNodesNumber];
239 int* GlobalID =
new int[LocalNodesNumber];
243 for (std::unordered_set<ID>::iterator it = M_GIdsKnownMesh.begin(); it != M_GIdsKnownMesh.end(); ++it)
246 MatrixGraph[k] = M_neighbors->pointPointNeighborsList() [GlobalID[k]];
247 MatrixGraph[k].insert (GlobalID[k]);
248 RBF_radius[k] = computeRBFradius ( M_fullMeshKnown, M_fullMeshKnown, MatrixGraph[k], GlobalID[k]);
249 ElementsPerRow[k] = MatrixGraph[k].size();
250 if (ElementsPerRow[k] > Max_entries)
252 Max_entries = ElementsPerRow[k];
257 M_interpolationOperatorMap.reset (
new map_Type (-1, LocalNodesNumber, GlobalID, M_knownField->mapPtr()->commPtr() ) );
258 M_interpolationOperator.reset (
new matrix_Type (*M_interpolationOperatorMap, ElementsPerRow) );
260 int* Indices =
new int[Max_entries];
261 double* Values =
new double[Max_entries];
263 for (
int i = 0 ; i < LocalNodesNumber; ++i )
266 for ( std::unordered_set<ID>::iterator it = MatrixGraph[i].begin(); it != MatrixGraph[i].end(); ++it)
269 Values[k] = rbf ( M_kx[GlobalID[i]], M_ky[GlobalID[i]], M_kz[GlobalID[i]],
270 M_kx[*it], M_ky[*it], M_kz[*it],
274 M_interpolationOperator->matrixPtr()->InsertGlobalValues (GlobalID[i], k, Values, Indices);
276 M_interpolationOperator->globalAssemble();
279 delete[] ElementsPerRow;
283 template <
typename mesh_Type>
289 int LocalNodesNumber = M_GIdsUnknownMesh.size();
291 std::vector<
double> RBF_radius (LocalNodesNumber);
292 std::vector<std::unordered_set<ID> > MatrixGraph (LocalNodesNumber);
293 int* ElementsPerRow =
new int[LocalNodesNumber];
294 int* GlobalID =
new int[LocalNodesNumber];
301 for (std::unordered_set<ID>::iterator it = M_GIdsUnknownMesh.begin(); it != M_GIdsUnknownMesh.end(); ++it)
305 for (
int j = 0; j < M_fullMeshKnown->numVertices(); ++j)
307 if ( M_flags[0] == -1 ||
this->isInside (M_fullMeshKnown->point (j).markerID(), M_flags) )
309 d = std::sqrt ( std::pow (M_kx[j] - M_ukx[GlobalID[k]], 2)
310 + std::pow (M_ky[j] - M_uky[GlobalID[k]], 2)
311 + std::pow (M_kz[j] - M_ukz[GlobalID[k]], 2) );
315 nearestPoint = M_fullMeshKnown->point (j).id();
319 MatrixGraph[k] = M_neighbors->pointPointNeighborsList() [nearestPoint];
320 MatrixGraph[k].insert (nearestPoint);
321 RBF_radius[k] = computeRBFradius ( M_fullMeshKnown, M_fullMeshUnknown, MatrixGraph[k], GlobalID[k]);
322 ElementsPerRow[k] = MatrixGraph[k].size();
323 if (ElementsPerRow[k] > Max_entries)
325 Max_entries = ElementsPerRow[k];
330 M_projectionOperatorMap.reset (
new map_Type (-1, LocalNodesNumber, GlobalID, M_unknownField->mapPtr()->commPtr() ) );
331 M_projectionOperator.reset (
new matrix_Type (*M_projectionOperatorMap, ElementsPerRow) );
333 int* Indices =
new int[Max_entries];
334 double* Values =
new double[Max_entries];
336 for (
int i = 0 ; i < LocalNodesNumber; ++i )
339 for ( std::unordered_set<ID>::iterator it = MatrixGraph[i].begin(); it != MatrixGraph[i].end(); ++it)
342 Values[k] = rbf ( M_ukx[GlobalID[i]], M_uky[GlobalID[i]], M_ukz[GlobalID[i]],
343 M_kx[*it], M_ky[*it], M_kz[*it], RBF_radius[i]);
346 M_projectionOperator->matrixPtr()->InsertGlobalValues (GlobalID[i], k, Values, Indices);
348 M_projectionOperator->globalAssemble (M_interpolationOperatorMap, M_projectionOperatorMap);
351 delete[] ElementsPerRow;
355 template <
typename mesh_Type>
360 for (idContainer_Type::iterator it = Neighbors.begin(); it != Neighbors.end(); ++it)
362 r = std::sqrt ( std::pow ( MeshGID->point ( GlobalID ).x() - MeshNeighbors->point ( *it ).x(), 2 )
363 + std::pow ( MeshGID->point ( GlobalID ).y() - MeshNeighbors->point ( *it ).y(), 2 )
364 + std::pow ( MeshGID->point ( GlobalID ).z() - MeshNeighbors->point ( *it ).z(), 2 ) );
365 r_max = ( r > r_max ) ? r : r_max;
370 template <
typename mesh_Type>
373 M_RhsF.reset (
new vector_Type (*M_interpolationOperatorMap) );
374 M_RhsOne.reset (
new vector_Type (*M_interpolationOperatorMap) );
376 M_RhsF->subset (*M_knownField, *M_interpolationOperatorMap, 0, 0);
380 template <
typename mesh_Type>
384 gamma_one.reset (
new vector_Type (*M_interpolationOperatorMap) );
390 precRawPtr->setDataFromGetPot ( M_datafile,
"prec" );
391 precPtr.reset ( precRawPtr );
393 LinearSolver solverOne;
394 solverOne.setCommunicator ( M_knownField->mapPtr()->commPtr() );
395 solverOne.setParameters ( *M_belosList );
396 solverOne.setPreconditioner ( precPtr );
399 solverOne.setRightHandSide (
M_RhsOne );
400 solverOne.solve ( gamma_one );
402 M_rbf_one.reset (
new vector_Type (*M_projectionOperatorMap) );
403 M_projectionOperator->multiply (
false, *gamma_one, *M_rbf_one);
406 template <
typename mesh_Type>
410 gamma_f.reset (
new vector_Type (*M_interpolationOperatorMap) );
416 precRawPtr->setDataFromGetPot ( M_datafile,
"prec" );
417 precPtr.reset ( precRawPtr );
419 LinearSolver solverRBF;
420 solverRBF.setCommunicator ( M_knownField->mapPtr()->commPtr() );
421 solverRBF.setParameters ( *M_belosList );
422 solverRBF.setPreconditioner ( precPtr );
425 solverRBF.setRightHandSide (
M_RhsF);
426 solverRBF.solve (gamma_f);
429 rbf_f.reset (
new vector_Type (*M_projectionOperatorMap) );
432 solution.reset (
new vector_Type (*M_projectionOperatorMap) );
434 M_projectionOperator->multiply (
false, *gamma_f, *rbf_f);
437 *solution /= *M_rbf_one;
439 M_unknownField_rbf.reset (
new vector_Type (M_unknownField->map() ) );
440 M_unknownField_rbf->subset (*rbf_f, *M_projectionOperatorMap, 0, 0);
442 M_unknownField->subset (*solution, *M_projectionOperatorMap, 0, 0);
445 template <
typename mesh_Type>
450 for ( UInt i = 0; i < LocalMesh->numVertices(); ++i )
451 if (CheckVector->blockMap().LID (
static_cast<EpetraInt_Type> (LocalMesh->point (i).id()) ) != -1)
453 GID_nodes.insert (LocalMesh->point (i).id() );
458 for ( UInt i = 0; i < LocalMesh->numVertices(); ++i )
459 if (
this->isInside (LocalMesh->point (i).markerID(), M_flags) )
460 if (CheckVector->blockMap().LID (
static_cast<EpetraInt_Type> (LocalMesh->point (i).id()) ) != -1)
462 GID_nodes.insert (LocalMesh->point (i).id() );
467 template <
typename mesh_Type>
471 for (UInt i = 0; i < flags.size(); ++i)
472 if (pointMarker == flags[i])
476 return (check > 0) ?
true :
false;
480 template <
typename mesh_Type>
483 double distance = std::sqrt ( std::pow (x1 - x2, 2) + std::pow (y1 - y2, 2) + std::pow (z1 - z2, 2) );
484 return std::pow (1 - distance / radius, 4) * (4 * distance / radius + 1);
487 template <
typename mesh_Type>
494 template <
typename mesh_Type>
500 template <
typename mesh_Type>
507 template <
typename mesh_Type>
void setup(meshPtr_Type fullMeshKnown, meshPtr_Type localMeshKnown, meshPtr_Type fullMeshUnknown, meshPtr_Type localMeshUnknown, flagContainer_Type flags)
std::shared_ptr< mesh_Type > meshPtr_Type
bool isInside(ID pointMarker, flagContainer_Type Flags)
void start()
Start the timer.
void setRadius(double radius)
virtual ~RBFlocallyRescaledScalar()
RBFlocallyRescaledScalar()
void interpolationOperator()
idContainer_Type M_GIdsUnknownMesh
std::unordered_set< ID > idContainer_Type
double computeRBFradius(meshPtr_Type MeshNeighbors, meshPtr_Type MeshGID, idContainer_Type Neighbors, ID GlobalID)
idContainer_Type M_GIdsKnownMesh
std::vector< double > M_ukz
matrixPtr_Type M_interpolationOperator
std::shared_ptr< basePrec_Type > basePrecPtr_Type
GhostHandler< mesh_Type > neighbors_Type
flagContainer_Type M_flags
void interpolateCostantField()
MatrixEpetra< double > matrix_Type
static const LifeV::UInt elm_nodes_num[]
void solution(vectorPtr_Type &Solution)
static bool S_registerTetLRS
std::shared_ptr< vector_Type > vectorPtr_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
void getprojectionOperatorMap(mapPtr_Type &map)
void updateRhs(vectorPtr_Type newRhs)
vectorPtr_Type M_unknownField_rbf
matrixPtr_Type M_projectionOperator
meshPtr_Type M_fullMeshKnown
double rbf(double x1, double y1, double z1, double x2, double y2, double z2, double radius)
LifeV::PreconditionerIfpack prec_Type
meshPtr_Type M_localMeshUnknown
parameterList_Type M_belosList
std::vector< double > M_uky
meshPtr_Type M_localMeshKnown
vectorPtr_Type M_unknownField
std::shared_ptr< matrix_Type > matrixPtr_Type
vectorPtr_Type M_knownField
std::shared_ptr< prec_Type > precPtr_Type
void stop()
Stop the timer.
LifeV::Preconditioner basePrec_Type
void projectionOperator()
Teuchos::RCP< Teuchos::ParameterList > parameterList_Type
std::vector< double > M_kx
void solutionrbf(vectorPtr_Type &Solution_rbf)
void getinterpolationOperatorMap(mapPtr_Type &map)
void setupRBFData(vectorPtr_Type KnownField, vectorPtr_Type UnknownField, GetPot datafile, parameterList_Type belosList)
mapPtr_Type M_interpolationOperatorMap
mapPtr_Type M_projectionOperatorMap
std::vector< int > flagContainer_Type
std::vector< double > M_ky
neighborsPtr_Type M_neighbors
meshPtr_Type M_fullMeshUnknown
void identifyNodes(meshPtr_Type LocalMesh, std::unordered_set< ID > &GID_nodes, vectorPtr_Type CheckVector)
RBFInterpolation< mesh_Type > * createRBFlocallyRescaledScalar()
Factory create function.
std::shared_ptr< MapEpetra > mapPtr_Type
std::vector< double > M_ukx
void importFromHDF5(std::string const &fileName="ghostmap")
Import neighbor lists to an hdf5 file.
std::vector< double > M_kz
std::shared_ptr< neighbors_Type > neighborsPtr_Type
static bool S_registerTriLRS