LCOV - code coverage report
Current view: top level - src/postprocessors - GreaterThanLessThanPostprocessor.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 45 50 90.0 %
Date: 2026-05-29 20:35:17 Functions: 6 6 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 "GreaterThanLessThanPostprocessor.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseVariable.h"
      14             : #include "FEProblemBase.h"
      15             : #include "NonlinearSystemBase.h"
      16             : #include "MooseMesh.h"
      17             : #include "AllLocalDofIndicesThread.h"
      18             : 
      19             : #include "libmesh/mesh_base.h"
      20             : 
      21             : registerMooseObject("MooseApp", GreaterThanLessThanPostprocessor);
      22             : 
      23             : InputParameters
      24        4477 : GreaterThanLessThanPostprocessor::validParams()
      25             : {
      26        4477 :   InputParameters params = GeneralPostprocessor::validParams();
      27        8954 :   params.addClassDescription("Count number of DOFs of a non-linear variable that are greater than "
      28             :                              "or less than a given threshold");
      29       17908 :   params.addRequiredParam<VariableName>("variable",
      30             :                                         "The name of the variable to conduct a comparison for");
      31       17908 :   params.addParam<SubdomainName>("subdomain", "The subdomain that the variable lives on");
      32       17908 :   params.addParam<Real>("value", 0, "The value to compare against");
      33       17908 :   MooseEnum comparator("greater less", "greater");
      34       13431 :   params.addParam<MooseEnum>(
      35             :       "comparator",
      36             :       comparator,
      37             :       "The comparison to perform between the variable and the provided value");
      38        8954 :   return params;
      39        4477 : }
      40             : 
      41         708 : GreaterThanLessThanPostprocessor::GreaterThanLessThanPostprocessor(
      42         708 :     const InputParameters & parameters)
      43             :   : GeneralPostprocessor(parameters),
      44        2124 :     _var(_fe_problem.getVariable(_tid,
      45         708 :                                  getParam<VariableName>("variable"),
      46             :                                  Moose::VarKindType::VAR_SOLVER,
      47             :                                  Moose::VarFieldType::VAR_FIELD_STANDARD)),
      48         708 :     _mesh(_fe_problem.mesh().getMesh()),
      49        1416 :     _subdomain_restricted(isParamValid("subdomain")),
      50        1416 :     _subdomain_id(_subdomain_restricted
      51         708 :                       ? _fe_problem.mesh().getSubdomainID(getParam<SubdomainName>("subdomain"))
      52             :                       : Moose::INVALID_BLOCK_ID),
      53        1416 :     _value(getParam<Real>("value")),
      54        2124 :     _comparator(getParam<MooseEnum>("comparator"))
      55             : {
      56         708 : }
      57             : 
      58             : void
      59       19424 : GreaterThanLessThanPostprocessor::initialize()
      60             : {
      61       19424 :   _count = 0;
      62       19424 : }
      63             : 
      64             : void
      65       19424 : GreaterThanLessThanPostprocessor::execute()
      66             : {
      67       58272 :   AllLocalDofIndicesThread aldit(_fe_problem, {_var.name()});
      68             : 
      69       19424 :   if (_subdomain_restricted)
      70             :   {
      71           0 :     ConstElemRange range(_mesh.active_local_subdomain_elements_begin(_subdomain_id),
      72           0 :                          _mesh.active_local_subdomain_elements_end(_subdomain_id));
      73             : 
      74           0 :     Threads::parallel_reduce(range, aldit);
      75           0 :   }
      76             :   else
      77             :   {
      78       19424 :     ConstElemRange range(_mesh.active_local_elements_begin(), _mesh.active_local_elements_end());
      79             : 
      80       19424 :     Threads::parallel_reduce(range, aldit);
      81       19424 :   }
      82             : 
      83       19424 :   const auto & solution = _fe_problem.getNonlinearSystemBase(_sys.number()).solution();
      84             : 
      85       19424 :   if (_comparator == "greater")
      86             :   {
      87      867413 :     for (auto dof : aldit.getDofIndices())
      88      854351 :       if (solution(dof) > _value)
      89       99473 :         ++_count;
      90             :   }
      91        6362 :   else if (_comparator == "less")
      92             :   {
      93      433661 :     for (auto dof : aldit.getDofIndices())
      94      427299 :       if (solution(dof) < _value)
      95        7147 :         ++_count;
      96             :   }
      97             :   else
      98           0 :     mooseError("Invalid comparator ", _comparator);
      99       38848 : }
     100             : 
     101             : PostprocessorValue
     102       19424 : GreaterThanLessThanPostprocessor::getValue() const
     103             : {
     104       19424 :   return _count;
     105             : }
     106             : 
     107             : void
     108       19424 : GreaterThanLessThanPostprocessor::finalize()
     109             : {
     110       19424 :   gatherSum(_count);
     111       19424 : }

Generated by: LCOV version 1.14