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>
78 error_indicators = all_in;
79 this->gamma_p = gamma_p;
80 this->gamma_h = gamma_h;
81 this->gamma_n = gamma_n;
82 register_data_attach();
87 template <
int dim,
int spacedim>
95 &dof_handler->get_triangulation())));
101 return this->pack_callback(cell, status);
108 template <
int dim,
int spacedim>
112 const double gamma_p,
113 const double gamma_h,
114 const double gamma_n)
116 std::vector<const Vector<float> *> all_in(1, &in);
117 prepare_for_coarsening_and_refinement(all_in, gamma_p, gamma_h, gamma_n);
122 template <
int dim,
int spacedim>
126 Assert(error_indicators.size() == all_out.size(),
133 &dof_handler->get_triangulation())));
141 const boost::iterator_range<std::vector<char>::const_iterator>
143 this->unpack_callback(cell, status, data_range, all_out);
146 for (
const auto &out : all_out)
149 error_indicators.clear();
154 template <
int dim,
int spacedim>
158 std::vector<Vector<float> *> all_out(1, &out);
164 template <
int dim,
int spacedim>
174 std::vector<float> predicted_errors(error_indicators.size());
176 auto predicted_error_it = predicted_errors.begin();
177 auto estimated_error_it = error_indicators.cbegin();
178 for (; estimated_error_it != error_indicators.cend();
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);
291 if (error_indicators.size() == 1)
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"