when i am trying to find out L2-norm of heat equation on the
V = VectorFunctionSpace(mesh, 'P', 1)
the error decreases and remains constant.
Here is the code
from fenics import *
def heat(N):
T = 2.0 # final time
num_steps = 4 # number of time steps
dt = T / num_steps # time step size
alpha = 3 # parameter alpha
beta = 1.2 # parameter beta
# Create mesh and define function space
mesh = UnitSquareMesh(N, N)
V = VectorFunctionSpace(mesh, 'P', 1)
# Define boundary condition
u_D = Expression(('1 + x[0]*x[0] + alpha*x[1]*x[1] + beta*t','1 + x[0]*x[1]+beta*pow(t,2)'),
degree=2, alpha=alpha, beta=beta, t=0)
bc = DirichletBC(V, u_D, "on_boundary")
# Define initial value
u_n = interpolate(u_D, V)
#u_n = project(u_D, V)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression(('beta - 2 - 2*alpha', '2*beta*t'), degree=1, alpha=alpha, beta=beta, t=0 )
F = inner(u,v)*dx + dt*inner(grad(u), grad(v))*dx - inner(u_n + dt*f,v)*dx
a = lhs(F)
L = rhs(F)
# Time-stepping
u = Function(V)
t = 0
for n in range(num_steps):
# Update current time
t += dt
u_D.t = t
f.t = t
# Compute solution
solve(a == L, u, bc)
# Plot solution
#plot(u)
error_L2 = errornorm(u_D, u, 'L2')
# Update previous solution
u_n.assign(u)
return error_L2
for N in [2, 4, 8,16, 32, 64]:
print("{0:d} error_L2 ={1:.2e}".format(N, heat(N)))
2 error_L2 =1.80e-01
4 error_L2 =5.12e-02
8 error_L2 =2.73e-02
16 error_L2 =2.49e-02
32 error_L2 =2.48e-02
64 error_L2 =2.48e-02
Kindly clarify this issue.
when I am using `V = VectorFunctionSpace(mesh, 'P', 2)`
error is coming like
2 error_L2 =2.39e-02
4 error_L2 =2.47e-02
8 error_L2 =2.48e-02
16 error_L2 =2.48e-02
32 error_L2 =2.48e-02
64 error_L2 =2.48e-02
kindly, give the necessary suggestion to find out the order of convergence and mention if there is any issue with this code.
Waiting for a positive reply!
Thank You,
Debendra