Salome HOME
5f2cfcac48e9361f306048d92505d0dfba36da12
[modules/med.git] / doc / doxygen / remapper.dox
1
2 /*!
3 \page RemapperClasses The REMAPPER class.
4
5 \section InterpKerHighLevUsage High-level usage
6
7 The simplest way of using the \ref interptools in sequential mode is to use the class \c ParaMEDMEM::MEDCouplingRemapper . This class fulfills \c HXX2SALOME rules and may be used in YACS coupling graphs.
8
9 - If you intend to use \ref MEDCoupling data structure, ParaMEDMEM::MEDCouplingRemapper class should be used :
10
11 \code
12 ...
13 const char sourceFileName[]="source.med";
14 MEDCouplingFieldDouble *sourceField=MEDLoader::ReadFieldCell(sourceFileName,"Source_Mesh",0,"Density",/*iteration*/0,/*order*/0);
15 const char targetFileName[]="target.med";
16 MEDCouplingUMesh *med_target_mesh=MEDLoader::ReadUMeshFromFile(targetFileName,"Target_Mesh",0);
17 //
18 sourceField->setNature(ConservativeVolumic);//Specify which formula to use in case of non overlapping meshes
19 MEDCouplingRemapper remapper;
20 remapper.setPrecision(1e-12);
21 remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
22 remapper.prepare(sourceField->getMesh(),med_target_mesh,"P0P0");
23 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.
24 ...
25 // clean-up
26 targetField->decrRef();
27 sourceField->decrRef();
28 med_target_mesh->decrRef();
29 \endcode
30
31
32 \section InterpKerMidLevUsage Middle-level usage
33
34 This mode is the mode that needs the minimum of prerequisites
35 (algorithms and the datastructure you intend to use). On the other
36 hand it is needed to specify precisely nature of interpolator.
37
38 As consequence of the genericity of the interpolators,  they are usable only by
39 instanciating an underlying \ref InterpKerMeshType "mesh" and \ref  InterpKerMatrixType "matrix" data structure fulfilling some requirements. The two following
40 examples show how to use interpolator at this level.
41
42 - The simplest way to use the interpolator with \ref medcoupling datastruture is illustrated in the following example.
43
44 \code
45 ...
46 MEDCouplingUMesh *med_source_mesh=MEDLoader::ReadUMeshFromFile("source.med","Source_mesh",0);
47 MEDCouplingUMesh *med_target_mesh=MEDLoader::ReadUMeshFromFile("target.med","Target_mesh",0);
48 MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_source_mesh(med_source_mesh);
49 MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_target_mesh(med_target_mesh);
50 // Go for interpolation...
51 INTERP_KERNEL::Interpolation2D myInterpolator;
52 myInterpolator.setPrecision(1e-7);
53 myInterpolator.setIntersectionType(INTERP_KERNEL::Geometric2D);
54 std::vector<std::map<int,double> > resultMatrix;
55 INTERP_KERNEL::Matrix<double,ALL_C_MODE> resultMatrix2;
56 // here the interpolation is performed twice for this code to illustrate the possibility of storing data the interpolation matrix in 2 different data structures.
57 myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0");
58 myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix2,"P0P0");
59 //Ok resultMatrix and resultMatrix2 contain matrix now
60 ...
61 \endcode
62
63
64 - Same with VTK datastructure :
65
66 \code
67 ...
68 vtkXMLUnstructuredGridReader *readerSource=vtkXMLUnstructuredGridReader::New();
69 readerSource->SetFileName("source.vtu");
70 vtkUnstructuredGrid *vtk_source_mesh=readerSource->GetOutput();
71 readerSource->Update();
72 vtkXMLUnstructuredGridReader *readerTarget=vtkXMLUnstructuredGridReader::New();
73 readerTarget->SetFileName("target.vtu");
74 vtkUnstructuredGrid *vtk_target_mesh=readerTarget->GetOutput();
75 readerTarget->Update();
76 // Ok at this point we have our mesh in VTK format.
77 // Go to wrap vtk_source_mesh and vtk_target_mesh.
78 VTKNormalizedUnstructuredMesh<2> wrap_source_mesh(vtk_source_mesh);
79 VTKNormalizedUnstructuredMesh<2> wrap_target_mesh(vtk_target_mesh);
80 // Go for interpolation...
81 INTERP_KERNEL::Interpolation2D myInterpolator;
82 //optionnal call to parametrize your interpolation. First precision, tracelevel, intersector wanted.
83 myInterpolator.setOptions(1e-7,0,Geometric2D);
84 INTERP_KERNEL::Matrix<double,ALL_C_MODE> resultMatrix;
85 myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0");
86 //Ok let's multiply resultMatrix by source field to interpolate to target field.
87 resultMatrix.multiply(...)
88 //clean-up
89 readerSource->Delete();
90 readerTarget->Delete();
91 ...
92 \endcode
93
94 */