From 228746a5cd4f33980c235c74aabb9ce5c23cbe6a Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Mon, 19 Feb 2024 17:23:32 +0100 Subject: [PATCH 1/5] fix number of userx values read --- toughio/_io/input/tough/_read.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toughio/_io/input/tough/_read.py b/toughio/_io/input/tough/_read.py index 10362be5..c967e88a 100644 --- a/toughio/_io/input/tough/_read.py +++ b/toughio/_io/input/tough/_read.py @@ -1186,7 +1186,7 @@ def _read_incon(f, label_length, n_variables, eos=None, simulator="tough"): incon["initial_conditions"][label]["phase_composition"] = data[4] else: - userx = prune_values(data[4:9]) + userx = prune_values(data[4:]) incon["initial_conditions"][label]["userx"] = userx if userx else None # Record 2 From ad5f5d2e9480717935244fe39a7bebd6de6ac69f Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Thu, 25 Apr 2024 14:12:31 +0200 Subject: [PATCH 2/5] force a white space after TIMBC block --- toughio/_io/input/tough/_write.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/toughio/_io/input/tough/_write.py b/toughio/_io/input/tough/_write.py index 73996bcd..37c549ff 100644 --- a/toughio/_io/input/tough/_write.py +++ b/toughio/_io/input/tough/_write.py @@ -356,7 +356,6 @@ def write_buffer( if "TIMBC" in blocks and parameters["boundary_conditions"]: out += _write_timbc(parameters) - out += ["\n"] if space_between_blocks else [] if "DIFFU" in blocks and len(parameters["diffusion"]): out += _write_diffu(parameters, space_between_values) @@ -1233,7 +1232,7 @@ def _write_gener(parameters, space_between_values, simulator="tough"): return out -@block("TIMBC") +@block("TIMBC", multi=True) def _write_timbc(parameters): """Write TIMBC block data.""" from ._common import boundary_conditions From 92ae3f7028c06ac9ce51e4b8961202d2fb55f8af Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Thu, 25 Apr 2024 14:13:27 +0200 Subject: [PATCH 3/5] fix typo --- toughio/_io/input/_helpers.py | 2 +- toughio/_io/input/tough/_write.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/toughio/_io/input/_helpers.py b/toughio/_io/input/_helpers.py index 78230a4b..326e0608 100644 --- a/toughio/_io/input/_helpers.py +++ b/toughio/_io/input/_helpers.py @@ -117,7 +117,7 @@ def write(filename, parameters, file_format=None, **kwargs): Only if ``file_format = "tough"`` and `block` is None. Blocks to ignore. space_between_blocks : bool, optional, default False Only if ``file_format = "tough"``. Add an empty record between blocks. - space_between_blocks : bool, optional, default True + space_between_values : bool, optional, default True Only if ``file_format = "tough"``. Add a white space between floating point values. eos : str or None, optional, default None Only if ``file_format = "tough"``. Equation of State. diff --git a/toughio/_io/input/tough/_write.py b/toughio/_io/input/tough/_write.py index 37c549ff..3819741d 100644 --- a/toughio/_io/input/tough/_write.py +++ b/toughio/_io/input/tough/_write.py @@ -46,7 +46,7 @@ def write( Blocks to ignore. Only if `block` is None. space_between_blocks : bool, optional, default False Add an empty record between blocks. - space_between_blocks : bool, optional, default True + space_between_values : bool, optional, default True Add a white space between floating point values. eos : str or None, optional, default None Equation of State. If `eos` is defined in `parameters`, this option will be ignored. From 0a600448bfdb5d2fb9bba118a3c28d4c9eae4559 Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Thu, 25 Apr 2024 14:17:06 +0200 Subject: [PATCH 4/5] invoke format --- tests/test_input.py | 38 ++++++++++++++---------- toughio/_cli/_extract.py | 4 +-- toughio/_common.py | 8 +++-- toughio/_io/input/tough/_read.py | 4 +-- toughio/_io/input/tough/_write.py | 20 +++++++------ toughio/_mesh/_mesh.py | 10 +++---- toughio/_mesh/_properties.py | 8 +++-- toughio/_run.py | 4 +-- toughio/capillarity/_linear.py | 4 +-- toughio/capillarity/_pickens.py | 4 +-- toughio/relative_permeability/_linear.py | 8 ++--- 11 files changed, 55 insertions(+), 57 deletions(-) diff --git a/tests/test_input.py b/tests/test_input.py index 76f2c04b..1a665881 100644 --- a/tests/test_input.py +++ b/tests/test_input.py @@ -631,11 +631,11 @@ def test_eleme(write_read, label_length, coord): key: ( np.random.randint(10) if key in {"nseq", "nadd"} - else helpers.random_string(5) - if key == "material" - else np.random.rand(3) - if key == "center" - else np.random.rand() + else ( + helpers.random_string(5) + if key == "material" + else np.random.rand(3) if key == "center" else np.random.rand() + ) ) for key in keys } @@ -677,13 +677,19 @@ def test_conne(write_read, label_length): key: ( np.random.randint(10) if key == "nseq" - else np.random.randint(10, size=2) - if key == "nadd" - else np.random.randint(1, 4) - if key == "permeability_direction" - else np.random.rand(2) - if key == "nodal_distances" - else np.random.rand() + else ( + np.random.randint(10, size=2) + if key == "nadd" + else ( + np.random.randint(1, 4) + if key == "permeability_direction" + else ( + np.random.rand(2) + if key == "nodal_distances" + else np.random.rand() + ) + ) + ) ) for key in keys } @@ -722,9 +728,11 @@ def test_incon(write_read, label_length, num_pvars, num_items): key: ( np.random.rand() if key == "porosity" - else np.random.rand(np.random.randint(5) + 1) - if key == "userx" - else np.random.rand(num_pvars) + else ( + np.random.rand(np.random.randint(5) + 1) + if key == "userx" + else np.random.rand(num_pvars) + ) ) for key in keys } diff --git a/toughio/_cli/_extract.py b/toughio/_cli/_extract.py index 038de834..173e6559 100644 --- a/toughio/_cli/_extract.py +++ b/toughio/_cli/_extract.py @@ -70,9 +70,7 @@ def extract(argv=None): filename = ( args.output_file if args.output_file is not None - else f"OUTPUT_ELEME{ext}" - if not args.connection - else f"OUTPUT_CONNE{ext}" + else f"OUTPUT_ELEME{ext}" if not args.connection else f"OUTPUT_CONNE{ext}" ) if not args.split or len(output) == 1: write_output(filename, output, file_format=args.file_format) diff --git a/toughio/_common.py b/toughio/_common.py index 8770433b..d3b600c6 100644 --- a/toughio/_common.py +++ b/toughio/_common.py @@ -140,9 +140,11 @@ def str2format(fmt): base_fmt = "{{:{}}}" out = [ - base_fmt.format(f"{token[:-1]}.{token[:-1]}") - if token[-1].lower() == "s" - else base_fmt.format(f">{token[:-1]}{token_to_format[token[-1]]}") + ( + base_fmt.format(f"{token[:-1]}.{token[:-1]}") + if token[-1].lower() == "s" + else base_fmt.format(f">{token[:-1]}{token_to_format[token[-1]]}") + ) for token in fmt.split(",") ] diff --git a/toughio/_io/input/tough/_read.py b/toughio/_io/input/tough/_read.py index c967e88a..38d82b25 100644 --- a/toughio/_io/input/tough/_read.py +++ b/toughio/_io/input/tough/_read.py @@ -1157,9 +1157,7 @@ def _read_incon(f, label_length, n_variables, eos=None, simulator="tough"): fmt2 = ( fmt[simulator] if simulator == "toughreact" - else fmt[eos] - if eos in fmt - else fmt["default"] + else fmt[eos] if eos in fmt else fmt["default"] ) incon = {"initial_conditions": {}} diff --git a/toughio/_io/input/tough/_write.py b/toughio/_io/input/tough/_write.py index 3819741d..d538b15f 100644 --- a/toughio/_io/input/tough/_write.py +++ b/toughio/_io/input/tough/_write.py @@ -128,9 +128,11 @@ def write_buffer( parameters["end_comments"] = ( None if not parameters["end_comments"] - else [parameters["end_comments"]] - if isinstance(parameters["end_comments"], str) - else parameters["end_comments"] + else ( + [parameters["end_comments"]] + if isinstance(parameters["end_comments"], str) + else parameters["end_comments"] + ) ) for k, v in default.items(): @@ -1452,9 +1454,7 @@ def _write_incon(parameters, space_between_values, eos_=None, simulator="tough") fmt1 = str2format( fmt[simulator][label_length] if simulator == "toughreact" - else fmt[eos_][label_length] - if eos_ in fmt - else fmt["default"][label_length] + else fmt[eos_][label_length] if eos_ in fmt else fmt["default"][label_length] ) fmt2 = str2format(fmt[0]) @@ -1540,9 +1540,11 @@ def _write_meshm(parameters, space_between_values): elif ndim == 1: values += [ - parameter["n_increment"] - if parameter["n_increment"] - else len(parameter["sizes"]) + ( + parameter["n_increment"] + if parameter["n_increment"] + else len(parameter["sizes"]) + ) ] out += write_record(values, fmt2, space_between_values) out += write_record( diff --git a/toughio/_mesh/_mesh.py b/toughio/_mesh/_mesh.py index e755d4ee..a7e8c371 100644 --- a/toughio/_mesh/_mesh.py +++ b/toughio/_mesh/_mesh.py @@ -991,9 +991,7 @@ def from_meshio(mesh, material="dfalt"): point_sets=( mesh.point_sets if hasattr(mesh, "point_sets") - else mesh.node_sets - if hasattr(mesh, "node_sets") - else None + else mesh.node_sets if hasattr(mesh, "node_sets") else None ), cell_sets=mesh.cell_sets if hasattr(mesh, "cell_sets") else None, ) @@ -1068,9 +1066,9 @@ def from_pyvista(mesh, material="dfalt"): cell = ( cell if cell_type not in pixel_voxel - else cell[[0, 1, 3, 2]] - if cell_type == 8 - else cell[[0, 1, 3, 2, 4, 5, 7, 6]] + else ( + cell[[0, 1, 3, 2]] if cell_type == 8 else cell[[0, 1, 3, 2, 4, 5, 7, 6]] + ) ) cell_type = cell_type if cell_type not in pixel_voxel else cell_type + 1 cell_type = ( diff --git a/toughio/_mesh/_properties.py b/toughio/_mesh/_properties.py index 46ba0ead..bbcb6622 100644 --- a/toughio/_mesh/_properties.py +++ b/toughio/_mesh/_properties.py @@ -95,9 +95,11 @@ def _face_areas(mesh): if "quad" in faces_dict and len(faces_dict["quad"]): tmp = np.concatenate( [ - _get_triangle_normals(mesh, v, [0, 2, 3]) - if k == "quad" - else np.zeros((len(v), 3)) + ( + _get_triangle_normals(mesh, v, [0, 2, 3]) + if k == "quad" + else np.zeros((len(v), 3)) + ) for k, v in faces_dict.items() ] ) diff --git a/toughio/_run.py b/toughio/_run.py index 841fdf23..44064009 100644 --- a/toughio/_run.py +++ b/toughio/_run.py @@ -102,9 +102,7 @@ def run( other_filenames = ( {k: k for k in other_filenames} if isinstance(other_filenames, (list, tuple)) - else other_filenames - if other_filenames - else {} + else other_filenames if other_filenames else {} ) if command is None: diff --git a/toughio/capillarity/_linear.py b/toughio/capillarity/_linear.py index d42f786e..4e2a8288 100644 --- a/toughio/capillarity/_linear.py +++ b/toughio/capillarity/_linear.py @@ -33,9 +33,7 @@ def _eval(self, sl, *args): return ( -pmax if sl <= smin - else 0.0 - if sl >= smax - else -pmax * (smax - sl) / (smax - smin) + else 0.0 if sl >= smax else -pmax * (smax - sl) / (smax - smin) ) @property diff --git a/toughio/capillarity/_pickens.py b/toughio/capillarity/_pickens.py index 285acfa0..ca04b0cb 100644 --- a/toughio/capillarity/_pickens.py +++ b/toughio/capillarity/_pickens.py @@ -45,9 +45,7 @@ def _eval(self, sl, *args): A = (1.0 + sl / sl0) * (sl0 - slr) / (sl0 + slr) B = 1.0 - sl / sl0 - return -p0 * (np.log(A / B * (1.0 + (1.0 - B**2 / A**2) ** 0.5))) ** ( - 1.0 / x - ) + return -p0 * (np.log(A / B * (1.0 + (1.0 - B**2 / A**2) ** 0.5))) ** (1.0 / x) @property def parameters(self): diff --git a/toughio/relative_permeability/_linear.py b/toughio/relative_permeability/_linear.py index d3091518..2d5df613 100644 --- a/toughio/relative_permeability/_linear.py +++ b/toughio/relative_permeability/_linear.py @@ -37,18 +37,14 @@ def _eval(self, sl, *args): kl = ( 1.0 if sl >= slmax - else 0.0 - if sl <= slmin - else (sl - slmin) / (slmax - slmin) + else 0.0 if sl <= slmin else (sl - slmin) / (slmax - slmin) ) sg = 1.0 - sl kg = ( 1.0 if sg >= sgmax - else 0.0 - if sg <= sgmin - else (sg - sgmin) / (sgmax - sgmin) + else 0.0 if sg <= sgmin else (sg - sgmin) / (sgmax - sgmin) ) return kl, kg From ff69fc5bc30fd8faef393009a8629c366b901fb7 Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Thu, 25 Apr 2024 14:17:15 +0200 Subject: [PATCH 5/5] version bump --- toughio/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toughio/VERSION b/toughio/VERSION index 30f101cb..a32d5a6a 100644 --- a/toughio/VERSION +++ b/toughio/VERSION @@ -1 +1 @@ -1.14.1 \ No newline at end of file +1.14.2 \ No newline at end of file