# Elastic structure analysis with two different material constants depending on region (can't \[region\] be specified in \[buildmesh\]?)

**URL:** https://community.freefem.org/t/elastic-structure-analysis-with-two-different-material-constants-depending-on-region-cant-region-be-specified-in-buildmesh/2766
**Category:** General Discussion
**Created:** [October 31, 2023, 11:54am UTC](https://community.freefem.org/t/elastic-structure-analysis-with-two-different-material-constants-depending-on-region-cant-region-be-specified-in-buildmesh/2766 "2023-10-31T11:54:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Keita](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@Keita](https://community.freefem.org/u/Keita)
#### Post date: [October 31, 2023, 11:54am UTC](https://community.freefem.org/t/elastic-structure-analysis-with-two-different-material-constants-depending-on-region-cant-region-be-specified-in-buildmesh/2766/1 "2023-10-31T11:54:35Z")

</div>

Hello, FF++ developers!

I would like to do structural analysis of elastic bodies with different material constants in different regions.  
When creating a mesh with the square command, the [region] can be set, but this is not possible with the [buildmesh] command.  
How can I do it?

I am considering the analysis of an elastic body with a region (A, B) having two different material constants, with the description of the equation as shown below.

* * *

## solve Elasticity ([uu, vv], [w, s]) = int2d(th,regionA)( lambda\*div(w,s)\*div(uu,vv) + 2._mu_( epsilon(w,s)'_epsilon(uu,vv) ) ) +int2d(th,regionB)( lambda_div(w,s)\*div(uu,vv) + 2._mu_( epsilon(w,s)'_epsilon(uu,vv) ) ) + int2d(th)( - gravity_s ) + on(1, uu=0, vv=0) ;

Thank you in advance.

---

<div class="post-metadata">

### Author: ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)
#### Post date: [October 31, 2023, 1:08pm UTC](https://community.freefem.org/t/elastic-structure-analysis-with-two-different-material-constants-depending-on-region-cant-region-be-specified-in-buildmesh/2766/2 "2023-10-31T13:08:28Z")

</div>

See if this helps. IIRC, It makes a mesh with a line in the middle creating two regions  
which can then be used to determine material properties etc.

[innerline.edp](https://community.freefem.org/uploads/short-url/8msqhi5x6wXVGjr4apLikQwZVu7.edp) (1.4 KB)

```auto
 cat drill.edp 
load "medit" 
macro buildouter()
border left(t=0, 1){x=-szx/2; y=szy*(t-.5);label=1; }
border top(t=0, 1){x=szx*(t-.5);y=szy/2; label=2; }
border right(t=0, 1){x=szx/2; y=-szy*(t-.5);label=3; }
border bottom(t=0, 1){x=-szx*(t-.5);y=-szy/2; label=4; }
 // EOM
real szx=2;
real szy=1;
int nx=20;
int ny=20;
buildouter
border middle(t=0, 1){x=0; y=-szy*(t-.5);label=5; }

mesh Th = buildmesh(left(-ny)+top(-nx)+right(-ny)+bottom(-nx)
 + middle(ny));
//medit("Th",Th);
//plot(Th,wait=1,fill=1);
//medit("Th",Th);
macro Op(xx,vxx) (dx(xx)*dx(vxx)+dy(xx)*dy(vxx)) // 
fespace Vh1(Th,P1);
fespace Vh2(Th,P2);
Vh1 a1,va1,b1=0;
Vh2 a2,va2,b2=0;
// https://doc.freefem.org/examples/mesh-generation.html
int rl=Th(-szx/2,0).region;
int rr=Th(szx/2,0).region;;
cout<<" rl="<<rl<<" rr="<<rr<<endl; cout.flush;
problem both([a1,a2],[va1,va2],solver=sparsesolver,tgv=-1)
//problem both([a1,a2],[va1,va2],solver=CG)
= int2d(Th,rl)(Op(a1,va1))+int2d(Th,rl)(b1*va1)
+ int2d(Th,rr)(Op(a2,va2))+int2d(Th,rr)(b2*va2)
// otherwise use CG 
+int2d(Th,rr)(a1*va1)+int2d(Th,rl)(a2*va2)
// a1 to a2 boundary 
+int1d(Th,5)(a2*va2)-int1d(Th,5)(a1*2.0*va2)
+int1d(Th,5)(a2*va1)-int1d(Th,5)(a1*2.0*va1)
+on(1,a1=2*y)+on(3,a2=-3*y)
;

both;
Vh1 net=a1+a2;
plot(a1,cmm="a1",wait=1,fill=true,value=1);
plot(a2,cmm="a2",wait=1,fill=true,value=1);
plot(net,cmm="net",wait=1,fill=true,value=1);
medit("net",Th,net);

marchywka@happy:/home/documents/cpp/proj/freefem/forum$ 

```

---

<div class="post-metadata">

### Author: ![lucassfernandez](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@lucassfernandez](https://community.freefem.org/u/lucassfernandez)
#### Post date: [October 31, 2023, 5:27pm UTC](https://community.freefem.org/t/elastic-structure-analysis-with-two-different-material-constants-depending-on-region-cant-region-be-specified-in-buildmesh/2766/3 "2023-10-31T17:27:53Z")

</div>

Hi Keita,

Please, take a look at Chapter 2, Section 2.15 Optimal Control ([https://doc.freefem.org/pdf/FreeFEM-documentation.pdf](https://doc.freefem.org/pdf/FreeFEM-documentation.pdf)). In such a problem, the reference domain is a circle with three smaller circles within. Each circle has a different material property. The mesh is created from the buildmesh command.

;D I hope it is useful.

---

<div class="post-metadata">

### Author: ![Keita](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@Keita](https://community.freefem.org/u/Keita)
#### Post date: [November 1, 2023, 2:25am UTC](https://community.freefem.org/t/elastic-structure-analysis-with-two-different-material-constants-depending-on-region-cant-region-be-specified-in-buildmesh/2766/4 "2023-11-01T02:25:20Z")

</div>

Dear marchywka

Thank you very much for your prompt reply !!  
When setting the area with [buildmesh], I was able to do what I wanted by using [border] to delimit the area around the area I wanted to distinguish.  
I see that different region labels change the color of the mesh (sorry, amateur).

* * *

・Create a region mesh with [buildmesh] (use only the minimum necessary [border])  
・Add [border] to delimit the area

Thank you for your continued support.  
Keita Kambayashi

---

<div class="post-metadata">

### Author: ![Keita](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@Keita](https://community.freefem.org/u/Keita)
#### Post date: [November 1, 2023, 2:41am UTC](https://community.freefem.org/t/elastic-structure-analysis-with-two-different-material-constants-depending-on-region-cant-region-be-specified-in-buildmesh/2766/5 "2023-11-01T02:41:28Z")

</div>

Dear lucassfernandez

Thank you for your prompt reply!!  
I have checked the references you indicate.  
The reference you provided is for a function that returns a value for each region (Ib, Ic … etc.) that return different values for each region.  
This could be implemented for various regions by combining inequalities for the functions used to create [border].

Your advice was very useful, but in this case I have adopted the other comment.  
I will refer to it in the future.

Thank you for your continued support.  
Keita Kambayashi
