You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be convenient to integrate some interface for accessing the mesh (perhaps similar to the fvMesh class in OpenFOAM?).
This functionality should be relatively straightforward, since all the core features for parsing are already present, it is just a matter of developing a wrapper to simplify the user interface.
Here is an example of how I use foamlib to parse the mesh when it is located in time/polyMesh.
classPolyMesh(object):
""" Class to represent a polygonal mesh with vertices and faces. """@classmethoddeffrom_foam_case(cls, time_folder:str) ->'PolyMesh':
poly_mesh_path=Path(time_folder) /"polyMesh"ifnotpoly_mesh_path.exists():
raiseFileNotFoundError(f"polyMesh directory not found in {time_folder}")
# Load pointspoints_file=FoamFile(str(poly_mesh_path/"points"))
points=points_file[None]
# Load facesfaces_file=FoamFile(str(poly_mesh_path/"faces"))
faces=faces_file[None]
# Check if compactList (binary)ifisinstance(faces, tuple) andlen(faces) ==2:
# Convert to list of np.ndarraysvec1, vec2=facesfaces=np.fromiter((vec2[start:stop] forstart, stopinzip (vec1[:-1], vec1[1:])), dtype=np.ndarray, count=vec1.size-1)
# Load ownersowners_file=FoamFile(str(poly_mesh_path/"owner"))
owners=owners_file[None]
# Load neighboursneighbours_file=FoamFile(str(poly_mesh_path/"neighbour"))
neighbours=neighbours_file[None]
# Load boundaryboundary_file=FoamFile(str(poly_mesh_path/"boundary"))
boundary= {b:dataforb,datainboundary_file[None]}
returncls(points, faces, owners, neighbours, boundary)
def__init__(self, points:np.ndarray, faces:np.ndarray[np.ndarray], owners:np.ndarray, neighbours:np.ndarray, boundary:dict[str, dict]) ->None:
# TODO: Validate inputsself.vertices=points.copy()
self.faces=faces.copy()
self.owners=owners.copy()
self.neighbours=neighbours.copy()
self.boundary=cp.deepcopy(boundary)
This is a rudimentary proof of concept, it still requires some features:
The mesh can be either located in the constant or time folder. If in constant, accessing to the mesh in time should link to the one in constant
Moving meshes store the mesh in constant and only save the points in the time folder. This should be correctly handled
Meshed with topological changes store the mesh in the time folder, but write all the mesh data (points, faces, boundary, etc...) only when the mesh changes topology, while all the following times store only the points (see above). This should be handled properly (lookup last time where everything was saved, but use the points of this folder)
It would be convenient to integrate some interface for accessing the mesh (perhaps similar to the fvMesh class in OpenFOAM?).
This functionality should be relatively straightforward, since all the core features for parsing are already present, it is just a matter of developing a wrapper to simplify the user interface.
Here is an example of how I use
foamlibto parse the mesh when it is located intime/polyMesh.This is a rudimentary proof of concept, it still requires some features:
constantortimefolder. If inconstant, accessing to the mesh intimeshould link to the one inconstantconstantand only save thepointsin thetimefolder. This should be correctly handledtimefolder, but write all the mesh data (points,faces,boundary, etc...) only when the mesh changes topology, while all the following times store only thepoints(see above). This should be handled properly (lookup lasttimewhere everything was saved, but use thepointsof this folder)