]> SALOME platform Git repositories - modules/paravis.git/blob - src/Plugins/MEDReader/Test/testMEDReader5.py
Salome HOME
59c54a5da4a4f00d611c47ce93ecc74725e7f2c4
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader5.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2019  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
21
22 import os
23 import sys
24
25 from MEDLoader import *
26
27 """ This test is CEA specific one. It generates a .sauv file
28 that is then read by MEDReader
29 """
30
31 fname="testMEDReader5.sauv"
32 outImgName="testMEDReader5.png"
33 #########
34 arr=DataArrayDouble(5) ; arr.iota()
35 c=MEDCouplingCMesh("mesh")
36 c.setCoords(arr,arr,arr)
37 m=c.buildUnstructured()
38 mbis=m.deepCopy() ; mbis.translate([5,0,0]) ; mbis.tetrahedrize(PLANAR_FACE_5)
39 m=MEDCouplingUMesh.MergeUMeshes([mbis,m]) ; m.setName(c.getName())
40 mm=MEDFileUMesh()
41 mm.setMeshAtLevel(0,m)
42 grp0=DataArrayInt.Range(0,m.getNumberOfCells(),2) ; grp0.setName("grp0")
43 grp1=DataArrayInt.Range(1,m.getNumberOfCells(),2) ; grp1.setName("grp1")
44 grp2=DataArrayInt.Range(0,m.getNumberOfNodes(),7) ; grp2.setName("grp2")
45 mm.setGroupsAtLevel(0,[grp0,grp1])
46 mm.setGroupsAtLevel(1,[grp2])
47 ms=MEDFileMeshes()
48 ms.pushMesh(mm)
49 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("fCell") ; f.setMesh(m[:10])
50 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota() ; f.setArray(arr)
51 f2=MEDCouplingFieldDouble(ON_NODES) ; f2.setName("fNode") ; f2.setMesh(m)
52 arr=DataArrayDouble(f2.getNumberOfTuplesExpected()) ; arr.iota() ; f2.setArray(arr)
53
54 fs=MEDFileFields()
55 f1ts=MEDFileField1TS()
56 #f1ts.setFieldNoProfileSBT(f)
57 pfl=DataArrayInt(10); pfl.iota() ; pfl.setName("pfl") ; f1ts.setFieldProfile(f,mm,0,pfl)
58 fmts=MEDFileFieldMultiTS()
59 fmts.pushBackTimeStep(f1ts)
60 fs.pushField(fmts)
61 f1ts=MEDFileField1TS()
62 f1ts.setFieldNoProfileSBT(f2)
63 fmts=MEDFileFieldMultiTS()
64 fmts.pushBackTimeStep(f1ts)
65 fs.pushField(fmts)
66
67 mfd=MEDFileData()
68 mfd.setMeshes(ms)
69 mfd.setFields(fs)
70 #mfd.write(fname,2) not activated because useless
71 #
72 sw=SauvWriter();
73 sw.setMEDFileDS(mfd);
74 sw.write(fname);
75 del mm,m,c,f,arr
76 del f1ts
77 ################### MED write is done -> Go to MEDReader
78 from paraview.simple import *
79
80 myMedReader=MEDReader(FileName=fname)
81 myMedReader.AllArrays = ['TS0/mesh/ComSup1/fNode@@][@@P1']
82 myMedReader.AllTimeSteps = ['0000']
83
84 Clip1=Clip(ClipType="Plane",Input=myMedReader)
85 Clip1.Scalars = ['POINTS', 'FamilyIdNode']
86 Clip1.ClipType.Origin = [2.0, 2.0, 2.0]
87 Clip1.ClipType = "Plane"
88 Clip1.ClipType.Normal = [0.04207410474474753, 0.9319448861971525, 0.3601506612529047]
89 Clip1.Invert = 1
90
91 DataRepresentation2 = Show()
92 DataRepresentation2.EdgeColor = [0.0, 0.0, 0.5000076295109483]
93 DataRepresentation2.ScalarOpacityUnitDistance = 1.5768745057161244
94 DataRepresentation2.ExtractedBlockIndex = 1
95 DataRepresentation2.ScaleFactor = 0.4
96
97 if '-D' not in sys.argv:
98   RenderView1=GetRenderView()
99   RenderView1.CenterOfRotation=[2.,2.,2.]
100   RenderView1.CameraViewUp=[0.24562884954787187,0.6907950752417243,-0.680050463047831]
101   RenderView1.CameraPosition=[-2.5085697461776486,11.6185941755061,10.14210560568201]
102   RenderView1.CameraFocalPoint=[2.,2.,2.]
103   RenderView1.CameraParallelScale=5.071791174723188
104
105   LookupTable=GetLookupTableForArray("fNode",1,RGBPoints=[0.0,0.23,0.299,0.754,55.0,0.706,0.016,0.15],VectorMode='Magnitude',NanColor=[0.25,0.0,0.0],ColorSpace='Diverging',ScalarRangeInitialized=1.0,AllowDuplicateScalars=1)
106   DataRepresentation2 = Show()
107   DataRepresentation2.EdgeColor = [0.0, 0.0, 0.5000076295109483]
108   DataRepresentation2.ScalarOpacityUnitDistance = 1.5768745057161244
109   DataRepresentation2.ExtractedBlockIndex = 1
110   DataRepresentation2.ScaleFactor = 0.4
111   DataRepresentation2.ColorArrayName=('POINTS','fNode')
112   DataRepresentation2.LookupTable=LookupTable
113
114   RenderView1.ViewSize=[300,300]
115   Render()
116
117   # compare with baseline image
118   try:
119     baselineIndex = sys.argv.index('-B')+1
120     baselinePath = sys.argv[baselineIndex]
121   except:
122     print("Could not get baseline directory. Test failed.")
123     exit(1)
124   baseline_file = os.path.join(baselinePath, "testMEDReader5.png")
125   import vtk.test.Testing
126   from vtk.util.misc import vtkGetTempDir
127   vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
128   vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
129                                                               threshold=1)
130   vtk.test.Testing.interact()