www.mooseframework.org
MooseVariableBase.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 #include "MooseVariableBase.h"
11 #include "SubProblem.h"
12 #include "SystemBase.h"
13 #include "MooseMesh.h"
14 #include "MooseApp.h"
16 
17 #include "libmesh/variable.h"
18 #include "libmesh/dof_map.h"
19 #include "libmesh/system.h"
20 #include "libmesh/fe_type.h"
21 #include "libmesh/string_to_enum.h"
22 
23 // Users should never actually create this object
25 
27 
30 {
33  params += OutputInterface::validParams();
34 
36  "CONSTANT FIRST SECOND THIRD FOURTH FIFTH SIXTH SEVENTH EIGHTH NINTH TENTH ELEVENTH TWELFTH "
37  "THIRTEENTH FOURTEENTH FIFTEENTH SIXTEENTH SEVENTEENTH EIGHTTEENTH NINETEENTH TWENTIETH "
38  "TWENTYFIRST TWENTYSECOND TWENTYTHIRD TWENTYFOURTH TWENTYFIFTH TWENTYSIXTH TWENTYSEVENTH "
39  "TWENTYEIGHTH TWENTYNINTH THIRTIETH THIRTYFIRST THIRTYSECOND THIRTYTHIRD THIRTYFOURTH "
40  "THIRTYFIFTH THIRTYSIXTH THIRTYSEVENTH THIRTYEIGHTH THIRTYNINTH FORTIETH FORTYFIRST "
41  "FORTYSECOND FORTYTHIRD",
42  "FIRST",
43  true);
44  params.addParam<MooseEnum>("order",
45  order,
46  "Order of the FE shape function to use for this variable (additional "
47  "orders not listed here are allowed, depending on the family).");
48 
49  MooseEnum family("LAGRANGE MONOMIAL HERMITE SCALAR HIERARCHIC CLOUGH XYZ SZABAB BERNSTEIN "
50  "L2_LAGRANGE L2_HIERARCHIC NEDELEC_ONE LAGRANGE_VEC MONOMIAL_VEC",
51  "LAGRANGE");
52  params.addParam<MooseEnum>(
53  "family", family, "Specifies the family of FE shape functions to use for this variable.");
54 
55  params.addParam<std::vector<Real>>("initial_condition",
56  "Specifies the initial condition for this variable");
57  // ArrayVariable capability
58  params.addRangeCheckedParam<unsigned int>(
59  "components", 1, "components>0", "Number of components for an array variable");
60 
61  // Advanced input options
62  params.addParam<std::vector<Real>>("scaling",
63  "Specifies a scaling factor to apply to this variable");
64  params.addParam<bool>("eigen", false, "True to make this variable an eigen variable");
65  params.addParamNamesToGroup("scaling eigen", "Advanced");
66 
67  params.registerBase("MooseVariableBase");
68  params.addPrivateParam<SystemBase *>("_system_base");
69  params.addPrivateParam<FEProblemBase *>("_fe_problem_base");
70  params.addPrivateParam<Moose::VarKindType>("_var_kind");
71  params.addPrivateParam<unsigned int>("_var_num");
72  params.addPrivateParam<THREAD_ID>("tid");
73 
74  params.addClassDescription(
75  "Base class for Moose variables. This should never be the terminal object type");
76  return params;
77 }
78 
80  : MooseObject(parameters),
81  BlockRestrictable(this),
82  OutputInterface(parameters),
83  _sys(*getParam<SystemBase *>("_system_base")), // TODO: get from _fe_problem_base
84  _fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
85  Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))),
86  _var_num(getParam<unsigned int>("_var_num")),
87  _var_kind(getParam<Moose::VarKindType>("_var_kind")),
88  _subproblem(_sys.subproblem()),
89  _variable(_sys.system().variable(_var_num)),
90  _assembly(_subproblem.assembly(getParam<THREAD_ID>("_tid"))),
91  _dof_map(_sys.dofMap()),
92  _mesh(_subproblem.mesh()),
93  _tid(getParam<THREAD_ID>("tid")),
94  _count(getParam<unsigned int>("components")),
95  _scaling_factor(isParamValid("scaling") ? getParam<std::vector<Real>>("scaling")
96  : std::vector<Real>(_count, 1.))
97 {
98  if (_count > 1)
99  {
100  auto name0 = _sys.system().variable(_var_num).name();
101  std::size_t found = name0.find_last_of("_");
102  if (found == std::string::npos)
103  mooseError("Error creating ArrayMooseVariable name with base name ", name0);
104  _var_name = name0.substr(0, found);
105  }
106  else
107  _var_name = _sys.system().variable(_var_num).name();
108 }
109 
110 const std::vector<dof_id_type> &
112 {
113  const auto it = _sys.subproblem()._var_dof_map.find(name());
114  if (it != _sys.subproblem()._var_dof_map.end())
115  return it->second;
116  else
117  mooseError("VariableAllDoFMap not prepared for ",
118  name(),
119  " . Check nonlocal coupling requirement for the variable.");
120 }
121 
122 Order
124 {
125  return _fe_type.order;
126 }
127 
128 std::vector<dof_id_type>
129 MooseVariableBase::componentDofIndices(const std::vector<dof_id_type> & dof_indices,
130  unsigned int component) const
131 {
132  std::vector<dof_id_type> new_dof_indices(dof_indices);
133  if (component != 0)
134  {
135  if (isNodal())
136  for (auto & id : new_dof_indices)
137  id += component;
138  else
139  {
140  unsigned int n = dof_indices.size();
141  for (auto & id : new_dof_indices)
142  id += component * n;
143  }
144  }
145  return new_dof_indices;
146 }
Moose
Definition: Moose.h:116
SubProblem::_var_dof_map
std::map< std::string, std::vector< dof_id_type > > _var_dof_map
Definition: SubProblem.h:586
MooseObject::validParams
static InputParameters validParams()
Definition: MooseObject.C:35
THREAD_ID
unsigned int THREAD_ID
Definition: MooseTypes.h:196
MooseMesh.h
SystemBase.h
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
MooseEnum
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
MooseVariableBase::MooseVariableBase
MooseVariableBase(const InputParameters &parameters)
Definition: MooseVariableBase.C:79
MooseVariableBase::_fe_type
FEType _fe_type
The FEType associated with this variable.
Definition: MooseVariableBase.h:132
BlockRestrictable::validParams
static InputParameters validParams()
Definition: BlockRestrictable.C:23
SystemBase::system
virtual System & system()=0
Get the reference to the libMesh system.
InputParameters::addParam
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.
Definition: InputParameters.h:1198
InputParameters::registerBase
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
Definition: InputParameters.C:330
OutputInterface
A class to provide an common interface to objects requiring "outputs" option.
Definition: OutputInterface.h:37
MooseObject
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:50
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
MooseVariableBase::_count
const unsigned int _count
Number of variables in the array.
Definition: MooseVariableBase.h:165
SystemBase::subproblem
virtual SubProblem & subproblem()
Definition: SystemBase.h:108
MooseVariableBase::allDofIndices
const std::vector< dof_id_type > & allDofIndices() const
Get all global dofindices for the variable.
Definition: MooseVariableBase.C:111
MooseVariableBase::_var_num
unsigned int _var_num
variable number (from libMesh)
Definition: MooseVariableBase.h:135
MooseVariableBase::order
Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int.
Definition: MooseVariableBase.C:123
MooseVariableBase::_var_name
std::string _var_name
Variable name.
Definition: MooseVariableBase.h:171
MooseApp.h
InputParameters::addClassDescription
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.
Definition: InputParameters.C:70
SubProblem.h
MooseVariableBase::_sys
SystemBase & _sys
System this variable is part of.
Definition: MooseVariableBase.h:129
InputParameters::addRangeCheckedParam
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
Definition: InputParameters.h:1245
InputParameterWarehouse.h
registerMooseObject
registerMooseObject("MooseApp", MooseVariableBase)
defineLegacyParams
defineLegacyParams(MooseVariableBase)
Moose::VarKindType
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:606
InputParameters::addParamNamesToGroup
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
Definition: InputParameters.C:590
MooseVariableBase::validParams
static InputParameters validParams()
Definition: MooseVariableBase.C:29
std
Definition: TheWarehouse.h:80
BlockRestrictable
An interface that restricts an object to subdomains via the 'blocks' input parameter.
Definition: BlockRestrictable.h:61
SystemBase
Base class for a system (of equations)
Definition: SystemBase.h:95
MooseVariableBase::componentDofIndices
std::vector< dof_id_type > componentDofIndices(const std::vector< dof_id_type > &dof_indices, unsigned int component) const
Obtain DoF indices of a component with the indices of the 0th component.
Definition: MooseVariableBase.C:129
MooseVariableBase.h
system
nl system()
Definition: PetscDMMoose.C:1287
MooseVariableBase
Definition: MooseVariableBase.h:37
MooseVariableBase::isNodal
virtual bool isNodal() const
Is this variable nodal.
Definition: MooseVariableBase.h:104
OutputInterface::validParams
static InputParameters validParams()
Definition: OutputInterface.C:20
InputParameters::addPrivateParam
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
Definition: InputParameters.h:1308
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
MooseVariableBase::name
const std::string & name() const override
Get the variable name.
Definition: MooseVariableBase.h:63
n
PetscInt n
Definition: PetscDMMoose.C:1504