18#ifdef DEAL_II_WITH_P4EST
55 template <
typename value_type>
58 const unsigned int dofs_per_cell)
60 for (
const auto &values : dof_values)
66 const std::size_t bytes_per_entry =
sizeof(value_type) * dofs_per_cell;
68 std::vector<char> buffer(dof_values.size() * bytes_per_entry);
69 for (
unsigned int i = 0; i < dof_values.size(); ++i)
70 std::memcpy(&buffer[i * bytes_per_entry],
82 template <
typename value_type>
83 std::vector<Vector<value_type>>
85 const boost::iterator_range<std::vector<char>::const_iterator> &data_range,
86 const unsigned int dofs_per_cell)
88 const std::size_t bytes_per_entry =
sizeof(value_type) * dofs_per_cell;
89 const unsigned int n_elements = data_range.size() / bytes_per_entry;
93 std::vector<Vector<value_type>> unpacked_data;
94 unpacked_data.reserve(n_elements);
95 for (
unsigned int i = 0; i < n_elements; ++i)
98 std::memcpy(&dof_values(0),
99 &(*std::next(data_range.begin(), i * bytes_per_entry)),
101 unpacked_data.emplace_back(std::move(dof_values));
104 return unpacked_data;
112 namespace distributed
114 template <
int dim,
typename VectorType,
int spacedim>
117 const bool average_values)
118 : dof_handler(&dof, typeid(*this).name())
119 , average_values(average_values)
120 , handle(
numbers::invalid_unsigned_int)
127 "parallel::distributed::SolutionTransfer requires a parallel::distributed::Triangulation object."));
132 template <
int dim,
typename VectorType,
int spacedim>
136 const std::vector<const VectorType *> &all_in)
138 for (
unsigned int i = 0; i < all_in.size(); ++i)
139 Assert(all_in[i]->size() == dof_handler->n_dofs(),
142 input_vectors = all_in;
143 register_data_attach();
148 template <
int dim,
typename VectorType,
int spacedim>
156 &dof_handler->get_triangulation())));
160 ExcMessage(
"You can only add one solution per "
161 "SolutionTransfer object."));
167 return this->pack_callback(cell_, status);
169 dof_handler->has_hp_capabilities());
174 template <
int dim,
typename VectorType,
int spacedim>
179 std::vector<const VectorType *> all_in(1, &in);
180 prepare_for_coarsening_and_refinement(all_in);
185 template <
int dim,
typename VectorType,
int spacedim>
188 const VectorType &in)
190 std::vector<const VectorType *> all_in(1, &in);
191 prepare_for_serialization(all_in);
196 template <
int dim,
typename VectorType,
int spacedim>
199 const std::vector<const VectorType *> &all_in)
201 prepare_for_coarsening_and_refinement(all_in);
206 template <
int dim,
typename VectorType,
int spacedim>
210 std::vector<VectorType *> all_in(1, &in);
216 template <
int dim,
typename VectorType,
int spacedim>
219 std::vector<VectorType *> &all_in)
221 register_data_attach();
224 input_vectors.resize(all_in.size());
230 template <
int dim,
typename VectorType,
int spacedim>
233 std::vector<VectorType *> &all_out)
235 Assert(input_vectors.size() == all_out.size(),
237 for (
unsigned int i = 0; i < all_out.size(); ++i)
238 Assert(all_out[i]->size() == dof_handler->n_dofs(),
245 &dof_handler->get_triangulation())));
249 for (
auto *
const vec : all_out)
256 valence.reinit(*all_out[0]);
260 [
this, &all_out, &valence](
263 const boost::iterator_range<std::vector<char>::const_iterator>
265 this->unpack_callback(cell_, status, data_range, all_out, valence);
271 using Number =
typename VectorType::value_type;
273 for (
const auto i : valence.locally_owned_elements())
274 valence[i] = (
static_cast<Number
>(valence[i]) == Number() ?
276 (Number(1.0) /
static_cast<Number
>(valence[i])));
279 for (
auto *
const vec : all_out)
288 for (
auto *
const vec : all_out)
292 input_vectors.clear();
298 template <
int dim,
typename VectorType,
int spacedim>
302 std::vector<VectorType *> all_out(1, &out);
303 interpolate(all_out);
308 template <
int dim,
typename VectorType,
int spacedim>
318 std::vector<::Vector<typename VectorType::value_type>> dof_values(
319 input_vectors.size());
321 unsigned int fe_index = 0;
322 if (dof_handler->has_hp_capabilities())
329 fe_index = cell->future_fe_index();
339 for (
const auto &child : cell->child_iterators())
340 Assert(child->is_active() && child->coarsen_flag_set(),
341 typename ::Triangulation<
342 dim>::ExcInconsistentCoarseningFlags());
356 const unsigned int dofs_per_cell =
357 dof_handler->get_fe(fe_index).n_dofs_per_cell();
359 if (dofs_per_cell == 0)
360 return std::vector<char>();
362 auto it_input = input_vectors.cbegin();
363 auto it_output = dof_values.begin();
364 for (; it_input != input_vectors.cend(); ++it_input, ++it_output)
366 it_output->reinit(dofs_per_cell);
367 cell->get_interpolated_dof_values(*(*it_input), *it_output, fe_index);
370 return pack_dof_values<typename VectorType::value_type>(dof_values,
376 template <
int dim,
typename VectorType,
int spacedim>
381 const boost::iterator_range<std::vector<char>::const_iterator>
383 std::vector<VectorType *> &all_out,
389 unsigned int fe_index = 0;
390 if (dof_handler->has_hp_capabilities())
397 fe_index = cell->active_fe_index();
408 fe_index = cell->child(0)->active_fe_index();
409 for (
unsigned int child_index = 1;
410 child_index < cell->n_children();
412 Assert(cell->child(child_index)->active_fe_index() ==
424 const unsigned int dofs_per_cell =
425 dof_handler->get_fe(fe_index).n_dofs_per_cell();
427 if (dofs_per_cell == 0)
430 const std::vector<::Vector<typename VectorType::value_type>>
432 unpack_dof_values<typename VectorType::value_type>(data_range,
440 for (
auto it_dof_values = dof_values.begin();
441 it_dof_values != dof_values.end();
444 dofs_per_cell == it_dof_values->size(),
446 "The transferred data was packed with a different number of dofs than the "
447 "currently registered FE object assigned to the DoFHandler has."));
450 auto it_input = dof_values.cbegin();
451 auto it_output = all_out.begin();
452 for (; it_input != dof_values.cend(); ++it_input, ++it_output)
454 cell->distribute_local_to_global_by_interpolation(*it_input,
458 cell->set_dof_values_by_interpolation(*it_input,
468 cell->distribute_local_to_global_by_interpolation(ones,
478# include "solution_transfer.inst"
@ children_will_be_coarsened
unsigned int register_data_attach(const std::function< std::vector< char >(const cell_iterator &, const ::CellStatus)> &pack_callback, const bool returns_variable_size_data)
void notify_ready_to_unpack(const unsigned int handle, const std::function< void(const cell_iterator &, const ::CellStatus, const boost::iterator_range< std::vector< char >::const_iterator > &)> &unpack_callback)
std::vector< char > pack_callback(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const CellStatus status)
void unpack_callback(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const CellStatus status, const boost::iterator_range< std::vector< char >::const_iterator > &data_range, std::vector< VectorType * > &all_out, VectorType &valence)
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)
#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
#define DEAL_II_ASSERT_UNREACHABLE()
unsigned int dominated_future_fe_on_children(const typename DoFHandler< dim, spacedim >::cell_iterator &parent)
static const unsigned int invalid_unsigned_int