Not getting accurate order of convergence

I compute the solution for several spatial mesh sizes and measure the L2 error with respect to the exact solution. My goal is to study the order of convergence, but the computed rates seem inconsistent or lower than expected.

verbosity=0;
macro dn(u) (N.xdx(u)+N.ydy(u)) // def the normal derivative
// parameter
real dt, h, T= 1;
int nref =4;
real [int] L2error ( nref ); // initialize the L2 error array
real [int] Dx( nref ); // initialize the Space discretization array
real [int] DT( nref ); // initialize the Time discretization array
real L2err;
real eorr;

macro Grad(u)[dx(u),dy(u)]//
macro uex(t)(exp(-t)(x^2 - y^2)) //
macro g(t) (exp(-3
(t))*(x^2 - y^2)^3) //

//Mesh
for ( int n=0; n< nref ;n++) {
int M =52^(n) ;
h =1./ M;
Dx[n]=h;
dt=1./256;//0.4
h;//0.4h^2;//
DT[n]= dt;
// border bottom(t=0,1){x = 0 + t
2 - 1; y = -1; label = 1;}
// border right(t=0,1){x = 1; y = -1 + t2; label = 1;}
// border top(t=0,1){x = 1 - t
2; y = 1; label = 1;}
// border left(t=0,1){x = -1; y = 1 - t*2; label = 1;}

mesh Th = square(M,M,[2x-1,2y-1]);//buildmesh(bottom(M) + right(M) + top(M) + left(M));
cout << "level M = " << M << endl;
//plot(Th, wait=false);

//Fespace
fespace Vh(Th,P1);
fespace Vh2(Th,P1);
//fespace Vh2(Th,[P1dc,P1dc]);
//fespace Vh2(Th,[P1,P1]);

// Function
func real df(real u){return u^3; }
func real ddf(real u){return 3*u^2; }

Vh u, uold, uoldd, auxv, vv;
Vh2 dfalpha;
Vh2 ddfalpha;

uoldd = x^2 - y^2;
uold = uoldd - dt*(x^2 - y^2);

plot(u,wait=0,cmm=“Klein-Gordan Exact Solution” ,value=true);

for (real t=0.;t<T;t+=dt){
uold=uoldd;
u=uold;
real res;
int iter=0;
for (int k=0;k<50;k++) // Newton loop
{
dfalpha=df(u);
ddfalpha= ddf(u);

varf Fv(v, phi)=int2d(Th)

((u-2uold+uoldd)phi1./(dtdt)+(dx(u)*dx(phi)+dy(u)*dy(phi))1./(2dt)
-(dx(uoldd)*dx(phi)+dy(uoldd)*dy(phi))1./(2dt)+(dx(u)*dx(phi)+dy(u)*dy(phi))1./2+(dx(uoldd)dx(phi)+dy(uoldd)dy(phi))1./2+ (u-uoldd)phi1./(2dt) + (dfalpha)phi1./4 +((uoldduoldd)u)phi1./4 +((uu)uoldd)phi1./4+((uoldduoldduoldd)phi1.4))// dfalphaphi)
+int2d(Th)(-g(t)*phi);// + on(1,2,3,4, u=0);

auxv=Fv(0,Vh); // nabla J
res= sqrt(auxv'auxv[]); // Residual
// cout << " residu = " << res << endl;
if (res< 1e-6) break;
varf dFv(v, phi) = int2d(Th)(
v
phi*(1./(dt*dt))

  • (dx(v)dx(phi) + dy(v)dy(phi))(1./(2dt) + 1./2)
  • vphi(1./(2*dt))
  • ddfalphavphi // df/du = 3u^2 * v
    +(uvuoldd)phi1./2
  • (1./4)uoldd^2v*phi // df/du = 3u^2 * v
    );

// varf dFv(v,phi)=int2d(Th)
// (vphi1./(dtdt) + (dx(v)dx(phi)+dy(v)dy(phi))1./(2dt) +(dx(v)dx(phi)+dy(v)dy(phi))1./(2)+ vphi1./(2dt)+((vv)phi3./4)+((uoldduoldd)phi1./4)+((uuoldd)phi1./2));

matrix H=dFv(Vh,Vh, factorize=1,solver=LU); // HJ
vv=H^-1*auxv;
u-=vv;
iter++;
}// end of Newton loop

// uold=2.*u-uold;
plot(u,wait=0,cmm=“Klein-Gordan Approximate Solution”, value=true);
eorr= abs(u-uex(t+dt))^2;
L2err=sqrt(int2d(Th)(abs(u-uex(t+dt))^2));
cout << "time = " << t+dt << " iter = " << iter << " residu = " << res << " L2 error = " << L2err << " eror = "<< eorr << endl;
}//end of time loop
cout << “final time T is reached” << endl;

L2error [n]= L2err;
}//end of loop on n< nref

for ( int n =0;n< nref ;n ++)
cout << " L2error " << n << " = " << L2error [n] <<endl;
for ( int n =1; n< nref; n ++){
cout <<" Space convergence rate = " << log ( L2error [n-1]/L2error
[n])/log(Dx[n-1]/Dx[n]) <<endl;
}

Please upload your code in .edp format here so that it can run directly.

Here is the code. getting error while imposing dirichlet boundary condition

ad1.edp (5.9 KB)

Kindly please share your full scheme that you want to implement in FF++ code. It will help me to check the code.

I am trying to solve numerical experiment of
https://www.tandfonline.com/doi/full/10.1080/00036811.2024.2426227#:~:text=In%20this%20work%2C%20we%20consider,semidiscrete%20and%20fully%20discrete%20schemes.

1 Like

I will check and let you know.

1 Like

Here, is your code with several modifications but still order is coming initially good but reducing as nref increases. I will know you if i get any better results in this. But approximate solution figure and values coming fine. I hope there are some mistakes in code that reducing the order of converegence. If that fixed the i hope you will get optimal results.

Ad1_MI.edp (3.3 KB)

Results for h=1/4, 1/8, 1/16, 1/32

1 Like

Thank you for your response…i think second initial condition will be calculated using weak formulation.

AD1_L2.edp (3.5 KB)


(With dt=h^2 using P1 is giving optimal in space. Issue is comming for time. Since, you are using CN, so optimal order should be 2). I will check in future again for time.


(With dt=h)(It should give 2 in space and 2 in time but it giving less this means there is a problem in code)

You can run the last code for h=1/128, 1/256, 1/512, 1/1024 (That is M=2^(n+7), where n varies from 0 to 3). I hope order will come good. Let me know after doing getting results.

1 Like

I have fixed error in Fv and DFv function. But according to paper we have to fix k and h varying from 1/5, 1/10, 1/20, 1/40, 1/80. While adding dirichlet boundary condition using exact solution, it is showing error.

Please upload your code here.

AD1_L2 (1).edp (4.0 KB)
Error wil be calculated in H1 norm.

Okay. Thanks. I will check.

In your code,

Blockquote
uoldd = x^2 - y^2;
uold = uoldd - dt*(x^2 - y^2);
Blockquote

This ensures that you are computing U^1 from backward-euler. But you have to use equation (37) to compute U^1 when U^0 is known. After that you can compute rest of the solutions U^2,…, U^n, U^{n+1}.

I think due to that it is giving first order in time.

1 Like

AD1_L2 (1).edp (5.3 KB)
I have added that but not sure is it correct way to implement, because order of convergence is still not accurate.

Okay, i will check soon.