Skip to content

Commit

Permalink
Convert some of the tutorials.
Browse files Browse the repository at this point in the history
  • Loading branch information
bangerth committed Oct 5, 2023
1 parent 07de9e4 commit 706a419
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
7 changes: 4 additions & 3 deletions examples/step-11/step-11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ namespace Step11

// Then generate a constraints object with just this one constraint. First
// clear all previous content (which might reside there from the previous
// computation on a once coarser grid), then add this one line
// computation on a once coarser grid), then add this one constraint,
// constraining the <code>first_boundary_dof</code> to the sum of other
// boundary DoFs each with weight -1. Finally, close the constraints
// object, i.e. do some internal bookkeeping on it for faster processing
// of what is to come later:
mean_value_constraints.clear();
mean_value_constraints.add_line(first_boundary_dof);
std::vector<std::pair<types::global_dof_index, double>> rhs;
for (const types::global_dof_index i : boundary_dofs)
if (i != first_boundary_dof)
mean_value_constraints.add_entry(first_boundary_dof, i, -1);
rhs.emplace_back(i, -1.);
mean_value_constraints.add_constraint(first_boundary_dof, rhs);
mean_value_constraints.close();

// Next task is to generate a sparsity pattern. This is indeed a tricky
Expand Down
3 changes: 1 addition & 2 deletions examples/step-41/step-41.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ namespace Step41
0)
{
active_set.add_index(dof_index);
constraints.add_line(dof_index);
constraints.set_inhomogeneity(dof_index, obstacle_value);
constraints.add_constraint(dof_index, {}, obstacle_value);

solution(dof_index) = obstacle_value;

Expand Down
15 changes: 5 additions & 10 deletions examples/step-46/doc/intro.dox
Original file line number Diff line number Diff line change
Expand Up @@ -494,21 +494,16 @@ for (const auto &cell: dof_handler.active_cell_iterators())
cell->face(f)->get_dof_indices (local_face_dof_indices, 0);
for (unsigned int i=0; i<local_face_dof_indices.size(); ++i)
if (stokes_fe.face_system_to_component_index(i).first < dim)
constraints.add_line (local_face_dof_indices[i]);
constraints.add_constraint (local_face_dof_indices[i], {}, 0.);
}
}
@endcode

The call <code>constraints.add_line(t)</code> tells the
AffineConstraints to start a new constraint for degree of freedom
<code>t</code> of the form $x_t=\sum_{l=0}^{N-1} c_{tl} x_l +
b_t$. Typically, one would then proceed to set individual coefficients
$c_{tl}$ to nonzero values (using AffineConstraints::add_entry) or set
$b_t$ to something nonzero (using
AffineConstraints::set_inhomogeneity); doing nothing as above, funny as
it looks, simply leaves the constraint to be $x_t=0$, which is exactly
The last line calls
AffineConstraints::add_constraint() and adds the constraint
<i>x<sub>local_face_dof_indices[i]</sub>=0</i>, which is exactly
what we need in the current context. The call to
FiniteElement::face_system_to_component_index makes sure that we only set
FiniteElement::face_system_to_component_index() makes sure that we only set
boundary values to zero for velocity but not pressure components.

Note that there are cases where this may yield incorrect results:
Expand Down
4 changes: 3 additions & 1 deletion examples/step-46/step-46.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ namespace Step46
++i)
if (stokes_fe.face_system_to_component_index(i).first <
dim)
constraints.add_line(local_face_dof_indices[i]);
constraints.add_constraint(local_face_dof_indices[i],
{},
0.);
}
}
}
Expand Down

0 comments on commit 706a419

Please sign in to comment.