]> SALOME platform Git repositories - modules/paravis.git/blob - src/Plugins/MEDReader/Test/testMEDReader14.py
Salome HOME
Merge remote branch 'origin/V7_dev'
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader14.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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 MEDLoader import *
23
24 """ This test reproduces precisely the bug EDF8655 (PAL 22677) by cheking that multi loc per geo type in a field is correctly managed.
25 """
26
27 fname="testMEDReader14.med"
28 outImgName="testMEDReader14.png"
29
30 arr0=DataArrayDouble(7) ; arr0.iota()
31 arr1=DataArrayDouble(5) ; arr1.iota()
32 c=MEDCouplingCMesh()
33 c.setCoords(arr0,arr1)
34 m=c.build1SGTUnstructured()
35 pfl=DataArrayInt([5,10,11,16,17,23])
36 m0=m[pfl.buildComplement(24)]
37 m1=m[pfl] ; m1.simplexize(0)
38 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1.buildUnstructured(),m0.buildUnstructured())
39 m.setName("Mesh")
40 m1=MEDCoupling1SGTUMesh(m.getName(),NORM_SEG2)
41 m1.setCoords(m.getCoords())
42 m1.allocateCells()
43 for i in [[28,21],[21,14],[14,7],[7,0]]:
44     m1.insertNextCell(i)
45     pass
46 for i in xrange(6):
47     m1.insertNextCell([i,i+1])
48     pass
49 for i in [[6,13],[13,20],[20,27],[27,34]]:
50     m1.insertNextCell(i)
51     pass
52 for i in xrange(6,0,-1):
53     m1.insertNextCell([28+i,28+i-1])
54     pass
55 #
56 mm=MEDFileUMesh()
57 mm.setMeshAtLevel(0,m)
58 mm.setMeshAtLevel(-1,m1)
59 mm.write(fname,2)
60 #
61 pfl0=DataArrayInt([0,1,2,3]) ; pfl0.setName("PFL000")
62 pfl1=DataArrayInt([4,5,6,7,8,9]) ; pfl1.setName("PFL001")
63 pfl2=DataArrayInt([10,11,12,13]) ; pfl2.setName("PFL002")
64 pfl3=DataArrayInt([13,14,15,16,19,20,23,24,26,27,28,29]) ; pfl3.setName("PFL003")
65 #
66 fieldName0="zeField0"
67 fieldName1="zeField1"
68 fieldName2="zeField2"
69 fs0=MEDFileFieldMultiTS()
70 fs1=MEDFileFieldMultiTS()
71 fs2=MEDFileFieldMultiTS()
72 for i in xrange(5):
73     f=MEDFileField1TS()
74     zePfl0=DataArrayInt.Aggregate(DataArrayInt.Range(0,12,1),pfl3,0) ; zePfl0.setName("PFL")
75     fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
76     tmp=m[zePfl0]
77     fNode.setName(fieldName0) ; fNode.setMesh(tmp)
78     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])
79     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.])
80     arr=DataArrayDouble(2*(12*3+12*4)) ; arr.iota(0+1000*i) ; arr.rearrange(2)
81     fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) ; fNode.checkConsistencyLight()
82     fNode.setName(fieldName0)
83     f.setFieldProfile(fNode,mm,0,zePfl0)
84     #
85     zePfl1=DataArrayInt.Range(0,14,1) ; zePfl1.setName("PFL")
86     fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
87     tmp=m1[zePfl1]
88     #
89     fNode.setName(fieldName0) ; fNode.setMesh(tmp)
90     fNode.setGaussLocalizationOnCells(DataArrayInt.Range(0,4,1),[-1.,1.],[-0.33333333333333337,0.33333333333333337],[1.,1.])
91     fNode.setGaussLocalizationOnCells(DataArrayInt.Range(4,10,1),[-1.,1.],[-0.5,0.,0.5],[1.,1.,1.])
92     fNode.setGaussLocalizationOnCells(DataArrayInt.Range(10,14,1),[-1.,1.],[-0.6,-0.2,0.2,0.6],[1.,1.,1.,1.])
93     arr=DataArrayDouble(2*(4*2+6*3+4*4)) ; arr.iota(100+1000*i) ; arr.rearrange(2)
94     fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) ; fNode.checkConsistencyLight()
95     fNode.setName(fieldName0)
96     f.setFieldProfile(fNode,mm,-1,zePfl1)
97     fs0.pushBackTimeStep(f)
98     #
99     f=MEDFileField1TS()
100     zePfl2=DataArrayInt.Range(10,20,1) ; zePfl2.setName("PFL2")
101     fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
102     tmp=m1[zePfl2]
103     fNode.setName(fieldName1) ; fNode.setMesh(tmp)
104     fNode.setGaussLocalizationOnCells(DataArrayInt.Range(0,4,1),[-1.,1.],[-0.6,-0.2,0.2,0.6],[1.,1.,1.,1.])
105     fNode.setGaussLocalizationOnCells(DataArrayInt.Range(4,10,1),[-1.,1.],[-0.6666666666666667,-0.33333333333333337,0.,0.33333333333333337,0.6666666666666667],[1.,1.,1.,1.,1.])
106     arr=DataArrayDouble(2*(4*4+6*5)) ; arr.iota(500+1000*i) ; arr.rearrange(2)
107     fNode.setArray(arr) ; arr.setInfoOnComponents(["C1 [m]","C2 [s^2]"]) ; fNode.checkConsistencyLight()
108     f.setFieldProfile(fNode,mm,-1,zePfl2)
109     fs1.pushBackTimeStep(f)
110     #
111     f=MEDFileField1TS()
112     zePfl3=DataArrayInt([6,10,11,12,13,17,18,19,20,24,25,26,27,34]) ; zePfl3.setName("PFL3")
113     fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
114     fNode.setName(fieldName2)
115     arr=DataArrayDouble(2*14) ; arr.iota(700+1000*i) ; arr.rearrange(2)
116     fNode.setArray(arr) ; arr.setInfoOnComponents(["C3 [kg]","C4 [m^2]"])
117     f.setFieldProfile(fNode,mm,0,zePfl3)
118     fs2.pushBackTimeStep(f)
119     pass
120 fs0.write(fname,0)
121 fs1.write(fname,0)
122 fs2.write(fname,0)
123
124 #
125
126 from paraview.simple import *
127
128 paraview.simple._DisableFirstRenderCameraReset()
129 reader=MEDReader(FileName=fname)
130 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']
131 assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries)
132 renderView1=GetActiveViewOrCreate('RenderView')
133 for entry in [[ExpectedEntries[0]],[ExpectedEntries[1]],[ExpectedEntries[2],ExpectedEntries[3]],[ExpectedEntries[4]]]:
134     reader=MEDReader(FileName=fname)
135     reader.AllArrays=entry
136     gaussPoints=GaussPoints(Input=reader)
137     gaussPoints.SelectSourceArray="ELGA@0"
138     Show(gaussPoints,renderView1)
139     pass
140
141 #
142
143 readerNodeField=MEDReader(FileName=fname)
144 readerNodeField.AllArrays=[ExpectedEntries[5]]
145 nodeFieldDisplay=Show(readerNodeField,renderView1)
146 ColorBy(nodeFieldDisplay,('POINTS','zeField2'))
147 nodeFieldDisplay.RescaleTransferFunctionToDataRange(True)
148 zeField2LUT=GetColorTransferFunction('zeField2')
149 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]
150 zeField2LUT.ScalarRangeInitialized=1.
151 #
152 renderView1.ResetCamera()
153 renderView1.InteractionMode = '2D'
154 renderView1.CameraPosition = [3.0, 2.0, 10000.0]
155 renderView1.CameraFocalPoint = [3.0, 2.0, 0.0]
156 renderView1.ViewSize =[300,300]
157 renderView1.GetRenderWindow().DoubleBufferOff()
158 #
159
160 Render()
161
162 # compare with baseline image
163 import os
164 import sys
165 try:
166   baselineIndex = sys.argv.index('-B')+1
167   baselinePath = sys.argv[baselineIndex]
168 except:
169   print "Could not get baseline directory. Test failed."
170   exit(1)
171 baseline_file = os.path.join(baselinePath, "testMEDReader14.png")
172 import vtk.test.Testing
173 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
174 vtk.test.Testing.compareImage(renderView1.GetRenderWindow(), baseline_file,
175                                                             threshold=25)
176 vtk.test.Testing.interact()