# How to mesh an interior rectangle?

**URL:** <https://community.freefem.org/t/how-to-mesh-an-interior-rectangle/3687>\
**Category:** General Discussion\
**Created:** [January 11, 2025, 7:17am UTC](https://community.freefem.org/t/how-to-mesh-an-interior-rectangle/3687 "2025-01-11T07:17:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dxdydelight](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@dxdydelight](https://community.freefem.org/u/dxdydelight)\
**Post date:** [January 11, 2025, 7:17am UTC](https://community.freefem.org/t/how-to-mesh-an-interior-rectangle/3687/1 "2025-01-11T07:17:16Z")

</div>

The overal boundary C I made with 4 lines.  
The line which separates B (a different material) from the rest of the interior I made with a single line - is this the correct approach ?

i’m stuck on how to create A. If i simply create 4 more lines I get a lot of errors - not surprising but I figured I should try.

![rect1](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/7/719b5f15101eafa099c03d6ef6e9e9fbf0e80ce7.png)

I’m wondering if I need to create something similar to this drawing, i.e. two lines across the center, and then two more vertical lines to bound the interior rectangle.

![rect6](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/b/b4ab88cdb7818be1cfdb49a508b86425e89c1fe7.png)

That approach would seem to make the meshing much more difficult as the number of mesh points needs to be tightly controlled based on the location.

Thank you

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [January 12, 2025, 5:03pm UTC](https://community.freefem.org/t/how-to-mesh-an-interior-rectangle/3687/2 "2025-01-12T17:03:40Z")

</div>

Hello,  
You must not double the lines. You can make your middle horizontal line with three pieces, and then the three remaining sides of A are three other pieces.  
Then you build the mesh as in the example of  
[https://doc.freefem.org/documentation/mesh-generation.html](https://doc.freefem.org/documentation/mesh-generation.html)  
code before figure 58.  
The mesh will automatically have three regions. In order to get the region numbers,  
You take the coordinate of a point (x\_1,y\_1) and then `int n1=Th(x_1, y_1).region`  
gives you the region number (which (x\_1,y\_1) belongs to).  
You can then create your variational formulation over this region by involving  
`int2d(Th,n1)(...)`  
You do similarly with the two other regions.
