Salome HOME
Merge branch 'origin/abn/openfile_fix'
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader3.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2014  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.
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
21
22 from MEDLoader import *
23
24 fname="testMEDReader3.med"
25 outImgName="testMEDReader3.png"
26
27 """ This test checks that invalid double time (not in [-1e299:1e299])
28  leads MEDReader to takes iteration numbers instead of double time to discriminate timesteps each other
29  See EDF 1956.
30 """
31 #########
32
33 m=MEDCouplingUMesh("mesh",2)
34 coords=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(1.,1.,0.),(0.,1.,0.)],4,3)
35 m.setCoords(coords)
36 m.allocateCells()
37 m.insertNextCell(NORM_QUAD4,[0,3,2,1])
38 mm=MEDFileUMesh()
39 mm.setMeshAtLevel(0,m)
40 mm.write(fname,2)
41 fmts=MEDFileFieldMultiTS()
42 #
43 f=MEDCouplingFieldDouble(ON_NODES) ; f.setName("ANodeField")
44 f.setTime(1.7976931348623157e+308,1,1) ; f.setMesh(m)
45 arr=DataArrayDouble([0.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
46 f.setArray(arr)
47 f1ts=MEDFileField1TS()
48 f1ts.setFieldNoProfileSBT(f)
49 fmts.pushBackTimeStep(f1ts)
50 #
51 f.setTime(1.7976931348623157e+308,2,2)
52 arr=DataArrayDouble([1.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
53 f.setArray(arr)
54 f1ts=MEDFileField1TS()
55 f1ts.setFieldNoProfileSBT(f)
56 fmts.pushBackTimeStep(f1ts)
57 #
58 f.setTime(1.7976931348623157e+308,3,3)
59 arr=DataArrayDouble([2.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
60 f.setArray(arr)
61 f1ts=MEDFileField1TS()
62 f1ts.setFieldNoProfileSBT(f)
63 fmts.pushBackTimeStep(f1ts)
64 #
65 f.setTime(1.7976931348623157e+308,4,6)
66 arr=DataArrayDouble([3.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
67 f.setArray(arr)
68 f1ts=MEDFileField1TS()
69 f1ts.setFieldNoProfileSBT(f)
70 fmts.pushBackTimeStep(f1ts)
71 #
72 f.setTime(1.7976931348623157e+308,5,7)
73 arr=DataArrayDouble([4.,4.,4.,4.]) ; arr.setInfoOnComponent(0,"aaa")
74 f.setArray(arr)
75 f1ts=MEDFileField1TS()
76 f1ts.setFieldNoProfileSBT(f)
77 fmts.pushBackTimeStep(f1ts)
78 #
79 fmts.write(fname,0)
80
81 ################### MED write is done -> Go to MEDReader
82
83 from paraview.simple import *
84
85 AnimationScene1=GetAnimationScene()
86 AnimationScene1.PlayMode='Snap To TimeSteps'
87 AnimationScene1.EndTime = 2.0
88 AnimationScene1.AnimationTime = 1.0
89 AnimationScene1.StartTime = 1.0
90
91 testMEDReader3=MEDReader(FileName=fname)
92 testMEDReader3.AllArrays=['TS0/mesh/ComSup0/ANodeField@@][@@P1']
93
94 assert(list(testMEDReader3.TimestepValues)==[1.,2.,3.,4.,5.]) ## <- the test is here - double time steps are too big use dt.
95
96 RenderView1=GetRenderView()
97 RenderView1.ViewTime=3.0
98 RenderView1.CameraPosition=[0.5,0.5,5.7320508075688776]
99 RenderView1.CameraClippingRange=[2.704730299493189,2.7730315696824106]
100 RenderView1.ViewSize=[300,300]
101
102 DataRepresentation2=Show()
103 DataRepresentation2.EdgeColor=[0.0, 0.0, 0.5000076295109483]
104 DataRepresentation2.SelectionPointFieldDataArrayName='ANodeField'
105 DataRepresentation2.SelectionCellFieldDataArrayName='FamilyIdCell'
106 DataRepresentation2.ScalarOpacityUnitDistance=1.4142135623730951
107 DataRepresentation2.ExtractedBlockIndex=1
108 DataRepresentation2.ScaleFactor=0.1
109
110 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],
111                                                      ColorSpace='Diverging',ScalarRangeInitialized=1.0,AllowDuplicateScalars=1)
112 a1_ANodeField_PiecewiseFunction=CreatePiecewiseFunction(Points=[0.0,0.0,0.5,0.0,1.0,1.0,0.5,0.0])
113 a1_ANodeField_PVLookupTable.ScalarOpacityFunction=a1_ANodeField_PiecewiseFunction
114
115 DataRepresentation2.ScalarOpacityFunction=a1_ANodeField_PiecewiseFunction
116 DataRepresentation2.ColorArrayName='ANodeField'
117 DataRepresentation2.LookupTable=a1_ANodeField_PVLookupTable
118 ###
119 WriteImage(outImgName)
120
121