19 #ifdef DEAL_II_WITH_P4EST 41 # include <functional> 52 template <
int dim,
int spacedim>
55 : dof_handler(&dof, typeid(*this).name())
65 "parallel::distributed::ErrorPredictor requires a parallel::distributed::Triangulation object."));
70 template <
int dim,
int spacedim>
87 template <
int dim,
int spacedim>
108 template <
int dim,
int spacedim>
116 std::vector<const Vector<float> *> all_in(1, &in);
122 template <
int dim,
int spacedim>
141 const boost::iterator_range<std::vector<char>::const_iterator>
146 for (
const auto &out : all_out)
154 template <
int dim,
int spacedim>
158 std::vector<Vector<float> *> all_out(1, &out);
164 template <
int dim,
int spacedim>
176 auto predicted_error_it = predicted_errors.begin();
179 ++predicted_error_it, ++estimated_error_it)
183 spacedim>::CELL_PERSIST:
185 if (cell->future_fe_index_set())
187 const int degree_difference =
188 dof_handler->get_fe_collection()[cell->future_fe_index()]
192 *predicted_error_it =
193 (**estimated_error_it)[cell->active_cell_index()] *
194 std::pow(
gamma_p, degree_difference);
198 *predicted_error_it =
199 (**estimated_error_it)[cell->active_cell_index()] *
206 spacedim>::CELL_REFINE:
210 const unsigned int future_fe_degree =
211 dof_handler->get_fe_collection()[cell->future_fe_index()]
214 *predicted_error_it =
215 (**estimated_error_it)[cell->active_cell_index()] *
216 (
gamma_h * std::pow(.5, future_fe_degree));
220 if (cell->future_fe_index_set())
221 *predicted_error_it *=
223 static_cast<int>(future_fe_degree -
230 spacedim>::CELL_COARSEN:
236 std::set<unsigned int> fe_indices_children;
237 for (
unsigned int child_index = 0;
238 child_index < cell->n_children();
241 const auto child = cell->child(child_index);
242 Assert(child->is_active() && child->coarsen_flag_set(),
244 dim>::ExcInconsistentCoarseningFlags());
246 fe_indices_children.insert(child->future_fe_index());
249 const unsigned int future_fe_index =
250 dof_handler->get_fe_collection().find_dominated_fe_extended(
251 fe_indices_children, 0);
253 const unsigned int future_fe_degree =
254 dof_handler->get_fe_collection()[future_fe_index].degree;
258 float sqrsum_of_predicted_errors = 0.;
259 float predicted_error = 0.;
260 int degree_difference = 0;
261 for (
unsigned int child_index = 0;
262 child_index < cell->n_children();
265 const auto child = cell->child(child_index);
268 (**estimated_error_it)[child->active_cell_index()] /
269 (
gamma_h * std::pow(.5, future_fe_degree));
272 future_fe_degree - child->get_fe().degree;
274 if (degree_difference != 0)
275 predicted_error *= std::pow(
gamma_p, degree_difference);
277 sqrsum_of_predicted_errors +=
278 predicted_error * predicted_error;
280 *predicted_error_it = std::sqrt(sqrsum_of_predicted_errors);
300 template <
int dim,
int spacedim>
305 const boost::iterator_range<std::vector<char>::const_iterator>
309 std::vector<float> predicted_errors;
311 if (all_out.size() == 1)
312 predicted_errors.push_back(
313 Utilities::unpack<float>(data_range.begin(),
318 Utilities::unpack<std::vector<float>>(data_range.begin(),
324 auto it_input = predicted_errors.cbegin();
325 auto it_output = all_out.begin();
326 for (; it_input != predicted_errors.cend(); ++it_input, ++it_output)
330 spacedim>::CELL_PERSIST:
332 spacedim>::CELL_COARSEN:
333 (**it_output)[cell->active_cell_index()] = *it_input;
338 spacedim>::CELL_REFINE:
339 for (
unsigned int child_index = 0;
340 child_index < cell->n_children();
342 (**it_output)[cell->child(child_index)->active_cell_index()] =
343 (*it_input) / std::sqrt(cell->n_children());
356 # include "error_predictor.inst"
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
void register_data_attach()
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< Vector< float > *> &all_out)
std::vector< char > pack_callback(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status)
SmartPointer< const hp::DoFHandler< dim, spacedim >, ErrorPredictor< dim, spacedim > > dof_handler
static ::ExceptionBase & ExcMessage(std::string arg1)
typename ActiveSelector::cell_iterator cell_iterator
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define DEAL_II_NAMESPACE_CLOSE
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< const Vector< float > * > error_indicators
TriangulationBase< dim, spacedim > Triangulation
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
ErrorPredictor(const hp::DoFHandler< dim, spacedim > &dof)
void prepare_for_coarsening_and_refinement(const std::vector< const Vector< float > *> &all_in, const double gamma_p=std::sqrt(0.4), const double gamma_h=2., const double gamma_n=1.)
#define DEAL_II_NAMESPACE_OPEN
const FiniteElement< dim, spacedim > & get_fe(const unsigned int index) const
void unpack(std::vector< Vector< float > *> &all_out)
static ::ExceptionBase & ExcInternalError()