Salome HOME
970f320b88763b6ca797506f4f3f3c189dc21db7
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader4.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2017  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 checks that umeshes with no names work properly.
28 """
29
30 fname="testMEDReader4.med"
31 outImgName="testMEDReader4.png"
32 #########
33 coords=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.)])
34 m0=MEDCouplingUMesh("mesh",2)
35 m0.allocateCells()
36 m0.setCoords(coords)
37 ##
38 mm=MEDFileUMesh()
39 mm.setMeshAtLevel(0,m0)
40 mm.setFamilyFieldArr(1,DataArrayInt([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]))
41 #
42 f1ts0=MEDFileField1TS()
43 f1ts1=MEDFileField1TS()
44 #
45 f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m0) ; f0.setName("f0NoPfl")
46 arr0=DataArrayDouble([0.,1.,2.,3.,1.,1.5,2.2,3.1,2.,2.2,3.,3.1,3.,3.1,3.5,4.])
47 f0.setArray(arr0)
48 f0.checkConsistencyLight()
49 f1ts0.setFieldNoProfileSBT(f0)
50 #
51 pfl1=DataArrayInt([0,1,2,3,4,5,6,8,9,12]) ; pfl1.setName("pfl1")
52 f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setName("f1Pfl")
53 arr1=DataArrayDouble([3.,2.,1.,0.,2.,1.5,0.,1.,0.,0.2])
54 f1.setArray(arr1)
55 f1ts1.setFieldProfile(f1,mm,0,pfl1)
56 #
57 fs=MEDFileFields()
58 fmts0=MEDFileFieldMultiTS()
59 fmts0.pushBackTimeStep(f1ts0)
60 fmts1=MEDFileFieldMultiTS()
61 fmts1.pushBackTimeStep(f1ts1)
62 fs.pushField(fmts0) ; fs.pushField(fmts1)
63 mm.write(fname,2)
64 fs.write(fname,0)
65 ################### MED write is done -> Go to MEDReader
66
67 from paraview.simple import *
68
69 testMEDReader4_med=MEDReader(FileName=fname)
70
71 testMEDReader4_med.AllArrays=['TS0/mesh/ComSup0/f0NoPfl@@][@@P1','TS0/mesh/ComSup0/mesh@@][@@P1']
72 #testMEDReader4_med.AllTimeSteps=['0000']
73
74 Glyph1=Glyph(Input=testMEDReader4_med,GlyphType='Sphere')
75 Glyph1.ScaleArray=['POINTS','f0NoPfl']
76 Glyph1.MaximumGlyphSize=0.3
77 Glyph1.OrientationArray = ['POINTS', 'No orientation array']
78 Glyph1.GlyphTransform="Transform2"
79
80 DataRepresentation1 = Show()
81 DataRepresentation1.EdgeColor = [0.0, 0.0, 0.5000076295109483]
82 DataRepresentation1.SelectionPointFieldDataArrayName = 'f0NoPfl'
83 DataRepresentation1.ScaleFactor = 0.3
84 DataRepresentation1.ColorArrayName = 'f0NoPfl'
85 lookupTable = GetLookupTableForArray( "f0NoPfl", 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], ColorSpace='Diverging', ScalarRangeInitialized=1.0, AllowDuplicateScalars=1 )
86 function=CreatePiecewiseFunction(Points=[0.0,0.0,0.5,0.0,1.0,1.0,0.5,0.0] )
87 lookupTable.ScalarOpacityFunction = function
88 DataRepresentation1.LookupTable = lookupTable
89
90 if '-D' not in sys.argv:
91   RenderView1 = GetRenderView()
92   RenderView1.CameraViewUp = [0.06254683966704512, 0.9980420295997885, 0.0]
93   RenderView1.CameraPosition = [0.8087292125440382, 1.3325993334207897, 12.692130429902462]
94   RenderView1.CameraFocalPoint = [0.8087292125440382, 1.3325993334207897, 0.0]
95   RenderView1.CameraParallelScale = 3.712804729456109
96
97   RenderView1.ViewSize =[300,300]
98   Render()
99
100   # compare with baseline image
101   try:
102     baselineIndex = sys.argv.index('-B')+1
103     baselinePath = sys.argv[baselineIndex]
104   except:
105     print("Could not get baseline directory. Test failed.")
106     exit(1)
107   baseline_file = os.path.join(baselinePath, "testMEDReader4.png")
108   import vtk.test.Testing
109   from vtk.util.misc import vtkGetTempDir
110   vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
111   vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
112                                                               threshold=1)
113   vtk.test.Testing.interact()