How to rotate a mesh in FEniCs?

Hello,
I would like to know how to rotate a mesh in FEniCS, according to Documentation Doflin, MeshTransformation_rotate, it should be like: rotate(mesh, angle, axis, point), but I did not succeed, do you have any idea or are there any examples I can learn from?

Thanks in advance.

See for instance: Bitbucket

Thanks! It’s very useful.

Hi @dokken, it looks like dolfinx==0.6.0 does not have a method to rotate the mesh. Is that true?

You can for instance use scipy to work on the mesh geometry directly:

import dolfinx
from mpi4py import MPI
import numpy as np
from scipy.spatial.transform import Rotation

degrees = 90
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
rotation = Rotation.from_euler("z", degrees, degrees=True)
mesh.geometry.x[:,:] = rotation.apply(mesh.geometry.x)
with dolfinx.io.XDMFFile(mesh.comm, "rotated_mesh.xdmf", "w") as xdmf:
    xdmf.write_mesh(mesh)

It is also trivial to extend this to rotation around arbitrary centers:


def rotation_around_point(mesh, p, degree):
    x_original = mesh.geometry.x.copy()
    original_shift = x_original - np.asarray(p)
    rotation = Rotation.from_euler("z", degree, degrees=True)
    mesh.geometry.x[:,:] = np.asarray(p)+rotation.apply(original_shift)
2 Likes

Awesome! Thank you for the quick response. Do you think that rotation of the mesh is enough to implement a “moving band” method (Moving band) without too much headache? Or are there other things to consider?

Ive not read the whole paper that you are referring to, so its hard for me to say anything with too much confidence. The paper seems two involve multiple meshes with assembly from functions on one mesh being transferred to the other, which I guess one could do with the non-matching mesh interpolation implemented by @Massimiliano_Leoni (see for instance https://github.com/FEniCS/dolfinx/blob/84b16751821d359fb2c5db74bcf2894b9c69db74/python/test/unit/fem/test_function.py#L180).

1 Like

Thank you! I will take a look