Searching...
No Matches
Computational meshers

CAD Exchanger offers the following algorithms based on third-party meshers:

• Mefisto-based algorithm;
• Netgen-based algorithm.

# Mefisto-based algorithm

Mefisto is provided by the MeshAlgo_MefistoFactory class.

When building a mesh, Mefisto uses a maximum element length parameter M. M is computed for each edge from the user-defined parameters (see MeshAlgo_MefistoFactory::Parameters class) as a minimum of three values:

• Explicitly defined absolute value;
• Value calculated from a ratio to the bounding box of a parent shape (Shell or Solid);
• Value calculated from a ratio to the bounding box of a parent Face. If an edge is shared by two (or more) faces then the minimum of all faces is taken.

First, Mefisto splits each model edge honoring individual edge max sizes. Then it builds triangular tessellation for each model face using max size computed from the bounding box of the face. Mefisto works in 2D parameter space using approximate scaling along U and V directions to produce regular mesh in 3D. It is usually faster than Netgen but may produce triangles which sometimes are more skewed than those produced by Netgen.

# Netgen-based algorithm

Netgen is provided by the MeshAlgo_NetgenFactory class.

Netgen uses multiple parameters, including maximum and minimum element sizes, mesh granularity, number of optimization steps, etc. See MeshAlgo_NetgenFactory::Parameters for details.

Netgen primarily works in 3D. Depending on set parameters, it may produce elements with sizes adjusted to local curvatures - greater at flat surface patches and smaller at bending parts.

Once the mesh has been built for edges and faces, Netgen performs additional iterations (controlled by user-defined parameter MeshAlgo_NetgenFactory::Parameters::myOptSteps) to optimize the mesh. Setting this parameter to 0 disables optimization.

Netgen is generally slower than Mefisto and is more sensitive to quality of the input models. It is especially vulnerable (working very slowly) to elongate pin-like faces (or parts thereof).

For surface tessellation Netgen uses the advancing front method.

# Limitations

In addition to above mentioned issues of performance and sensitivity to input geometry, both Netgen and Mefisto can produce too fine-grain meshes. This will result in significant memory footprint (up to hundreds of MB's). In many cases, on complex models, this may result in exceeding virtual memory available for 32 bit applications. Thus, users may have to tailor default parameters for their most typical model configurations.

To mitigate adverse impact of limitations (primarily performance and memory footprint) users can be recommended to consider the following strategies:

• To launch the mesher in a separate worker thread. This will allow to avoid blocking the application GUI thread and will therefore keep the application responsive. In ultimate case, that worker thread can be killed without complete loss of user's data.
• To launch the mesher in a separate worker process. This will not only provide benefits of the previous approach but also can reduce memory footprints at interim computational steps as each process will start with clean memory. To communicate data back from worker processes some method should be designed. One approach is to use temporary STL files to save computed mesh model and restore it in main process.

# Visual comparisons

The following images compare the same models triangulated with the two meshers:

 Mesh built by Mefisto Mesh built by Netgen

# Netgen-specific extensions

CAD Exchanger provides additional extensions when working with the Netgen-based algorithm provided by the MeshAlgo_NetgenFactory class. These include:

• Generation of volume (3D) meshes;
• Specifying boundary conditions;
• Export to specific file formats.
Note
These extensions may only be used for solid bodies (ModelData_Solid and respective ModelData_Body).

## Generation of volume (3D) meshes

In addition to 2D surface elements, Netgen may also create 3D tetrahedron elements. To enable that, respective parameters must be set prior to invoking a computational mesher as follows:

ModelData_Shape aShape = ...;
MeshAlgo_NetgenFactory aF;
MeshAlgo_NetgenFactory::Parameters aP;
//enable volume meshing
aP.myIsVolumeMesh = true;
aP.myVolumeOptSteps = 3;
aF.SetParameters (aP);
//set computational mesher
ModelAlgo_BRepMesher aMesher;
ModelAlgo_BRepMesherParameters& aParam = aMesher.Parameters();
aParam.ComputationalMeshAlgo() = aF;
//iterate over bodies
ModelData_BRepRepresentation aBRep (aShape);
const ModelData_BodyList& aList = aBRep.Get();
for (ModelData_BodyList::SizeType i = 0; i < aList.Size(); ++i) {
const ModelData_Body& aBody = aList[i];
std::shared_ptr<Mesh_SMDS> aMeshDS;
ModelData_PolyShapeList aPSL = aMesher.Compute (aBody, aMeshDS);
}

After initial generation of volume elements, Netgen may invoke iterative optimization. The number of these iterations can be controlled by the MeshAlgo_NetgenFactory::Parameters::myVolumeOptSteps parameter.

Once the computational mesh has been created, the internal Netgen mesh can be retrieved and queried as follows:

if (aMeshDS && aMeshDS->HasNetgenMeshDS()) {
const Mesh_NetgenMeshDS& aNetgenMeshDS = aMeshDS->NetgenMeshDS();
size_t n = aNetgenMeshDS.NumberOfVolumeElements();
}

## Specifying boundary conditions

To prepare the mesh for further usage in CAE applications, original B-Rep faces may be assigned with boundary conditions.

SDK API refers to a boundary condition via its integer id and allows to specify a string name for each boundary condition.

The following example demonstrates how to assign boundary conditions:

ModelData_Body aBody = ...; //original BRep body
const Mesh_NetgenMeshDS& aNetgenMeshDS = aMeshDS.NetgenMeshDS();
for (ModelData_Shape::Iterator i; i.HasNext();) {
const ModelData_Face& aFace = static_cast<const ModelData_Face& aFace> (i.Next());
int aBCIndex = ...; //retrieve the boundary condition id for the face
aNetgenMeshDS.SetFaceBCIndex (aFace, aBCIndex);
}
for (int i = 0; i < aNumberOfBC; ++i) {
Base_String aBCName = ...; //name of the i-th boundary condition
aNetgenMeshDS.SetBCName (aBCIndex, aBCName;
}

Boundary condition indices must be greater or equal to 1. Although CAD Exchanger SDK does not enforce the requirement that indices must be sequential, the internal Netgen algorithms may have such expectations and behave indefinitely otherwise. So ensuring that there are no gaps in the indices is strongly recommended.

## Export to specific file formats

CAD Exchanger SDK allows to export internal Netgen meshes to the following file formats:

CAD Exchanger relies on own Netgen implementation of export. All the writers inherit common base class (Mesh_NetgenBaseWriter) and follow consistent approach:

const Mesh_NetgenMeshDS& aNetgenMeshDS = aMeshDS.NetgenMeshDS();
Mesh_NetgenNeutralWriter aWriter;
if (!aWriter.WriteFile (aNetgenMeshDS, "myfile.vol")) {
std::cerr << "Error occured during writing a mesh file" << std::endl;
}

The OpenFOAM exporter additionally allows to customize the mechanism of writing boundary conditions. Refer to Mesh_NetgenOpenFOAMWriter for details.