LCOV - code coverage report
Current view: top level - src/markers - ErrorFractionLookAheadMarker.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: be601f Lines: 29 30 96.7 %
Date: 2025-07-15 20:50:38 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /********************************************************************/
       2             : /*                  SOFTWARE COPYRIGHT NOTIFICATION                 */
       3             : /*                             Cardinal                             */
       4             : /*                                                                  */
       5             : /*                  (c) 2021 UChicago Argonne, LLC                  */
       6             : /*                        ALL RIGHTS RESERVED                       */
       7             : /*                                                                  */
       8             : /*                 Prepared by UChicago Argonne, LLC                */
       9             : /*               Under Contract No. DE-AC02-06CH11357               */
      10             : /*                With the U. S. Department of Energy               */
      11             : /*                                                                  */
      12             : /*             Prepared by Battelle Energy Alliance, LLC            */
      13             : /*               Under Contract No. DE-AC07-05ID14517               */
      14             : /*                With the U. S. Department of Energy               */
      15             : /*                                                                  */
      16             : /*                 See LICENSE for full restrictions                */
      17             : /********************************************************************/
      18             : 
      19             : #include "ErrorFractionLookAheadMarker.h"
      20             : 
      21             : #include "libmesh/error_vector.h"
      22             : 
      23             : registerMooseObject("MooseApp", ErrorFractionLookAheadMarker);
      24             : 
      25             : InputParameters
      26           4 : ErrorFractionLookAheadMarker::validParams()
      27             : {
      28           4 :   InputParameters params = ErrorFractionMarker::validParams();
      29           4 :   params.addClassDescription(
      30             :       "Marks elements for refinement or coarsening based on the fraction of "
      31             :       "the min/max error from the supplied indicator and the relative error of a tally value.");
      32           8 :   params.addRequiredRangeCheckedParam<Real>(
      33             :       "rel_error_refine", "0 <= rel_error_refine <= 1", "The relative error refinement threshold.");
      34           8 :   params.addRequiredParam<IndicatorName>(
      35             :       "stat_error_indicator",
      36             :       "The name of the statistical relative error Indicator that this Marker uses.");
      37             : 
      38           4 :   return params;
      39           0 : }
      40             : 
      41           2 : ErrorFractionLookAheadMarker::ErrorFractionLookAheadMarker(const InputParameters & parameters)
      42             :   : ErrorFractionMarker(parameters),
      43           2 :     _rel_error_limit(getParam<Real>("rel_error_refine")),
      44           4 :     _rel_error_vec(getErrorVector(parameters.get<IndicatorName>("stat_error_indicator")))
      45             : {
      46           2 : }
      47             : 
      48             : void
      49           2 : ErrorFractionLookAheadMarker::markerSetup()
      50             : {
      51           2 :   if (_clear_extremes)
      52             :   {
      53           2 :     _min = std::numeric_limits<Real>::max();
      54           2 :     _max = 0;
      55             :   }
      56             : 
      57             :   // First find the max and min error
      58         514 :   for (unsigned int i = 0; i < _rel_error_vec.size(); ++i)
      59             :   {
      60             :     // Initial pruning step: elements only contribute to the min/max spatial
      61             :     // error if their relative errors are sufficiently low.
      62         512 :     if (_rel_error_vec[i] < _rel_error_limit)
      63             :     {
      64         230 :       _min = std::min(_min, static_cast<Real>(_error_vector[i]));
      65         240 :       _max = std::max(_max, static_cast<Real>(_error_vector[i]));
      66             :     }
      67             :   }
      68             : 
      69           2 :   _delta = _max - _min;
      70           2 :   _refine_cutoff = (1.0 - _refine) * _max;
      71           2 :   _coarsen_cutoff = _coarsen * _delta + _min;
      72           2 : }
      73             : 
      74             : Marker::MarkerValue
      75         512 : ErrorFractionLookAheadMarker::computeElementMarker()
      76             : {
      77             :   // Lookahead statistical error in an element.
      78         512 :   Real m = std::sqrt(_current_elem->n_children());
      79         512 :   Real stat_error = _rel_error_vec[_current_elem->id()];
      80             : 
      81             :   // Spatial error in an element.
      82         512 :   Real error = _error_vector[_current_elem->id()];
      83             : 
      84         512 :   if (error > _refine_cutoff && (stat_error * m) <= _rel_error_limit)
      85             :     return REFINE;
      86         512 :   else if (error < _coarsen_cutoff || stat_error > _rel_error_limit)
      87         282 :     return COARSEN;
      88             : 
      89             :   // Goldilocks zone, do nothing.
      90             :   return DO_NOTHING;
      91             : }

Generated by: LCOV version 1.14