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