This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to get errornorm on subdomain

0 votes

I have the following script:

from dolfin import *
from mshr import *

nx, ny = 30, 30
plx, prx = 0.2, 0.8
u0, u1 = 0.0, 0.05

mesh = UnitSquareMesh(nx, ny)

#-------------refinement-start

p, q = Point(0.2, 1.), Point(0.8, 1.)
tol = 0.1
tol2= 0.5

# Selecting edges to refine
class Border(SubDomain):
    def inside(self, x, on_boundary):
        return (near(x[0], p.x(), tol) and near(x[1], p.y(), tol) or
    near(x[0], q.x(), tol) and near(x[1], q.y(), tol)) and near(x[1], 1.0, tol2)

Border = Border()

# Number of refinements
nor = 3

for i in range(nor):
    edge_markers = EdgeFunction("bool", mesh)
    Border.mark(edge_markers, True)

    adapt(mesh, edge_markers)
    mesh = mesh.child()

#---------------refinement-end

def plate_boundary(x, on_boundary):
    return (plx < x[0] < prx) and near(x[1], 1.0)

def empty_boundary(x, on_boundary):
    return on_boundary and not plate_boundary(x, on_boundary)

V = FunctionSpace(mesh, "Lagrange", 1)
u = TrialFunction(V)
v = TestFunction(V)

bcs = [DirichletBC(V, Constant(u1), plate_boundary),
       DirichletBC(V, Constant(u0), empty_boundary)]

a = inner(grad(u), grad(v)) * dx
L = Constant(0.0) * v * dx

u = Function(V)

problem = LinearVariationalProblem(a, L, u, bcs)
solver = LinearVariationalSolver(problem)
solver.solve()

plot(u)

plot(mesh)

interactive()

I want to calculate errornorm of numerical solution and solution that I got by the separation of variables. Analytic solution has emissions in little subdomains near the points of break (points p and q) caused by Gibbs phenomenon. So I need to cut out these subdomains for calculating an errornorm.
How can I perform this?

asked Apr 21, 2016 by Illusion FEniCS Novice (290 points)

1 Answer

0 votes

Hi,
you can define two subdomains and integrate only over one of them. Something like:

excluded_sub = excluded_subdomain()

domains = MeshFunction("size_t", mesh, mesh.topology().dim())
domains.set_all(1)
excluded_sub.mark(domains, 0)

dx = Measure("dx")[domains]
error_norm = assemble(0.5*inner(u - uh, u - uh)*dx(1))

In this manner you are calculating the error, in this case defined as

$$error = \frac{1}{2}\int_{\Omega_1}(\mathbf{u}-\mathbf{u}_h)\cdot(\mathbf{u}-\mathbf{u}_h)\;\text{d}\Omega$$

only on the cells marked as 1. I don't know if the python functions norm and errornorm has the functionality of select an user-defined domain (apparently not at the moment).

answered Apr 21, 2016 by hernan_mella FEniCS Expert (19,460 points)
reshown Apr 22, 2016 by hernan_mella
...