Gmsh and freefem

Hi,
I’m quite new, i’d like to use freefem with gmsh file mesh.
LoadMesh function make easy to import a 2D gmsh mesh file and labels(Th) function give all physical boundary tags (dim=1).
1 - I’d like to know how to get all physical region tags (dim=2), is there a function return that list ?
2 - I want to solve the heat equation with different kappa for each region, how to define a piecewise constant value for each subdomain identified by their physical tag ? All examples tackles the case where subdomains are easily defined by the indicator domain function, but in my case each domain are complex and only the physical region tag can help to indicate the label region. Is there an instruction to define kappa as the sum of indicator region function lika kappa = 4on(region1) + 2on(region2) ?

Best regards

fespace Ph(Th, P0);
Ph reg = region;
plot(reg);
int region1, region2;
Ph kappa = 4 * (region == region1) +  2 * (region == region2);
1 Like

Thanks that works fine !
is there a way to get the array of all physical tags ?

I’m guessing something like this should work fine.

real[int] tags;
Unique(reg[], tags);
cout << tags << endl;

In fact that’s works well !

I have many regions in my msh file (up to 100). Is there a trick to write kappa definition with many lines instead of having a very long line definition ? Is seems that += operator does not work.

Ph kappa;
for(int i = 0; i < tags.n; ++i) {
  Ph tag = tags[i] * (region == tags[i]);
  kappa[] += tag[];
}

Hi,

Thanks a lot for this short trick, may be you meants Ph tag= valueOfKappa[i] * (region == tags[i]) ?

I’m very sorry to ask some basic questions but i didin’t find any help even if the freefem documentation is quite big.

1 - Moreover i want to define two boundary functions, for example temperature and conductance surface for each mixed boundary condition so that i coult add this in my weak formulation :

  • int1d(Th)(Rsuv)
  • int1d(Th)(RsTsv);

I guess “region” keyword won’t work with labels ? I didn’t find the equivalent keyword for boundaries…

2 - Is there a way to prescribe dirichlet condition for all boundary defined by an int-array ?

uBC = 273.15 * (region==boundary1) + 293.15 * (region==boundary2);

So that i could write this in the weak formula :
+on(arrayDir, u=uDir)

Please read the documentation.

Hi everybody,

I have the same kind of problem but with general elasticity Cijkl. I have 3 domains, but also we could have more. And I wrote

fespace Ph(Th3,P0);

Ph[int] c(37);
for (i=1;i<=6;i++) {
for (j=1;j<=6;j++)
c[(i-1)6+j]=c1(i,j)(region==1)+c2(i,j)(region==2)+c3(i,j)(region==3);
}
where cI(i,j) have been given before as real[int,int].

after I use macro
macro C [[ c[1], c[2], c[3], c[4], c[5], c[6] ],
[ c[7], c[8], c[9], c[10], c[11], c[12] ],
[ c[13], c[14], c[15], c[16], c[17], c[18] ],
[ c[19], c[20], c[21], c[22], c[23], c[24] ],
[ c[25], c[26], c[27], c[28], c[29], c[30] ],
[ c[31], c[32], c[33], c[34], c[35], c[36] ]] // EOM

and then a varf as
varf vK(u,v)=int3d(Th3)( (C*epsilon(u))’ *epsilon(v)) etc ; where epsilon(u) describes strain usual parts.

But my model doesn’t work. And if I replace Ph by real it gives results but I imagine that my domains are not taken into account. Because how a real declaration can take into account a boolean part (region==k)?

So I know I am not very familiar with syntax and I aim to write elegant macro for simplicity but I didn’t achieve it for this general elastic, and then thermoelastic coupled problem.

Could you help me to find the right method to attribute physical properties to many domains (but tensor properties, not only nu or kappa or…) ?

Because I know that I could presumably use 3 varf with a mesh trunc for each domain but I hope a better solution.

Best regards.