-
Notifications
You must be signed in to change notification settings - Fork 37
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
.json() conversion from TOUGH2 dat #56
Comments
hi, I think I can see what the problem is. Petrasim is using a different way of ordering the blocks in the connections, so PyTOUGH is looking for e.g. connection (' a 2', ' a 1') but not finding it, because it's there as (' a 1', ' a 2'). I will try to modify rectgeo() so that it respects the way blocks are ordered in the connections in the original data file. That should fix the problem. |
Thank you for your acknowledgment. It would be greatly appreciated if you could update the code to address the connection issue. I eagerly await the update. |
I have just pushed a commit to the PyTOUGH testing branch which should address this problem. Are you able to install the testing branch and test it? I tried it on another data file generated by Petrasim. I modified your script slightly: from t2data import *
import json
dat = t2data(filename='model.dat')
geo, blockmap = dat.grid.rectgeo()
geo.write('gmodel.dat')
dat.rename_blocks(blockmap, invert = True)
j = dat.json(geo, 'gmodel.msh', eos = 1)
with open('model.json', 'w') as f:
json.dump(j, f, indent = 2, sort_keys = True) Main changes:
|
Thank you for your prompt response. It appears that the error regarding blockmap naming inversion has been resolved. However, a new issue has arisen concerning generation. I have attached the .dat file extracted from my Petrasim for your reference. I would appreciate your assistance in resolving this new issue. The error. |
OK, thanks for that, one of your generators has a blank LTAB and I wasn't checking for it. I have pushed another fix to the testing branch. It seems to convert your model to JSON ok now. I did notice that your two DELV generators appear to have bottomhole pressures for the deliverability defined as 85 Pa and 95 Pa - they seem very low? |
Thank you again for your response. I am pleased to inform you that the Python file runs flawlessly. My objective in building the model is to analyze the pressure, temperature, and tracer sensitivity by manipulating the porosity and permeability parameters so I set the pressure to 80-90 bar actually, is it change to Pa all of a sudden? I have revised the code accordingly (attached). However, upon executing it in Waiwera, I encountered the following error (attached). I would appreciate your assistance in resolving this issue. The code from t2data import * dat = t2data(filename='T1DP290424.dat') dat.rename_blocks(blockmap, invert = True) with open('T1DP290424.json', 'w') as f: The error Error running Waiwera in Docker container 7f8ae59c7ee3.` |
Following the export from the Gmsh application, the model runs smoothly without any issues. However, I remain uncertain about the underlying differences. Nevertheless, I appreciate your assistance thus far. Thank you. |
In your script above you are writing the mesh file using the line: geo.write('gT1DP290424.msh') which won't work - the You would need to use the mulgrid There are various versions of the GMSH format, and the PETSc library that Waiwera uses doesn't support the latest ones yet. Depending on which version of GMSH and geo.write_mesh('gT1DP290424.msh', file_format = 'gmsh22') |
I have just found out a bit more about this. The meshio library used by PyTOUGH can write GMSH mesh files in two GMSH file formats, 2.2 and 4.1. PETSc does in fact support both of them. The 4.1 format introduced a new optional section called $Entities. By default, meshio doesn't write this section, but PETSc expects it to be present and will complain if it isn't, as you saw, saying it isn't a valid GMSH file. When you wrote out your mesh from GMSH itself it would have written the $Entities section, giving you a mesh that PETSc was happy with. I have suggested to the PETSc developers that they make the $Entities section optional. That may take some time. So in the meantime, as I said, it is usually safest to stick to GMSH file format 2.2, by specifying |
Thank you for the comprehensive explanation. I have now scaled up my simulation to incorporate topography. However, after converting using the same method, I noticed that several blocks are missing and not available in the '.json' file after the conversion from '.dat'. I would appreciate any insights you could provide to resolve this issue. |
As you are aware, PetraSim utilizes a layer-based surface for topography input, whereas PyTOUGH employs a staircase style. |
Yes, that can happen for example if you have topography represented by a top layer that is allowed to have different surface elevations in different columns. PyTOUGH's mulgrid does allow this, but Waiwera does not - incomplete layers are allowed (i.e. upper layers not having all columns present) but the surface elevation of each column must be equal to a layer top elevation. If that results in an inaccurate topography you need to refine the upper layers. If your mulgrid geometry does not satisfy this requirement you can use its There are two reasons Waiwera does not support different column surface elevations in the top layer. First, it results in mesh faces that do not satisfy the orthogonality criterion (TOUGH2 also assumes orthogonality, but some users ignore this). Second, it results in a mesh that is not easily representable by the commonly-used mesh file formats, e.g. GMSH or ExodusII, used by PETSc and Waiwera. |
Hi @acroucher, Thank you for your response. I will try that method. Currently, I am aiming to create a better grid using the from t2data import *
from t2grids import *
from mulgrids import *
geo = mulgrid().rectangular(
xblocks=[250]*6,
yblocks=[250]*6,
zblocks=[50]*200,
origin=[0.,0.,0.],
atmos_type=0,
convention=2
)
xmin = 500
xmax = 1000
ymin = 500
ymax = 1000
polygon = [
np.array([xmin,ymin]),
np.array([xmin,ymax]),
np.array([xmax,ymax]),
np.array([xmax,ymin]),
]
ref_col = []
ref_col_bisect = []
for col in geo.column.values():
if col.in_polygon(polygon):
ref_col.append(col)
ref_col_bisect.append(True)
geo.refine(ref_col,False)
geo.optimize()
geo.layer_plot() However, I encountered the following error:
It seems there is a mismatch in the input vector length N and the output vector length M. I would appreciate any guidance you can provide to resolve this issue. Thank you. |
It's usually not a good idea to try and optimize the entire mesh - depending on the mesh, it may have more degrees of freedom than constraints for the optimization. So you should only optimize the nodes that need optimizing. In this case, after a local refinement, it's usually just the nodes in the new triangular transition columns that need optimizing. So you can do something like this: opt_cols = [col for col in geo.columnlist if col.num_nodes == 3] # only triangular columns
opt_nodes = geo.nodes_in_columns(opt_cols) # nodes in the triangular columns
opt_node_names = [n.name for n in opt_nodes] # extract node names
geo.optimize(opt_node_names) |
Thanks, the code run perfectly.
|
Another reason not to optimize the whole mesh is that even if it does work, it will probably move your mesh boundaries, which you usually don't want. |
Dear @acroucher , Regarding the surface columns issue, I have discovered that the model exhibits the same error even without varied elevation on the surface. Could you please assist me with resolving this matter? Thank you for your help. Best regards, mpc |
The code
The error
|
I think you also need to make sure the block order of your renamed t2grid agrees with the ordering in the geometry. You can do that by adding a line: dat.grid.reorder(geo = geo) just after the call to |
Thank you, the conversion ran perfectly. It also works when I change the Best regards, mpc |
It looks like you have a problem with permissions - so the Waiwera Docker image isn't able to create the output HDF5 file. There are a few things you need to be careful of with Docker - it only has permissions to access the current directory and the ones below it, so e.g. you can't run an input file in directories above the current one. I can't tell exactly what the issue is without knowing the command you used to run it. But there is some stuff in the user guide which may help: https://waiwera.readthedocs.io/en/testing/run.html#file-paths-when-running-with-docker It could also be an issue with directory delimiters if you have any in your input file - they need to be POSIX-style (forward slash not Windows-style backslash), because Docker is running Linux inside the container. |
I just noticed another issue - your JSON file had a bunch of additional weird boundary conditions with negative cell indices. I realised this is because in your original TOUGH2 data file there are connections between the atmosphere blocks (not sure why that would ever be a good idea - presumably an artefact of PetraSim). I've pushed a fix (b338423) to the PyTOUGH testing branch so that these connections are now ignored and the resulting JSON file just has one boundary condition at the surface with 100 cells. |
The model in TOUGH2 is actually having the top layer rocks as the atmosphere material with fixed state condition. The reference of the model is https://doi.org/10.1016/j.geothermics.2018.10.001 |
Thanks @acroucher , I just found out that the json file containing full path that can't be read in waiwera. The model is now running perfectly. |
Hello,
Firstly, thank you for the straightforward conversion using the json() method. Recently, I have been studying simulation with TOUGH2 and acquired the .dat file from Petrasim extraction. I have diligently followed the provided instructions, including utilizing the rectgeo methods for the grid and renaming blocks. However, despite these efforts, I am encountering the error attached below. I would greatly appreciate your assistance in resolving this issue. Thank you for your consideration.
Best regards, mpc
The code
from t2data import *
dat = t2data(
filename='TS090524.dat'
)
geo = dat.grid
geo_mg, geo_mg_naming = geo.rectgeo()
geo_mg.write('gTS090524.dat')
geo_map = dat.grid.blockmap(geo_mg)
geo_map = {v: k for k, v in geo_map.items()}
dat.rename_blocks(geo_map)
dat.json(
geo=geo_mg,
mesh_filename='gTS090524'
)
The error
Traceback (most recent call last): File "C:\Users\piere\Try Running\Using PyTOUGH\waiwera_conversion_research\test1.py", line 31, in <module> dat.json( File "C:\Users\piere\AppData\Roaming\Python\Python311\site-packages\t2data.py", line 2791, in json jsondata.update(self.mesh_json(geo, mesh_filename)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\piere\AppData\Roaming\Python\Python311\site-packages\t2data.py", line 2076, in mesh_json con = self.grid.connection[blknames] ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ KeyError: (' a 2', ' a 1')
The text was updated successfully, but these errors were encountered: