Salome HOME
Set dev version marker to 1.
[modules/paravis.git] / test / VisuPrs / imps / B2.py
1 # Copyright (C) 2010-2016  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # This case corresponds to: /visu/imps/B2 case
21
22 from paravistest import datadir
23 from presentations import *
24 import pvsimple
25
26 # 1. Import MED file
27 print 'Import "ResOK_0000.med"...............',
28
29 file_path = datadir + "ResOK_0000.med"
30 pvsimple.OpenDataFile(file_path)
31 med_reader = pvsimple.GetActiveSource()
32
33 if med_reader is None:
34     raise RuntimeError, "import failed"
35 else:
36     print "OK"
37
38
39 def _extract_all_arrays_of_type(array_type, source):
40     import re
41     #sep = source.GetProperty("Separator").GetData() # "@@][@@"
42     arrays = source.AllArrays
43     result = []
44     for arr in arrays:
45         match = re.search("ComSup[^/]*/(.*)@@\]\[@@(.*)", arr)
46         field_name = match.group(1)
47         arr_typ = match.group(2)
48         if arr_typ == array_type:
49             result += [field_name]
50         pass
51     return result
52 #
53
54 def _extract_cell_arrays(source):
55     return _extract_all_arrays_of_type("P0", source)
56 #
57 def _extract_point_arrays(source):
58     return _extract_all_arrays_of_type("P1", source)
59 #
60
61 # 2. Get some information on the MED file
62 #fields_on_nodes = med_reader.PointArrays
63 fields_on_nodes = _extract_point_arrays(med_reader)
64 print "Field names on NODE: ", fields_on_nodes
65 is_ok = len(fields_on_nodes) == 2 and ("temperature" in fields_on_nodes) and ("vitesse" in fields_on_nodes)
66 if not is_ok:
67     raise RuntimeError,  "=> Error in PointArrays property"
68
69 #fields_on_cells = med_reader.CellArrays
70 fields_on_cells = _extract_cell_arrays(med_reader)
71 print "Field names on CELL: ", fields_on_cells
72 is_ok = len(fields_on_cells) == 1 and ("pression" in fields_on_cells)
73 if not is_ok:
74     raise RuntimeError,  "=> Error in CellArrays property"
75
76 timestamps = med_reader.TimestepValues.GetData()[1:]
77 print "timestamps: ", timestamps
78 if timestamps != [17.030882013694594]:
79     raise RuntimeError,  "=> Wrong TimestepValues property value"