# Unifying regions to assing constant values

**URL:** <https://community.freefem.org/t/unifying-regions-to-assing-constant-values/2097>\
**Category:** General Discussion\
**Created:** [November 2, 2022, 12:10am UTC](https://community.freefem.org/t/unifying-regions-to-assing-constant-values/2097 "2022-11-02T00:10:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![galfras](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@galfras](https://community.freefem.org/u/galfras)\
**Post date:** [November 2, 2022, 12:10am UTC](https://community.freefem.org/t/unifying-regions-to-assing-constant-values/2097/1 "2022-11-02T00:10:36Z")

</div>

Hello!

I have a domain like the one shown in the picture. I need to solve an equation where k = 1 inside the squares and 0 outside (ignore the red border). I know it is possible to solve this in multiple ways and I actually solved it defining the value of k using k=a\*(x\<b)\*(x\>c)… for each square.

My question is, is it possible to somehow define the region inside the squares like only one region (something like k=1\*(region==squares)) and apply the value of k only one time to the hole area? I also tried to build a mesh with the squares and use that mesh to define the value of k, but i couldn’t make it work.

Thanks!

![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/f/f4ff761e87d31e0721bea6aade8886f3e8ecd016.png)

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [November 2, 2022, 5:36pm UTC](https://community.freefem.org/t/unifying-regions-to-assing-constant-values/2097/2 "2022-11-02T17:36:27Z")

</div>

Remark , by default the region a different on each region.

So if you put all centre of square in a array cs(2,nsquare)

you can get the region numler of each square

here the mesh is call TH

```auto
int[int] regs= regions(Th); 
int[int] labs= labels(Th); 
int mxreg = regs.max+1; 
assert(merge < 1000); // no too big
int[int] regs(nsquare);
for(int i=0; i<nsquare;++i)
 regs[i] = Th(cs(0,i),cs(1,i)).region ; // get the region number of each square;

real[int] K(mxreg);

K= 2; // out of square;
for(int i=0; i<nsquare;++i)
  K[regs[i]] =1.; // put 1 on each square

// new to use K 
fespace Ph(Th,P0); // function constant per Triangle
Ph Kk=K[region];
plo(Kk, fill=1, wait=1);
Vh u,v; 
solve Lap(u,v) ( K[region]*grad(u)'*grad(v)- +on(labs,u=1); 

// region depend directly of the place of the current point . 
//or
solve Lap1(u,v) ( Kk*grad(u)'*grad(v)- +on(labs,u=1); 

```
