1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2018-2020 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
25 class TestParavis(unittest.TestCase):
31 def processGuiEvents(self):
33 if salome.sg.hasDesktop():
34 salome.sg.updateObjBrowser();
36 SalomePyQt.SalomePyQt().processEvents()
38 def test_paravis(self):
39 """Quick test for Paravis module"""
42 if salome.hasDesktop(): # can test paravis in gui mode only
45 print('Testing Paravis module')
47 # ---- initialize Paravis
48 print('... Initialize Paravis module (this can take some time)')
49 self.processGuiEvents()
50 import pvsimple as pvs
51 self.processGuiEvents()
54 data_dir = os.getenv('DATA_DIR', '')
55 self.assertNotEqual(data_dir, '', 'DATA_DIR should be defined to load the test data')
57 # ---- import med File
58 print('... Load MED file')
59 file_path = os.path.join(os.getenv('DATA_DIR'), 'MedFiles', 'ResOK_0000.med')
60 med_reader = pvs.MEDReader(FileName=file_path)
61 self.assertIsNotNone(med_reader)
62 times = med_reader.TimestepValues.GetData()
63 self.assertEqual(len(times), 2)
64 self.processGuiEvents()
68 view = pvs.GetRenderView()
69 self.assertIsNotNone(view)
71 self.processGuiEvents()
73 # ---- create presentations
74 print("... Display presentations")
77 print('...... Show mesh')
78 mesh = pvs.Show(med_reader, view)
79 self.assertIsNotNone(mesh)
81 mesh.Representation = 'Surface With Edges'
84 self.processGuiEvents()
86 # ---- show scalar map
87 print('...... Show scalar map')
89 self.assertIsNotNone(scalar_map)
90 scalar_map.Representation = 'Surface'
91 pvs.ColorBy(scalar_map, ('POINTS', 'vitesse', 'Magnitude'))
92 view.ViewTime = times[-1]
95 scalar_map.Visibility = 0
97 self.processGuiEvents()
100 print('...... Show vectors')
101 calc = pvs.Calculator(Input=med_reader)
102 self.assertIsNotNone(calc)
103 calc.ResultArrayName = 'vitesse_3c'
104 calc.Function = 'iHat * vitesse_X + jHat * vitesse_Y + kHat * 0'
105 glyph = pvs.Glyph(Input=calc, GlyphType='Arrow')
106 self.assertIsNotNone(glyph)
107 glyph.OrientationArray = ['POINTS', 'vitesse_3c']
108 glyph.ScaleArray = ['POINTS', 'No scale array']
109 glyph.ScaleFactor = 0.01
110 vectors = pvs.Show(glyph, view)
111 self.assertIsNotNone(vectors)
112 vectors.Representation = 'Surface'
115 vectors.Visibility = 0
117 self.processGuiEvents()
119 # ---- show iso surfaces
120 print('...... Show iso surfaces')
121 merge_blocks = pvs.MergeBlocks(Input=med_reader)
122 self.assertIsNotNone(merge_blocks)
123 calc = pvs.Calculator(Input=merge_blocks)
124 self.assertIsNotNone(calc)
125 calc.ResultArrayName = 'vitesse_magnitude'
126 calc.Function = 'sqrt(vitesse_X^2+vitesse_Y^2)'
127 data_range = med_reader.GetPointDataInformation()['vitesse'].GetComponentRange(-1)
129 surfaces = [data_range[0] + i*(data_range[1]-data_range[0])/(nb_surfaces-1) for i in range(nb_surfaces)]
130 contour = pvs.Contour(Input=calc)
131 self.assertIsNotNone(contour)
132 contour.ComputeScalars = 1
133 contour.ContourBy = ['POINTS', 'vitesse_magnitude']
134 contour.Isosurfaces = surfaces
135 iso_surfaces = pvs.Show(contour, view)
136 self.assertIsNotNone(iso_surfaces)
137 iso_surfaces.Representation = 'Surface'
138 pvs.ColorBy(iso_surfaces, ('POINTS', 'vitesse', 'Magnitude'))
141 iso_surfaces.Visibility = 0
143 self.processGuiEvents()
145 # ---- show cut planes
146 print('...... Show cut planes')
147 slice = pvs.Slice(Input=med_reader)
148 self.assertIsNotNone(slice)
149 slice.SliceType = "Plane"
150 slice.SliceType.Normal = [1.0, 0.0, 0.0]
151 bounds = med_reader.GetDataInformation().GetBounds()
154 b_left = bounds[0] + (bounds[1]-bounds[0])*displacement/100
155 b_right = bounds[1] - (bounds[1]-bounds[0])*displacement/100
156 b_range = b_right - b_left
157 positions = [b_left + i*b_range/(nb_planes-1) for i in range(nb_planes)]
158 slice.SliceOffsetValues = positions
159 pvs.Hide3DWidgets(proxy=slice.SliceType)
160 cut_planes = pvs.Show(slice, view)
161 self.assertIsNotNone(cut_planes)
162 cut_planes.Representation = 'Surface'
163 pvs.ColorBy(cut_planes, ('POINTS', 'vitesse', 'Magnitude'))
166 cut_planes.Visibility = 0
168 self.processGuiEvents()
170 # ---- show deformed shape
171 print('...... Show deformed shape')
172 merge_blocks = pvs.MergeBlocks(Input=med_reader)
173 self.assertIsNotNone(merge_blocks)
174 calc = pvs.Calculator(Input=merge_blocks)
175 self.assertIsNotNone(calc)
176 calc.ResultArrayName = 'vitesse_3c'
177 calc.Function = 'iHat * vitesse_X + jHat * vitesse_Y + kHat * 0'
178 warp = pvs.WarpByVector(Input=calc)
179 self.assertIsNotNone(warp)
180 warp.Vectors = ['POINTS', 'vitesse_3c']
181 warp.ScaleFactor = 0.5
182 deformed_shape = pvs.Show(warp, view)
183 self.assertIsNotNone(deformed_shape)
184 deformed_shape.Representation = 'Surface'
185 pvs.ColorBy(deformed_shape, ('CELLS', 'pression'))
188 deformed_shape.Visibility = 0
190 self.processGuiEvents()
192 else: # not in gui mode, Paravis can not be tested
194 print("PARAVIS module requires SALOME to be running in GUI mode.")
196 print("Skipping test for PARAVIS...")
197 self.processGuiEvents()
199 if __name__ == '__main__':