Creating a mesh
We start with setting the Feel++ environment and loading the Feel++ library.
import feelpp
import sys
app = feelpp.Environment(["myapp"],config=feelpp.localRepository(""))
Results
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) File:1 ----> 1 import feelpp 2 import sys 3 app = feelpp.Environment(["myapp"],config=feelpp.localRepository("")) ModuleNotFoundError: No module named 'feelpp'
1. Load a mesh from a geo or msh file
feelpp.mesh(dim=2, geo=1, realdim=2, worldComm=None) : create a mesh.
The mesh is of topological dimension dim, in real dimension realdim with geometric order geo.
The mesh is configured with a WorldComm which provides the parallel process layout.
Keyword arguments:
-
dim: the topological dimension (default:2) -
geo: the geometrical order (default:1) -
realdim: the real dimension (default:2) -
worldComm: the parallel communicator for the mesh (default:Environment::worldCommPtr())
feelpp.load(m, path, size) → feelpp._mesh.Mesh_S1DG1R1 : load a mesh from a file
-
mdeclared with the functionmeshabove -
path(string) path to the geometry (withgeoormshformat) -
size(float) size of the meshed geometry (if it is not meshed yet)
geo=feelpp.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0]
print("geo file: {}".format(geo))
mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), geo, 0.1)
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) File:1 ----> 1 geo=feelpp.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0] 2 print("geo file: {}".format(geo)) 3 mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), geo, 0.1) NameError: name 'feelpp' is not defined
2. Usage
The mesh provides the Feel++ data structures in Python:
The following methods are to use on the mesh object (mesh in the previous example) :
2.1. Mesh information :
-
dimension(self) → int: get topological dimension -
hAverage(self) → float: get the average edge length of the mesh -
hMax(self) → float: get the maximum edge length of the mesh -
hMin(self) → float: get the minimum edge length of the mesh -
measure(self, parallel: bool = True) → float: get the measure of the mesh (which is equal to \(\int_\Omega 1\)) -
measureBoundary(self) → float: get the measure of the boundary of the mesh (which is equal to \(???\)) -
numGlobalEdges(self) → int: get the number of edges over the whole mesh, requires communication if the mesh is parallel -
numGlobalElements(self) → int: get the number of elements over the whole mesh, requires communication if the mesh is parallel -
numGlobalFaces(self) → int: get the number of faces over the whole mesh, requires communication if the mesh is parallel -
numGlobalPoints(self) → int: get the number of points over the whole mesh, requires communication if the mesh is parallel -
realDimension(self) → int: get real dimension -
updateMeasures(self) → None: update the measures of the mesh
Here is an example of how to use the mesh information:
print(f"dimention: {mesh.dimension()}")
print(f"number of elements: {mesh.numGlobalElements()}")
print(f"number of faces: {mesh.numGlobalFaces()}")
print(f"hmin: {mesh.hMin()}")
print(f"havg: {mesh.hAverage()}")
print(f"hmax: {mesh.hMax()}")
print(f"measure: {mesh.measure()}")
print(f"measure of boundary: {mesh.measureBoundary()}")
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) File:1 ----> 1 print(f"dimention: {mesh.dimension()}") 2 print(f"number of elements: {mesh.numGlobalElements()}") 3 print(f"number of faces: {mesh.numGlobalFaces()}") NameError: name 'mesh' is not defined
2.2. Test relation between meshes :
-
isParentMeshOf(self: feelpp._mesh.Mesh_S3DG1R3, arg0: feelpp._mesh.Mesh_S3DG1R3) → bool: is the mesh the parent mesh of another mesh -
isRelatedTo(self: feelpp._mesh.Mesh_S3DG1R3, arg0: feelpp._mesh.Mesh_S3DG1R3) → bool: is the mesh related to another mesh -
isSiblingOf(self: feelpp._mesh.Mesh_S3DG1R3, arg0: feelpp._mesh.Mesh_S3DG1R3) → bool: is the mesh a sibling of another mesh -
isSubMeshFrom(self: feelpp._mesh.Mesh_S3DG1R3, arg0: feelpp._mesh.Mesh_S3DG1R3) → bool: is the mesh a sub mesh of another mesh
2.3. Export and load mesh on HDF5 format
-
saveHDF5(self, name: str) → None: save mesh to H5 file -
loadHDF5(self, name: str) → None: load mesh from H5 file
3. Ranges
elements-
feelpp.elements(mesh): get iterator over the elements of the mesh markedelements-
-
feelpp.markedelements(mesh, tag: str): get iterator over the marked elements of the mesh -
feelpp.markedelements(mesh, marker: str): return the range of elements of the mesh with marker -
feelpp.markedelements(mesh, markers: List[str]): return the range of elements of the mesh with markers
-
faces-
feelpp.faces(mesh): get iterator over the faces of the mesh markedfaces-
-
feelpp.markedfaces(mesh, marker: str): return the range of facets of the mesh with marker -
markedfaces(mesh, markers: List[str]): return the range of facets of the mesh with marker
-
boundaryfaces-
feelpp.boundaryfaces(mesh): get iterator over the boundary faces of the mesh
A first example with ranges:
r = feelpp.elements(mesh)
print("mesh elts:", feelpp.nelements(r))
r = feelpp.boundaryfaces(mesh)
print("mesh boundary faces:", feelpp.nelements(r))
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) File:1 ----> 1 r = feelpp.elements(mesh) 2 print("mesh elts:", feelpp.nelements(r)) 3 r = feelpp.boundaryfaces(mesh) NameError: name 'feelpp' is not defined
A second more interesting example with ranges uses integrate to compute integrals of expressions over the mesh:
from feelpp.integrate import integrate
i1 = integrate(range=feelpp.elements(mesh),expr="sin(x+y):x:y")
i2 = integrate(range=feelpp.boundaryfaces(mesh),expr="x*nx+y*ny+z*nz:x:y:z:nx:ny:nz")
i3 = integrate(range=feelpp.markedelements(mesh, "marker"), expr="1")
print(f"i1 = {i1}, i2 = {i2}, i3 = {i3}")
Results
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) File:1 ----> 1 from feelpp.integrate import integrate 3 i1 = integrate(range=feelpp.elements(mesh),expr="sin(x+y):x:y") 4 i2 = integrate(range=feelpp.boundaryfaces(mesh),expr="x*nx+y*ny+z*nz:x:y:z:nx:ny:nz") ModuleNotFoundError: No module named 'feelpp'