# 1D periodic boundary condition

**URL:** <https://community.freefem.org/t/1d-periodic-boundary-condition/1800>\
**Category:** General Discussion\
**Created:** [June 6, 2022, 1:19pm UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800 "2022-06-06T13:19:22Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [June 6, 2022, 1:19pm UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/1 "2022-06-06T13:19:22Z")

</div>

Hello, Professor, I used the following one-dimensional periodic boundary code, but something went wrong,

> load “msh3”  
> border OX(t=-40,40){x=t;y=0;}  
> int m=100; // grid points on x-interval [0,1]  
> real h=1./m;  
> meshL Th=segment(m);
> 
> real T=1;  
> real k=0.3;  
> real x0=4;  
> real A=12_k^2;  
> real omega=4_k^2;  
> real dt=0.01;
> 
> fespace Uh(Th,P1,periodic=[[1, x]]);//periodic boundary condition

---

<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:** [June 7, 2022, 6:59am UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/2 "2022-06-07T06:59:00Z")

</div>

Yes because in 1d the syntaxe is show in example

> <https://github.com/FreeFem/FreeFem-sources/blob/master/examples/3dCurve/periodicL.edp>

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [June 8, 2022, 2:22pm UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/4 "2022-06-08T14:22:18Z")

</div>

Hello, according to your reply, I used the linear element P1. There is no problem with the program. However, using the quadratic element P2, I found that this item

> -int1d(Thf)(dxx(u1)\*dx(v))

will lead to program interruption. Why？

> 60 : sizestack + 1024 =4460 ( 3436 )
> 
> – Build Nodes/DF on mesh : n.v. 321, n. elmt. 320, n b. elmt. 2  
> nb of Nodes 640 nb of DoF 640 DFon=1100  
> – FESpace: Nb of Nodes 640 Nb of DoF 640  
> – Build Nodes/DF on mesh : n.v. 641, n. elmt. 640, n b. elmt. 2  
> nb of Nodes 1280 nb of DoF 1280 DFon=1100  
> – FESpace: Nb of Nodes 1280 Nb of DoF 1280  
> current line = 37  
> Assertion fail : (0)  
> line :245, in file …/femlib/P012\_3dCurve.cpp  
> Assertion fail : (0)  
> line :245, in file …/femlib/P012\_3dCurve.cpp  
> err code 6 , mpirank 0

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [June 9, 2022, 10:14am UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/5 "2022-06-09T10:14:36Z")

</div>

Hello, I use the following command

> fespace Uh(Th,P3,periodic=[[1],[2]]);

. My periodic boundary condition is  
 ![屏幕截图 2022-06-09 181327](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/2/2c12bf39ecf32fc3a71877e8fb6ae97266f0c754.png)  
，

> problem KDV(u1,v)=int1d(Thf)(u1_v/dt)-int1d(Thf)(u0_v/dt)-int1d(Thf)(dxx(u1)_dx(v))  
> +int1d(Thf)(u0_dx(u1)\*v);

So is this command right?

---

<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:** [June 15, 2022, 12:53pm UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/6 "2022-06-15T12:53:47Z")

</div>

You use a old version do freefem++ with the computation of dxx in 1d is not computed  
Need version 4.11 (the last to day).

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [June 15, 2022, 1:01pm UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/7 "2022-06-15T13:01:38Z")

</div>

Thank you very much for your reply. 😃

---

<div class="post-metadata">

**Author:** ![hezl09](https://avatars.discourse-cdn.com/v4/letter/h/f07891/32.png) [@hezl09](https://community.freefem.org/u/hezl09)\
**Post date:** [June 16, 2022, 6:53am UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/8 "2022-06-16T06:53:50Z")

</div>

Hello Prof. Hecht,

I have a doubt if FreeFEM can work on 1D periodic multiphysics problem where the physical quantities are coupled. For example, I’m now working on 1d piezoelectric composites with two phases: fiber and matrix. The displacement and electric potential are coupled by the following equation  
 ![4](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/5d6fd3394f91a85b3daa689fd3cef595e1c881f0.jpeg)  
I use the following code to solve the governing differential equation

```auto
load "msh3"
real L0 = 1.;
meshL Th = segment(100,[L0*x]);
fespace Vh(Th,P1,periodic=[[1],[2]]);
real cf = 0.5;
real C1 = 131, e1 = 10.99, k1 = 2.081; // fiber
real C2 = 145.5, e2 = 17.36, k2 = 15.1; // matrix
func Cp = C1*(x<cf*L0) + C2*(x>=cf*L0 && x<=L0);
func ep = e1*(x<cf*L0) + e2*(x>=cf*L0 && x<=L0);
func kp = k1*(x<cf*L0) + k2*(x>=cf*L0 && x<=L0);
Vh N1u,M1u,N1us,v1,v2,xx;
xx = x;
problem microflucNMu([N1u,M1u], [v1,v2]) = int1d(Th)( (Cp*dx(N1u)+ep*dx(M1u))*dx(v1) +
                                                      (ep*dx(N1u)-kp*dx(M1u))*dx(v2) ) +
                                           int1d(Th)( Cp*dx(v1)+ep*dx(v2) );
microflucNMu;
plot([xx[],N1u[]],cmm = "distribution of N1u");
plot([xx[],M1u[]],cmm = "distribution of M1u",WindowIndex=1);

```

However, the solution I got for N1u and M1u are not periodic! Meanwhile, if I degrade to uncoupled elasticity problem using the following equation and code  
 ![5](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/e50306f674de53d9b40090384f90d72c6ce9bcbb.jpeg)

```auto
problem microflucNus(N1us,v1) = int1d(Th)( Cp*dx(N1us)*dx(v1) ) +
                                int1d(Th)( Cp*dx(v1) );
microflucNus;
plot([xx[],N1us[]],cmm = "distribution of N1us",WindowIndex=2);

```

Then, I can get the periodic solution for N1us.  
I don’t know where the problem is for my multiphysics code. I’ve attached my code below. I used FreeFEM v4.11.

[Periodic-1D.edp](https://community.freefem.org/uploads/short-url/c9oqg8f4uKcPA6D1J3NUQyDdOmk.edp) (1.1 KB)

Thanks a lot if you or anyone else can help.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [July 25, 2022, 1:14am UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/9 "2022-07-25T01:14:38Z")

</div>

> [@Qianrui](#):
>
> fespace Uh(Th,P3,periodic=[[1],[2]]);

Hello, about 1D periodic boundary command, my periodic boundary conditions need to be met

U (a) =u (b) and dx (U (a)) =dx (U (b)), use this command

> fespace Uh(Th,P3,periodic=[[1],[2]]);

Where periodic=[[1], [2]] represents U (a) =u (b), but how to satisfy the periodic boundary condition dx (U (a)) =dx (U (b)) of the first derivative?

---

<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:** [July 25, 2022, 1:01pm UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/10 "2022-07-25T13:01:38Z")

</div>

Remark, if the function is periodic when all derivative are periodic.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [July 27, 2022, 6:01am UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/11 "2022-07-27T06:01:36Z")

</div>

Thank you for your reply. In fact, does this command

> fespace Uh(Th,P3,periodic=[[1],[2]]);

mean that the original function and its derivatives of all orders satisfy the characteristics of periodic functions in finite element space?

---

<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:** [July 27, 2022, 2:25pm UTC](https://community.freefem.org/t/1d-periodic-boundary-condition/1800/12 "2022-07-27T14:25:50Z")

</div>

yes, this is a math propriety!
