toughanimator 0.1.11__tar.gz → 0.1.13__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toughanimator
3
- Version: 0.1.11
3
+ Version: 0.1.13
4
4
  Summary: A tool for visualizing TOUGH simulation outputs.
5
5
  Home-page: https://github.com/scarletref/toughanimator
6
6
  Author: scarletref
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='toughanimator', # Package name on PyPI
5
- version='0.1.11',
5
+ version='0.1.13',
6
6
  description='A tool for visualizing TOUGH simulation outputs.',
7
7
  long_description=open('README.md').read(),
8
8
  long_description_content_type='text/markdown',
@@ -11,7 +11,8 @@ case_name = "3D five spot MINC"
11
11
  test_case_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), dir_name)
12
12
 
13
13
  case_dir = os.path.join(test_case_dir, case_name)
14
- case_dir = r"D:\Projects\tough-processing\uwc\tough_case\uwc_polygonal_20251231\PetraSim"
14
+ case_dir = r"D:\Projects\202601\0 Base_res_k"
15
+ #case_dir = r"D:\Projects\202601\260123_UWC_homo"
15
16
  #case_dir = r"D:\Projects\202511\ta-post\0 Base_res_k"
16
17
  #case_dir = r"D:\Projects\202504\polygonal\poly_test"
17
18
  #case_dir = r"D:\Projects\202507\tough系列output\tough output format\TR_MINC_exe"
@@ -19,10 +20,10 @@ case_dir = r"D:\Projects\tough-processing\uwc\tough_case\uwc_polygonal_20251231\
19
20
  #case_dir = r"D:\Projects\202511\case_TRv4\uwc"
20
21
  #case_dir = r"D:\Projects\202501\toughanimator\test_cases\2DCCS 100yrs_RC"
21
22
  reader = ta.vis_reader(case_dir)
22
- reader.write_eleme_conne()
23
- reader.write_geometry()
23
+ #reader.write_eleme_conne()
24
+ #reader.write_geometry()
24
25
  #reader.write_incon()
25
26
  #reader.write_result()
26
- #reader.write_all()
27
+ reader.write_all()
27
28
 
28
29
 
@@ -9,7 +9,6 @@ import pandas as pd
9
9
  from vtkmodules.all import *
10
10
  import pathlib
11
11
  import json
12
- import chardet
13
12
 
14
13
  from enum import Enum
15
14
 
@@ -71,7 +70,7 @@ class VisVariable:
71
70
  }
72
71
 
73
72
  class VisSetting:
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
+ 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, trap=False):
75
74
  self.mesh_type = mesh_type
76
75
  self.out_format_type = out_format_type
77
76
  self.vis_types = vis_types
@@ -90,6 +89,7 @@ class VisSetting:
90
89
  self.selected_variables_scalar = selected_variables_scalar
91
90
  self.selected_variables_vector = selected_variables_vector
92
91
  self.ngv = ngv
92
+ self.trap = trap
93
93
 
94
94
 
95
95
  def setBounds(self, x_bounds, y_bounds, z_bounds):
@@ -107,7 +107,7 @@ class vis_reader:
107
107
  self.rock_dict = []
108
108
  if os.path.isdir(case_dir):
109
109
  config_path = os.path.join(case_dir, "config.json")
110
- if os.path.exists(config_path):
110
+ if os.path.isfile(config_path):
111
111
  with open(config_path, "r", encoding="latin-1") as config_file:
112
112
  config = json.load(config_file)
113
113
 
@@ -168,7 +168,8 @@ class vis_reader:
168
168
  selected_variables_scalar = config['selected_variables_scalar'] if 'selected_variables_scalar' in config else [],
169
169
  selected_variables_vector = config['selected_variables_vector'] if 'selected_variables_vector' in config else [],
170
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)
171
+ ngv = next((v for k, v in config.items() if k.lower() == "ngv"),False),
172
+ trap= next((v for k, v in config.items() if k.lower() == "trap"),False)
172
173
  )
173
174
 
174
175
  # check if the project is using MINC
@@ -407,10 +408,15 @@ class vis_reader:
407
408
 
408
409
  #skip 1 lines
409
410
  f.readline()
410
- third_line = f.readline()
411
- new_line = f'{first_line}{third_line}'
412
- self.rocks_buffer.write(new_line)
413
411
  f.readline()
412
+ forth_line = f.readline() # read forth line
413
+ if len(forth_line) < 30:
414
+ # create a line with fixed lenth dafault value
415
+ values = [8, 0, 0.03]
416
+ forth_line = "".join(f"{v:10.3f}" for v in values)
417
+ new_line = f'{first_line}{forth_line}' # merge first and forth line
418
+ self.rocks_buffer.write(new_line)
419
+
414
420
 
415
421
 
416
422
  if has_rocks == False:
@@ -852,8 +858,8 @@ class vis_reader:
852
858
  extension = os.path.splitext(self.main_geometry)[1]
853
859
  vtr_path = os.path.join(self.setting.vis_dir, 'paraview', f'time_step_{vis_time_step.time_step}{extension}')
854
860
  self.time_steps_list[time_index].vtu_file_name = vtr_path
855
- scalar_vtr = self.__read_vtk_file(vtr_path)
856
- vtr = scalar_vtr
861
+ vtr = self.__read_vtk_file(vtr_path)
862
+
857
863
 
858
864
  post_variable_list = []
859
865
  # p
@@ -890,7 +896,8 @@ class vis_reader:
890
896
 
891
897
 
892
898
  # add toughreact variables
893
- if self.setting.tough_version == ToughVersion.TOUGHReact or self.setting.tough_version == ToughVersion.TOUGH3:
899
+ #if self.setting.tough_version == ToughVersion.TOUGHReact or self.setting.tough_version == ToughVersion.TOUGH3:
900
+ if self.setting.trap:
894
901
  trapHCO2_array = vtkDoubleArray()
895
902
  trapHCO2_array.SetName('trapHCO2')
896
903
 
@@ -903,49 +910,94 @@ class vis_reader:
903
910
  trapMCO2_array = vtkDoubleArray()
904
911
  trapMCO2_array.SetName('trapMCO2')
905
912
 
913
+
914
+
915
+ # 1. Saturation of gas
916
+ sat_gas_array = None
917
+ sat_gas_names = ["SatGas", "SAT_G", "SG"]
918
+ for sat_gas_name in sat_gas_names:
919
+ if vtr.GetCellData().GetArray(sat_gas_name) is not None:
920
+ sat_gas_array = vtr.GetCellData().GetArray(sat_gas_name)
921
+ if sat_gas_array is None:
922
+ print(f' ⚠️ Can\'t find gas saturation array (SatGas/SAT_G/SG). Skipping trap calculations.')
923
+ return
924
+
925
+ # 2. Porosity
926
+ porosity_array = None
927
+ porosity_names = ["Porosity", "POR"] # if not found, try Rock_dict # TODO:異質性考慮
928
+ for porosity_name in porosity_names:
929
+ if vtr.GetCellData().GetArray(porosity_name) is not None:
930
+ porosity_array = vtr.GetCellData().GetArray(porosity_name)
931
+ if porosity_array is None:
932
+ porosity_array = vtr.GetCellData().GetArray("rock_por")
933
+ if porosity_array is None:
934
+ print(f' ⚠️ Can\'t find porosity array (Porosity/POR). Skipping trap calculations.')
935
+ return
936
+
937
+ # 3. Gas density
938
+ dgas_kg_m3_array = None
939
+ dgas_names = ["DGas_kg/m3", "DEN_G", "DG (kg/m^3)"]
940
+ for dgas_name in dgas_names:
941
+ if vtr.GetCellData().GetArray(dgas_name) is not None:
942
+ dgas_kg_m3_array = vtr.GetCellData().GetArray(dgas_name)
943
+ if dgas_kg_m3_array is None:
944
+ print(f' ⚠️ Can\'t find gas density array (DGas_kg/m3/DEN_G). Skipping trap calculations.')
945
+ return
946
+
947
+ # 4. Liquid saturation (if not, 1-SG)
948
+ sat_liq_array = None
949
+ sat_liq_names = ["SatLiq", "SAT_L"]
950
+ for sat_liq_name in sat_liq_names:
951
+ if vtr.GetCellData().GetArray(sat_liq_name) is not None:
952
+ sat_liq_array = vtr.GetCellData().GetArray(sat_liq_name)
953
+ if sat_liq_array is None:
954
+ if sat_gas_array is not None:
955
+ sat_liq_array = vtkDoubleArray()
956
+ for index in range(0, vtr.GetNumberOfCells()):
957
+ sat_liq_value = 1 - sat_gas_array.GetValue(index)
958
+ sat_liq_array.InsertNextValue(sat_liq_value)
959
+ else:
960
+ print(f' ⚠️ Can\'t find liquid saturation array (SatLiq/SAT_L). Skipping trap calculations.')
961
+ return
962
+
963
+ # 5. CO2 concentration in liquid
964
+ xco2_liq_array = None
965
+ xco2_liq_names = ["XCO2Liq", "X_CO2 _L", "XCO2aq"]
966
+ for xco2_liq_name in xco2_liq_names:
967
+ if vtr.GetCellData().GetArray(xco2_liq_name) is not None:
968
+ xco2_liq_array = vtr.GetCellData().GetArray(xco2_liq_name)
969
+ if xco2_liq_array is None:
970
+ print(f' ⚠️ Can\'t find XCO2 in liquid array (XCO2Liq/X_CO2_L). Skipping trap calculations.')
971
+ return
972
+
973
+ # 6. residual gas saturation
974
+ sgr_array = None
975
+ if vtr.GetCellData().GetArray("sgr") is not None: # rock line4 3rd value default = 0.03 user guide:resitual of gas
976
+ sgr_array = vtr.GetCellData().GetArray("sgr")
977
+ if sgr_array is None:
978
+ print(f' ⚠️ Can\'t find residual gas saturation array (sgr). Skipping trap calculations.')
979
+ return
980
+
981
+ # 7. VOLX
982
+ volx_array = None
983
+ if vtr.GetCellData().GetArray("VOLX") is not None:
984
+ volx_array = vtr.GetCellData().GetArray("VOLX")
985
+ else:
986
+ print(f' ⚠️ Can\'t find cell volume array (VOLX). Skipping trap calculations.')
987
+ return
988
+
906
989
  for index in range(0, vtr.GetNumberOfCells()):
907
990
  trapHCO2 = 0
908
991
  trapRCO2 = 0
909
992
  trapDCO2 = 0
910
993
  trapMCO2 = 0
911
- VOLX = 0
912
- if vtr.GetCellData().GetArray("VOLX") is not None:
913
- VOLX = vtr.GetCellData().GetArray("VOLX").GetValue(index)
914
-
915
- SatGas = 0
916
- if vtr.GetCellData().GetArray("SatGas") is not None:
917
- SatGas = vtr.GetCellData().GetArray("SatGas").GetValue(index)
918
- elif vtr.GetCellData().GetArray("SAT_G") is not None:
919
- SatGas = vtr.GetCellData().GetArray("SAT_G").GetValue(index)
920
-
921
- Porosity = 0
922
- if vtr.GetCellData().GetArray("Porosity") is not None:
923
- Porosity = vtr.GetCellData().GetArray("Porosity").GetValue(index)
924
- elif vtr.GetCellData().GetArray("POR") is not None:
925
- Porosity = vtr.GetCellData().GetArray("POR").GetValue(index)
926
-
927
- DGas_kg_m3 = 0
928
- if vtr.GetCellData().GetArray("DGas_kg/m3") is not None:
929
- DGas_kg_m3 = vtr.GetCellData().GetArray("DGas_kg/m3").GetValue(index)
930
- elif vtr.GetCellData().GetArray("DEN_G") is not None:
931
- DGas_kg_m3 = vtr.GetCellData().GetArray("DEN_G").GetValue(index)
932
-
933
- SatLiq = 0
934
- if vtr.GetCellData().GetArray("SatLiq") is not None:
935
- SatLiq = vtr.GetCellData().GetArray("SatLiq").GetValue(index)
936
- elif vtr.GetCellData().GetArray("SAT_L") is not None:
937
- SatLiq = vtr.GetCellData().GetArray("SAT_L").GetValue(index)
938
-
939
- XCO2Liq = 0
940
- if vtr.GetCellData().GetArray("XCO2Liq") is not None:
941
- XCO2Liq = vtr.GetCellData().GetArray("XCO2Liq").GetValue(index)
942
- elif vtr.GetCellData().GetArray("X_CO2_L") is not None:
943
- XCO2Liq = vtr.GetCellData().GetArray("X_CO2_L").GetValue(index)
944
-
945
- sgr = 0
946
- if vtr.GetCellData().GetArray("sgr") is not None:
947
- sgr = vtr.GetCellData().GetArray("sgr").GetValue(index)
948
-
994
+ VOLX = volx_array.GetValue(index)
995
+ SatGas = sat_gas_array.GetValue(index)
996
+ Porosity = porosity_array.GetValue(index)
997
+ DGas_kg_m3 = dgas_kg_m3_array.GetValue(index)
998
+ SatLiq = sat_liq_array.GetValue(index)
999
+ XCO2Liq = xco2_liq_array.GetValue(index)
1000
+ sgr = sgr_array.GetValue(index)
949
1001
 
950
1002
  trapHCO2 =(SatGas-sgr)*VOLX*Porosity*DGas_kg_m3* (SatGas>sgr)
951
1003
  trapRCO2 = 0.05 * VOLX * Porosity * DGas_kg_m3* (SatGas > sgr)+ SatGas * VOLX * Porosity * DGas_kg_m3*(SatGas <= sgr)
@@ -1587,12 +1639,12 @@ class vis_reader:
1587
1639
  '''
1588
1640
  compute permeability
1589
1641
  '''
1590
- rock_colspecs = [(0, 5), (30, 40), (40, 50), (50, 60), (100, 110)] # define column widths
1591
- rock_names = ['MAT', 'PER_1', 'PER_2', 'PER_3', 'SGR']
1642
+ rock_colspecs = [(0, 5), (20, 30), (30, 40), (40, 50), (50, 60), (100, 110)] # define column widths
1643
+ rock_names = ['MAT', 'POR', 'PER_1', 'PER_2', 'PER_3', 'SGR']
1592
1644
  self.rocks_buffer.seek(0)
1593
1645
  rocks_df = pd.read_fwf(self.rocks_buffer, colspecs=rock_colspecs, header=None,
1594
1646
  names=rock_names,
1595
- dtype={'MAT':str, 'PER_1':str, 'PER_2':str, 'PER_3':str, 'SGR':str})
1647
+ dtype={'MAT':str, 'POR':str, 'PER_1':str, 'PER_2':str, 'PER_3':str, 'SGR':str})
1596
1648
 
1597
1649
  #sgr_dict = {}
1598
1650
  self.rock_dict = None
@@ -1604,6 +1656,7 @@ class vis_reader:
1604
1656
  rock_dict.append({
1605
1657
  'id': i,
1606
1658
  'rock_name': rocks_df['MAT'][i],
1659
+ 'por':self.__parse_float(rocks_df['POR'][i]),
1607
1660
  'per_1':self.__parse_float(rocks_df['PER_1'][i]),
1608
1661
  'per_2':self.__parse_float(rocks_df['PER_2'][i]),
1609
1662
  'per_3':self.__parse_float(rocks_df['PER_3'][i]),
@@ -1616,22 +1669,31 @@ class vis_reader:
1616
1669
 
1617
1670
  sgr_array = vtkDoubleArray()
1618
1671
  sgr_array.SetName('sgr')
1672
+
1673
+ porosity_array = vtkDoubleArray()
1674
+ porosity_array.SetName('rock_por')
1675
+
1619
1676
  for i in range(0, len(elem_df.values)):
1620
1677
  value = 0
1621
-
1678
+ sgr = 0
1679
+ porosity = 0
1622
1680
  mat = matArray.GetValue(i)
1623
1681
  if self.__isInt(mat):
1624
1682
  mat_id = int(mat)
1625
1683
  value = pmxArray.GetValue(i) * rock_dict[mat_id-1]['per_1']
1626
1684
  sgr = rock_dict[mat_id-1]['sgr']
1685
+ porosity = rock_dict[mat_id-1]['por']
1627
1686
  else:
1628
1687
  rock_item = [rock for rock in rock_dict if rock['rock_name'] == mat]
1629
1688
  #if mat in rock_dict:
1630
1689
  value = pmxArray.GetValue(i) * rock_item[0]['per_1']
1631
1690
  sgr = rock_item[0]['sgr']
1691
+ porosity = rock_item[0]['por']
1692
+
1632
1693
 
1633
1694
  per_array.InsertNextValue(value)
1634
1695
  sgr_array.InsertNextValue(sgr)
1696
+ porosity_array.InsertNextValue(porosity)
1635
1697
  self.rock_dict = rock_dict
1636
1698
 
1637
1699
 
@@ -1674,6 +1736,10 @@ class vis_reader:
1674
1736
  elem_conne_vtu.GetPointData().AddArray(volxArray)
1675
1737
  elem_conne_vtu.GetPointData().AddArray(matArray)
1676
1738
  elem_conne_vtu.GetPointData().AddArray(matIDArray)
1739
+ if self.rock_dict is not None:
1740
+ elem_conne_vtu.GetPointData().AddArray(per_array)
1741
+ elem_conne_vtu.GetPointData().AddArray(sgr_array)
1742
+ elem_conne_vtu.GetPointData().AddArray(porosity_array)
1677
1743
 
1678
1744
  elem_conne_vtu.SetCells(4, line_cell_array)
1679
1745
  elem_conne_vtu.GetCellData().AddArray(d1_array)
@@ -1712,8 +1778,9 @@ class vis_reader:
1712
1778
  matIDArray = elem_conne_vtu.GetPointData().GetArray('Material_ID')
1713
1779
  pmxArray = elem_conne_vtu.GetPointData().GetArray('PMX')
1714
1780
  if self.rock_dict is not None:
1715
- per_array = elem_conne_vtu.GetCellData().GetArray('Permeability')
1716
- sgr_array = elem_conne_vtu.GetCellData().GetArray('sgr')
1781
+ per_array = elem_conne_vtu.GetPointData().GetArray('Permeability')
1782
+ sgr_array = elem_conne_vtu.GetPointData().GetArray('sgr')
1783
+ porosity_array = elem_conne_vtu.GetPointData().GetArray('rock_por')
1717
1784
 
1718
1785
 
1719
1786
 
@@ -1755,7 +1822,7 @@ class vis_reader:
1755
1822
 
1756
1823
 
1757
1824
  if all(xyz_elem) and range_ratio < 1000:
1758
- if os.path.exists(self.setting.corners_file):
1825
+ if os.path.isfile(self.setting.corners_file):
1759
1826
  self.setting.mesh_type = MeshType.StructuredGridOrth
1760
1827
  else:
1761
1828
  self.setting.mesh_type = MeshType.RegularGrid
@@ -1763,7 +1830,7 @@ class vis_reader:
1763
1830
  else:
1764
1831
  is_parallel = self.__checkParallel(elem_conne_vtu)
1765
1832
  # check if polygonal mesh
1766
- if os.path.exists(self.setting.corners_file):
1833
+ if os.path.isfile(self.setting.corners_file):
1767
1834
 
1768
1835
  if is_parallel:
1769
1836
  self.setting.mesh_type = MeshType.StructuredGridFree
@@ -1776,7 +1843,7 @@ class vis_reader:
1776
1843
  print(f' Mesh type: {self.setting.mesh_type.name}')
1777
1844
 
1778
1845
  # Read corners file to dataframe
1779
- if os.path.exists(self.setting.corners_file):
1846
+ if os.path.isfile(self.setting.corners_file):
1780
1847
  corners_buffer = io.StringIO()
1781
1848
  csv_headers = []
1782
1849
  line_number = -1
@@ -1935,6 +2002,7 @@ class vis_reader:
1935
2002
  if self.rock_dict is not None:
1936
2003
  rGrid.GetCellData().AddArray(per_array)
1937
2004
  rGrid.GetCellData().AddArray(sgr_array)
2005
+ rGrid.GetCellData().AddArray(porosity_array)
1938
2006
  rGrid.GetCellData().AddArray(pmxArray)
1939
2007
 
1940
2008
  self.main_geometry = os.path.join(
@@ -1974,6 +2042,7 @@ class vis_reader:
1974
2042
  if self.rock_dict is not None:
1975
2043
  vts.GetCellData().AddArray(per_array)
1976
2044
  vts.GetCellData().AddArray(sgr_array)
2045
+ vts.GetCellData().AddArray(porosity_array)
1977
2046
  self.main_geometry = os.path.join(self.setting.vis_dir, "main_geometry.vts")
1978
2047
  self.__write_vtk_file(vts, self.main_geometry)
1979
2048
 
@@ -2021,6 +2090,7 @@ class vis_reader:
2021
2090
  if self.rock_dict is not None:
2022
2091
  auto_corner_vtu.GetCellData().AddArray(per_array)
2023
2092
  auto_corner_vtu.GetCellData().AddArray(sgr_array)
2093
+ auto_corner_vtu.GetCellData().AddArray(porosity_array)
2024
2094
  auto_corner_vtu.GetCellData().AddArray(matIDArray)
2025
2095
  self.main_geometry = os.path.join(self.setting.vis_dir, "main_geometry.vtu")
2026
2096
  self.__write_vtk_file(auto_corner_vtu, self.main_geometry)
@@ -2361,6 +2431,7 @@ class vis_reader:
2361
2431
  if self.rock_dict is not None:
2362
2432
  main_geometray.GetCellData().AddArray(per_array)
2363
2433
  main_geometray.GetCellData().AddArray(sgr_array)
2434
+ main_geometray.GetCellData().AddArray(porosity_array)
2364
2435
 
2365
2436
  main_geometray.GetCellData().AddArray(matIDArray)
2366
2437
  main_geometray.GetCellData().AddArray(horizon_id_array)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toughanimator
3
- Version: 0.1.11
3
+ Version: 0.1.13
4
4
  Summary: A tool for visualizing TOUGH simulation outputs.
5
5
  Home-page: https://github.com/scarletref/toughanimator
6
6
  Author: scarletref
File without changes
File without changes