Reduced Lagrange Multipliers
 
Loading...
Searching...
No Matches
reduced_coupling.cc
Go to the documentation of this file.
1#include "reduced_coupling.h"
2
4
7
8#include <fstream>
9
12#include "utils.h"
13#include "vtk_utils.h"
14
15template <int reduced_dim, int dim, int spacedim, int n_components>
18 : ParameterAcceptor("Reduced coupling/")
19{
20 this->enter_subsection("Representative domain");
21 this->add_parameter("Reduced right hand side",
23 "",
24 this->prm,
26 1,
28 ";"));
29 this->leave_subsection();
30}
31
32template <int reduced_dim, int dim, int spacedim, int n_components>
36 &par)
37 : TensorProductSpace<reduced_dim, dim, spacedim, n_components>(
38 par.tensor_product_space_parameters,
39#if DEAL_II_VERSION_GTE(9, 6, 0)
40 background_tria.get_communicator())
41#else
42background_tria.get_mpi_communicator()
43#endif
44 , ParticleCoupling<spacedim>(par.particle_coupling_parameters)
45 , mpi_communicator(
46#if DEAL_II_VERSION_GTE(9, 6, 0)
47 background_tria.get_communicator()
48#else
49 background_tria.get_mpi_communicator()
50#endif
51 )
52 , par(par)
53 , background_tria(&background_tria)
54 , immersed_partitioner(background_tria)
55{
56 this->preprocess_serial_triangulation =
58 // Preprocess the serial triangulation before setting up the partitioner
59 adjust_grids(*(this->background_tria), tria, par.refinement_parameters);
60 };
61
62 this->set_partitioner = [&](auto &tria) {
63 tria.set_partitioner(immersed_partitioner,
65 };
66}
67
68template <int reduced_dim, int dim, int spacedim, int n_components>
69void
71 const Mapping<spacedim> &mapping)
72{
73 // Initialize the tensor product space
75
76 auto locally_owned_dofs = this->get_dof_handler().locally_owned_dofs();
77 auto locally_relevant_dofs =
78 DoFTools::extract_locally_relevant_dofs(this->get_dof_handler());
79
80 coupling_constraints.clear();
81 coupling_constraints.reinit(locally_owned_dofs, locally_relevant_dofs);
82 DoFTools::make_hanging_node_constraints(this->get_dof_handler(),
83 coupling_constraints);
84 coupling_constraints.close();
85
86 // Initialize the particle coupling
88 *this->background_tria, mapping);
89
90 // Initialize the particles
91 const auto &qpoints = this->get_locally_owned_qpoints();
92 const auto &weights = this->get_locally_owned_weights();
93 auto q_index = this->insert_points(qpoints, weights);
94 this->update_local_dof_indices(q_index);
95
96 // Initialize the coupling rhs
97 typename FunctionParser<spacedim>::ConstMap constants;
98 constants["pi"] = numbers::PI;
99 constants["E"] = numbers::E;
100
101 coupling_rhs = std::make_unique<FunctionParser<spacedim>>(
102 this->get_reference_cross_section().n_selected_basis());
103
104 coupling_rhs->initialize(FunctionParser<spacedim>::default_variable_names() +
105 ",t",
107 constants,
108 true);
109
110 // This should be true. Let's double check
111 AssertDimension(coupling_rhs->n_components,
112 this->get_dof_handler().get_fe().n_components());
113
114 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
115 {
116 std::cout
117 << "Selected degree: "
118 << par.tensor_product_space_parameters.section.inclusion_degree
119 << ", selected basis functions: "
121 par.tensor_product_space_parameters.section.selected_coefficients)
122 << std::endl;
123 std::cout << "Reduced coupling initialized" << std::endl;
124 std::cout << "Reduced grid name: "
125 << par.tensor_product_space_parameters.reduced_grid_name
126 << std::endl;
127 }
128}
129
130template <int reduced_dim, int dim, int spacedim, int n_components>
131void
134 const DoFHandler<spacedim> &dh,
135 const AffineConstraints<double> &constraints) const
136{
137 const auto &fe = dh.get_fe();
138 std::vector<types::global_dof_index> background_dof_indices(
139 fe.n_dofs_per_cell());
140
141 auto particle = this->get_particles().begin();
142 while (particle != this->get_particles().end())
143 {
144 const auto &cell = particle->get_surrounding_cell();
145 const auto dh_cell =
146 typename DoFHandler<spacedim>::cell_iterator(*cell, &dh);
147 dh_cell->get_dof_indices(background_dof_indices);
148
149 const auto pic = this->get_particles().particles_in_cell(cell);
150 Assert(pic.begin() == particle, ExcInternalError());
151
153 for (const auto &p : pic)
154 {
155 const auto [immersed_cell_id, immersed_q, section_q] =
156 this->particle_id_to_cell_and_qpoint_indices(p.get_id());
157 // If cell id is the same, we can skip the rest of the loop. We
158 // already added these entries
159 if (immersed_cell_id != previous_cell_id)
160 {
161 const auto &immersed_dof_indices =
162 this->get_dof_indices(immersed_cell_id);
163
164 constraints.add_entries_local_to_global(background_dof_indices,
165 coupling_constraints,
166 immersed_dof_indices,
167 dsp);
168
169 previous_cell_id = immersed_cell_id;
170 }
171 }
172 particle = pic.end();
173 }
174}
175
176template <int reduced_dim, int dim, int spacedim, int n_components>
180{
181 return coupling_constraints;
182}
183
184// Explicit instantiations for ReducedCouplingParameters
189
194
195
196template struct ReducedCoupling<1, 2, 2, 1>;
197template struct ReducedCoupling<1, 2, 3, 1>;
198template struct ReducedCoupling<1, 3, 3, 1>;
199template struct ReducedCoupling<2, 3, 3, 1>;
200
201template struct ReducedCoupling<1, 2, 2, 2>;
202template struct ReducedCoupling<1, 2, 3, 3>;
203template struct ReducedCoupling<1, 3, 3, 3>;
204template struct ReducedCoupling<2, 3, 3, 3>;
void add_entries_local_to_global(const std::vector< size_type > &local_dof_indices, SparsityPatternBase &sparsity_pattern, const bool keep_constrained_entries=true, const Table< 2, bool > &dof_mask=Table< 2, bool >()) const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
std::map< std::string, double > ConstMap
static std::string default_variable_names()
ParameterAcceptor(const std::string &section_name="")
static ParameterHandler prm
void enter_subsection(const std::string &subsection)
void add_parameter(const std::string &entry, ParameterType &parameter, const std::string &documentation="", ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern())
static const unsigned int max_int_value
Manages the coupling of particles with a finite element background mesh.
void initialize_particle_handler(const parallel::TriangulationBase< dim > &tria_background, const Mapping< dim > &mapping=StaticMappingQ1< dim >::mapping)
#define DEAL_II_VERSION_GTE(major, minor, subminor)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
void make_hanging_node_constraints(const DoFHandler< dim, spacedim > &dof_handler, AffineConstraints< number > &constraints)
IndexSet extract_locally_relevant_dofs(const DoFHandler< dim, spacedim > &dof_handler)
std::string to_string(const T &t)
VectorType::value_type * end(VectorType &V)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
constexpr double E
constexpr double PI
constexpr unsigned int invalid_unsigned_int
unsigned int global_cell_index
Combines tensor product space and particle coupling for reduced Lagrange multipliers.
void assemble_coupling_sparsity(DynamicSparsityPattern &dsp, const DoFHandler< spacedim > &dh, const AffineConstraints< double > &constraints) const
Assemble the sparsity pattern for the coupling matrix.
ReducedCoupling(parallel::TriangulationBase< spacedim > &background_tria, const ReducedCouplingParameters< reduced_dim, dim, spacedim, n_components > &par)
Constructor that initializes the ReducedCoupling object with background triangulation and parameters.
const AffineConstraints< double > & get_coupling_constraints() const
Get the affine constraints associated with the coupling.
Parameter structure for configuring ReducedCoupling objects.
ReducedCouplingParameters()
Constructor that registers parameters with the ParameterAcceptor.
RefinementParameters refinement_parameters
TensorProductSpaceParameters< reduced_dim, dim, spacedim, n_components > tensor_product_space_parameters
Parameters for the tensor product space.
std::vector< std::string > coupling_rhs_expressions
Right hand side expressions for the reduced coupling.
void adjust_grids(Triangulation< spacedim, spacedim > &space_triangulation, Triangulation< reduced_dim, spacedim > &embedded_triangulation, const RefinementParameters &parameters=RefinementParameters())
Definition utils.h:65