OpenPisco.MuscatExtentions.FoamWriter module#

For more details about OpenFOAM format, we refer to section 4.1.2 the polymesh description in https://www.openfoam.com/documentation/user-guide/4-mesh-generation-and-conversion/4.1-mesh-description

see also https://openfoamwiki.net/index.php/Write_OpenFOAM_meshes

see also https://www.cfd-online.com/Forums/openfoam-meshing/61656-creating-your-own-mesh-files.html

OpenPisco.MuscatExtentions.FoamWriter.CheckIntegrity()[source]#
OpenPisco.MuscatExtentions.FoamWriter.CreateHeader(filePath: str, keyWordClass: str, keyWordObject: str, note: Optional[str] = None) str[source]#

Create header following OpenFOAM style

Parameters
  • filePath (str) – file path

  • keyWordClass (str) – type of data in file

  • keyWordObject (str) – type of main physical/geometrical quantity in file

  • note (Optional[str], optional) – extra note, by default None

Returns

OpenFOAM header formated as a string

Return type

str

class OpenPisco.MuscatExtentions.FoamWriter.FoamWriter(location: Optional[str] = None)[source]#

Bases: WriterBase

ComputeFaceCaracteristics(mesh: Mesh) tuple[source]#
Compute internal/external triangular face caracteristics:
  • internal (2 tetra faces in common):

    triangular faces connectivity faces tetra (owners) indices (lowest tetra indices linked to internal faces) face tetra (neighbours) indices (other tetra indices linked to internal faces)

  • external:

    triangular faces connectivity faces tetra indices (tetra indices linked to external faces)

Parameters

mesh (Mesh) – mesh to be written

Returns

internal/external face caracteristics

Return type

tuple

ComputeFaceNumbering(mesh: Mesh) tuple[source]#
Compute face numbering from tetrahedron:
  • Extract all faces associated to each individual tetrahedron and map it to associated tetrahedron

  • Collect unique triangle faces, defined unique integer for each, map all triangles faces to such integer

  • Build unique face numbering mapping to corresponding triangle faces numbering

For instance, in faceNumbers = [array([8]), array([13]), array([10, 14])…] it means unique triangular face 2 can be found in triangular face 10 and 14

Note that, for tetrahedron, a triangular face can belong to 1 (external face) or 2 tetrahedrons (internal face)

Parameters

mesh (Mesh) – mesh to be written

Returns

unique face number mapping to all triangular faces,tetrahedron indices associated to each face,triangle face connectivity

Return type

tuple

RenumberExternalFacesForBoundary(externalFacesCarac: tuple, mesh: Mesh, physicalTagNames: Iterable)[source]#
Renumber external faces: OpenFOAM is slightly picky about face ordering.

Boundary faces are supposed to be bunched per patch (contiguous numerotation for elem ids in tag). Case where intersection between tags is not empty not handled. The physical tag names should be a partition of the external surface

Parameters
  • externalFacesCarac (tuple) – triangular faces connectivity,faces tetra indices (tetra indices linked to external faces)

  • mesh (Mesh) – mesh to be written

  • physicalTagNames (Iterable) – physical tag names

Returns

renumerated external face caracteristics

Return type

tuple

RenumberInternalFaces(internalFacesCarac: tuple) tuple[source]#
Renumber internal faces: OpenFOAM is slightly picky about face ordering.

Internal faces get ordered such that when stepping through the higher numbered neighbouring cells in incremental order one also steps through the corresponding faces in incremental order (upper-triangular ordering)

Parameters

internalFacesCarac (tuple) – unique face number mapping to all triangular faces,tetrahedron indices associated to each face,triangle face connectivity

Returns

renumerated internal face caracteristics

Return type

tuple

RenumerateFaceConnectivity(triaFaces: ndarray, facesTetra: ndarray, mesh: Mesh)[source]#

Renumerate face connectivity: OpenFOAM is slightly picky about normal orientation. The normal (righthand rule) should point away from the owner cell (so the boundary faces point out of the domain). If this condition is not respected for specific faces, the faces connectivity is changed

Parameters
  • triaFaces (np.ndarray) – triangular faces connectivity

  • facesTetra (np.ndarray) – physical tag names

  • mesh (Mesh) – mesh to be written

Returns

renumerated face connectivity

Return type

tuple

RetrieveWrongOrientedFaces(nodesCoordinates: ndarray, triaFaces: ndarray, complementaryNodeCoords: ndarray) ndarray[source]#

Retrieve wrong oriented faces Find which faces do not have an acceptable orientation. For a given face, if we move in the direction of the normal, the distance between the triangle center and the complementary node should increase. Else, the orientation is wrong.

Parameters
  • nodesCoordinates (np.ndarray) – nodes coordinates

  • triaFaces (np.ndarray) – triangular faces connectivity

  • complementaryNodeCoords (np.ndarray) – each node coordinates belonging to the tetra attached to the face but not belonging to this very face

Returns

renumerated face connectivity

Return type

tuple

Write(meshObject: Mesh, physicalTagNames: Iterable, PointFields: Optional[Iterable] = None, PointFieldsNames: Optional[str] = None, CellFields: Optional[Iterable] = None, CellFieldsNames: Optional[str] = None)[source]#

Write mesh in FOAM format

Parameters
  • meshObject (Mesh) – Original mesh to be written

  • physicalTagNames (Iterable) – collection of physical tag names to be used in a FOAM analysis

  • PointFields (Optional[Iterable], optional) – Values of nodal fields to be written if required, by default None

  • PointFieldsNames (Optional[str], optional) – Names of nodal fields to be written if required, by default None

  • CellFields (Optional[Iterable], optional) – Values of cell fields to be written if required, by default None

  • CellFieldsNames (Optional[str], optional) – Names of cell fields to be written if required, by default None

WriteFaceBoundary(filename: str, nbInternalFace: int, faceIdsByTagName: dict)[source]#
Write face boundary

Write face boundary in file

Parameters
  • filename (str) – output file name

  • nbInternalFace (int) – number of internal face

  • physicalTagNames (dict) – mapping between tag name and associated face ids (assume contiguous numerotation for boundary)

WriteFaceCaracteristics(mesh: Mesh, physicalTagNames: Iterable)[source]#
Write face caracteristics, including:
  • boundary file (related to physical tag names in physical problem)

  • faces file

  • owner file

  • neighbour file

Parameters
  • mesh (Mesh) – Mesh to be written

  • physicalTagNames (Iterable) – collection of physical tag names used in physical problem setting

WriteFaceConnectivity(filename: str, triaFaces: ndarray)[source]#
Write face connectivity

Write face connectivity in file

Parameters
  • filename (str) – output file name

  • triaFaces (np.ndarray) – number of internal face

WriteFaceNeighbour(filename: str, internalFacesNeighbours: ndarray, note: str)[source]#
Write face neighbours

Write face neighbours (for each tetra: tetra index attached to each face except minimal index amongst tetra attached to face) in file

Parameters
  • filename (str) – output file name

  • internalFacesNeighbours (np.ndarray) – internal face neighbours

  • note (str) – extra note

WriteFaceOwner(filename: str, facesOwner: ndarray, note: str)[source]#
Write face owners

Write face owner (for each tetra: tetra indices attached to each face whose index is minimal amongst tetra attached to face) in file

Parameters
  • filename (str) – output file name

  • internalFacesNeighbours (np.ndarray) – internal face neighbours

  • note (str) – extra note

WritePoints(filename: str, mesh: Mesh)[source]#

Write nodes coordinates in FOAM format

Parameters
  • filename (str) – Output file name

  • meshObject (Mesh) – Original mesh to be written

WriteSingleNodalField(fieldName: str, fieldValue: Iterable) str[source]#

Write single nodal field in file

Parameters
  • fieldName (str) – field name to be written

  • fieldValue (Iterable) – field value