www.mooseframework.org
MooseVariableBase.h
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 #pragma once
11 
12 #include "MooseObject.h"
13 #include "BlockRestrictable.h"
14 #include "OutputInterface.h"
15 #include "SetupInterface.h"
16 #include "MooseTypes.h"
17 #include "MooseArray.h"
18 #include "MooseError.h"
19 
20 #include "libmesh/fe_type.h"
21 #include "libmesh/enum_fe_family.h"
22 
23 // libMesh forward declarations
24 namespace libMesh
25 {
26 class DofMap;
27 class Variable;
28 }
29 
30 class Assembly;
31 class SubProblem;
32 class SystemBase;
33 class MooseMesh;
34 
36  public BlockRestrictable,
37  public OutputInterface,
38  public SetupInterface
39 {
40 public:
42 
44 
49  unsigned int number() const { return _var_num; }
50 
54  const FEType & feType() const { return _fe_type; }
55 
59  SystemBase & sys() { return _sys; }
60 
64  const SystemBase & sys() const { return _sys; }
65 
69  const std::string & name() const override { return _var_name; }
70 
74  bool useDual() const { return _use_dual; }
75 
79  const std::vector<dof_id_type> & allDofIndices() const;
80  unsigned int totalVarDofs() { return allDofIndices().size(); }
81 
85  Moose::VarKindType kind() const { return _var_kind; }
86 
90  void scalingFactor(const std::vector<Real> & factor);
91 
95  Real scalingFactor() const { return _scaling_factor[0]; }
96  const std::vector<Real> & arrayScalingFactor() const { return _scaling_factor; }
97 
102  Order order() const;
103 
108  unsigned int count() const { return _count; }
109 
114  virtual bool isNodal() const { mooseError("Base class cannot determine this"); }
115 
120  virtual bool hasDoFsOnNodes() const { mooseError("Base class cannot determine this"); };
121 
125  virtual FEContinuity getContinuity() const { mooseError("Base class cannot determine this"); };
126 
130  const DofMap & dofMap() const { return _dof_map; }
131 
132  virtual void getDofIndices(const Elem * /*elem*/,
133  std::vector<dof_id_type> & /*dof_indices*/) const
134  {
135  mooseError("not implemented");
136  };
137 
141  virtual const std::vector<dof_id_type> & dofIndices() const { return _dof_indices; }
142 
146  std::vector<dof_id_type> componentDofIndices(const std::vector<dof_id_type> & dof_indices,
147  unsigned int component) const;
148 
152  virtual unsigned int numberOfDofs() const { return _dof_indices.size(); }
153 
157  bool eigen() const { return _is_eigen; }
158 
162  void eigen(bool eigen) { _is_eigen = eigen; }
163 
164  void initialSetup() override;
165 
166  virtual void clearAllDofIndices() { _dof_indices.clear(); }
167 
173  virtual void setActiveTags(const std::set<TagID> & vtags);
174 
178  bool isArray() const { return _is_array; }
179 
183  bool isLowerD() const { return _is_lower_d; }
184 
185 protected:
189  bool doDerivatives() const;
190 
193 
195  FEType _fe_type;
196 
198  unsigned int _var_num;
199 
201  unsigned int _index;
202 
204  bool _is_eigen;
205 
208 
211 
213  const Variable & _variable;
214 
217 
219  const DofMap & _dof_map;
220 
222  std::vector<dof_id_type> _dof_indices;
223 
226 
229 
231  const unsigned int _count;
232 
234  std::vector<Real> _scaling_factor;
235 
237  std::string _var_name;
238 
240  bool _use_dual;
241 
243  const bool _is_array;
244 
247 };
248 
249 inline void
250 MooseVariableBase::setActiveTags(const std::set<TagID> &)
251 {
252  mooseError("setActiveTags must be overridden in derived classes.");
253 }
254 
255 #define usingMooseVariableBaseMembers \
256  using MooseVariableBase::_sys; \
257  using MooseVariableBase::_fe_type; \
258  using MooseVariableBase::_var_num; \
259  using MooseVariableBase::_index; \
260  using MooseVariableBase::_var_kind; \
261  using MooseVariableBase::_subproblem; \
262  using MooseVariableBase::_variable; \
263  using MooseVariableBase::_assembly; \
264  using MooseVariableBase::_dof_map; \
265  using MooseVariableBase::_dof_indices; \
266  using MooseVariableBase::_mesh; \
267  using MooseVariableBase::_tid; \
268  using MooseVariableBase::_count; \
269  using MooseVariableBase::_scaling_factor; \
270  using MooseVariableBase::_var_name
bool _use_dual
If dual mortar approach is used.
static InputParameters validParams()
virtual bool isNodal() const
Is this variable nodal.
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.
virtual void clearAllDofIndices()
Order
FEType _fe_type
The FEType associated with this variable.
virtual unsigned int numberOfDofs() const
Get the number of local DoFs.
Keeps track of stuff related to assembling.
Definition: Assembly.h:93
const DofMap & _dof_map
DOF map.
const std::vector< Real > & arrayScalingFactor() const
unsigned int number() const
Get variable number coming from libMesh.
bool _is_lower_d
Whether this variable lives on lower dimensional blocks.
const SystemBase & sys() const
Get the system this variable is part of.
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one...
A class to provide an common interface to objects requiring "outputs" option.
const std::string & name() const override
Get the variable name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Variable & _variable
libMesh variable object for this variable
virtual void getDofIndices(const Elem *, std::vector< dof_id_type > &) const
std::string _var_name
Variable name.
void eigen(bool eigen)
Mark this variable as an eigen var or non-eigen var.
unsigned int _index
variable number within MOOSE
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Base class for a system (of equations)
Definition: SystemBase.h:84
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
const FEType & feType() const
Get the type of finite element object.
THREAD_ID _tid
Thread ID.
std::vector< dof_id_type > _dof_indices
DOF indices.
bool eigen() const
Whether or not this variable operates on an eigen kernel.
virtual bool hasDoFsOnNodes() const
Does this variable have DoFs on nodes.
bool _is_eigen
Whether or not this variable operates on eigen kernels.
bool useDual() const
Get dual mortar option.
SubProblem & _subproblem
Problem this variable is part of.
virtual FEContinuity getContinuity() const
Return the continuity of this variable.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
SystemBase & _sys
System this variable is part of.
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:627
std::vector< Real > _scaling_factor
scaling factor for this variable
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
Moose::VarKindType _var_kind
Variable type (see MooseTypes.h)
Real scalingFactor() const
Get the scaling factor for this variable.
const unsigned int _count
Number of variables in the array.
const DofMap & dofMap() const
The DofMap associated with the system this variable is in.
MooseMesh & _mesh
mesh the variable is active in
Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:75
Assembly & _assembly
Assembly data.
FEContinuity
const std::vector< dof_id_type > & allDofIndices() const
Get all global dofindices for the variable.
unsigned int _var_num
variable number (from libMesh)
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
unsigned int totalVarDofs()
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
const bool _is_array
Whether this is an array variable.
bool doDerivatives() const
SystemBase & sys()
Get the system this variable is part of.
MooseVariableBase(const InputParameters &parameters)
unsigned int THREAD_ID
Definition: MooseTypes.h:198
virtual void setActiveTags(const std::set< TagID > &vtags)
Set the active vector tags.