# Integrating a variable over a line, and returning nodewise value

**URL:** <https://community.freefem.org/t/integrating-a-variable-over-a-line-and-returning-nodewise-value/1993>\
**Category:** General Discussion\
**Created:** [September 8, 2022, 9:59pm UTC](https://community.freefem.org/t/integrating-a-variable-over-a-line-and-returning-nodewise-value/1993 "2022-09-08T21:59:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahdi](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@mahdi](https://community.freefem.org/u/mahdi)\
**Post date:** [September 8, 2022, 9:59pm UTC](https://community.freefem.org/t/integrating-a-variable-over-a-line-and-returning-nodewise-value/1993/1 "2022-09-08T21:59:40Z")

</div>

Dear Colleagues;  
I want to solve an equation like \nabla \Psi=0 with a Dirichlet boundary condition on the dashed-blue line border, where  
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \Psi(y)=\int\_0^y f(y) dy  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/9/99e8ff633d98a47954d320f10537b1ce5090943a.png)

Indeed I want to integrate over a boundary to return value at each node, while the existing functions return the integral on whole boundary. In other words I want F(y)=\int\_0^y f(y) dy , while the existing function gives F(L)=\int\_0^L f(y) dy.

Any thoughts on how can I solve this problem?

---

<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:** [September 9, 2022, 8:43am UTC](https://community.freefem.org/t/integrating-a-variable-over-a-line-and-returning-nodewise-value/1993/2 "2022-09-09T08:43:16Z")

</div>

I am sorry, but I do not understand your problem,

It is some thing like:

find \psi in rectangle \Omega=]0,A[\times]0,L[ such than  
\nabla \phi = 0 in \Omega and \phi = f on line x=0 where f is a given function.

---

<div class="post-metadata">

**Author:** ![mahdi](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@mahdi](https://community.freefem.org/u/mahdi)\
**Post date:** [September 10, 2022, 4:26am UTC](https://community.freefem.org/t/integrating-a-variable-over-a-line-and-returning-nodewise-value/1993/3 "2022-09-10T04:26:47Z")

</div>

Dear professor Hecht

Thanks so much for your answer; Your understanding is correct. But:  
\psi(y)=\int\_0^y f(y)dy . where f(y) is indeed a data nodes [There is not a explicit relation to integrate and f(y) comes out of iteration on data]

What I think I need to do is:

- Define new variable like \alpha where \alpha=\int\_0^y f(y)dy.
- In my weak form add the Dirichlet BC as …+ on(3,\psi=\alpha)+…

As we can see I need to calculate the a cumulative integral for each node,

The only integration in FreeFEM is int1D which returns the integral one whole boundary i.e.  
\int\_0^L f(y)dy, and returns one number as result.  
I am wondering how can I calculate a cumulative integral (i.e. \int\_0^y for each point, y \in [0, L], which returns results for all nodes)

---

<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:** [September 10, 2022, 4:01pm UTC](https://community.freefem.org/t/integrating-a-variable-over-a-line-and-returning-nodewise-value/1993/4 "2022-09-10T16:01:25Z")

</div>

You problem is not correct because, if \nabla\phi=0 then \phi is a constant, so f on border must be constant.

---

<div class="post-metadata">

**Author:** ![mahdi](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@mahdi](https://community.freefem.org/u/mahdi)\
**Post date:** [September 11, 2022, 7:09pm UTC](https://community.freefem.org/t/integrating-a-variable-over-a-line-and-returning-nodewise-value/1993/5 "2022-09-11T19:09:10Z")

</div>

Dear Professor Hecht

Thanks so much for your response;  
As I said an equation **like** \nabla \psi =0, not exactly this one;

The question is how to make a Dirichlet BC as:  
\psi(y)=\int\_0^y f(y) dy ~~~~~~~~~~~ \text{on}~x=0

I think I need to define a variable \alpha where \alpha=\int\_0^y f(y)dy and in my weak form add  
…+on(3,\psi=\alpha)…

However I don’t know if there is any function defined in FreeFEM to calculate a cumulative integral, i.e., F(y)=\int\_0^yf(y)dy~~~y \in [0,L]? The only function that I found is int1D which returns F(L)=\int\_0^Lf(y)dy

---

<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:** [September 12, 2022, 8:03am UTC](https://community.freefem.org/t/integrating-a-variable-over-a-line-and-returning-nodewise-value/1993/6 "2022-09-12T08:03:52Z")

</div>

A way to compute a cumulative integral here alpha , and you can use directly alpha as a BC on on

```auto
load "msh3"

meshL ThL= segment(10,[1,x*pi*2,0]);// vertical segement 
fespace Pl(ThL,P0); // for f
fespace Vl(ThL,P1); // for alpha

Pl f = cos(y);
Vl alpha,aa;
Vl yy=y,ff=sin(y)+0.01; 
solve Pb(alpha,aa) = int1d(ThL) ( dy(alpha)*aa)-int1d(ThL) ( f*aa) +on(1,alpha=0);

plot([yy[],alpha[]],[yy[],ff[]]);

```
