I have a 2D mesh that I generated via ToElementMesh. It discretizes a square domain with a small hole whose shape comes from a parametric B-spline. I now want to change the shape of the hole very very slightly and produce a new mesh identical in every respect to the original, except that (only) the coordinates of nodes on the hole are changed. The change is small enough so that I do not have to worry about excessive element distortion. Is there any way to update "Coordinates" in the mesh "object" without changing anything else in it?

I tried to build the new mesh manually by extracting "Coordinates" and "MeshElements" from the original. For instance,

XC = meshoriginal["Coordinates"];
ME = meshoriginal["MeshElements"];
meshupdated = ToElementMesh["Coordinates" -> XC, "MeshElements" -> ME];

changes many properties in meshupdated, which I want to keep the same as in meshoriginal (e.g., "BoundaryElements" and several other properties change);

The purpose of this is to compute a finite difference estimate of the gradient of the response with respect to the B-spline parameters.

I apologize in advance if my question does not conform to this forum standards. It's the first time I ask a question. Thanks!

  • 1
    $\begingroup$ It's always good to post complete working code that can be cut and pasted to reproduce exactly what you have. The answers will be better - even in this case. $\endgroup$
    – user21
    Jun 9, 2016 at 20:21

1 Answer 1


You can use

newcoords = updatecoords[XC];
meshupdated = ToElementMesh["Coordinates" -> newcoords, "MeshElements" -> ME,
                            "BoundaryElements" -> meshoriginal["BoundaryElements"],
                            "PointElements" -> meshoriginal["PointElements"]];

That can be sped up (if you are absolutely sure the structure of the mesh did not change) by giving options changing the options of ElementMesh:

{"CheckIncidentsCompletness" -> True, 
 "CheckIntersections" -> Automatic, "CheckQuality" -> Automatic, 
 "DeleteDuplicateCoordinates" -> True, "MessageHead" -> Automatic}


opts = {"CheckIncidentsCompletness" -> False, "CheckIntersections" -> False, 
        "CheckQuality" -> Automatic, "DeleteDuplicateCoordinates" -> False, 
        "MessageHead" -> Automatic}

and give that to ToElementMesh[...., opts]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.