xinyuan
November 24, 2021, 10:57am
1
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.
dokken
November 24, 2021, 12:10pm
2
See for instance: Bitbucket
xinyuan
November 24, 2021, 1:09pm
4
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?
dokken
July 15, 2023, 8:17am
6
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?
dokken
July 15, 2023, 6:20pm
8
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
dokken:
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)
Thank you! I will take a look