16 #ifndef INCLUDE_IDEAL_II_NUMERICS_VECTOR_TOOLS_HH_
17 #define INCLUDE_IDEAL_II_NUMERICS_VECTOR_TOOLS_HH_
19 #include <deal.II/base/config.h>
21 #include <ideal.II/base/quadrature_lib.hh>
23 #include <ideal.II/dofs/slab_dof_handler.hh>
25 #include <deal.II/fe/fe_values.h>
27 #include <deal.II/lac/affine_constraints.h>
28 #include <deal.II/lac/trilinos_vector.h>
29 #include <deal.II/lac/vector.h>
31 #include <deal.II/numerics/vector_tools.h>
54 template <
int dim,
typename Number>
58 const dealii::types::boundary_id boundary_component,
59 dealii::Function<dim, Number> &boundary_function,
60 std::shared_ptr<dealii::AffineConstraints<Number>> spacetime_constraints,
61 const dealii::ComponentMask &component_mask = dealii::ComponentMask());
80 template <
int dim,
typename Number =
double>
83 dealii::IndexSet space_relevant_dofs,
85 const dealii::types::boundary_id boundary_component,
86 dealii::Function<dim, Number> &boundary_function,
87 std::shared_ptr<dealii::AffineConstraints<Number>> spacetime_constraints,
88 const dealii::ComponentMask &component_mask = dealii::ComponentMask())
90 auto space_constraints =
91 std::make_shared<dealii::AffineConstraints<Number>>();
92 space_constraints->reinit(space_relevant_dofs);
93 dealii::Quadrature<1> quad_time(
94 dof_handler.
temporal()->get_fe(0).get_unit_support_points());
95 dealii::FEValues<1> fev(dof_handler.
temporal()->get_fe(0),
97 dealii::update_quadrature_points);
100 unsigned int time_dof = 0;
101 std::vector<dealii::types::global_dof_index> local_indices(
104 for (
const auto &cell_time :
105 dof_handler.
temporal()->active_cell_iterators())
107 fev.reinit(cell_time);
109 cell_time->get_dof_indices(local_indices);
110 for (
unsigned int q = 0; q < quad_time.size(); q++)
112 space_constraints->clear();
113 time_dof = local_indices[q];
114 boundary_function.set_time(fev.quadrature_point(q)[0]);
115 dealii::VectorTools::interpolate_boundary_values(
122 for (
auto id = space_relevant_dofs.begin();
123 id != space_relevant_dofs.end();
127 if (space_constraints->is_constrained(*
id))
129 const std::vector<std::pair<dealii::types::global_dof_index,
131 space_constraints->get_constraint_entries(*
id);
132 spacetime_constraints->add_line(*
id +
133 time_dof * n_space_dofs);
135 if (entries->size() > 0)
137 for (
auto entry : *entries)
139 std::cout << entry.first <<
"," << entry.second
141 spacetime_constraints->add_entry(
142 *
id + time_dof * n_space_dofs,
143 entry.first + time_dof * n_space_dofs,
149 spacetime_constraints->set_inhomogeneity(
150 *
id + time_dof * n_space_dofs,
151 space_constraints->get_inhomogeneity(*
id));
175 template <
int dim,
typename Number>
179 unsigned int first_vector_component,
180 dealii::Function<dim, Number> &boundary_function,
181 const dealii::types::boundary_id boundary_component,
182 std::shared_ptr<dealii::AffineConstraints<Number>> spacetime_constraints);
193 dealii::Vector<double> &space_vector,
194 unsigned int dof_index)
196 unsigned int n_dofs_space = space_vector.size();
197 for (
unsigned int i = 0; i < n_dofs_space; i++)
199 space_vector[i] = spacetime_vector[i + dof_index * n_dofs_space];
203 #ifdef DEAL_II_WITH_MPI
213 const dealii::TrilinosWrappers::MPI::Vector &spacetime_vector,
214 dealii::TrilinosWrappers::MPI::Vector &space_vector,
215 unsigned int dof_index)
217 dealii::IndexSet space_owned = space_vector.locally_owned_elements();
218 unsigned int n_dofs_space = space_vector.size();
219 dealii::TrilinosWrappers::MPI::Vector tmp;
220 tmp.reinit(space_owned, space_vector.get_mpi_communicator());
221 for (
auto id = space_owned.begin();
id != space_owned.end();
id++)
223 tmp[*id] = spacetime_vector[*
id + dof_index * n_dofs_space];
242 const dealii::Vector<double> &spacetime_vector,
243 dealii::Vector<double> &space_vector,
247 unsigned int n_dofs_space = space_vector.size();
250 for (
auto cell : dof_handler.
temporal()->active_cell_iterators())
252 left = cell->face(0)->center()(0);
253 right = cell->face(1)->center()(0);
254 if (t < left || t > right)
258 double _t = (t - left) / (right - left);
259 dealii::Point<1> qpoint(_t);
260 const dealii::Quadrature<1> time_qf(qpoint);
261 dealii::FEValues<1> time_values(dof_handler.
temporal()->get_fe(),
263 dealii::update_values);
264 time_values.reinit(cell);
265 unsigned int offset =
269 double factor = time_values.shape_value(ii, 0);
270 for (
unsigned int i = 0; i < n_dofs_space; i++)
273 spacetime_vector[i + ii * n_dofs_space + offset] * factor;
279 #ifdef DEAL_II_WITH_MPI
294 const dealii::TrilinosWrappers::MPI::Vector &spacetime_vector,
295 dealii::TrilinosWrappers::MPI::Vector &space_vector,
299 unsigned int n_dofs_space = space_vector.size();
302 for (
auto cell : dof_handler.
temporal()->active_cell_iterators())
304 left = cell->face(0)->center()(0);
305 right = cell->face(1)->center()(0);
306 if (t < left || t > right)
310 double _t = (t - left) / (right - left);
311 dealii::Point<1> qpoint(_t);
312 const dealii::Quadrature<1> time_qf(qpoint);
313 dealii::FEValues<1> time_values(dof_handler.
temporal()->get_fe(),
315 dealii::update_values);
316 time_values.reinit(cell);
317 dealii::IndexSet space_owned = space_vector.locally_owned_elements();
318 unsigned int n_dofs_space = space_vector.size();
319 dealii::TrilinosWrappers::MPI::Vector tmp;
320 tmp.reinit(space_owned, space_vector.get_mpi_communicator());
324 double factor = time_values.shape_value(ii, 0);
325 for (
auto id = space_owned.begin();
id != space_owned.end();
id++)
327 tmp[*id] += spacetime_vector[*
id + ii * n_dofs_space] * factor;
349 dealii::Vector<double> &spacetime_vector,
350 dealii::Function<dim, double> &exact_solution,
368 dealii::TrilinosWrappers::MPI::Vector &spacetime_vector,
369 dealii::Function<dim, double> &exact_solution,
Actual DoFHandler for a specific slab.
Definition: slab_dof_handler.hh:43
std::shared_ptr< dealii::DoFHandler< 1 > > temporal()
The underlying temporal dof handler.
std::shared_ptr< dealii::DoFHandler< dim > > spatial()
The underlying spatial dof handler.
unsigned int n_dofs_space()
Number of spatial degrees of fredom on this slab.
unsigned int dofs_per_cell_time()
Number of temporal dofs in a single element/interval.
The base class for quadrature formulae in space and time.
Definition: spacetime_quadrature.hh:35