Markers¶
Introduction¶
In mufem, as in other FEM codes, you need a method to identify specific parts of the mesh. You can define the regions of the computational domain where a given model operates. You can specify the boundaries that get boundary conditions. You can assign specific materials to designated bodies. To do this, we use markers.
Each marker is an instance of the mufem.Marker class.
It holds the mesh attributes of the entity that you want to mark.
Meshes are usually stored in files of a specific format.
These files describe the connectivity between different elements.
These files include attributes that give information about groups of mesh
elements. A group can represent a particular body or boundary.
For example, the following block shows the beginning of a mesh file created by
the Gmsh mesh generator:
$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
5
2 11 "Bnd1"
2 12 "Bnd2"
2 13 "Bnd3"
3 101 "Vol1"
3 102 "Vol2"
$EndPhysicalNames
$Nodes
945
1 6.798155367234455e-33 6.123233995736766e-17 1
2 1.110223024625157e-16 1 0
3 1 0 0
4 1.359631073446891e-32 1.224646799147353e-16 2
5 2.220446049250313e-16 2 0
...
In the header, between $PhysicalNames and $EndPhysicalNames, we see a block
that holds the mesh attributes.
The number 5 shows that there are five records in total. They follow
immediately after.
The records use three columns.
The first column gives the dimension of the entity of each attribute (2 for
two-dimensional entities, such as planes or boundaries, and 3 for
three-dimensional bodies).
The second column gives an integer attribute for a given entity.
The last column holds an optional string name.
For example, the above mesh has a boundary with the integer attribute
11 and the name "Bnd1".
There is also a volume with the integer attribute 101 and
the name "Vol1".
Defining Markers¶
In mufem we can mark a specific mesh entity in one of the following ways:
This indicates that we are marking a boundary with the integer attribute 11.
This signifies that we are marking a boundary with the string name attribute "Bnd1".
This means that we are marking a volume with the integer attribute 101.
This indicates that we are marking a volume with the string name attribute "Vol1".
We can also mark multiple entities at once. For example, the following code creates a marker that marks two boundaries with the integer attributes 11 and 12:
Similarly, the following code achieves the same result for boundaries with the string name attributes "Bnd1" and "Bnd2":
In the same manner, we can create markers that refer to several volumes at once:
or
Using the Everywhere Keyword¶
In situations where we want to mark the entire computational domain or all the
mesh boundaries, we can use a special keyword Everywhere.
For example, in the case of the above mesh file, the marker
is equivalent to:
Similarly, for volumes, we can use:
which is equivalent to:
Using Regular Expressions¶
When a mesh has several attributes and we prefer not to list them all individually, we can define a marker with a regular expression (regex) pattern. For example, if we have a set of attributes with string names such as "Coil::Vol1", "Coil::Vol2", "Coil::Vol3", and so on, we can create a marker that includes all these volumes as follows:
In this case, the "." in the pattern "Coil::." acts as a placeholder. This marks any string name that starts with "Coil::".
As another example, the following marker:
is equivalent to:
You can use any valid regex pattern for attribute string names to define markers. This approach gives more flexibility and efficiency when you manage a large number of mesh attributes.
Combining Markers¶
You can combine markers to create a new marker that holds the attributes of both terms. For example, in the following code:
The final marker will include all of the attributes 11, 12, and 13, which is equivalent to the following definition:
Example¶
import mufem
sim = mufem.Simulation.New(
name="My Case", mesh_path="data/geometry.mesh", print_only_warnings=True,
)
volume_marker = "MyVolume" @ mufem.Vol
boundary_marker = [
"MyVolume::1::Boundary", "MyVolume::2::Boundary", "MyVolume::3::Boundary"
] @ mufem.Bnd
print(volume_marker)
print(boundary_marker)