1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Anthony Geay (EDF R&D)
22 from MEDLoader import *
24 """ This test is a non regression test of EDF8662 : This bug revealed that ELNOfieldToSurface and ELNOfieldToPointGaussian do not behave correctly after the call of ExtractGroup"""
26 fname="testMEDReader16.med"
28 arr=DataArrayDouble([0,1,2])
29 m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured() ; m.setName("Mesh")
30 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
31 grp0=DataArrayInt([0,1]) ; grp0.setName("grp0")
32 grp1=DataArrayInt([2,3]) ; grp1.setName("grp1")
33 grp2=DataArrayInt([1,2]) ; grp2.setName("grp2")
34 grp3=DataArrayInt([0,1,2,3]) ; grp3.setName("grp3")
35 mm.setGroupsAtLevel(0,[grp0,grp1,grp2,grp3])
36 f=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f.setMesh(m) ; f.setName("MyField") ; f.setTime(0.,0,0)
37 arr2=DataArrayDouble(4*4*2) ; arr2.iota() ; arr2.rearrange(2) ; arr2.setInfoOnComponents(["aa","bbb"])
38 f.setArray(arr2) ; arr2+=0.1 ; f.checkConsistencyLight()
40 WriteFieldUsingAlreadyWrittenMesh(fname,f)
42 from paraview.simple import *
43 from paraview import servermanager
45 paraview.simple._DisableFirstRenderCameraReset()
46 reader=MEDReader(FileName=fname)
47 ExpectedEntries=['TS0/Mesh/ComSup0/MyField@@][@@GSSNE','TS1/Mesh/ComSup0/Mesh@@][@@P0']
48 assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries)
49 reader.AllArrays=['TS0/Mesh/ComSup0/MyField@@][@@GSSNE']
50 ExtractGroup1 = ExtractGroup(Input=reader)
51 ExtractGroup1.UpdatePipelineInformation()
52 ExtractGroup1.AllGroups=["GRP_grp1"]
53 ELNOfieldToSurface1=ELNOfieldToSurface(Input=ExtractGroup1)
54 ELNOfieldToPointGaussian1=ELNOfieldToPointGaussian(Input=ExtractGroup1)
55 ELNOfieldToPointGaussian1.SelectSourceArray=['ELNO@MyField']
56 for elt in [ELNOfieldToSurface1,ELNOfieldToPointGaussian1]:
57 elnoMesh=servermanager.Fetch(ELNOfieldToPointGaussian1,0)
58 vtkArrToTest=elnoMesh.GetBlock(0).GetPointData().GetArray("MyField")
59 assert(vtkArrToTest.GetNumberOfTuples()==8)
60 assert(vtkArrToTest.GetNumberOfComponents()==2)
61 assert(vtkArrToTest.GetComponentName(0)==arr2.getInfoOnComponent(0))
62 assert(vtkArrToTest.GetComponentName(1)==arr2.getInfoOnComponent(1))
63 vals=[vtkArrToTest.GetValue(i) for i in range(16)]
64 assert(arr2[8:].isEqualWithoutConsideringStr(DataArrayDouble(vals,8,2),1e-12))
67 ExtractGroup1.AllGroups=["GRP_grp2"]
68 for elt in [ELNOfieldToSurface1,ELNOfieldToPointGaussian1]:
69 elnoMesh=servermanager.Fetch(ELNOfieldToSurface1)
70 vtkArrToTest=elnoMesh.GetBlock(0).GetPointData().GetArray("MyField")
71 assert(vtkArrToTest.GetNumberOfTuples()==8)
72 assert(vtkArrToTest.GetNumberOfComponents()==2)
73 assert(vtkArrToTest.GetComponentName(0)==arr2.getInfoOnComponent(0))
74 assert(vtkArrToTest.GetComponentName(1)==arr2.getInfoOnComponent(1))
75 vals=[vtkArrToTest.GetValue(i) for i in range(16)]
76 assert(arr2[4:12].isEqualWithoutConsideringStr(DataArrayDouble(vals,8,2),1e-12))
78 # important to check that if all the field is present that it is OK (check of the optimization)
79 ExtractGroup1.AllGroups=["GRP_grp3"]
80 for elt in [ELNOfieldToSurface1,ELNOfieldToPointGaussian1]:
81 elnoMesh=servermanager.Fetch(ELNOfieldToSurface1)
82 vtkArrToTest=elnoMesh.GetBlock(0).GetPointData().GetArray("MyField")
83 assert(vtkArrToTest.GetNumberOfTuples()==16)
84 assert(vtkArrToTest.GetNumberOfComponents()==2)
85 assert(vtkArrToTest.GetComponentName(0)==arr2.getInfoOnComponent(0))
86 assert(vtkArrToTest.GetComponentName(1)==arr2.getInfoOnComponent(1))
87 vals=[vtkArrToTest.GetValue(i) for i in range(32)]
88 assert(arr2.isEqualWithoutConsideringStr(DataArrayDouble(vals,16,2),1e-12))
90 ELNOfieldToSurface1=ELNOfieldToSurface(Input=reader)
91 ELNOfieldToPointGaussian1=ELNOfieldToPointGaussian(Input=reader)
92 ELNOfieldToPointGaussian1.SelectSourceArray=['ELNO@MyField']
93 for elt in [ELNOfieldToSurface1,ELNOfieldToPointGaussian1]:
94 elnoMesh=servermanager.Fetch(ELNOfieldToSurface1)
95 vtkArrToTest=elnoMesh.GetBlock(0).GetPointData().GetArray("MyField")
96 assert(vtkArrToTest.GetNumberOfTuples()==16)
97 assert(vtkArrToTest.GetNumberOfComponents()==2)
98 assert(vtkArrToTest.GetComponentName(0)==arr2.getInfoOnComponent(0))
99 assert(vtkArrToTest.GetComponentName(1)==arr2.getInfoOnComponent(1))
100 vals=[vtkArrToTest.GetValue(i) for i in range(32)]
101 assert(arr2.isEqualWithoutConsideringStr(DataArrayDouble(vals,16,2),1e-12))