19 #ifdef DEAL_II_WITH_P4EST
41 # include <functional>
58 template <
typename value_type>
60 pack_dof_values(std::vector<Vector<value_type>> &dof_values,
61 const unsigned int dofs_per_cell)
63 for (
const auto &values : dof_values)
69 const std::size_t bytes_per_entry =
sizeof(
value_type) * dofs_per_cell;
71 std::vector<char> buffer(dof_values.size() * bytes_per_entry);
72 for (
unsigned int i = 0; i < dof_values.size(); ++i)
73 std::memcpy(&buffer[i * bytes_per_entry],
85 template <
typename value_type>
86 std::vector<Vector<value_type>>
88 const boost::iterator_range<std::vector<char>::const_iterator> &data_range,
89 const unsigned int dofs_per_cell)
91 const std::size_t bytes_per_entry =
sizeof(
value_type) * dofs_per_cell;
92 const unsigned int n_elements = data_range.size() / bytes_per_entry;
96 std::vector<Vector<value_type>> unpacked_data;
97 unpacked_data.reserve(n_elements);
98 for (
unsigned int i = 0; i < n_elements; ++i)
100 Vector<value_type> dof_values(dofs_per_cell);
101 std::memcpy(&dof_values(0),
102 &(*std::next(data_range.begin(), i * bytes_per_entry)),
104 unpacked_data.emplace_back(std::move(dof_values));
107 return unpacked_data;
115 namespace distributed
117 template <
int dim,
typename VectorType,
typename DoFHandlerType>
119 const DoFHandlerType &dof)
120 : dof_handler(&dof, typeid(*this).name())
124 (
dynamic_cast<const parallel::distributed::
125 Triangulation<dim, DoFHandlerType::space_dimension> *
>(
128 "parallel::distributed::SolutionTransfer requires a parallel::distributed::Triangulation object."));
133 template <
int dim,
typename VectorType,
typename DoFHandlerType>
137 const std::vector<const VectorType *> &all_in)
139 input_vectors = all_in;
140 register_data_attach();
145 template <
int dim,
typename VectorType,
typename DoFHandlerType>
153 DoFHandlerType::space_dimension
> *>(
155 *
>(&dof_handler->get_triangulation())));
161 cell_iterator &cell_,
163 CellStatus status) {
return this->pack_callback(cell_, status); },
164 DoFHandlerType::is_hp_dof_handler);
169 template <
int dim,
typename VectorType,
typename DoFHandlerType>
174 std::vector<const VectorType *> all_in(1, &in);
175 prepare_for_coarsening_and_refinement(all_in);
180 template <
int dim,
typename VectorType,
typename DoFHandlerType>
185 std::vector<const VectorType *> all_in(1, &in);
186 prepare_for_serialization(all_in);
191 template <
int dim,
typename VectorType,
typename DoFHandlerType>
196 prepare_for_coarsening_and_refinement(all_in);
201 template <
int dim,
typename VectorType,
typename DoFHandlerType>
206 prepare_for_serialization(in);
211 template <
int dim,
typename VectorType,
typename DoFHandlerType>
214 const std::vector<const VectorType *> &all_in)
216 prepare_for_serialization(all_in);
221 template <
int dim,
typename VectorType,
typename DoFHandlerType>
226 std::vector<VectorType *> all_in(1, &in);
232 template <
int dim,
typename VectorType,
typename DoFHandlerType>
235 std::vector<VectorType *> &all_in)
237 register_data_attach();
240 input_vectors.resize(all_in.size());
246 template <
int dim,
typename VectorType,
typename DoFHandlerType>
249 std::vector<VectorType *> &all_out)
251 Assert(input_vectors.size() == all_out.size(),
258 DoFHandlerType::space_dimension
> *>(
260 *
>(&dof_handler->get_triangulation())));
267 cell_iterator &cell_,
270 const boost::iterator_range<std::vector<char>::const_iterator>
272 this->unpack_callback(cell_, status, data_range, all_out);
275 for (
typename std::vector<VectorType *>::iterator it = all_out.begin();
280 input_vectors.clear();
285 template <
int dim,
typename VectorType,
typename DoFHandlerType>
290 std::vector<VectorType *> all_out(1, &out);
296 template <
int dim,
typename VectorType,
typename DoFHandlerType>
300 cell_iterator &cell_,
302 DoFHandlerType::space_dimension>::CellStatus
305 typename DoFHandlerType::cell_iterator cell(*cell_, dof_handler);
308 std::vector<::Vector<typename VectorType::value_type>> dof_values(
309 input_vectors.size());
311 unsigned int fe_index = 0;
312 if (DoFHandlerType::is_hp_dof_handler)
318 DoFHandlerType::space_dimension>::CELL_PERSIST:
321 DoFHandlerType::space_dimension>::CELL_REFINE:
323 fe_index = cell->future_fe_index();
329 DoFHandlerType::space_dimension>::CELL_COARSEN:
334 std::set<unsigned int> fe_indices_children;
335 for (
unsigned int child_index = 0;
336 child_index < cell->n_children();
339 const auto &child = cell->child(child_index);
340 Assert(child->is_active() && child->coarsen_flag_set(),
342 dim>::ExcInconsistentCoarseningFlags());
344 fe_indices_children.insert(child->future_fe_index());
349 dof_handler->get_fe_collection().find_dominated_fe_extended(
350 fe_indices_children, 0);
353 typename ::hp::FECollection<
354 dim>::ExcNoDominatedFiniteElementAmongstChildren());
365 const unsigned int dofs_per_cell =
366 dof_handler->get_fe(fe_index).dofs_per_cell;
368 auto it_input = input_vectors.cbegin();
369 auto it_output = dof_values.begin();
370 for (; it_input != input_vectors.cend(); ++it_input, ++it_output)
372 it_output->reinit(dofs_per_cell);
373 cell->get_interpolated_dof_values(*(*it_input), *it_output, fe_index);
376 return pack_dof_values<typename VectorType::value_type>(dof_values,
382 template <
int dim,
typename VectorType,
typename DoFHandlerType>
386 cell_iterator &cell_,
388 DoFHandlerType::space_dimension>::CellStatus
390 const boost::iterator_range<std::vector<char>::const_iterator>
392 std::vector<VectorType *> &all_out)
394 typename DoFHandlerType::cell_iterator cell(*cell_, dof_handler);
396 unsigned int fe_index = 0;
397 if (DoFHandlerType::is_hp_dof_handler)
403 DoFHandlerType::space_dimension>::CELL_PERSIST:
406 DoFHandlerType::space_dimension>::CELL_COARSEN:
408 fe_index = cell->active_fe_index();
414 DoFHandlerType::space_dimension>::CELL_REFINE:
421 fe_index = cell->child(0)->active_fe_index();
422 for (
unsigned int child_index = 1;
423 child_index < cell->n_children();
425 Assert(cell->child(child_index)->active_fe_index() ==
437 const unsigned int dofs_per_cell =
438 dof_handler->get_fe(fe_index).dofs_per_cell;
440 const std::vector<::Vector<typename VectorType::value_type>>
442 unpack_dof_values<typename VectorType::value_type>(data_range,
450 for (
auto it_dof_values = dof_values.begin();
451 it_dof_values != dof_values.end();
454 dofs_per_cell == it_dof_values->size(),
456 "The transferred data was packed with a different number of dofs than the "
457 "currently registered FE object assigned to the DoFHandler has."));
460 auto it_input = dof_values.cbegin();
461 auto it_output = all_out.begin();
462 for (; it_input != dof_values.cend(); ++it_input, ++it_output)
463 cell->set_dof_values_by_interpolation(*it_input,
472 # include "solution_transfer.inst"