# How to 1D integrate along a path inside mesh

**URL:** <https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700>\
**Category:** General Discussion\
**Created:** [December 22, 2020, 11:14pm UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700 "2020-12-22T23:14:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![amtravco](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@amtravco](https://community.freefem.org/u/amtravco)\
**Post date:** [December 22, 2020, 11:14pm UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700/1 "2020-12-22T23:14:22Z")

</div>

Suppose I have a mesh Th defined in the square from x = 0 to 1, y = 0 to 1. I solve a PDE on this mesh, getting solution u. Now I want to know the line integral of u along the straight path from (0, 1/2) to (1, 1/2), that is, along a horizontal line that goes through the center of the square. What is the correct syntax for this?

I tried defining a border “bb” that runs from (0, 1/2) to (1, 1/2), then calling

```
   int1d(Th, bb)(u),

```

but this gives zero. I assume this fails because bb is not an actual border of Th.

---

<div class="post-metadata">

**Author:** ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)\
**Post date:** [December 23, 2020, 6:35am UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700/2 "2020-12-23T06:35:33Z")

</div>

I think you should use `levelset` keyword for the integration. something like

> `int1d(Th, levelset=phi)(...)`

see doc [here](https://doc.freefem.org/documentation/finite-element.html#parameters-affecting-solve-and-problem)

---

<div class="post-metadata">

**Author:** ![amtravco](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@amtravco](https://community.freefem.org/u/amtravco)\
**Post date:** [December 24, 2020, 3:33am UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700/3 "2020-12-24T03:33:09Z")

</div>

Hi. I looked at the documentation, but I didn’t really understand what “levelset” does. How would adding this flag allow me to integrate along a given path?

---

<div class="post-metadata">

**Author:** ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)\
**Post date:** [December 24, 2020, 6:28am UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700/4 "2020-12-24T06:28:57Z")

</div>

take this [example](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/tutorial/intlevelset.edp).

> func r = sqrt(x_x +y_y);  
> real lc = int1d(Th,levelset=r-1.)(1.) ;

here it integrates along the circle of radius one. Basically the `phi` in  
`int1d(Th, levelset=phi)(...)` is the parametric equation along which you integrate.

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.freefem.org/u/gaurav)\
**Post date:** [September 14, 2021, 12:01pm UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700/5 "2021-09-14T12:01:46Z")

</div>

Hi,

I managed to get two domains: one big domain and inside that big domain, I have a small domain. I need to get line integral around the small domain as well as area integral. I am getting some value as one d line integral but the area integral is zero. Can you suggest what is the best way of doing that? Thankyou.

 ![example](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/5294ecf5a09f1d6f841fce2bb57621e4e1ded0f5.png)

---

<div class="post-metadata">

**Author:** ![Emma87](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@Emma87](https://community.freefem.org/u/Emma87)\
**Post date:** [September 15, 2021, 12:52am UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700/6 "2021-09-15T00:52:33Z")

</div>

see it:

> [@How to 1d intergrate along x/y direction in 2d mesh](https://community.freefem.org/t/how-to-1d-intergrate-along-x-y-direction-in-2d-mesh/986):
>
> Now I have a mesh Th defined in the square from x = 0 to 1, y = 0 to 1. I solve a PDE on this mesh, getting solution u. Then I want to know the line integral of u along y to get ∫𝑢𝑑𝑦, but I don’t know how to implement

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.freefem.org/u/gaurav)\
**Post date:** [September 15, 2021, 9:41am UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700/7 "2021-09-15T09:41:38Z")

</div>

Thanks, but in my case, I have the labels available. I have a problem in getting area integral for f(u)dxdy in the smaller domain (black mesh). Mesh Th is defined for the whole domain (green+black) and int2d(Th,1)(f(u)) doen’t give me any result. 1 is the labels of inner boundary (black).

---

<div class="post-metadata">

**Author:** ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)\
**Post date:** [September 14, 2023, 8:30am UTC](https://community.freefem.org/t/how-to-1d-integrate-along-a-path-inside-mesh/700/8 "2023-09-14T08:30:54Z")

</div>

I am not sure this is what you are looking for, but if you do a 1d integral, ` int1d(Th,BoundaryLabel)`, then `BoundaryLabel` is the label of your border. From what I see, you do a 2d integral, with a label. the 2d integrals work like this: `int2d(Th,RegionLabel)` and here `RegionLabel` is the label of the region, and in general it is different from the boundary label. I guess you have no region with number `1`…

If I am correct, you should check the region number. This can be easily done by defining a `P0` function equal to `region`, and check its value:

> fespace Uh(Th,P0);  
> Uh Reg = region;  
> plot(Reg,fill=1,value=1,wait=true); //to see the value of the region flag
