Salome HOME
c2cd709518d9c38abb83f18ae3d715983263ce14
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader6.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2023  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 generate a GaussPoint field on a mesh with groups.
31     The aim of this test is to check that the ExtractGroup works well for ELGAfieldToPointGaussian
32     """
33     fname="testMEDReader6.med"
34     #########
35     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)])
36     m0=MEDCouplingUMesh("mesh",2) ; m0.setCoords(arr) ; m0.allocateCells()
37     for elt in [[2,3,6],[3,7,6],[6,9,5],[6,10,9]]:
38         m0.insertNextCell(NORM_TRI3,elt)
39         pass
40     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]]:
41         m0.insertNextCell(NORM_QUAD4,elt)
42         pass
43     mm=MEDFileUMesh()
44     mm.setMeshAtLevel(0,m0)
45     grp0=DataArrayInt([0,1,4,5,7,10]) ; grp0.setName("grp0")
46     mm.setGroupsAtLevel(0,[grp0])
47     #
48     fGauss=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fGauss.setName("fGauss")
49     fGauss.setMesh(m0)
50     fGauss.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,0.,1.],[0.1,0.1,0.05,0.9],[0.4,0.6])
51     fGauss.setGaussLocalizationOnType(NORM_QUAD4,[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[-0.9,-0.9,0.,0.,0.9,0.9],[0.2,0.3,0.5])
52     fGauss.setArray(DataArrayDouble([0.9,1.3,0.22,1.3,1.62,2.21,1.62,2.72,2.95,2.54,2.25,2.16,1.58,1.05,3.13,2.91,2.82,1.41,1.58,1.95,3.59,3.53,3.59,2.82,2.91,3.13,2.25,2.54,2.95]))
53     fGauss.getArray().setInfoOnComponent(0,"C0")
54     fGauss.checkConsistencyLight()
55     #
56     f1ts=MEDFileField1TS()
57     f1ts.setFieldNoProfileSBT(fGauss)
58     #
59     mm.write(fname,2)
60     f1ts.write(fname,0)
61     return fname
62
63 @WriteInTmpDir
64 def test(baseline_file):
65     fname = GenerateCase()
66     ################### MED write is done -> Go to MEDReader
67
68     myMedReader=MEDReader(FileNames=[fname])
69     myMedReader.FieldsStatus = ['TS0/mesh/ComSup0/fGauss@@][@@GAUSS']
70     myMedReader.TimesFlagsStatus = ['0000']
71
72     ExtractGroup1 = ExtractGroup(Input=myMedReader)
73     ExtractGroup1.UpdatePipelineInformation()
74     ExtractGroup1.AllGroups = ['GRP_grp0']
75
76     ELGAfieldToPointGaussian1 = ELGAfieldToPointGaussian(Input=ExtractGroup1)
77     ELGAfieldToPointGaussian1.SelectSourceArray = ['CELLS','ELGA@0']
78
79     Glyph1 = Glyph( Input=ELGAfieldToPointGaussian1, GlyphType="Sphere", GlyphTransform="Transform2" )
80     Glyph1.GlyphType = "Sphere"
81     Glyph1.OrientationArray = ['POINTS', 'No orientation array']
82     Glyph1.ScaleFactor = 0.29
83
84     if '-D' not in sys.argv:
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.CameraParallelScale = 2.1213203435596424
91         RenderView1.CenterOfRotation = [1.5, 1.5, 0.0]
92
93         DataRepresentation4 = Show()
94         DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
95         DataRepresentation4.SelectionPointFieldDataArrayName = 'fGauss'
96         DataRepresentation4.ScaleFactor = 0.3182729169726372
97
98         a1_fGauss_PVLookupTable = GetLookupTableForArray( "fGauss", 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 )
99         a1_fGauss_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] )
100         DataRepresentation4.ColorArrayName = 'fGauss'
101         DataRepresentation4.LookupTable = a1_fGauss_PVLookupTable
102         a1_fGauss_PVLookupTable.ScalarOpacityFunction = a1_fGauss_PiecewiseFunction
103
104         RenderView1.ViewSize=[300,300]
105         Render()
106
107         # compare with baseline image
108         import vtk.test.Testing
109         from vtk.util.misc import vtkGetTempDir
110         vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
111         vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
112                                                                     threshold=1)
113         vtk.test.Testing.interact()
114
115 if __name__ == "__main__":
116   outImgName="testMEDReader6.png"
117   baseline_file = RetriveBaseLine(outImgName)
118   test(baseline_file)
119   pass