Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #166

Merged
merged 5 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions tests/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion toughio/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.14.1
1.14.2
4 changes: 1 addition & 3 deletions toughio/_cli/_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions toughio/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
]

Expand Down
2 changes: 1 addition & 1 deletion toughio/_io/input/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions toughio/_io/input/tough/_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}}

Expand All @@ -1186,7 +1184,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
Expand Down
25 changes: 13 additions & 12 deletions toughio/_io/input/tough/_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -356,7 +358,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)
Expand Down Expand Up @@ -1233,7 +1234,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
Expand Down Expand Up @@ -1453,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])

Expand Down Expand Up @@ -1541,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(
Expand Down
10 changes: 4 additions & 6 deletions toughio/_mesh/_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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 = (
Expand Down
8 changes: 5 additions & 3 deletions toughio/_mesh/_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]
)
Expand Down
4 changes: 1 addition & 3 deletions toughio/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions toughio/capillarity/_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions toughio/capillarity/_pickens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions toughio/relative_permeability/_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading