Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader2.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 use case is a mesh containing a large number of orphan cells (cells having no field lying on them)
31   """
32   fname="testMEDReader2.med"
33   #########
34   arrX=DataArrayDouble(7) ; arrX.iota()
35   arrY=DataArrayDouble(7) ; arrY.iota()
36   arrZ=DataArrayDouble(7) ; arrZ.iota()
37   m=MEDCouplingCMesh()
38   m.setCoords(arrX,arrY,arrZ)
39   m=m.buildUnstructured() ; m.setName("mesh")
40   tmp=m[3*36:4*36]
41   tmp=tmp.buildDescendingConnectivity()[0]
42   nodeIds=tmp.findNodesOnPlane([0.,0.,3.],[0.,0.,1.],1e-12)
43   cellIds=tmp.getCellIdsLyingOnNodes(nodeIds,True)
44   m1=tmp[cellIds]
45   mm=MEDFileUMesh()
46   mm.setMeshAtLevel(0,m)
47   mm.setMeshAtLevel(-1,m1)
48   mm.write(fname,2)
49   #
50   pfl=DataArrayInt([7,8,9,10,13,14,15,16,19,20,21,22,25,26,27,28]) ; pfl.setName("pfl")
51   f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("ACellField")
52   arr=DataArrayDouble(16) ; arr.iota()
53   arr2=arr.deepCopy() ; arr2.reverse()
54   arr=DataArrayDouble.Meld(arr,arr2) ; arr.setInfoOnComponents(["aa","bbb"])
55   f.setArray(arr)
56   f1ts=MEDFileField1TS()
57   f1ts.setFieldProfile(f,mm,-1,pfl)
58   f1ts.write(fname,0)
59   return fname
60
61 @WriteInTmpDir
62 def test(baseline_file):
63   fname = GenerateCase()
64   ################### MED write is done -> Go to MEDReader
65   testMEDReader1=MEDReader(FileName=fname)
66   testMEDReader1.AllArrays=['TS0/mesh/ComSup0/ACellField@@][@@P0']
67   testMEDReader2=MEDReader(FileName=fname)
68   testMEDReader2.AllArrays=['TS0/mesh/ComSup1/mesh@@][@@P0']
69   GroupDatasets1=GroupDatasets(Input=[testMEDReader1,testMEDReader2])
70
71   Clip1 = Clip(ClipType="Plane",Input=GroupDatasets1)
72   Clip1.Scalars=['FamilyIdCell']
73   Clip1.ClipType.Origin=[3.0, 3.0, 3.0]
74   Clip1.Invert=1
75   Clip1.ClipType.Normal=[0.9255623174457069, 0.0027407477590518157, 0.378585373233375]
76   Clip1.Scalars=['CELLS']
77
78   DataRepresentation4 = Show()
79   DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
80   DataRepresentation4.SelectionCellFieldDataArrayName = 'ACellField'
81   DataRepresentation4.ScalarOpacityUnitDistance = 1.61104723630366
82   DataRepresentation4.ExtractedBlockIndex = 2
83   DataRepresentation4.ScaleFactor = 0.6000000000000001
84   DataRepresentation4.Visibility = 1
85   DataRepresentation4.Representation = 'Wireframe'
86
87   ExtractBlock1 = ExtractBlock(Input=Clip1)
88   ExtractBlock1.BlockIndices=[1, 2]
89
90   DataRepresentation5 = Show()
91   DataRepresentation5.EdgeColor = [0.0, 0.0, 0.5000076295109483]
92   DataRepresentation5.SelectionCellFieldDataArrayName = 'FamilyIdCell'
93   DataRepresentation5.ScaleFactor = 0.6
94   a2_ACellField_PVLookupTable=GetLookupTableForArray( "ACellField", 2, RGBPoints=[10.63014581273465, 0.23, 0.299, 0.754, 15.0, 0.706, 0.016, 0.15], VectorMode='Magnitude', NanColor=[0.25, 0.0, 0.0], ColorSpace='Diverging', ScalarRangeInitialized=1.0, AllowDuplicateScalars=1 )
95   a2_ACellField_PiecewiseFunction=CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] )
96   a2_ACellField_PVLookupTable.ScalarOpacityFunction = a2_ACellField_PiecewiseFunction
97   DataRepresentation5.ScalarOpacityFunction = a2_ACellField_PiecewiseFunction
98   DataRepresentation5.LookupTable = a2_ACellField_PVLookupTable
99   DataRepresentation5.ColorArrayName = ("CELLS", "ACellField")
100
101   if '-D' not in sys.argv:
102     RenderView1 = GetRenderView()
103     RenderView1.CenterOfRotation = [3.0, 3.0, 3.0]
104     RenderView1.CameraViewUp = [-0.03886073885859842, 0.48373409998193495, 0.8743518533691291]
105     RenderView1.CameraPosition = [7.351939549758929, -5.688193007926853, 8.000155023042788]
106     RenderView1.CameraFocalPoint = [2.9999999999999996, 2.9999999999999987, 2.9999999999999982]
107
108     RenderView1.ViewSize =[300,300]
109     Render()
110
111     #WriteImage(outImgName)
112
113     # compare with baseline image
114     import vtk.test.Testing
115     from vtk.util.misc import vtkGetTempDir
116     vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
117     vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
118                                                                 threshold=1)
119     vtk.test.Testing.interact()
120
121 if __name__ == "__main__":
122   outImgName="testMEDReader2.png"
123   baseline_file = RetriveBaseLine(outImgName)
124   test(baseline_file)
125   pass