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
25 from MEDLoader import *
27 fname="testMEDReader3.med"
28 outImgName="testMEDReader3.png"
30 """ This test checks that invalid double time (not in [-1e299:1e299])
31 leads MEDReader to takes iteration numbers instead of double time to discriminate timesteps each other
36 m=MEDCouplingUMesh("mesh",2)
37 coords=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(1.,1.,0.),(0.,1.,0.)],4,3)
40 m.insertNextCell(NORM_QUAD4,[0,3,2,1])
42 mm.setMeshAtLevel(0,m)
44 fmts=MEDFileFieldMultiTS()
46 f=MEDCouplingFieldDouble(ON_NODES) ; f.setName("ANodeField")
47 f.setTime(1.7976931348623157e+308,1,1) ; f.setMesh(m)
48 arr=DataArrayDouble([0.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
50 f1ts=MEDFileField1TS()
51 f1ts.setFieldNoProfileSBT(f)
52 fmts.pushBackTimeStep(f1ts)
54 f.setTime(1.7976931348623157e+308,2,2)
55 arr=DataArrayDouble([1.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
57 f1ts=MEDFileField1TS()
58 f1ts.setFieldNoProfileSBT(f)
59 fmts.pushBackTimeStep(f1ts)
61 f.setTime(1.7976931348623157e+308,3,3)
62 arr=DataArrayDouble([2.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
64 f1ts=MEDFileField1TS()
65 f1ts.setFieldNoProfileSBT(f)
66 fmts.pushBackTimeStep(f1ts)
68 f.setTime(1.7976931348623157e+308,4,6)
69 arr=DataArrayDouble([3.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
71 f1ts=MEDFileField1TS()
72 f1ts.setFieldNoProfileSBT(f)
73 fmts.pushBackTimeStep(f1ts)
75 f.setTime(1.7976931348623157e+308,5,7)
76 arr=DataArrayDouble([4.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
78 f1ts=MEDFileField1TS()
79 f1ts.setFieldNoProfileSBT(f)
80 fmts.pushBackTimeStep(f1ts)
84 ################### MED write is done -> Go to MEDReader
86 from paraview.simple import *
88 AnimationScene1=GetAnimationScene()
89 AnimationScene1.PlayMode='Snap To TimeSteps'
90 AnimationScene1.EndTime = 2.0
91 AnimationScene1.AnimationTime = 1.0
92 AnimationScene1.StartTime = 1.0
94 testMEDReader3=MEDReader(FileName=fname)
95 testMEDReader3.AllArrays=['TS0/mesh/ComSup0/ANodeField@@][@@P1']
97 assert(list(testMEDReader3.TimestepValues)==[1.,2.,3.,4.,5.]) ## <- the test is here - double time steps are too big use dt.
99 if '-D' not in sys.argv:
100 RenderView1=GetRenderView()
101 RenderView1.ViewTime=3.0
102 RenderView1.CameraPosition=[0.5,0.5,5.7320508075688776]
103 RenderView1.ViewSize=[300,300]
105 DataRepresentation2=Show()
106 DataRepresentation2.EdgeColor=[0.0, 0.0, 0.5000076295109483]
107 DataRepresentation2.SelectionPointFieldDataArrayName='ANodeField'
108 DataRepresentation2.SelectionCellFieldDataArrayName='FamilyIdCell'
109 DataRepresentation2.ScalarOpacityUnitDistance=1.4142135623730951
110 DataRepresentation2.ExtractedBlockIndex=1
111 DataRepresentation2.ScaleFactor=0.1
113 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],
114 ColorSpace='Diverging',ScalarRangeInitialized=1.0,AllowDuplicateScalars=1)
115 a1_ANodeField_PiecewiseFunction=CreatePiecewiseFunction(Points=[0.0,0.0,0.5,0.0,1.0,1.0,0.5,0.0])
116 a1_ANodeField_PVLookupTable.ScalarOpacityFunction=a1_ANodeField_PiecewiseFunction
118 DataRepresentation2.ScalarOpacityFunction=a1_ANodeField_PiecewiseFunction
119 DataRepresentation2.ColorArrayName='ANodeField'
120 DataRepresentation2.LookupTable=a1_ANodeField_PVLookupTable
122 # Triangulate so rendring always the same with different gpu or graphic backend.
123 extSurf = ExtractSurface(Input=testMEDReader3)
124 triangulate = Triangulate(Input=extSurf)
125 Hide(testMEDReader3, RenderView1)
126 Show(triangulate, RenderView1)
127 triangulate1Display = GetDisplayProperties(triangulate, view=RenderView1)
128 ColorBy(triangulate1Display, ('POINTS', 'ANodeField'))
133 # compare with baseline image
135 baselineIndex = sys.argv.index('-B')+1
136 baselinePath = sys.argv[baselineIndex]
138 print("Could not get baseline directory. Test failed.")
140 baseline_file = os.path.join(baselinePath, "testMEDReader3.png")
141 import vtk.test.Testing
142 from vtk.util.misc import vtkGetTempDir
143 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
144 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
146 vtk.test.Testing.interact()