www.mooseframework.org
ErrorFractionMarker.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "ErrorFractionMarker.h"
16 
17 #include "libmesh/error_vector.h"
18 
19 template <>
22 {
24  params.addRangeCheckedParam<Real>("coarsen",
25  0,
26  "coarsen>=0 & coarsen<=1",
27  "Elements within this percentage of the min error "
28  "will be coarsened. Must be between 0 and 1!");
29  params.addRangeCheckedParam<Real>("refine",
30  0,
31  "refine>=0 & refine<=1",
32  "Elements within this percentage of the max error will "
33  "be refined. Must be between 0 and 1!");
34 
35  params.addParam<bool>("clear_extremes",
36  true,
37  "Whether or not to clear the extremes during each error calculation. "
38  " Changing this to `false` will result in the global extremes ever "
39  "encountered during the run to be used as the min and max error.");
40 
41  params.addClassDescription("Marks elements for refinement or coarsening based on the fraction of "
42  "the min/max error from the supplied indicator.");
43  return params;
44 }
45 
47  : IndicatorMarker(parameters),
48  _coarsen(parameters.get<Real>("coarsen")),
49  _refine(parameters.get<Real>("refine")),
50  _clear_extremes(parameters.get<bool>("clear_extremes")),
51  _max(0),
52  _min(std::numeric_limits<Real>::max())
53 {
54 }
55 
56 void
58 {
59  if (_clear_extremes)
60  {
61  _min = std::numeric_limits<Real>::max();
62  _max = 0;
63  }
64 
65  // First find the max and min error
66  for (const auto & val : _error_vector)
67  {
68  _min = std::min(_min, static_cast<Real>(val));
69  _max = std::max(_max, static_cast<Real>(val));
70  }
71 
72  _delta = _max - _min;
73  _refine_cutoff = (1.0 - _refine) * _max;
75 }
76 
79 {
80  Real error = _error_vector[_current_elem->id()];
81 
82  if (error > _refine_cutoff)
83  return REFINE;
84  else if (error < _coarsen_cutoff)
85  return COARSEN;
86 
87  return DO_NOTHING;
88 }
virtual MarkerValue computeElementMarker() override
InputParameters validParams< ErrorFractionMarker >()
ErrorFractionMarker(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MarkerValue
This mirrors the main refinement flag values in libMesh in Elem::RefinementState but adds "dont_mark"...
Definition: Marker.h:58
const Elem *& _current_elem
Definition: Marker.h:118
InputParameters validParams< IndicatorMarker >()
virtual void markerSetup() override
Is called before any element looping is started so any "global" computation can be done...
ErrorVector & _error_vector
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)