19#ifdef DEAL_II_WITH_P4EST
56 template <
typename value_type>
59 const unsigned int dofs_per_cell)
61 for (
const auto &values : dof_values)
67 const std::size_t bytes_per_entry =
sizeof(value_type) * dofs_per_cell;
69 std::vector<char> buffer(dof_values.size() * bytes_per_entry);
70 for (
unsigned int i = 0; i < dof_values.size(); ++i)
71 std::memcpy(&buffer[i * bytes_per_entry],
83 template <
typename value_type>
84 std::vector<Vector<value_type>>
86 const boost::iterator_range<std::vector<char>::const_iterator> &data_range,
87 const unsigned int dofs_per_cell)
89 const std::size_t bytes_per_entry =
sizeof(value_type) * dofs_per_cell;
90 const unsigned int n_elements = data_range.size() / bytes_per_entry;
94 std::vector<Vector<value_type>> unpacked_data;
95 unpacked_data.reserve(n_elements);
96 for (
unsigned int i = 0; i < n_elements; ++i)
99 std::memcpy(&dof_values(0),
100 &(*std::next(data_range.begin(), i * bytes_per_entry)),
102 unpacked_data.emplace_back(std::move(dof_values));
105 return unpacked_data;
113 namespace distributed
115 template <
int dim,
typename VectorType,
int spacedim>
118 const bool average_values)
119 : dof_handler(&dof, typeid(*this).name())
120 , average_values(average_values)
121 , handle(
numbers::invalid_unsigned_int)
128 "parallel::distributed::SolutionTransfer requires a parallel::distributed::Triangulation object."));
133 template <
int dim,
typename VectorType,
int spacedim>
137 const std::vector<const VectorType *> &all_in)
139 for (
unsigned int i = 0; i < all_in.size(); ++i)
140 Assert(all_in[i]->size() == dof_handler->n_dofs(),
143 input_vectors = all_in;
144 register_data_attach();
149 template <
int dim,
typename VectorType,
int spacedim>
157 &dof_handler->get_triangulation())));
161 ExcMessage(
"You can only add one solution per "
162 "SolutionTransfer object."));
164 handle =
tria->register_data_attach(
168 return this->pack_callback(cell_, status);
170 dof_handler->has_hp_capabilities());
175 template <
int dim,
typename VectorType,
int spacedim>
180 std::vector<const VectorType *> all_in(1, &in);
181 prepare_for_coarsening_and_refinement(all_in);
186 template <
int dim,
typename VectorType,
int spacedim>
189 const VectorType &in)
191 std::vector<const VectorType *> all_in(1, &in);
192 prepare_for_serialization(all_in);
197 template <
int dim,
typename VectorType,
int spacedim>
200 const std::vector<const VectorType *> &all_in)
202 prepare_for_coarsening_and_refinement(all_in);
207 template <
int dim,
typename VectorType,
int spacedim>
211 std::vector<VectorType *> all_in(1, &in);
217 template <
int dim,
typename VectorType,
int spacedim>
220 std::vector<VectorType *> &all_in)
222 register_data_attach();
225 input_vectors.resize(all_in.size());
231 template <
int dim,
typename VectorType,
int spacedim>
234 std::vector<VectorType *> &all_out)
236 Assert(input_vectors.size() == all_out.size(),
238 for (
unsigned int i = 0; i < all_out.size(); ++i)
239 Assert(all_out[i]->size() == dof_handler->n_dofs(),
246 &dof_handler->get_triangulation())));
250 for (
const auto vec : all_out)
257 valence.reinit(*all_out[0]);
259 tria->notify_ready_to_unpack(
261 [
this, &all_out, &valence](
264 const boost::iterator_range<std::vector<char>::const_iterator>
266 this->unpack_callback(cell_, status, data_range, all_out, valence);
272 using Number =
typename VectorType::value_type;
274 for (
const auto i : valence.locally_owned_elements())
275 valence[i] = (
static_cast<Number
>(valence[i]) == Number() ?
277 (Number(1.0) /
static_cast<Number
>(valence[i])));
280 for (
const auto vec : all_out)
289 for (
const auto vec : all_out)
293 input_vectors.
clear();
299 template <
int dim,
typename VectorType,
int spacedim>
303 std::vector<VectorType *> all_out(1, &out);
304 interpolate(all_out);
309 template <
int dim,
typename VectorType,
int spacedim>
319 std::vector<::Vector<typename VectorType::value_type>> dof_values(
320 input_vectors.size());
322 unsigned int fe_index = 0;
323 if (dof_handler->has_hp_capabilities())
328 spacedim>::CELL_PERSIST:
330 spacedim>::CELL_REFINE:
332 fe_index = cell->future_fe_index();
337 spacedim>::CELL_COARSEN:
343 for (
const auto &child : cell->child_iterators())
344 Assert(child->is_active() && child->coarsen_flag_set(),
345 typename ::Triangulation<
346 dim>::ExcInconsistentCoarseningFlags());
349 fe_index = ::internal::hp::DoFHandlerImplementation::
350 dominated_future_fe_on_children<dim, spacedim>(cell);
360 const unsigned int dofs_per_cell =
361 dof_handler->get_fe(fe_index).n_dofs_per_cell();
363 if (dofs_per_cell == 0)
364 return std::vector<char>();
366 auto it_input = input_vectors.cbegin();
367 auto it_output = dof_values.begin();
368 for (; it_input != input_vectors.cend(); ++it_input, ++it_output)
370 it_output->reinit(dofs_per_cell);
371 cell->get_interpolated_dof_values(*(*it_input), *it_output, fe_index);
374 return pack_dof_values<typename VectorType::value_type>(dof_values,
380 template <
int dim,
typename VectorType,
int spacedim>
385 const boost::iterator_range<std::vector<char>::const_iterator>
387 std::vector<VectorType *> &all_out,
388 VectorType & valence)
393 unsigned int fe_index = 0;
394 if (dof_handler->has_hp_capabilities())
399 spacedim>::CELL_PERSIST:
401 spacedim>::CELL_COARSEN:
403 fe_index = cell->active_fe_index();
408 spacedim>::CELL_REFINE:
415 fe_index = cell->child(0)->active_fe_index();
416 for (
unsigned int child_index = 1;
417 child_index < cell->n_children();
419 Assert(cell->child(child_index)->active_fe_index() ==
431 const unsigned int dofs_per_cell =
432 dof_handler->get_fe(fe_index).n_dofs_per_cell();
434 if (dofs_per_cell == 0)
437 const std::vector<::Vector<typename VectorType::value_type>>
439 unpack_dof_values<typename VectorType::value_type>(data_range,
447 for (
auto it_dof_values = dof_values.begin();
448 it_dof_values != dof_values.end();
451 dofs_per_cell == it_dof_values->size(),
453 "The transferred data was packed with a different number of dofs than the "
454 "currently registered FE object assigned to the DoFHandler has."));
457 auto it_input = dof_values.cbegin();
458 auto it_output = all_out.begin();
459 for (; it_input != dof_values.cend(); ++it_input, ++it_output)
461 cell->distribute_local_to_global_by_interpolation(*it_input,
465 cell->set_dof_values_by_interpolation(*it_input,
475 cell->distribute_local_to_global_by_interpolation(ones,
485# 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
static const unsigned int invalid_unsigned_int
const ::Triangulation< dim, spacedim > & tria