Changing mesh coordinates in fenicsx

Hi all,

I’ve just upgraded from legacy Fenics to Fenicsx. I used to be able to generate a linearly spaced mesh, apply a transformation to its coordinates, and get a new nonlinearly-spaced mesh that I knew would work well for my problem.

It used to work as follows:
mesh = IntervalMesh( num_cells, x_min, x_max )
new_coordinates = some_nonlinear_function( mesh.coordinates()[:,0] )
mesh.coordinates()[:,0] = new_coordinates[:]

I would like to get the same to work. Now I’m generating an interval mesh as follows:
mesh = create_interval( comm=MPI.COMM_WORLD, nx=num_cells, points=(x_min, x_max) )

But this mesh doesn’t have any coordinates() attributes. I would really like to use the transformation I have, and that I know works, as opposed to learning lots of new mesh code from scratch that may not do what I want.

Please let me know if it’s possible. Thanks!

See dolfinx/cpp/dolfinx/mesh/Geometry.h at main · FEniCS/dolfinx · GitHub. From the python layer, something like mesh.geometry.x.

Edit: Updated permalink to relevant C++ code dolfinx/cpp/dolfinx/mesh/Geometry.h at d04eba8996a51a5e0c2d02691577da81302ab0fe · FEniCS/dolfinx · GitHub

You can also have a look at:

1 Like

Thank you both, that helps!