From 866ffdcb5becaf524cad41451be232fc8def6427 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 5 Oct 2023 16:19:22 -0600 Subject: [PATCH] Convert a bunch of places to use AffineConstraint::add_constraint(). --- .../vector_tools_boundary.templates.h | 97 ++++++++----------- .../vector_tools_constraints.templates.h | 32 +++--- source/dofs/dof_tools_constraints.cc | 6 +- 3 files changed, 58 insertions(+), 77 deletions(-) diff --git a/include/deal.II/numerics/vector_tools_boundary.templates.h b/include/deal.II/numerics/vector_tools_boundary.templates.h index 6bd811a010..7b8b9d4a42 100644 --- a/include/deal.II/numerics/vector_tools_boundary.templates.h +++ b/include/deal.II/numerics/vector_tools_boundary.templates.h @@ -519,11 +519,9 @@ namespace VectorTools { if (constraints.can_store_line(boundary_value.first) && !constraints.is_constrained(boundary_value.first)) - { - constraints.add_line(boundary_value.first); - constraints.set_inhomogeneity(boundary_value.first, - boundary_value.second); - } + constraints.add_constraint(boundary_value.first, + {}, + boundary_value.second); } } @@ -564,11 +562,9 @@ namespace VectorTools { if (constraints.can_store_line(boundary_value.first) && !constraints.is_constrained(boundary_value.first)) - { - constraints.add_line(boundary_value.first); - constraints.set_inhomogeneity(boundary_value.first, - boundary_value.second); - } + constraints.add_constraint(boundary_value.first, + {}, + boundary_value.second); } } @@ -955,16 +951,13 @@ namespace VectorTools std::map boundary_values; project_boundary_values( mapping, dof, boundary_functions, q, boundary_values, component_mapping); - typename std::map::const_iterator - boundary_value = boundary_values.begin(); - for (; boundary_value != boundary_values.end(); ++boundary_value) + + for (const auto &boundary_value : boundary_values) { - if (!constraints.is_constrained(boundary_value->first)) - { - constraints.add_line(boundary_value->first); - constraints.set_inhomogeneity(boundary_value->first, - boundary_value->second); - } + if (!constraints.is_constrained(boundary_value.first)) + constraints.add_constraint(boundary_value.first, + {}, + boundary_value.second); } } @@ -1934,16 +1927,12 @@ namespace VectorTools face_dof_indices[dof]) && !(constraints.is_constrained( face_dof_indices[dof]))) - { - constraints.add_line( - face_dof_indices[dof]); - if (std::abs(dof_values[dof]) > 1e-13) - { - constraints.set_inhomogeneity( - face_dof_indices[dof], - dof_values[dof]); - } - } + constraints.add_constraint( + face_dof_indices[dof], + {}, + (std::abs(dof_values[dof]) > 1e-13 ? + dof_values[dof] : + 0)); } } } @@ -2078,17 +2067,12 @@ namespace VectorTools face_dof_indices[dof]) && !(constraints.is_constrained( face_dof_indices[dof]))) - { - constraints.add_line( - face_dof_indices[dof]); - - if (std::abs(dof_values[dof]) > 1e-13) - { - constraints.set_inhomogeneity( - face_dof_indices[dof], - dof_values[dof]); - } - } + constraints.add_constraint( + face_dof_indices[dof], + {}, + (std::abs(dof_values[dof]) > 1e-13 ? + dof_values[dof] : + 0)); } } } @@ -2232,12 +2216,11 @@ namespace VectorTools cell->face_orientation(face), cell->face_flip(face), cell->face_rotation(face)))[first_vector_component]) - { - constraints.add_line(face_dof_indices[i]); - - if (std::abs(dof_values(i)) > 1e-14) - constraints.set_inhomogeneity(face_dof_indices[i], dof_values(i)); - } + constraints.add_constraint(face_dof_indices[i], + {}, + (std::abs(dof_values[i]) > 1e-14 ? + dof_values[i] : + 0)); } // dummy implementation of above function for all other dimensions @@ -2529,12 +2512,11 @@ namespace VectorTools for (unsigned int dof = 0; dof < n_dofs; ++dof) if ((projected_dofs[dof] != 0) && !(constraints.is_constrained(dof))) - { - constraints.add_line(dof); - - if (std::abs(dof_values[dof]) > 1e-14) - constraints.set_inhomogeneity(dof, dof_values[dof]); - } + constraints.add_constraint(dof, + {}, + (std::abs(dof_values[dof]) > 1e-14 ? + dof_values[dof] : + 0)); break; } @@ -2688,12 +2670,11 @@ namespace VectorTools for (unsigned int dof = 0; dof < n_dofs; ++dof) if ((projected_dofs[dof] != 0) && !(constraints.is_constrained(dof))) - { - constraints.add_line(dof); - - if (std::abs(dof_values[dof]) > 1e-14) - constraints.set_inhomogeneity(dof, dof_values[dof]); - } + constraints.add_constraint(dof, + {}, + (std::abs(dof_values[dof]) > 1e-14 ? + dof_values[dof] : + 0)); break; } diff --git a/include/deal.II/numerics/vector_tools_constraints.templates.h b/include/deal.II/numerics/vector_tools_constraints.templates.h index f8c8146c61..7a28a5efb8 100644 --- a/include/deal.II/numerics/vector_tools_constraints.templates.h +++ b/include/deal.II/numerics/vector_tools_constraints.templates.h @@ -1063,13 +1063,13 @@ namespace VectorTools constraints.can_store_line( same_dof_range[0]->first.dof_indices[i])) { - const types::global_dof_index line = - dof_indices.dof_indices[i]; - constraints.add_line(line); - if (std::fabs(b_values[i]) > - std::numeric_limits::epsilon()) - constraints.set_inhomogeneity(line, b_values[i]); - // no add_entries here + constraints.add_constraint( + dof_indices.dof_indices[i], + {}, + (std::fabs(b_values[i]) > + std::numeric_limits::epsilon() ? + b_values[i] : + 0)); } break; @@ -1459,10 +1459,7 @@ namespace VectorTools { const Vector b_value = dof_vector_to_b_values[dofs]; for (unsigned int d = 0; d < dim; ++d) - { - constraints.add_line(dofs[d]); - constraints.set_inhomogeneity(dofs[d], b_value(d)); - } + constraints.add_constraint(dofs[d], {}, b_value(d)); continue; } @@ -1502,12 +1499,15 @@ namespace VectorTools const unsigned int new_index = dofs[d]; if (!constraints.is_constrained(new_index)) { - constraints.add_line(new_index); if (std::abs(normal[d]) > 1e-13) - constraints.add_entry(new_index, - dofs[constrained_index], - -normal[d]); - constraints.set_inhomogeneity(new_index, boundary_value[d]); + constraints.add_constraint(new_index, + {{dofs[constrained_index], + -normal[d]}}, + boundary_value[d]); + else + constraints.add_constraint(new_index, + {}, + boundary_value[d]); } } } diff --git a/source/dofs/dof_tools_constraints.cc b/source/dofs/dof_tools_constraints.cc index 7e8aafdef6..716de8eca8 100644 --- a/source/dofs/dof_tools_constraints.cc +++ b/source/dofs/dof_tools_constraints.cc @@ -571,9 +571,9 @@ namespace DoFTools if (std::fabs(face_constraints(row, i)) >= 1e-14 * abs_sum) entries.emplace_back(primary_dofs[i], face_constraints(row, i)); - constraints.add_line(dependent_dofs[row]); - constraints.add_entries(dependent_dofs[row], entries); - constraints.set_inhomogeneity(dependent_dofs[row], 0.); + constraints.add_constraint(dependent_dofs[row], + entries, + /* inhomogeneity= */ 0.); } } -- 2.39.5