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 From the python layer, something like mesh.geometry.x.

You can also have a look at:

1 Like

Thank you both, that helps!