The main purpose of this module is to propose a set of algorithms for mesh interpolation fully independant of the mesh datastructure to support several type of format. This component is parameterized as much as possible using C++ templates. For the moment only interpolators for unstructured meshes are present in the interpolation kernel.
In the interpolation kernel, algorithms that computes the intersection
given the locations and geometries of source cell
and target cell
are called Intersectors.
As can be seen in the theory of interpolation, all the proposed interpolators aim at filling the interpolation matrix W (which is generally sparse). For each pair (i,j),
is obtained by calling the desired intersector. The problem is that each call to this algorithm is CPU-expensive. To reduce the computational time, a first filtering is done to detect pairs (i,j)
is obviously equal to 0. It is typically the case when a cell in the source mesh is too far from an another cell in the target mesh each.
So for a given type of interpolation, the computation of W is performed in two steps :
Whatever its dimension and type, each interpolator inherits from INTERP_KERNEL::Interpolation which is a template (CRTP) class than enable an easy access to the main API without useless CPU cost.
Each Interpolators and Intersectors are parameterized (templated in C++ langage) with class MeshType . This type of generalization has been chosen to reduce at maximum overhead.
Thanks to this principle intersectors and interpolators are usable with mesh formats such as MED or VTK, without preformance loss. MeshType is a concept that should strictly fulfilled the following rules :
int or long int .
) or FORTRAN (
).void getBoundingBox(double *boundingBox) const
INTERP_KERNEL::NormalizedCellType getTypeOfElement(MyConnType eltId) const
unsigned char getNumberOfNodesOfElement(MyConnType eltId) const
unsigned long getNumberOfNodes() const
unsigned long getNumberOfElements() const
const MyConnType *getConnectivityPtr() const
const double *getCoordinatesPtr() const
const MyConnType *getConnectivityIndexPtr() const
void releaseTempArrays()
getCoordinatesPtr must be a full interlace array.getConnectivityPtr and getConnectivityIndexPtr must be with the same principle as it is in medmem. Of course the numbering format may change according to My_numPol policy.Note that the array format for connectivity is kept close to MED. It is close to VTK format too but slightly different. So it may require for the VTK side a copy on wrap. To avoid this copy of a part of the connectivity structure, an iterator should be used.
As already said, the matrix returned by interpolator is typically a sparse matrix. Instances of class MatrixType are used to store the resulting interpolation matrix. To be able to be filled by the interpolator the MatrixType class has to match the following concept :
void resize(uint nbrows)
Row &operator [] (uint irow)
class Row has to match at least the following concept :
void insert(const std::pair<int,T>& myPair)
Note that std::vector is a candidate for < std::map<int,double> >MatrixType.
The simplest way of using the interpolation tools is in sequential mode to use the REMAPPER classes. These classes fulfill HXX2SALOME rules and may be used in coupling graphs. Two sequential REMAPPERS exist, ParaMEDMEM::MEDCouplingRemapper and MEDMEM::MEDMEM_REMAPPER . These classes are strongly linked to their corresponding data structure, respectively MEDCoupling and MEDMEM.
... const char sourceFileName[]="source.med"; MEDCouplingFieldDouble *sourceField=MEDLoader::ReadFieldCell(sourceFileName,"Source_Mesh",0,"Density",/*iteration*/0,/*order*/0); const char targetFileName[]="target.med"; MEDCouplingUMesh *med_target_mesh=MEDLoader::ReadUMeshFromFile(targetFileName,"Target_Mesh",0); // sourceField->setNature(ConservativeVolumic);//Specify nature is needed to allow remapper object to apply correct policy for denominator computation ! MEDCouplingRemapper remapper; remapper.setPrecision(1e-12); remapper.setIntersectionType(INTERP_KERNEL::Triangulation); remapper.prepare(sourceField->getMesh(),med_target_mesh,"P0P0"); MEDCouplingFieldDouble *targetField=remapper.transferField(sourceField,/*default_value*/4.57);//Any target cell not intercepted by any source cell will have value set to 4.57. ... // clean-up targetField->decrRef(); sourceField->decrRef(); med_target_mesh->decrRef();
medmemremapper class should be used :... std::string sourceFileName("source.med"); MEDMEM::MESH med_source_mesh(MED_DRIVER,sourceFileName,"Source_Mesh"); std::string targetFileName("target.med"); MEDMEM::MESH med_target_mesh(MED_DRIVER,targetFileName,"Target_Mesh"); FIELD<double> sourceField(MED_DRIVER,sourceFileName,"Density",0,0); FIELD<double> targetField; Remapper mapper; mapper.prepare(med_source_mesh,med_target_mesh,"P0P1"); mapper.transfer(sourceField,targetField); //use targetField ...
This mode is the mode that needs the minimum of prerequisites (algorithms and the datastructure you intend to use). On the other hand it is needed to specify precisely nature of interpolator.
As consequence of genericity of interpolators, they are usable only by instanciating an underneath mesh data structure. The two following examples show how to use interpolator at this level.
... MEDCouplingUMesh *med_source_mesh=MEDLoader::ReadUMeshFromFile("source.med","Source_mesh",0); MEDCouplingUMesh *med_target_mesh=MEDLoader::ReadUMeshFromFile("target.med","Target_mesh",0); MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_source_mesh(med_source_mesh); MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_target_mesh(med_target_mesh); // Go for interpolation... INTERP_KERNEL::Interpolation2D myInterpolator; myInterpolator.setPrecision(1e-7); myInterpolator.setIntersectionType(INTERP_KERNEL::Geometric2D); std::vector<std::map<int,double> > resultMatrix; INTERP_KERNEL::Matrix<double,ALL_C_MODE> resultMatrix2; // here the interpolation is performed twice for this code to show the capability of storing data of out matrix in 2 different data structures. myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0"); myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix2,"P0P0"); //Ok resultMatrix and resultMatrix2 contain matrix now ...
... std::string sourceFileName("source.med"); MEDMEM::MESH med_source_mesh(MED_DRIVER,sourceFileName,"Source_Mesh"); std::string targetFileName("target.med"); MEDMEM::MESH med_target_mesh(MED_DRIVER,targetFileName,"Target_Mesh"); // Ok at this point we have our mesh in MED-Memory format. // Go to wrap med_source_mesh and med_target_mesh. MEDNormalizedUnstructuredMesh<2,2> wrap_source_mesh(&med_source_mesh); MEDNormalizedUnstructuredMesh<2,2> wrap_target_mesh(&med_target_mesh); // Go for interpolation... INTERP_KERNEL::Interpolation2D myInterpolator; //optionnal call to parametrize your interpolation. First precision, tracelevel, intersector wanted. myInterpolator.setOptions(1e-7,0,Geometric2D); INTERP_KERNEL::Matrix<double,ALL_FORTRAN_MODE> resultMatrix; myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0"); //Ok let's multiply resultMatrix by source field to interpolate to target field. resultMatrix.multiply(...) ...
... vtkXMLUnstructuredGridReader *readerSource=vtkXMLUnstructuredGridReader::New(); readerSource->SetFileName("source.vtu"); vtkUnstructuredGrid *vtk_source_mesh=readerSource->GetOutput(); readerSource->Update(); vtkXMLUnstructuredGridReader *readerTarget=vtkXMLUnstructuredGridReader::New(); readerTarget->SetFileName("target.vtu"); vtkUnstructuredGrid *vtk_target_mesh=readerTarget->GetOutput(); readerTarget->Update(); // Ok at this point we have our mesh in VTK format. // Go to wrap vtk_source_mesh and vtk_target_mesh. VTKNormalizedUnstructuredMesh<2> wrap_source_mesh(vtk_source_mesh); VTKNormalizedUnstructuredMesh<2> wrap_target_mesh(vtk_target_mesh); // Go for interpolation... INTERP_KERNEL::Interpolation2D myInterpolator; //optionnal call to parametrize your interpolation. First precision, tracelevel, intersector wanted. myInterpolator.setOptions(1e-7,0,Geometric2D); INTERP_KERNEL::Matrix<double,ALL_C_MODE> resultMatrix; myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0"); //Ok let's multiply resultMatrix by source field to interpolate to target field. resultMatrix.multiply(...) //clean-up readerSource->Delete(); readerTarget->Delete(); ...
At the basis of many CFD numerical schemes is the fact that physical quantities such as density, momentum per unit volume or energy per unit volume obey some balance laws that should be preserved at the discrete level on every cell. This property is critical for example to accurately capture shockwaves.
When interpolation is performed between a source mesh S and a target mesh T the aspect of overlapping is important. In fact if any cell of of S is fully overlapped by cells of T and inversely any cell of T is fully overlapped by cells of S the meshes S and T are said to be coincident and some general formulae in next sub section are simpler. As far as possible in the next sub sections the formulae for coincident and non-coincident meshes will be given.
For fields with polynomial representation on each cell, the components of the discretized field
on the source side can be expressed as linear combinations of the components of the discretized field
on the target side, in terms of a matrix-vector product :
The objectives of interpolators is to compute the matrix W depending on their physical properties (intensive or extensive field) and their mesh discretisation (P0, P1,...).
It is often desired that the process interpolation preserve the integral of
on any domain. At the discrete level, for any target cell
, the following general interpolation equation has to be always verified :
This equation is used to compute
, based on the fields representation ( P0, P1, P1d etc..) and the geometry of source and target mesh cells. :
We assume that the field is represented by a vector with a discrete value on each cell. This value can represent either
In the general interpolation equation the left hand side becomes :
Here Vol represents the volume when the mesh dimension is equal to 3, the area when mesh dimension is equal to 2, and length when mesh dimension is equal to 1.
Note that
in case of perfect overlapping.
In the general interpolation equation the right hand side becomes :
As the field values are constant on each cell, the coefficients of the linear remapping matrix
are given by the formula :
and in case of perfect overlapping :
In code coupling from neutronics to hydraulics, extensive field of power is exchanged and the total power should remain the same. The discrete values of the field represent the total power contained in the cell. Hence in the general interpolation equation the left hand side becomes :
while the right hand side is now :
Note
in case of perfect overlapping.
The coefficients of the linear remapping matrix
are then given by the formula :
and in case of perfect overlapping :