Create unstructured mesh region with specified discretisation of one border

Hi,

I am trying to mesh a 2D rectangular region with unstructured elements but I would like to specify a distribution of grid points along one border.

I havve created the border and am using the buildmesh command. However, I can see that this command calls for an integer, i.e. the number of segments to discretise the border. How can I input an array containing the coordinate locations of the grid points? I have seen this is possible with the square command but that is for structured meshes.

thank you for your help

The keyword triangulate allows you to create a mesh from a given set of point. I think you could combine buildmesh+triangulate: create a mesh using buildmesh, throw away the point at the boundary, set them to the value you want, and create the final mesh with triangulate.

Please have a look to the following code, I think this is what you are looking for…

int Npts = 100 ;
// Number of points on the perimeter
int nBPTS = 6;
real[int,int] BPts(nBPTS,2);// Array of information about the border
// BPts(i,0) x-coordinate
// BPts(i,1) y-coordinate
int[int] Labels(nBPTS); // Labels
BPts(0,0) = 0.0 ; BPts(0,1)=0.0; Labels[0] = 0;
BPts(1,0) = 0.40; BPts(1,1)=0.0; Labels[1] = 0;
BPts(2,0) = 1.0 ; BPts(2,1)=1.0; Labels[2] = 0;
BPts(3,0) = 0.0 ; BPts(3,1)=2.0; Labels[3] = 0;
BPts(4,0) = -1.0; BPts(4,1)=1.0; Labels[4] = 0;
BPts(5,0) = -0.5; BPts(5,1)=0.1; Labels[5] = 0;
//
real[int] length(BPts.n); int[int] ptsArr(BPts.n);
real perim=0.0;
//
for(int ii=0; ii<BPts.n; ii++){ int ie = (ii==BPts.n-1? 0: ii+1);
length[ii] = sqrt( (BPts(ie,0)-BPts(ii,0))^2 + (BPts(ie,1)-BPts(ii,1))^2 );
perim+=length[ii]; }
for(int ii=0; ii<BPts.n; ii++) ptsArr[ii] = int(Npts*length[ii]/perim);
//
border a(t=0,1;ii){ label=Labels[ii];
int ib = ii; int ie = (ib==BPts.n-1? 0: ib+1);
x = BPts(ib,0) + (BPts(ie,0)-BPts(ib,0))*t ;
y = BPts(ib,1) + (BPts(ie,1)-BPts(ib,1))*t ; }
//
mesh Th = buildmesh (a(ptsArr));
plot(Th);