17 #include <deal.II/base/config.h> 19 #ifdef DEAL_II_WITH_P4EST 21 # include <deal.II/distributed/solution_transfer.h> 22 # include <deal.II/distributed/tria.h> 24 # include <deal.II/dofs/dof_accessor.h> 25 # include <deal.II/dofs/dof_tools.h> 27 # include <deal.II/grid/tria_accessor.h> 28 # include <deal.II/grid/tria_iterator.h> 30 # include <deal.II/hp/dof_handler.h> 32 # include <deal.II/lac/block_vector.h> 33 # include <deal.II/lac/la_parallel_block_vector.h> 34 # include <deal.II/lac/la_parallel_vector.h> 35 # include <deal.II/lac/petsc_block_vector.h> 36 # include <deal.II/lac/petsc_vector.h> 37 # include <deal.II/lac/trilinos_parallel_block_vector.h> 38 # include <deal.II/lac/trilinos_vector.h> 39 # include <deal.II/lac/vector.h> 41 # include <functional> 43 DEAL_II_NAMESPACE_OPEN
49 template <
int dim,
typename VectorType,
typename DoFHandlerType>
51 const DoFHandlerType &dof)
52 : dof_handler(&dof, typeid(*this).name())
53 , handle(
numbers::invalid_unsigned_int)
56 (
dynamic_cast<const parallel::distributed::
57 Triangulation<dim, DoFHandlerType::space_dimension> *
>(
60 "parallel::distributed::SolutionTransfer requires a parallel::distributed::Triangulation object."));
65 template <
int dim,
typename VectorType,
typename DoFHandlerType>
69 const std::vector<const VectorType *> &all_in)
71 input_vectors = all_in;
72 register_data_attach();
77 template <
int dim,
typename VectorType,
typename DoFHandlerType>
85 DoFHandlerType::space_dimension
> *>(
87 *
>(&dof_handler->get_triangulation())));
94 std::placeholders::_1,
95 std::placeholders::_2),
96 DoFHandlerType::is_hp_dof_handler);
101 template <
int dim,
typename VectorType,
typename DoFHandlerType>
106 std::vector<const VectorType *> all_in(1, &in);
107 prepare_for_coarsening_and_refinement(all_in);
112 template <
int dim,
typename VectorType,
typename DoFHandlerType>
117 std::vector<const VectorType *> all_in(1, &in);
118 prepare_for_serialization(all_in);
123 template <
int dim,
typename VectorType,
typename DoFHandlerType>
128 prepare_for_coarsening_and_refinement(all_in);
133 template <
int dim,
typename VectorType,
typename DoFHandlerType>
136 const VectorType &in)
138 prepare_for_serialization(in);
143 template <
int dim,
typename VectorType,
typename DoFHandlerType>
146 const std::vector<const VectorType *> &all_in)
148 prepare_for_serialization(all_in);
153 template <
int dim,
typename VectorType,
typename DoFHandlerType>
158 std::vector<VectorType *> all_in(1, &in);
164 template <
int dim,
typename VectorType,
typename DoFHandlerType>
167 std::vector<VectorType *> &all_in)
169 register_data_attach();
172 input_vectors.resize(all_in.size());
178 template <
int dim,
typename VectorType,
typename DoFHandlerType>
181 std::vector<VectorType *> &all_out)
183 Assert(input_vectors.size() == all_out.size(),
190 DoFHandlerType::space_dimension
> *>(
192 *
>(&dof_handler->get_triangulation())));
200 std::placeholders::_1,
201 std::placeholders::_2,
202 std::placeholders::_3,
206 for (
typename std::vector<VectorType *>::iterator it = all_out.begin();
211 input_vectors.clear();
216 template <
int dim,
typename VectorType,
typename DoFHandlerType>
221 std::vector<VectorType *> all_out(1, &out);
222 interpolate(all_out);
227 template <
int dim,
typename VectorType,
typename DoFHandlerType>
231 cell_iterator &cell_,
233 DoFHandlerType::space_dimension>::CellStatus
236 typename DoFHandlerType::cell_iterator cell(*cell_, dof_handler);
239 std::vector<::Vector<typename VectorType::value_type>> dofvalues(
240 input_vectors.size());
242 if (DoFHandlerType::is_hp_dof_handler)
249 DoFHandlerType::space_dimension>::CELL_PERSIST:
252 DoFHandlerType::space_dimension>::CELL_REFINE:
254 fe_index = cell->future_fe_index();
260 DoFHandlerType::space_dimension>::CELL_COARSEN:
265 std::set<unsigned int> fe_indices_children;
266 for (
unsigned int child_index = 0;
267 child_index < GeometryInfo<dim>::max_children_per_cell;
269 fe_indices_children.insert(
270 cell->child(child_index)->future_fe_index());
272 fe_index = dof_handler->get_fe_collection()
273 .find_dominating_fe_extended(fe_indices_children,
279 "No FiniteElement has been found in your FECollection " 280 "that dominates all children of a cell you are trying " 291 const unsigned int dofs_per_cell =
292 dof_handler->get_fe(fe_index).dofs_per_cell;
294 auto it_input = input_vectors.cbegin();
295 auto it_output = dofvalues.begin();
296 for (; it_input != input_vectors.cend(); ++it_input, ++it_output)
298 it_output->reinit(dofs_per_cell);
299 cell->get_interpolated_dof_values(*(*it_input),
306 auto it_input = input_vectors.cbegin();
307 auto it_output = dofvalues.begin();
308 for (; it_input != input_vectors.cend(); ++it_input, ++it_output)
310 it_output->reinit(cell->get_fe().dofs_per_cell);
311 cell->get_interpolated_dof_values(*(*it_input), *it_output);
321 dofvalues, DoFHandlerType::is_hp_dof_handler);
326 template <
int dim,
typename VectorType,
typename DoFHandlerType>
330 cell_iterator &cell_,
332 DoFHandlerType::space_dimension>::CellStatus
334 const boost::iterator_range<std::vector<char>::const_iterator>
336 std::vector<VectorType *> &all_out)
338 typename DoFHandlerType::cell_iterator cell(*cell_, dof_handler);
340 const std::vector<::Vector<typename VectorType::value_type>>
342 std::vector<::Vector<typename VectorType::value_type>>>(
345 DoFHandlerType::is_hp_dof_handler);
350 if (DoFHandlerType::is_hp_dof_handler)
358 DoFHandlerType::space_dimension>::CELL_PERSIST:
361 DoFHandlerType::space_dimension>::CELL_COARSEN:
363 fe_index = cell->active_fe_index();
369 DoFHandlerType::space_dimension>::CELL_REFINE:
376 fe_index = cell->child(0)->active_fe_index();
377 for (
unsigned int child_index = 1;
378 child_index < GeometryInfo<dim>::max_children_per_cell;
380 Assert(cell->child(child_index)->active_fe_index() ==
393 for (
auto it_dofvalues = dofvalues.begin();
394 it_dofvalues != dofvalues.end();
397 dof_handler->get_fe(fe_index).dofs_per_cell ==
398 it_dofvalues->size(),
400 "The transferred data was packed with a different number of dofs than the" 401 "currently registered FE object assigned to the DoFHandler has."));
404 auto it_input = dofvalues.cbegin();
405 auto it_output = all_out.begin();
406 for (; it_input != dofvalues.cend(); ++it_input, ++it_output)
407 cell->set_dof_values_by_interpolation(*it_input,
415 for (
auto it_dofvalues = dofvalues.begin();
416 it_dofvalues != dofvalues.end();
419 cell->get_fe().dofs_per_cell == it_dofvalues->size(),
421 "The transferred data was packed with a different number of dofs than the" 422 "currently registered FE object assigned to the DoFHandler has."));
425 auto it_input = dofvalues.cbegin();
426 auto it_output = all_out.begin();
427 for (; it_input != dofvalues.cend(); ++it_input, ++it_output)
428 cell->set_dof_values_by_interpolation(*it_input, *(*it_output));
438 # include "solution_transfer.inst" 440 DEAL_II_NAMESPACE_CLOSE
void prepare_for_coarsening_and_refinement(const std::vector< const VectorType *> &all_in)
unsigned int register_data_attach(const std::function< std::vector< char >(const cell_iterator &, const CellStatus)> &pack_callback, const bool returns_variable_size_data)
static const unsigned int invalid_unsigned_int
std::vector< char > pack_callback(const typename Triangulation< dim, DoFHandlerType::space_dimension >::cell_iterator &cell, const typename Triangulation< dim, DoFHandlerType::space_dimension >::CellStatus status)
void deserialize(VectorType &in)
SolutionTransfer(const DoFHandlerType &dof)
void interpolate(std::vector< VectorType *> &all_out)
void prepare_for_serialization(const VectorType &in)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
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)
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
void prepare_serialization(const VectorType &in)
SmartPointer< const DoFHandlerType, SolutionTransfer< dim, VectorType, DoFHandlerType > > dof_handler
void register_data_attach()
T unpack(const std::vector< char > &buffer, const bool allow_compression=true)
void unpack_callback(const typename Triangulation< dim, DoFHandlerType::space_dimension >::cell_iterator &cell, const typename Triangulation< dim, DoFHandlerType::space_dimension >::CellStatus status, const boost::iterator_range< std::vector< char >::const_iterator > &data_range, std::vector< VectorType *> &all_out)
static ::ExceptionBase & ExcInternalError()