Mesh perturbation in C++


I am using a C++ HDG solver which interfaces Netgen. For a project, I would like to perturb the Netgen mesh by changing vertex coordinates.

I have a shared_ptr pointer to access the mesh nodes and I tried to perturb them this way:

Vec<D> vertex; double eps = 1E-8; for (int j = 0; j < VolumeVertices.size(); ++j) { ma->GetPoint(VolumeVertices[j], vertex); for (int dd = 0; dd < D; ++dd){ vertex(dd) = vertex(dd)+eps; } }

but that does not work because I am not updating the actual vertices inside Netgen.

What I would like is to have two pointers, one to the initial unperturbed mesh and one to the deformed mesh but I do not really know how to proceed.

Could you indicate me how to change user-defined vertex coordinates and update the mesh metrics in C++ while keeping an access to the initial mesh? I could not find how to do that when browsing the mesh classes of Netgen.

Thank you very much,


Hi Joachim,

the shared_ptr holds a shared pointer to the Netgen class Mesh (in libsrc/meshing/meshclass.hpp), which can be accessed by “GetNetgenMesh()”.
Having the Mesh object on the Netgen side, you can get a reference to the points using the member function “Points()”, which allows you to modify them.

I guess you have to start with two meshes on the Netgen side and perturb one of them, otherwise you won’t be able to keep initial mesh.


Dear Christoph,

Thank you very much for your reply! With your advice, I managed to modify the vertices coordinates.

What I would like is to keep the solution field the same before and after mesh perturbation, and just modify the mesh metrics. I am thus wondering which routines I should call to update the mesh topology properly (Jacobians, face normals, etc.)?

Right now, I am doing:

shared_ptr<MeshAccess> ma;
shared_ptr<netgen::Mesh> ngmesh = ma->GetNetgenMesh();

Is it sufficient to do it this way or are there other functions that I need to call?

Thanks again,


Hi Joachim,

since you just change the coordinates of the points and not the topology (like number of vertices, edges, …) I think you need neither of them.
Jacobians, normals and so on are calculated based on the ElementTransformation, which loads the coordinates of the points when it is created. Thus you should get the updated ones.

Another option came into my mind, which is used for ALE. You could use

MeshAccess :: SetDeformation (shared_ptr<GridFunction> def)

to set a mesh deformation, which is also considered when Jacobians and normals are calculated.


Dear Christoph,

Thank you very much for your kind input, I will continue working on that.