Differences between parts of mixed FEM and single FEM

Asked by Jan

I am wondering, why I get different sizes and entries in the system matrices when I assemble them
1.) as a submatrix of a mixed FEM ansatz
2.) directly using the same single test/trial spaces

Or do I something fundamentally wrong.

Please consider the following example in python.
For example, the length of the right hand side vector differs when changing the parameter mixed = True, False

from dolfin import *
from scipy.sparse import csr_matrix
import numpy as np

parameters.linear_algebra_backend = "uBLAS"

mixed = False

mesh = UnitSquareMesh(2, 2)

if mixed is True:
 # Define mixed FEM function spaces
 V = VectorFunctionSpace(mesh, "CG", 2)
 Q = FunctionSpace(mesh, "CG", 1)
 W = V * Q

 (u, p) = TrialFunctions(W)
 (v, q) = TestFunctions(W)

 # Define FEM function spaces
 V = VectorFunctionSpace(mesh, "CG", 2)

 u = TrialFunction(V)
 v = TestFunction(V)

# define Form
aa = inner(grad(u), grad(v))*dx

# Assemble system
A = assemble(aa)

# righthandside
fvhomo = Constant((1,2))
Lvh = inner(fvhomo,v)*dx
b = assemble(Lvh)

## Convert DOLFIN representation to numpy arrays
rows, cols, values = A.data()
Aa = csr_matrix((values, cols, rows))
ba = b.array()
ba = ba.reshape(len(ba), 1)

print ba.shape

Question information

English Edit question
DOLFIN Edit question
No assignee Edit question
Solved by:
Jan Blechta
Last query:
Last reply:
Revision history for this message
Best Jan Blechta (blechta) said :


If you assemble forms on space V you got matrix shaped (50, 50) and vector shaped 50. Conversely if you assemble on space W you got (59, 59) and 59 respectively. Even if you use test functions of only first subspace. So the entries in matrix and vector corresponding to V.sub(1) are zero making it singular.

If your intent is assembling the problem blockwise consider using cbc.block package.


Revision history for this message
Jan Blechta (blechta) said :

Typo fix: there should be W.sub(1) instead of V.sub(1).

Revision history for this message
Jan (jnhlnd) said :

Thanks Jan Blechta, that solved my question.