Geometry Initialization

utils.ls_utils.init_level_set(msh: dolfinx.mesh.Mesh, parameters, test_case: str) → dolfinx.fem.Function[source]

Initialize the level-set function defined on the mesh.

The function returns a dolfinx.fem.Function defined in a standard Lagrange space (degree 1). The level-set expression is interpolated onto the function space.

Parameters:
  • msh (dolfinx.mesh.Mesh) – Mesh where the level-set is defined.

  • parameters (Parameters) – Parameters object used by analytic expressions (if required).

  • test_case (str) – Identifier of the test case to choose the analytic level-set.

Returns:

The level-set function interpolated on V_ls.

Return type:

dolfinx.fem.Function

utils.ls_utils.level_set(x, parameters)[source]

Computes a 2D level set function based on cosine functions.

This function returns a level set value based on a combination of cosine functions depending on the coordinates of the input point x = (x_0, x_1) and a parameter lx.

\[\text{level set}(x) = -\cos\left(\frac{6\pi x_0}{l_x}\right)\cos(4\pi x_1) - 0.6\]
Parameters:
  • x (tuple) – A tuple representing the point coordinates (x_0, x_1).

  • parameters (object with attribute lx.) – The parameters object containing the domain length lx.

Returns:

The computed level set value.

Return type:

float

utils.ls_utils.level_set_3D(x, parameters)[source]

Computes a 3D level set function based on cosine functions.

This function returns a level set value based on a combination of cosine functions depending on the coordinates of the input point x = (x_0, x_1, x_2) and a parameter lx, ‘ly’ and ‘lz’, the dimensions of the box containing \(\Omega\).

\[\text{level set}(x) = -\cos\left(\frac{6\pi x_0}{l_x}\right)\cos(4\pi x_1)\cos(4\pi x_2) - 0.6\]
Parameters:
  • x (tuple) – A tuple representing the point coordinates (x_0, x_1, x_2).

  • parameters (object with attribute lx.) – The parameters object containing the domain length lx, ‘ly’ and ‘lz’.

Returns:

The computed level set value.

Return type:

float

utils.ls_utils.level_set_L_shape(x)[source]

Calculate the level set for an L-shaped domain.

This function computes the level set for a geometric shape consisting of a series of overlapping circles. The L-shape is represented by a set of level sets for these circles, and the function uses the ufl.max_value and ufl.sqrt functions to compute the level set values for a given point x in the domain.

Parameters:

x (tuple of float) – A tuple containing the coordinates (x[0], x[1]) of the point where the level set is evaluated. The point is expected to be in 2D space.

Returns:

The computed level set value at the point x. The value represents the distance from the point x to the nearest boundary of the L-shaped domain formed by the overlapping circles. A negative value indicates the point is inside the domain, and a positive value indicates the point is outside the domain.

Return type:

float

Notes

The function uses a series of circles with radius r_cercle and an adjusted radius r_cercle_modif to form the shape. The level set is computed by iteratively taking the maximum of the distances to the circle boundaries.

The function is designed to work with the ufl module, typically used in finite element methods for computational geometry and simulations.

Example

>>> x = (1.0, 2.0)
>>> level_set_L_shape(x)
-0.0037388523762586055

See also

ufl.max_value, ufl.sqrt

utils.ls_utils.load_mesh(test_case, parameters, mesh_folder='mesh')[source]

Load or create a mesh based on the test case or provided mesh file.

Parameters:
  • test_case (str) – The test case name (“rectangle”, “L_shape”, or “3D”).

  • parameters (Parameters) – The object parameters.

  • mesh_folder (str) – The folder where mesh files are stored.

Returns:

The mesh object.

Return type:

dolfinx.mesh.Mesh