www.mooseframework.org
ErrorFractionMarker.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "ErrorFractionMarker.h"
11 
12 #include "libmesh/error_vector.h"
13 
15 
16 template <>
19 {
21  params.addRangeCheckedParam<Real>("coarsen",
22  0,
23  "coarsen>=0 & coarsen<=1",
24  "Elements within this percentage of the min error "
25  "will be coarsened. Must be between 0 and 1!");
26  params.addRangeCheckedParam<Real>("refine",
27  0,
28  "refine>=0 & refine<=1",
29  "Elements within this percentage of the max error will "
30  "be refined. Must be between 0 and 1!");
31 
32  params.addParam<bool>("clear_extremes",
33  true,
34  "Whether or not to clear the extremes during each error calculation. "
35  " Changing this to `false` will result in the global extremes ever "
36  "encountered during the run to be used as the min and max error.");
37 
38  params.addClassDescription("Marks elements for refinement or coarsening based on the fraction of "
39  "the min/max error from the supplied indicator.");
40  return params;
41 }
42 
44  : IndicatorMarker(parameters),
45  _coarsen(parameters.get<Real>("coarsen")),
46  _refine(parameters.get<Real>("refine")),
47  _clear_extremes(parameters.get<bool>("clear_extremes")),
48  _max(0),
49  _min(std::numeric_limits<Real>::max())
50 {
51 }
52 
53 void
55 {
56  if (_clear_extremes)
57  {
58  _min = std::numeric_limits<Real>::max();
59  _max = 0;
60  }
61 
62  // First find the max and min error
63  for (const auto & val : _error_vector)
64  {
65  _min = std::min(_min, static_cast<Real>(val));
66  _max = std::max(_max, static_cast<Real>(val));
67  }
68 
69  _delta = _max - _min;
70  _refine_cutoff = (1.0 - _refine) * _max;
72 }
73 
76 {
77  Real error = _error_vector[_current_elem->id()];
78 
79  if (error > _refine_cutoff)
80  return REFINE;
81  else if (error < _coarsen_cutoff)
82  return COARSEN;
83 
84  return DO_NOTHING;
85 }
virtual MarkerValue computeElementMarker() override
InputParameters validParams< ErrorFractionMarker >()
ErrorFractionMarker(const InputParameters &parameters)
const Elem *const & _current_elem
Definition: Marker.h:115
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:55
registerMooseObject("MooseApp", ErrorFractionMarker)
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)