https://mooseframework.inl.gov
MooseVariableInterface.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 "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 "MooseLinearVariableFV.h"
18 #include "Problem.h"
19 #include "SubProblem.h"
20 #include "SystemBase.h"
21 
22 template <typename T>
24  bool nodal,
25  std::string var_param_name,
26  Moose::VarKindType expected_var_type,
27  Moose::VarFieldType expected_var_field_type)
28  : _nodal(nodal), _moose_object(*moose_object)
29 {
30  const InputParameters & parameters = _moose_object.parameters();
31 
32  SubProblem & problem = *parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
33 
34  THREAD_ID tid = parameters.get<THREAD_ID>("_tid");
35 
36  _var = &problem.getVariable(tid,
37  parameters.varName(var_param_name, moose_object->name()),
38  expected_var_type,
39  expected_var_field_type);
40  if (!(_variable = dynamic_cast<MooseVariableFE<T> *>(_var)))
41  if (!(_fv_variable = dynamic_cast<MooseVariableFV<T> *>(_var)))
43  if (!(_field_variable = dynamic_cast<MooseVariableField<T> *>(_var)))
44  mooseError("The variable supplied to the variable interface is not of field type");
45 
47  &problem.assembly(tid, (_var->kind() == Moose::VAR_SOLVER) ? _var->sys().number() : 0);
48 }
49 
50 template <typename T>
52 {
53 }
54 
55 template <typename T>
58 {
59  if (!_fv_variable)
60  mooseError("_fv_variable is null in ",
61  _moose_object.name(),
62  ". Did you forget to set fv = true in the Variables block?");
63  return _fv_variable;
64 }
65 
66 template <typename T>
69 {
70  if (!_linear_fv_variable)
71  mooseError(
72  "The variable defined in ", _moose_object.name(), " is not a MooseLinearVariableFV!");
73  return _linear_fv_variable;
74 }
75 
76 template <typename T>
79 {
80  if (!_variable)
81  mooseError(
82  "_variable is null in ", _moose_object.name(), ". Are you using a finite volume variable?");
83  return _variable;
84 }
85 
86 template <typename T>
87 const typename OutputTools<T>::VariableValue &
89 {
90  if (_nodal)
91  return _variable->dofValues();
92  else
93  return _variable->sln();
94 }
95 
96 template <>
97 const VectorVariableValue &
99 {
100  if (_nodal)
101  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
102  else
103  return _variable->sln();
104 }
105 
106 template <typename T>
107 const typename OutputTools<T>::VariableValue &
109 {
110  if (_nodal)
111  return _variable->dofValuesOld();
112  else
113  return _variable->slnOld();
114 }
115 
116 template <>
117 const VectorVariableValue &
119 {
120  if (_nodal)
121  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
122  else
123  return _variable->slnOld();
124 }
125 
126 template <typename T>
127 const typename OutputTools<T>::VariableValue &
129 {
130  if (_nodal)
131  return _variable->dofValuesOlder();
132  else
133  return _variable->slnOlder();
134 }
135 
136 template <>
137 const VectorVariableValue &
139 {
140  if (_nodal)
141  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
142  else
143  return _variable->slnOlder();
144 }
145 
146 template <typename T>
147 const typename OutputTools<T>::VariableValue &
149 {
150  if (_nodal)
151  return _variable->dofValuesDot();
152  else
153  return _variable->uDot();
154 }
155 
156 template <typename T>
157 const typename OutputTools<T>::VariableValue &
159 {
160  if (_nodal)
161  return _variable->dofValuesDotDot();
162  else
163  return _variable->uDotDot();
164 }
165 
166 template <typename T>
167 const typename OutputTools<T>::VariableValue &
169 {
170  if (_nodal)
171  return _variable->dofValuesDotOld();
172  else
173  return _variable->uDotOld();
174 }
175 
176 template <typename T>
177 const typename OutputTools<T>::VariableValue &
179 {
180  if (_nodal)
181  return _variable->dofValuesDotDotOld();
182  else
183  return _variable->uDotDotOld();
184 }
185 
186 template <>
187 const VectorVariableValue &
189 {
190  if (_nodal)
191  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
192  else
193  return _variable->uDot();
194 }
195 
196 template <>
197 const VectorVariableValue &
199 {
200  if (_nodal)
201  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
202  else
203  return _variable->uDotDot();
204 }
205 
206 template <>
207 const VectorVariableValue &
209 {
210  if (_nodal)
211  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
212  else
213  return _variable->uDotOld();
214 }
215 
216 template <>
217 const VectorVariableValue &
219 {
220  if (_nodal)
221  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
222  else
223  return _variable->uDotDotOld();
224 }
225 
226 template <typename T>
227 const VariableValue &
229 {
230  if (_nodal)
231  return _variable->dofValuesDuDotDu();
232  else
233  return _variable->duDotDu();
234 }
235 
236 template <typename T>
237 const VariableValue &
239 {
240  if (_nodal)
241  return _variable->dofValuesDuDotDotDu();
242  else
243  return _variable->duDotDotDu();
244 }
245 
246 template <typename T>
247 const typename OutputTools<T>::VariableGradient &
249 {
250  if (_nodal)
251  mooseError("gradients are not defined at nodes");
252 
253  return _variable->gradSln();
254 }
255 
256 template <typename T>
257 const typename OutputTools<T>::VariableGradient &
259 {
260  if (_nodal)
261  mooseError("gradients are not defined at nodes");
262 
263  return _variable->gradSlnOld();
264 }
265 
266 template <typename T>
267 const typename OutputTools<T>::VariableGradient &
269 {
270  if (_nodal)
271  mooseError("gradients are not defined at nodes");
272 
273  return _variable->gradSlnOlder();
274 }
275 
276 template <typename T>
277 const typename OutputTools<T>::VariableSecond &
279 {
280  if (_nodal)
281  mooseError("second derivatives are not defined at nodes");
282 
283  return _variable->secondSln();
284 }
285 
286 template <typename T>
287 const typename OutputTools<T>::VariableSecond &
289 {
290  if (_nodal)
291  mooseError("second derivatives are not defined at nodes");
292 
293  return _variable->secondSlnOld();
294 }
295 
296 template <typename T>
297 const typename OutputTools<T>::VariableSecond &
299 {
300  if (_nodal)
301  mooseError("second derivatives are not defined at nodes");
302 
303  return _variable->secondSlnOlder();
304 }
305 
306 template <typename T>
307 const typename OutputTools<T>::VariableTestSecond &
309 {
310  if (_nodal)
311  mooseError("second derivatives are not defined at nodes");
312 
313  return _variable->secondPhi();
314 }
315 
316 template <typename T>
317 const typename OutputTools<T>::VariableTestSecond &
319 {
320  if (_nodal)
321  mooseError("second derivatives are not defined at nodes");
322 
323  return _variable->secondPhiFace();
324 }
325 
326 template <typename T>
327 const typename OutputTools<T>::VariablePhiSecond &
329 {
330  if (_nodal)
331  mooseError("second derivatives are not defined at nodes");
332 
333  if (_linear_fv_variable)
334  mooseError("second order shape function derivatives not available for linear FV variables");
335 
336  return _mvi_assembly->secondPhi(*_variable);
337 }
338 
339 template <typename T>
340 const typename OutputTools<T>::VariablePhiSecond &
342 {
343  if (_nodal)
344  mooseError("second derivatives are not defined at nodes");
345 
346  if (_linear_fv_variable)
347  mooseError("second order shape function derivatives not available for linear FV variables");
348 
349  return _mvi_assembly->secondPhiFace(*_variable);
350 }
351 
352 template <typename T>
355 {
356  return *_field_variable;
357 }
358 
359 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:721
virtual const OutputTools< T >::VariablePhiSecond & secondPhiFace()
The second derivative of the trial function on the current face.
MooseVariableFV< T > * mooseVariableFV() const
Return the MooseVariableFV object that this interface acts on.
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:302
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:331
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
MooseLinearVariableFV< T > * _linear_fv_variable
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:57
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
Return the MooseVariableFE object that this interface acts on.
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:28
const FieldVariableValue & uDotDot() const
const FieldVariableValue & sln() const override
element solutions
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:714
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:1159
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:314
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:78
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num)=0
virtual const OutputTools< T >::VariableGradient & gradient()
The gradient of the variable this object is operating on.
MooseVariableField< T > & mooseVariableField()
Return the MooseVariableField 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.
MooseVariableField< T > * _field_variable
MooseLinearVariableFV< T > * mooseLinearVariableFV() const
Return the MooseLinearVariableFV object that this interface acts on.
virtual const OutputTools< T >::VariablePhiSecond & secondPhi()
The second derivative of the trial function.
const FieldVariableValue & slnOld() const override
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:209
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.