/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/common/affine_constraint_metadata.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/common/affine_constraint_metadata.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
affine_constraint_metadata.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
5
6// external libraries
7#include <deal.II/base/index_set.h>
8#include <deal.II/base/point.h>
9#include <deal.II/dofs/dof_handler.h>
10#include <deal.II/dofs/dof_tools.h>
11
12// standard library
13#include <utility>
14#include <vector>
15
16namespace DiFfRG
17{
18 template <int dim> struct AffineConstraintComponentView {
19 const dealii::IndexSet &dofs;
20 const std::vector<dealii::Point<dim>> &points;
21 };
22
23 template <typename Components_, int dim> class AffineConstraintContext
24 {
25 public:
26 using Components = Components_;
27 static constexpr int dimension = dim;
28
29 AffineConstraintContext(const std::vector<dealii::IndexSet> &component_boundary_dofs,
30 const std::vector<std::vector<dealii::Point<dim>>> &component_boundary_points,
31 const std::vector<dealii::IndexSet> &component_support_dofs,
32 const std::vector<std::vector<dealii::Point<dim>>> &component_support_points)
35 {
36 }
37
38 template <typename Metadata>
39 explicit AffineConstraintContext(const Metadata &metadata)
42 {
43 }
44
45 template <FixedString component_name> static consteval unsigned int component_index()
46 {
47 return static_cast<unsigned int>(typename Components::FEFunction_Descriptor{}(component_name));
48 }
49
50 template <FixedString component_name> static consteval std::size_t component_size()
51 {
52 return Components::FEFunction_Descriptor::sizes[component_index<component_name>()];
53 }
54
55 template <FixedString component_name> AffineConstraintComponentView<dim> boundary() const
56 {
57 constexpr auto c = component_index<component_name>();
59 }
60
61 template <FixedString component_name> AffineConstraintComponentView<dim> support() const
62 {
63 constexpr auto c = component_index<component_name>();
65 }
66
67 private:
68 const std::vector<dealii::IndexSet> &component_boundary_dofs;
69 const std::vector<std::vector<dealii::Point<dim>>> &component_boundary_points;
70 const std::vector<dealii::IndexSet> &component_support_dofs;
71 const std::vector<std::vector<dealii::Point<dim>>> &component_support_points;
72 };
73
74 namespace internal
75 {
76 template <typename> inline constexpr bool accepts_affine_constraint_context = false;
77
78 template <typename Model, typename Constraints, typename Context>
79 void apply_model_affine_constraints(Model &model, Constraints &constraints, const Context &context)
80 {
81 if constexpr (requires { model.affine_constraints(constraints, context); }) {
82 model.affine_constraints(constraints, context);
83 } else {
85 "The three-argument affine_constraints callback was removed. Implement "
86 "apply_boundary_affine_constraints(constraints, context) or "
87 "apply_affine_constraints(constraints, context) using AffineConstraintContext instead");
88 }
89 }
90
91 template <int dim> struct AffineConstraintMetadata {
92 std::vector<dealii::IndexSet> component_boundary_dofs;
93 std::vector<std::vector<dealii::Point<dim>>> component_boundary_points;
94 std::vector<dealii::IndexSet> component_support_dofs;
95 std::vector<std::vector<dealii::Point<dim>>> component_support_points;
96 };
97
98 template <typename Components, int dim, typename Discretization>
100 {
101 const auto &dof_handler = discretization.get_dof_handler();
103 metadata.component_boundary_dofs.resize(Components::count_fe_functions());
104 metadata.component_boundary_points.resize(Components::count_fe_functions());
105 metadata.component_support_dofs.resize(Components::count_fe_functions());
106 metadata.component_support_points.resize(Components::count_fe_functions());
107
108 for (unsigned int c = 0; c < Components::count_fe_functions(); ++c) {
109 dealii::ComponentMask component_mask(Components::count_fe_functions(), false);
110 component_mask.set(c, true);
111
112 metadata.component_boundary_dofs[c] = dealii::DoFTools::extract_boundary_dofs(dof_handler, component_mask);
113 metadata.component_boundary_points[c].resize(metadata.component_boundary_dofs[c].n_elements());
114 for (unsigned int i = 0; i < metadata.component_boundary_dofs[c].n_elements(); ++i)
115 metadata.component_boundary_points[c][i] =
116 discretization.get_support_point(metadata.component_boundary_dofs[c].nth_index_in_set(i));
117
118 metadata.component_support_dofs[c] = dealii::DoFTools::extract_dofs(dof_handler, component_mask);
119 metadata.component_support_points[c].resize(metadata.component_support_dofs[c].n_elements());
120 for (unsigned int i = 0; i < metadata.component_support_dofs[c].n_elements(); ++i)
121 metadata.component_support_points[c][i] =
122 discretization.get_support_point(metadata.component_support_dofs[c].nth_index_in_set(i));
123 }
124
125 return metadata;
126 }
127 } // namespace internal
128} // namespace DiFfRG
Definition affine_constraint_metadata.hh:24
AffineConstraintComponentView< dim > boundary() const
Definition affine_constraint_metadata.hh:55
const std::vector< dealii::IndexSet > & component_boundary_dofs
Definition affine_constraint_metadata.hh:68
static consteval std::size_t component_size()
Definition affine_constraint_metadata.hh:50
static constexpr int dimension
Definition affine_constraint_metadata.hh:27
const std::vector< std::vector< dealii::Point< dim > > > & component_support_points
Definition affine_constraint_metadata.hh:71
AffineConstraintContext(const Metadata &metadata)
Definition affine_constraint_metadata.hh:39
const std::vector< std::vector< dealii::Point< dim > > > & component_boundary_points
Definition affine_constraint_metadata.hh:69
Components_ Components
Definition affine_constraint_metadata.hh:26
const std::vector< dealii::IndexSet > & component_support_dofs
Definition affine_constraint_metadata.hh:70
static consteval unsigned int component_index()
Definition affine_constraint_metadata.hh:45
AffineConstraintComponentView< dim > support() const
Definition affine_constraint_metadata.hh:61
AffineConstraintContext(const std::vector< dealii::IndexSet > &component_boundary_dofs, const std::vector< std::vector< dealii::Point< dim > > > &component_boundary_points, const std::vector< dealii::IndexSet > &component_support_dofs, const std::vector< std::vector< dealii::Point< dim > > > &component_support_points)
Definition affine_constraint_metadata.hh:29
AffineConstraintMetadata< dim > build_affine_constraint_metadata(const Discretization &discretization)
Definition affine_constraint_metadata.hh:99
constexpr bool accepts_affine_constraint_context
Definition affine_constraint_metadata.hh:76
void apply_model_affine_constraints(Model &model, Constraints &constraints, const Context &context)
Definition affine_constraint_metadata.hh:79
Definition complex_math.hh:10
Definition affine_constraint_metadata.hh:18
const dealii::IndexSet & dofs
Definition affine_constraint_metadata.hh:19
const std::vector< dealii::Point< dim > > & points
Definition affine_constraint_metadata.hh:20
Definition affine_constraint_metadata.hh:91
std::vector< std::vector< dealii::Point< dim > > > component_boundary_points
Definition affine_constraint_metadata.hh:93
std::vector< dealii::IndexSet > component_support_dofs
Definition affine_constraint_metadata.hh:94
std::vector< std::vector< dealii::Point< dim > > > component_support_points
Definition affine_constraint_metadata.hh:95
std::vector< dealii::IndexSet > component_boundary_dofs
Definition affine_constraint_metadata.hh:92