Applying bcs when using LinearSolver
Hi all, Say I have this: a = dot(grad(u),grad(v))*dx L = f*v*dx bcs = DirichletBC(...) A = assemble(a) b = assemble(L) solver = LinearSolver(A, ...) solver.solve(x,b) If I want to apply the DirichletBC's, I would use "A = assemble(a,bcs=bcs)." Is it necessary to also do this for b? Would it have any affect? Thanks, Justin
Yes, that's necessary; see the last bit of the doc-string for assemble(): If ``bcs`` is supplied and ``f`` is a 2-form, the rows and columns of the resulting :class:`.Matrix` corresponding to boundary nodes will be set to 0 and the diagonal entries to 1. If ``f`` is a 1-form, the vector entries at boundary nodes are set to the boundary condition values. Cheers Stephan On 31/12/15 20:01, Justin Chang wrote:
Hi all,
Say I have this:
a = dot(grad(u),grad(v))*dx L = f*v*dx bcs = DirichletBC(...)
A = assemble(a) b = assemble(L) solver = LinearSolver(A, ...) solver.solve(x,b)
If I want to apply the DirichletBC's, I would use "A = assemble(a,bcs=bcs)." Is it necessary to also do this for b? Would it have any affect?
Thanks, Justin
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
On 03/01/16 12:45, Stephan Kramer wrote:
Yes, that's necessary; see the last bit of the doc-string for assemble():
If ``bcs`` is supplied and ``f`` is a 2-form, the rows and columns of the resulting :class:`.Matrix` corresponding to boundary nodes will be set to 0 and the diagonal entries to 1. If ``f`` is a 1-form, the vector entries at boundary nodes are set to the boundary condition values.
Cheers Stephan
Actually, the answer is a little more complicated than that. The actual matrix and lhs are typically only assembled in the solve() call and you would actually need to have the matrix available to get the correct rhs when lifting bcs. Also you are allowed to change the bcs before the solve by using bcs.apply(A). I suspect this confusion comes from Dolfin which treats bcs differently (doesn't properly lift them). So in practice in firedrake the bcs are just handled as extra bits of information stored on the matrix, but I would just supply it to the assembly of b as well - if anything it will change the outcome if you force assembly of the rhs with b.vector().array() Cheers Stephan
On 31/12/15 20:01, Justin Chang wrote:
Hi all,
Say I have this:
a = dot(grad(u),grad(v))*dx L = f*v*dx bcs = DirichletBC(...)
A = assemble(a) b = assemble(L) solver = LinearSolver(A, ...) solver.solve(x,b)
If I want to apply the DirichletBC's, I would use "A = assemble(a,bcs=bcs)." Is it necessary to also do this for b? Would it have any affect?
Thanks, Justin
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
On 3 Jan 2016, at 12:24, Stephan Kramer <s.kramer@imperial.ac.uk> wrote:
...
On 31/12/15 20:01, Justin Chang wrote:
Hi all,
Say I have this:
a = dot(grad(u),grad(v))*dx L = f*v*dx bcs = DirichletBC(...)
A = assemble(a) b = assemble(L) solver = LinearSolver(A, ...) solver.solve(x,b)
If I want to apply the DirichletBC's, I would use "A = assemble(a,bcs=bcs)." Is it necessary to also do this for b? Would it have any affect?
It's unnecessary to do anything for b. If you also assemble b with bcs it doesn't harm, however. As Stephan points out, boundary conditions are lifted from the operator to the RHS during the solve, so they're sort of a property of the operator. If you assemble the RHS with bcs applied (b = assemble(L, bcs=bcs)), then the boundary nodes will have the boundary condition value. Cheers, Lawrence
Alright got it, thanks all On Mon, Jan 4, 2016 at 2:35 AM, Lawrence Mitchell < lawrence.mitchell@imperial.ac.uk> wrote:
On 3 Jan 2016, at 12:24, Stephan Kramer <s.kramer@imperial.ac.uk> wrote:
...
On 31/12/15 20:01, Justin Chang wrote:
Hi all,
Say I have this:
a = dot(grad(u),grad(v))*dx L = f*v*dx bcs = DirichletBC(...)
A = assemble(a) b = assemble(L) solver = LinearSolver(A, ...) solver.solve(x,b)
If I want to apply the DirichletBC's, I would use "A = assemble(a,bcs=bcs)." Is it necessary to also do this for b? Would it have any affect?
It's unnecessary to do anything for b. If you also assemble b with bcs it doesn't harm, however.
As Stephan points out, boundary conditions are lifted from the operator to the RHS during the solve, so they're sort of a property of the operator. If you assemble the RHS with bcs applied (b = assemble(L, bcs=bcs)), then the boundary nodes will have the boundary condition value.
Cheers,
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (3)
- 
                
                Justin Chang
- 
                
                Lawrence Mitchell
- 
                
                Stephan Kramer