87 Assert(prepared_for != pure_refinement, ExcAlreadyPrepForRef());
88 Assert(prepared_for != coarsening_and_refinement,
89 ExcAlreadyPrepForCoarseAndRef());
103 subdomain_modifier(dof_handler->get_triangulation());
105 const unsigned int n_active_cells =
106 dof_handler->get_triangulation().n_active_cells();
107 n_dofs_old = dof_handler->n_dofs();
110 std::vector<std::vector<types::global_dof_index>>(n_active_cells)
111 .
swap(indices_on_cell);
113 for (
const auto &cell : dof_handler->active_cell_iterators())
115 const unsigned int i = cell->active_cell_index();
116 indices_on_cell[i].resize(cell->get_fe().n_dofs_per_cell());
123 cell->get_dof_indices(indices_on_cell[i]);
124 cell_map[std::make_pair(cell->level(), cell->index())] =
127 prepared_for = pure_refinement;
135 const VectorType &in,
136 VectorType &out)
const
138 Assert(prepared_for == pure_refinement, ExcNotPrepared());
140 Assert(out.size() == dof_handler->n_dofs(),
143 ExcMessage(
"Vectors cannot be used as input and output"
144 " at the same time!"));
156 subdomain_modifier(dof_handler->get_triangulation());
160 typename std::map<std::pair<unsigned int, unsigned int>,
162 cell_map_end = cell_map.end();
164 for (
const auto &cell : dof_handler->cell_iterators())
167 cell_map.find(std::make_pair(cell->level(), cell->index()));
169 if (pointerstruct != cell_map_end)
177 const unsigned int this_fe_index =
178 pointerstruct->second.active_fe_index;
179 const unsigned int dofs_per_cell =
180 cell->get_dof_handler().get_fe(this_fe_index).n_dofs_per_cell();
181 local_values.
reinit(dofs_per_cell,
true);
186 Assert(dofs_per_cell == (*pointerstruct->second.indices_ptr).size(),
188 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
190 in, (*pointerstruct->second.indices_ptr)[i]);
191 cell->set_dof_values_by_interpolation(local_values,
225 matrices.reinit(fe.size(), fe.size());
226 for (
unsigned int i = 0; i < fe.size(); ++i)
227 for (
unsigned int j = 0; j < fe.size(); ++j)
230 matrices(i, j).reinit(fe[i].n_dofs_per_cell(),
231 fe[j].n_dofs_per_cell());
242 fe[i].get_interpolation_matrix(fe[j], matrices(i, j));
245 ExcInterpolationNotImplemented &)
247 matrices(i, j).reinit(0, 0);
262 std::vector<std::vector<bool>> &restriction_is_additive)
264 restriction_is_additive.resize(fe.size());
265 for (
unsigned int f = 0; f < fe.size(); ++f)
267 restriction_is_additive[f].resize(fe[f].n_dofs_per_cell());
268 for (
unsigned int i = 0; i < fe[f].n_dofs_per_cell(); ++i)
269 restriction_is_additive[f][i] = fe[f].restriction_is_additive(i);
281 Assert(prepared_for != pure_refinement, ExcAlreadyPrepForRef());
282 Assert(prepared_for != coarsening_and_refinement,
283 ExcAlreadyPrepForCoarseAndRef());
286 n_dofs_old = dof_handler->n_dofs();
287 const unsigned int in_size = all_in.size();
291 ExcMessage(
"The array of input vectors you pass to this "
292 "function has no elements. This is not useful."));
293 for (
unsigned int i = 0; i < in_size; ++i)
295 Assert(all_in[i].size() == n_dofs_old,
310 subdomain_modifier(dof_handler->get_triangulation());
315 unsigned int n_cells_to_coarsen = 0;
316 unsigned int n_cells_to_stay_or_refine = 0;
317 for (
const auto &act_cell : dof_handler->active_cell_iterators())
319 if (act_cell->coarsen_flag_set())
320 ++n_cells_to_coarsen;
322 ++n_cells_to_stay_or_refine;
324 Assert((n_cells_to_coarsen + n_cells_to_stay_or_refine) ==
325 dof_handler->get_triangulation().n_active_cells(),
328 unsigned int n_coarsen_fathers = 0;
329 for (
const auto &cell : dof_handler->cell_iterators())
330 if (!cell->is_active() && cell->child(0)->coarsen_flag_set())
333 (void)n_cells_to_coarsen;
338 std::vector<std::vector<types::global_dof_index>>(n_cells_to_stay_or_refine)
339 .
swap(indices_on_cell);
341 std::vector<std::vector<Vector<typename VectorType::value_type>>>(
343 std::vector<Vector<typename VectorType::value_type>>(in_size))
344 .swap(dof_values_on_cell);
347 std::vector<std::vector<bool>> restriction_is_additive;
351 restriction_is_additive);
356 unsigned int n_sr = 0, n_cf = 0;
357 for (
const auto &cell : dof_handler->cell_iterators())
360 if (cell->is_active() && !cell->coarsen_flag_set())
362 const unsigned int dofs_per_cell = cell->get_fe().n_dofs_per_cell();
363 indices_on_cell[n_sr].resize(dofs_per_cell);
368 cell->get_dof_indices(indices_on_cell[n_sr]);
369 cell_map[std::make_pair(cell->level(), cell->index())] =
370 Pointerstruct(&indices_on_cell[n_sr], cell->active_fe_index());
375 else if (cell->has_children() && cell->child(0)->coarsen_flag_set())
383 std::set<unsigned int> fe_indices_children;
384 for (
const auto &child : cell->child_iterators())
386 Assert(child->is_active() && child->coarsen_flag_set(),
387 typename ::Triangulation<
388 dim>::ExcInconsistentCoarseningFlags());
390 fe_indices_children.insert(child->active_fe_index());
394 const unsigned int target_fe_index =
395 dof_handler->get_fe_collection().find_dominated_fe_extended(
396 fe_indices_children, 0);
400 ExcNoDominatedFiniteElementOnChildren());
402 const unsigned int dofs_per_cell =
403 dof_handler->get_fe(target_fe_index).n_dofs_per_cell();
405 std::vector<Vector<typename VectorType::value_type>>(
407 .
swap(dof_values_on_cell[n_cf]);
415 for (
unsigned int j = 0; j < in_size; ++j)
416 cell->get_interpolated_dof_values(all_in[j],
417 dof_values_on_cell[n_cf][j],
419 cell_map[std::make_pair(cell->level(), cell->index())] =
427 prepared_for = coarsening_and_refinement;
446 const std::vector<VectorType> &all_in,
447 std::vector<VectorType> &all_out)
const
449 const unsigned int size = all_in.size();
451 Assert(prepared_for == coarsening_and_refinement, ExcNotPrepared());
453 for (
unsigned int i = 0; i < size; ++i)
454 Assert(all_in[i].size() == n_dofs_old,
456 for (
unsigned int i = 0; i < all_out.size(); ++i)
457 Assert(all_out[i].size() == dof_handler->n_dofs(),
459 for (
unsigned int i = 0; i < size; ++i)
460 for (
unsigned int j = 0; j < size; ++j)
461 Assert(&all_in[i] != &all_out[j],
462 ExcMessage(
"Vectors cannot be used as input and output"
463 " at the same time!"));
476 subdomain_modifier(dof_handler->get_triangulation());
479 std::vector<types::global_dof_index> dofs;
481 typename std::map<std::pair<unsigned int, unsigned int>,
483 cell_map_end = cell_map.end();
489 for (
const auto &cell : dof_handler->cell_iterators())
492 cell_map.find(std::make_pair(cell->level(), cell->index()));
494 if (pointerstruct != cell_map_end)
496 const std::vector<types::global_dof_index> *
const indexptr =
497 pointerstruct->second.indices_ptr;
499 const std::vector<Vector<typename VectorType::value_type>>
500 *
const valuesptr = pointerstruct->second.dof_values_ptr;
503 if (indexptr !=
nullptr)
507 const unsigned int old_fe_index =
508 pointerstruct->second.active_fe_index;
512 unsigned int in_size = indexptr->size();
513 for (
unsigned int j = 0; j < size; ++j)
515 tmp.
reinit(in_size,
true);
516 for (
unsigned int i = 0; i < in_size; ++i)
521 cell->set_dof_values_by_interpolation(tmp,
533 const unsigned int dofs_per_cell =
534 cell->get_fe().n_dofs_per_cell();
535 dofs.resize(dofs_per_cell);
538 cell->get_dof_indices(dofs);
541 for (
unsigned int j = 0; j < size; ++j)
548 const unsigned int active_fe_index = cell->active_fe_index();
549 if (active_fe_index != pointerstruct->second.active_fe_index)
551 const unsigned int old_index =
552 pointerstruct->second.active_fe_index;
554 interpolation_hp(active_fe_index, old_index);
557 if (interpolation_matrix.empty())
558 tmp.
reinit(dofs_per_cell,
false);
561 tmp.
reinit(dofs_per_cell,
true);
563 interpolation_matrix.
n());
565 interpolation_matrix.
vmult(tmp, (*valuesptr)[j]);
570 data = &(*valuesptr)[j];
573 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
587 for (
auto &vec : all_out)