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