1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2022 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Anthony Geay
25 from medcoupling import *
26 from paraview.simple import *
27 from MEDReaderHelper import WriteInTmpDir,RetriveBaseLine
30 """ This test is a non regression test. ExtractCellType then ExtractGroup.
32 fname="testMEDReader8.med"
34 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)])
35 m0=MEDCouplingUMesh("mesh",2) ; m0.setCoords(arr) ; m0.allocateCells()
36 for elt in [[2,3,6],[3,7,6],[6,9,5],[6,10,9]]:
37 m0.insertNextCell(NORM_TRI3,elt)
39 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]]:
40 m0.insertNextCell(NORM_QUAD4,elt)
43 mm.setMeshAtLevel(0,m0)
44 grp0=DataArrayInt([0,1,2,5]) ; grp0.setName("grp0")
45 mm.setGroupsAtLevel(0,[grp0])
46 fmts=MEDFileFieldMultiTS()
48 fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setName("fNode")
50 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]))
51 fNode.getArray().setInfoOnComponent(0,"C0")
52 fNode.setTime(0.5,1,1)
53 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
55 fNode.getArray().reverse()
56 fNode.setTime(0.5,1,2)
57 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
59 fNode.getArray().reverse()
60 fNode.setTime(0.5,2,1)
61 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
63 fNode.getArray().reverse()
64 fNode.setTime(0.5,2,2)
65 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
73 def test(baseline_file):
74 fname = GenerateCase()
75 ################### MED write is done -> Go to MEDReader
77 myMedReader=MEDReader(FileNames=[fname])
78 myMedReader.FieldsStatus = ['TS0/mesh/ComSup0/fNode@@][@@P1']
79 assert(list(myMedReader.TimestepValues)==[0.,1.,2.,3.])
80 myMedReader.UpdatePipeline()
82 extractCT=ExtractCellType(Input=myMedReader)
83 extractCT.UpdatePipelineInformation()
84 assert(list(extractCT.GetProperty("GeoTypesInfo"))==['Triangle', '0', 'Quad', '0'])
85 extractCT.AllGeoTypes=['Triangle']
87 extGrp=ExtractGroup(Input=extractCT)
88 #extGrp.UpdatePipelineInformation()
89 assert([x for x in list(extGrp.GetProperty("GroupsFlagsInfo")[::2]) if x[:4]=="GRP_"]==['GRP_grp0'])
90 extGrp.AllGroups="GRP_grp0"
92 if '-D' not in sys.argv:
93 RenderView1 = GetRenderView()
94 RenderView1.CameraFocalPoint = [1.5, 1.5, 0.0]
95 RenderView1.CameraPosition = [1.5, 1.5, 10000.0]
96 RenderView1.InteractionMode = '3D'
97 RenderView1.CameraPosition = [1.5, 1.5, 8.196152422706632]
98 RenderView1.CameraParallelScale = 2.1213203435596424
99 RenderView1.CenterOfRotation = [1.5, 1.5, 0.0]
101 DataRepresentation4 = Show()
102 DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
103 DataRepresentation4.SelectionPointFieldDataArrayName = 'fNode'
104 DataRepresentation4.ScaleFactor = 0.3182729169726372
106 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 )
107 a1_fGauss_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] )
108 DataRepresentation4.ColorArrayName = 'fNode'
109 DataRepresentation4.LookupTable = a1_fGauss_PVLookupTable
110 a1_fGauss_PVLookupTable.ScalarOpacityFunction = a1_fGauss_PiecewiseFunction
112 RenderView1.ViewTime = 1.0 #### Important # red is in right bottom
113 RenderView1.CacheKey = 1.0
114 RenderView1.UseCache = 1
115 RenderView1.ViewSize=[300,300]
118 # compare with baseline image
120 import vtk.test.Testing
121 from vtk.util.misc import vtkGetTempDir
122 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
123 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
125 vtk.test.Testing.interact()
127 if __name__ == "__main__":
128 outImgName="testMEDReader8.png"
129 baseline_file = RetriveBaseLine(outImgName)