http://www.dealii.org/ Wolfgang Bangerth
MATH 676 – Finite element methods in scientifjc computing
Wolfgang Bangerth, T exas A&M University
MATH 676 Finite element methods in scientifjc computing Wolfgang - - PowerPoint PPT Presentation
MATH 676 Finite element methods in scientifjc computing Wolfgang Bangerth, T exas A&M University http://www.dealii.org/ Wolfgang Bangerth Lecture 21.6: Boundary conditions Part 3a: Homogenous Dirichlet boundary conditions
http://www.dealii.org/ Wolfgang Bangerth
MATH 676 – Finite element methods in scientifjc computing
Wolfgang Bangerth, T exas A&M University
http://www.dealii.org/ Wolfgang Bangerth
Lecture 21.6: Boundary conditions Part 3a: Homogenous Dirichlet boundary conditions
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Consider this simple example:
{1,5,6}: “real” degrees of freedom {0,2…4,7…9}: Constrained to zero
−Δu = f in Ω u = 0 on Γ=∂Ω
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
There are three approaches:
– do local assembly without boundary conditions – copy to global system – eliminate boundary DoFs
– do local assembly without boundary conditions – eliminate boundary DoFs – copy to global system Criteria: All approaches are correct; which one we like best is determined by considerations of algorithm design!
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Approach 1:
1 0, 5 1, 6 2 → → →
1 2 3 4 5 6 7 8 9 X X X X 1 2 X X X
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Approach 1:
1 2 3 4 5 6 7 8 9 X X X X 1 2 X X X
∑j=0
2 [∑K=0 11
(∇ φi, ∇ φ j)K]
Aij
U j=∑K=0
11
(φi,f )K
Fi
∀i=0...2
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Advantages of approach 1:
by a linear system)
1 2 3 4 5 6 7 8 9 X X X X 1 2 X X X
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Advantages of approach 1:
by a linear system)
But: This size reduction doesn't matter on finer meshes! 1 vs 9 DoFs 9 vs 25 DoFs 49 vs 81 DoFs
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Disdvantages of approach 1:
cell: – when enumerating degrees of freedom – when assembling – when evaluating the solution at individual points – …
X X X X 1 2 X X X
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Disdvantages of approach 1:
Some boundary nodes would have to be treated differently than others.
X 4 6 5 1 2 X X X
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Disdvantages of approach 1:
conditions of the sort u.n=0?
1 8 9 2 3 4 5 6 7 10 11 14 15 18 19 16 17 12 13 X 1 8 9 2 X 4 X 10 11 14 15 18 X 16 X X 13 X 7
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Approach 2:
conditions Variation 2a:
for boundary DoFs {0,2,3,4,7,8,9}
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2a:
(forget about sparsity for a moment)
1 2 3 4 5 6 7 8 9
a00 a01 a02 a03 a04 a05 a06 a07 a08 a09 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50 a51 a52 a53 a54 a55 a56 a57 a58 a59 a60 a61 a62 a63 a64 a65 a66 a67 a68 a69 a70 a71 a72 a73 a74 a75 a76 a77 a78 a79 a80 a81 a82 a83 a84 a85 a86 a87 a88 a89 a90 a91 a92 a93 a94 a95 a96 a97 a98 a99)( u0 u1 u2 u3 u4 u5 u6 u7 u8 u9) =
f 0 f 1 f 2 f 3 f 4 f 5 f 6 f 7 f 8 f 9)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2a:
1 2 3 4 5 6 7 8 9
a00 a01 a02 a03 a04 a05 a06 a07 a08 a09 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50 a51 a52 a53 a54 a55 a56 a57 a58 a59 a60 a61 a62 a63 a64 a65 a66 a67 a68 a69 a70 a71 a72 a73 a74 a75 a76 a77 a78 a79 a80 a81 a82 a83 a84 a85 a86 a87 a88 a89 a90 a91 a92 a93 a94 a95 a96 a97 a98 a99)( u0 u1 u2 u3 u4 u5 u6 u7 u8 u9) =
f 0 f 1 f 2 f 3 f 4 f 5 f 6 f 7 f 8 f 9)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2a:
The resulting system has a 3x3 sub-block for “free” DoFs
1 2 3 4 5 6 7 8 9
a11 a15 a16 a51 a55 a56 a61 a65 a66 0)( u0 u1 u2 u3 u4 u5 u6 u7 u8 u9) =
f 1 f 5 f 6 0)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2a:
1 2 3 4 5 6 7 8 9
1 a11 a15 a16 1 1 1 a51 a55 a56 a61 a65 a66 1 1 1)( u0 u1 u2 u3 u4 u5 u6 u7 u8 u9) =
f 1 f 5 f 6 0)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Result for approach 2a: We get a linear system of the form The solution satisfies
1 2 3 4 5 6 7 8 9
1 a11 a15 a16 1 1 1 a51 a55 a56 a61 a65 a66 1 1 1)( u0 u1 u2 u3 u4 u5 u6 u7 u8 u9) =
f 1 f 5 f 6 0)
U 0=U 2=U 3=U 4=U 7=U 8=U 9=0
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Result for approach 2a: We get a linear system of the form The solution satisfies
1 2 3 4 5 6 7 8 9
1 a11 a15 a16 1 1 1 a51 a55 a56 a61 a65 a66 1 1 1)( u0 u1 u2 u3 u4 u5 u6 u7 u8 u9) =
f 1 f 5 f 6 0)
a11 a15 a16 a51 a55 a56 a61 a65 a66)( u1 u5 u6) =( f 1 f 5 f 6)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Summary approach 2a:
This results in a linear system that:
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Implementation approach 2a (step-4):
void Step4::assemble_system { …; for (cell=...) { ...assemble cell_matrix, cell_rhs...; ...add cell_matrix, cell_rhs to system_matrix, system_rhs...; } std::map<types::global_dof_index,double> boundary_values; VectorTools::interpolate_boundary_values (dof_handler, 0, ZeroFunction<dim>(), boundary_values); MatrixTools::apply_boundary_values (boundary_values, system_matrix, solution, system_rhs); }
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Summary approach 2a:
Advantages:
every cell during assembly/postprocessing
part of the code, independent of assembly
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Summary approach 2a:
Disadvantages:
after global assembly
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Approach 2:
conditions Variation 2b:
for boundary DoFs {0,2,3,4,7,8,9}
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2b: Recall that the linear system is computed from contributions of all cells:
1 2 3 4 5 6 7 8 9
AU = F A = ∑K=0
10
A K F = ∑K=0
10
F
K
1 2 3 4 5 4 6 7 8 10 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2b: Recall that the linear system is computed from contributions of all cells. For example:
1 2 3 4 5 6 7 8 9
AU = F
1 2 3 4 5 4 6 7 8 10 9
A
1=
a00
1
a01
1
a06
1
a10
1
a11
1
a16
1
a60
1
a61
1
a66
1
0) , F
1=
f 0
1
f 1
1
f 6
1
0)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2b: Recall that the linear system is computed from contributions of all cells. In reality, of course, we only store the dense 3x3 sub-block:
1 2 3 4 5 6 7 8 9
AU = F
1 2 3 4 5 4 6 7 8 10 9
A
1, loc=(
a00
1
a01
1
a06
1
a10
1
a11
1
a16
1
a60
1
a61
1
a66
1 )
, F
1,loc=(
f 0
1
f 1
1
f 6
1)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2b: Recall that the linear system is computed from contributions of all cells. Zero out rows and columns DoFs {0,2,3,4,7,8,9}:
1 2 3 4 5 6 7 8 9
AU = F
1 2 3 4 5 4 6 7 8 10 9
A
1, loc=(
a00
1
a01
1
a06
1
a10
1
a11
1
a16
1
a60
1
a61
1
a66
1 )
, F
1,loc=(
f 0
1
f 1
1
f 6
1)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2b: Recall that the linear system is computed from contributions of all cells. Zero out rows and columns DoFs {0,2,3,4,7,8,9}:
1 2 3 4 5 6 7 8 9
AU = F
1 2 3 4 5 4 6 7 8 10 9
A1, loc=( a11
1
a16
1
a61
1
a66
1 )
, F 1,loc=( f 1
1
f 6
1)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2b: Recall that the linear system is computed from contributions of all cells. Fix up under-determinedness:
1 2 3 4 5 6 7 8 9
AU = F
1 2 3 4 5 4 6 7 8 10 9
A1, loc=( 1 a11
1
a16
1
a61
1
a66
1 )
, F 1,loc=( f 1
1
f 6
1)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Example for approach 2b: Recall that the linear system is computed from contributions of all cells. Then add to global linear system:
1 2 3 4 5 6 7 8 9
AU = F
1 2 3 4 5 4 6 7 8 10 9
A := A+expand( A
1, loc)
F := F+expand(F
1,loc)
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Summary approach 2b:
Actual implementation:
at the same time
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Implementation approach 2b (step-6):
void Step6::assemble_system { ConstraintMatrix constraints; VectorTools::interpolate_boundary_values (dof_handler, 0, ZeroFunction<dim>(), constraints); …; for (cell=...) { ...assemble cell_matrix, cell_rhs...; cell->get_dof_indices (local_dof_indices); constraints.distribute_local_to_global (cell_matrix, cell_rhs, local_dof_indices, system_matrix, system_rhs); } }
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Summary approach 2b:
Advantages:
every cell during assembly/postprocessing
part of the code, independent of assembly
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Zero Dirichlet conditions
Summary approach 2b:
Disdvantages:
after local integration or during copy-local-to-global (both options are easy and cheap)
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
Summary
We are driven by algorithm design considerations:
code pieces as possible
contributions is simpler than with global linear systems Consequently:
1 2 3 4 5 6 7 8 9
http://www.dealii.org/ Wolfgang Bangerth
A final implementation detail
As a postscript: Consider a linear system of the form This matrix is ill-conditioned if Consequence:
1 a11 a15 a16 1 1 1 a51 a55 a56 a61 a65 a66 1 1 1)( u0 u1 u2 u3 u4 u5 u6 u7 u8 u9) =
f 1 f 5 f 6 0)
|aij|≫1 or |aij|≪1
http://www.dealii.org/ Wolfgang Bangerth
MATH 676 – Finite element methods in scientifjc computing
Wolfgang Bangerth, T exas A&M University