https://mooseframework.inl.gov
NumDOFs.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 
10 #include "NumDOFs.h"
11 #include "SubProblem.h"
12 #include "MooseStringUtils.h"
13 
14 #include "libmesh/equation_systems.h"
15 #include "libmesh/system.h"
16 
17 registerMooseObject("MooseApp", NumDOFs);
18 
21 {
23  params.addParam<std::string>(
24  "system",
25  "ALL",
26  "The system for which you want to retrieve the number of DOFs. Use ALL for all systems, "
27  "NL as an alias for nl0, AUX as an alias for aux0, or the name of a specific system.");
28 
29  params.addClassDescription(
30  "Return the number of Degrees of freedom from one or more equation systems.");
31  return params;
32 }
33 
34 NumDOFs::NumDOFs(const InputParameters & parameters)
35  : GeneralPostprocessor(parameters),
36  _all_systems(false),
37  _system_pointer(nullptr),
38  _es_pointer(nullptr)
39 {
40  const auto system_param = getParam<std::string>("system");
41  const auto system_upper = MooseUtils::toUpper(system_param);
42 
43  if (system_upper == "ALL")
44  {
45  _all_systems = true;
47  return;
48  }
49 
50  std::string system_name = system_param;
51  if (system_upper == "NL")
52  system_name = "nl0";
53  else if (system_upper == "AUX")
54  system_name = "aux0";
55 
56  if (!_subproblem.es().has_system(system_name))
57  paramError("system", "No system found with name '", system_name, "'.");
58 
59  _system_pointer = &_subproblem.es().get_system(system_name);
60 }
61 
62 Real
64 {
65  if (_all_systems)
66  return _es_pointer->n_dofs();
67 
68  return _system_pointer->n_dofs();
69 }
registerMooseObject("MooseApp", NumDOFs)
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:467
bool has_system(std::string_view name) const
NumDOFs(const InputParameters &parameters)
Definition: NumDOFs.C:34
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
Definition: NumDOFs.C:63
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...
const T_sys & get_system(std::string_view name) const
const libMesh::System * _system_pointer
Definition: NumDOFs.h:34
dof_id_type n_dofs() const
const EquationSystems * _es_pointer
Definition: NumDOFs.h:35
std::string toUpper(std::string name)
Convert supplied string to upper case.
static InputParameters validParams()
virtual libMesh::EquationSystems & es()=0
bool _all_systems
Definition: NumDOFs.h:33
SubProblem & _subproblem
Reference to the Subproblem for this user object.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...
static InputParameters validParams()
Definition: NumDOFs.C:20
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...