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