From: ageay Date: Thu, 19 Jul 2012 12:47:47 +0000 (+0000) Subject: Doc #5 X-Git-Tag: V6_main_FINAL~574 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5ce24d839f5d971f3b54c33bfcd325e71d77df11;p=tools%2Fmedcoupling.git Doc #5 --- diff --git a/doc/doxygen/Doxyfile_med_user.in b/doc/doxygen/Doxyfile_med_user.in index f2fb7a42d..7c4a2f768 100644 --- a/doc/doxygen/Doxyfile_med_user.in +++ b/doc/doxygen/Doxyfile_med_user.in @@ -139,7 +139,8 @@ EXCLUDE = CVS EXCLUDE_PATTERNS = *~ EXAMPLE_PATH = @srcdir@/../../src/ParaMEDMEM \ @srcdir@/../../src/MEDCoupling/Test \ - @srcdir@/../../src//MEDCoupling_Swig \ + @srcdir@/../../src/MEDCoupling_Swig \ + @srcdir@/../../src/MEDLoader/Swig \ @srcdir@/../../doc/MEDMEM \ @srcdir@/../../src/MEDMEMBinTest \ @srcdir@/../../src/MEDMEM diff --git a/doc/doxygen/medloader.dox b/doc/doxygen/medloader.dox index 630c7b5f6..9b894b4ec 100644 --- a/doc/doxygen/medloader.dox +++ b/doc/doxygen/medloader.dox @@ -115,7 +115,7 @@ This specificity leads to a constraint during writing phase because some mesh op \section MEDLoaderCommonVoc Vocabulary used in MEDLoader -\subsection Relative mesh dimension +\subsection MEDLoaderCommonVocRelMeshDimMesh Relative mesh dimension in meshes As it has been seen \ref BasicMEDLoaderAPIGen "above", all big arrays in fields and meshes (execpted coordinates) are sorted by geometric type, without any awareness of the dimension. @@ -142,7 +142,7 @@ of the whole MED file dimension. It leads to the following **relative mesh dimen - MED_POLYHED -> **relative mesh dimension** = 0 - MED_TETRA4 -> **relative mesh dimension** = 0 -In \ref medloader **MEDLoader** all geometric information are then grouped relative dimension per relative dimension. It leads to the following geometric sorting of +In \ref medloader "MEDLoader" all geometric information are then grouped relative dimension per relative dimension. It leads to the following geometric sorting of MED file data structure of \a myMesh : - Level 0 @@ -155,7 +155,34 @@ MED file data structure of \a myMesh : - Level -3 - MED_POINT1 -The mesh dimension of \a myMesh is 3. The relative mesh dimension available are [0,-1,-3]. +The mesh dimension of \a myMesh is 3. The relative mesh dimensions available are 0, -1 and -3. + +\subsection MEDLoaderCommonVocRelMeshDimField Relative mesh dimension in fields + +As it has been seen previously in \ref MEDLoaderCommonVocRelMeshDimMesh "for meshes", the values of fields are sorted by levels too. + +The principle is the same than those explained for meshes. The only difference is in the fact that it is possible for fields on cell and fields on + +gauss points that mesh dimension of underlying mesh of a field is not always (but very often) equal to the dimension of geometric types on which this field is defined. + +So it is advised, to compare the non empty level of a field **and** of its underlying mesh before trying to request heavy data from a MED file. + +\subsection MEDLoaderCommonVocIterationOrder Iteration and order in MED file + +As seen \ref BasicMEDLoaderAPIGen "above", fields in MED file can be defined on different time steps. + +But there is a **major difference** with \ref medcoupling MEDCoupling concept in time steps. \ref medcoupling MEDCoupling is focused to the float value of time for interpolation reason. + +\ref medloader MEDLoader and MED file are focused on pair of integer to precise a specific time steps. + +This difference of point of view can be seen in the API where the order of returned parameters in python differs from MEDCouplingFieldDouble::getTime to MEDFileField1TS::getTime. + +In MED file and so in \ref medloader MEDLoader the time steps are identified by a pair of integers called : + +- iteration +- order + +Order refers to sub iteration id, that is by default set to -1 in case of non use. A physical time with float type is attached to this pair of integer. */ @@ -231,15 +258,11 @@ MED_POLYGON, MED_TRI3, MED_SEG2 and MED_SEG3 : The max dimension of cells is 2 (for MED_POLYGON and MED_TRI3). So if you want exclusively cells with type MED_POLYGON and MED_TRI3 you should use : -\code -MEDCouplingUMesh *m2D=MEDLoader::ReadUMeshFromFile("file1.med","MyMesh",0); -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_9 If you are interested in MED_SEG2 and MED_SEG3 you should use : -\code -MEDCouplingUMesh *m1D=MEDLoader::ReadUMeshFromFile("file1.med","MyMesh",-1); -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_10 The method MEDLoader::ReadUMeshDimFromFile could help you to have this mesh dimension. @@ -248,32 +271,23 @@ help you to have this mesh dimension. containing MED_POLYHEDRA, MED_TETRA4, MED_QUAD8, MED_TRI6, MED_SEG2 and MED_POINT1. In this case you will have : -\code -assert(3==MEDLoader::ReadUMeshDimFromFile("file2.med","Example2")); -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_8 To get 3D cells (MED_POLYHEDRA and MED_TETRA4) you should type : -\code -MEDCouplingUMesh *m3D=MEDLoader::ReadUMeshFromFile("file2.med","Example2",0); -\endcode + +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_7 To get 2D cells (MED_TRI6 and MED_QUAD8) you should type : -\code -MEDCouplingUMesh *m2D=MEDLoader::ReadUMeshFromFile("file2.med","Example2",-1); -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_4 To get 1D cells (MED_SEG2) you should type : -\code -MEDCouplingUMesh *m1D=MEDLoader::ReadUMeshFromFile("file2.med","Example2",-2); -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_5 And finally for 0D cells (MED_POINT1) you will write : -\code -MEDCouplingUMesh *m0D=MEDLoader::ReadUMeshFromFile("file2.med","Example2",-3); -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_6 To finish this subsection, it is important to know that MEDLoader takes into account of the cell numbers stored in a mesh of a med @@ -315,15 +329,11 @@ So to retrieve a field on 3D cell called "F1Cell" in example file \ref MEDLoaderExample2 "file2.med (seen in meshes section)" on a mesh "Example2" on time step defined by iteration number 2 and iteration 3 the request will be : -\code -MEDCouplingFieldDouble *f1Cell_3D=MEDLoader::ReadFieldCell("file2.med","Example2",0,"F1Cell",2,3); -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_12 To retrive the same field (same iteration) on 2D cells only the call will be : -\code -MEDCouplingFieldDouble *f1Cell_2D=MEDLoader::ReadFieldCell("file2.med","Example2",-1,"F1Cell",2,3); -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_13 \subsection MEDLoaderMEDFieldsRead Reading several field time steps at a time in MED files @@ -334,12 +344,7 @@ time a same mesh. This is typically recommanded to use the following code when you desire to load all time steps of a field on cell "myField" lying on same mesh "mesh1" in one shot : -\code - -std::vector > timeStepsIds=MEDLoader::GetCellFieldIterations("file4.med"); -std::vector fs=MEDLoader::ReadFieldsCellOnSameMesh("file4.med","mesh1",0,"myField",timeStepsIds); - -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_11 \section MEDLoaderWriteMain Writing a MED file with MEDLoader @@ -389,13 +394,7 @@ INTERP_KERNEL::Exception will be thrown. To write one mesh \b myMesh with name \b "myMeshName" in a MED file \b "wfile1.med" the following code should be typed : -\code - -MEDCouplingUMesh *myMesh=...; -myMesh->setName("myMeshName"); -MEDLoader::WriteUMesh("wFile1.med",myMesh,true); - -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_1 With the previous code, if "wFile1.med" file existed the file is crashed and will contain after the call only the content of myMesh @@ -403,13 +402,7 @@ instance. If you desire to append a mesh in "wFile1.med" you should type : -\code - -MEDCouplingUMesh *myMesh=...; -myMesh->setName("myMeshName"); -MEDLoader::WriteUMesh("wFile1.med",myMesh,false); - -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_2 With the previous code, if the "wFile1.med" had already a mesh called "myMeshName" an INTERP_KERNEL::Exception will be thrown. @@ -473,19 +466,7 @@ To write a serie of time steps in a "file3.med" file lying on the same unstructured mesh the typical code to write is the following : -\code - -MEDCouplingFieldDouble *f=...; -MEDLoader::WriteUMesh("file3.med",static_castf->getMesh(),true); -f->setTime(1.2,1,0); -//Writing first time step with iteration==1 and order==0 -MEDLoader::WriteFieldUsingAlreadyWrittenMesh("file3.med",f); -f->setTime(1.3,2,0); -f->applyFunc("sqrt(x)"); -//Writing second time step with iteration==2 and order==0 -MEDLoader::WriteFieldUsingAlreadyWrittenMesh("file3.med",f); - -\endcode +\snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_3 In the previous code, it is important to note that the values of pair (iteration,order) should be different between two calls to avoid that @@ -501,7 +482,7 @@ is not needed here. */ /*! -\page MEDLoaderAdvancedAPIPage Advanced %MEDLoader API. +\page MEDLoaderAdvancedAPIPage Advanced MEDLoader API. [TOC] @@ -514,13 +495,13 @@ In reading mode, the user can scan entirely and directly the content of its MED Inversely, in writing mode, the user can describe its data in the same way that MED file does. -\section AdvMEDLoaderBasics Some of basic parameters appearing in advanced API +\section AdvMEDLoaderBasics Some of basics of advanced API - Like basic %MEDLoader API there is a notion of \c meshDimRelToMax. Each time This parameter appears in API, it will have the semantic explain here. The value of the parameter \c meshDimRelToMax is at most in {0,-1,-2,-3}. This relative value specifies a level -relative to value returned by \c myMedMesh->getMeshDimension(). +relative to value returned by ParaMEDMEM::MEDFileMesh::getMeshDimension(). A mesh containing MED_TETRA4, MED_TRI3, MED_QUAD4 and MED_POINT1 has a meshDimension equal to 3. For \c meshDimRelToMax equal to 0 the user will @@ -529,7 +510,7 @@ say here MED_TETRA4. For \c meshDimRelToMax equal to -1 the user will deal with cells witch dimension equal to 3-1 that is to say MED_TRI3 and MED_QUAD4. -An important method is \c getNonEmptyLevels() method. It returns all +An important method is ParaMEDMEM::MEDFileUMesh::getNonEmptyLevels() method. It returns all non empty levels available. In the previous example, this method will return {0,-1,-3}. -2 does not appear because no cells with dimension equal to 1 (3-2) appear in MED file mesh (no MED_SEG2 not MED_SEG3). @@ -580,7 +561,7 @@ parameter. \b The \b parameter \b renum \b should \b be \b set \b with existed previously the content is overwritten by the content of the current instance, that can lead to a file corruption. -\section AdvMEDLoaderAPIReading Reading from a file with advanced API. +\section AdvMEDLoaderAPIMeshesRW Dealing with Meshes with advanced API. Contrary to the basic %MEDLoader API, here after reading process, the user has to deal with a new instance of class that fits the MED file model. @@ -749,5 +730,107 @@ mm->write(2); \endcode +\section AdvMEDLoaderAPIFieldRW Dealing with Fields with advanced API. + +In advanced API fields have been developed using divide and conquer pattern to reproduce with the maximal fidelity the MED file field concept \ref BasicMEDLoaderAPIGen "seen here". + +Here the list of classes in %MEDLoader advanced API top down sorted : + +- Level 0 : ParaMEDMEM::MEDFileFields +- Level -1 : ParaMEDMEM::MEDFileFieldMultiTSWithoutDAS +- Level -2 : ParaMEDMEM::MEDFileField1TSWithoutDAS +- Level -3 : ParaMEDMEM::MEDFileFieldPerMesh (present only for backward compatibility MED file 2.2) +- Level -4 : ParaMEDMEM::MEDFileFieldPerMeshPerType +- Level -5 : ParaMEDMEM::MEDFileFieldPerMeshPerTypePerDisc + + +In each level in tree of the the cyan box of field is represented by a class. The only difference is that values are grouped in a single big array located +in level -2 (ParaMEDMEM::MEDFileField1TSWithoutDAS) in which each leaves (level -5) of MED file field +point to using a range [\a start, \a end). + +As different time steps of a same field and different field inside a MED file can shared or not profiles (yellow box) and Locatization (red box) a manipulable field classes instance +(ParaMEDMEM::MEDFileField1TS and ParaMEDMEM::MEDFileFieldMultiTS) in advanced API are the result of a subclass of a data class +(respectively ParaMEDMEM::MEDFileField1TSWithoutDAS, ParaMEDMEM::MEDFileFieldMultiTSWithoutDAS) and a instance of ParaMEDMEM::MEDFileFieldGlobsReal representing the shared data arrays (DAS) +at a specified scope inside the MED file. + +\subsection AdvMEDLoaderAPIFieldR Reading a field + +\subsubsection AdvMEDLoaderAPIFieldRC Reading a field defined on all entity + +Fields defined on all entity are the most used and common fields in MED file world. + +In this mode the user do **not** want to retrieve the entity ids of the constituting subsupport of the whole mesh because it has no sense. + +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 +by \a iteration and \a order. + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_1 + +To read it there are 3 main approaches : + +- Use ParaMEDMEM::MEDFileField1TS class : + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_3 + +- Use ParaMEDMEM::MEDFileFieldMultiTS class : + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_4 + +- Use iteration ParaMEDMEM::MEDFileFieldMultiTS class : + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_5 + +\subsubsection AdvMEDLoaderAPIFieldRP Reading a partial field + +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 +by \a iteration and \a order. + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_1 + +Fields defined partially on a meshes can been read using 2 main approaches : + +- Either the user wants to retreave it's field in %MEDCoupling sense, that is to say for interpolation, to evaluate such field on different points... +\n In this mode the link with the whole mesh is not useful for the user + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_3 + +- 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. + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_4 + +\ref medcoupling "MEDCoupling" allows to make bridges between the approaches. For example \a pfl \ref ParaMEDMEM::DataArrayInt "DataArrayInt instance" retrieved directly +from the file in the second approach can be retrived starting from first approach. + +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 : + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_5 + +Inversely, it is possible to rebuild field obtained in first apprach starting from second approach : + +\snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_6 + +\subsection AdvMEDLoaderAPIFieldW Writing a field + +\subsubsection AdvMEDLoaderAPIFieldWC Writing a field defined on all entity + +Fields defined on all entity are the most used and common fields in MED file world. + +In this mode the user do **not** want to retrieve the entity ids of the constituting subsupport of the whole mesh because it has no sense. + +Let's write a cell 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 +by \a iteration and \a order. + +\snippet MEDLoaderExamplesTest.py PySnippetWriteFieldOnAllEntity1_2 + +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. +The mode of write is 0 to simply add to the file the field specific part. + +\subsubsection AdvMEDLoaderAPIFieldWP Writing a partial field + +\snippet MEDLoaderExamplesTest.py PySnippetWriteFieldPartial1_2 + +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. + + */ diff --git a/src/MEDLoader/Swig/CMakeLists.txt b/src/MEDLoader/Swig/CMakeLists.txt index 209465bc0..16da8eb57 100644 --- a/src/MEDLoader/Swig/CMakeLists.txt +++ b/src/MEDLoader/Swig/CMakeLists.txt @@ -56,4 +56,5 @@ INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${MED_salomescript_PYTHO ADD_TEST(MEDLoaderTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDLoaderTest.py) ADD_TEST(MEDLoaderTest2 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDLoaderTest2.py) ADD_TEST(MEDLoaderTest3 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDLoaderTest3.py) +ADD_TEST(MEDLoaderExamplesTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDLoaderExamplesTest.py) ADD_TEST(SauvLoaderTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/SauvLoaderTest.py) diff --git a/src/MEDLoader/Swig/MEDLoaderExamplesTest.py b/src/MEDLoader/Swig/MEDLoaderExamplesTest.py new file mode 100644 index 000000000..f9b265111 --- /dev/null +++ b/src/MEDLoader/Swig/MEDLoaderExamplesTest.py @@ -0,0 +1,249 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2012 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from MEDLoader import * +import unittest + +class MEDLoaderBasicsTest(unittest.TestCase): + def testExampleReadFieldOnAllEntity1(self): + from MEDLoaderDataForTest import MEDLoaderDataForTest +#! [PySnippetReadFieldOnAllEntity1_1] + fname="PyExamples1.med" + meshName="mesh" + fieldName="FieldOnAll" + iteration=3 + order=4 +#! [PySnippetReadFieldOnAllEntity1_1] +#! [PySnippetWriteFieldOnAllEntity1_2] + m=MEDLoaderDataForTest.build2DMesh_3() + m=m[:10] + m.setName(meshName) + f=m.getMeasureField(ON_CELLS) + f=f.buildNewTimeReprFromThis(ONE_TIME,False) + f.setTime(5.5,iteration,order) + f.setName(fieldName) + # MEDCoupling finished, MEDLoader advanced API specific part starting from here + mm=MEDFileUMesh.New() + mm.setMeshAtLevel(0,m) + ff=MEDFileField1TS.New() + ff.setFieldNoProfileSBT(f) + mm.write(fname,2) + ff.write(fname,0) +#! [PySnippetWriteFieldOnAllEntity1_2] +#! [PySnippetReadFieldOnAllEntity1_3] + medfileField1TS=MEDFileField1TS.New(fname,fieldName,iteration,order) + mm=MEDFileMesh.New(fname) + fread=medfileField1TS.getFieldOnMeshAtLevel(ON_CELLS,0,mm) + fread2=medfileField1TS.getFieldAtLevel(ON_CELLS,0) + self.assertTrue(fread.isEqual(f,1e-12,1e-12)) + self.assertTrue(fread2.isEqual(f,1e-12,1e-12)) +#! [PySnippetReadFieldOnAllEntity1_3] +#! [PySnippetReadFieldOnAllEntity1_4] + medfileFieldMTS=MEDFileFieldMultiTS.New(fname,fieldName) + mm=MEDFileMesh.New(fname) + fread=medfileFieldMTS.getFieldOnMeshAtLevel(ON_CELLS,iteration,order,0,mm) + fread2=medfileFieldMTS.getFieldAtLevel(ON_CELLS,iteration,order,0) + self.assertTrue(fread.isEqual(f,1e-12,1e-12)) + self.assertTrue(fread2.isEqual(f,1e-12,1e-12)) +#! [PySnippetReadFieldOnAllEntity1_4] +#! [PySnippetReadFieldOnAllEntity1_5] + medfileFieldMTS=MEDFileFieldMultiTS.New(fname,fieldName) + for medfileField1TS in medfileFieldMTS: + if medfileField1TS.getTime()[:2]==[iteration,order]: + fread=medfileField1TS.getFieldOnMeshAtLevel(ON_CELLS,0,mm) + fread2=medfileField1TS.getFieldAtLevel(ON_CELLS,0) + self.assertTrue(fread.isEqual(f,1e-12,1e-12)) + self.assertTrue(fread2.isEqual(f,1e-12,1e-12)) + pass + pass +#! [PySnippetReadFieldOnAllEntity1_5] + pass + + def testExampleReadFieldPartial1(self): + from MEDLoaderDataForTest import MEDLoaderDataForTest +#! [PySnippetReadFieldPartial1_1] + fname="PyExamples2.med" + meshName="mesh" + fieldName="FieldPartial" + iteration=3 + order=4 +#! [PySnippetReadFieldPartial1_1] +#! [PySnippetWriteFieldPartial1_2] + m=MEDLoaderDataForTest.build2DMesh_1() + m.sortCellsInMEDFileFrmt() + m.setName(meshName) + # end of generation of a mesh -> let's create a field on that mesh + f=m.getMeasureField(ON_CELLS) + f=f.buildNewTimeReprFromThis(ONE_TIME,False) + f.setTime(5.5,iteration,order) + f.setName(fieldName) + # The MEDCoupling part is finished -> let's perform advanced API + mm=MEDFileUMesh.New() + mm.setMeshAtLevel(0,m) # the MED file data structure is ready for writing. Of course mm could have been more complicated with groups, families, multilevel + # Let's building a sub field + pfl=DataArrayInt.New([1,3,4,5]) + pfl.setName("myPfl") # here it is necessary to give a name to be compliant with MED file + f=f[pfl] ; f.getMesh().setName(m.getName()) # of course f should be in coherence with pfl -> f[pfl] + # + ff=MEDFileField1TS.New() + tmp=f.getMesh() # useless line, only to show that mesh into f is not considered by MEDFileField1TS.setFieldProfile + f.setMesh(None) # useless line, only to show that mesh into f is not considered by MEDFileField1TS.setFieldProfile + ff.setFieldProfile(f,mm,0,pfl) + f.setMesh(tmp) # useless line, only to show that mesh into f is not considered by MEDFileField1TS.setFieldProfile + mm.write(fname,2) + ff.write(fname,0) +#! [PySnippetWriteFieldPartial1_2] +#! [PySnippetReadFieldPartial1_3] + mm=MEDFileMesh.New(fname) + medfileField1TS=MEDFileField1TS.New(fname,fieldName,iteration,order) + fread=medfileField1TS.getFieldOnMeshAtLevel(ON_CELLS,0,mm) + fread2=medfileField1TS.getFieldAtLevel(ON_CELLS,0) + self.assertTrue(fread.isEqual(f,1e-12,1e-12)) + self.assertTrue(fread2.isEqual(f,1e-12,1e-12)) +#! [PySnippetReadFieldPartial1_3] +#! [PySnippetReadFieldPartial1_4] + medfileField1TS=MEDFileField1TS.New(fname,fieldName,iteration,order) + mm=MEDFileMesh.New(fname) + valsRead,pflRead=medfileField1TS.getFieldWithProfile(ON_CELLS,0,mm) + self.assertEqual(valsRead.getName(),f.getName()) + valsRead.setName("") + self.assertTrue(valsRead.isEqual(f.getArray(),1e-12)) + pflRead.setName(pfl.getName()) + self.assertTrue(pflRead.isEqual(pfl)) +#! [PySnippetReadFieldPartial1_4] +#! [PySnippetReadFieldPartial1_5] + firstApproachMesh=fread.getMesh() + mm=MEDFileMesh.New(fname) + wholeMesh=mm.getMeshAtLevel(0) + wholeMesh.tryToShareSameCoords(firstApproachMesh,1e-12) + isIncluded,pflComputed=wholeMesh.areCellsIncludedIn(firstApproachMesh,2) + self.assertTrue(isIncluded) + self.assertEqual(pflComputed.getName(),mm.getName()) + pflComputed.setName(pflRead.getName()) + self.assertTrue(pflComputed.isEqual(pflRead)) +#! [PySnippetReadFieldPartial1_5] +#! [PySnippetReadFieldPartial1_6] + mm=MEDFileMesh.New(fname) + wholeMesh=mm.getMeshAtLevel(0) + computedMesh=wholeMesh[pflRead] ; computedMesh.setName(mm.getName()) + self.assertTrue(computedMesh.isEqual(fread.getMesh(),1e-12)) + fieldFromSecondApproach=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) + fieldFromSecondApproach.setName(medfileField1TS.getName()) + fieldFromSecondApproach.setMesh(computedMesh) + fieldFromSecondApproach.setArray(valsRead) + fieldFromSecondApproach.setTime(medfileField1TS.getTime()[2],medfileField1TS.getTime()[0],medfileField1TS.getTime()[1]) + self.assertTrue(fieldFromSecondApproach.isEqual(fread,1e-12,1e-12)) +#! [PySnippetReadFieldPartial1_6] + pass + + def testExampleMeshAdvAPI1(self): + da=DataArrayDouble.New([0.,1.1,2.3,3.6]) + meshName="Example2" + cmesh=MEDCouplingCMesh.New() ; cmesh.setCoords(da,da,da) + myMesh=cmesh.buildUnstructured() +#! [PySnippetMeshAdvAPI1_1] + self.assertTrue(isinstance(myMesh,MEDCouplingUMesh)) + myMesh.setName(meshName) + MEDLoader.WriteUMesh("wFile1.med",myMesh,True) +#! [PySnippetMeshAdvAPI1_1] +#! [PySnippetMeshAdvAPI1_2] + self.assertTrue(isinstance(myMesh,MEDCouplingUMesh)) + myMesh.setName(meshName) + MEDLoader.WriteUMesh("wFile1.med",myMesh,True) +#! [PySnippetMeshAdvAPI1_2] + f=myMesh.getMeasureField(ON_CELLS) + f=f.buildNewTimeReprFromThis(ONE_TIME,False) + f.setName("myField") +#! [PySnippetMeshAdvAPI1_3] + MEDLoader.WriteUMesh("file3.med",f.getMesh(),True) + f.setTime(1.2,1,0) + fileNameMultiTimeStep="file3.med" + MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileNameMultiTimeStep,f) + f.setTime(1.3,2,0) + f.applyFunc("sqrt(x)"); + #Writing second time step with iteration==2 and order==0 + MEDLoader.WriteFieldUsingAlreadyWrittenMesh("file3.med",f); +#! [PySnippetMeshAdvAPI1_3] +#! [PySnippetMeshAdvAPI1_11] + timeStepsIds=MEDLoader.GetCellFieldIterations("file3.med","Example2","myField") + self.assertEqual([(1, 0),(2, 0)],timeStepsIds) + fs=MEDLoader.ReadFieldsOnSameMesh(ON_CELLS,"file3.med","Example2",0,"myField",timeStepsIds); +#! [PySnippetMeshAdvAPI1_11] + ### + myMesh0=myMesh[:] ; myMesh0.setName("Example2") + myMesh1=myMesh0.buildDescendingConnectivity()[0] ; myMesh1.setName(myMesh0.getName()) + myMesh2=myMesh1.buildDescendingConnectivity()[0] ; myMesh2.setName(myMesh0.getName()) + myMesh3=myMesh2.buildDescendingConnectivity()[0] ; myMesh3.setName(myMesh0.getName()) + mm=MEDFileUMesh.New() + mm.setMeshAtLevel(0,myMesh0) + mm.setMeshAtLevel(-1,myMesh1) + mm.setMeshAtLevel(-2,myMesh2) + mm.setMeshAtLevel(-3,myMesh3) + mm.write("file2.med",2) + F1Cell=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) + F1Cell.setMesh(myMesh0) + F1Cell.setArray(myMesh0.getCoords()[:myMesh0.getNumberOfCells()]) + F1Cell.setTime(1000.,2,3) + F1Cell.setName("F1Cell") + MEDLoader.WriteFieldUsingAlreadyWrittenMesh("file2.med",F1Cell) + F1Cell1=F1Cell.deepCpy() + F1Cell1.setMesh(myMesh1) + F1Cell1.setArray(myMesh1.getBarycenterAndOwner()) + MEDLoader.WriteFieldUsingAlreadyWrittenMesh("file2.med",F1Cell1) +#! [PySnippetMeshAdvAPI1_12] + f1Cell_3D=MEDLoader.ReadFieldCell("file2.med","Example2",0,"F1Cell",2,3) +#! [PySnippetMeshAdvAPI1_12] +#! [PySnippetMeshAdvAPI1_13] + f1Cell_2D=MEDLoader.ReadFieldCell("file2.med","Example2",-1,"F1Cell",2,3) +#! [PySnippetMeshAdvAPI1_13] + self.assertTrue(F1Cell.isEqual(f1Cell_3D,1e-12,1e-12)) +#! [PySnippetMeshAdvAPI1_8] + self.assertEqual(3,MEDLoader.ReadUMeshDimFromFile("file2.med","Example2")) +#! [PySnippetMeshAdvAPI1_8] +#! [PySnippetMeshAdvAPI1_7] + m2D=MEDLoader.ReadUMeshFromFile("file2.med","Example2",0) +#! [PySnippetMeshAdvAPI1_7] +#! [PySnippetMeshAdvAPI1_4] + m2D=MEDLoader.ReadUMeshFromFile("file2.med","Example2",-1) +#! [PySnippetMeshAdvAPI1_4] +#! [PySnippetMeshAdvAPI1_5] + m1D=MEDLoader.ReadUMeshFromFile("file2.med","Example2",-2) +#! [PySnippetMeshAdvAPI1_5] +#! [PySnippetMeshAdvAPI1_6] + m0D=MEDLoader.ReadUMeshFromFile("file2.med","Example2",-3) +#! [PySnippetMeshAdvAPI1_6] + for i in xrange(4): + mm.removeMeshAtLevel(-i) + pass + mm.setMeshAtLevel(0,myMesh1) + mm.setMeshAtLevel(-1,myMesh2) + mm.setName("MyMesh") + mm.write("file1.med",2) +#! [PySnippetMeshAdvAPI1_9] + m2D=MEDLoader.ReadUMeshFromFile("file1.med","MyMesh",0) +#! [PySnippetMeshAdvAPI1_9] +#! [PySnippetMeshAdvAPI1_10] + m1D=MEDLoader.ReadUMeshFromFile("file1.med","MyMesh",-1) +#! [PySnippetMeshAdvAPI1_10] + pass + + pass + +unittest.main()