19#ifdef DEAL_II_WITH_P4EST
58 template <
typename value_type>
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)
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,
int spacedim>
120 const bool average_values)
121 : dof_handler(&dof, typeid(*this).name())
122 , average_values(average_values)
123 , handle(
numbers::invalid_unsigned_int)
130 "parallel::distributed::SolutionTransfer requires a parallel::distributed::Triangulation object."));
135 template <
int dim,
typename VectorType,
int spacedim>
139 const std::vector<const VectorType *> &all_in)
141 for (
unsigned int i = 0; i < all_in.size(); ++i)
142 Assert(all_in[i]->size() == dof_handler->n_dofs(),
145 input_vectors = all_in;
146 register_data_attach();
151 template <
int dim,
typename VectorType,
int spacedim>
159 &dof_handler->get_triangulation())));
162 handle =
tria->register_data_attach(
166 return this->pack_callback(cell_, status);
168 dof_handler->has_hp_capabilities());
173 template <
int dim,
typename VectorType,
int spacedim>
178 std::vector<const VectorType *> all_in(1, &in);
179 prepare_for_coarsening_and_refinement(all_in);
184 template <
int dim,
typename VectorType,
int spacedim>
187 const VectorType &in)
189 std::vector<const VectorType *> all_in(1, &in);
190 prepare_for_serialization(all_in);
195 template <
int dim,
typename VectorType,
int spacedim>
198 const std::vector<const VectorType *> &all_in)
200 prepare_for_coarsening_and_refinement(all_in);
205 template <
int dim,
typename VectorType,
int spacedim>
209 std::vector<VectorType *> all_in(1, &in);
215 template <
int dim,
typename VectorType,
int spacedim>
218 std::vector<VectorType *> &all_in)
220 register_data_attach();
223 input_vectors.resize(all_in.size());
229 template <
int dim,
typename VectorType,
int spacedim>
232 std::vector<VectorType *> &all_out)
234 Assert(input_vectors.size() == all_out.size(),
236 for (
unsigned int i = 0; i < all_out.size(); ++i)
237 Assert(all_out[i]->size() == dof_handler->n_dofs(),
244 &dof_handler->get_triangulation())));
248 for (
const auto vec : all_out)
255 valence.reinit(*all_out[0]);
257 tria->notify_ready_to_unpack(
259 [
this, &all_out, &valence](
262 const boost::iterator_range<std::vector<char>::const_iterator>
264 this->unpack_callback(cell_, status, data_range, all_out, valence);
270 using Number =
typename VectorType::value_type;
272 for (
const auto i : valence.locally_owned_elements())
273 valence[i] = (
static_cast<Number
>(valence[i]) == Number() ?
275 (Number(1.0) /
static_cast<Number
>(valence[i])));
278 for (
const auto vec : all_out)
287 for (
const auto vec : all_out)
291 input_vectors.
clear();
296 template <
int dim,
typename VectorType,
int spacedim>
300 std::vector<VectorType *> all_out(1, &out);
301 interpolate(all_out);
306 template <
int dim,
typename VectorType,
int spacedim>
316 std::vector<::Vector<typename VectorType::value_type>> dof_values(
317 input_vectors.size());
319 unsigned int fe_index = 0;
320 if (dof_handler->has_hp_capabilities())
325 spacedim>::CELL_PERSIST:
327 spacedim>::CELL_REFINE:
329 fe_index = cell->future_fe_index();
334 spacedim>::CELL_COARSEN:
340 for (
const auto &child : cell->child_iterators())
341 Assert(child->is_active() && child->coarsen_flag_set(),
342 typename ::Triangulation<
343 dim>::ExcInconsistentCoarseningFlags());
346 fe_index = ::internal::hp::DoFHandlerImplementation::
347 dominated_future_fe_on_children<dim, spacedim>(cell);
357 const unsigned int dofs_per_cell =
358 dof_handler->get_fe(fe_index).n_dofs_per_cell();
360 if (dofs_per_cell == 0)
361 return std::vector<char>();
363 auto it_input = input_vectors.cbegin();
364 auto it_output = dof_values.begin();
365 for (; it_input != input_vectors.cend(); ++it_input, ++it_output)
367 it_output->reinit(dofs_per_cell);
368 cell->get_interpolated_dof_values(*(*it_input), *it_output, fe_index);
371 return pack_dof_values<typename VectorType::value_type>(dof_values,
377 template <
int dim,
typename VectorType,
int spacedim>
382 const boost::iterator_range<std::vector<char>::const_iterator>
384 std::vector<VectorType *> &all_out,
385 VectorType & valence)
390 unsigned int fe_index = 0;
391 if (dof_handler->has_hp_capabilities())
396 spacedim>::CELL_PERSIST:
398 spacedim>::CELL_COARSEN:
400 fe_index = cell->active_fe_index();
405 spacedim>::CELL_REFINE:
412 fe_index = cell->child(0)->active_fe_index();
413 for (
unsigned int child_index = 1;
414 child_index < cell->n_children();
416 Assert(cell->child(child_index)->active_fe_index() ==
428 const unsigned int dofs_per_cell =
429 dof_handler->get_fe(fe_index).n_dofs_per_cell();
431 if (dofs_per_cell == 0)
434 const std::vector<::Vector<typename VectorType::value_type>>
436 unpack_dof_values<typename VectorType::value_type>(data_range,
444 for (
auto it_dof_values = dof_values.begin();
445 it_dof_values != dof_values.end();
448 dofs_per_cell == it_dof_values->size(),
450 "The transferred data was packed with a different number of dofs than the "
451 "currently registered FE object assigned to the DoFHandler has."));
454 auto it_input = dof_values.cbegin();
455 auto it_output = all_out.begin();
456 for (; it_input != dof_values.cend(); ++it_input, ++it_output)
458 cell->distribute_local_to_global_by_interpolation(*it_input,
462 cell->set_dof_values_by_interpolation(*it_input,
472 cell->distribute_local_to_global_by_interpolation(ones,
482# include "solution_transfer.inst"
void unpack_callback(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status, const boost::iterator_range< std::vector< char >::const_iterator > &data_range, std::vector< VectorType * > &all_out, VectorType &valence)
std::vector< char > pack_callback(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status)
void register_data_attach()
SmartPointer< const DoFHandler< dim, spacedim >, SolutionTransfer< dim, VectorType, spacedim > > dof_handler
void deserialize(VectorType &in)
void prepare_for_coarsening_and_refinement(const std::vector< const VectorType * > &all_in)
void prepare_for_serialization(const VectorType &in)
void interpolate(std::vector< VectorType * > &all_out)
SolutionTransfer(const DoFHandler< dim, spacedim > &dof_handler, const bool average_values=false)
typename ::Triangulation< dim, spacedim >::CellStatus CellStatus
#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)
typename ActiveSelector::cell_iterator cell_iterator
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
const ::Triangulation< dim, spacedim > & tria