Dear all,
I have a mixed function-space problem with complex numbers. Eventhough I increase the function-space order (p_h) the error of the numerical solution compared to the exact solution does not decrease at all for p_h > 3. It is somehow always stuck at p_h = 3 which should not (from other software and solutions for the same problem I know that). Here is how I define my function-space in my own problem:
Er = FiniteElement('P', triangle, p_h)
Ei = FiniteElement('P', triangle, p_h)
V = FunctionSpace(mesh,Ec)
Also, I define the exact solution function-space order as p_ex = p_h + 1. Both exact and numerical solutions are solved on the same mesh and the error is calculated by errornorm() function.
I was not able to write a simple code to show my problem here. But I found a topic closest to my problem. I have tried my best to do what they were describing but I was not able to reach to a better result in that problem either. Here is the topic that I think describes the same problem that I go through:
https://fenicsproject.org/qa/3795/solution-showing-linear-functions-higher-lagrange-elements/
The suggested solution is:
“The workaround I have been going through is to interpolate the higher order solution onto a finer linear space. If you need to write the solution on a finer mesh anyway, you could plot and write the finer mesh that’s an interpolation of the higher order solution.”
I don’t understand it. Do I need to create a new mesh to interpolate the high-order solution on-to? This is very confusing.
Here is the code that they have given and I have updated a little bit. I am trying to get a better result as their accepted solution suggests:
from dolfin import *
%matplotlib inline
mesh = UnitSquareMesh(3,3)
p = 3
q = 5
E = FiniteElement('CG', triangle, p)
V = FunctionSpace(mesh,E)
def boundary(x):
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-(pow(x[0] - 0.5, 4) + pow(x[1] - 0.5, 4)) / 0.02)", degree = q)
g = Expression("sin(5*x[0])", degree = q)
a = inner(grad(u), grad(v))*dx
L = f*v*dx + g*v*ds
u = Function(V)
solve(a == L, u, bc)
plot(u)
# From here on, it is my solution that looks like it will work
# but I want to project this solution (if it is actually the higher order solution)
# to a finer mesh if I have to. I am not even sure from this point after
import numpy as np
W = FunctionSpace(mesh,'Lagrange', p+1)
w = interpolate(u, W)
print(w.vector()[:])
print(w.compute_vertex_values())
# Should I create a new mesh according to this higher-order solution?
#I think I am doing what they suggest below, but I could not figure out
# how to plot my new high-order solution to this new mesh also
gdim = mesh.geometry().dim()
dofmap = V.dofmap()
dofs = dofmap.dofs()
dofs_x = W.tabulate_dof_coordinates().reshape((-1, gdim))
# plot(?)
I hope I made it clear enough. I would like to plot the high-order solution function on my geometry in the end.