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

Symmetricity

0 votes

Hi,

Could anyone give me some hints here. I would like to know if the stiffness matrix A is symmetric. I tried two methods of estimating the symmetricity. But they give me different results.

The problem is that A.array() does not work for large matrices.

Is there an easy way to get around this issue?

Thanks!

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(20,20)

parameters["linear_algebra_backend"] = "PETSc"

P2 = VectorFunctionSpace(mesh, "CG", 2)
P1 = FunctionSpace(mesh, "CG", 1)
W = MixedFunctionSpace([P2,P1])

bc = DirichletBC(W.sub(0), Constant((0,0)), DomainBoundary())

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

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

A = PETScMatrix()

assemble(a, A)
print 'Is symmetric', np.linalg.norm(A.array() - A.array().T) < 1E-10
temp=A.mat()
print 'Is symmetric', temp.symmetric

`

related to an answer for: Assemble system for eigenvalue problem
asked Jun 17, 2016 by lulio FEniCS Novice (450 points)

1 Answer

+1 vote
 
Best answer

Hello, the difference is due to tolerances. With symmetric property you are calling isSymmetric with the default 0 tolerance, see here. To get a matching answer try

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(20,20)

parameters["linear_algebra_backend"] = "PETSc"

P2 = VectorFunctionSpace(mesh, "CG", 2)
P1 = FunctionSpace(mesh, "CG", 1)
W = MixedFunctionSpace([P2,P1])

bc = DirichletBC(W.sub(0), Constant((0,0)), DomainBoundary())

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

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

A = PETScMatrix()

assemble(a, A)
print 'Is symmetric', np.linalg.norm(A.array() - A.array().T) < 1E-10
temp=A.mat()
print 'Is symmetric', temp.isSymmetric(1E-10)

Note t

answered Jun 17, 2016 by OxbowQuest FEniCS User (1,360 points)
selected Jun 19, 2016 by lulio

Great. Thanks!

...