Calculating error on subregion of mesh
12 weeks ago by
I need to calculate the maximum error between exact and FE solution for a problem on only a subregion of the mesh. Mesh is defined as a square and subregion is defined as a circle. Here is the part of the code I use to do this.
# Generate mesh point=0.6 mesh = RectangleMesh(Point(-point,-point), Point(point,point), nx, nx,'crossed') # Initial conditions radius = 0.5 circle=sqrt(x*x + x*x)-radius # Exact solution u_exact=Expression(someexpression, degree=2) # Calculate error Ve = FunctionSpace(mesh, 'Lagrange', 2) u_e_Ve = interpolate(u_exact, Ve) u_Ve = interpolate(u, Ve) e_Ve = Function(Ve) e_Ve.vector()[:] = u_e_Ve.vector().get_local() - u_Ve.vector().get_local() # Calculate max error norm error=e_Ve.vector().get_local() error_max=conditional(le(circle,0.5),np.max(error),0.0) # Write results to file resfile=open("res_euler.csv","a") resfile.write("%.12f"%(error_max)) resfile.close
When I use a conditional statement I get the following error while writing max error to the resfile:
"Float is expected rather than a conditional"
Do you know how to get the max error in an efficient way inside the subregion (circle in this case)?
Community: FEniCS Project
Please login to add an answer/comment or follow this question.