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

How to apply boundary condition for different trial and test function?

+1 vote

If I don't apply boundary condition, it's OK.
But applying boundary condition causes a fault, message below:

Error: Unable to apply boundary condition.
Reason: Dofmap ownership range (0,289) does not match matrix row range (0,1089).

from dolfin import *
import numpy as np
import pdb

def LeastSquare(A, b):
    from numpy import linalg
    result = linalg.lstsq(A, b)[0]
    return result

mesh = UnitSquareMesh(5,5)

V = FunctionSpace(mesh, "CG", 1)
W = FunctionSpace(mesh, "CG", 2)

f = Expression("sin(3.14*x[0])", degree=2)
u = TrialFunction(V)
v = TestFunction(V)
w = TestFunction(W)

bc = DirichletBC(V, Constant(1.0), DomainBoundary())
print 'Index and values of DOFs on boundary:', bc.get_boundary_values()

# Forms for linear system, with different test/trial functions
a = u*w*dx + dot(grad(u), grad(w))*dx
L = f*w*dx

# Create linear system (matrices, transpose operator, RHS vector)
A = assemble(a)
b = assemble(L)

bc.apply(A, b)

# Solve and plot
u = Function(V)
u.vector()[:] = LeastSquare(A.array(), b.array())
plot(u, title='solution')

interactive()
asked Jul 8, 2017 by fanronghong FEniCS User (1,680 points)

1 Answer

0 votes

I think what's happening is that when you try to solve a problem with more than one function space you should use a mixed function space to apply the boundary conditions to one of the function spaces. So either:

  • 1: use a mixed function space and u.sub(0) (in the fenics tutorials)
  • 2: see if you can break the problem into two steps with two different solves and apply the boundary condition in one of the solves (which might be faster if one step is a non-linear solve and the other one a linear solve of vice versa)
answered Jul 10, 2017 by alexmm FEniCS User (4,240 points)
edited Jul 10, 2017 by alexmm
...