How can we get the convergence for time dependent non-linear pde?

Solving time dependent non-linear pde

Hi all, I tried the code given below but not getting the convergence. I don’t understand where I am doing wrong . I am using P1 non-conforming finite element. I checked my code many times but didn’t find any error. So, I don’t understand why I am not getting the convergence .

Here is mycode:

 from fenics import*
 import numpy as np
 %matplotlib inline
 mesh = UnitSquareMesh(8,8)
 plot(mesh)
 V = FunctionSpace(mesh,'CR',1)
 print('V=',V)
 u_D = Expression('x[0]*x[1]*(x[0]-1)*(x[1]-1)*exp(t)',degree=2,t=0)
 def boundary(x, on_boundary):
       return on_boundary
 bc = DirichletBC(V, u_D , boundary)
 print('bc=',bc)
 u = Function(V)
 un = interpolate(u_D , V)  #initial guess (=0)
 v = TestFunction(V)
 T = 1 #final time
 num_steps = 16
 dt= T / num_steps
 k = Constant(dt)
 x = SpatialCoordinate(mesh)
 f = Expression('x[0]*x[1]*(x[0]-1)*(x[1]-1)*exp(t) + (1/sqrt(1+exp(2*t)*x[1]*x[1]*(x[1]-1)*(x[1]-1)*(2*x[0]-      1)*(2*x[0]-1) + \
 x[0]*x[0]*(x[0]-1)*(x[0]-1)*(2*x[1]-1)*(2*x[1]-1)*exp(2*t)))*(2*x[1]*(1-x[1])+2*x[0]*(1-x[0]))*exp(t) + \
 (1/sqrt(1+exp(2*t)*x[1]*x[1]*(x[1]-1)*(x[1]-1)*(2*x[0]-1)*(2*x[0]-1) + \
 x[0]*x[0]*(x[0]-1)*(x[0]-1)*(2*x[1]-1)*(2*x[1]-1)*exp(2*t)))*(exp(3*t)/(1+exp(2*t)*x[1]*x[1]*(x[1]-1)*(x[1]- 1)*(2*x[0]-1)*(2*x[0]-1) + \
 x[0]*x[0]*(x[0]-1)*(x[0]-1)*(2*x[1]-1)*(2*x[1]-1)*exp(2*t)))*(1/2)*(4*(2*x[0]-1)*(2*x[0]-1)*x[1]*x[1]*x[1]*(x[1]-1)*(x[1]-1)*(x[1]-1) + \
2*x[0]*x[0]*x[1]*(x[0]-1)*(x[1]-1)*(2*x[0]-1)*(2*x[1]-1)*(2*x[1]-1) + \
2*x[0]*x[1]*(x[0]-1)*(x[0]-1)*(x[1]-1)*(2*x[0]-1)*(2*x[1]-1)*(2*x[1]-1) + \
2*x[0]*x[1]*(x[0]-1)*(x[1]-1)*(x[1]-1)*(2*x[0]-1)*(2*x[0]-1)*(2*x[1]-1) + \
2*x[0]*x[1]*x[1]*(x[0]-1)*(x[1]-1)*(2*x[1]-1)*(2*x[0]-1)*(2*x[0]-1) + \
4*x[0]*x[0]*x[0]*(x[0]-1)*(x[0]-1)*(x[0]-1)*(2*x[1]-1)*(2*x[1]-1))', degree=2 , t=0)

F = ((u-un)/k)*v*dx + dot((grad(u)/sqrt(1+dot(grad(un),grad(un)))),grad(v))*dx - f*v*dx
for n in range(num_steps)
     t=+dt
     f.t = t
     u_D.t = t
     print('t=',t)
     solve(F==0,u,bc)
     u_e = interpolate(u_D, V)
     error_L2 = errornorm(u_e, u, 'L2')
     print('error_L2  =', error_L2)
     fileu << (u,t)
     print('u=',u)
     print('u_e=',u_e)
     un.assign(u)

One subtle typo I see is t=+dt instead of t+=dt.

2 Likes

Thanks for your reply. To update time we have to use t+=dt . t=+dt is not working . In demo also you can see its t+=dt.