Setting labels for surfaces at time of square3 meshS creation

I’m making a somewhat complex 3d geometry, with lots of meshS pieces glued together. I can’t seem to find a way to set the label for each surface (needed for some boundary conditions) in the same line that I create the meshS. For example, it seems I have to do this:

int[int] tt1 = [0,2];
meshS Th1 = square3(4, 5, [x, y, 0], orientation=-1);
Th1= change(Th1, reftri=tt1);

I would prefer something like this, if possible:

int[int] tt1 = [0,2];
meshS Th1 = square3(4, 5, [x, y, 0], orientation=-1, reftri=tt1);

to be more succinct, but I can’t figure out what if any other argument to use in the square3 function. As a workaround I tried creating my own function that would combine the two steps into one line, like:

func meshS sq3lab (int &n1, int &n2, func[int] &ff, int &orient, int &tlab) {
meshS Th = square3(n1, n2, [ff[0], ff[1], ff[2]], orientation=orient);
Th = change(Th, reftri=tlab);
return Th;
}

but “func[int]” is not the right syntax for the transformation vector.

Any ideas on a one-line solution with square3 OR with how to implement my user-defined function arguments? Thanks!

If you don’t care about type-checking you can simply create a macro instead.

load "medit"
load "msh3"
macro sq3lab(Th, n1, n2, ff, orient, tlab)
meshS Th = square3(n1, n2, ff, orientation=orient);
Th = change(Th, reftri=tlab);// EOM

int[int] tt1 = [0,2];
sq3lab(ThS1, 4, 5, [x, y, 0], -1, tt1);

There is really no shorter way. In your case, I think making the code more concise makes it less understandable, but that’s my personnal opinion :slight_smile:

1 Like

Thanks for your answer. I can’t believe there’s not another away.

I’m sorry maybe I misunderstood your question, why don’t you use the label parameter (just as with standard cube or square)?

load "msh3"
int[int] tt1 = [10,20,30,40];
meshS Th1 = square3(4, 5, [x, y, 0], orientation=-1,label=tt1);

I had tried that originally. But it seemed that when I set the label, it seemed to be setting the labels for the surface borders and not for the surface (face) itself. I checked this in two ways:

First, when I run medit, the colors of the surfaces don’t change when the labels are different, but I can see an outline (on the surface borders) toggling on and off as I toggle the “matcolors”. When I use change and reftri, the different reftri labels become different colors.

Second, I get a zero solution when I try setting the labels through the label parameter, but when I use change with reftri, I get the expected solution.

Ah, my bad, you want to change the triangle label. Then, no, there is no dedicated one-liner, just as there is no dedicated one-liner for creating and setting the region of the tetrahedra or triangles in a 2D or 3D mesh.

1 Like

Yeah… OK. Thanks a lot for your responses!