37 #ifndef RBFRESCALEDVECTORIAL_H 38 #define RBFRESCALEDVECTORIAL_H 1
40 #include <lifev/core/interpolation/RBFInterpolation.hpp> 44 template <
typename mesh_Type>
97 double rbf (
double x1,
double y1,
double z1,
double x2,
double y2,
double z2,
double radius);
136 template <
typename mesh_Type>
141 template <
typename mesh_Type>
146 template <
typename mesh_Type>
156 template <
typename mesh_Type>
162 template <
typename mesh_Type>
167 M_datafile = datafile;
171 template <
typename Mesh>
174 this->interpolationOperator();
175 this->projectionOperator();
177 this->interpolateCostantField();
180 template <
typename Mesh>
183 ASSERT(M_radius!=0,
"Please set the basis radius using RBFrescaledScalar<mesh_Type>::setRadius(double radius)")
185 M_neighbors.reset (
new neighbors_Type ( M_fullMeshKnown, M_localMeshKnown, M_knownField->mapPtr(), M_knownField->mapPtr()->commPtr() ) );
188 M_neighbors->setUpNeighbors ();
192 M_neighbors->createPointPointNeighborsList (M_flags);
195 int LocalNodesNumber = M_GIdsKnownMesh.size();
197 std::vector<std::unordered_set<ID> > MatrixGraph (LocalNodesNumber);
198 int* ElementsPerRow =
new int[LocalNodesNumber];
199 int* GlobalID =
new int[LocalNodesNumber];
203 for (std::unordered_set<ID>::iterator it = M_GIdsKnownMesh.begin(); it != M_GIdsKnownMesh.end(); ++it)
206 MatrixGraph[k] = M_neighbors->neighborsWithinRadius (M_radius, GlobalID[k]);
207 MatrixGraph[k].insert (GlobalID[k]);
208 ElementsPerRow[k] = MatrixGraph[k].size();
209 if (ElementsPerRow[k] > Max_entries)
211 Max_entries = ElementsPerRow[k];
216 M_interpolationOperatorMap.reset (
new map_Type (-1, LocalNodesNumber, GlobalID, M_knownField->mapPtr()->commPtr() ) );
217 M_interpolationOperator.reset (
new matrix_Type (*M_interpolationOperatorMap, ElementsPerRow) );
219 int* Indices =
new int[Max_entries];
220 double* Values =
new double[Max_entries];
222 for (
int i = 0 ; i < LocalNodesNumber; ++i )
225 for ( std::unordered_set<ID>::iterator it = MatrixGraph[i].begin(); it != MatrixGraph[i].end(); ++it)
228 Values[k] = rbf ( M_fullMeshKnown->point (GlobalID[i]).x(),
229 M_fullMeshKnown->point (GlobalID[i]).y(),
230 M_fullMeshKnown->point (GlobalID[i]).z(),
231 M_fullMeshKnown->point (*it).x(),
232 M_fullMeshKnown->point (*it).y(),
233 M_fullMeshKnown->point (*it).z(),
237 M_interpolationOperator->matrixPtr()->InsertGlobalValues (GlobalID[i], k, Values, Indices);
239 M_interpolationOperator->globalAssemble();
242 delete[] ElementsPerRow;
246 template <
typename mesh_Type>
251 int LocalNodesNumber = M_GIdsUnknownMesh.size();
253 std::vector<std::unordered_set<ID> > MatrixGraph (LocalNodesNumber);
254 int* ElementsPerRow =
new int[LocalNodesNumber];
255 int* GlobalID =
new int[LocalNodesNumber];
262 for (std::unordered_set<ID>::iterator it = M_GIdsUnknownMesh.begin(); it != M_GIdsUnknownMesh.end(); ++it)
266 for (
int j = 0; j < M_fullMeshKnown->numVertices(); ++j)
268 if ( M_flags[0] == -1 ||
this->isInside (M_fullMeshKnown->point (j).markerID(), M_flags) )
270 d = std::sqrt ( pow (M_fullMeshKnown->point (j).x() - M_fullMeshUnknown->point (GlobalID[k]).x(), 2)
271 + pow (M_fullMeshKnown->point (j).y() - M_fullMeshUnknown->point (GlobalID[k]).y(), 2)
272 + pow (M_fullMeshKnown->point (j).z() - M_fullMeshUnknown->point (GlobalID[k]).z(), 2) );
276 nearestPoint = M_fullMeshKnown->point (j).id();
281 MatrixGraph[k] = M_neighbors->neighborsWithinRadius (M_radius, nearestPoint);
282 MatrixGraph[k].insert (nearestPoint);
283 ElementsPerRow[k] = MatrixGraph[k].size();
284 if (ElementsPerRow[k] > Max_entries)
286 Max_entries = ElementsPerRow[k];
291 M_projectionOperatorMap.reset (
new map_Type (-1, LocalNodesNumber, GlobalID, M_unknownField->mapPtr()->commPtr() ) );
292 M_projectionOperator.reset (
new matrix_Type (*M_projectionOperatorMap, ElementsPerRow) );
294 int* Indices =
new int[Max_entries];
295 double* Values =
new double[Max_entries];
297 for (
int i = 0 ; i < LocalNodesNumber; ++i )
300 for ( std::unordered_set<ID>::iterator it = MatrixGraph[i].begin(); it != MatrixGraph[i].end(); ++it)
303 Values[k] = rbf ( M_fullMeshUnknown->point (GlobalID[i]).x(),
304 M_fullMeshUnknown->point (GlobalID[i]).y(),
305 M_fullMeshUnknown->point (GlobalID[i]).z(),
306 M_fullMeshKnown->point (*it).x(),
307 M_fullMeshKnown->point (*it).y(),
308 M_fullMeshKnown->point (*it).z(),
312 M_projectionOperator->matrixPtr()->InsertGlobalValues (GlobalID[i], k, Values, Indices);
314 M_projectionOperator->globalAssemble (M_interpolationOperatorMap, M_projectionOperatorMap);
317 delete ElementsPerRow;
321 template <
typename mesh_Type>
324 M_RhsF1.reset (
new vector_Type (*M_interpolationOperatorMap) );
325 M_RhsF2.reset (
new vector_Type (*M_interpolationOperatorMap) );
326 M_RhsF3.reset (
new vector_Type (*M_interpolationOperatorMap) );
327 M_RhsOne.reset (
new vector_Type (*M_interpolationOperatorMap) );
329 M_RhsF1->subset (*M_knownField, *M_interpolationOperatorMap, 0, 0);
330 M_RhsF2->subset (*M_knownField, *M_interpolationOperatorMap, M_knownField->size()/3, 0);
331 M_RhsF3->subset (*M_knownField, *M_interpolationOperatorMap, M_knownField->size()/3*2, 0);
335 template <
typename mesh_Type>
339 gamma_one.reset (
new vector_Type (*M_interpolationOperatorMap) );
345 precRawPtr->setDataFromGetPot ( M_datafile,
"prec" );
346 precPtr.reset ( precRawPtr );
348 LinearSolver solverOne;
349 solverOne.setCommunicator ( M_knownField->mapPtr()->commPtr() );
350 solverOne.setParameters ( *M_belosList );
351 solverOne.setPreconditioner ( precPtr );
354 solverOne.setRightHandSide (
M_RhsOne );
355 solverOne.solve ( gamma_one );
357 M_rbf_one.reset (
new vector_Type (*M_projectionOperatorMap) );
358 M_projectionOperator->multiply (
false, *gamma_one, *M_rbf_one);
361 template <
typename mesh_Type>
365 gamma_f1.reset (
new vector_Type (*M_interpolationOperatorMap) );
368 gamma_f2.reset (
new vector_Type (*M_interpolationOperatorMap) );
371 gamma_f3.reset (
new vector_Type (*M_interpolationOperatorMap) );
378 precRawPtr->setDataFromGetPot ( M_datafile,
"prec" );
379 precPtr.reset ( precRawPtr );
381 LinearSolver solverRBF1;
382 solverRBF1.setCommunicator ( M_knownField->mapPtr()->commPtr() );
383 solverRBF1.setParameters ( *M_belosList );
384 solverRBF1.setPreconditioner ( precPtr );
387 solverRBF1.setRightHandSide (
M_RhsF1);
388 solverRBF1.solve (gamma_f1);
390 LinearSolver solverRBF2;
391 solverRBF2.setCommunicator ( M_knownField->mapPtr()->commPtr() );
392 solverRBF2.setParameters ( *M_belosList );
393 solverRBF2.setPreconditioner ( precPtr );
396 solverRBF2.setRightHandSide (
M_RhsF2);
397 solverRBF2.solve (gamma_f2);
399 LinearSolver solverRBF3;
400 solverRBF3.setCommunicator ( M_knownField->mapPtr()->commPtr() );
401 solverRBF3.setParameters ( *M_belosList );
402 solverRBF3.setPreconditioner ( precPtr );
405 solverRBF3.setRightHandSide (
M_RhsF3);
406 solverRBF3.solve (gamma_f3);
410 rbf_f1.reset (
new vector_Type (*M_projectionOperatorMap) );
413 solution1.reset (
new vector_Type (*M_projectionOperatorMap) );
415 M_projectionOperator->multiply (
false, *gamma_f1, *rbf_f1);
417 *solution1 = *rbf_f1;
418 *solution1 /= *M_rbf_one;
421 rbf_f2.reset (
new vector_Type (*M_projectionOperatorMap) );
424 solution2.reset (
new vector_Type (*M_projectionOperatorMap) );
426 M_projectionOperator->multiply (
false, *gamma_f2, *rbf_f2);
428 *solution2 = *rbf_f2;
429 *solution2 /= *M_rbf_one;
432 rbf_f3.reset (
new vector_Type (*M_projectionOperatorMap) );
435 solution3.reset (
new vector_Type (*M_projectionOperatorMap) );
437 M_projectionOperator->multiply (
false, *gamma_f3, *rbf_f3);
439 *solution3 = *rbf_f3;
440 *solution3 /= *M_rbf_one;
442 M_unknownField_rbf.reset (
new vector_Type (M_unknownField->map() ) );
443 M_unknownField_rbf->subset (*rbf_f1, *M_projectionOperatorMap, 0, 0);
444 M_unknownField_rbf->subset (*rbf_f2, *M_projectionOperatorMap, 0, M_unknownField->size()/3);
445 M_unknownField_rbf->subset (*rbf_f3, *M_projectionOperatorMap, 0, M_unknownField->size()/3*2);
447 M_unknownField->subset (*solution1, *M_projectionOperatorMap, 0, 0);
448 M_unknownField->subset (*solution2, *M_projectionOperatorMap, 0, M_unknownField->size()/3);
449 M_unknownField->subset (*solution3, *M_projectionOperatorMap, 0, M_unknownField->size()/3*2);
453 template <
typename mesh_Type>
458 for ( UInt i = 0; i < LocalMesh->numVertices(); ++i )
459 if (CheckVector->blockMap().LID (
static_cast<EpetraInt_Type> (LocalMesh->point (i).id()) ) != -1)
461 GID_nodes.insert (LocalMesh->point (i).id() );
466 for ( UInt i = 0; i < LocalMesh->numVertices(); ++i )
467 if (
this->isInside (LocalMesh->point (i).markerID(), M_flags) )
468 if (CheckVector->blockMap().LID (
static_cast<EpetraInt_Type> (LocalMesh->point (i).id()) ) != -1)
470 GID_nodes.insert (LocalMesh->point (i).id() );
475 template <
typename mesh_Type>
479 for (UInt i = 0; i < flags.size(); ++i)
480 if (pointMarker == flags[i])
484 return (check > 0) ?
true :
false;
488 template <
typename mesh_Type>
491 double distance = sqrt ( pow (x1 - x2, 2) + pow (y1 - y2, 2) + pow (z1 - z2, 2) );
492 return pow (1 - distance / radius, 4) * (4 * distance / radius + 1);
495 template <
typename mesh_Type>
499 M_RhsF1->subset (*newRhs, *M_interpolationOperatorMap, 0, 0);
501 M_RhsF2->subset (*newRhs, *M_interpolationOperatorMap, newRhs->size()/3, 0);
503 M_RhsF3->subset (*newRhs, *M_interpolationOperatorMap, newRhs->size()/3*2, 0);
506 template <
typename mesh_Type>
512 template <
typename mesh_Type>
519 template <
typename mesh_Type>
neighborsPtr_Type M_neighbors
static bool S_registerTriRV
void updateRhs(vectorPtr_Type newRhs)
std::unordered_set< ID > idContainer_Type
void setRadius(double radius)
std::shared_ptr< neighbors_Type > neighborsPtr_Type
LifeV::Preconditioner basePrec_Type
vectorPtr_Type M_unknownField_rbf
void interpolationOperator()
RBFInterpolation< mesh_Type > * createRBFrescaledVectorial()
Factory create function.
mapPtr_Type M_interpolationOperatorMap
void identifyNodes(meshPtr_Type LocalMesh, std::unordered_set< ID > &GID_nodes, vectorPtr_Type CheckVector)
void setupRBFData(vectorPtr_Type KnownField, vectorPtr_Type UnknownField, GetPot datafile, parameterList_Type belosList)
parameterList_Type M_belosList
std::shared_ptr< prec_Type > precPtr_Type
static const LifeV::UInt elm_nodes_num[]
void solution(vectorPtr_Type &Solution)
flagContainer_Type M_flags
std::vector< int > flagContainer_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
vectorPtr_Type M_knownField
MatrixEpetra< double > matrix_Type
GhostHandler< mesh_Type > neighbors_Type
mapPtr_Type M_projectionOperatorMap
double rbf(double x1, double y1, double z1, double x2, double y2, double z2, double radius)
void solutionrbf(vectorPtr_Type &Solution_rbf)
std::shared_ptr< MapEpetra > mapPtr_Type
meshPtr_Type M_localMeshUnknown
void projectionOperator()
Teuchos::RCP< Teuchos::ParameterList > parameterList_Type
std::shared_ptr< matrix_Type > matrixPtr_Type
vectorPtr_Type M_unknownField
meshPtr_Type M_localMeshKnown
void interpolateCostantField()
std::shared_ptr< mesh_Type > meshPtr_Type
bool isInside(ID pointMarker, flagContainer_Type Flags)
virtual ~RBFrescaledVectorial()
LifeV::PreconditionerIfpack prec_Type
meshPtr_Type M_fullMeshUnknown
meshPtr_Type M_fullMeshKnown
std::shared_ptr< vector_Type > vectorPtr_Type
idContainer_Type M_GIdsUnknownMesh
std::shared_ptr< basePrec_Type > basePrecPtr_Type
static bool S_registerTetRV
matrixPtr_Type M_interpolationOperator
void importFromHDF5(std::string const &fileName="ghostmap")
Import neighbor lists to an hdf5 file.
matrixPtr_Type M_projectionOperator
void setup(meshPtr_Type fullMeshKnown, meshPtr_Type localMeshKnown, meshPtr_Type fullMeshUnknown, meshPtr_Type localMeshUnknown, flagContainer_Type flags)
idContainer_Type M_GIdsKnownMesh