# [petsc-users] How do constraint dofs work?

Matthew Knepley knepley at gmail.com
Mon Dec 7 14:06:46 CST 2020

```On Mon, Dec 7, 2020 at 2:25 PM Alexis Marboeuf <alexis.marboeuf at hotmail.fr>
wrote:

> Hi Matt,
>
> I don't understand how unconstrained dofs in the neighborhood of a
> Dirichlet boundary can see non-zero constrained dofs in a finite element
> framework. To me, known non-zero terms due to non-zero imposed dofs are
> added in the RHS of the unconstrained dofs system?
>

I see now. I never do this, so I misunderstood your question. Yes, if you
are assembling A and b separately, then you need the terms you constrained
in b. You can
do that, but I think it is needlessly complex and error prone. I phrase
everything as a nonlinear system, forming the residual and Jacobian

F(u) = A u - b
J(u) = A

Since you have the boundary values in u, your residual will automatically
create the correct RHS for the Newton equation, which you only solve once.
There is no
overhead relative to the linear case, it is simpler, and you can
automatically do things like iterative refinement.

Thanks,

Matt

> Or the proper terms are automatically added in the RHS and no modification
> of the system is necessary? But, in that case, I don't know how to set
> imposed non-zero values to tell Petsc what terms to include?
> Thank you again for your time and I apologize if I miss something.
>
> Regards,
> Alexis
>
> ------------------------------
> *De :* Matthew Knepley <knepley at gmail.com>
> *Envoyé :* lundi 7 décembre 2020 02:02
> *À :* Alexis Marboeuf <alexis.marboeuf at hotmail.fr>
> *Cc :* petsc-users at mcs.anl.gov <petsc-users at mcs.anl.gov>
> *Objet :* Re: [petsc-users] How do constraint dofs work?
>
> On Sun, Dec 6, 2020 at 1:46 PM Alexis Marboeuf <alexis.marboeuf at hotmail.fr>
> wrote:
>
> Hello,
>
> I intend to contribute to the Petsc documentation, especially on PetscSF
> and PetscSection objects. I'm writing an example where I solve a linear
> elasticity problem in parallel on unstructured meshes. I discretize the
> system with a finite element method and P1 Lagrange base functions. I only
> use Petsc basics such as PetscSF, PetscSection, Mat, Vec and SNES objects
> and I need to implement Dirichlet and/or Neuman boundary conditions.
> PetscSectionSetConstraintDof and related routines allow to define which
> dofs are removed from the global system but are kept in local Vec. I don't
> how it works? In particular, do I have to manually add terms related to
> inhomogeneous Dirichlet boundary condition in the RHS? Am I missing
> something?
>
>
> The way this mechanism is intended to work is to support removal of
> constrained dofs from the global system. This means it solves for only
> unconstrained dofs and no modification of the system is necessary.
> However, you would be responsible for putting the correct boundary values
> into
> any local vector you use. Note that this mechanism is really only
> effective when you can constrain a dof itself, not a linear combination.
> For that, we
> do something more involved.
>
> Operationally, SetConstraintDof() keeps track of how many dofs are
> constrained on each point. Then SetConstraintIndices() tells us which dofs
> on that
> point are constrained, where the indices are in [0, n) if there are n dofs
> on that point. If you make a global Section, constrained dofs have negative
> offsets,
> just like ghost dofs.
>
>   Thanks,
>
>      Matt
>
>
> Regards,
> Alexis Marboeuf
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/
> <http://www.cse.buffalo.edu/~knepley/>
>

--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20201207/eb15abd5/attachment.html>
```