1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2019 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)
25 from MEDLoader import *
27 """ This test reproduces precisely the bug EDF8655 (PAL 22677) by cheking that multi loc per geo type in a field is correctly managed.
30 fname="testMEDReader14.med"
31 outImgName="testMEDReader14.png"
33 arr0=DataArrayDouble(7) ; arr0.iota()
34 arr1=DataArrayDouble(5) ; arr1.iota()
36 c.setCoords(arr0,arr1)
37 m=c.build1SGTUnstructured()
38 pfl=DataArrayInt([5,10,11,16,17,23])
39 m0=m[pfl.buildComplement(24)]
40 m1=m[pfl] ; m1.simplexize(0)
41 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1.buildUnstructured(),m0.buildUnstructured())
43 m1=MEDCoupling1SGTUMesh(m.getName(),NORM_SEG2)
44 m1.setCoords(m.getCoords())
46 for i in [[28,21],[21,14],[14,7],[7,0]]:
50 m1.insertNextCell([i,i+1])
52 for i in [[6,13],[13,20],[20,27],[27,34]]:
55 for i in range(6,0,-1):
56 m1.insertNextCell([28+i,28+i-1])
60 mm.setMeshAtLevel(0,m)
61 mm.setMeshAtLevel(-1,m1)
64 pfl0=DataArrayInt([0,1,2,3]) ; pfl0.setName("PFL000")
65 pfl1=DataArrayInt([4,5,6,7,8,9]) ; pfl1.setName("PFL001")
66 pfl2=DataArrayInt([10,11,12,13]) ; pfl2.setName("PFL002")
67 pfl3=DataArrayInt([13,14,15,16,19,20,23,24,26,27,28,29]) ; pfl3.setName("PFL003")
72 fs0=MEDFileFieldMultiTS()
73 fs1=MEDFileFieldMultiTS()
74 fs2=MEDFileFieldMultiTS()
77 zePfl0=DataArrayInt.Aggregate(DataArrayInt.Range(0,12,1),pfl3,0) ; zePfl0.setName("PFL")
78 fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
80 fNode.setName(fieldName0) ; fNode.setMesh(tmp)
81 fNode.setGaussLocalizationOnCells(DataArrayInt.Range(0,12,1),[0.,0.,1.,0.,0.,1.],[0.1,0.1,0.8,0.1,0.1,0.8],3*[0.16666666666666666])
82 fNode.setGaussLocalizationOnCells(DataArrayInt.Range(12,24,1),[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[-0.577350,-0.577350,0.577350,-0.577350,0.577350,0.577350,-0.577350,0.577350],4*[1.])
83 arr=DataArrayDouble(2*(12*3+12*4)) ; arr.iota(0+1000*i) ; arr.rearrange(2)
84 fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) ; fNode.checkConsistencyLight()
85 fNode.setName(fieldName0)
86 f.setFieldProfile(fNode,mm,0,zePfl0)
88 zePfl1=DataArrayInt.Range(0,14,1) ; zePfl1.setName("PFL")
89 fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
92 fNode.setName(fieldName0) ; fNode.setMesh(tmp)
93 fNode.setGaussLocalizationOnCells(DataArrayInt.Range(0,4,1),[-1.,1.],[-0.33333333333333337,0.33333333333333337],[1.,1.])
94 fNode.setGaussLocalizationOnCells(DataArrayInt.Range(4,10,1),[-1.,1.],[-0.5,0.,0.5],[1.,1.,1.])
95 fNode.setGaussLocalizationOnCells(DataArrayInt.Range(10,14,1),[-1.,1.],[-0.6,-0.2,0.2,0.6],[1.,1.,1.,1.])
96 arr=DataArrayDouble(2*(4*2+6*3+4*4)) ; arr.iota(100+1000*i) ; arr.rearrange(2)
97 fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) ; fNode.checkConsistencyLight()
98 fNode.setName(fieldName0)
99 f.setFieldProfile(fNode,mm,-1,zePfl1)
100 fs0.pushBackTimeStep(f)
103 zePfl2=DataArrayInt.Range(10,20,1) ; zePfl2.setName("PFL2")
104 fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
106 fNode.setName(fieldName1) ; fNode.setMesh(tmp)
107 fNode.setGaussLocalizationOnCells(DataArrayInt.Range(0,4,1),[-1.,1.],[-0.6,-0.2,0.2,0.6],[1.,1.,1.,1.])
108 fNode.setGaussLocalizationOnCells(DataArrayInt.Range(4,10,1),[-1.,1.],[-0.6666666666666667,-0.33333333333333337,0.,0.33333333333333337,0.6666666666666667],[1.,1.,1.,1.,1.])
109 arr=DataArrayDouble(2*(4*4+6*5)) ; arr.iota(500+1000*i) ; arr.rearrange(2)
110 fNode.setArray(arr) ; arr.setInfoOnComponents(["C1 [m]","C2 [s^2]"]) ; fNode.checkConsistencyLight()
111 f.setFieldProfile(fNode,mm,-1,zePfl2)
112 fs1.pushBackTimeStep(f)
115 zePfl3=DataArrayInt([6,10,11,12,13,17,18,19,20,24,25,26,27,34]) ; zePfl3.setName("PFL3")
116 fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
117 fNode.setName(fieldName2)
118 arr=DataArrayDouble(2*14) ; arr.iota(700+1000*i) ; arr.rearrange(2)
119 fNode.setArray(arr) ; arr.setInfoOnComponents(["C3 [kg]","C4 [m^2]"])
120 f.setFieldProfile(fNode,mm,0,zePfl3)
121 fs2.pushBackTimeStep(f)
129 from paraview.simple import *
131 paraview.simple._DisableFirstRenderCameraReset()
132 reader=MEDReader(FileName=fname)
133 ExpectedEntries=['TS0/Mesh/ComSup0/zeField0_MM0@@][@@GAUSS', 'TS0/Mesh/ComSup1/zeField0_MM1@@][@@GAUSS', 'TS0/Mesh/ComSup2/zeField0_MM2@@][@@GAUSS', 'TS0/Mesh/ComSup2/zeField1_MM0@@][@@GAUSS', 'TS0/Mesh/ComSup3/zeField1_MM1@@][@@GAUSS', 'TS0/Mesh/ComSup4/zeField2@@][@@P1', 'TS1/Mesh/ComSup0/Mesh@@][@@P0']
134 assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries)
136 if '-D' not in sys.argv:
137 renderView1=GetActiveViewOrCreate('RenderView')
138 for entry in [[ExpectedEntries[0]],[ExpectedEntries[1]],[ExpectedEntries[2],ExpectedEntries[3]],[ExpectedEntries[4]]]:
139 reader=MEDReader(FileName=fname)
140 reader.AllArrays=entry
141 gaussPoints=ELGAfieldToPointGaussian(Input=reader)
142 gaussPoints.SelectSourceArray="ELGA@0"
143 Show(gaussPoints,renderView1)
148 readerNodeField=MEDReader(FileName=fname)
149 readerNodeField.AllArrays=[ExpectedEntries[5]]
150 nodeFieldDisplay=Show(readerNodeField,renderView1)
151 ColorBy(nodeFieldDisplay,('POINTS','zeField2'))
152 nodeFieldDisplay.RescaleTransferFunctionToDataRange(True)
153 zeField2LUT=GetColorTransferFunction('zeField2')
154 zeField2LUT.RGBPoints=[990.6568528002015, 0.231373, 0.298039, 0.752941, 1009.0416245953584, 0.865003, 0.865003, 0.865003, 1027.4263963905153, 0.705882, 0.0156863, 0.14902]
155 zeField2LUT.ScalarRangeInitialized=1.
157 renderView1.ResetCamera()
158 renderView1.InteractionMode = '2D'
159 renderView1.CameraPosition = [3.0, 2.0, 10000.0]
160 renderView1.CameraFocalPoint = [3.0, 2.0, 0.0]
161 renderView1.ViewSize =[300,300]
162 renderView1.GetRenderWindow().DoubleBufferOff()
167 # compare with baseline image
169 baselineIndex = sys.argv.index('-B')+1
170 baselinePath = sys.argv[baselineIndex]
172 print("Could not get baseline directory. Test failed.")
174 baseline_file = os.path.join(baselinePath, "testMEDReader14.png")
175 import vtk.test.Testing
176 from vtk.util.misc import vtkGetTempDir
177 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
178 vtk.test.Testing.compareImage(renderView1.GetRenderWindow(), baseline_file,
180 vtk.test.Testing.interact()