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