From 9fa1dcc79c75a78d07ed400e77ef85dcfc90095b Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Wed, 29 May 2024 09:49:54 +0200 Subject: [PATCH 1/6] fix duplicate connection outputs --- toughio/_io/output/_common.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/toughio/_io/output/_common.py b/toughio/_io/output/_common.py index defdc5dd..39b01879 100644 --- a/toughio/_io/output/_common.py +++ b/toughio/_io/output/_common.py @@ -271,12 +271,17 @@ def to_output(file_type, labels_order, headers, times, labels, data): "Found duplicate connections. Fixing outputs by summing duplicate connections." ) - for output in outputs: - output.labels = list(connections) - output.data = { - k: np.array([v[idx].sum() for idx in connections.values()]) - for k, v in output.data.items() - } + outputs = [ + ConnectionOutput( + time=output.time, + data={ + k: np.array([v[idx].sum() for idx in connections.values()]) + for k, v in output.data.items() + }, + labels=list(connections), + ) + for output in outputs + ] if file_type == "element" and labels_order is not None: outputs = [output[labels_order] for output in outputs] From fb5214aecc611c051da2b6c431ace5c4fd6c7c15 Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Wed, 29 May 2024 09:51:00 +0200 Subject: [PATCH 2/6] add element and connection outputs --- doc/source/api/io.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/source/api/io.rst b/doc/source/api/io.rst index c932d689..b1dc700d 100644 --- a/doc/source/api/io.rst +++ b/doc/source/api/io.rst @@ -14,6 +14,12 @@ Input parameters Simulation outputs ------------------ +.. autoclass:: toughio.ElementOutput + :members: + +.. autoclass:: toughio.ConnectionOutput + :members: + .. autofunction:: toughio.read_output .. autofunction:: toughio.read_table From a312bc01f06f51c5a9f5fe6ad39cc3fd7c08c61b Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Mon, 19 Aug 2024 17:11:09 +0200 Subject: [PATCH 3/6] support flag option in oft blocks --- tests/test_input.py | 12 ++++++- toughio/_common.py | 6 ++-- toughio/_io/input/tough/_common.py | 5 +++ toughio/_io/input/tough/_read.py | 7 +++- toughio/_io/input/tough/_write.py | 57 ++++++++++++++++++------------ 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/tests/test_input.py b/tests/test_input.py index 1a665881..68fa35df 100644 --- a/tests/test_input.py +++ b/tests/test_input.py @@ -446,10 +446,20 @@ def test_hyste(write_read): ) def test_oft(write_read, oft, n): parameters_ref = { - oft: [helpers.random_string(n) for _ in range(np.random.randint(10) + 1)] + oft: [ + helpers.random_string(n), + helpers.random_string(n), + {"label": helpers.random_string(n)}, + {"label": helpers.random_string(n), "flag": np.random.randint(10)}, + ] } parameters = write_read(parameters_ref) + if write_read == write_read_tough: + for i, v in enumerate(parameters_ref[oft]): + if not isinstance(v, dict): + parameters_ref[oft][i] = {"label": v} + assert helpers.allclose(parameters_ref, parameters) diff --git a/toughio/_common.py b/toughio/_common.py index d3b600c6..cbf3cb57 100644 --- a/toughio/_common.py +++ b/toughio/_common.py @@ -38,9 +38,9 @@ "MOMOP": "50S", "TIMES": {1: "5d,5d,10f,10f", 2: ",".join(8 * ["10f"])}, "HYSTE": ",".join(3 * ["5d"]), - "FOFT": {5: "5s", 6: "6s", 7: "7s", 8: "8s", 9: "9s"}, - "COFT": {5: "10s", 6: "12s", 7: "14s", 8: "16s", 9: "18s"}, - "GOFT": {5: "5s", 6: "6s", 7: "7s", 8: "8s", 9: "9s"}, + "FOFT": {5: "5s,5s,5d", 6: "6s,4s,5d", 7: "7s,3s,5d", 8: "8s,2s,5d", 9: "9s,1s,5d"}, + "COFT": {5: "10s,10s,5d", 6: "12s,8s,5d", 7: "14s,6s,5d", 8: "16s,4s,5d", 9: "18s,2s,5d"}, + "GOFT": {5: "5s,5s,5d", 6: "6s,4s,5d", 7: "7s,3s,5d", 8: "8s,2s,5d", 9: "9s,1s,5d"}, "ROFT": "5s,5s", "GENER": { 0: ",".join(4 * ["14f"]), diff --git a/toughio/_io/input/tough/_common.py b/toughio/_io/input/tough/_common.py index b764af92..9fa9d5da 100644 --- a/toughio/_io/input/tough/_common.py +++ b/toughio/_io/input/tough/_common.py @@ -166,6 +166,11 @@ "eps": 1.0e-6, } +histories = { + "label": None, + "flag": None, +} + generators = { "label": None, "name": None, diff --git a/toughio/_io/input/tough/_read.py b/toughio/_io/input/tough/_read.py index 38d82b25..50e3555c 100644 --- a/toughio/_io/input/tough/_read.py +++ b/toughio/_io/input/tough/_read.py @@ -841,7 +841,12 @@ def _read_oft(f, oft, label_length): while True: if line.strip(): data = read_record(line, fmt[label_length]) - history[key].append(label_format.format(data[0])) + tmp = {"label": label_format.format(data[0])} + + if data[2] is not None: + tmp["flag"] = data[2] + + history[key].append(tmp) else: break diff --git a/toughio/_io/input/tough/_write.py b/toughio/_io/input/tough/_write.py index d538b15f..0cd2740b 100644 --- a/toughio/_io/input/tough/_write.py +++ b/toughio/_io/input/tough/_write.py @@ -1056,43 +1056,56 @@ def _write_hyste(parameters, space_between_values): return out -@block("FOFT", multi=True) -def _write_foft(parameters, space_between_values): - """Write FOFT block data.""" +def _write_oft(oft, parameters, space_between_values): + """Write FOFT, COFT, and GOFT blocks data.""" + from ._common import histories + + keys = { + "FOFT": "element", + "COFT": "connection", + "GOFT": "generator", + } + # Formats - fmt = block_to_format["FOFT"] + fmt = block_to_format[oft] fmt = str2format(fmt[5]) - values = [x for x in parameters["element_history"]] - out = write_record(values, fmt, space_between_values, multi=True) + out = [] + for oft in parameters[f"{keys[oft]}_history"]: + data = deepcopy(histories) + + if isinstance(oft, dict): + data.update(oft) + + else: + data["label"] = oft + + values = [ + data["label"], + None, + data["flag"], + ] + out += write_record(values, fmt, space_between_values) return out +@block("FOFT", multi=True) +def _write_foft(parameters, space_between_values): + """Write FOFT block data.""" + return _write_oft("FOFT", parameters, space_between_values) + + @block("COFT", multi=True) def _write_coft(parameters, space_between_values): """Write COFT block data.""" - # Format - fmt = block_to_format["COFT"] - fmt = str2format(fmt[5]) - - values = [x for x in parameters["connection_history"]] - out = write_record(values, fmt, space_between_values, multi=True) - - return out + return _write_oft("COFT", parameters, space_between_values) @block("GOFT", multi=True) def _write_goft(parameters, space_between_values): """Write GOFT block data.""" - # Format - fmt = block_to_format["GOFT"] - fmt = str2format(fmt[5]) - - values = [x for x in parameters["generator_history"]] - out = write_record(values, fmt, space_between_values, multi=True) - - return out + return _write_oft("GOFT", parameters, space_between_values) @block("ROFT", multi=True) From 7dc5ca4312e5e315ca852afc3c98e383d6830caf Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Mon, 19 Aug 2024 17:11:55 +0200 Subject: [PATCH 4/6] invoke format --- toughio/_common.py | 8 +++++++- toughio/_io/input/tough/_write.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/toughio/_common.py b/toughio/_common.py index cbf3cb57..fd39ba2a 100644 --- a/toughio/_common.py +++ b/toughio/_common.py @@ -39,7 +39,13 @@ "TIMES": {1: "5d,5d,10f,10f", 2: ",".join(8 * ["10f"])}, "HYSTE": ",".join(3 * ["5d"]), "FOFT": {5: "5s,5s,5d", 6: "6s,4s,5d", 7: "7s,3s,5d", 8: "8s,2s,5d", 9: "9s,1s,5d"}, - "COFT": {5: "10s,10s,5d", 6: "12s,8s,5d", 7: "14s,6s,5d", 8: "16s,4s,5d", 9: "18s,2s,5d"}, + "COFT": { + 5: "10s,10s,5d", + 6: "12s,8s,5d", + 7: "14s,6s,5d", + 8: "16s,4s,5d", + 9: "18s,2s,5d", + }, "GOFT": {5: "5s,5s,5d", 6: "6s,4s,5d", 7: "7s,3s,5d", 8: "8s,2s,5d", 9: "9s,1s,5d"}, "ROFT": "5s,5s", "GENER": { diff --git a/toughio/_io/input/tough/_write.py b/toughio/_io/input/tough/_write.py index 0cd2740b..c71c9109 100644 --- a/toughio/_io/input/tough/_write.py +++ b/toughio/_io/input/tough/_write.py @@ -1076,7 +1076,7 @@ def _write_oft(oft, parameters, space_between_values): if isinstance(oft, dict): data.update(oft) - + else: data["label"] = oft From ee46675ea256205ade43d1bf63560a1797453f71 Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Mon, 19 Aug 2024 17:13:20 +0200 Subject: [PATCH 5/6] version bump --- toughio/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toughio/VERSION b/toughio/VERSION index d19d0890..795d8700 100644 --- a/toughio/VERSION +++ b/toughio/VERSION @@ -1 +1 @@ -1.15.0 \ No newline at end of file +1.15.1 \ No newline at end of file From 321e9b10b0c6dcf3f036e2e21b3fd907271703a1 Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Mon, 19 Aug 2024 17:19:45 +0200 Subject: [PATCH 6/6] try fixing osmesa --- .github/workflows/doc.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index d8d6e7f3..b5b7f95b 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -22,11 +22,10 @@ jobs: python-version: '3.9' - name: Install OSMesa VTK run: | - sudo apt update - sudo apt install libosmesa6-dev libgl1-mesa-dev retry --option="APT::Acquire::Retries=3" - pip install https://github.com/pyvista/pyvista-wheels/raw/main/vtk-osmesa-9.1.0-cp39-cp39-linux_x86_64.whl + pip install vtk-osmesa==9.3.0 --index-url https://gitlab.kitware.com/api/v4/projects/13/packages/pypi/simple - name: Install libGLU for pygmsh run: | + sudo apt update sudo apt install libglu1 - name: Install toughio run: |