Build mesh from a vector of nodes

I’m trying to build a mesh using a vector of nodes

real[int,int] nodes = [[0,0],

border bdry(t=0,nodes.n-1){ P.x=nodes(0,t); P.y=nodes(1,t); label=1; };
mesh Th = buildmesh(bdry(nodes.n-1),fixeborder=true); 

But I get the following error:

Out of bound  0 <=0 < 9 2 < 2 array type = P3KNMIdE
  current line = 11

What am I doing wrong?

The way you set up your matrix of nodes, it is \in\mathbb{R}^{9\times2}. You are treating it somehow mixed, like sometimes as \in\mathbb{R}^{9\times2} an sometimes as \in\mathbb{R}^{2\times 9}. Check the documentation Types for matrix size.

real[int,int] nodes = [[0,0],[0.5,0],[1,0],[0,0.5],[0.5,0.5],[1,0.5],[0,1],

// cout << nodes << endl;
cout << "nrows = " << nodes.n << ", ncols" << nodes.m << endl;

border bdry(t=0,nodes.n-1){ P.x=nodes(t,0); P.y=nodes(t,1); label=1; };

Also, your boundary is not a closed loop, so it won’t mesh of course.

Check also post Building a border from an array of vertices - #2 by fivanci, although, I see now there is lapsus calami in there as well. It should be, in declaration,
real[int,int] vtxCoords(2,nn); and later in code vtxCoords.n-1\mapstovtxCoords.m-1.


Do you know a way to build a mesh using connectivity matrix? Something like:

matrix elems = [[1,2,5,4],

matrix edges = [[1,2],

I’m trying to get control over all edges, boundary and internal. Also, I wouldlike to label each edge

When you say label, you mean label each edge in the triangle ( local [1,2,3] \mapsto global [i_1,i_2,i_3] ) ? I.e., by

you mean (global) label each edge in the mesh by hand ?

  1. In that case, why use automatic mesh generator ? Seems to me it is easier to just write the mesh file directly – I am assuming you are checking some technical things and need only relatively small mesh (with small amount of entities), otherwise this would be a tedious procedure. If this is indeed the case, please read the documentation, e.g. Mesh Generation (there is everything you need). Also, for mesh connectivity you can check Mesh Generation .

  2. Alternatively, command change(...) (Mesh Generation) might also be of interest since it gives a certain amount of control over mesh entities. Actually, in the documentation it says you can prescribe a new numbering of both vertices and elements (renumv, renumt), although I never played with this.

  3. As a third option, you might want to look at gmsh software and explicitly construct your mesh via .geo file – a tradeoff (up to some extent) between writing by hand directly a mesh into file and automatic mesh generation. You can have a great control over mesh entities labeling with a little bit of writing.


1 Like