45template <
int dim,
typename VectorType,
int spacedim>
48 : dof_handler(&dof, typeid(*this).name())
55 ExcMessage(
"You are calling the ::SolutionTransfer class "
56 "with a DoFHandler that is built on a "
57 "parallel::distributed::Triangulation. This will not "
58 "work for parallel computations. You probably want to "
59 "use the parallel::distributed::SolutionTransfer class."));
64template <
int dim,
typename VectorType,
int spacedim>
72template <
int dim,
typename VectorType,
int spacedim>
76 indices_on_cell.clear();
77 dof_values_on_cell.clear();
85template <
int dim,
typename VectorType,
int spacedim>
89 Assert(prepared_for != pure_refinement, ExcAlreadyPrepForRef());
90 Assert(prepared_for != coarsening_and_refinement,
91 ExcAlreadyPrepForCoarseAndRef());
105 subdomain_modifier(dof_handler->get_triangulation());
107 const unsigned int n_active_cells =
108 dof_handler->get_triangulation().n_active_cells();
109 n_dofs_old = dof_handler->n_dofs();
112 std::vector<std::vector<types::global_dof_index>>(n_active_cells)
113 .
swap(indices_on_cell);
115 for (
const auto &cell : dof_handler->active_cell_iterators())
117 const unsigned int i = cell->active_cell_index();
118 indices_on_cell[i].resize(cell->get_fe().n_dofs_per_cell());
125 cell->get_dof_indices(indices_on_cell[i]);
126 cell_map[std::make_pair(cell->level(), cell->index())] =
129 prepared_for = pure_refinement;
134template <
int dim,
typename VectorType,
int spacedim>
137 const VectorType &in,
138 VectorType & out)
const
140 Assert(prepared_for == pure_refinement, ExcNotPrepared());
142 Assert(out.size() == dof_handler->n_dofs(),
145 ExcMessage(
"Vectors cannot be used as input and output"
146 " at the same time!"));
158 subdomain_modifier(dof_handler->get_triangulation());
162 typename std::map<std::pair<unsigned int, unsigned int>,
164 cell_map_end = cell_map.end();
166 for (
const auto &cell : dof_handler->cell_iterators())
169 cell_map.find(std::make_pair(cell->level(), cell->index()));
171 if (pointerstruct != cell_map_end)
179 const unsigned int this_fe_index =
181 const unsigned int dofs_per_cell =
182 cell->get_dof_handler().get_fe(this_fe_index).n_dofs_per_cell();
183 local_values.
reinit(dofs_per_cell,
true);
188 Assert(dofs_per_cell == (*pointerstruct->second.indices_ptr).size(),
190 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
192 in, (*pointerstruct->second.indices_ptr)[i]);
193 cell->set_dof_values_by_interpolation(local_values,
218 template <
int dim,
int spacedim>
227 matrices.reinit(fe.size(), fe.size());
228 for (
unsigned int i = 0; i < fe.size(); ++i)
229 for (
unsigned int j = 0; j < fe.size(); ++j)
232 matrices(i, j).reinit(fe[i].n_dofs_per_cell(),
233 fe[j].n_dofs_per_cell());
244 fe[i].get_interpolation_matrix(fe[j], matrices(i, j));
247 ExcInterpolationNotImplemented &)
249 matrices(i, j).reinit(0, 0);
255 template <
int dim,
int spacedim>
258 std::vector<std::vector<bool>> &)
261 template <
int dim,
int spacedim>
264 std::vector<std::vector<bool>> &restriction_is_additive)
266 restriction_is_additive.resize(fe.size());
267 for (
unsigned int f = 0; f < fe.size(); ++f)
269 restriction_is_additive[f].resize(fe[f].n_dofs_per_cell());
270 for (
unsigned int i = 0; i < fe[f].n_dofs_per_cell(); ++i)
271 restriction_is_additive[f][i] = fe[f].restriction_is_additive(i);
278template <
int dim,
typename VectorType,
int spacedim>
283 Assert(prepared_for != pure_refinement, ExcAlreadyPrepForRef());
284 Assert(prepared_for != coarsening_and_refinement,
285 ExcAlreadyPrepForCoarseAndRef());
288 n_dofs_old = dof_handler->n_dofs();
289 const unsigned int in_size = all_in.size();
293 ExcMessage(
"The array of input vectors you pass to this "
294 "function has no elements. This is not useful."));
295 for (
unsigned int i = 0; i < in_size; ++i)
297 Assert(all_in[i].size() == n_dofs_old,
312 subdomain_modifier(dof_handler->get_triangulation());
317 unsigned int n_cells_to_coarsen = 0;
318 unsigned int n_cells_to_stay_or_refine = 0;
319 for (
const auto &act_cell : dof_handler->active_cell_iterators())
321 if (act_cell->coarsen_flag_set())
322 ++n_cells_to_coarsen;
324 ++n_cells_to_stay_or_refine;
326 Assert((n_cells_to_coarsen + n_cells_to_stay_or_refine) ==
327 dof_handler->get_triangulation().n_active_cells(),
330 unsigned int n_coarsen_fathers = 0;
331 for (
const auto &cell : dof_handler->cell_iterators())
332 if (!cell->is_active() && cell->child(0)->coarsen_flag_set())
335 (void)n_cells_to_coarsen;
340 std::vector<std::vector<types::global_dof_index>>(n_cells_to_stay_or_refine)
341 .
swap(indices_on_cell);
343 std::vector<std::vector<Vector<typename VectorType::value_type>>>(
345 std::vector<Vector<typename VectorType::value_type>>(in_size))
346 .swap(dof_values_on_cell);
349 std::vector<std::vector<bool>> restriction_is_additive;
353 restriction_is_additive);
358 unsigned int n_sr = 0, n_cf = 0;
359 for (
const auto &cell : dof_handler->cell_iterators())
362 if (cell->is_active() && !cell->coarsen_flag_set())
364 const unsigned int dofs_per_cell = cell->get_fe().n_dofs_per_cell();
365 indices_on_cell[n_sr].resize(dofs_per_cell);
370 cell->get_dof_indices(indices_on_cell[n_sr]);
371 cell_map[std::make_pair(cell->level(), cell->index())] =
372 Pointerstruct(&indices_on_cell[n_sr], cell->active_fe_index());
377 else if (cell->has_children() && cell->child(0)->coarsen_flag_set())
385 std::set<unsigned int> fe_indices_children;
386 for (
const auto &child : cell->child_iterators())
388 Assert(child->is_active() && child->coarsen_flag_set(),
389 typename ::Triangulation<
390 dim>::ExcInconsistentCoarseningFlags());
392 fe_indices_children.insert(child->active_fe_index());
396 const unsigned int target_fe_index =
397 dof_handler->get_fe_collection().find_dominated_fe_extended(
398 fe_indices_children, 0);
402 ExcNoDominatedFiniteElementOnChildren());
404 const unsigned int dofs_per_cell =
405 dof_handler->get_fe(target_fe_index).n_dofs_per_cell();
407 std::vector<Vector<typename VectorType::value_type>>(
409 .
swap(dof_values_on_cell[n_cf]);
417 for (
unsigned int j = 0; j < in_size; ++j)
418 cell->get_interpolated_dof_values(all_in[j],
419 dof_values_on_cell[n_cf][j],
421 cell_map[std::make_pair(cell->level(), cell->index())] =
429 prepared_for = coarsening_and_refinement;
434template <
int dim,
typename VectorType,
int spacedim>
439 std::vector<VectorType> all_in(1, in);
440 prepare_for_coarsening_and_refinement(all_in);
445template <
int dim,
typename VectorType,
int spacedim>
448 const std::vector<VectorType> &all_in,
449 std::vector<VectorType> & all_out)
const
451 const unsigned int size = all_in.size();
453 Assert(prepared_for == coarsening_and_refinement, ExcNotPrepared());
455 for (
unsigned int i = 0; i < size; ++i)
456 Assert(all_in[i].size() == n_dofs_old,
458 for (
unsigned int i = 0; i < all_out.size(); ++i)
459 Assert(all_out[i].size() == dof_handler->n_dofs(),
461 for (
unsigned int i = 0; i < size; ++i)
462 for (
unsigned int j = 0; j < size; ++j)
463 Assert(&all_in[i] != &all_out[j],
464 ExcMessage(
"Vectors cannot be used as input and output"
465 " at the same time!"));
478 subdomain_modifier(dof_handler->get_triangulation());
481 std::vector<types::global_dof_index> dofs;
483 typename std::map<std::pair<unsigned int, unsigned int>,
485 cell_map_end = cell_map.end();
491 for (
const auto &cell : dof_handler->cell_iterators())
494 cell_map.find(std::make_pair(cell->level(), cell->index()));
496 if (pointerstruct != cell_map_end)
498 const std::vector<types::global_dof_index> *
const indexptr =
499 pointerstruct->second.indices_ptr;
501 const std::vector<Vector<typename VectorType::value_type>>
502 *
const valuesptr = pointerstruct->second.dof_values_ptr;
505 if (indexptr !=
nullptr)
509 const unsigned int old_fe_index =
510 pointerstruct->second.active_fe_index;
514 unsigned int in_size = indexptr->size();
515 for (
unsigned int j = 0; j < size; ++j)
517 tmp.
reinit(in_size,
true);
518 for (
unsigned int i = 0; i < in_size; ++i)
523 cell->set_dof_values_by_interpolation(tmp,
535 const unsigned int dofs_per_cell =
536 cell->get_fe().n_dofs_per_cell();
537 dofs.resize(dofs_per_cell);
540 cell->get_dof_indices(dofs);
543 for (
unsigned int j = 0; j < size; ++j)
550 const unsigned int active_fe_index = cell->active_fe_index();
551 if (active_fe_index != pointerstruct->second.active_fe_index)
553 const unsigned int old_index =
554 pointerstruct->second.active_fe_index;
556 interpolation_hp(active_fe_index, old_index);
559 if (interpolation_matrix.empty())
560 tmp.
reinit(dofs_per_cell,
false);
563 tmp.
reinit(dofs_per_cell,
true);
565 interpolation_matrix.
n());
567 interpolation_matrix.
vmult(tmp, (*valuesptr)[j]);
572 data = &(*valuesptr)[j];
575 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
590template <
int dim,
typename VectorType,
int spacedim>
593 VectorType &out)
const
596 Assert(out.size() == dof_handler->n_dofs(),
599 std::vector<VectorType> all_in(1);
601 std::vector<VectorType> all_out(1);
603 interpolate(all_in, all_out);
609template <
int dim,
typename VectorType,
int spacedim>
619 sizeof(prepared_for) +
626template <
int dim,
typename VectorType,
int spacedim>
631 return sizeof(*this);
636#define SPLIT_INSTANTIATIONS_COUNT 4
637#ifndef SPLIT_INSTANTIATIONS_INDEX
638# define SPLIT_INSTANTIATIONS_INDEX 0
640#include "solution_transfer.inst"
const hp::FECollection< dim, spacedim > & get_fe_collection() const
bool has_hp_capabilities() const
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void refine_interpolate(const VectorType &in, VectorType &out) const
void interpolate(const std::vector< VectorType > &all_in, std::vector< VectorType > &all_out) const
SmartPointer< const DoFHandler< dim, spacedim >, SolutionTransfer< dim, VectorType, spacedim > > dof_handler
std::size_t memory_consumption() const
void prepare_for_coarsening_and_refinement(const std::vector< VectorType > &all_in)
void prepare_for_pure_refinement()
SolutionTransfer(const DoFHandler< dim, spacedim > &dof)
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::enable_if_t< std::is_fundamental< T >::value, std::size_t > memory_consumption(const T &t)
void restriction_additive(const FiniteElement< dim, spacedim > &, std::vector< std::vector< bool > > &)
void extract_interpolation_matrices(const DoFHandler< dim, spacedim > &dof, ::Table< 2, FullMatrix< double > > &matrices)
static const unsigned int invalid_unsigned_int
void swap(SmartPointer< T, P > &t1, SmartPointer< T, Q > &t2)
unsigned int active_fe_index
std::size_t memory_consumption() const
static VectorType::value_type get(const VectorType &V, const types::global_dof_index i)