Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader7.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
26 from medcoupling import *
27 from paraview.simple import *
28 from MEDReaderHelper import WriteInTmpDir,RetriveBaseLine
29
30 def GenerateCase():
31     """ This test generate a simple multi time field with a very aggressive time steps triplets. Neither dt, nor iteration nor order is considered.
32     In this case only the rank is considered.
33     """
34     fname="testMEDReader7.med"
35     #########
36     arr=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)])
37     m0=MEDCouplingUMesh("mesh",2) ; m0.setCoords(arr) ; m0.allocateCells()
38     for elt in [[2,3,6],[3,7,6],[6,9,5],[6,10,9]]:
39         m0.insertNextCell(NORM_TRI3,elt)
40         pass
41     for elt in [[0,4,5,1],[5,6,2,1],[4,8,9,5],[6,10,11,7],[8,12,13,9],[9,13,14,10],[10,14,15,11]]:
42         m0.insertNextCell(NORM_QUAD4,elt)
43         pass
44     mm=MEDFileUMesh()
45     mm.setMeshAtLevel(0,m0)
46     grp0=DataArrayInt([0,1,4,5,7,10]) ; grp0.setName("grp0")
47     mm.setGroupsAtLevel(0,[grp0])
48     fmts=MEDFileFieldMultiTS()
49     #
50     fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setName("fNode")
51     fNode.setMesh(m0)
52     fNode.setArray(DataArrayDouble([3,2,1,0,3.16,2.23,1.41,1,3.6,2.82,2.23,2,4.24,3.6,3.16,3]))
53     fNode.getArray().setInfoOnComponent(0,"C0")
54     fNode.setTime(0.5,1,1)
55     f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
56     #
57     fNode.getArray().reverse()
58     fNode.setTime(0.5,1,2)
59     f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
60     #
61     fNode.getArray().reverse()
62     fNode.setTime(0.5,2,1)
63     f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
64     #
65     fNode.getArray().reverse()
66     fNode.setTime(0.5,2,2)
67     f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
68     #
69     mm.write(fname,2)
70     fmts.write(fname,0)
71     return fname
72
73
74 @WriteInTmpDir
75 def test(baseline_file):
76     fname = GenerateCase()
77     ################### MED write is done -> Go to MEDReader
78     myMedReader=MEDReader(FileName=fname)
79     myMedReader.AllArrays = ['TS0/mesh/ComSup0/fNode@@][@@P1']
80     assert(list(myMedReader.TimestepValues)==[0.,1.,2.,3.])
81
82     if '-D' not in sys.argv:
83         RenderView1 = GetRenderView()
84         RenderView1.CameraFocalPoint = [1.5, 1.5, 0.0]
85         RenderView1.CameraPosition = [1.5, 1.5, 10000.0]
86         RenderView1.InteractionMode = '3D'
87         RenderView1.CameraPosition = [1.5, 1.5, 8.196152422706632]
88         RenderView1.CameraParallelScale = 2.1213203435596424
89         RenderView1.CenterOfRotation = [1.5, 1.5, 0.0]
90
91         DataRepresentation4 = Show()
92         DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
93         DataRepresentation4.SelectionPointFieldDataArrayName = 'fNode'
94         DataRepresentation4.ScaleFactor = 0.3182729169726372
95
96         a1_fGauss_PVLookupTable = GetLookupTableForArray( "fNode", 1, RGBPoints=[0.22, 0.23, 0.299, 0.754, 2.95, 0.706, 0.016, 0.15], VectorMode='Magnitude', NanColor=[0.25, 0.0, 0.0], ColorSpace='Diverging', ScalarRangeInitialized=1.0, AllowDuplicateScalars=1 )
97         a1_fGauss_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] )
98         DataRepresentation4.ColorArrayName = 'fNode'
99         DataRepresentation4.LookupTable = a1_fGauss_PVLookupTable
100         a1_fGauss_PVLookupTable.ScalarOpacityFunction = a1_fGauss_PiecewiseFunction
101
102         RenderView1.ViewTime = 1.0 #### Important # red is in right bottom
103         RenderView1.CacheKey = 1.0
104         RenderView1.UseCache = 1
105         RenderView1.ViewSize=[300,300]
106         Render()
107
108         # compare with baseline image
109         import vtk.test.Testing
110         from vtk.util.misc import vtkGetTempDir
111         vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
112         vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
113                                                                     threshold=6)
114         vtk.test.Testing.interact()
115
116 if __name__ == "__main__":
117   outImgName="testMEDReader7.png"
118   baseline_file = RetriveBaseLine(outImgName)
119   test(baseline_file)
120   pass