1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2022 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
25 from medcoupling import *
26 from paraview.simple import *
27 from MEDReaderHelper import WriteInTmpDir,RetriveBaseLine
29 outImgName="testMEDReader3.png"
32 """ This test checks that invalid double time (not in [-1e299:1e299])
33 leads MEDReader to takes iteration numbers instead of double time to discriminate timesteps each other
36 fname="testMEDReader3.med"
38 m=MEDCouplingUMesh("mesh",2)
39 coords=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(1.,1.,0.),(0.,1.,0.)],4,3)
42 m.insertNextCell(NORM_QUAD4,[0,3,2,1])
44 mm.setMeshAtLevel(0,m)
46 fmts=MEDFileFieldMultiTS()
48 f=MEDCouplingFieldDouble(ON_NODES) ; f.setName("ANodeField")
49 f.setTime(1.7976931348623157e+308,1,1) ; f.setMesh(m)
50 arr=DataArrayDouble([0.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
52 f1ts=MEDFileField1TS()
53 f1ts.setFieldNoProfileSBT(f)
54 fmts.pushBackTimeStep(f1ts)
56 f.setTime(1.7976931348623157e+308,2,2)
57 arr=DataArrayDouble([1.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
59 f1ts=MEDFileField1TS()
60 f1ts.setFieldNoProfileSBT(f)
61 fmts.pushBackTimeStep(f1ts)
63 f.setTime(1.7976931348623157e+308,3,3)
64 arr=DataArrayDouble([2.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
66 f1ts=MEDFileField1TS()
67 f1ts.setFieldNoProfileSBT(f)
68 fmts.pushBackTimeStep(f1ts)
70 f.setTime(1.7976931348623157e+308,4,6)
71 arr=DataArrayDouble([3.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
73 f1ts=MEDFileField1TS()
74 f1ts.setFieldNoProfileSBT(f)
75 fmts.pushBackTimeStep(f1ts)
77 f.setTime(1.7976931348623157e+308,5,7)
78 arr=DataArrayDouble([4.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
80 f1ts=MEDFileField1TS()
81 f1ts.setFieldNoProfileSBT(f)
82 fmts.pushBackTimeStep(f1ts)
88 def test(baseline_file):
89 fname = GenerateCase()
90 ################### MED write is done -> Go to MEDReader
91 AnimationScene1=GetAnimationScene()
92 AnimationScene1.PlayMode='Snap To TimeSteps'
93 AnimationScene1.EndTime = 2.0
94 AnimationScene1.AnimationTime = 1.0
95 AnimationScene1.StartTime = 1.0
97 testMEDReader3=MEDReader(FileName=fname)
98 testMEDReader3.AllArrays=['TS0/mesh/ComSup0/ANodeField@@][@@P1']
100 assert(list(testMEDReader3.TimestepValues)==[1.,2.,3.,4.,5.]) ## <- the test is here - double time steps are too big use dt.
102 if '-D' not in sys.argv:
103 RenderView1=GetRenderView()
104 RenderView1.ViewTime=3.0
105 RenderView1.CameraPosition=[0.5,0.5,5.7320508075688776]
106 RenderView1.ViewSize=[300,300]
108 DataRepresentation2=Show()
109 DataRepresentation2.EdgeColor=[0.0, 0.0, 0.5000076295109483]
110 DataRepresentation2.SelectionPointFieldDataArrayName='ANodeField'
111 DataRepresentation2.SelectionCellFieldDataArrayName='FamilyIdCell'
112 DataRepresentation2.ScalarOpacityUnitDistance=1.4142135623730951
113 #DataRepresentation2.ExtractedBlockIndex=1
114 DataRepresentation2.ScaleFactor=0.1
116 a1_ANodeField_PVLookupTable=GetLookupTableForArray("ANodeField",1,RGBPoints=[0.0,0.23,0.299,0.754,4.0,0.706,0.016,0.15],VectorMode='Magnitude',NanColor=[0.25,0.0,0.0],
117 ColorSpace='Diverging',ScalarRangeInitialized=1.0,AllowDuplicateScalars=1)
118 a1_ANodeField_PiecewiseFunction=CreatePiecewiseFunction(Points=[0.0,0.0,0.5,0.0,1.0,1.0,0.5,0.0])
119 a1_ANodeField_PVLookupTable.ScalarOpacityFunction=a1_ANodeField_PiecewiseFunction
121 DataRepresentation2.ScalarOpacityFunction=a1_ANodeField_PiecewiseFunction
122 DataRepresentation2.ColorArrayName='ANodeField'
123 DataRepresentation2.LookupTable=a1_ANodeField_PVLookupTable
125 # Triangulate so rendring always the same with different gpu or graphic backend.
126 extSurf = ExtractSurface(Input=testMEDReader3)
127 triangulate = Triangulate(Input=extSurf)
128 Hide(testMEDReader3, RenderView1)
129 Show(triangulate, RenderView1)
130 triangulate1Display = GetDisplayProperties(triangulate, view=RenderView1)
131 ColorBy(triangulate1Display, ('POINTS', 'ANodeField'))
136 # compare with baseline image
137 import vtk.test.Testing
138 from vtk.util.misc import vtkGetTempDir
139 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
140 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
142 vtk.test.Testing.interact()
144 if __name__ == "__main__":
145 outImgName="testMEDReader3.png"
146 baseline_file = RetriveBaseLine(outImgName)