toughanimator 0.1.9__py3-none-any.whl → 0.1.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
toughanimator/run.py CHANGED
@@ -3,23 +3,26 @@ import tough_classes as ta
3
3
  import pandas as pd
4
4
  import matplotlib.pyplot as plt
5
5
 
6
- #dir_name = "unresolved"
7
- dir_name = "test_cases"
8
- case_name = "PetraSim_2D_Conceptual"
6
+ dir_name = "unresolved"
7
+ #dir_name = "test_cases"
8
+ #case_name = "PetraSim_2D_Conceptual"
9
+ #case_name = "cp950_problem"
10
+ case_name = "3D five spot MINC"
9
11
  test_case_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), dir_name)
10
12
 
11
13
  case_dir = os.path.join(test_case_dir, case_name)
12
-
13
- case_dir = r"D:\Projects\202511\dip_left\TRv4"
14
+ case_dir = r"D:\Projects\tough-processing\uwc\tough_case\uwc_polygonal_20251231\PetraSim"
15
+ #case_dir = r"D:\Projects\202511\ta-post\0 Base_res_k"
14
16
  #case_dir = r"D:\Projects\202504\polygonal\poly_test"
15
17
  #case_dir = r"D:\Projects\202507\tough系列output\tough output format\TR_MINC_exe"
16
18
  #case_dir = r"D:\Projects\202508\tough_cases\WW\7_TR_MINC_petrasim2025__5spot"
17
- #case_dir = r"D:\Projects\202508\tough_cases\WW\6_TR_MINC_exe"
19
+ #case_dir = r"D:\Projects\202511\case_TRv4\uwc"
20
+ #case_dir = r"D:\Projects\202501\toughanimator\test_cases\2DCCS 100yrs_RC"
18
21
  reader = ta.vis_reader(case_dir)
19
- #reader.write_eleme_conne()
20
- #reader.write_geometry()
22
+ reader.write_eleme_conne()
23
+ reader.write_geometry()
21
24
  #reader.write_incon()
22
25
  #reader.write_result()
23
- reader.write_all()
26
+ #reader.write_all()
24
27
 
25
28
 
@@ -1,3 +1,4 @@
1
+ import math
1
2
  import os
2
3
  import io
3
4
  import sys
@@ -8,6 +9,7 @@ import pandas as pd
8
9
  from vtkmodules.all import *
9
10
  import pathlib
10
11
  import json
12
+ import chardet
11
13
 
12
14
  from enum import Enum
13
15
 
@@ -69,7 +71,7 @@ class VisVariable:
69
71
  }
70
72
 
71
73
  class VisSetting:
72
- def __init__(self, input_file_paths, out_file_paths, vis_dir, corners_file="unkown", out_format_type=OutType.Unknown, tough_version = ToughVersion.Unknown, vis_types=[VisType.ParaView, VisType.Tecplot], mesh_type=MeshType.RegularGrid, debug=False, eos="ECO2N", minc=False, selected_variables_scalar = [], selected_variables_vector = [] ):
74
+ def __init__(self, input_file_paths, out_file_paths, vis_dir, corners_file="unkown", out_format_type=OutType.Unknown, tough_version = ToughVersion.Unknown, vis_types=[VisType.ParaView, VisType.Tecplot], mesh_type=MeshType.RegularGrid, debug=False, eos="ECO2N", minc=False, selected_variables_scalar = [], selected_variables_vector = [], ngv=False):
73
75
  self.mesh_type = mesh_type
74
76
  self.out_format_type = out_format_type
75
77
  self.vis_types = vis_types
@@ -87,6 +89,7 @@ class VisSetting:
87
89
  self.minc = minc
88
90
  self.selected_variables_scalar = selected_variables_scalar
89
91
  self.selected_variables_vector = selected_variables_vector
92
+ self.ngv = ngv
90
93
 
91
94
 
92
95
  def setBounds(self, x_bounds, y_bounds, z_bounds):
@@ -105,11 +108,39 @@ class vis_reader:
105
108
  if os.path.isdir(case_dir):
106
109
  config_path = os.path.join(case_dir, "config.json")
107
110
  if os.path.exists(config_path):
108
- with open(config_path, "r") as config_file:
111
+ with open(config_path, "r", encoding="latin-1") as config_file:
109
112
  config = json.load(config_file)
113
+
110
114
  else:
111
- print(f"Config file:({config_path}) not found. Please create it.")
112
- sys.exit(1)
115
+
116
+ # find if INFILE or flow.inp under case_dir
117
+ input_files = []
118
+ output_files = []
119
+ corners_file = ""
120
+ for file_name in os.listdir(case_dir):
121
+ if file_name.upper() == "INFILE" or file_name.lower() == "flow.inp":
122
+ input_files.append(file_name)
123
+ if file_name.lower().endswith(".tec"):
124
+ output_files.append(file_name)
125
+
126
+ # if the file name contains "corners"
127
+ if "corners" in file_name.lower():
128
+ corners_file = file_name
129
+
130
+ # atomatically create a config.json file
131
+ config = {
132
+ "case_name": case_dir.split(os.sep)[-1],
133
+ "input_files": input_files,
134
+ "output_files": output_files,
135
+ "corners_file": corners_file
136
+ }
137
+
138
+ # save the file
139
+ with open(config_path, "w", encoding="latin-1") as config_file:
140
+ json.dump(config, config_file, indent=4)
141
+
142
+ #print(f"Config file:({config_path}) not found. Please create it.")
143
+ #sys.exit(1)
113
144
  else:
114
145
  print(f"Case directory:({case_dir}) not found. Please check it.")
115
146
  sys.exit(1)
@@ -130,16 +161,22 @@ class vis_reader:
130
161
  vis_dir = config["vis_dir"] if "vis_dir" in config else case_dir,
131
162
  corners_file = os.path.join(case_dir, config["corners_file"] if "corners_file" in config else "None"),
132
163
  debug = config['debug'] if 'debug' in config else False,
133
- eos = config['EOS'] if 'EOS' in config else "ECO2N",
134
- minc = config['MINC'] if 'MINC' in config else False,
164
+ #eos = config['EOS'] if 'EOS' in config else "ECO2N",
165
+ eos = next((v for k, v in config.items() if k.lower() == "eos"),"ECO2N"),
166
+ #minc = config['MINC'] if 'MINC' in config else False,
167
+ minc = next((v for k, v in config.items() if k.lower() == "minc"),False),
135
168
  selected_variables_scalar = config['selected_variables_scalar'] if 'selected_variables_scalar' in config else [],
136
- selected_variables_vector = config['selected_variables_vector'] if 'selected_variables_vector' in config else []
169
+ selected_variables_vector = config['selected_variables_vector'] if 'selected_variables_vector' in config else [],
170
+ #ngv= config['NGV'] if 'NGV' in config else False
171
+ ngv = next((v for k, v in config.items() if k.lower() == "ngv"),False)
137
172
  )
138
173
 
139
174
  # check if the project is using MINC
140
175
  minc_file = os.path.join(case_dir, 'MINC')
141
176
  if os.path.exists(minc_file):
142
177
  setting.minc = True
178
+ self.minc_file = minc_file
179
+ self.__check_num_of_minc()
143
180
  if minc_file in setting.input_file_paths:
144
181
  setting.input_file_paths.remove(minc_file)
145
182
 
@@ -229,6 +266,8 @@ class vis_reader:
229
266
  # add post calculation
230
267
  for timestep in self.time_steps_list:
231
268
  self.__post_process(timestep)
269
+ if self.setting.ngv:
270
+ self.__post_process_ngv(timestep)
232
271
  self.__write_json()
233
272
  print(f'All files have been created in {self.setting.vis_dir}.')
234
273
 
@@ -266,7 +305,8 @@ class vis_reader:
266
305
  has_elem = False
267
306
  for input_file_path in self.setting.input_file_paths:
268
307
  line_counter = 0
269
- with open(input_file_path) as f:
308
+ with open(input_file_path, "r", encoding="latin-1") as f:
309
+
270
310
  reading_elem = False
271
311
 
272
312
  for line in f:
@@ -289,6 +329,26 @@ class vis_reader:
289
329
  sys.exit(1)
290
330
  else:
291
331
  print(f' Found ELEME block in {found_path}')
332
+ def __check_num_of_minc(self):
333
+ #self.minc_buffer = io.StringIO()
334
+ minc_num = 0
335
+ with open(self.minc_file, "r", encoding="latin-1") as f:
336
+ reading_minc = False
337
+ for line in f:
338
+ if line.startswith('ELEME-') or line.startswith('ELEME'):
339
+ reading_minc = True
340
+ #has_minc = True
341
+ continue
342
+ if reading_minc:
343
+
344
+ if self.__check_if_block_end(line, minc_num):
345
+ reading_minc = False
346
+ #found_path = input_file_path
347
+ break
348
+ else:
349
+ minc_num += 1
350
+ #self.minc_buffer.write(line)
351
+ self.num_of_minc = minc_num
292
352
 
293
353
  def __write_conne_buffer(self):
294
354
  self.conne_buffer = io.StringIO()
@@ -296,7 +356,7 @@ class vis_reader:
296
356
  has_conne = False
297
357
  for input_file_path in self.setting.input_file_paths:
298
358
  line_counter = 0
299
- with open(input_file_path) as f:
359
+ with open(input_file_path, "r", encoding="latin-1") as f:
300
360
 
301
361
  reading_conne = False
302
362
  for line in f:
@@ -326,7 +386,7 @@ class vis_reader:
326
386
 
327
387
  for input_file_path in self.setting.input_file_paths:
328
388
  line_counter = 0
329
- with open(input_file_path) as f:
389
+ with open(input_file_path, "r", encoding="latin-1") as f:
330
390
  reading_rocks = False
331
391
  for line in f:
332
392
  if line.startswith('ROCKS-'):
@@ -367,7 +427,7 @@ class vis_reader:
367
427
 
368
428
  for input_file_path in self.setting.input_file_paths:
369
429
  line_counter = 0
370
- with open(input_file_path) as f:
430
+ with open(input_file_path, "r", encoding="latin-1") as f:
371
431
 
372
432
  reading_incon = False
373
433
  for line in f:
@@ -385,9 +445,9 @@ class vis_reader:
385
445
  #line = f.readline() # skip first line #self.number_of_elements
386
446
  eos = self.setting.eos
387
447
  num = len(line.split())
388
- if self.setting.eos == "ECO2N" and len(line.split()) == 4:
448
+ if self.setting.eos.upper() == "ECO2N" and len(line.split()) == 4:
389
449
  self.incon_buffer.write(line)
390
- elif self.setting.eos == "EOS1":
450
+ elif self.setting.eos.upper() == "EOS1":
391
451
  line = f.readline() # skip first line #self.number_of_elements
392
452
  if len(line.split()) == 2:
393
453
  self.incon_buffer.write(line)
@@ -400,7 +460,7 @@ class vis_reader:
400
460
  reading_pram = False
401
461
  for input_file_path in self.setting.input_file_paths:
402
462
  line_counter = 0
403
- with open(input_file_path) as f:
463
+ with open(input_file_path, "r", encoding="latin-1") as f:
404
464
  reading_pram = False
405
465
  for line in f:
406
466
  if line.startswith('PARAM-'):
@@ -430,14 +490,14 @@ class vis_reader:
430
490
 
431
491
  self.incon_buffer.seek(0)
432
492
  incon_df = pd.DataFrame()
433
- if self.setting.eos == "ECO2N":
493
+ if self.setting.eos.upper() == "ECO2N":
434
494
  # read incon
435
495
  incon_colspecs = [(0, 20), (20, 40), (40, 60), (60, 80)] # define column widths
436
496
  incon_names = ['Pressure', 'NaCl', 'CO2', 'Temperature']
437
497
  incon_df = pd.read_fwf(self.incon_buffer, colspecs=incon_colspecs, header=None,
438
498
  names=incon_names,
439
499
  dtype={'Pressure':float, 'NaCl':float, 'CO2':float, 'Temperature':float})
440
- elif self.setting.eos == "EOS1":
500
+ elif self.setting.eos.upper() == "EOS1":
441
501
  # read incon
442
502
  incon_colspecs = [(0, 20), (20, 40)]
443
503
  incon_names = ['Temperature', 'Pressure']
@@ -501,7 +561,7 @@ class vis_reader:
501
561
  buffer.flush()
502
562
  buffer.close()
503
563
 
504
- with open(self.current_out_file) as f:
564
+ with open(self.current_out_file, "r", encoding="latin-1") as f:
505
565
  for line in f:
506
566
  line_number = line_number + 1
507
567
  values = line.strip().split(',')
@@ -557,7 +617,7 @@ class vis_reader:
557
617
  start_index = -1
558
618
  self.time_steps_list = []
559
619
 
560
- with open(self.current_out_file) as f:
620
+ with open(self.current_out_file, "r", encoding="latin-1") as f:
561
621
  for line in f:
562
622
  line_number = line_number + 1
563
623
  values = line.strip().split(',')
@@ -643,8 +703,8 @@ class vis_reader:
643
703
  value_type = ValueType.Unknown
644
704
  start_index = -1
645
705
  self.time_steps_list = []
646
-
647
- with open(self.current_out_file) as f:
706
+
707
+ with open(self.current_out_file, "r", encoding="latin-1") as f:
648
708
  for line in f:
649
709
  line_number = line_number + 1
650
710
  values = line.strip().split(',')
@@ -729,7 +789,8 @@ class vis_reader:
729
789
  reading_scalar = False
730
790
  scalar_headers = []
731
791
  self.time_steps_list = []
732
- with open(self.current_out_file) as f:
792
+
793
+ with open(self.current_out_file, "r", encoding="latin-1") as f:
733
794
  for line in f:
734
795
  if line.strip().lower().startswith('Variables'.lower()):
735
796
  headers_value = line.strip().split('=')[1]
@@ -929,6 +990,172 @@ class vis_reader:
929
990
  self.variable_list["post"] = post_variable_list
930
991
  self.__write_vtk_file(vtr, vtr_path)
931
992
 
993
+ def __post_process_ngv(self, vis_time_step):
994
+
995
+ #self.rock_dict
996
+ post_variable_list = []
997
+ if self.setting.mesh_type != MeshType.RegularGrid:
998
+ print(' NGV post-processing is only available for RegularGrid mesh.')
999
+ return
1000
+
1001
+
1002
+ time_index = self.time_steps_list.index(vis_time_step)
1003
+ #vtr_path = os.path.join(self.setting.vis_dir, 'paraview', f'time_step_{vis_time_step.time_step}.vtr')
1004
+
1005
+ extension = os.path.splitext(self.main_geometry)[1]
1006
+ vtr_path = os.path.join(self.setting.vis_dir, 'paraview', f'time_step_{vis_time_step.time_step}{extension}')
1007
+ self.time_steps_list[time_index].vtu_file_name = vtr_path
1008
+ scalar_vtr = self.__read_vtk_file(vtr_path)
1009
+ vtr = scalar_vtr
1010
+
1011
+
1012
+ vtr_dimemsion = scalar_vtr.GetDimensions()
1013
+ cell_index = 0
1014
+ matIDArray = vtr.GetCellData().GetArray('Material_ID')
1015
+
1016
+ G = 9.81
1017
+ Pc = 3000
1018
+ # creare vtk double array 'ut','delta_p','Ncv_k1','Ncv_k2','Ncv_k3','Ngv_k1','Ngv_k2','Ngv_k3','Nb','R1'
1019
+
1020
+ Ncv_k1_array = vtkDoubleArray()
1021
+ Ncv_k1_array.SetName('Ncv_k1')
1022
+ vtr.GetCellData().AddArray(Ncv_k1_array)
1023
+ Ncv_k2_array = vtkDoubleArray()
1024
+ Ncv_k2_array.SetName('Ncv_k2')
1025
+ vtr.GetCellData().AddArray(Ncv_k2_array)
1026
+ Ncv_k3_array = vtkDoubleArray()
1027
+ Ncv_k3_array.SetName('Ncv_k3')
1028
+ vtr.GetCellData().AddArray(Ncv_k3_array)
1029
+ Ngv_k1_array = vtkDoubleArray()
1030
+ Ngv_k1_array.SetName('Ngv_k1')
1031
+ vtr.GetCellData().AddArray(Ngv_k1_array)
1032
+ Ngv_k2_array = vtkDoubleArray()
1033
+ Ngv_k2_array.SetName('Ngv_k2')
1034
+ vtr.GetCellData().AddArray(Ngv_k2_array)
1035
+ Ngv_k3_array = vtkDoubleArray()
1036
+ Ngv_k3_array.SetName('Ngv_k3')
1037
+ vtr.GetCellData().AddArray(Ngv_k3_array)
1038
+ Nb_array = vtkDoubleArray()
1039
+ Nb_array.SetName('Nb')
1040
+ vtr.GetCellData().AddArray(Nb_array)
1041
+ R1_array = vtkDoubleArray()
1042
+ R1_array.SetName('R1')
1043
+ vtr.GetCellData().AddArray(R1_array)
1044
+
1045
+ post_variable_list.append(VisVariable('Ncv_k1', ValueType.Scalar, 1))
1046
+ post_variable_list.append(VisVariable('Ncv_k2', ValueType.Scalar, 1))
1047
+ post_variable_list.append(VisVariable('Ncv_k3', ValueType.Scalar, 1))
1048
+ post_variable_list.append(VisVariable('Ngv_k1', ValueType.Scalar, 1))
1049
+ post_variable_list.append(VisVariable('Ngv_k2', ValueType.Scalar, 1))
1050
+ post_variable_list.append(VisVariable('Ngv_k3', ValueType.Scalar, 1))
1051
+ post_variable_list.append(VisVariable('Nb', ValueType.Scalar, 1))
1052
+ post_variable_list.append(VisVariable('R1', ValueType.Scalar, 1))
1053
+
1054
+
1055
+ # check if the required arrays are in the vtk file
1056
+ vis_gas_array = vtkDoubleArray()
1057
+ vis_gas_name = 'VIS(gas)'
1058
+ if vtr.GetCellData().GetArray(vis_gas_name) is not None:
1059
+ vis_gas_array = vtr.GetCellData().GetArray(vis_gas_name)
1060
+ else:
1061
+ print(f' Can\'t find {vis_gas_name} array in the vtk file for NGV post-processing.')
1062
+ return
1063
+
1064
+ dl_array = vtkDoubleArray()
1065
+ dl_name = 'DL (kg/m^3)'
1066
+ if vtr.GetCellData().GetArray(dl_name) is not None:
1067
+ dl_array = vtr.GetCellData().GetArray(dl_name)
1068
+ else:
1069
+ print(f' Can\'t find {dl_name} array in the vtk file for NGV post-processing.')
1070
+ return
1071
+
1072
+ dg_array = vtkDoubleArray()
1073
+ dg_name = 'DG (kg/m^3)'
1074
+ if vtr.GetCellData().GetArray(dg_name) is not None:
1075
+ dg_array = vtr.GetCellData().GetArray(dg_name)
1076
+ else:
1077
+ print(f' Can\'t find {dg_name} array in the vtk file for NGV post-processing.')
1078
+ return
1079
+
1080
+ flof_array = vtkDoubleArray()
1081
+ flof_name = 'FLOF (kg/s)'
1082
+ if vtr.GetCellData().GetArray(flof_name) is not None:
1083
+ flof_array = vtr.GetCellData().GetArray(flof_name)
1084
+ else:
1085
+ print(f' Can\'t find {flof_name} array in the vtk file for NGV post-processing.')
1086
+ return
1087
+
1088
+
1089
+
1090
+ for z_index in range(0, vtr_dimemsion[2]-1):
1091
+ for y_index in range(0, vtr_dimemsion[1]-1):
1092
+ for x_index in range(0, vtr_dimemsion[0]-1):
1093
+ dx = vtr.GetXCoordinates().GetValue(x_index+1) - vtr.GetXCoordinates().GetValue(x_index)
1094
+ dy = vtr.GetYCoordinates().GetValue(y_index+1) - vtr.GetYCoordinates().GetValue(y_index)
1095
+ #dz = vtr.GetZCoordinates().GetValue(z_index+1) - vtr.GetZCoordinates().GetValue(z_index)
1096
+
1097
+
1098
+ #elemID = self..GetValue(cell_index)
1099
+ matID = matIDArray.GetValue(cell_index)
1100
+ # find rock from self.rock_dict with id = matID
1101
+ #rock = [obj for obj in self.rock_dict if obj.id == matID]
1102
+
1103
+ rock = next((o for o in self.rock_dict if o["id"] == matID), None)
1104
+ per_1 = rock["per_1"] if rock else 0
1105
+ per_2 = rock["per_2"] if rock else 0
1106
+ per_3 = rock["per_3"] if rock else 0
1107
+
1108
+ #df['μCO2'] = df['VIS(gas)']
1109
+ μCO2 = vis_gas_array.GetValue(cell_index)
1110
+ #df['delta_p'] = df['DL (kg/m^3)'] - df['DG (kg/m^3)']
1111
+ delta_p = dl_array.GetValue(cell_index) - dg_array.GetValue(cell_index)
1112
+ #df['ut'] = np.sqrt(df['FLOF (kg/s)_x']**2 + df['FLOF (kg/s)_y']**2 + df['FLOF (kg/s)_z']**2)
1113
+ FLOF = flof_array.GetTuple(cell_index)
1114
+
1115
+ ut = math.sqrt(FLOF[0]**2 + FLOF[1]**2 + FLOF[2]**2)
1116
+
1117
+ #df['Ncv_k1'] = (df['k1'] * df[L] * df['Pc'] )/(df[H]**2 * df['μCO2'] * df['ut'])
1118
+ #df['Ncv_k2'] = (df['k2'] * df[L] * df['Pc'] )/(df[H]**2 * df['μCO2'] * df['ut'])
1119
+ #df['Ncv_k3'] = (df['k3'] * df[L] * df['Pc'] )/(df[H]**2 * df['μCO2'] * df['ut'])
1120
+ #df['Ngv_k1'] = (df['delta_p'] * df['G'] * df['k1'] * df['d_x'])/(df[H] * df['μCO2'] * df['ut'])
1121
+ #df['Ngv_k2'] = (df['delta_p'] * df['G'] * df['k2'] * df['d_x'])/(df[H] * df['μCO2'] * df['ut'])
1122
+ #df['Ngv_k3'] = (df['delta_p'] * df['G'] * df['k3'] * df['d_x'])/(df[H] * df['μCO2'] * df['ut'])
1123
+
1124
+ L = dx
1125
+ H = dy
1126
+ k1 = per_1
1127
+ k2 = per_2
1128
+ k3 = per_3
1129
+ Ncv_k1 = (k1 * L * Pc )/(H**2 * μCO2 * ut) if (H**2 * μCO2 * ut) !=0 else 0
1130
+ Ncv_k2 = (k2 * L * Pc )/(H**2 * μCO2 * ut) if (H**2 * μCO2 * ut) !=0 else 0
1131
+ Ncv_k3 = (k3 * L * Pc )/(H**2 * μCO2 * ut) if (H**2 * μCO2 * ut) !=0 else 0
1132
+ Ngv_k1 = (delta_p * G * k1 * dx)/(H * μCO2 * ut) if (H * μCO2 * ut) !=0 else 0
1133
+ Ngv_k2 = (delta_p * G * k2 * dx)/(H * μCO2 * ut) if (H * μCO2 * ut) !=0 else 0
1134
+ Ngv_k3 = (delta_p * G * k3 * dx)/(H * μCO2 * ut) if (H * μCO2 * ut) !=0 else 0
1135
+
1136
+ #df['Nb'] =(df['delta_p'] * df['G'] * df[H])/df['Pc']
1137
+ Nb =(delta_p * G * H)/Pc if Pc !=0 else 0
1138
+ #df['R1'] = df[L]/df[H]
1139
+ R1 = L/H if H !=0 else 0
1140
+ Ncv_k1_array.InsertNextValue(Ncv_k1)
1141
+ Ncv_k2_array.InsertNextValue(Ncv_k2)
1142
+ Ncv_k3_array.InsertNextValue(Ncv_k3)
1143
+ Ngv_k1_array.InsertNextValue(Ngv_k1)
1144
+ Ngv_k2_array.InsertNextValue(Ngv_k2)
1145
+ Ngv_k3_array.InsertNextValue(Ngv_k3)
1146
+ Nb_array.InsertNextValue(Nb)
1147
+ R1_array.InsertNextValue(R1)
1148
+ cell_index += 1
1149
+
1150
+ #for z_index in range(0, scalar_vtr.GetZCoordinates().GetNumberOfTuples()):
1151
+
1152
+
1153
+ #if len(post_variable_list) > 0:
1154
+ #self.variable_list["post"].append(post_variable_list)
1155
+ self.__write_vtk_file(vtr, vtr_path)
1156
+
1157
+
1158
+
932
1159
 
933
1160
  def __write_scalar_result(self, vis_time_step, dataframe, csv_headers):
934
1161
 
@@ -981,15 +1208,18 @@ class vis_reader:
981
1208
 
982
1209
  #if self.setting.minc:
983
1210
  #print(f' MinC is enabled. Adding MinC values to the result.')
1211
+ minc_ratio = 1
1212
+ if self.setting.minc:
1213
+ minc_ratio = self.num_of_minc / self.number_of_elements
984
1214
 
985
1215
  for i in range(0, vtr.GetNumberOfCells()):
986
1216
  elemID = self.elemIDArray.GetValue(i)
1217
+
987
1218
  index = self.sequence_dist[i]
988
1219
  if 'ELEM' in dataframe.columns:
989
1220
  index = dataframe['ELEM'].tolist().index(elemID)
990
- #elem_string = dataframe['ELEM'].iloc[index]
991
- #target_row = dataframe.iloc[index]
992
- #print(f' Processing ELEM {elem_string} at index {index}')
1221
+ else:
1222
+ index = int(index * minc_ratio)
993
1223
  for header in headers:
994
1224
  value = float(self.__parse_float(dataframe[header].iloc[index]))
995
1225
  vtr.GetCellData().GetArray(header).InsertNextValue(value)
@@ -1027,7 +1257,7 @@ class vis_reader:
1027
1257
  firstFile = True
1028
1258
  if os.path.isfile(self.tec_scalar_path):
1029
1259
  firstFile = False
1030
- file = open(self.tec_scalar_path, "a")
1260
+ file = open(self.tec_scalar_path, "a", encoding="utf-8")
1031
1261
  if len(self.setting.selected_variables_scalar) == 0:
1032
1262
  self.setting.selected_variables_scalar = headers
1033
1263
 
@@ -1223,7 +1453,7 @@ class vis_reader:
1223
1453
  firstFile = True
1224
1454
  if os.path.isfile(self.tec_vector_path):
1225
1455
  firstFile = False
1226
- file = open(self.tec_vector_path, "a")
1456
+ file = open(self.tec_vector_path, "a", encoding="utf-8")
1227
1457
 
1228
1458
  #selected_header_string = '"'+'", "'.join(self.setting.selected_variables_scalar) + '"'
1229
1459
  if len(self.setting.selected_variables_vector) == 0:
@@ -1550,7 +1780,7 @@ class vis_reader:
1550
1780
  corners_buffer = io.StringIO()
1551
1781
  csv_headers = []
1552
1782
  line_number = -1
1553
- with open(self.setting.corners_file) as f:
1783
+ with open(self.setting.corners_file, "r", encoding="latin-1") as f:
1554
1784
  for line in f:
1555
1785
  line_number = line_number + 1
1556
1786
  values = line.strip().split(',')
@@ -2341,7 +2571,7 @@ class vis_reader:
2341
2571
  elif extension == '.csv':
2342
2572
  self.setting.out_format_type = OutType.CSV
2343
2573
  line_number = 0
2344
- with open(out_file_path) as f:
2574
+ with open(out_file_path, "r", encoding="latin-1") as f:
2345
2575
  for line in f:
2346
2576
  if line_number == 0:
2347
2577
  first_col = line.split(',')[0].strip().lower()
@@ -2392,7 +2622,7 @@ class vis_reader:
2392
2622
 
2393
2623
  # Write to JSON file
2394
2624
  path = os.path.join(self.setting.vis_dir, "variable_list.json")
2395
- with open(path, "w") as f:
2625
+ with open(path, "w", encoding="utf-8") as f:
2396
2626
  json.dump(variable_list_dicts, f, indent=2)
2397
2627
 
2398
2628
  timestep_list_dicts = [timestep.__dict__ for timestep in self.time_steps_list]
@@ -2400,7 +2630,7 @@ class vis_reader:
2400
2630
 
2401
2631
  # Write to JSON file
2402
2632
  path = os.path.join(self.setting.vis_dir, "timestep_list.json")
2403
- with open(path, "w") as f:
2633
+ with open(path, "w", encoding="utf-8") as f:
2404
2634
  json.dump(timestep_list_dicts, f, indent=2)
2405
2635
 
2406
2636
  def __fix_negative_zero(self, x):
@@ -2421,7 +2651,7 @@ class vis_charting:
2421
2651
 
2422
2652
  variable_list_path = os.path.join(case_dir, "tough_vis", "variable_list.json")
2423
2653
  if os.path.isfile(variable_list_path):
2424
- with open(variable_list_path, "r") as f:
2654
+ with open(variable_list_path, "r", encoding="latin-1") as f:
2425
2655
  self.variable_list = json.load(f)
2426
2656
  else:
2427
2657
  print(f'Case variable_list.json({variable_list_path}) not found.')
@@ -2429,7 +2659,7 @@ class vis_charting:
2429
2659
 
2430
2660
  timestep_list_path = os.path.join(case_dir, "tough_vis", "timestep_list.json")
2431
2661
  if os.path.isfile(timestep_list_path):
2432
- with open(timestep_list_path, "r") as f:
2662
+ with open(timestep_list_path, "r", encoding="latin-1") as f:
2433
2663
  self.time_steps_list = json.load(f)
2434
2664
  else:
2435
2665
  print(f'Case timestep_list.json({timestep_list_path}) not found.')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toughanimator
3
- Version: 0.1.9
3
+ Version: 0.1.11
4
4
  Summary: A tool for visualizing TOUGH simulation outputs.
5
5
  Home-page: https://github.com/scarletref/toughanimator
6
6
  Author: scarletref
@@ -0,0 +1,7 @@
1
+ toughanimator/__init__.py,sha256=m1f3fJ1SNGLNKxHlS0pLNHwaHlN6UUTh5GpS_8hC8kw,30
2
+ toughanimator/run.py,sha256=20BqrpQyNxdGPlcKFYoiQ8nFGamjDhUYhdmWlQOnIok,1038
3
+ toughanimator/tough_classes.py,sha256=l3nK8wMItvGqBluEsSmUtSilhmlvcnDZbyh6HVRV4JI,124404
4
+ toughanimator-0.1.11.dist-info/METADATA,sha256=Leu6KwBBGVzaiwqNZU73aQ7M6H2NgZc8UBVjZQk1Klk,4571
5
+ toughanimator-0.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ toughanimator-0.1.11.dist-info/top_level.txt,sha256=pAT-UflvbjT4lTmBdzHqApZGWbywkSM3Y_qsHyLi4pU,14
7
+ toughanimator-0.1.11.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- toughanimator/__init__.py,sha256=m1f3fJ1SNGLNKxHlS0pLNHwaHlN6UUTh5GpS_8hC8kw,30
2
- toughanimator/run.py,sha256=LplSjwo8it2cLGZM3GAwah1UvJ5FGrpsloF6A3z2gsU,817
3
- toughanimator/tough_classes.py,sha256=jjxuG59vo6uqGYHIsKMp2dIeBnyPFyYCqCRGyj3N5V0,113089
4
- toughanimator-0.1.9.dist-info/METADATA,sha256=l-JeJLpgOdo_-nqpTq0TAgbRWt6FHGgGrZ2e3Nw8gJE,4570
5
- toughanimator-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- toughanimator-0.1.9.dist-info/top_level.txt,sha256=pAT-UflvbjT4lTmBdzHqApZGWbywkSM3Y_qsHyLi4pU,14
7
- toughanimator-0.1.9.dist-info/RECORD,,