Meshing

The CFD numerical method used for the incompressible setup requires the discretization of the fluid domain, a process also known as meshing. In the Simscale platform, a mesh is an individual object that needs a model to specify its properties, such as sizing. The mesh also has to be computed before the simulation can be run.

Mesh Model

Similar to a simulation, we first need to specify the mesh parameters with a model object. It can be done as follows:

import simscale_sdk as sim

mesh_model = sim.SimmetrixMeshingFluid(
    sizing=sim.AutomaticMeshSizingSimmetrix(
        fineness=5,
        curvature=sim.AutomaticCurvature(),
    ),
    automatic_layer_settings=sim.AutomaticLayerOn(
        layer_type=sim.FractionalHeight2(
            number_of_layers=3,
            total_relative_thickness=0.4,
            growth_rate=1.5
        ),
    ),
    physics_based_meshing=True,
    hex_core=True,
)

Here we make use of the automatic sizing with fineness level 5. Also, physics-based meshing allows to take into account boundary conditions for layer creation. boundary layer settings are entered manually with 3 layers on walls. Finally, the hex_core is entered to improve the orthogonality of the mesh.

Mesh Operation

Now that we have a proper mesh model, we can create the mesh operation, which links the project, the geometry and the model:

import simscale_sdk as sim

mesh_operation_api = sim.MeshOperationsApi(api_client)

mesh_operation = mesh_operation_api.create_mesh_operation(
    project_id,
    sim.MeshOperation(
        name="Pipe junction mesh",
        geometry_id=geometry_id,
        model=mesh_model,
    )
)

The mesh operation object is used to launch the computation and track its progress:

mesh_operation_api.start_mesh_operation(
    project_id,
    mesh_operation.mesh_operation_id,
    simulation_id=simulation.simulation_id,
)

while mesh_operation.status not in ("FINISHED", "CANCELED", "FAILED"):

    mesh_operation = mesh_operation_api.get_mesh_operation(
        project_id,
        mesh_operation.mesh_operation_id,
    )

    time.sleep(30)

print(f"Mesh with id={mesh_operation.mesh_id} was completed with status {mesh_operation.status}")

You should recognize this pattern from the geometry import process. Of course, it is possible to improve the loop, as was done there, to include a time limit or use parallel async computation of multiple meshes.

Generating Code for Mesh Model

In the same fashion as a simulation model, SDK code can be generated from an existing mesh that was set up in the Workbench for convenience (for example, to easily assign refinements to geometry faces). To achieve this, we make use of the MeshOperationsApi.get_mesh_operation_sdk_code() method:

mesh_skd_code = mesh_operation_api.get_mesh_operation_sdk_code(
    project_id,
    mesh_operation_id,
)

The mesh_operation_id can be obtained in a similar fashion to the way is done for a simulation:

print(mesh_operation_api.get_mesh_operations(project_id))

Then identifying the proper mesh and noting down its mesh_operation_id.