Salome HOME
Merge from V6_main 15/03/2013
[tools/medcoupling.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 (Note that the same API can be used with \ref medmem field instead of \ref medcoupling fields using  another remapper class \ref medmemremapper.)
32
33
34 \section InterpKerMidLevUsage Middle-level usage
35
36 This mode is the mode that needs the minimum of prerequisites
37 (algorithms and the datastructure you intend to use). On the other
38 hand it is needed to specify precisely nature of interpolator.
39
40 As consequence of the genericity of the interpolators,  they are usable only by
41 instanciating an underlying \ref InterpKerMeshType "mesh" and \ref  InterpKerMatrixType "matrix" data structure fulfilling some requirements. The two following
42 examples show how to use interpolator at this level.
43
44 - The simplest way to use the interpolator with \ref medcoupling datastruture is illustrated in the following example.
45
46 \code
47 ...
48 MEDCouplingUMesh *med_source_mesh=MEDLoader::ReadUMeshFromFile("source.med","Source_mesh",0);
49 MEDCouplingUMesh *med_target_mesh=MEDLoader::ReadUMeshFromFile("target.med","Target_mesh",0);
50 MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_source_mesh(med_source_mesh);
51 MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_target_mesh(med_target_mesh);
52 // Go for interpolation...
53 INTERP_KERNEL::Interpolation2D myInterpolator;
54 myInterpolator.setPrecision(1e-7);
55 myInterpolator.setIntersectionType(INTERP_KERNEL::Geometric2D);
56 std::vector<std::map<int,double> > resultMatrix;
57 INTERP_KERNEL::Matrix<double,ALL_C_MODE> resultMatrix2;
58 // here the interpolation is performed twice for this code to illustrate the possibility of storing data the interpolation matrix in 2 different data structures.
59 myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0");
60 myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix2,"P0P0");
61 //Ok resultMatrix and resultMatrix2 contain matrix now
62 ...
63 \endcode
64
65
66 - Same with VTK datastructure :
67
68 \code
69 ...
70 vtkXMLUnstructuredGridReader *readerSource=vtkXMLUnstructuredGridReader::New();
71 readerSource->SetFileName("source.vtu");
72 vtkUnstructuredGrid *vtk_source_mesh=readerSource->GetOutput();
73 readerSource->Update();
74 vtkXMLUnstructuredGridReader *readerTarget=vtkXMLUnstructuredGridReader::New();
75 readerTarget->SetFileName("target.vtu");
76 vtkUnstructuredGrid *vtk_target_mesh=readerTarget->GetOutput();
77 readerTarget->Update();
78 // Ok at this point we have our mesh in VTK format.
79 // Go to wrap vtk_source_mesh and vtk_target_mesh.
80 VTKNormalizedUnstructuredMesh<2> wrap_source_mesh(vtk_source_mesh);
81 VTKNormalizedUnstructuredMesh<2> wrap_target_mesh(vtk_target_mesh);
82 // Go for interpolation...
83 INTERP_KERNEL::Interpolation2D myInterpolator;
84 //optionnal call to parametrize your interpolation. First precision, tracelevel, intersector wanted.
85 myInterpolator.setOptions(1e-7,0,Geometric2D);
86 INTERP_KERNEL::Matrix<double,ALL_C_MODE> resultMatrix;
87 myInterpolator.interpolateMeshes(wrap_source_mesh,wrap_target_mesh,resultMatrix,"P0P0");
88 //Ok let's multiply resultMatrix by source field to interpolate to target field.
89 resultMatrix.multiply(...)
90 //clean-up
91 readerSource->Delete();
92 readerTarget->Delete();
93 ...
94 \endcode
95
96 */