Salome HOME
fix bug of extract group after extract cell type.
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader8.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2014  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.
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 is a non regression test. ExtractCellType then ExtractGroup.
25 """
26
27 fname="testMEDReader8.med"
28 outImgName="testMEDReader8.png"
29 #########
30 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)])
31 m0=MEDCouplingUMesh("mesh",2) ; m0.setCoords(arr) ; m0.allocateCells()
32 for elt in [[2,3,6],[3,7,6],[6,9,5],[6,10,9]]:
33     m0.insertNextCell(NORM_TRI3,elt)
34     pass
35 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]]:
36     m0.insertNextCell(NORM_QUAD4,elt)
37     pass
38 mm=MEDFileUMesh()
39 mm.setMeshAtLevel(0,m0)
40 grp0=DataArrayInt([0,1,2,5]) ; grp0.setName("grp0")
41 mm.setGroupsAtLevel(0,[grp0])
42 fmts=MEDFileFieldMultiTS()
43 #
44 fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setName("fNode")
45 fNode.setMesh(m0)
46 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]))
47 fNode.getArray().setInfoOnComponent(0,"C0")
48 fNode.setTime(0.5,1,1)
49 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
50 #
51 fNode.getArray().reverse()
52 fNode.setTime(0.5,1,2)
53 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
54 #
55 fNode.getArray().reverse()
56 fNode.setTime(0.5,2,1)
57 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
58 #
59 fNode.getArray().reverse()
60 fNode.setTime(0.5,2,2)
61 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(fNode) ; fmts.pushBackTimeStep(f1ts)
62 #
63 mm.write(fname,2)
64 fmts.write(fname,0)
65 ################### MED write is done -> Go to MEDReader
66 from paraview.simple import *
67
68 myMedReader=MEDReader(FileName=fname)
69 myMedReader.AllArrays = ['TS0/mesh/ComSup0/fNode@@][@@P1']
70 assert(list(myMedReader.TimestepValues)==[0.,1.,2.,3.])
71 myMedReader.UpdatePipeline()
72
73 extractCT=ExtractCellType()
74 extractCT.Input=myMedReader
75 extractCT.UpdatePipelineInformation()
76 assert(list(extractCT.GetProperty("GeoTypesInfo"))==['TRI3','0','QUAD4','0'])
77 extractCT.AllGeoTypes=['TRI3']
78
79 extGrp=ExtractGroup()
80 extGrp.Input=extractCT
81 extGrp.UpdatePipelineInformation()
82 assert(filter(lambda x:x[:4]=="GRP_",list(extGrp.GetProperty("GroupsFlagsInfo")[::2]))==['GRP_grp0'])
83 extGrp.AllGroups="GRP_grp0"
84
85 RenderView1 = GetRenderView()
86 RenderView1.CameraFocalPoint = [1.5, 1.5, 0.0]
87 RenderView1.CameraPosition = [1.5, 1.5, 10000.0]
88 RenderView1.InteractionMode = '3D'
89 RenderView1.CameraPosition = [1.5, 1.5, 8.196152422706632]
90 RenderView1.CameraClippingRange = [7.825640906782493, 8.682319698595558]
91 RenderView1.CameraParallelScale = 2.1213203435596424
92 RenderView1.CenterOfRotation = [1.5, 1.5, 0.0]
93
94 DataRepresentation4 = Show()
95 DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
96 DataRepresentation4.SelectionPointFieldDataArrayName = 'fNode'
97 DataRepresentation4.ScaleFactor = 0.3182729169726372
98
99 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 )
100 a1_fGauss_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] )
101 DataRepresentation4.ColorArrayName = 'fNode'
102 DataRepresentation4.LookupTable = a1_fGauss_PVLookupTable
103 a1_fGauss_PVLookupTable.ScalarOpacityFunction = a1_fGauss_PiecewiseFunction
104
105 RenderView1.ViewTime = 1.0 #### Important # red is in right bottom
106 RenderView1.CacheKey = 1.0
107 RenderView1.UseCache = 1
108 RenderView1.ViewSize=[300,300]
109 WriteImage(outImgName)