fluiddyn / fluidfoam

OpenFoam postprocessing python tool
GNU General Public License v3.0
158 stars 50 forks source link

Cannot read the airfoil2D case from OpenFOAM tutorials #32

Closed OpenFoam-User closed 2 years ago

OpenFoam-User commented 2 years ago

Hello, I am trying to use this package to read the mesh from the OpenFOAM's airfoil2D tutorial located in $FOAM_TUTORIALS/incompressible/simpleFoam/airFoil2D. Note that I am using OpenFOAM 9.

When I try to read the mesh from the case as follows:

from fluidfoam import readmesh
sol="/tmp/mywork/airf"
x, y, z = readmesh(sol, structured=True) # note that I have also used structured=False

When I run the code I always get errors when I use either structured=True or structured=False. In both cases I get errors as below:

CyrilleBonamy commented 2 years ago

Your problem is related to the header of the mesh files. The headers are not as usual. So i just pushed a commit to support this kind of header...

Try again with the latest version of fluidfoam and confirm that everything is fine.

OpenFoam-User commented 2 years ago

Thank you very much for the update! Now, I can successfuly read the mesh when I use the flag: structured=False (even though the mesh is structured).

However, when I try with the flag structured=True I get the following error:

x, y, z = readmesh(sol, structured=True, precision=14)                                                                                                     
Reading file /tmp/mywork/airf/constant/polyMesh/owner
Reading file /tmp/mywork/airf/constant/polyMesh/faces
Reading file /tmp/mywork/airf/constant/polyMesh/points
Reading file /tmp/mywork/airf/constant/polyMesh/neighbour
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 x, y, z = readmesh(sol, structured=True, precision=14)

File ~/.local/lib/python3.8/site-packages/fluidfoam-0.2.2-py3.8.egg/fluidfoam/readof.py:1046, in readmesh(path, time_name, structured, boundary, order, precision, verbose)
   1044 nz = np.unique(zs).size
   1045 if nx * ny * nz != nmesh:
-> 1046     raise ValueError(
   1047         "nx.ny.nz not equal to number of cells."
   1048         "Are you sure that your mesh is cartesian?"
   1049         "Maybe try to use precision option"
   1050         "For example : "
   1051         "fluidfoam.readmesh(case, True, precision=13)"
   1052     )
   1053 ind = np.lexsort((xs, ys, zs))
   1054 shape = (nx, ny, nz)

ValueError: nx.ny.nz not equal to number of cells.Are you sure that your mesh is cartesian?Maybe try to use precision optionFor example : fluidfoam.readmesh(case, True, precision=13)

I have changed the precision option to several values 14, 9, 8, etc. but still getting the same error.

Does that mean fluidfoam cannot recognize multi-block structured meshes as structured?

Thank you

CyrilleBonamy commented 2 years ago

In order for the "structured" option to work, we need to be able to define the mesh as (i, j, k), i being on the x-axis, j on the y-axis and k on the z-axis. I think that this is not the case for the airfoil. Therefore, we can not use the "structured" option. Maybe the name of the option (structured) is not correct. Maybe the right name is "structured Cartesian" or something like that. Sorry...

OpenFoam-User commented 2 years ago

I think the correct term should be "multi-block structured grid". If "somehow" fluidfoam could detect the multiblocks (each block can be indexed by (i, j, k)) then the whole grid could be read as structured.

In practice, I don't know how easy/difficult is that.

CyrilleBonamy commented 2 years ago

i agree with the "multi-block structured grid" term 👍 But i don't see how fluidfoam can extract the individual blocks. Indeed, in the airfoil example, there is no description of the blocks in the polymesh directory. :-(

OpenFoam-User commented 2 years ago

Exactly, that information is lost and OpenFOAM cannot retain that information. Do you think that in theory fluidfoam could plot the original mesh in Matplotlib using the topology information already read from faces, neighbour, owner, etc.?

OpenFoam-User commented 2 years ago

One naive approach I can think of to plot the OpenFOAM mesh in Matplotlib is as follows:

CyrilleBonamy commented 2 years ago

A Phd student from my lab is planning to contribute to fluidfoam on this topic. He has a python workflow that allows him to create vector images of the OpenFOAM mesh; it is planned that we work together very soon to integrate it into fluidfoam

OpenFoam-User commented 2 years ago

Very interesting! I do really look forward to see that :) Thank you

OpenFoam-User commented 2 years ago

Since the feature was added to the package, I consider closing the issue.