Skip to content

Commit a8fbe18

Browse files
authored
immersed mesh documentation (#4052)
* immersed mesh documentation
1 parent 018eb5f commit a8fbe18

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

docs/source/images/sin_mesh.png

86.6 KB
Loading

docs/source/mesh-coordinates.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,30 @@ Or simply:
8383
8484
new_mesh = Mesh(Function(f))
8585
86+
Immersing a mesh in higher dimensional space
87+
--------------------------------------------
88+
89+
A useful special case of creating a mesh on modified coordinates is to immerse
90+
a lower dimensional mesh in a higher dimension, for example to create a mesh of
91+
a two-dimensional manifold immersed in 3D.
92+
93+
This is accomplished by setting the value dimension of the new
94+
:py:func:`~.VectorFunctionSpace` to that of the space in which it should be
95+
immersed. For example, a mesh of square bent into a sine wave using
96+
linear (flat) elements can be created with:
97+
98+
.. literalinclude:: ../../tests/firedrake/regression/test_mesh_generation.py
99+
:language: python3
100+
:dedent:
101+
:start-after: start_immerse
102+
:end-before: end_immerse
103+
104+
105+
.. figure:: images/sin_mesh.png
106+
:align: center
107+
108+
A sine-wave shaped triangle mesh immersed in three-dimensional space.
109+
86110

87111
Replacing the mesh geometry of an existing function
88112
---------------------------------------------------

tests/firedrake/regression/test_mesh_generation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,18 @@ def test_split_comm_dm_mesh():
520520
bad_comm = COMM_WORLD.Split(color=(rank % nspace), key=rank)
521521
with pytest.raises(ValueError):
522522
mesh2 = Mesh(dm, comm=bad_comm) # noqa: F841
523+
524+
525+
def test_immerse_mesh():
526+
"""This test exists to ensure that the code used in the manual runs
527+
correctly."""
528+
529+
# start_immerse
530+
mesh = UnitSquareMesh(10, 10)
531+
x, y = SpatialCoordinate(mesh)
532+
coord_fs = VectorFunctionSpace(mesh, "CG", 1, dim=3)
533+
new_coord = assemble(interpolate(as_vector([x, y, sin(2*pi*x)]), coord_fs))
534+
new_mesh = Mesh(new_coord)
535+
# end_immerse
536+
537+
new_mesh # Variable reference to silence linter.

0 commit comments

Comments
 (0)