Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader9.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2022  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Anthony Geay
21
22 from medcoupling import *
23 from paraview.simple import *
24 from MEDReaderHelper import WriteInTmpDir,RetriveBaseLine
25
26 def GenerateCase():
27     """ This test is a non regression test. Test that ExtractGroup adapt to the current mesh of MEDReader. A MED file containing 2 fields on a 2 different meshes.
28     This test checks that the MeshName follows.
29     """
30     fname="testMEDReader9.med"
31     #########
32     m1=MEDCouplingUMesh("m1",2) ; m1.setCoords(DataArrayDouble([(0.,0.),(1.,0.),(0.,1.)])) ; m1.allocateCells() ; m1.insertNextCell(NORM_TRI3,[0,1,2])
33     m2=MEDCouplingUMesh("m2",2) ; m2.setCoords(DataArrayDouble([(0.,0.),(1.,0.),(0.,1.),(1.,1.)])) ; m2.allocateCells() ; m2.insertNextCell(NORM_QUAD4,[0,1,3,2])
34     mm1=MEDFileUMesh() ; mm2=MEDFileUMesh()
35     mm1.setMeshAtLevel(0,m1) ; mm2.setMeshAtLevel(0,m2)
36     ms=MEDFileMeshes() ; ms.pushMesh(mm1) ; ms.pushMesh(mm2)
37     f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName("f1") ; f1.setMesh(m1) ; f1.setArray(DataArrayDouble([1.111]))
38     f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setName("f2") ; f2.setMesh(m2) ; f2.setArray(DataArrayDouble([2.2222]))
39     ff1=MEDFileField1TS() ; ff2=MEDFileField1TS()
40     ff1.setFieldNoProfileSBT(f1) ; ff2.setFieldNoProfileSBT(f2)
41     ms.write(fname,2)
42     ff1.write(fname,0)
43     ff2.write(fname,0)
44     return fname
45
46 @WriteInTmpDir
47 def test():
48     fname = GenerateCase()
49     ################### MED write is done -> Go to MEDReader
50     myMedReader=MEDReader(FileName=fname)
51     myMedReader.AllArrays=['TS0/m1/ComSup0/f1@@][@@P0']
52     ExtractGroup1=ExtractGroup(Input=myMedReader)
53     ExtractGroup1.UpdatePipeline()
54     assert(ExtractGroup1.GetProperty("MeshName")[0]=="m1")
55     myMedReader.AllArrays=['TS0/m2/ComSup0/f2@@][@@P0']
56     ExtractGroup2=ExtractGroup(Input=myMedReader)
57     ExtractGroup2.UpdatePipeline()
58     assert(ExtractGroup2.GetProperty("MeshName")[0]=="m2")
59     
60 if __name__ == "__main__":
61     test()