keurfonluu / toughio

Pre- and post-processing Python library for TOUGH
Other
58 stars 9 forks source link

Problem of extracting results #132

Closed Cocytus-kyon closed 1 year ago

Cocytus-kyon commented 1 year ago

Hi,

When I intend to extract results from output file and reformat as a TMVOC CSV output file:

toughio-extract ini.out MESH

I get the following error message:

 File "C:\Users\Lenovo\Envs\toughio\lib\site-packages\toughio\_cli\_extract.py", line 52, in extract
    [parameters["elements"][label]["center"] for label in output[-1].labels]
  File "C:\Users\Lenovo\Envs\toughio\lib\site-packages\toughio\_cli\_extract.py", line 52, in <listcomp>
    [parameters["elements"][label]["center"] for label in output[-1].labels]
KeyError: '    1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\lenovo\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\lenovo\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Lenovo\Envs\toughio\Scripts\toughio-extract.exe\__main__.py", line 7, in <module>
  File "C:\Users\Lenovo\Envs\toughio\lib\site-packages\toughio\_cli\_extract.py", line 68, in extract
    raise ValueError(
ValueError: Elements in 'ini.out' and 'MESH' are not consistent.

I'm not sure if it's toughio's problem.

I am enclosing the input, output and MESH files here.

MESH.txt ini.txt ini.out.txt

Thank you!

Cocytus-kyon commented 1 year ago

Hi,

I solved this problem.

Because my labels are '1','2','3'...'10000', will become '    1', '    2', '    3'...'10000' in the MESH file.

But in _ extract.py,

parameters ["element"]. keys()

The result is

['1', '2', '3', '4', '5', ...'1 1'...]

The space on the left of labels has been deleted.

Therefore, make the following changes in _extract.py

line 52

[parameters["elements"][label.lstrip()]["center"] for label in output[-1].labels]
keurfonluu commented 1 year ago

That shouldn't happen. I will investigate the issue when I have time. Thanks for reporting. I am reopening the issue until it's actually fixed.

Cocytus-kyon commented 1 year ago

Thank you. I have one more question.

The mesh I input is POLYHEDRON, however, after TMVOC calculation, the output mesh is tetrahedron.

inputMesh inputMesh

outputMesh outputMesh

Did I miss any parameters?

jtecklenburg commented 1 year ago

I tried to read a vtu-mesh with polyhedrons (vtk.VTK_WEDGE, vtk.VTK_HEXAHEDRON, vtk.VTK_PENTAGONAL_PRISM, VTK_HEXAGONAL_PRISM, vtk.VTK_CONVEX_POINT_SET) and I saw some error messages, that some of these element types are not supported.

keurfonluu commented 1 year ago

That looks like a recurrent issue when dealing with Voronoi grids. I am not sure how to solve it (the code is relying on SciPy's Delaunay triangulation function to reconstruct a mesh).

I would recommend to interpolate your results on a rectangular grid, for instance:

import numpy as np
import toughio

from scipy.interpolate import griddata

parameters = toughio.read_input("MESH.txt")
outputs = toughio.read_output("ini.out.txt")
centers = np.array([element["center"] for element in parameters["elements"].values()])
xmin, ymin, zmin = centers.min(axis=0)
xmax, ymax, zmax = centers.max(axis=0)

nx, ny, nz = 20, 20, 20
dx = np.diff(np.linspace(xmin, xmax, nx + 1))
dy = np.diff(np.linspace(ymin, ymax, ny + 1))
dz = np.diff(np.linspace(zmin, zmax, nz + 1))

mesh = toughio.meshmaker.structured_grid(dx, dy, dz, origin=[xmin, ymin, zmin], layer=True)
for k, v in outputs[-1].data.items():
    vint = griddata(centers, v, mesh.centers, method="linear")
    mesh.add_cell_data(k, vint)

mesh.write("out.vtu")

I will implement such feature later in toughio.

medhay36 commented 1 year ago

Hello

Can you tell me in which format I should write the origin point coordiantes?

image

image

keurfonluu commented 1 year ago

Hi @medhay36

Please use the following syntax:

toughio-export -t -1 -o parameter.vtu -f vtu -v --origin 0.0 0.0 0.0 OUTPUT_ELEME.csv
medhay36 commented 1 year ago

Thank you dear @keurfonluu I tried that but still encoutring the same error

image

keurfonluu commented 1 year ago

My bad:

toughio-export OUTPUT_ELEME.csv -t -1 -o parameter.vtu -f vtu -v --origin 0.0 0.0 0.0
medhay36 commented 1 year ago

My bad:

toughio-export OUTPUT_ELEME.csv -t -1 -o parameter.vtu -f vtu -v --origin 0.0 0.0 0.0

@keurfonluu Thank you very much . works fine now

medhay36 commented 1 year ago

Hello again @keurfonluu I am encountreing an issure while trying to use an atmospheric boundary condition on top

image

I tried using --ignore-elements option but it seems there is an issue with it here is the element causing the problem image

have you got any ideas ? and thank you

keurfonluu commented 1 year ago

What's the issue with "ignore-elements"? toughio-export OUTPUT_ELEME.csv --ignore-elements "at 0" should work.

medhay36 commented 1 year ago

Thank you dear Luu. Problem solved (forgot to put quotes around element name) Best regards