1212ARROW_TYPE = 3
1313
1414
15- def visualize_vtu (
15+ def _visualize_vtu (
1616 filepath ,
1717 cycle ,
1818 scale_factor = 10 ** 3 ,
@@ -30,6 +30,19 @@ def visualize_vtu(
3030 Must be 'w' for wetting phase (usually waater) injection cycles and 'o'
3131 for non-wetting phase (usually oil) injection cycles
3232 """
33+ if axis == "x" :
34+ arrow_x = 0
35+ arrow_y = 0
36+ arrow_z = 1
37+ elif axis == "y" :
38+ arrow_x = 0
39+ arrow_y = 1
40+ arrow_z = 0
41+ elif axis == "z" :
42+ arrow_x = 1
43+ arrow_y = 0
44+ arrow_z = 0
45+
3346 reader = vtk .vtkXMLUnstructuredGridReader ()
3447 reader .SetFileName (filepath )
3548 reader .Update ()
@@ -116,7 +129,7 @@ def visualize_vtu(
116129 arrows_saturations .InsertTuple1 (i , arrow_saturation )
117130 arrows_condW .InsertTuple1 (i , 0 )
118131 arrows_condO .InsertTuple1 (i , 0 )
119- arrows_direction .InsertTuple3 (i , 0 , 0 , 1 )
132+ arrows_direction .InsertTuple3 (i , arrow_x , arrow_y , arrow_z )
120133 arrows_position .InsertTuple3 (i , * arrow_position )
121134 arrows_type .InsertTuple1 (i , ARROW_TYPE )
122135 arrows_id .InsertTuple1 (i , object_id )
@@ -193,13 +206,17 @@ def visualize_vtu(
193206 return pressure , merger
194207
195208
196- def generate_model_variable_scalar (temp_folder , is_multiscale = False ):
209+ def generate_model_variable_scalar (temp_folder , is_multiscale = False , ** kwargs ):
197210 file_names = sorted ([i for i in os .listdir (temp_folder ) if i [- 4 :] == ".vtu" ])
198211
199212 pressures = []
200213 base_filepath = os .path .join (temp_folder , file_names [0 ])
201- pressure , pore_mesh = visualize_vtu (
202- base_filepath , create_model = False , cycle = file_names [0 ][2 ].lower (), normalize_radius = is_multiscale
214+ pressure , pore_mesh = _visualize_vtu (
215+ base_filepath ,
216+ create_model = False ,
217+ cycle = file_names [0 ][2 ].lower (),
218+ normalize_radius = is_multiscale ,
219+ ** kwargs ,
203220 )
204221 point_data = pore_mesh .GetOutput ().GetPointData ()
205222 pressures .append (pressure )
@@ -214,8 +231,12 @@ def generate_model_variable_scalar(temp_folder, is_multiscale=False):
214231
215232 for data_point , file_name in enumerate (file_names [1 :], start = 1 ):
216233 filepath = os .path .join (temp_folder , file_name )
217- pressure , poly_data = visualize_vtu (
218- filepath , cycle = file_name [2 ].lower (), create_model = False , normalize_radius = is_multiscale
234+ pressure , poly_data = _visualize_vtu (
235+ filepath ,
236+ cycle = file_name [2 ].lower (),
237+ create_model = False ,
238+ normalize_radius = is_multiscale ,
239+ ** kwargs ,
219240 )
220241 saturation = poly_data .GetOutput ().GetPointData ().GetArray ("saturation" )
221242 new_array = vtk .util .numpy_support .vtk_to_numpy (saturation )
@@ -285,6 +306,13 @@ def _unstructured_grid_to_dict(
285306 Returns:
286307 dict: model elements data
287308 """
309+ if axis == "x" :
310+ arrow_displacement_axis = 2
311+ elif axis == "y" :
312+ arrow_displacement_axis = 1
313+ elif axis == "z" :
314+ arrow_displacement_axis = 0
315+
288316 n_points = unstructured_grid .GetNumberOfPoints ()
289317 n_cells = unstructured_grid .GetNumberOfCells ()
290318
@@ -347,8 +375,7 @@ def _unstructured_grid_to_dict(
347375 radius = unstructured_grid .GetPointData ().GetArray ("radius" ).GetComponent (pore_id , 0 )
348376 sw = unstructured_grid .GetPointData ().GetArray ("Sw" ).GetComponent (pore_id , 0 )
349377
350- if axis == "x" :
351- position = position [- 1 ::- 1 ]
378+ position = position [- 1 ::- 1 ]
352379
353380 is_inlet = unstructured_grid .GetPointData ().GetArray ("inlets" ).GetComponent (pore_id , 0 )
354381 if is_inlet == 1 :
@@ -400,9 +427,11 @@ def _unstructured_grid_to_dict(
400427 volume_side = volume ** (1.0 / 3.0 )
401428
402429 inlet_arrows_positions = position_list [inlet_bool_list ] * scale_factor
403- inlet_arrows_positions [:, 2 ] -= volume_side * arrow_scale + pore_radius_list [inlet_bool_list ] / 2
430+ inlet_arrows_positions [:, arrow_displacement_axis ] -= (
431+ volume_side * arrow_scale + pore_radius_list [inlet_bool_list ] / 2
432+ )
404433 outlet_arrows_positions = position_list [outlet_bool_list ] * scale_factor
405- outlet_arrows_positions [:, 2 ] += pore_radius_list [outlet_bool_list ] / 2
434+ outlet_arrows_positions [:, arrow_displacement_axis ] += pore_radius_list [outlet_bool_list ] / 2
406435
407436 arrows = []
408437 for i , sw in enumerate (sw_list [inlet_bool_list ]):
0 commit comments