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 15225 : GreaterThanLessThanPostprocessor::validParams() 25 : { 26 15225 : InputParameters params = GeneralPostprocessor::validParams(); 27 15225 : params.addClassDescription("Count number of DOFs of a non-linear variable that are greater than " 28 : "or less than a given threshold"); 29 15225 : params.addRequiredParam<VariableName>("variable", 30 : "The name of the variable to conduct a comparison for"); 31 15225 : params.addParam<SubdomainName>("subdomain", "The subdomain that the variable lives on"); 32 15225 : params.addParam<Real>("value", 0, "The value to compare against"); 33 15225 : MooseEnum comparator("greater less", "greater"); 34 15225 : params.addParam<MooseEnum>( 35 : "comparator", 36 : comparator, 37 : "The comparison to perform between the variable and the provided value"); 38 30450 : return params; 39 15225 : } 40 : 41 480 : GreaterThanLessThanPostprocessor::GreaterThanLessThanPostprocessor( 42 480 : const InputParameters & parameters) 43 : : GeneralPostprocessor(parameters), 44 1440 : _var(_fe_problem.getVariable(_tid, 45 480 : getParam<VariableName>("variable"), 46 : Moose::VarKindType::VAR_SOLVER, 47 : Moose::VarFieldType::VAR_FIELD_STANDARD)), 48 480 : _mesh(_fe_problem.mesh().getMesh()), 49 480 : _subdomain_restricted(isParamValid("subdomain")), 50 960 : _subdomain_id(_subdomain_restricted 51 480 : ? _fe_problem.mesh().getSubdomainID(getParam<SubdomainName>("subdomain")) 52 : : Moose::INVALID_BLOCK_ID), 53 480 : _value(getParam<Real>("value")), 54 960 : _comparator(getParam<MooseEnum>("comparator")) 55 : { 56 480 : } 57 : 58 : void 59 12608 : GreaterThanLessThanPostprocessor::initialize() 60 : { 61 12608 : _count = 0; 62 12608 : } 63 : 64 : void 65 12608 : GreaterThanLessThanPostprocessor::execute() 66 : { 67 25216 : AllLocalDofIndicesThread aldit(_fe_problem, {_var.name()}); 68 : 69 12608 : 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 12608 : ConstElemRange range(_mesh.active_local_elements_begin(), _mesh.active_local_elements_end()); 79 : 80 12608 : Threads::parallel_reduce(range, aldit); 81 12608 : } 82 : 83 12608 : const auto & solution = _fe_problem.getNonlinearSystemBase(_sys.number()).solution(); 84 : 85 12608 : if (_comparator == "greater") 86 : { 87 537137 : for (auto dof : aldit.getDofIndices()) 88 529170 : if (solution(dof) > _value) 89 48101 : ++_count; 90 : } 91 4641 : else if (_comparator == "less") 92 : { 93 321497 : for (auto dof : aldit.getDofIndices()) 94 316856 : if (solution(dof) < _value) 95 5803 : ++_count; 96 : } 97 : else 98 0 : mooseError("Invalid comparator ", _comparator); 99 25216 : } 100 : 101 : PostprocessorValue 102 12608 : GreaterThanLessThanPostprocessor::getValue() const 103 : { 104 12608 : return _count; 105 : } 106 : 107 : void 108 12608 : GreaterThanLessThanPostprocessor::finalize() 109 : { 110 12608 : gatherSum(_count); 111 12608 : }