2 \section ExamplesOther Other
4 \subsection ExamplesOtherInputOutput Input/Output
6 \subsubsection cpp_mcfielddouble_WriteVTK Writing fields in a VTK file
9 - create an 2D mesh and 3 fields on it,
11 \ref ParaMEDMEM::MEDCouplingFieldDouble::WriteVTK "WriteVTK()"
12 to write all the fields and the mesh to a VTK file.
14 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingFieldDouble_WriteVTK_1
17 \anchor BEGIN_PYTHON_ONLY
18 \subsubsection MEDLoaderExample2 Loading a mesh using basic API
20 Consider a mesh called "Example2" in file "file2.med"
21 containing MED_POLYHEDRA, MED_TETRA4, MED_QUAD8, MED_TRI6, MED_SEG2
22 and MED_POINT1. In this case you will have :
24 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_8
26 To get 3D cells (MED_POLYHEDRA and MED_TETRA4) you should type :
28 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_7
30 To get 2D cells (MED_TRI6 and MED_QUAD8) you should type :
32 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_4
34 To get 1D cells (MED_SEG2) you should type :
36 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_5
38 And finally for 0D cells (MED_POINT1) you will write :
40 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_6
42 \anchor END_PYTHON_ONLY
45 \anchor BEGIN_PYTHON_ONLY
46 \subsubsection py_mcumesh_writefile_onemesh_basic Writing one mesh using basic API
48 To write one mesh \b myMesh with name \b "myMeshName" in a MED file \b "wfile1.med" the following code should be typed :
50 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_1
52 With the previous code, if "wFile1.med" file exists the file is
53 crashed and will contain after the call only the contents of myMesh
56 If you want to append a mesh in "wFile1.med" you should type :
58 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_2
60 With the previous code, if the "wFile1.med" has already a mesh called "myMeshName" an
61 INTERP_KERNEL::Exception will be thrown.
62 \anchor END_PYTHON_ONLY
65 \anchor BEGIN_CPP_ONLY
66 \subsubsection cpp_mcumesh_loadfile Loading a mesh using advanced API
70 const char fileName[]=...;
71 const char meshName[]=...;
72 MEDFileUMesh *medmesh=MEDFileUMesh::New(fileName,meshName);
73 std::vector<int> nel=medmesh->getNonEmptyLevels();
75 throw INTERP_KERNEL::Exception("The test is not good for my file ! Expecting a multi level mesh to play with !");
76 MEDCouplingUMesh *m0=medmesh->getMeshAtLevel(nel[1],false);
77 MEDCouplingUMesh *g1=medmesh->getGroup(nel[1],"mesh2",false);
78 DataArrayInt *dag1=medmesh->getGroupArr(nel[1],"mesh2",false);
79 MEDCouplingUMesh *g1bis=m0->buildPartOfMySelf(dag1->getConstPointer(),dag1->getConstPointer()+dag1->getNbOfElems());
80 g1bis->setName(dag1->getName());
81 if(!g1->isEqual(g1bis,1e-12))
82 throw INTERP_KERNEL::Exception("hmmmm :g1 and g1bis should be equal...");
92 \anchor BEGIN_CPP_ONLY
93 \subsubsection cpp_mcumesh_writefile Writing a mesh using advanced API
97 MEDCouplingUMesh *m=...; //m is a mesh with meshDim=2 spaceDim=2
98 MEDCouplingUMesh *m1=...; //m1 is a mesh with meshDim=1 spaceDim=2 same coords than m
99 MEDCouplingUMesh *m2=...; //m2 is a mesh with meshDim=0 spaceDim=2 same coords than m
100 MEDFileUMesh *mm=MEDFileUMesh::New();
101 mm->setName("mm");//name needed to be non empty
102 mm->setDescription("Description mm");
103 mm->setCoords(m1->getCoords());
104 mm->setMeshAtLevel(-1,m1,false);
105 mm->setMeshAtLevel(0,m,false);
106 mm->setMeshAtLevel(-2,m2,false);
107 DataArrayInt *g1=DataArrayInt::New();
110 const int val1[2]={1,3};
111 std::copy(val1,val1+2,g1->getPointer());
112 DataArrayInt *g2=DataArrayInt::New();
115 const int val2[3]={1,2,3};
116 std::copy(val2,val2+3,g2->getPointer());
118 std::vector<const DataArrayInt *> grps(2);
119 grps[0]=g1; grps[1]=g2;
120 mm->setGroupsAtLevel(0,grps,false);
131 \anchor BEGIN_PYTHON_ONLY
132 \subsubsection py_mcfield_loadfile_onetimestep_basic Reading a field at one time step using basic API
133 So to retrieve a field on 3D cell called "F1Cell" in example file
134 "file2.med" on a mesh "Example2" (\ref MEDLoaderExample2 "as defined here") on time
135 step defined by iteration number 2 and iteration 3 the request will be :
137 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_12
139 To retrieve the same field (same iteration) on 2D cells only the call will be :
141 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_13
142 \anchor END_PYTHON_ONLY
145 \anchor BEGIN_PYTHON_ONLY
146 \subsubsection py_mcfield_loadfile_alltimesteps_basic Reading a field at all time steps using basic API
148 It is typically recommended to use the following
149 code when you want to load all time steps of a field on cell "myField" lying on
150 same mesh "mesh1" in one shot :
152 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_11
154 \anchor END_PYTHON_ONLY
158 \anchor BEGIN_PYTHON_ONLY
159 \subsubsection py_mcfield_loadfile_allentities Reading a field on all entities using advanced API
161 Let's read a field on all entity called \a fieldName lying on a mesh called \a meshName in a MED file called \a fname at a iteration defined on time step defined
162 by \a iteration and \a order.
164 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_1
166 To read it there are 3 main approaches :
168 - Use ParaMEDMEM::MEDFileField1TS class :
170 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_3
172 - Use ParaMEDMEM::MEDFileFieldMultiTS class :
174 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_4
176 - Use iteration ParaMEDMEM::MEDFileFieldMultiTS class :
178 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_5
180 \anchor END_PYTHON_ONLY
184 \anchor BEGIN_PYTHON_ONLY
185 \subsubsection py_mcfield_loadfile_partial Reading a partial field using advanced API
187 Let's read a partial field called \a fieldName lying on a mesh called \a meshName in a MED file called \a fname at a iteration defined on time step defined
188 by \a iteration and \a order.
190 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_1
192 Fields defined partially on a meshes can been read using 2 main approaches :
194 - Either the user wants to retrieve it's field in %MEDCoupling sense, that is to say for interpolation, to evaluate such field on different points...
195 \n In this mode the link with the whole mesh is not useful for the user
197 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_3
199 - Or the user wants to retrieve the binding (cell ids or node ids) with the whole mesh on which the partial field lies partially on.
201 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_4
203 \ref medcoupling "MEDCoupling" allows to make bridges between the approaches. For example \a pfl \ref ParaMEDMEM::DataArrayInt "DataArrayInt instance" retrieved directly
204 from the file in the second approach can be retrieved starting from first approach.
206 Starting from mesh \a firstApproachMesh of read field in first approach \a fread, whith the whole mesh \a wholeMesh the profile \a pflComputed can be computed :
208 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_5
210 Inversely, it is possible to rebuild field obtained in first approach starting from second approach :
212 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_6
214 \anchor END_PYTHON_ONLY
217 \anchor BEGIN_PYTHON_ONLY
218 \subsubsection py_mcfield_writefile_severaltimesteps_basic Writing several time steps of a field using basic API
220 To write a serie of time steps in a "file3.med" file lying on the same
221 unstructured mesh the typical code
222 to write is the following :
224 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_3
226 In the above code, it is important to note that the values of pairs
227 (iteration,order) should be different between two calls to avoid that
228 a call to MEDLoader::WriteFieldUsingAlreadyWrittenMesh overwrites a
230 Another important thing is the fact that \c f.getMesh() is not modified.
231 This write method presents the big advantage to be fast, because
232 neither check nor read is performed. That's why the parameter of \b writeFromScratch
233 is not needed here, contrary
234 to other MEDLoader::Write* methods.
236 \anchor END_PYTHON_ONLY
239 \anchor BEGIN_PYTHON_ONLY
240 \subsubsection py_mcfield_writefile_allentities Writing a field defined on all entities using advanced API
242 Let's write a cell field on all entities called \a fieldName lying on a mesh called \a meshName in a MED file called \a fname at a iteration defined on time step defined
243 by \a iteration and \a order.
245 \snippet MEDLoaderExamplesTest.py PySnippetWriteFieldOnAllEntity1_2
247 We can see here that the necessity to deal with both mesh and field to write a field is exposed by the API. The mesh write mode is 2 to tell to MED file that is file already exists to scratch it.
248 The mode of write is 0 to simply add to the file the field specific part.
250 \anchor END_PYTHON_ONLY
253 \anchor BEGIN_PYTHON_ONLY
254 \subsubsection py_mcfield_writefile_partial Writing a partial field using advanced API
256 \snippet MEDLoaderExamplesTest.py PySnippetWriteFieldPartial1_2
258 To write a partial field \a f can have a **null mesh**, because the link with mesh is made given the entry of \a mm MEDFileField1TS::setFieldProfile method.
260 \anchor END_PYTHON_ONLY