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