www.mooseframework.org
NumVars.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 // MOOSE includes
11 #include "NumVars.h"
12 
13 #include "AuxiliarySystem.h"
14 #include "NonlinearSystemBase.h"
15 #include "SubProblem.h"
16 
17 registerMooseObject("MooseApp", NumVars);
18 
21 {
23 
24  MooseEnum system_enum("NL AUX ALL", "ALL");
25  params.addParam<MooseEnum>("system",
26  system_enum,
27  "The system(s) for which you want to retrieve the number of variables "
28  "(NL, AUX, ALL). Default == ALL");
29 
30  params.addClassDescription(
31  "Return the number of variables from either the NL, Aux, or both systems.");
32 
33  return params;
34 }
35 
36 NumVars::NumVars(const InputParameters & parameters)
37  : GeneralPostprocessor(parameters),
38  _system_enum(parameters.get<MooseEnum>("system").getEnum<SystemEnum>()),
39  _system_pointer(nullptr),
40  _es_pointer(nullptr)
41 {
42  switch (_system_enum)
43  {
44  case NL:
45  mooseAssert(_subproblem.es().has_system("nl0"), "No Nonlinear System found with name nl0");
46  _system_pointer = &_subproblem.es().get_system("nl0");
47  break;
48  case AUX:
49  mooseAssert(_subproblem.es().has_system("aux0"), "No Auxilary System found with name aux0");
50  _system_pointer = &_subproblem.es().get_system("aux0");
51  break;
52  case ALL:
54  break;
55  default:
56  mooseError("Unhandled enum");
57  }
58 }
59 
60 Real
62 {
63  switch (_system_enum)
64  {
65  case NL:
66  case AUX:
67  return _system_pointer->n_vars();
68  case ALL:
69  return _es_pointer->n_vars();
70  default:
71  return 0;
72  }
73 }
const SystemEnum _system_enum
Definition: NumVars.h:35
const System * _system_pointer
Definition: NumVars.h:37
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
Definition: NumVars.C:61
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1147
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...
SystemEnum
Definition: NumVars.h:28
virtual EquationSystems & es()=0
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:207
static InputParameters validParams()
registerMooseObject("MooseApp", NumVars)
static InputParameters validParams()
Definition: NumVars.C:20
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
NumVars(const InputParameters &parameters)
Definition: NumVars.C:36
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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 option parameter and a documentation string to the InputParameters object...
const EquationSystems * _es_pointer
Definition: NumVars.h:38