https://mooseframework.inl.gov
GreaterThanLessThanPostprocessor.C
Go to the documentation of this file.
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 
11 
12 // MOOSE includes
13 #include "MooseVariable.h"
14 #include "FEProblemBase.h"
15 #include "NonlinearSystemBase.h"
16 #include "MooseMesh.h"
18 
19 #include "libmesh/mesh_base.h"
20 
22 
25 {
27  params.addClassDescription("Count number of DOFs of a non-linear variable that are greater than "
28  "or less than a given threshold");
29  params.addRequiredParam<VariableName>("variable",
30  "The name of the variable to conduct a comparison for");
31  params.addParam<SubdomainName>("subdomain", "The subdomain that the variable lives on");
32  params.addParam<Real>("value", 0, "The value to compare against");
33  MooseEnum comparator("greater less", "greater");
34  params.addParam<MooseEnum>(
35  "comparator",
36  comparator,
37  "The comparison to perform between the variable and the provided value");
38  return params;
39 }
40 
42  const InputParameters & parameters)
43  : GeneralPostprocessor(parameters),
44  _var(_fe_problem.getVariable(_tid,
45  getParam<VariableName>("variable"),
48  _mesh(_fe_problem.mesh().getMesh()),
49  _subdomain_restricted(isParamValid("subdomain")),
50  _subdomain_id(_subdomain_restricted
51  ? _fe_problem.mesh().getSubdomainID(getParam<SubdomainName>("subdomain"))
53  _value(getParam<Real>("value")),
54  _comparator(getParam<MooseEnum>("comparator"))
55 {
56 }
57 
58 void
60 {
61  _count = 0;
62 }
63 
64 void
66 {
68 
70  {
71  ConstElemRange range(_mesh.active_local_subdomain_elements_begin(_subdomain_id),
72  _mesh.active_local_subdomain_elements_end(_subdomain_id));
73 
74  Threads::parallel_reduce(range, aldit);
75  }
76  else
77  {
78  ConstElemRange range(_mesh.active_local_elements_begin(), _mesh.active_local_elements_end());
79 
80  Threads::parallel_reduce(range, aldit);
81  }
82 
83  const auto & solution = _fe_problem.getNonlinearSystemBase(_sys.number()).solution();
84 
85  if (_comparator == "greater")
86  {
87  for (auto dof : aldit.getDofIndices())
88  if (solution(dof) > _value)
89  ++_count;
90  }
91  else if (_comparator == "less")
92  {
93  for (auto dof : aldit.getDofIndices())
94  if (solution(dof) < _value)
95  ++_count;
96  }
97  else
98  mooseError("Invalid comparator ", _comparator);
99 }
100 
103 {
104  return _count;
105 }
106 
107 void
109 {
110  gatherSum(_count);
111 }
VarFieldType
Definition: MooseTypes.h:722
const SubdomainID _subdomain_id
An optional subdomain over which to query degrees of freedom.
MeshBase & mesh
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
unsigned int _count
Represents the number of values in contact.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
const MeshBase & _mesh
The libmesh mesh.
const Real _value
The tolerance used to decide whether the variable indicates contact.
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:20
Grab all the (possibly semi)local dof indices for the variables passed in, in the system passed in...
static InputParameters validParams()
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
Definition: UserObject.h:126
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:715
Real PostprocessorValue
various MOOSE typedefs
Definition: MooseTypes.h:202
const bool _subdomain_restricted
Whether we are subdomain restricting the active set search.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
SystemBase & _sys
Reference to the system object for this user object.
Definition: UserObject.h:215
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1149
const MooseVariableFEBase & _var
MOOSE variable we compute the contact set from.
virtual void execute() override
Execute method.
registerMooseObject("MooseApp", GreaterThanLessThanPostprocessor)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
GreaterThanLessThanPostprocessor(const InputParameters &parameters)
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:211
const MooseEnum _comparator
The comparison to perform.
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual PostprocessorValue getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.