Multipy mesh with coefficient

Hello,

I have an 1D mesh ranging from 0 to 1. How can I multiply all the nodes with a constant coefficient to get a new mesh?

You can use the scale method to multiply all mesh vertex coordinates by a constant:

from dolfin import *
N = 4
factor = 3
mesh = UnitIntervalMesh(N)

# Scale mesh by `factor`:
mesh.scale(factor)

# Equivalent built-in function:
#mesh = IntervalMesh(N,0,factor)

# Check results:
print(FunctionSpace(mesh,"CG",1).tabulate_dof_coordinates())
1 Like

Thank you. Works !!!

Hello,

How would this be done in dolfinx, i.e. with the Mesh object of dolfinx.mesh? Say, I have solved a problem dimensionless and want to scale solution and mesh back to SI units.

I believe I can scale the solution simply by multiplying with a factor, as discussed here, How to scale deformation solution by axial directions, and I would like to do the same with the mesh, to eventually write out the scaled solution on the scaled mesh with the standard io methods, e.g. the dolfinx.io.XDMFFile writer.

If “mesh” is a Mesh object, I can access the coordinates with mesh.geometry.x, but these are read-only attributes.

Thanks a lot for suggestions.

mesh.geometry.x[:,:] *= c
would do it, as you cannot reassigning the x-array, But you can modify its entries.

1 Like

Thank you! That was simple enough :slight_smile: