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