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: | 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 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/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 diff --git a/toughio/_common.py b/toughio/_common.py index d3b600c6..fd39ba2a 100644 --- a/toughio/_common.py +++ b/toughio/_common.py @@ -38,9 +38,15 @@ "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..c71c9109 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) 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]