How to scale down a mesh?

I am able to read in a mesh which has units of mm, but all the rest of my math relies on units of meters. How can I scale a mesh by a uniform factor to make the mesh match the rest of my code?

I read in the mesh with

domain, markers, facets = io.gmshio.read_from_msh(
        mesh_path, MPI.COMM_WORLD)

Then to establish the units it’s in:

domain_min = np.min(domain.geometry.x, 0)
domain_max = np.max(domain.geometry.x, 0)

print("Domain Min:", domain_min)
# array([-150.,   -5.,   -5.])

print("Domain Max:", domain_max)
# array([150.,   5.,   5.])

So the object spans 300 units on the x axis, which I know corresponds to .3 meters in the real world. I think I need to divide everything by 1000, but nothing I’ve tried works:

domain = domain / 1000
*** TypeError: unsupported operand type(s) for /: 'Mesh' and 'int'

domain.geometry = domain.geometry / 1000
*** TypeError: unsupported operand type(s) for /: 'Geometry' and 'int'

domain.geometry.x = domain.geometry.x / 1000
*** AttributeError: property 'x' of 'Geometry' object has no setter

I wasn’t able to find anything like .scale() or .transform() in the docs either. What am I missing?

mesh.geometry.x[:] /= 1000
as seen with += in Update mesh over time - #2 by dokken

1 Like