www.mooseframework.org
MooseVariableInterface.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 "MooseVariableInterface.h"
11 
12 #include "Assembly.h"
13 #include "MooseError.h" // mooseDeprecated
14 #include "MooseTypes.h"
15 #include "MooseVariableFE.h"
16 #include "MooseVariableFV.h"
17 #include "Problem.h"
18 #include "SubProblem.h"
19 #include "SystemBase.h"
20 
21 template <typename T>
23  bool nodal,
24  std::string var_param_name,
25  Moose::VarKindType expected_var_type,
26  Moose::VarFieldType expected_var_field_type)
27  : _nodal(nodal), _moose_object(*moose_object)
28 {
29  const InputParameters & parameters = _moose_object.parameters();
30 
31  SubProblem & problem = *parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
32 
33  THREAD_ID tid = parameters.get<THREAD_ID>("_tid");
34 
35  _var = &problem.getVariable(tid,
36  parameters.varName(var_param_name, moose_object->name()),
37  expected_var_type,
38  expected_var_field_type);
39  if (!(_variable = dynamic_cast<MooseVariableFE<T> *>(_var)))
40  _fv_variable = dynamic_cast<MooseVariableFV<T> *>(_var);
41 
43  &problem.assembly(tid, _var->kind() == Moose::VAR_NONLINEAR ? _var->sys().number() : 0);
44 }
45 
46 template <typename T>
48 {
49 }
50 
51 template <typename T>
54 {
55  if (!_fv_variable)
56  mooseError("_fv_variable is null in ",
57  _moose_object.name(),
58  ". Did you forget to set fv = true in the Variables block?");
59  return _fv_variable;
60 }
61 
62 template <typename T>
65 {
66  if (!_variable)
67  mooseError(
68  "_variable is null in ", _moose_object.name(), ". Are you using a finite volume variable?");
69  return _variable;
70 }
71 
72 template <typename T>
73 const typename OutputTools<T>::VariableValue &
75 {
76  if (_nodal)
77  return _variable->dofValues();
78  else
79  return _variable->sln();
80 }
81 
82 template <>
83 const VectorVariableValue &
85 {
86  if (_nodal)
87  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
88  else
89  return _variable->sln();
90 }
91 
92 template <typename T>
93 const typename OutputTools<T>::VariableValue &
95 {
96  if (_nodal)
97  return _variable->dofValuesOld();
98  else
99  return _variable->slnOld();
100 }
101 
102 template <>
103 const VectorVariableValue &
105 {
106  if (_nodal)
107  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
108  else
109  return _variable->slnOld();
110 }
111 
112 template <typename T>
113 const typename OutputTools<T>::VariableValue &
115 {
116  if (_nodal)
117  return _variable->dofValuesOlder();
118  else
119  return _variable->slnOlder();
120 }
121 
122 template <>
123 const VectorVariableValue &
125 {
126  if (_nodal)
127  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
128  else
129  return _variable->slnOlder();
130 }
131 
132 template <typename T>
133 const typename OutputTools<T>::VariableValue &
135 {
136  if (_nodal)
137  return _variable->dofValuesDot();
138  else
139  return _variable->uDot();
140 }
141 
142 template <typename T>
143 const typename OutputTools<T>::VariableValue &
145 {
146  if (_nodal)
147  return _variable->dofValuesDotDot();
148  else
149  return _variable->uDotDot();
150 }
151 
152 template <typename T>
153 const typename OutputTools<T>::VariableValue &
155 {
156  if (_nodal)
157  return _variable->dofValuesDotOld();
158  else
159  return _variable->uDotOld();
160 }
161 
162 template <typename T>
163 const typename OutputTools<T>::VariableValue &
165 {
166  if (_nodal)
167  return _variable->dofValuesDotDotOld();
168  else
169  return _variable->uDotDotOld();
170 }
171 
172 template <>
173 const VectorVariableValue &
175 {
176  if (_nodal)
177  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
178  else
179  return _variable->uDot();
180 }
181 
182 template <>
183 const VectorVariableValue &
185 {
186  if (_nodal)
187  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
188  else
189  return _variable->uDotDot();
190 }
191 
192 template <>
193 const VectorVariableValue &
195 {
196  if (_nodal)
197  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
198  else
199  return _variable->uDotOld();
200 }
201 
202 template <>
203 const VectorVariableValue &
205 {
206  if (_nodal)
207  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
208  else
209  return _variable->uDotDotOld();
210 }
211 
212 template <typename T>
213 const VariableValue &
215 {
216  if (_nodal)
217  return _variable->dofValuesDuDotDu();
218  else
219  return _variable->duDotDu();
220 }
221 
222 template <typename T>
223 const VariableValue &
225 {
226  if (_nodal)
227  return _variable->dofValuesDuDotDotDu();
228  else
229  return _variable->duDotDotDu();
230 }
231 
232 template <typename T>
233 const typename OutputTools<T>::VariableGradient &
235 {
236  if (_nodal)
237  mooseError("gradients are not defined at nodes");
238 
239  return _variable->gradSln();
240 }
241 
242 template <typename T>
243 const typename OutputTools<T>::VariableGradient &
245 {
246  if (_nodal)
247  mooseError("gradients are not defined at nodes");
248 
249  return _variable->gradSlnOld();
250 }
251 
252 template <typename T>
253 const typename OutputTools<T>::VariableGradient &
255 {
256  if (_nodal)
257  mooseError("gradients are not defined at nodes");
258 
259  return _variable->gradSlnOlder();
260 }
261 
262 template <typename T>
263 const typename OutputTools<T>::VariableSecond &
265 {
266  if (_nodal)
267  mooseError("second derivatives are not defined at nodes");
268 
269  return _variable->secondSln();
270 }
271 
272 template <typename T>
273 const typename OutputTools<T>::VariableSecond &
275 {
276  if (_nodal)
277  mooseError("second derivatives are not defined at nodes");
278 
279  return _variable->secondSlnOld();
280 }
281 
282 template <typename T>
283 const typename OutputTools<T>::VariableSecond &
285 {
286  if (_nodal)
287  mooseError("second derivatives are not defined at nodes");
288 
289  return _variable->secondSlnOlder();
290 }
291 
292 template <typename T>
293 const typename OutputTools<T>::VariableTestSecond &
295 {
296  if (_nodal)
297  mooseError("second derivatives are not defined at nodes");
298 
299  return _variable->secondPhi();
300 }
301 
302 template <typename T>
303 const typename OutputTools<T>::VariableTestSecond &
305 {
306  if (_nodal)
307  mooseError("second derivatives are not defined at nodes");
308 
309  return _variable->secondPhiFace();
310 }
311 
312 template <typename T>
313 const typename OutputTools<T>::VariablePhiSecond &
315 {
316  if (_nodal)
317  mooseError("second derivatives are not defined at nodes");
318 
319  return _mvi_assembly->secondPhi(*_variable);
320 }
321 
322 template <typename T>
323 const typename OutputTools<T>::VariablePhiSecond &
325 {
326  if (_nodal)
327  mooseError("second derivatives are not defined at nodes");
328 
329  return _mvi_assembly->secondPhiFace(*_variable);
330 }
331 
332 template <typename T>
335 {
336  if (_variable)
337  return *_variable;
338  else
339  {
340  if (!_fv_variable)
341  mooseError("Either _variable or _fv_variable must be non-null in MooseVariableInterface");
342 
343  return *_fv_variable;
344  }
345 }
346 
347 template class MooseVariableInterface<Real>;
virtual const OutputTools< T >::VariableValue & valueOld()
The old value of the variable this object is operating on.
VarFieldType
Definition: MooseTypes.h:634
virtual const OutputTools< T >::VariablePhiSecond & secondPhiFace()
The second derivative of the trial function on the current face.
MooseVariableFV< T > * mooseVariableFV() const
virtual const OutputTools< T >::VariableGradient & gradientOld()
The old gradient of the variable this object is operating on.
MooseVariableBase * _var
The variable this object is acting on.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
OutputTools< RealVectorValue >::VariableValue VectorVariableValue
Definition: MooseTypes.h:319
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual const OutputTools< T >::VariableValue & dotDot()
The second time derivative of the variable this object is operating on.
virtual const OutputTools< T >::VariableValue & dotDotOld()
The old second time derivative of the variable this object is operating on.
const FieldVariableValue & uDotOld() const
bool _nodal
Whether or not this object is acting only at nodes.
MooseVariableFV< T > * _fv_variable
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
const FieldVariableValue & uDot() const
element dots
virtual const VariableValue & dotDotDu()
The derivative of the second time derivative of the variable this object is operating on with respect...
MooseVariableFE< T > * mooseVariable() const
virtual const OutputTools< T >::VariableValue & valueOlder()
The older value of the variable this object is operating on.
virtual const OutputTools< T >::VariableGradient & gradientOlder()
The older gradient of the variable this object is operating on.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
const FieldVariableValue & uDotDot() const
const FieldVariableValue & sln() const override
element solutions
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:627
const FieldVariableValue & uDotDotOld() const
virtual const OutputTools< T >::VariableTestSecond & secondTest()
The second derivative of the test function.
virtual const OutputTools< T >::VariableValue & value()
The value of the variable this object is operating on.
virtual const OutputTools< T >::VariableValue & dotOld()
The old time derivative of the variable this object is operating on.
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1125
MooseVariableFE< T > * _variable
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const =0
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
virtual const OutputTools< T >::VariableTestSecond & secondTestFace()
The second derivative of the test function on the current face.
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:302
virtual const VariableValue & dotDu()
The derivative of the time derivative of the variable this object is operating on with respect to thi...
const FieldVariableValue & slnOlder() const override
virtual const OutputTools< T >::VariableValue & dot()
The time derivative of the variable this object is operating on.
std::string varName(const std::string &var_param_name, const std::string &moose_object_with_var_param_name) const
Determine the actual variable name from the given variable parameter name.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:75
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
virtual const OutputTools< T >::VariableGradient & gradient()
The gradient of the variable this object is operating on.
MooseVariableField< T > & mooseVariableField()
Return the MooseVariableField<T> object that this interface acts on.
const MooseObject & _moose_object
virtual const OutputTools< T >::VariableSecond & secondOld()
The old second derivative of the variable this object is operating on.
const InputParameters & parameters() const
Get the parameters of the object.
virtual const OutputTools< T >::VariableSecond & second()
The second derivative of the variable this object is operating on.
virtual const OutputTools< T >::VariablePhiSecond & secondPhi()
The second derivative of the trial function.
const FieldVariableValue & slnOld() const override
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int nl_sys_num)=0
SystemBase & sys()
Get the system this variable is part of.
virtual const OutputTools< T >::VariableSecond & secondOlder()
The older second derivative of the variable this object is operating on.
unsigned int THREAD_ID
Definition: MooseTypes.h:198
MooseVariableInterface(const MooseObject *moose_object, bool nodal, std::string var_param_name="variable", Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY)
Constructing the object.