LCOV - code coverage report
Current view: top level - src/markers - ErrorFractionMarker.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 33 34 97.1 %
Date: 2025-07-17 01:28:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       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             : 
      14             : registerMooseObject("MooseApp", ErrorFractionMarker);
      15             : 
      16             : InputParameters
      17       15172 : ErrorFractionMarker::validParams()
      18             : {
      19       15172 :   InputParameters params = IndicatorMarker::validParams();
      20       15172 :   params.addRangeCheckedParam<Real>("coarsen",
      21             :                                     0,
      22             :                                     "coarsen>=0 & coarsen<=1",
      23             :                                     "Elements within this percentage of the min error "
      24             :                                     "will be coarsened.  Must be between 0 and 1!");
      25       15172 :   params.addRangeCheckedParam<Real>("refine",
      26             :                                     0,
      27             :                                     "refine>=0 & refine<=1",
      28             :                                     "Elements within this percentage of the max error will "
      29             :                                     "be refined.  Must be between 0 and 1!");
      30             : 
      31       45516 :   params.addParam<bool>("clear_extremes",
      32       30344 :                         true,
      33             :                         "Whether or not to clear the extremes during each error calculation. "
      34             :                         " Changing this to `false` will result in the global extremes ever "
      35             :                         "encountered during the run to be used as the min and max error.");
      36             : 
      37       15172 :   params.addClassDescription("Marks elements for refinement or coarsening based on the fraction of "
      38             :                              "the min/max error from the supplied indicator.");
      39       15172 :   return params;
      40           0 : }
      41             : 
      42         477 : ErrorFractionMarker::ErrorFractionMarker(const InputParameters & parameters)
      43             :   : IndicatorMarker(parameters),
      44         473 :     _coarsen(parameters.get<Real>("coarsen")),
      45         473 :     _refine(parameters.get<Real>("refine")),
      46         473 :     _clear_extremes(parameters.get<bool>("clear_extremes")),
      47         473 :     _max(0),
      48         950 :     _min(std::numeric_limits<Real>::max())
      49             : {
      50         473 : }
      51             : 
      52             : void
      53        2389 : ErrorFractionMarker::markerSetup()
      54             : {
      55        2389 :   if (_clear_extremes)
      56             :   {
      57        2353 :     _min = std::numeric_limits<Real>::max();
      58        2353 :     _max = 0;
      59             :   }
      60             : 
      61             :   // First find the max and min error
      62     1723793 :   for (const auto & val : _error_vector)
      63             :   {
      64     1721404 :     _min = std::min(_min, static_cast<Real>(val));
      65     1721404 :     _max = std::max(_max, static_cast<Real>(val));
      66             :   }
      67             : 
      68        2389 :   _delta = _max - _min;
      69        2389 :   _refine_cutoff = (1.0 - _refine) * _max;
      70        2389 :   _coarsen_cutoff = _coarsen * _delta + _min;
      71        2389 : }
      72             : 
      73             : Marker::MarkerValue
      74      778609 : ErrorFractionMarker::computeElementMarker()
      75             : {
      76      778609 :   Real error = _error_vector[_current_elem->id()];
      77             : 
      78      778609 :   if (error > _refine_cutoff)
      79      296023 :     return REFINE;
      80      482586 :   else if (error < _coarsen_cutoff)
      81      238493 :     return COARSEN;
      82             : 
      83      244093 :   return DO_NOTHING;
      84             : }

Generated by: LCOV version 1.14