https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"),
46 Moose::VarKindType::VAR_SOLVER,
47 Moose::VarFieldType::VAR_FIELD_STANDARD)),
48 _mesh(_fe_problem.mesh().getMesh()),
49 _subdomain_restricted(isParamValid("subdomain")),
50 _subdomain_id(_subdomain_restricted
51 ? _fe_problem.mesh().getSubdomainID(getParam<SubdomainName>("subdomain"))
52 : Moose::INVALID_BLOCK_ID),
53 _value(getParam<Real>("value")),
54 _comparator(getParam<MooseEnum>("comparator"))
55{
56}
57
58void
63
64void
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
106
107void
registerMooseObject("MooseApp", GreaterThanLessThanPostprocessor)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Real PostprocessorValue
various MOOSE typedefs
Definition MooseTypes.h:230
Grab all the (possibly semi)local dof indices for the variables passed in, in the system passed in.
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
static InputParameters validParams()
virtual PostprocessorValue getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
const SubdomainID _subdomain_id
An optional subdomain over which to query degrees of freedom.
const Real _value
The tolerance used to decide whether the variable indicates contact.
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.
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
const MooseVariableFEBase & _var
MOOSE variable we compute the contact set from.
GreaterThanLessThanPostprocessor(const InputParameters &parameters)
const bool _subdomain_restricted
Whether we are subdomain restricting the active set search.
const MooseEnum _comparator
The comparison to perform.
virtual void execute() override
Execute method.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
unsigned int number() const
Gets the number of this system.
NumericVector< Number > & solution()
Definition SystemBase.h:203
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
SystemBase & _sys
Reference to the system object for this user object.
MeshBase & mesh
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())