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 
19 template <>
22 {
24 
25  MooseEnum system_enum("NL AUX ALL", "ALL");
26  params.addParam<MooseEnum>("system",
27  system_enum,
28  "The system(s) for which you want to retrieve the number of variables "
29  "(NL, AUX, ALL). Default == ALL");
30 
31  params.addClassDescription(
32  "Return the number of variables from either the NL, Aux, or both systems.");
33 
34  return params;
35 }
36 
37 NumVars::NumVars(const InputParameters & parameters)
38  : GeneralPostprocessor(parameters),
39  _system_enum(parameters.get<MooseEnum>("system").getEnum<SystemEnum>()),
40  _system_pointer(nullptr),
41  _es_pointer(nullptr)
42 {
43  switch (_system_enum)
44  {
45  case NL:
46  mooseAssert(_subproblem.es().has_system("nl0"), "No Nonlinear System found with name nl0");
47  _system_pointer = &_subproblem.es().get_system("nl0");
48  break;
49  case AUX:
50  mooseAssert(_subproblem.es().has_system("aux0"), "No Auxilary System found with name aux0");
51  _system_pointer = &_subproblem.es().get_system("aux0");
52  break;
53  case ALL:
55  break;
56  default:
57  mooseError("Unhandled enum");
58  }
59 }
60 
61 Real
63 {
64  switch (_system_enum)
65  {
66  case NL:
67  case AUX:
68  return _system_pointer->n_vars();
69  case ALL:
70  return _es_pointer->n_vars();
71  default:
72  return 0;
73  }
74 }
const SystemEnum _system_enum
Definition: NumVars.h:39
virtual Real getValue() override
This will get called to actually grab the final value the postprocessor has calculated.
Definition: NumVars.C:62
const System * _system_pointer
Definition: NumVars.h:41
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< GeneralPostprocessor >()
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
SystemEnum
Definition: NumVars.h:32
virtual EquationSystems & es()=0
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:138
registerMooseObject("MooseApp", NumVars)
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:37
InputParameters validParams< NumVars >()
Definition: NumVars.C:21
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:42