33 #ifndef __H__UG_DISC__ERROR_INDICATOR_UTIL__
34 #define __H__UG_DISC__ERROR_INDICATOR_UTIL__
52 template<
typename TElem>
63 max = 0.0, min = std::numeric_limits<number>::max();
69 const_iterator iter = dd->template begin<TElem>();
70 const_iterator iterEnd = dd->template end<TElem>();
73 for (; iter != iterEnd; ++iter)
78 const number elemEta2 = aaError2[elem];
82 if (aaError2[elem] < 0)
UG_THROW(
"error value invalid!");
85 const number elemEta = sqrt(aaError2[elem]);
88 if (elemEta > max) max = elemEta;
89 if (elemEta < min) min = elemEta;
104 numElemLocal = numElem;
117 UG_LOG(
" +++++ Error indicator on " << numElem <<
" elements +++++\n");
118 UG_LOG(
" +++ Element errors: maxEta=" << max <<
", minEta="
119 << min <<
", sumEta=" << sum <<
", sumEtaSq=" << errSq <<
".\n");
121 return (sum/numElem);
133 template<
typename TElem>
144 max = 0.0, min = std::numeric_limits<number>::max();
149 const_iterator iter = dd->template begin<TElem>();
150 const_iterator iterEnd = dd->template end<TElem>();
153 for (; iter != iterEnd; ++iter)
160 if (aaError[elem] < 0)
continue;
163 if (aaError[elem] > max) max = aaError[elem];
164 if (aaError[elem] < min) min = aaError[elem];
167 totalErr += aaError[elem];
174 totalErrLocal = totalErr;
175 numElemLocal = numElem;
187 UG_LOG(
" +++++ Error indicator on " << numElem <<
" elements +++++\n");
188 UG_LOG(
" +++ Element errors: maxEtaSq=" << max <<
", minEtaSq="
189 << min <<
", sumEtaSq=" << totalErr <<
".\n");
194 template<
typename TElem>
202 number minLocal, maxLocal, totalErrLocal;
204 ComputeMinMax(aaError2, dd, min, max, totalErr, numElem, minLocal, maxLocal, totalErrLocal, numElemLocal);
221 template<
typename TElem>
232 number min, max, totalErr;
239 UG_LOG(
" +++ Total error "<<totalErr<<
" smaller than TOL ("<<TOL<<
"). done.");
244 number minErrToRefine = max * refineFrac;
245 UG_LOG(
" +++ Refining elements if error greater " << refineFrac <<
"*" << max <<
246 " = " << minErrToRefine <<
".\n");
247 number maxErrToCoarse = min * (1 + coarseFrac);
248 if(maxErrToCoarse < TOL/numElem) maxErrToCoarse = TOL/numElem;
249 UG_LOG(
" +++ Coarsening elements if error smaller " << maxErrToCoarse <<
".\n");
252 int numMarkedRefine = 0, numMarkedCoarse = 0;
254 const_iterator iter = dd->template begin<TElem>();
255 const_iterator iterEnd = dd->template end<TElem>();
258 for(; iter != iterEnd; ++iter)
264 if(aaError[elem] >= minErrToRefine)
265 if(dd->multi_grid()->get_level(elem) <= maxLevel)
272 if(aaError[elem] <= maxErrToCoarse)
282 UG_LOG(
" +++ Marked for refinement on Proc "<<
pcl::ProcRank()<<
": " << numMarkedRefine <<
" Elements.\n");
283 UG_LOG(
" +++ Marked for coarsening on Proc "<<
pcl::ProcRank()<<
": " << numMarkedCoarse <<
" Elements.\n");
285 int numMarkedRefineLocal = numMarkedRefine, numMarkedCoarseLocal = numMarkedCoarse;
291 UG_LOG(
" +++ Marked for refinement: " << numMarkedRefine <<
" Elements.\n");
292 UG_LOG(
" +++ Marked for coarsening: " << numMarkedCoarse <<
" Elements.\n");
311 template<
typename TElem>
323 number min, max, totalErr;
330 UG_LOG(
" +++ Total error "<<totalErr<<
" smaller than TOL (" << tol <<
"). "
331 "No refinement necessary." << std::endl);
337 number minErrToRefine = tol / numElem;
338 UG_LOG(
" +++ Refining elements if error greater " << tol <<
"/" << numElem <<
339 " = " << minErrToRefine <<
".\n");
342 size_t numMarkedRefine = 0;
344 const_iterator iter = dd->template begin<TElem>();
345 const_iterator iterEnd = dd->template end<TElem>();
348 for (; iter != iterEnd; ++iter)
355 if (aaError[elem] < 0)
continue;
358 if (aaError[elem] >= minErrToRefine)
359 if (dd->multi_grid()->get_level(elem) < maxLevel)
370 size_t numMarkedRefineLocal = numMarkedRefine;
375 UG_LOG(
" +++ Marked for refinement: " << numMarkedRefine <<
" elements.\n");
393 template<
typename TElem>
407 number min, max, totalErr;
414 number maxErrToCoarse = TOL / numElem / 4.0 / safety;
415 UG_LOG(
" +++ Coarsening elements if avg child error smaller than "<< maxErrToCoarse <<
".\n");
418 size_t numMarkedCoarse = 0;
420 const_iterator iter = dd->template begin<TElem>();
421 const_iterator iterEnd = dd->template end<TElem>();
424 for (; iter != iterEnd; ++iter)
433 if (dd->multi_grid()->get_level(elem) <= minLevel)
437 TElem* parent =
dynamic_cast<TElem*
>(dd->multi_grid()->get_parent(elem));
438 if (!parent)
continue;
443 size_t nCh = dd->multi_grid()->num_children<TElem>(parent);
444 for (
size_t ch = 0; ch < nCh; ch++)
446 TElem* child = dd->multi_grid()->get_child<TElem>(parent, ch);
450 if (aaError[child] < 0)
continue;
452 sum += aaError[child];
457 if (sum/cnt <= maxErrToCoarse)
459 for (
size_t ch = 0; ch < nCh; ch++)
461 TElem* child = dd->multi_grid()->get_child<TElem>(parent, ch);
473 size_t numMarkedCoarseLocal = numMarkedCoarse;
478 UG_LOG(
" +++ Marked for coarsening: " << numMarkedCoarse <<
" Elements.\n");
496 template<
typename TElem>
504 bool refTopLvlOnly =
false)
508 int numMarkedRefine = 0, numMarkedCoarse = 0;
509 const_iterator iter = dd->template begin<TElem>();
510 const_iterator iterEnd = dd->template end<TElem>();
516 refTopLvlOnly =
false;
519 for(; iter != iterEnd; ++iter)
525 && (aaError[elem] > refTol)
526 && (dd->multi_grid()->get_level(elem) < maxLevel)
527 && ((!refTopLvlOnly) || (mg->
get_level(elem) == topLvl)))
535 && (aaError[elem] < coarsenTol)
536 && (dd->multi_grid()->get_level(elem) > minLevel))
546 UG_LOG(
" +++ Marked for refinement on Proc "<<
pcl::ProcRank()<<
": " << numMarkedRefine <<
" Elements.\n");
547 UG_LOG(
" +++ Marked for coarsening on Proc "<<
pcl::ProcRank()<<
": " << numMarkedCoarse <<
" Elements.\n");
549 int numMarkedRefineLocal = numMarkedRefine, numMarkedCoarseLocal = numMarkedCoarse;
555 UG_LOG(
" +++ Marked for refinement: " << numMarkedRefine <<
" Elements.\n");
556 UG_LOG(
" +++ Marked for coarsening: " << numMarkedCoarse <<
" Elements.\n");
Definition: smart_pointer.h:296
const T * get() const
Definition: smart_pointer.h:409
Definition: pcl_process_communicator.h:70
void allreduce(const void *sendBuf, void *recBuf, int count, DataType type, ReduceOperation op) const
performs MPI_Allreduce on the processes of the communicator.
Definition: pcl_process_communicator.cpp:318
the generic attachment-accessor for access to grids attachment pipes.
Definition: grid.h:182
The refiner interface allows to mark elements for refinement and to call refine.
Definition: refiner_interface.h:67
virtual bool mark(Vertex *v, RefinementMark refMark=RM_REFINE)
Marks an element for refinement. Default implementation is empty.
Definition: refiner_interface.h:103
virtual RefinementMark get_mark(Vertex *v) const
Returns the mark of a given element. Default returns RM_REFINE.
Definition: refiner_interface.h:198
Definition: multi_grid.h:72
int get_level(TElem *elem) const
Definition: multi_grid.h:206
size_t top_level() const
index of the highest level.
Definition: multi_grid_impl.hpp:86
Const iterator to traverse the surface of a multi-grid hierarchy.
Definition: surface_view.h:237
@ RM_COARSEN
the element is coarsened (only valid for adaptive multi-grid refinement)
Definition: refiner_interface.h:56
@ RM_REFINE
DEPRECATED. Use RM_FULL instead.
Definition: refiner_interface.h:55
#define PCL_RO_SUM
Definition: pcl_methods.h:63
int ProcRank()
returns the rank of the process
Definition: pcl_base.cpp:83
#define PCL_RO_MAX
Definition: pcl_methods.h:61
#define PCL_RO_MIN
Definition: pcl_methods.h:62
int NumProcs()
returns the number of processes
Definition: pcl_base.cpp:91
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124
void ComputeMinMax(MultiGrid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError, ConstSmartPtr< DoFDistribution > dd, number &min, number &max, number &totalErr, size_t &numElem, number &minLocal, number &maxLocal, number &totalErrLocal, size_t &numElemLocal)
helper function that computes min/max and total of error indicators
Definition: error_indicator_util.h:135
void MarkElements(MultiGrid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd, number TOL, number refineFrac, number coarseFrac, int maxLevel)
marks elements according to an attached error value field
Definition: error_indicator_util.h:222
void MarkElementsAbsolute(MultiGrid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd, number refTol, number coarsenTol, int minLevel, int maxLevel, bool refTopLvlOnly=false)
marks elements according to an attached error value field
Definition: error_indicator_util.h:497
void MarkElementsForCoarsening(MultiGrid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd, number TOL, number safety, int minLevel=0)
marks elements for coarsening according to an attached error value field
Definition: error_indicator_util.h:395
number ComputeAvg(MultiGrid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError2, ConstSmartPtr< DoFDistribution > dd, number &min, number &max, number &sum, number &errSq, size_t &numElem, number &minLocal, number &maxLocal, number &sumLocal, size_t &numElemLocal)
helper function that computes min/max and total of error indicators
Definition: error_indicator_util.h:54
void ComputeMinMaxTotal(MultiGrid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError2, ConstSmartPtr< DoFDistribution > dd, number &min, number &max, number &totalErr, size_t &numElem)
helper function that computes min/max and total of error indicators
Definition: error_indicator_util.h:196
void MarkElementsForRefinement(MultiGrid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd, number tol, int maxLevel)
marks elements according for refinement to an attached error value field
Definition: error_indicator_util.h:313