# Value and derivative at same boundary pt, "+on" ignored?

**URL:** <https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429>\
**Category:** General Discussion\
**Created:** [May 4, 2023, 9:49am UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429 "2023-05-04T09:49:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 4, 2023, 9:49am UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429/1 "2023-05-04T09:49:37Z")

</div>

Quite often it looked like some boundary conditions were ignored.  
So, I went back to a simple example trying to generate a sine wave  
in 1D starting at arbitrary phase and amplitude ( value and slope on left ).  
I could not find a combination of terms to do that and inevitably the result  
had a value of slope of zero on the other end of the mesh. Also, I could not figure  
out how to plot the things in FreeFEM so I just exported to txt files and used R.  
Looking at the matrix and RHS, it appeared in many cases that “+on” had no  
effect. I guess I could try to “do the math” and figure out what entries I expect  
in “A” and b or see why it is not possible but thought someone may know offhand.  
In 1D with P1 elements and a uniform mesh it shouldn’t be that difficult, the laplacian  
looks like a scaled FD expression.

```auto
 cat sinephase.edp 
load "msh3"
load "medit"
int nx=100;
//int nx=5;
int[int] lbe=[100,200]; // begin and end point labels 
meshL Th=Sline(nx, [1.5*x],label=lbe);
fespace Vh(Th,P1);
Vh u,v;
Vh w=x;
// the tgv is ignored here... 
varf sinewave(u,v,tgv=-1) 
= int1d(Th)(dx(u)*dx(v)) + int1d(Th)(-4*pi*pi*u*v)
+int0d(Th,100)(-11230*v)
+on(100,u=10) // value on 100
;
matrix A=sinewave(Vh,Vh,tgv=-1);
real[int] b= sinewave(0,Vh,tgv=-1);
real[int] sm=A^-1 * b;
if (false)
{
cout<<" solution axb : "; cout<<sm;
cout.flush;
{ofstream outf("sinea.txt");
outf<<A<<endl;
cout<<A<<endl;
outf.flush;
}
{ofstream outf("sineb.txt");
outf<<b<<endl;
cout<<b<<endl;
outf.flush;
}
//if (nx<50) 
{ofstream outf("sine.txt");
for(int i=0; i<sm.n; ++i) outf<<i<<" "<<w[][i]<<" "<<sm[i]<<endl;
outf.flush;
}
}
u[]=sm;
// how to plot? 
//plot(u,wait=1, fill=1);
//plot(1:10,sm,wait=1, fill=1);
//medit("asdf", [sm,sm]);

```

[sinephase.edp](https://community.freefem.org/uploads/short-url/1CGv4jBIsF632J7SUpUXjTIocvY.edp) (879 Bytes)

---

<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:** [May 4, 2023, 10:01am UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429/2 "2023-05-04T10:01:30Z")

</div>

Why are you saying it’s ignored? Just look at `b`, you’ll see the first value to be precisely what you put in your `on`.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 4, 2023, 10:16am UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429/3 "2023-05-04T10:16:08Z")

</div>

Thanks. I may have gotten a bit confused at some point ( I deleted all the things  
I tried that did not seem to work ). Sure, most of the time I can get either Neumann  
or Difichlet to work, the problem was trying to speciify both on the same  
boundary region. How do I specify the initial phase of the sinewave on the  
initial point? I’m sure this is going to turn out to be something similarly simple 🙂

---

<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:** [May 4, 2023, 10:23am UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429/4 "2023-05-04T10:23:54Z")

</div>

Are you looking for Robin (or Fourier) boundary conditions? You cannot impose both Neumann and Dirichlet on the same label.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 4, 2023, 10:29am UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429/5 "2023-05-04T10:29:27Z")

</div>

What is the origin of that restriction?  
This becomes an issue when one dimension of the mesh is time and I want  
to continue a function from one iterations’ last value and derivative to  
use as the initial conditions in the next iteration.

Thanks.

---

<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:** [May 4, 2023, 10:36am UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429/6 "2023-05-04T10:36:15Z")

</div>

If you use `on`, it will overwrite whatever you have in the rest of your `varf` (this is not specific to FreeFEM, whenever you use Dirichlet boundary conditions, you somehow need to enforce it algebraically on your system). So if you want to have a combination of both kind of boundary conditions, you should simply use Robin boundary conditions instead of `on`.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 4, 2023, 1:07pm UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429/7 "2023-05-04T13:07:34Z")

</div>

Well, if you set the value setting the derivative is effectively fixing  
the adjacent node value isn’t it?  
I’m thinking in FD or maybe P0 terms but AFAICT its not much differnet  
for the others although I haven’t worked it through.  
Thanks.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 7, 2023, 11:47pm UTC](https://community.freefem.org/t/value-and-derivative-at-same-boundary-pt-on-ignored/2429/8 "2023-05-07T23:47:23Z")

</div>

For the u’’ +u case just splitting iit up into two vars seems to add enough dof’s  
to make it workout.  
I guess this is cheating and may have other issues but it looks like it works  
although I have not yet tried to extend the “z” results from one run to another using  
this ( final “z” and dz as init conitions for next run ). Creating 2 vars sounds bad  
except that the nuymber of non-zero matrix elements may not even be all that much  
worse.

```auto
varf sinewave2([u,du],[v,dv],tgv=-1)
= int1d(Th)(dx(u)*(v)) + int1d(Th)(-2*pi*du*v)
+ int1d(Th)(dx(du)*(dv)) + int1d(Th)(2*pi*u*dv)
+on(100,du=1)
+on(100,u=1)
;

```

 ![line2phase](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/d/df523a06bba156353225a11adc5fd58dfce7f6a1.jpeg)
