ug4
error_elem_marking_strategy.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3  * Author: Arne Nägel
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 
34 #ifndef __H__UG_DISC__ERROR_ELEM_MARKING_STRATEGY__
35 #define __H__UG_DISC__ERROR_ELEM_MARKING_STRATEGY__
36 
37 #include "lib_grid/algorithms/debug_util.h" // for ElementDebugInfo
38 #include "lib_grid/multi_grid.h"
42 #include "error_indicator_util.h"
43 
44 namespace ug{
45 
47 template <typename TDomain> class IElementMarkingStrategy;
48 
49 
51 
52 template <typename TDomain>
54 {
55 public:
57  static const int dim = TDomain::dim;
58 
62 
65 
68  {
70  }
71 
74  {
76 
77  // default value negative in order to distinguish between newly added elements (e.g. after refinement)
78  // and elements which an error indicator is known for
79  if (!pMG->has_attachment<elem_type>(m_aError))
80  pMG->template attach_to_dv<elem_type>(m_aError, -1.0); // attach with default value
81  m_pMG = pMG;
83  }
84 
87  {
88  if (m_pMG.invalid()) return; // no elements attached
89  if (m_pMG->has_attachment<elem_type>(m_aError))
90  m_pMG->template detach_from<elem_type>(m_aError);
91  }
92 
93 
96  { return this->m_aaError[pElem]; }
97 
100  { return this->m_aaError[pElem]; }
101 
102 
103  friend class IElementMarkingStrategy<TDomain>;
104 
105 
109  { return m_aaError; }
110 
111 protected:
113  error_attachment_type m_aError; // holding 'number' attachments
115 };
116 
117 
118 
119 
123 template <typename TDomain>
125 {
126 public:
128  static const int dim = TDomain::dim;
129 
133 
136  {}
138 
139 
142  IRefiner& refiner,
144  {
145  // forward call
146  mark(mgElemIndicators.errors(), refiner, dd);
147  };
148 
149  protected:
151  virtual void mark(elem_accessor_type& aaError,
152  IRefiner& refiner,
154 
158 
159  public:
163 };
164 
166 template <typename TDomain>
168 {
169 
170 public:
172 
174  : m_tol(tol), m_max_level(max_level) {};
175 
176  void set_tolerance(number tol) {m_tol = tol;}
177  void set_max_level(int max_level) {m_max_level = max_level;}
178 
179 protected:
180  void mark(typename base_type::elem_accessor_type& aaError,
181  IRefiner& refiner,
183 
186 };
187 
188 template <typename TDomain>
190  IRefiner& refiner,
192 {
193  MarkElementsForRefinement<typename base_type::elem_type>(aaError, refiner, dd, m_tol, m_max_level);
194 }
195 
196 
197 
199 template <typename TDomain>
200 class GlobalMarking : public IElementMarkingStrategy<TDomain>
201 {
202 
203 public:
205 
206  GlobalMarking(number tol, size_t max_level)
207  : m_tol(tol), m_max_level(max_level) {};
208 
209  void set_tolerance(number tol) {m_tol = tol;}
210  void set_max_level(size_t max_level) {m_max_level = max_level;}
211 
212 protected:
213  void mark(typename base_type::elem_accessor_type& aaError,
214  IRefiner& refiner,
216 
217 protected:
218 
220  size_t m_max_level;
221 };
222 
223 template <typename TDomain>
225  IRefiner& refiner,
227 {
228  number minElemErr;
229  number maxElemErr;
230  number errTotal;
231  size_t numElem;
232 
233  ComputeMinMaxTotal(aaError, dd, minElemErr, maxElemErr, errTotal, numElem);
234  if (errTotal <= m_tol || dd->multi_grid()->num_levels() > m_max_level)
235  return;
236 
238 
239  const_iterator iter = dd->template begin<typename base_type::elem_type>();
240  const_iterator iterEnd = dd->template end<typename base_type::elem_type>();
241 
242 // loop elements for marking
243  for (; iter != iterEnd; ++iter)
244  refiner.mark(*iter, RM_REFINE);
245 }
246 
247 
248 
250 template <typename TDomain>
252 {
253 
254 public:
256 
258  : m_tol(tol), m_safety(8.0), m_minLvl(0) {}
259 
261  : m_tol(tol), m_safety(safety), m_minLvl(0) {}
262 
263  StdCoarseningMarkingStrategy(number tol, number safety, int minLvl)
264  : m_tol(tol), m_safety(safety), m_minLvl(minLvl) {}
265 
266  void set_tolerance(number tol) {m_tol = tol;}
267  void set_safety_factor(number safety) {m_safety = safety;}
268 
269 protected:
270  void mark(typename base_type::elem_accessor_type& aaError,
271  IRefiner& refiner,
273 
274 protected:
277  int m_minLvl;
278 };
279 
280 template <typename TDomain>
282  IRefiner& refiner,
284 {
285  MarkElementsForCoarsening<typename base_type::elem_type>(aaError, refiner, dd, m_tol, m_safety, m_minLvl);
286 }
287 
288 
289 /* Generate an ordered list of \eta_k^2 (in descending order, ie. largest first) */
290 template<class TElem>
294  const typename DoFDistribution::traits<TElem>::const_iterator iterEnd,
295  std::vector<double> &etaSq)
296 {
297  number localErrSq=0;
299  size_t i=0;
300  for (iter = iterBegin; iter != iterEnd; ++iter)
301  {
302  const double elemErrSq = aaError[*iter];
303 
304  // If no error value exists: ignore (might be newly added by refinement);
305  // newly added elements are supposed to have a negative error estimator
306  if (elemErrSq < 0) continue;
307 
308  etaSq[i++] = elemErrSq;
309  localErrSq += elemErrSq;
310  }
311 
312  // Sort in descending order (using default comparison).
313  std::sort (etaSq.begin(), etaSq.end(), std::greater<double>());
314  return localErrSq;
315 };
316 
317 
318 
319 /* Generate an ordered list of \eta_k^2 (in descending order, ie. largest first) */
320 template<class TElem>
324  const typename DoFDistribution::traits<TElem>::const_iterator iterEnd,
325  std::vector< std::pair<double, TElem*> > &etaSqList)
326 {
327 
328  //typedef typename std::pair<double, TElem*> TPair;
330 
331  number localErrSq=0;
332  size_t i=0;
333  for (iter = iterBegin; iter != iterEnd; ++iter)
334  {
335  const double elemErrSq = aaError[*iter];
336 
337  // If no error value exists: ignore (might be newly added by refinement);
338  // newly added elements are supposed to have a negative error estimator
339  if (elemErrSq < 0) continue;
340 
341  etaSqList[i++] = std::make_pair<>(elemErrSq, *iter);
342  localErrSq += elemErrSq;
343  }
344 
345  // Sort in descending order (using default comparison).
346  std::sort (etaSqList.begin(), etaSqList.end());
347  return localErrSq;
348 };
349 
350 
351 
354 template <typename TDomain>
356 {
357 
358 public:
360 
361  ExpectedErrorMarkingStrategy(number tol, int max_level, number safetyFactor, number expectedReductionFactor)
362  : m_tol(tol), m_max_level(max_level), m_safety(safetyFactor), m_expRedFac(expectedReductionFactor) {};
363 
364  void set_tolerance(number tol) {m_tol = tol;}
365  void set_max_level(int max_level) {m_max_level = max_level;}
366  void set_safety_factor(number safetyFactor) {m_safety = safetyFactor;}
367  void set_expected_reduction_factor(number expectedReductionFactor) {m_expRedFac = expectedReductionFactor;}
368 
369  void mark(typename base_type::elem_accessor_type& aaError,
370  IRefiner& refiner,
372 
373 protected:
374  void merge_sorted_lists
375  (
376  std::vector<std::pair<number, int> >::iterator beginFirst,
377  std::vector<std::pair<number, int> >::iterator beginSecond,
378  std::vector<std::pair<number, int> >::iterator end
379  );
380 
381 protected:
386 };
387 
388 
389 template <typename TDomain>
391 {
395  : m_aaErr(aaErr) {}
396 
397  bool operator()(const elem_type* elem1, const elem_type* elem2)
398  {
399  return m_aaErr[elem1] > m_aaErr[elem2];
400  }
401 
403 };
404 
405 
406 template <typename TDomain>
408 (
409  std::vector<std::pair<number, int> >::iterator beginFirst,
410  std::vector<std::pair<number, int> >::iterator beginSecond,
411  std::vector<std::pair<number, int> >::iterator end
412 )
413 {
414  const size_t nVal = std::distance(beginFirst, end);
415  std::vector<std::pair<number, int> > sorted;
416  sorted.reserve(nVal);
417 
418  std::vector<std::pair<number, int> >::iterator it1 = beginFirst;
419  std::vector<std::pair<number, int> >::iterator it2 = beginSecond;
420  while (it1 != beginSecond && it2 != end)
421  {
422  if (it1->first > it2->first)
423  {
424  sorted.push_back(*it1);
425  ++it1;
426  }
427  else
428  {
429  sorted.push_back(*it2);
430  ++it2;
431  }
432  }
433 
434  for (; it1 != beginSecond; ++it1)
435  sorted.push_back(*it1);
436  for (; it2 != end; ++it2)
437  sorted.push_back(*it2);
438 
439  size_t i = 0;
440  for (it1 = beginFirst; it1 != end; ++it1, ++i)
441  *it1 = sorted[i];
442 }
443 
444 
445 
446 template <typename TDomain>
448 (
449  typename base_type::elem_accessor_type& aaErrorSq,
450  IRefiner& refiner,
452 )
453 {
454  typedef typename base_type::elem_type TElem;
455  typedef typename DoFDistribution::traits<TElem>::const_iterator const_iterator;
456 
457  // create vector of local element (squared) errors
458  const_iterator iter = dd->template begin<TElem>();
459  const const_iterator iterEnd = dd->template end<TElem>();
460  std::vector<TElem*> elemVec;
461  number locError = 0.0;
462  for (; iter != iterEnd; ++iter)
463  {
464  TElem* elem = *iter;
465 
466  if (aaErrorSq[elem] < 0)
467  continue;
468 
469  if (aaErrorSq[elem] != aaErrorSq[elem])
470  {
471  UG_LOG_ALL_PROCS("NaN error indicator on " << ElementDebugInfo(*refiner.grid(), elem));
472  continue;
473  }
474 
475  locError += aaErrorSq[elem];
476 
477  if (dd->multi_grid()->get_level(elem) < m_max_level)
478  elemVec.push_back(elem);
479  }
480  const size_t nLocalElem = elemVec.size();
481 
482  // sort vector of elements locally (descending)
483  ElemErrorSortDesc<TDomain> eeSort(aaErrorSq);
484  std::sort(elemVec.begin(), elemVec.end(), eeSort);
485 
486  // create sorted vector of errors
487  std::vector<number> etaSq(nLocalElem);
488  for (size_t i = 0; i < nLocalElem; ++i)
489  etaSq[i] = aaErrorSq[elemVec[i]];
490 
491 #ifdef UG_PARALLEL
492  const int nProcs = pcl::NumProcs();
493  if (nProcs > 1)
494  {
495  // calculate global error
497  const int rootProc = pcl::NumProcs() - 1;
498  const number globError = pc.allreduce(locError, PCL_RO_SUM);
499  UG_LOGN(" +++ Element errors: sumEtaSq = " << globError << ".");
500 
501  // construct global sorted vector of elem errors
502  // gather on root proc
503  // choose root as the highest-rank proc (proc 0 has least free memory)
504  std::vector<number> rcvBuf;
505  std::vector<int> vSizes;
506  pc.gatherv(rcvBuf, etaSq, rootProc, &vSizes);
507 
508  // merge of pre-sorted local vectors
509  std::vector<int> nRefineElems;
510  size_t globNumRefineElems = 0;
511  if (pcl::ProcRank() == rootProc)
512  {
513  // associate each error value with the proc it belongs to
514  // and calculate offsets at the same time
515  std::vector<size_t> vOffsets(nProcs, 0);
516  const size_t nGlobElem = rcvBuf.size();
517  std::vector<std::pair<number, int> > vGlobErrors(nGlobElem);
518  size_t e = 0;
519  for (int p = 0; p < nProcs; ++p)
520  {
521  const size_t szp = vSizes[p];
522  for (size_t i = 0; i < szp; ++i, ++e)
523  {
524  vGlobErrors[e].first = rcvBuf[e];
525  vGlobErrors[e].second = p;
526  }
527  if (p < nProcs-1)
528  vOffsets[p+1] = e;
529  }
530 
531  // free rcv buffer
532  {
533  std::vector<number> tmp;
534  tmp.swap(rcvBuf);
535  }
536 
537  // merge pre-sorted proc error lists ((log p) * N)
538  size_t nLists = 2;
539  while (true)
540  {
541  const size_t nMerge = nProcs / std::min(nLists, (size_t) nProcs);
542  for (size_t m = 0; m < nMerge; ++m)
543  {
544  std::vector<std::pair<number, int> >::iterator beginFirst =
545  vGlobErrors.begin() + vOffsets[m*nLists];
546  std::vector<std::pair<number, int> >::iterator beginSecond =
547  vGlobErrors.begin() + vOffsets[m*nLists + nLists/2];
548  std::vector<std::pair<number, int> >::iterator endSecond =
549  (m+1)*nLists < (size_t) nProcs ? vGlobErrors.begin() + vOffsets[(m+1)*nLists] : vGlobErrors.end();
550 
551  merge_sorted_lists(beginFirst, beginSecond, endSecond);
552  }
553 
554  if (nLists >= (size_t) nProcs)
555  break;
556 
557  nLists = nLists << 1;
558  }
559 
560  // decide how many elements on each proc have to be refined
561  const number requiredReduction = globError > m_tol ? globError - m_safety*m_tol : 0.0;
562  number red = 0.0;
563  nRefineElems.resize(nProcs, 0);
564  for (; red < requiredReduction && globNumRefineElems < nGlobElem; ++globNumRefineElems)
565  {
566  red += (1.0-m_expRedFac) * vGlobErrors[globNumRefineElems].first;
567  ++nRefineElems[vGlobErrors[globNumRefineElems].second];
568  }
569  }
570 
571  // tell each proc how many of their elements are to be marked
572  int nRefElems = 0;
573  pc.scatter(GetDataPtr(nRefineElems), 1, PCL_DT_INT, &nRefElems, 1, PCL_DT_INT, rootProc);
574 
575  pc.broadcast(globNumRefineElems, rootProc);
576 
577  // mark for refinement
578  UG_COND_THROW((size_t) nRefElems > nLocalElem, "More elements supposedly need refinement here ("
579  << nRefElems << ") than are refineable (" << nLocalElem << ").");
580  for (size_t i = 0; i < (size_t) nRefElems; ++i)
581  refiner.mark(elemVec[i], RM_REFINE);
582 
583  if (globNumRefineElems)
584  {
585  UG_LOGN(" +++ Marked for refinement: " << globNumRefineElems << " elements");
586  }
587  else
588  {
589  UG_LOGN(" +++ No refinement necessary.");
590  }
591  }
592  else
593  {
594 #endif
595 
596  // plan refinement of elements until expected error reduction is enough
597  // to get below tolerance (or all elements are marked)
598  const number requiredReduction = locError - m_safety*m_tol;
599  UG_LOGN(" +++ Element errors: sumEtaSq = " << locError << ".");
600  number red = 0.0;
601  size_t i = 0;
602  for (; red < requiredReduction && i < nLocalElem; ++i)
603  {
604  red += m_expRedFac * etaSq[i];
605  refiner.mark(elemVec[i], RM_REFINE);
606  }
607  if (i)
608  {
609  UG_LOGN(" +++ Marked for refinement: " << i << " elements.");
610  }
611  else
612  {
613  UG_LOGN(" +++ No refinement necessary.");
614  }
615 
616 #ifdef UG_PARALLEL
617  }
618 #endif
619 }
620 
621 
622 
625 template <typename TDomain>
626 class MaximumMarking : public IElementMarkingStrategy<TDomain>{
627 
628 public:
631  : m_theta(theta), m_theta_min(0.0), m_eps(0.01), m_max_level(100), m_min_level(0) {};
633  : m_theta(theta), m_theta_min(0.0), m_eps (eps), m_max_level(100), m_min_level(0) {};
634  MaximumMarking(number theta_max, number theta_min, number eps)
635  : m_theta(theta_max), m_theta_min(theta_min), m_eps (eps), m_max_level(100), m_min_level(0) {};
636 
637 protected:
638  void mark(typename base_type::elem_accessor_type& aaErrorSq, IRefiner& refiner, ConstSmartPtr<DoFDistribution> dd);
639 
640 public:
641  void set_max_level(int lvl) {m_max_level = lvl;}
642  void set_min_level(int lvl) {m_min_level = lvl;}
643 
644 protected:
645 
649 };
650 
651 
652 
653 template <typename TDomain>
655  IRefiner& refiner,
657 {
658  typedef typename base_type::elem_type TElem;
659  typedef typename DoFDistribution::traits<TElem>::const_iterator const_iterator;
660 
661  // compute minimal/maximal/ total error and number of elements
662 
663  number minElemErr, minElemErrLocal;
664  number maxElemErr, maxElemErrLocal;
665  number errTotal, errLocal;
666  size_t numElem, numElemLocal;
667 
668  ComputeMinMax(aaErrorSq, dd, minElemErr, maxElemErr, errTotal, numElem,
669  minElemErrLocal, maxElemErrLocal, errLocal, numElemLocal);
670 
671  this->m_latest_error = sqrt(errTotal);
672  this->m_latest_error_per_elem_max = maxElemErr;
673  this->m_latest_error_per_elem_min = minElemErr;
674 
675  // init iterators
676  const_iterator iter;
677  const const_iterator iterEnd = dd->template end<TElem>();
678 
679  // determine (local) number of excess elements
680  const size_t ndiscard = (size_t) (numElemLocal*m_eps); // TODO: on every process?
681  UG_LOG(" +++ MaximumMarking: Found max "<< maxElemErr << ", ndiscard="<<ndiscard<<".\n");
682 
683  if (numElemLocal > 0)
684  {
685  // create sorted array of elem weights
686  std::vector<double> etaSq;
687  etaSq.resize(numElemLocal);
688  CreateListOfElemWeights<TElem>(aaErrorSq,dd->template begin<TElem>(), iterEnd, etaSq);
689  UG_ASSERT(numElemLocal==etaSq.size(), "Huhh: number of elements does not match!");
690  UG_ASSERT(numElemLocal > ndiscard, "Huhh: number of elements does not match!");
691  maxElemErr = etaSq[ndiscard];
692  }
693 
694  // compute parallel threshold
695 #ifdef UG_PARALLEL
696  if (pcl::NumProcs() > 1)
697  {
699  number maxElemErrLocal = maxElemErr;
700  maxElemErr = com.allreduce(maxElemErrLocal, PCL_RO_MAX);
701  UG_LOG(" +++ Maximum for refinement: " << maxElemErr << ".\n");
702  }
703 #else
704  UG_LOG(" +++ Skipping " << ndiscard << " elements; new (parallel) max." << maxElemErr << ".\n");
705 #endif
706 
707  // refine all element above threshold
708  const number top_threshold = maxElemErr*m_theta;
709  const number bot_threshold = maxElemErr*m_theta_min;
710  UG_LOG(" +++ Refining elements, if error > " << maxElemErr << "*" << m_theta <<
711  " = " << top_threshold << ".\n");
712  UG_LOG(" +++ Coarsening elements, if error < " << maxElemErr << "*" << m_theta_min <<
713  " = " << bot_threshold << ".\n");
714 
715  // reset counter
716  std::size_t numMarkedRefine = 0;
717  std::size_t numMarkedCoarse = 0;
718 
719  // loop elements for marking
720  for (iter = dd->template begin<TElem>(); iter != iterEnd; ++iter)
721  {
722  // get element
723  TElem* elem = *iter;
724 
725  // if no error value exists: ignore (might be newly added by refinement);
726  // newly added elements are supposed to have a negative error estimator
727  if (aaErrorSq[elem] < 0) continue;
728 
729  // mark for refinement
730  if ((aaErrorSq[elem] > top_threshold) && (dd->multi_grid()->get_level(elem) <= m_max_level))
731  {
732  refiner.mark(elem, RM_REFINE);
733  numMarkedRefine++;
734  }
735 
736  // mark for coarsening
737  if ((aaErrorSq[elem] < bot_threshold) && (dd->multi_grid()->get_level(elem) >= m_min_level))
738  {
739  refiner.mark(elem, RM_COARSEN);
740  numMarkedCoarse++;
741  }
742  }
743 
744 #ifdef UG_PARALLEL
745  if (pcl::NumProcs() > 1)
746  {
748  std::size_t numMarkedRefineLocal = numMarkedRefine;
749  numMarkedRefine = com.allreduce(numMarkedRefineLocal, PCL_RO_SUM);
750  UG_LOG(" +++ MaximumMarking: Marked for refinement: " << numMarkedRefine << " ("<< numMarkedRefineLocal << ") elements.\n");
751  }
752  else
753 #endif
754  { UG_LOG(" +++ MaximumMarking: refinement: " << numMarkedRefine << ", coarsening" << numMarkedCoarse << " elements.\n") }
755 
756 
757 }
758 
759 
760 
763 template <typename TDomain>
765 
766 public:
769  : m_theta(theta), m_max_level(100), m_min_level(0) {};
770 protected:
771  void mark(typename base_type::elem_accessor_type& aaErrorSq, IRefiner& refiner, ConstSmartPtr<DoFDistribution> dd);
772 public:
773  void set_max_level(int lvl) {m_max_level = lvl;}
774  void set_min_level(int lvl) {m_min_level = lvl;}
775 
776 protected:
777 
780 };
781 
782 
783 
784 template <typename TDomain>
786  IRefiner& refiner,
788 {
789  typedef typename base_type::elem_type TElem;
790  //typedef typename DoFDistribution::traits<TElem>::const_iterator const_iterator;
791  typedef typename std::pair<double, TElem*> TPair;
792  typedef typename std::vector<TPair> TPairVector;
793 
794  // Compute minimal/maximal/ total error and number of elements.
795  number minElemErrSq, minElemErrSqLocal;
796  number maxElemErrSq, maxElemErrSqLocal;
797  number errSqTotal, errSqLocal;
798  size_t numElem, numElemLocal;
799 
800  size_t numCoarsened=0;
801 
802 
803  ComputeMinMax(aaErrorSq, dd, minElemErrSq, maxElemErrSq, errSqTotal, numElem,
804  minElemErrSqLocal, maxElemErrSqLocal, errSqLocal, numElemLocal);
805 
806  this->m_latest_error = sqrt(errSqTotal);
807  this->m_latest_error_per_elem_max = maxElemErrSq;
808  this->m_latest_error_per_elem_min = minElemErrSq;
809 
810 
811 
812  if (numElemLocal > 0)
813  {
814  // Create sorted array of elem weights.
815  TPairVector etaSqVec;
816  etaSqVec.resize(numElemLocal);
817  CreateSortedListOfElems<TElem>(aaErrorSq,dd->template begin<TElem>(), dd->template end<TElem>(), etaSqVec);
818 
819 
820  UG_ASSERT(numElemLocal==etaSqVec.size(), "Huhh: number of elements does not match!");
821 
822  {
823 
824  const double mySumSq = errSqLocal*m_theta;
825  double localSumSq = 0.0;
826 
827  typename TPairVector::const_iterator iterEnd = etaSqVec.end();
828 
829  for (typename TPairVector::iterator iter = etaSqVec.begin();
830  (iter != iterEnd) && (localSumSq < mySumSq); ++iter)
831  {
832 
833  localSumSq += iter->first;
834  if (localSumSq < mySumSq) {
835  refiner.mark(iter->second, RM_COARSEN);
836  numCoarsened++;
837  }
838 
839  }
840  UG_LOG(" +++ APosterioriCoarsening: localSumSq = "<< localSumSq << " >" << mySumSq << std::endl);
841 
842  }
843 
844 
845 
846  }
847 
848 
849 #ifdef UG_PARALLEL
850  if (pcl::NumProcs() > 1)
851  {
853  std::size_t numCoarsenedLocal = numCoarsened;
854  numCoarsened = com.allreduce(numCoarsenedLocal, PCL_RO_SUM);
855  UG_LOG(" +++ APosterioriCoarsening: Marked for coarsening: " << numCoarsened << " ("<< numCoarsenedLocal << ") elements.\n");
856  }
857  else
858 #endif
859  { UG_LOG(" +++ APosterioriCoarsening: coarsening" << numCoarsened << " elements.\n") }
860 
861 
862 }
863 
864 
866 
867 template <typename TDomain>
869 
870 public:
873  : m_theta_top(theta_top), m_theta_bot(0.0) {} //, m_max_level(100) {};
875  : m_theta_top(theta_top), m_theta_bot(theta_bot) {} ;// , m_max_level(100) {};
876 
877 
878 protected:
879  void mark(typename base_type::elem_accessor_type& aaErrorSq,
880  IRefiner& refiner,
882 
883  number m_theta_top; // refine at least a certain fraction, 0.0 <= m_theta_top <= 1.0
884  number m_theta_bot; // refine at least a certain fraction, 0.0 <= m_theta_bot <= 1.0
885  // int m_max_level;
886 };
887 
888 
889 
890 
891 
892 template <typename TDomain>
894  IRefiner& refiner,
896 {
897  typedef typename base_type::elem_type TElem;
898  typedef typename DoFDistribution::traits<TElem>::const_iterator const_iterator;
899 
900  // compute minimal/maximal/total error and number of elements
901  number minElemErr, minElemErrLocal;
902  number maxElemErr, maxElemErrLocal;
903  number errTotal= 0.0, errLocal= 0.0;
904  size_t numElem= 0, numElemLocal;
905 
906  // compute weights
907  ComputeMinMax(aaErrorSq, dd, minElemErr, maxElemErr, errTotal, numElem,
908  minElemErrLocal, maxElemErrLocal, errLocal, numElemLocal);
909 
910  // init iterators
911  const const_iterator iterEnd = dd->template end<TElem>();
912  const_iterator iter;
913 
914  // create and fill sorted array of $\etaSq^2_i$ for all (local) elements
915  std::vector<double> etaSq;
916  etaSq.resize(numElemLocal);
917  CreateListOfElemWeights<TElem>(aaErrorSq,dd->template begin<TElem>(), iterEnd, etaSq);
918  UG_ASSERT(numElemLocal==etaSq.size(), "Huhh: number of elements does not match!");
919 
920  // compute thresholds
921  UG_ASSERT( ((m_theta_top>=0.0) && (m_theta_top<=1.0)), "Huhh: m_theta_top invalid!");
922  UG_ASSERT( ((m_theta_bot>=0.0) && (m_theta_bot<=1.0)), "Huhh: m_theta_top invalid!");
923  UG_ASSERT( (m_theta_top>m_theta_bot), "Huhh: m_theta_top invalid!");
924 
925  // discard a fraction of elements
926  // a) largest elements
927  typename std::vector<double>::const_iterator top = etaSq.begin();
928  for (number sumSq=0.0;
929  (sumSq<m_theta_top*errLocal) && (top !=(etaSq.end()-1));
930  ++top) { sumSq += *top; }
931  number top_threshold = (top != etaSq.begin()) ? (*top + *(top-1))/2.0 : *top;
932 
933  // a) smallest elements
934  typename std::vector<double>::const_iterator bot = etaSq.end()-1;
935  for (number sumSq=0.0;
936  (sumSq<m_theta_bot*errLocal) && (bot !=etaSq.begin() );
937  --bot) { sumSq += *bot; }
938  number bot_threshold = (bot != (etaSq.end()-1)) ? (*bot + *(bot+1))/2.0 : 0.0;
939 
940  UG_LOG(" +++ error = "<< errLocal << std::endl);
941  UG_LOG(" +++ top_threshold= "<< top_threshold <<"( "<< top - etaSq.begin() << " cells)" << std::endl);
942  UG_LOG(" +++ bot_threshold= "<< bot_threshold <<"( "<< etaSq.end()-bot << " cells)" << std::endl);
943 
944  // mark elements with maximal contribution
945  size_t numMarkedRefine = 0;
946  size_t numMarkedCoarse = 0;
947  for (iter = dd->template begin<TElem>(); iter != iterEnd; ++iter)
948  {
949 
950  const double elemErr = aaErrorSq[*iter]; // get element
951  if (elemErr < 0) continue; // skip invalid
952 
953  if (elemErr > top_threshold)
954  {
955  refiner.mark(*iter, RM_REFINE);
956  numMarkedRefine++;
957  }
958 
959  if (elemErr < bot_threshold)
960  {
961  refiner.mark(*iter, RM_COARSEN);
962  numMarkedCoarse++;
963  }
964  }
965 
966 
967 
968  UG_LOG(" +++ EquilibrationMarkingStrategy: Marked for refinement: "<< numMarkedRefine << ", " << numMarkedCoarse << " elements.\n");
969 
970 }
971 
972 
975 template <typename TDomain>
976 class VarianceMarking : public IElementMarkingStrategy<TDomain>{
977 
978 public:
980  VarianceMarking(number theta) : m_theta(theta), m_width(3.0), m_max_level(100) {};
981  VarianceMarking(number theta, number width) : m_theta(theta), m_width (width), m_max_level(100) {};
982 
983 
984 protected:
985  void mark(typename base_type::elem_accessor_type& aaError2,
986  IRefiner& refiner,
988 
992 };
993 
994 template <typename TDomain>
996  IRefiner& refiner,
998 {
999  typedef typename base_type::elem_type TElem;
1000  typedef typename DoFDistribution::traits<TElem>::const_iterator const_iterator;
1001 
1002  // compute minimal/maximal/ total error and number of elements
1003 
1004  number minElemErr, minElemErrLocal;
1005  number maxElemErr, maxElemErrLocal;
1006  number errTotal, errLocal;
1007  size_t numElem, numElemLocal;
1008 
1009  ComputeMinMax(aaError2, dd, minElemErr, maxElemErr, errTotal, numElem,
1010  minElemErrLocal, maxElemErrLocal, errLocal, numElemLocal);
1011 
1012  this->m_latest_error = sqrt(errTotal);
1013  this->m_latest_error_per_elem_max = maxElemErr;
1014  this->m_latest_error_per_elem_min = minElemErr;
1015 
1016 // number elemMean = sqrt(errTotal) / numElem;
1017  number elemMean = errTotal / numElem;
1018 
1019  UG_LOG(" +++ VarianceMarking: Mean error : " << elemMean << " on "<< numElem << " elements.\n");
1020 
1021  // init iterators
1022  const_iterator iter;
1023  const const_iterator iterEnd = dd->template end<TElem>();
1024 
1025  number elemVar = 0.0;
1026  for (iter = dd->template begin<TElem>(); iter != iterEnd; ++iter)
1027  {
1028  TElem* elem = *iter;
1029  number elemError = aaError2[elem]; // eta_i^2
1030 
1031  if (elemError < 0) continue;
1032  elemVar += (elemMean-elemError) * (elemMean-elemError);
1033 
1034 
1035  }
1036 
1037 #ifdef UG_PARALLEL
1038  if (pcl::NumProcs() > 1)
1039  {
1041  number elemVarLocal = elemVar;
1042  elemVar = com.allreduce(elemVarLocal, PCL_RO_SUM);
1043 
1044  }
1045 #endif
1046  UG_LOG(" +++ VarianceMarking: Est. variance (1) : " << elemVar << " on "<< numElem << " elements.\n");
1047 
1048 
1049  elemVar /= (numElem-1.0);
1050  UG_LOG(" +++ VarianceMarking: Est. variance (2): " << elemVar << " on "<< numElem << " elements.\n");
1051 
1052 
1053  // refine all element above threshold
1054  const number sigma = sqrt(elemVar);
1055  const number maxError = elemMean + sigma*m_width;
1056  UG_LOG(" +++ Refining elements if error greater " << sigma << "*" << m_width <<" + "<< elemMean <<
1057  " = " << maxError << ".\n");
1058 
1059 
1060 
1061  const number minErrToRefine = maxError*m_theta;
1062  UG_LOG(" +++ Refining elements if error greater " << maxError << "*" << m_theta <<
1063  " = " << minErrToRefine << ".\n");
1064 
1065  // reset counter
1066  std::size_t numMarkedRefine = 0;
1067 
1068  // loop elements for marking
1069  for (iter = dd->template begin<TElem>(); iter != iterEnd; ++iter)
1070  {
1071  // get element
1072  TElem* elem = *iter;
1073 
1074  // if no error value exists: ignore (might be newly added by refinement);
1075  // newly added elements are supposed to have a negative error estimator
1076  if (aaError2[elem] < 0) continue;
1077 
1078  // marks for refinement
1079  if (aaError2[elem] >= minErrToRefine)
1080  if (dd->multi_grid()->get_level(elem) <= m_max_level)
1081  {
1082  refiner.mark(elem, RM_REFINE);
1083  numMarkedRefine++;
1084  }
1085  }
1086 
1087 #ifdef UG_PARALLEL
1088  if (pcl::NumProcs() > 1)
1089  {
1091  std::size_t numMarkedRefineLocal = numMarkedRefine;
1092  numMarkedRefine = com.allreduce(numMarkedRefineLocal, PCL_RO_SUM);
1093  UG_LOG(" +++ MaximumMarking: Marked for refinement: " << numMarkedRefine << " ("<< numMarkedRefineLocal << ") elements.\n");
1094  }
1095 #else
1096  UG_LOG(" +++ MaximumMarking: Marked for refinement: " << numMarkedRefine << " elements.\n");
1097 #endif
1098 
1099 
1100 }
1101 
1102 
1104 
1109 template <typename TDomain>
1111 
1112 public:
1115  m_theta(theta), m_width(3.0), m_max_level(100), m_theta_coarse(0.0), m_min_level(0)
1116  {};
1118  m_theta(theta), m_width (width), m_max_level(100), m_theta_coarse(0.0), m_min_level(0)
1119  {};
1120  VarianceMarkingEta(number theta, number width, number theta_coarse) :
1121  m_theta(theta), m_width (width), m_max_level(100), m_theta_coarse(theta_coarse), m_min_level(0)
1122  {};
1123 
1124  void init_refinement(number theta, int max_level)
1125  {m_theta = theta; m_max_level=max_level;}
1126 
1127  void init_coarsening(number theta, int min_level)
1128  {m_theta_coarse = theta; m_min_level=min_level;}
1129 
1130 protected:
1131  void mark(typename base_type::elem_accessor_type& aaError2,
1132  IRefiner& refiner,
1134 protected:
1135 
1139 
1142 };
1143 
1144 template <typename TDomain>
1146  IRefiner& refiner,
1148 {
1149  typedef typename base_type::elem_type TElem;
1150  typedef typename DoFDistribution::traits<TElem>::const_iterator const_iterator;
1151 
1152  // compute minimal/maximal/ total error and number of elements
1153 
1154  number minElemErr, minElemErrLocal;
1155  number maxElemErr, maxElemErrLocal;
1156  number errSum, errTotalSq, errLocal;
1157  size_t numElem, numElemLocal;
1158 
1159  const number elemMean = ComputeAvg(aaError2, dd, minElemErr, maxElemErr, errSum, errTotalSq, numElem,
1160  minElemErrLocal, maxElemErrLocal, errLocal, numElemLocal);
1161 
1162 
1163  this->m_latest_error = sqrt(errTotalSq);
1164  this->m_latest_error_per_elem_max = maxElemErr;
1165  this->m_latest_error_per_elem_min = minElemErr;
1166 
1167  UG_LOG(" +++ VarianceMarkingEta: error : "<< this->m_latest_error << " (meanEta : " << elemMean << " on "<< numElem << " elements).\n");
1168 
1169  // init iterators
1170  const_iterator iter;
1171  const const_iterator iterEnd = dd->template end<TElem>();
1172 
1173  number elemVar = 0.0;
1174  for (iter = dd->template begin<TElem>(); iter != iterEnd; ++iter)
1175  {
1176  TElem* elem = *iter;
1177 
1178  if (aaError2[elem] < 0) continue;
1179 
1180  number elemError = sqrt(aaError2[elem]); // eta_i
1181 
1182  elemVar += (elemMean-elemError) * (elemMean-elemError);
1183  }
1184 
1185  UG_LOG(" +++ VarianceMarkingEta: Est. variance (1) : " << (elemVar / (numElem -1.0)) << " on "<< numElem << " elements.\n");
1186 #ifdef UG_PARALLEL
1187  if (pcl::NumProcs() > 1)
1188  {
1190  number elemVarLocal = elemVar;
1191  elemVar = com.allreduce(elemVarLocal, PCL_RO_SUM);
1192 
1193  }
1194 #endif
1195  elemVar /= (numElem-1.0);
1196  UG_LOG(" +++ VarianceMarkingEta: Est. variance (2): " << elemVar << " on "<< numElem << " elements.\n");
1197 
1198 
1199  // refine all element above threshold
1200  const number sigma = sqrt(elemVar);
1201  const number maxError = elemMean + sigma*m_width;
1202  UG_LOG(" +++ Refining elements if error > " << elemMean << " + "<< sigma << "*" << m_width <<
1203  " = " << maxError << ".\n");
1204 
1205  const number elemErrorRefine = maxError*m_theta;
1206  UG_LOG(" +++ Refining elements if error > " << maxError << "*" << m_theta <<
1207  " = " << elemErrorRefine << ".\n");
1208 
1209  // coarsen all element not contributing significantly
1210  //const number minError = std::max(elemMean /*- sigma*m_width*/, 0.0);
1211  //UG_LOG(" +++ Coarsening elements if error greater " << elemMean << " - "<< sigma << "*" << m_width <<
1212  // " = " << minError << ".\n");
1213 
1214  const number elemErrorCoarsen = elemMean*m_theta_coarse;
1215  UG_LOG(" +++ Coarsening elements if error < " << elemMean << "*" << m_theta_coarse <<
1216  " = " << elemErrorCoarsen << ".\n");
1217 
1218 
1219 
1220  // reset counters
1221  std::size_t numMarkedRefine = 0;
1222  std::size_t numMarkedCoarsen = 0;
1223 
1224  // loop elements for marking
1225  for (iter = dd->template begin<TElem>(); iter != iterEnd; ++iter)
1226  {
1227  // get element
1228  TElem* elem = *iter;
1229 
1230  // if no error value exists: ignore (might be newly added by refinement);
1231  // newly added elements are supposed to have a negative error estimator
1232  if (aaError2[elem] < 0) continue;
1233 
1234  const number elemError = sqrt(aaError2[elem]); // eta_i
1235 
1236  // mark for refinement
1237  if ((elemError >= elemErrorRefine) && (dd->multi_grid()->get_level(elem) <= m_max_level))
1238  {
1239  refiner.mark(elem, RM_REFINE);
1240  numMarkedRefine++;
1241  }
1242 
1243  // mark for coarsening
1244  if ((elemError < elemErrorCoarsen) && (dd->multi_grid()->get_level(elem) >= m_min_level))
1245  {
1246  refiner.mark(elem, RM_COARSEN);
1247  numMarkedCoarsen++;
1248  }
1249 
1250  }
1251 
1252 #ifdef UG_PARALLEL
1253  if (pcl::NumProcs() > 1)
1254  {
1256  std::size_t numMarkedRefineLocal = numMarkedRefine;
1257  numMarkedRefine = com.allreduce(numMarkedRefineLocal, PCL_RO_SUM);
1258  UG_LOG(" +++ VarianceMarkingEta: Marked for refinement: " << numMarkedRefine << " ("<< numMarkedRefineLocal << ") elements.\n");
1259  } else
1260 #endif
1261  {
1262  UG_LOG(" +++ VarianceMarkingEta: Marked for refinement: " << numMarkedRefine << " elements.\n");
1263  UG_LOG(" +++ VarianceMarkingEta: Marked for coarsening: " << numMarkedCoarsen << " elements.\n");
1264  }
1265 }
1266 
1267 
1270 template <typename TDomain>
1272 
1273 public:
1275  MeanValueMarking(number theta, number factor) : m_theta(theta), m_factor (factor) {};
1276 
1277 protected:
1278  void mark(typename base_type::elem_accessor_type& aaError,
1279  IRefiner& refiner,
1281 protected:
1282 
1285 };
1286 
1287 template <typename TDomain>
1289  IRefiner& refiner,
1291 {
1292  typedef typename base_type::elem_type TElem;
1293  typedef typename DoFDistribution::traits<TElem>::const_iterator const_iterator;
1294 
1295  // compute minimal/maximal/ total error and number of elements
1296 
1297  number minElemErr, minElemErrLocal;
1298  number maxElemErrSq, maxElemErrLocal;
1299  number errTotalSq, errLocal;
1300  size_t numElem, numElemLocal;
1301 
1302  ComputeMinMax(aaError, dd, minElemErr, maxElemErrSq, errTotalSq, numElem,
1303  minElemErrLocal, maxElemErrLocal, errLocal, numElemLocal);
1304 
1305 
1306  // init iterators
1307  number avgElemErr = errTotalSq / numElem;
1308  UG_LOG(" +++ Global max: "<< maxElemErrSq << ", Global min: "<< minElemErr <<".\n");
1309  UG_LOG(" +++ MeanValueMarking: Mean value : " << avgElemErr << " (Global error sum: "<<errTotalSq<<" on "<< numElem <<" elements).\n");
1310 
1311  // refine all element above threshold
1312  const number minThetaErrToRefine = maxElemErrSq*m_theta;
1313  const number minFactorAvgErrToRefine = avgElemErr*m_factor;
1314  UG_LOG(" +++ MeanValueMarking: Min theta error : "<<minThetaErrToRefine<<" (Global Max Error: " << maxElemErrSq<< " for theta: "<<m_theta<<").\n");
1315  UG_LOG(" +++ MeanValueMarking: Min factor avg error : "<<minFactorAvgErrToRefine<<" (Global Avg Error: " << avgElemErr<< " for factor: "<<m_factor<<").\n");
1316 
1317  const number minErrToRefine = std::min(minThetaErrToRefine, minFactorAvgErrToRefine);
1318  UG_LOG(" +++ MeanValueMarking: Refining if error >= : "<<minErrToRefine<<".\n");
1319 
1320 
1321  // reset counter
1322  std::size_t numMarkedRefine = 0;
1323 
1324  // loop elements for marking
1325  const_iterator iter;
1326  const const_iterator iterEnd = dd->template end<TElem>();
1327  for (iter = dd->template begin<TElem>(); iter != iterEnd; ++iter)
1328  {
1329  // get element
1330  TElem* elem = *iter;
1331 
1332  // if no error value exists: ignore (might be newly added by refinement);
1333  // newly added elements are supposed to have a negative error estimator
1334  if (aaError[elem] < 0) continue;
1335 
1336  // marks for refinement
1337  if (aaError[elem] >= minErrToRefine)
1338  {
1339  refiner.mark(elem, RM_REFINE);
1340  numMarkedRefine++;
1341  }
1342  }
1343 
1344 #ifdef UG_PARALLEL
1345  if (pcl::NumProcs() > 1)
1346  {
1348  std::size_t numMarkedRefineLocal = numMarkedRefine;
1349  numMarkedRefine = com.allreduce(numMarkedRefineLocal, PCL_RO_SUM);
1350  UG_LOG(" +++ MeanValueMarking: Marked for refinement: " << numMarkedRefine << " ("<< numMarkedRefineLocal << ") elements.\n");
1351  }
1352 #else
1353  UG_LOG(" +++ MeanValueMarking: Marked for refinement: " << numMarkedRefine << " elements.\n");
1354 #endif
1355 
1356 
1357 }
1358 
1359 
1360 
1361 
1362 
1363 
1365 template <typename TDomain>
1367 
1368 public:
1370  AbsoluteMarking(number eta) : m_eta(eta), m_max_level(100) {};
1371 
1372 protected:
1373  void mark(typename base_type::elem_accessor_type& aaError,
1374  IRefiner& refiner,
1376 protected:
1377 
1380 };
1381 
1382 template <typename TDomain>
1384  IRefiner& refiner,
1386 {
1387  typedef typename base_type::elem_type TElem;
1388  typedef typename DoFDistribution::traits<TElem>::const_iterator const_iterator;
1389 
1390  // loop elements for marking
1391  const const_iterator iterEnd = dd->template end<TElem>();
1392 
1393  number lowerBound = m_eta*m_eta;
1394 
1395  number errTotal=0.0;
1396 
1397  size_t numMarkedRefine = 0;
1398  for (const_iterator iter = dd->template begin<TElem>(); iter != iterEnd; ++iter)
1399  {
1400  // get element error
1401  TElem* elem = *iter;
1402  const number elemError = aaError[elem];
1403 
1404  // skip newly added
1405  if (elemError < 0) continue;
1406  errTotal += elemError;
1407 
1408  // mark for refinement
1409  if ((elemError >= lowerBound) && (dd->multi_grid()->get_level(elem) <= m_max_level))
1410  {
1411  refiner.mark(elem, RM_REFINE);
1412  numMarkedRefine++;
1413  }
1414  }
1415 
1416 
1417 
1418 #ifdef UG_PARALLEL
1419  if (pcl::NumProcs() > 1)
1420  {
1422  std::size_t numMarkedRefineLocal = numMarkedRefine;
1423  number errLocal = errTotal;
1424  numMarkedRefine = com.allreduce(numMarkedRefineLocal, PCL_RO_SUM);
1425  errTotal = com.allreduce(errLocal, PCL_RO_SUM);
1426  }
1427 #endif
1428 
1429  this->m_latest_error = sqrt(errTotal);
1430 
1431  UG_LOG(" +++ AbsoluteMarking: Error**2 = "<<errTotal <<"; marked "<< numMarkedRefine << " elements for refinement "<<std::endl);
1432 
1433 }
1434 
1435 
1436 
1438 template <typename TDomain, typename TAlgebra>
1440  typedef typename domain_traits<TDomain::dim>::element_type TElem;
1442  refiner.mark(spDD->begin<TElem>(), spDD->end<TElem>(), RM_COARSEN);
1443  refiner.coarsen();
1444 }
1445 
1446 
1447 }// end of namespace
1448 
1449 #endif
1450 
parameterString p
Definition: smart_pointer.h:296
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:212
Definition: pcl_process_communicator.h:70
void gatherv(const void *sendBuf, int sendCount, DataType sendType, void *recBuf, int *recCounts, int *displs, DataType recType, int root) const
performs MPI_Gatherv on the processes of the communicator.
Definition: pcl_process_communicator.cpp:406
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
void scatter(const void *sendBuf, int sendCount, DataType sendType, void *recBuf, int recCount, DataType recType, int root) const
performs MPI_Scatter on the processes of the communicator
Definition: pcl_process_communicator.cpp:392
void broadcast(void *v, size_t size, DataType type, int root=0) const
Definition: pcl_process_communicator.cpp:685
Definition: error_elem_marking_strategy.h:764
APosterioriCoarsening(number theta=0.1)
Definition: error_elem_marking_strategy.h:768
void set_max_level(int lvl)
Definition: error_elem_marking_strategy.h:773
void mark(typename base_type::elem_accessor_type &aaErrorSq, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:785
void set_min_level(int lvl)
Definition: error_elem_marking_strategy.h:774
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:767
number m_theta
Definition: error_elem_marking_strategy.h:778
int m_min_level
Definition: error_elem_marking_strategy.h:779
int m_max_level
Definition: error_elem_marking_strategy.h:779
marks elements above an absolute threshold (based on S. Reiter's idea)
Definition: error_elem_marking_strategy.h:1366
int m_max_level
Definition: error_elem_marking_strategy.h:1379
number m_eta
Definition: error_elem_marking_strategy.h:1378
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:1369
void mark(typename base_type::elem_accessor_type &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:1383
AbsoluteMarking(number eta)
Definition: error_elem_marking_strategy.h:1370
marks elements above a certain fraction of the maximum
Definition: error_elem_marking_strategy.h:868
number m_theta_top
Definition: error_elem_marking_strategy.h:883
EquilibrationMarkingStrategy(number theta_top=0.9)
Definition: error_elem_marking_strategy.h:872
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:871
void mark(typename base_type::elem_accessor_type &aaErrorSq, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:893
EquilibrationMarkingStrategy(number theta_top, number theta_bot)
Definition: error_elem_marking_strategy.h:874
number m_theta_bot
Definition: error_elem_marking_strategy.h:884
Definition: error_elem_marking_strategy.h:356
number m_expRedFac
Definition: error_elem_marking_strategy.h:385
void merge_sorted_lists(std::vector< std::pair< number, int > >::iterator beginFirst, std::vector< std::pair< number, int > >::iterator beginSecond, std::vector< std::pair< number, int > >::iterator end)
Definition: error_elem_marking_strategy.h:408
int m_max_level
Definition: error_elem_marking_strategy.h:383
void set_expected_reduction_factor(number expectedReductionFactor)
Definition: error_elem_marking_strategy.h:367
number m_tol
Definition: error_elem_marking_strategy.h:382
void set_safety_factor(number safetyFactor)
Definition: error_elem_marking_strategy.h:366
void set_max_level(int max_level)
Definition: error_elem_marking_strategy.h:365
void mark(typename base_type::elem_accessor_type &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:448
ExpectedErrorMarkingStrategy(number tol, int max_level, number safetyFactor, number expectedReductionFactor)
Definition: error_elem_marking_strategy.h:361
void set_tolerance(number tol)
Definition: error_elem_marking_strategy.h:364
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:359
number m_safety
Definition: error_elem_marking_strategy.h:384
mark everything if error too high and refinement allowed
Definition: error_elem_marking_strategy.h:201
number m_tol
Definition: error_elem_marking_strategy.h:219
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:204
size_t m_max_level
Definition: error_elem_marking_strategy.h:220
GlobalMarking(number tol, size_t max_level)
Definition: error_elem_marking_strategy.h:206
void set_tolerance(number tol)
Definition: error_elem_marking_strategy.h:209
void set_max_level(size_t max_level)
Definition: error_elem_marking_strategy.h:210
void mark(typename base_type::elem_accessor_type &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:224
the generic attachment-accessor for access to grids attachment pipes.
Definition: grid.h:182
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
SmartPtr< DoFDistribution > dof_distribution()
Definition: grid_function.h:236
Abstract base class for element marking (in adaptive refinement)
Definition: error_elem_marking_strategy.h:125
static const int dim
world dimension
Definition: error_elem_marking_strategy.h:128
IElementMarkingStrategy()
Definition: error_elem_marking_strategy.h:134
virtual void mark(elem_accessor_type &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)=0
DEPRECATED:
void mark(IMultigridElementIndicators< TDomain > &mgElemIndicators, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
This function marks all elements.
Definition: error_elem_marking_strategy.h:141
Grid::AttachmentAccessor< elem_type, ug::Attachment< number > > elem_accessor_type
Definition: error_elem_marking_strategy.h:132
domain_traits< dim >::element_type elem_type
element type to be marked
Definition: error_elem_marking_strategy.h:131
number m_latest_error
Definition: error_elem_marking_strategy.h:155
number m_latest_error_per_elem_max
Definition: error_elem_marking_strategy.h:156
number global_estimated_error_per_elem_max() const
Definition: error_elem_marking_strategy.h:161
virtual ~IElementMarkingStrategy()
Definition: error_elem_marking_strategy.h:137
number global_estimated_error_per_elem_min() const
Definition: error_elem_marking_strategy.h:162
number m_latest_error_per_elem_min
Definition: error_elem_marking_strategy.h:157
number global_estimated_error() const
Definition: error_elem_marking_strategy.h:160
This class encapsulates the multi-grid attachments for error estimation.
Definition: error_elem_marking_strategy.h:54
Attachment< number > error_attachment_type
Definition: error_elem_marking_strategy.h:60
static const int dim
world dimension
Definition: error_elem_marking_strategy.h:57
domain_traits< dim >::element_type elem_type
Definition: error_elem_marking_strategy.h:59
IMultigridElementIndicators()
CTOR.
Definition: error_elem_marking_strategy.h:64
SmartPtr< MultiGrid > m_pMG
Definition: error_elem_marking_strategy.h:112
attachment_accessor_type & errors()
Definition: error_elem_marking_strategy.h:108
attachment_accessor_type m_aaError
Definition: error_elem_marking_strategy.h:114
const number & error(typename attachment_accessor_type::atraits::ConstElemPtr pElem) const
returns error indicator value
Definition: error_elem_marking_strategy.h:99
~IMultigridElementIndicators()
DTOR.
Definition: error_elem_marking_strategy.h:67
error_attachment_type m_aError
Definition: error_elem_marking_strategy.h:113
void attach_indicators(SmartPtr< MultiGrid > pMG)
Attach error indicator to multigrid.
Definition: error_elem_marking_strategy.h:73
MultiGrid::AttachmentAccessor< elem_type, error_attachment_type > attachment_accessor_type
Definition: error_elem_marking_strategy.h:61
void detach_indicators()
Detach error indicator from multigrid.
Definition: error_elem_marking_strategy.h:86
number & error(typename attachment_accessor_type::atraits::ConstElemPtr pElem)
returns error indicator value
Definition: error_elem_marking_strategy.h:95
The refiner interface allows to mark elements for refinement and to call refine.
Definition: refiner_interface.h:67
bool coarsen()
Performs coarsening on the elements marked RM_COARSEN.
Definition: refiner_interface.cpp:162
virtual bool mark(Vertex *v, RefinementMark refMark=RM_REFINE)
Marks an element for refinement. Default implementation is empty.
Definition: refiner_interface.h:103
virtual Grid * grid()=0
Returns the grid associated with the refiner.
Definition: error_elem_marking_strategy.h:626
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:629
int m_max_level
Definition: error_elem_marking_strategy.h:648
void set_max_level(int lvl)
Definition: error_elem_marking_strategy.h:641
int m_min_level
Definition: error_elem_marking_strategy.h:648
MaximumMarking(number theta_max, number theta_min, number eps)
Definition: error_elem_marking_strategy.h:634
MaximumMarking(number theta=1.0)
Definition: error_elem_marking_strategy.h:630
number m_eps
Definition: error_elem_marking_strategy.h:647
number m_theta_min
Definition: error_elem_marking_strategy.h:646
MaximumMarking(number theta, number eps)
Definition: error_elem_marking_strategy.h:632
void mark(typename base_type::elem_accessor_type &aaErrorSq, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:654
void set_min_level(int lvl)
Definition: error_elem_marking_strategy.h:642
number m_theta
Definition: error_elem_marking_strategy.h:646
Definition: error_elem_marking_strategy.h:1271
number m_factor
Definition: error_elem_marking_strategy.h:1284
MeanValueMarking(number theta, number factor)
Definition: error_elem_marking_strategy.h:1275
void mark(typename base_type::elem_accessor_type &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:1288
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:1274
number m_theta
Definition: error_elem_marking_strategy.h:1283
M. Breit's standard coarsening strategy.
Definition: error_elem_marking_strategy.h:252
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:255
number m_tol
Definition: error_elem_marking_strategy.h:275
StdCoarseningMarkingStrategy(number tol, number safety, int minLvl)
Definition: error_elem_marking_strategy.h:263
number m_safety
Definition: error_elem_marking_strategy.h:276
StdCoarseningMarkingStrategy(number tol)
Definition: error_elem_marking_strategy.h:257
int m_minLvl
Definition: error_elem_marking_strategy.h:277
void set_safety_factor(number safety)
Definition: error_elem_marking_strategy.h:267
void set_tolerance(number tol)
Definition: error_elem_marking_strategy.h:266
StdCoarseningMarkingStrategy(number tol, number safety)
Definition: error_elem_marking_strategy.h:260
void mark(typename base_type::elem_accessor_type &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:281
M. Breit's standard refinement strategy.
Definition: error_elem_marking_strategy.h:168
StdRefinementMarkingStrategy(number tol, int max_level)
Definition: error_elem_marking_strategy.h:173
int m_max_level
Definition: error_elem_marking_strategy.h:185
void set_tolerance(number tol)
Definition: error_elem_marking_strategy.h:176
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:171
number m_tol
Definition: error_elem_marking_strategy.h:184
void set_max_level(int max_level)
Definition: error_elem_marking_strategy.h:177
void mark(typename base_type::elem_accessor_type &aaError, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:189
Const iterator to traverse the surface of a multi-grid hierarchy.
Definition: surface_view.h:237
Marks elements above a certain threshold for refinement.
Definition: error_elem_marking_strategy.h:1110
VarianceMarkingEta(number theta, number width)
Definition: error_elem_marking_strategy.h:1117
number m_theta_coarse
Definition: error_elem_marking_strategy.h:1140
void init_coarsening(number theta, int min_level)
Definition: error_elem_marking_strategy.h:1127
VarianceMarkingEta(number theta)
Definition: error_elem_marking_strategy.h:1114
number m_width
Definition: error_elem_marking_strategy.h:1137
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:1113
number m_theta
Definition: error_elem_marking_strategy.h:1136
VarianceMarkingEta(number theta, number width, number theta_coarse)
Definition: error_elem_marking_strategy.h:1120
void mark(typename base_type::elem_accessor_type &aaError2, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:1145
void init_refinement(number theta, int max_level)
Definition: error_elem_marking_strategy.h:1124
int m_min_level
Definition: error_elem_marking_strategy.h:1141
int m_max_level
Definition: error_elem_marking_strategy.h:1138
Definition: error_elem_marking_strategy.h:976
int m_max_level
Definition: error_elem_marking_strategy.h:991
number m_width
Definition: error_elem_marking_strategy.h:990
VarianceMarking(number theta)
Definition: error_elem_marking_strategy.h:980
void mark(typename base_type::elem_accessor_type &aaError2, IRefiner &refiner, ConstSmartPtr< DoFDistribution > dd)
DEPRECATED:
Definition: error_elem_marking_strategy.h:995
number m_theta
Definition: error_elem_marking_strategy.h:989
VarianceMarking(number theta, number width)
Definition: error_elem_marking_strategy.h:981
IElementMarkingStrategy< TDomain > base_type
Definition: error_elem_marking_strategy.h:979
const void * ConstElemPtr
Definition: attachment_pipe.h:309
std::string ElementDebugInfo(const Grid &grid, GridObject *e)
Returns a string containing information on the given element.
Definition: debug_util.cpp:991
@ 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
int NumProcs()
returns the number of processes
Definition: pcl_base.cpp:91
#define PCL_DT_INT
Definition: pcl_datatype.h:51
static const int dim
T * GetDataPtr(std::vector< T > &v)
Returns a pointer to the array which is managed by the std::vector.
Definition: vector_util.h:51
#define UG_LOG_ALL_PROCS(msg)
Definition: log.h:371
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_LOG(msg)
Definition: log.h:367
#define UG_LOGN(msg)
Definition: log.h:369
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
the ug namespace
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
number CreateListOfElemWeights(Grid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError, typename DoFDistribution::traits< TElem >::const_iterator iterBegin, const typename DoFDistribution::traits< TElem >::const_iterator iterEnd, std::vector< double > &etaSq)
Definition: error_elem_marking_strategy.h:291
number CreateSortedListOfElems(Grid::AttachmentAccessor< TElem, ug::Attachment< number > > &aaError, typename DoFDistribution::traits< TElem >::const_iterator iterBegin, const typename DoFDistribution::traits< TElem >::const_iterator iterEnd, std::vector< std::pair< double, TElem * > > &etaSqList)
Definition: error_elem_marking_strategy.h:321
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 MarkForCoarsenening_SurfaceLayer(const GridFunction< TDomain, TAlgebra > &u, IRefiner &refiner)
Mark surface layer for coarsening.
Definition: error_elem_marking_strategy.h:1439
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
Definition: error_elem_marking_strategy.h:391
Grid::AttachmentAccessor< elem_type, ug::Attachment< number > > error_accessor_type
Definition: error_elem_marking_strategy.h:393
const error_accessor_type & m_aaErr
Definition: error_elem_marking_strategy.h:402
ElemErrorSortDesc(const error_accessor_type &aaErr)
Definition: error_elem_marking_strategy.h:394
domain_traits< TDomain::dim >::element_type elem_type
Definition: error_elem_marking_strategy.h:392
bool operator()(const elem_type *elem1, const elem_type *elem2)
Definition: error_elem_marking_strategy.h:397
Definition: domain_traits.h:53