https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
11
12#include "Assembly.h"
13#include "MooseError.h" // mooseDeprecated
14#include "MooseTypes.h"
15#include "MooseVariableFE.h"
16#include "MooseVariableFV.h"
18#include "Problem.h"
19#include "SubProblem.h"
20#include "SystemBase.h"
21
22template <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
50template <typename T>
54
55template <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}
66template <typename T>
69{
70 if (!_linear_fv_variable)
72 "The variable defined in ", _moose_object.name(), " is not a MooseLinearVariableFV!");
73 return _linear_fv_variable;
74}
75
76template <typename T>
79{
80 if (!_variable)
82 "_variable is null in ", _moose_object.name(), ". Are you using a finite volume variable?");
83 return _variable;
84}
85
86template <typename T>
87const typename OutputTools<T>::VariableValue &
90 if (_nodal)
91 return _variable->dofValues();
92 else
93 return _variable->sln();
94}
95
96template <>
99{
100 if (_nodal)
101 mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
102 else
103 return _variable->sln();
104}
105
106template <typename T>
107const typename OutputTools<T>::VariableValue &
109{
110 if (_nodal)
111 return _variable->dofValuesOld();
112 else
113 return _variable->slnOld();
114}
115
116template <>
119{
120 if (_nodal)
121 mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
122 else
123 return _variable->slnOld();
125
126template <typename T>
127const typename OutputTools<T>::VariableValue &
129{
130 if (_nodal)
131 return _variable->dofValuesOlder();
132 else
133 return _variable->slnOlder();
135
136template <>
139{
140 if (_nodal)
141 mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
142 else
143 return _variable->slnOlder();
145
146template <typename T>
147const typename OutputTools<T>::VariableValue &
149{
150 if (_nodal)
151 return _variable->dofValuesDot();
152 else
153 return _variable->uDot();
154}
155
156template <typename T>
157const typename OutputTools<T>::VariableValue &
159{
160 if (_nodal)
161 return _variable->dofValuesDotDot();
162 else
163 return _variable->uDotDot();
164}
165
166template <typename T>
169{
170 if (_nodal)
171 return _variable->dofValuesDotOld();
172 else
173 return _variable->uDotOld();
175
176template <typename T>
177const typename OutputTools<T>::VariableValue &
179{
180 if (_nodal)
181 return _variable->dofValuesDotDotOld();
182 else
183 return _variable->uDotDotOld();
184}
185
186template <>
189{
190 if (_nodal)
191 mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
192 else
193 return _variable->uDot();
194}
196template <>
199{
200 if (_nodal)
201 mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
202 else
203 return _variable->uDotDot();
205
206template <>
209{
210 if (_nodal)
211 mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
212 else
213 return _variable->uDotOld();
214}
215
216template <>
219{
220 if (_nodal)
221 mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
222 else
223 return _variable->uDotDotOld();
224}
225
226template <typename T>
227const VariableValue &
229{
230 if (_nodal)
231 return _variable->dofValuesDuDotDu();
232 else
233 return _variable->duDotDu();
234}
235
236template <typename T>
237const VariableValue &
239{
240 if (_nodal)
241 return _variable->dofValuesDuDotDotDu();
242 else
243 return _variable->duDotDotDu();
244}
245
246template <typename T>
249{
250 if (_nodal)
251 mooseError("gradients are not defined at nodes");
252
253 return _variable->gradSln();
254}
255
256template <typename T>
259{
260 if (_nodal)
261 mooseError("gradients are not defined at nodes");
262
263 return _variable->gradSlnOld();
264}
265
266template <typename T>
269{
270 if (_nodal)
271 mooseError("gradients are not defined at nodes");
272
273 return _variable->gradSlnOlder();
274}
275
276template <typename T>
277const typename OutputTools<T>::VariableSecond &
279{
280 if (_nodal)
281 mooseError("second derivatives are not defined at nodes");
282
283 return _variable->secondSln();
284}
285
286template <typename T>
287const typename OutputTools<T>::VariableSecond &
289{
290 if (_nodal)
291 mooseError("second derivatives are not defined at nodes");
292
293 return _variable->secondSlnOld();
294}
295
296template <typename T>
297const typename OutputTools<T>::VariableSecond &
299{
300 if (_nodal)
301 mooseError("second derivatives are not defined at nodes");
302
303 return _variable->secondSlnOlder();
304}
305
306template <typename T>
309{
310 if (_nodal)
311 mooseError("second derivatives are not defined at nodes");
312
313 return _variable->secondPhi();
314}
315
316template <typename T>
319{
320 if (_nodal)
321 mooseError("second derivatives are not defined at nodes");
322
323 return _variable->secondPhiFace();
324}
325
326template <typename T>
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
339template <typename T>
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
352template <typename T>
355{
356 return *_field_variable;
357}
358
359template class MooseVariableInterface<Real>;
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
OutputTools< Real >::VariableValue VariableValue
Definition MooseTypes.h:348
unsigned int THREAD_ID
Definition MooseTypes.h:237
OutputTools< RealVectorValue >::VariableValue VectorVariableValue
Definition MooseTypes.h:365
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 \emph parameter name.
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.
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.
forward declarations
Definition MooseArray.h:18
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
This class provides variable solution interface for linear finite volume problems.
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
SystemBase & sys()
Get the system this variable is part of.
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
Class for stuff related to variables.
This class provides variable solution values for other classes/objects to bind to when looping over f...
Class for stuff related to variables.
Interface for objects that need to get values of MooseVariables.
virtual const OutputTools< T >::VariableGradient & gradientOld()
The old gradient of the variable this object is operating on.
MooseVariableFE< T > * _variable
virtual const OutputTools< T >::VariableSecond & second()
The second derivative of the variable this object is operating on.
virtual const OutputTools< T >::VariableValue & value()
The 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.
virtual const VariableValue & dotDu()
The derivative of the time derivative of the variable this object is operating on with respect to thi...
virtual const OutputTools< T >::VariableValue & dot()
The time derivative of the variable this object is operating on.
virtual const OutputTools< T >::VariablePhiSecond & secondPhi()
The second derivative of the trial function.
virtual const OutputTools< T >::VariableValue & valueOld()
The old value of the variable this object is operating on.
virtual const OutputTools< T >::VariableValue & valueOlder()
The older value of the variable this object is operating on.
MooseVariableFE< T > * mooseVariable() const
Return the MooseVariableFE object that this interface acts on.
MooseVariableField< T > * _field_variable
MooseVariableField< T > & mooseVariableField()
Return the MooseVariableField object that this interface acts on.
virtual const OutputTools< T >::VariableTestSecond & secondTest()
The second derivative of the test function.
virtual const OutputTools< T >::VariableGradient & gradient()
The gradient of the variable this object is operating on.
virtual const OutputTools< T >::VariableSecond & secondOld()
The old second derivative of the variable this object is operating on.
virtual const OutputTools< T >::VariableTestSecond & secondTestFace()
The second derivative of the test function on the current face.
MooseVariableFV< T > * mooseVariableFV() const
Return the MooseVariableFV object that this interface acts on.
virtual const OutputTools< T >::VariableValue & dotOld()
The old time derivative of the variable this object is operating on.
MooseVariableFV< T > * _fv_variable
virtual const OutputTools< T >::VariableSecond & secondOlder()
The older second derivative of the variable this object is operating on.
const MooseObject & _moose_object
MooseVariableBase * _var
The variable this object is acting on.
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.
MooseLinearVariableFV< T > * mooseLinearVariableFV() const
Return the MooseLinearVariableFV object that this interface acts on.
MooseLinearVariableFV< T > * _linear_fv_variable
virtual const OutputTools< T >::VariablePhiSecond & secondPhiFace()
The second derivative of the trial function on the current face.
virtual const VariableValue & dotDotDu()
The derivative of the second time derivative of the variable this object is operating on with respect...
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.
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num)=0
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...
unsigned int number() const
Gets the number of this system.
VarKindType
Framework-wide stuff.
Definition MooseTypes.h:769
@ VAR_SOLVER
Definition MooseTypes.h:770