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 "Problem.h"
17 #include "SubProblem.h"
18 
19 template <typename T>
21  bool nodal,
22  std::string var_param_name,
23  Moose::VarKindType expected_var_type,
24  Moose::VarFieldType expected_var_field_type)
25  : _nodal(nodal)
26 {
27  const InputParameters & parameters = moose_object->parameters();
28 
29  SubProblem & problem = *parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
30 
31  THREAD_ID tid = parameters.get<THREAD_ID>("_tid");
32 
33  // Try the scalar version first
34  std::string variable_name = parameters.getMooseType(var_param_name);
35  if (variable_name == "")
36  {
37  auto vec = parameters.getVecMooseType(var_param_name);
38 
39  // Catch the (very unlikely) case where a user specifies
40  // variable = '' (the empty string)
41  // in their input file. This could happen if e.g. something goes
42  // wrong with dollar bracket expression expansion.
43  if (vec.empty())
44  mooseError("Error constructing object '",
45  moose_object->name(),
46  "' while retrieving value for '",
47  var_param_name,
48  "' parameter! Did you set ",
49  var_param_name,
50  " = '' (empty string) by accident?");
51 
52  // When using vector variables, we are only going to use the first one in the list at the
53  // interface level...
54  variable_name = vec[0];
55  }
56 
57  _variable = &dynamic_cast<MooseVariableFE<T> &>(
58  problem.getVariable(tid, variable_name, expected_var_type, expected_var_field_type));
59 
60  _mvi_assembly = &problem.assembly(tid);
61 }
62 
63 template <typename T>
65 {
66 }
67 
68 template <typename T>
71 {
72  return _variable;
73 }
74 
75 template <typename T>
76 const typename OutputTools<T>::VariableValue &
78 {
79  if (_nodal)
80  return _variable->dofValues();
81  else
82  return _variable->sln();
83 }
84 
85 template <>
86 const VectorVariableValue &
88 {
89  if (_nodal)
90  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
91  else
92  return _variable->sln();
93 }
94 
95 template <typename T>
96 const typename OutputTools<T>::VariableValue &
98 {
99  if (_nodal)
100  return _variable->dofValuesOld();
101  else
102  return _variable->slnOld();
103 }
104 
105 template <>
106 const VectorVariableValue &
108 {
109  if (_nodal)
110  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
111  else
112  return _variable->slnOld();
113 }
114 
115 template <typename T>
116 const typename OutputTools<T>::VariableValue &
118 {
119  if (_nodal)
120  return _variable->dofValuesOlder();
121  else
122  return _variable->slnOlder();
123 }
124 
125 template <>
126 const VectorVariableValue &
128 {
129  if (_nodal)
130  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
131  else
132  return _variable->slnOlder();
133 }
134 
135 template <typename T>
136 const typename OutputTools<T>::VariableValue &
138 {
139  if (_nodal)
140  return _variable->dofValuesDot();
141  else
142  return _variable->uDot();
143 }
144 
145 template <typename T>
146 const typename OutputTools<T>::VariableValue &
148 {
149  if (_nodal)
150  return _variable->dofValuesDotDot();
151  else
152  return _variable->uDotDot();
153 }
154 
155 template <typename T>
156 const typename OutputTools<T>::VariableValue &
158 {
159  if (_nodal)
160  return _variable->dofValuesDotOld();
161  else
162  return _variable->uDotOld();
163 }
164 
165 template <typename T>
166 const typename OutputTools<T>::VariableValue &
168 {
169  if (_nodal)
170  return _variable->dofValuesDotDotOld();
171  else
172  return _variable->uDotDotOld();
173 }
174 
175 template <>
176 const VectorVariableValue &
178 {
179  if (_nodal)
180  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
181  else
182  return _variable->uDot();
183 }
184 
185 template <>
186 const VectorVariableValue &
188 {
189  if (_nodal)
190  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
191  else
192  return _variable->uDotDot();
193 }
194 
195 template <>
196 const VectorVariableValue &
198 {
199  if (_nodal)
200  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
201  else
202  return _variable->uDotOld();
203 }
204 
205 template <>
206 const VectorVariableValue &
208 {
209  if (_nodal)
210  mooseError("Dofs are scalars while vector variables have vector values. Mismatch");
211  else
212  return _variable->uDotDotOld();
213 }
214 
215 template <typename T>
216 const VariableValue &
218 {
219  if (_nodal)
220  return _variable->dofValuesDuDotDu();
221  else
222  return _variable->duDotDu();
223 }
224 
225 template <typename T>
226 const VariableValue &
228 {
229  if (_nodal)
230  return _variable->dofValuesDuDotDotDu();
231  else
232  return _variable->duDotDotDu();
233 }
234 
235 template <typename T>
236 const typename OutputTools<T>::VariableGradient &
238 {
239  if (_nodal)
240  mooseError("gradients are not defined at nodes");
241 
242  return _variable->gradSln();
243 }
244 
245 template <typename T>
246 const typename OutputTools<T>::VariableGradient &
248 {
249  if (_nodal)
250  mooseError("gradients are not defined at nodes");
251 
252  return _variable->gradSlnOld();
253 }
254 
255 template <typename T>
256 const typename OutputTools<T>::VariableGradient &
258 {
259  if (_nodal)
260  mooseError("gradients are not defined at nodes");
261 
262  return _variable->gradSlnOlder();
263 }
264 
265 template <typename T>
266 const typename OutputTools<T>::VariableSecond &
268 {
269  if (_nodal)
270  mooseError("second derivatives are not defined at nodes");
271 
272  return _variable->secondSln();
273 }
274 
275 template <typename T>
276 const typename OutputTools<T>::VariableSecond &
278 {
279  if (_nodal)
280  mooseError("second derivatives are not defined at nodes");
281 
282  return _variable->secondSlnOld();
283 }
284 
285 template <typename T>
286 const typename OutputTools<T>::VariableSecond &
288 {
289  if (_nodal)
290  mooseError("second derivatives are not defined at nodes");
291 
292  return _variable->secondSlnOlder();
293 }
294 
295 template <typename T>
296 const typename OutputTools<T>::VariableTestSecond &
298 {
299  if (_nodal)
300  mooseError("second derivatives are not defined at nodes");
301 
302  return _variable->secondPhi();
303 }
304 
305 template <typename T>
306 const typename OutputTools<T>::VariableTestSecond &
308 {
309  if (_nodal)
310  mooseError("second derivatives are not defined at nodes");
311 
312  return _variable->secondPhiFace();
313 }
314 
315 template <typename T>
316 const typename OutputTools<T>::VariablePhiSecond &
318 {
319  if (_nodal)
320  mooseError("second derivatives are not defined at nodes");
321 
322  return _mvi_assembly->secondPhi(*_variable);
323 }
324 
325 template <typename T>
326 const typename OutputTools<T>::VariablePhiSecond &
328 {
329  if (_nodal)
330  mooseError("second derivatives are not defined at nodes");
331 
332  return _mvi_assembly->secondPhiFace(*_variable);
333 }
334 
335 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:488
std::string getMooseType(const std::string &name) const
Utility functions for retrieving one of the MooseTypes variables into the common "string" base class...
virtual const OutputTools< T >::VariablePhiSecond & secondPhiFace()
The second derivative of the trial function on the current face.
virtual const OutputTools< T >::VariableGradient & gradientOld()
The old gradient of the variable this object is operating on.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
OutputTools< RealVectorValue >::VariableValue VectorVariableValue
Definition: MooseTypes.h:211
virtual MooseVariableFEBase & getVariable(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)=0
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
virtual Assembly & assembly(THREAD_ID tid)=0
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
const FieldVariableValue & sln() const
element solutions
bool _nodal
Whether or not this object is acting only at nodes.
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
Get the variable that this object is using.
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:42
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
const FieldVariableValue & uDotDot() const
const FieldVariableValue & slnOld() const
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:481
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.
MooseVariableFE< T > * _variable
The variable this object is acting on.
virtual const OutputTools< T >::VariableTestSecond & secondTestFace()
The second derivative of the test function on the current face.
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:197
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.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:59
virtual const OutputTools< T >::VariableGradient & gradient()
The gradient of the variable this object is operating on.
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
virtual const OutputTools< T >::VariableSecond & secondOld()
The old second derivative of the variable this object is operating on.
virtual const OutputTools< T >::VariableSecond & second()
The second derivative of the variable this object is operating on.
const FieldVariableValue & slnOlder() const
virtual const OutputTools< T >::VariablePhiSecond & secondPhi()
The second derivative of the trial function.
std::vector< std::string > getVecMooseType(const std::string &name) const
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:161
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.