Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader17.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 (EDF R&D)
21
22 from medcoupling import *
23 from paraview.simple import *
24 from paraview import servermanager
25 from MEDReaderHelper import WriteInTmpDir,RetriveBaseLine
26
27 paraview.simple._DisableFirstRenderCameraReset()
28
29 def GenerateCase():
30     """ This test is a non regression test of EDF9622."""
31
32     fname="testMEDReader17.med"
33
34     arr=DataArrayDouble([0,1,2])
35     m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured() ; m.setName("Mesh")
36     mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
37     grp0=DataArrayInt([0,1]) ; grp0.setName("grp0")
38     grp1=DataArrayInt([2,3]) ; grp1.setName("grp1")
39     grp2=DataArrayInt([1,2]) ; grp2.setName("grp2")
40     grp3=DataArrayInt([0,1,2,3]) ; grp3.setName("grp3")
41     mm.setGroupsAtLevel(0,[grp0,grp1,grp2,grp3])
42     f=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f.setMesh(m) ; f.setName("MyField") ; f.setTime(0.,0,0)
43     arr2=DataArrayDouble(4*4*2) ; arr2.iota() ; arr2.rearrange(2) ; arr2.setInfoOnComponents(["aa","bbb"])
44     f.setArray(arr2) ; arr2+=0.1 ; f.checkConsistencyLight()
45     mm.write(fname,2)
46     WriteFieldUsingAlreadyWrittenMesh(fname,f)
47     return fname
48
49 @WriteInTmpDir
50 def test():
51     fname = GenerateCase()
52     #
53     reader=MEDReader(FileName=fname)
54     ExpectedEntries=['TS0/Mesh/ComSup0/MyField@@][@@GSSNE','TS1/Mesh/ComSup0/Mesh@@][@@P0']
55     assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries)
56     reader.AllArrays=['TS0/Mesh/ComSup0/MyField@@][@@GSSNE']
57     ExtractGroup1 = ExtractGroup(Input=reader)
58     #ExtractGroup1.UpdatePipelineInformation()
59     ExtractGroup1.AllGroups=["GRP_grp1"]
60     ELNOfieldToPointGaussian1=ELNOfieldToPointGaussian(Input=ExtractGroup1)
61     ELNOfieldToPointGaussian1.SelectSourceArray=['CELLS','ELNO@MyField']
62     #
63     ELNOfieldToPointGaussian1=ELNOfieldToPointGaussian(Input=reader)
64     ELNOfieldToPointGaussian1.SelectSourceArray=['CELLS','ELNO@MyField']
65     ExtractGroup1 = ExtractGroup(Input=ELNOfieldToPointGaussian1)
66     #ExtractGroup1.UpdatePipelineInformation()
67     ExtractGroup1.AllGroups=["GRP_grp1"]
68     #ExtractGroup1.UpdatePipeline()
69     res=servermanager.Fetch(ExtractGroup1,0)
70     assert(res.GetBlock(0).GetNumberOfCells()==8)
71     vtkArrToTest=res.GetBlock(0).GetPointData().GetArray("MyField")
72     assert(vtkArrToTest.GetNumberOfComponents()==2)
73     assert(vtkArrToTest.GetNumberOfTuples()==8)
74     vals=[vtkArrToTest.GetValue(i) for i in range(16)]
75     assert(DataArrayDouble([(16.1,17.1),(18.1,19.1),(20.1,21.1),(22.1,23.1),(24.1,25.1),(26.1,27.1),(28.1,29.1),(30.1,31.1)]).isEqual(DataArrayDouble(vals,8,2),1e-12))
76
77 if __name__ == "__main__":
78     test()