High-level usage
The simplest way of using the Interpolation tools in sequential mode is to use the class ParaMEDMEM::MEDCouplingRemapper
. This class fulfills HXX2SALOME
rules and may be used in YACS coupling graphs.
...
const char sourceFileName[]="source.med";
const char targetFileName[]="target.med";
MEDCouplingRemapper remapper;
remapper.setPrecision(1e-12);
remapper.prepare(sourceField->getMesh(),med_target_mesh,"P0P0");
MEDCouplingFieldDouble *targetField=remapper.transferField(sourceField,4.57);
...
targetField->decrRef();
sourceField->decrRef();
med_target_mesh->decrRef();
(Note that the same API can be used with MEDMEM library field instead of MEDCoupling fields using another remapper class MEDMEM::MEDMEM_REMAPPER.)
Middle-level usage
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 the genericity of the interpolators, they are usable only by instanciating an underlying mesh and matrix data structure fulfilling some requirements. The two following examples show how to use interpolator at this level.
- The simplest way to use the interpolator with MEDCoupling datastruture is illustrated in the following example.
...
MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_source_mesh(med_source_mesh);
MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_target_mesh(med_target_mesh);
myInterpolator.setPrecision(1e-7);
std::vector<std::map<int,double> > resultMatrix;
INTERP_KERNEL::Matrix<double,ALL_C_MODE> resultMatrix2;
myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0");
myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix2,"P0P0");
...
- Same with VTK datastructure :
...
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();
VTKNormalizedUnstructuredMesh<2> wrap_source_mesh(vtk_source_mesh);
VTKNormalizedUnstructuredMesh<2> wrap_target_mesh(vtk_target_mesh);
INTERP_KERNEL::Matrix<double,ALL_C_MODE> resultMatrix;
myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0");
resultMatrix.multiply(...)
readerSource->Delete();
readerTarget->Delete();
...