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

Applying Dirichlet boundary conditions in a symmetric way

+1 vote

Using assemble_system, one can make sure that a symmetric weak form results in a symmetric matrix after boundary conditions are applied. I already assembled my matrices however; is it possible to apply Dirichlet boundary conditions in FEniCS without losing symmetry, still?

To ask the question somehow differently: my problem can be written as $(A_1 + k(\varepsilon) A_2) x = b(\varepsilon)$, where I solve for varying $k$ and $b$. Hence I don't want to assemble $A_1$ and $A_2$ over and over again. Suppose I do something like:

a1 = ... # weak form
a2 = ...
dummy_rhs = ...
bcs = [dolfin.DirichletBC(...), dolfin.DirichletBC(...)]
A1, dummy = dolfin.assemble_system(a1, dummy_rhs, bcs)
A2, dummy = dolfin.assemble_system(a2, dummy_rhs, bcs)
b = ... # weak form
B = dolfin.assemble(b)
for bc in bcs:
    bc.apply(B)
A = A1 + k * A2 # using petsc4py to do this

Am I right to believe that using these A and B will give the correct result, as long as the values for the Dirichlet boundary conditions are all zero?

Is there any way to apply boundary conditions conserving symmetry in this case, AFTER an assemble step (i.e. not assemble_system) happened?

asked Jun 13, 2016 by maartent FEniCS User (3,910 points)
edited Jun 13, 2016 by maartent

As a bonus question: does applying Dirichlet boundary conditions with value zero change the sparsity pattern of the matrix? If not automatically, can I do so somehow?

...