# Assign different materials (composites)

**URL:** https://community.freefem.org/t/assign-different-materials-composites/2002
**Category:** General Discussion
**Created:** [September 12, 2022, 4:05pm UTC](https://community.freefem.org/t/assign-different-materials-composites/2002 "2022-09-12T16:05:54Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![danmo](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@danmo](https://community.freefem.org/u/danmo)
#### Post date: [September 12, 2022, 4:05pm UTC](https://community.freefem.org/t/assign-different-materials-composites/2002/1 "2022-09-12T16:05:54Z")

</div>

Hi,

I want to simulate a composite material made of matrix (E1) and inclusion (E2). I am not sure how to assign two different material properties and integrate over the domain.  
Assume a classic elasticity problem…how can I modify the following code to separately define C1 and C2 matrices and integrate them in the “solve” command?

// Material Parameters  
real E1 = 100.; // Elastic modulus of matrix  
real nu1 = 0.3; // Poisson’s ratio  
real mu1 = E1/(2\*(1+nu1)); // Lame’s constants  
real lambda1 = E1_nu1/((1+nu1)_(1-2\*nu1)); // Lame’s constants

real E2 = 1; // Elastic modulus of matrix  
real nu2 = 0.01; // Poisson’s ratio  
real mu2 = E2/(2\*(1+nu2)); // Lame’s constants  
real lambda2 = E2_nu2/((1+nu2)_(1-2\*nu2)); // Lame’s constants

func C1 = [[lambda1+2_mu1, lambda1, 0], [lambda1, lambda1+2_mu1, 0], [0, 0, 2_mu1]]; // matrix  
func C2 = [[lambda2+2_mu2, lambda2, 0], [lambda2, lambda2+2_mu2, 0], [0, 0, 2_mu2]]; // inclusion

// Geometric Parameters  
real L = 1;  
real t = 0.1;

// Geometry  
border botout(a=-L/2., L/2){x=a; y=-L/2;}  
border rightout(a=-L/2, L/2){x=L/2; y=a;}  
border topout(a=L/2, -L/2){x=a; y=L/2;}  
border leftout(a=L/2, -L/2){x=-L/2; y=a;}

border botin(a=-L/2+t/2., L/2-t/2.){x=a; y=-L/2+t/2.;}  
border rightin(a=-L/2+t/2., L/2-t/2.){x=L/2-t/2.; y=a;}  
border topin(a=L/2-t/2., -L/2+t/2.){x=a; y=L/2-t/2.;}  
border leftin(a=L/2-t/2., -L/2+t/2.){x=-L/2+t/2.; y=a;}

// Meshing  
mesh Th = buildmesh(botout(45) + rightout(45) + topout(45) + leftout(45) + botin(25) + rightin(25) + topin(25) + leftin(25));  
plot(Th, wait=true);

// FE space  
fespace Vh(Th, [P1, P1], periodic=[[rightout,y], [leftout,y], [botout,x], [topout,x]]);  
Vh [u1, u2]; //unknowns  
Vh [v1, v2]; //test functions

// Definitions  
macro epsilon(u1,u2) [dx(u1), dy(u2), dx(u2)+dy(u1)] //EOM

func Ebar = [1., 0., 0.]; // Applied load

solve Elastic([u1, u2], [v1, v2]) = int2d(Th)(epsilon(v1,v2)'_C_epsilon(u1,u2)) + int2d(Th)(epsilon(v1,v2)'_C_Ebar) ;

![composite](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/a212b3d1b3d69a10bb0a464ca330379b52d80645.png)

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [September 12, 2022, 4:19pm UTC](https://community.freefem.org/t/assign-different-materials-composites/2002/2 "2022-09-12T16:19:06Z")

</div>

Use a P0 function instead of constant scalars. See, e.g., [aldaas2019multi/elasticity-2d.edp at main · prj-/aldaas2019multi · GitHub](https://github.com/prj-/aldaas2019multi/blob/main/elasticity-2d.edp#L49).

---

<div class="post-metadata">

### Author: ![JuillenL](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@JuillenL](https://community.freefem.org/u/JuillenL)
#### Post date: [September 14, 2022, 11:45am UTC](https://community.freefem.org/t/assign-different-materials-composites/2002/3 "2022-09-14T11:45:10Z")

</div>

hello  
where C1 and C2 are used in your code ? in “solve Elastic(…” ??

---

<div class="post-metadata">

### Author: ![Yangshen](https://avatars.discourse-cdn.com/v4/letter/y/838e76/32.png) [@Yangshen](https://community.freefem.org/u/Yangshen)
#### Post date: [September 25, 2022, 6:05am UTC](https://community.freefem.org/t/assign-different-materials-composites/2002/4 "2022-09-25T06:05:08Z")

</div>

Have you solved this problem？  
I have the same problem as you.

---

<div class="post-metadata">

### Author: ![danmo](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@danmo](https://community.freefem.org/u/danmo)
#### Post date: [September 30, 2022, 8:03am UTC](https://community.freefem.org/t/assign-different-materials-composites/2002/5 "2022-09-30T08:03:21Z")

</div>

I think @prj has pointed out how this can be done. Yet, the slicing of the domain was not really straightforward to me so I still could not put it into a code for my case.

---

<div class="post-metadata">

### Author: ![danmo](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@danmo](https://community.freefem.org/u/danmo)
#### Post date: [September 30, 2022, 8:04am UTC](https://community.freefem.org/t/assign-different-materials-composites/2002/6 "2022-09-30T08:04:36Z")

</div>

Yes, they are supposed to appear in my “solve” equation. But I still could not figure out how to divide my domain and assign different materials.

---

<div class="post-metadata">

### Author: ![Yangshen](https://avatars.discourse-cdn.com/v4/letter/y/838e76/32.png) [@Yangshen](https://community.freefem.org/u/Yangshen)
#### Post date: [September 30, 2022, 9:36am UTC](https://community.freefem.org/t/assign-different-materials-composites/2002/7 "2022-09-30T09:36:09Z")

</div>

Thank you very much.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [October 2, 2022, 5:46am UTC](https://community.freefem.org/t/assign-different-materials-composites/2002/8 "2022-10-02T05:46:03Z")

</div>

Something along the following lines.

```auto
fespace Ph(Vh, P0);
Ph lambda = (x < L/4.0 && x > -L/4.0 && y < L/4.0 && y > -L/4.0) ? lambda2 : lambda1;

```
