Line data Source code
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 : #pragma once
11 :
12 : #ifdef MOOSE_KOKKOS_SCOPE
13 : #include "KokkosVariableValue.h"
14 : #endif
15 :
16 : #include <unordered_map>
17 : #include "MooseTypes.h"
18 : #include "MooseArray.h"
19 : #include "MooseVariableFE.h"
20 : #include "MooseVariableFV.h"
21 : #include "MooseLinearVariableFV.h"
22 : #include "InputParameters.h"
23 : #include "HasMembers.h"
24 :
25 : #define usingCoupleableMembers \
26 : using Coupleable::_zero; \
27 : using Coupleable::_grad_zero; \
28 : using Coupleable::_ad_zero; \
29 : using Coupleable::_ad_grad_zero; \
30 : using Coupleable::coupled; \
31 : using Coupleable::isCoupled; \
32 : using Coupleable::coupledComponents
33 :
34 : // Forward declarations
35 : class MooseVariableScalar;
36 : class MooseObject;
37 :
38 : namespace libMesh
39 : {
40 : template <typename T>
41 : class DenseVector;
42 : }
43 :
44 : template <typename>
45 : class MooseVariableField;
46 : typedef MooseVariableField<Real> MooseWritableVariable;
47 :
48 : /**
49 : * Interface for objects that needs coupling capabilities
50 : *
51 : */
52 : class Coupleable
53 : {
54 : public:
55 : /**
56 : * Constructing the object
57 : * @param parameters Parameters that come from constructing the object
58 : * @param nodal true if we need to couple with nodal values, otherwise false
59 : * @param is_fv Whether the \p MooseObject is a finite volume object
60 : */
61 : Coupleable(const MooseObject * moose_object, bool nodal, bool is_fv = false);
62 :
63 : #ifdef MOOSE_KOKKOS_ENABLED
64 : /**
65 : * Special constructor used for Kokkos functor copy during parallel dispatch
66 : */
67 : Coupleable(const Coupleable & object, const Moose::Kokkos::FunctorCopy & key);
68 : #endif
69 :
70 : /**
71 : * Get the list of coupled variables
72 : * @return The list of coupled variables
73 : */
74 : const std::unordered_map<std::string, std::vector<MooseVariableFieldBase *>> &
75 118484 : getCoupledVars() const
76 : {
77 118484 : return _coupled_vars;
78 : }
79 :
80 : /**
81 : * Get the list of all coupled variables
82 : * @return The list of all coupled variables
83 : */
84 2874711 : const std::vector<MooseVariableFieldBase *> & getCoupledMooseVars() const
85 : {
86 2874711 : return _coupled_moose_vars;
87 : }
88 :
89 : /**
90 : * Get the list of standard coupled variables
91 : * @return The list of standard coupled variables
92 : */
93 : const std::vector<MooseVariable *> & getCoupledStandardMooseVars() const
94 : {
95 : return _coupled_standard_moose_vars;
96 : }
97 :
98 : /**
99 : * Get the list of vector coupled variables
100 : * @return The list of vector coupled variables
101 : */
102 : const std::vector<VectorMooseVariable *> & getCoupledVectorMooseVars() const
103 : {
104 : return _coupled_vector_moose_vars;
105 : }
106 :
107 : /**
108 : * Get the list of array coupled variables
109 : * @return The list of array coupled variables
110 : */
111 : const std::vector<ArrayMooseVariable *> & getCoupledArrayMooseVars() const
112 : {
113 : return _coupled_array_moose_vars;
114 : }
115 :
116 2016 : void addFEVariableCoupleableVectorTag(TagID tag) { _fe_coupleable_vector_tags.insert(tag); }
117 :
118 259 : void addFEVariableCoupleableMatrixTag(TagID tag) { _fe_coupleable_matrix_tags.insert(tag); }
119 :
120 1394280 : std::set<TagID> & getFEVariableCoupleableVectorTags() { return _fe_coupleable_vector_tags; }
121 :
122 794830 : std::set<TagID> & getFEVariableCoupleableMatrixTags() { return _fe_coupleable_matrix_tags; }
123 :
124 15612033 : const std::set<TagID> & getFEVariableCoupleableVectorTags() const
125 : {
126 15612033 : return _fe_coupleable_vector_tags;
127 : }
128 :
129 : const std::set<TagID> & getFEVariableCoupleableMatrixTags() const
130 : {
131 : return _fe_coupleable_matrix_tags;
132 : }
133 :
134 : /**
135 : * returns a reference to the set of writable coupled variables
136 : */
137 65901508 : auto & getWritableCoupledVariables() const { return _writable_coupled_variables[_c_tid]; }
138 :
139 : /**
140 : * Checks whether the object has any writable coupled variables
141 : */
142 65870846 : bool hasWritableCoupledVariables() const { return !getWritableCoupledVariables().empty(); }
143 :
144 : protected:
145 : /**
146 : * A call-back function provided by the derived object for actions before coupling a variable
147 : * with functions such as coupledValue.
148 : */
149 127388 : virtual void coupledCallback(const std::string & /*var_name*/, bool /*is_old*/) const {}
150 :
151 : /**
152 : * Returns true if a variables has been coupled as name.
153 : * @param var_name The name the kernel wants to refer to the variable as.
154 : * @param i By default 0, in general the index to test in a vector of MooseVariable pointers.
155 : * @return True if a coupled variable has the supplied name
156 : */
157 : virtual bool isCoupled(const std::string & var_name, unsigned int i = 0) const;
158 :
159 : /**
160 : * Returns true if a variable passed as a coupled value is really a constant
161 : * @param var_name The name the kernel wants to refer to the variable as.
162 : * @return True if the variable is actually a constant
163 : */
164 : virtual bool isCoupledConstant(const std::string & var_name) const;
165 :
166 : /**
167 : * Number of coupled components
168 : * @param var_name Name of the variable
169 : * @return number of components this variable has (usually 1)
170 : */
171 : unsigned int coupledComponents(const std::string & var_name) const;
172 :
173 : /**
174 : * Names of the variable in the Coupleable interface
175 : * @param var_name Name of the variable
176 : * @param comp the component of the variable
177 : * @return name the variable has been coupled as. For constants, returns the constant
178 : */
179 : VariableName coupledName(const std::string & var_name, unsigned int comp = 0) const;
180 :
181 : /**
182 : * Names of the variables in the Coupleable interface
183 : * @param var_name Names of the variables
184 : * @return names the variables have been coupled as
185 : */
186 : std::vector<VariableName> coupledNames(const std::string & var_name) const;
187 :
188 : /**
189 : * Returns the index for a coupled variable by name
190 : * @param var_name Name of coupled variable
191 : * @param comp Component number for vector of coupled variables
192 : * @return Index of coupled variable, if this is an optionally coupled variable that wasn't
193 : * provided this will return a unique "invalid" index.
194 : */
195 : virtual unsigned int coupled(const std::string & var_name, unsigned int comp = 0) const;
196 :
197 : /**
198 : * Returns the indices for a coupled variable's components
199 : * @param var_name Name of coupled variable
200 : * @return Vector of the indices for all components of the coupled variable \p var_name.
201 : */
202 : std::vector<unsigned int> coupledIndices(const std::string & var_name) const;
203 :
204 : /**
205 : * Returns value of a coupled variable
206 : * @param var_name Name of coupled variable
207 : * @param comp Component number for vector of coupled variables
208 : * @return Reference to a VariableValue for the coupled variable
209 : * @see Kernel::_u
210 : */
211 : virtual const VariableValue & coupledValue(const std::string & var_name,
212 : unsigned int comp = 0) const;
213 :
214 : /**
215 : * Returns the values for all of a coupled variable components
216 : * @param var_name Name of coupled variable
217 : * @return Vector of VariableValue pointers for each component of \p var_name
218 : */
219 : std::vector<const VariableValue *> coupledValues(const std::string & var_name) const;
220 :
221 : /**
222 : * Returns the values for all of a coupled vector variable's components
223 : * @param var_name Name of coupled variable
224 : * @return Vector of VectorVariableValue pointers for each component of \p var_name
225 : */
226 : std::vector<const VectorVariableValue *> coupledVectorValues(const std::string & var_name) const;
227 :
228 : /**
229 : * Returns value of a coupled variable for use in templated automatic differentiation classes
230 : * @param var_name Name of coupled variable
231 : * @param comp Component number for vector of coupled variables
232 : * @return Reference to a GenericVariableValue for the coupled variable
233 : */
234 : template <bool is_ad>
235 : const GenericVariableValue<is_ad> & coupledGenericValue(const std::string & var_name,
236 : unsigned int comp = 0) const;
237 :
238 : /**
239 : * Returns value of a coupled vector variable for use in templated automatic differentiation
240 : * classes
241 : * @param var_name Name of coupled variable
242 : * @param comp Component number for vector of coupled variables
243 : * @return Reference to a GenericVariableVectorValue for the coupled variable
244 : */
245 : template <bool is_ad>
246 : const GenericVectorVariableValue<is_ad> & coupledGenericVectorValue(const std::string & var_name,
247 : unsigned int comp = 0) const;
248 :
249 : /**
250 : * Returns the values for all of a coupled variable's components for use in templated automatic
251 : * differentiation classes
252 : * @param var_name Name of coupled variable
253 : * @return Vector of GenericVariableValue pointers for each component of \p var_name
254 : */
255 : template <bool is_ad>
256 : std::vector<const GenericVariableValue<is_ad> *>
257 : coupledGenericValues(const std::string & var_name) const;
258 :
259 : /**
260 : * Returns DOF value of a coupled variable for use in templated automatic differentiation classes
261 : * @param var_name Name of coupled variable
262 : * @param comp Component number for vector of coupled variables
263 : * @return Reference to a GenericVariableValue for the coupled variable
264 : */
265 : template <bool is_ad>
266 : const GenericVariableValue<is_ad> & coupledGenericDofValue(const std::string & var_name,
267 : unsigned int comp = 0) const;
268 :
269 : /**
270 : * Returns time derivative of a coupled variable for use in templated automatic differentiation
271 : * classes
272 : * @param var_name Name of coupled variable
273 : * @param comp Component number for vector of coupled variables
274 : * @return Reference to a GenericVariableValue for the coupled variable time derivative
275 : */
276 : template <bool is_ad>
277 : const GenericVariableValue<is_ad> & coupledGenericDot(const std::string & var_name,
278 : unsigned int comp = 0) const;
279 :
280 : /**
281 : * Returns the second time derivative of a coupled variable for use in templated automatic
282 : * differentiation classes
283 : * @param var_name Name of coupled variable
284 : * @param comp Component number for vector of coupled variables
285 : * @return Reference to a GenericVariableValue for the coupled variable second time derivative
286 : */
287 : template <bool is_ad>
288 : const GenericVariableValue<is_ad> & coupledGenericDotDot(const std::string & var_name,
289 : unsigned int comp = 0) const;
290 :
291 : /**
292 : * Returns value of a coupled lower-dimensional variable
293 : * @param var_name Name of coupled variable
294 : * @param comp Component number for vector of coupled variables
295 : * @return Reference to a VariableValue for the coupled variable
296 : */
297 : virtual const VariableValue & coupledValueLower(const std::string & var_name,
298 : unsigned int comp = 0) const;
299 :
300 : /**
301 : * Returns value of a coupled variable for use in Automatic Differentiation
302 : * @param var_name Name of coupled variable
303 : * @param comp Component number for vector of coupled variables
304 : * @return Reference to a ADVariableValue for the coupled variable
305 : */
306 : const ADVariableValue & adCoupledValue(const std::string & var_name, unsigned int comp = 0) const;
307 :
308 : /**
309 : * Returns the values for all of a coupled variable's components for use in Automatic
310 : * Differentiation
311 : * @param var_name Name of coupled variable
312 : * @return Vector of ADVariableValue pointers for each component of \p var_name
313 : */
314 : std::vector<const ADVariableValue *> adCoupledValues(const std::string & var_name) const;
315 :
316 : /**
317 : * Returns value of a coupled lower-dimensional variable for use in Automatic Differentiation
318 : * @param var_name Name of coupled variable
319 : * @param comp Component number for vector of coupled variables
320 : * @return Reference to a ADVariableValue for the coupled variable
321 : */
322 : const ADVariableValue & adCoupledLowerValue(const std::string & var_name,
323 : unsigned int comp = 0) const;
324 :
325 : /**
326 : * Returns value of a coupled vector variable for use in Automatic Differentiation
327 : * @param var_name Name of coupled vector variable
328 : * @param comp Component number for vector of coupled variables
329 : * @return Reference to a VariableValue for the coupled variable
330 : * @see Kernel::value
331 : */
332 : const ADVectorVariableValue & adCoupledVectorValue(const std::string & var_name,
333 : unsigned int comp = 0) const;
334 :
335 : /**
336 : * Returns the values for all of a coupled vector variable's components for use in
337 : * Automatic Differentiation
338 : * @param var_name Name of coupled variable
339 : * @return Vector of ADVariableValue pointers for each component of \p var_name
340 : */
341 : std::vector<const ADVectorVariableValue *>
342 : adCoupledVectorValues(const std::string & var_name) const;
343 :
344 : /**
345 : * Returns value of a coupled variable for a given tag
346 : * @param var_names Name(s) of coupled variable(s)
347 : * @param tag vector tag ID
348 : * @param index Index of the desired variable in the vector of coupled variables
349 : * @return Reference to a VariableValue for the coupled variable
350 : * @see Kernel::_u
351 : */
352 : virtual const VariableValue &
353 : coupledVectorTagValue(const std::string & var_names, TagID tag, unsigned int index = 0) const;
354 :
355 : virtual const VariableValue & coupledVectorTagValue(const std::string & var_names,
356 : const std::string & tag_name,
357 : unsigned int index = 0) const;
358 :
359 : /**
360 : * Returns the values for all the coupled variables desired for a given tag
361 : * @param var_names Name(s) of coupled variable(s)
362 : * @param tag vector tag ID
363 : * @return Vector of VariableValue pointers for each variable in \p var_names
364 : */
365 : std::vector<const VariableValue *> coupledVectorTagValues(const std::string & var_names,
366 : TagID tag) const;
367 :
368 : std::vector<const VariableValue *> coupledVectorTagValues(const std::string & var_names,
369 : const std::string & tag_name) const;
370 :
371 : /**
372 : * Returns value of a coupled array variable for a given tag
373 : * @param var_names Name(s) of coupled array variable(s)
374 : * @param tag vector tag ID
375 : * @param index Index of the desired variable in the vector of coupled variables
376 : * @return Reference to a VariableValue for the coupled array variable
377 : * @see Kernel::_u
378 : */
379 : virtual const ArrayVariableValue & coupledVectorTagArrayValue(const std::string & var_names,
380 : TagID tag,
381 : unsigned int index = 0) const;
382 :
383 : virtual const ArrayVariableValue & coupledVectorTagArrayValue(const std::string & var_names,
384 : const std::string & tag_name,
385 : unsigned int index = 0) const;
386 :
387 : /**
388 : * Returns the values for all the coupled variables desired for a given tag
389 : * @param var_name Name of array coupled variable
390 : * @param tag vector tag ID
391 : * @return Vector of ArrayVariableValue pointers for each variable in \p var_names
392 : */
393 : std::vector<const ArrayVariableValue *> coupledVectorTagArrayValues(const std::string & var_names,
394 : TagID tag) const;
395 :
396 : std::vector<const ArrayVariableValue *>
397 : coupledVectorTagArrayValues(const std::string & var_names, const std::string & tag_name) const;
398 :
399 : /**
400 : * Returns gradient of a coupled variable for a given tag
401 : * @param var_names Name(s) of coupled variable(s)
402 : * @param tag vector tag ID
403 : * @param index Index of the desired variable in the vector of coupled variables
404 : * @return Reference to a VariableGradient containing the gradient of the coupled variable
405 : * @see Kernel::gradient
406 : */
407 : virtual const VariableGradient &
408 : coupledVectorTagGradient(const std::string & var_names, TagID tag, unsigned int index = 0) const;
409 :
410 : virtual const VariableGradient & coupledVectorTagGradient(const std::string & var_names,
411 : const std::string & tag_name,
412 : unsigned int index = 0) const;
413 :
414 : /**
415 : * Returns gradients for all the coupled variables desired for a given tag
416 : * @param var_names Name(s) of coupled array variable(s)
417 : * @param tag vector tag ID
418 : * @return Vector of VariableGradient pointers for each variables in \p var_name
419 : */
420 : std::vector<const VariableGradient *> coupledVectorTagGradients(const std::string & var_names,
421 : TagID tag) const;
422 :
423 : std::vector<const VariableGradient *>
424 : coupledVectorTagGradients(const std::string & var_names, const std::string & tag_name) const;
425 :
426 : /**
427 : * Returns gradient of a coupled array variable for a given tag
428 : * @param var_names Name(s) of coupled array variable(s)
429 : * @param tag vector tag ID
430 : * @param index Index of the desired variable in the vector of coupled variables
431 : * @return Reference to a ArrayVariableGradient containing the gradient of the coupled array
432 : * variable
433 : * @see Kernel::gradient
434 : */
435 : virtual const ArrayVariableGradient & coupledVectorTagArrayGradient(const std::string & var_names,
436 : TagID tag,
437 : unsigned int index = 0) const;
438 :
439 : virtual const ArrayVariableGradient & coupledVectorTagArrayGradient(const std::string & var_names,
440 : const std::string & tag_name,
441 : unsigned int index = 0) const;
442 :
443 : /**
444 : * Returns gradients for all the coupled variables desired for a given tag
445 : * @param var_names Name(s) of coupled array variable(s)
446 : * @param tag vector tag ID
447 : * @return Vector of ArrayVariableGradient pointers for each variable in \p var_name
448 : */
449 : std::vector<const ArrayVariableGradient *>
450 : coupledVectorTagArrayGradients(const std::string & var_names, TagID tag) const;
451 :
452 : std::vector<const ArrayVariableGradient *>
453 : coupledVectorTagArrayGradients(const std::string & var_names, const std::string & tag_name) const;
454 :
455 : /**
456 : * Returns dof value of a coupled variable for a given tag
457 : * @param var_names Name(s) of coupled variable(s)
458 : * @param tag vector tag ID
459 : * @param index Index of the desired variable in the vector of coupled variables
460 : * @return Reference to a DofValue for the coupled variable
461 : */
462 : virtual const VariableValue &
463 : coupledVectorTagDofValue(const std::string & var_name, TagID tag, unsigned int index = 0) const;
464 :
465 : virtual const VariableValue & coupledVectorTagDofValue(const std::string & var_names,
466 : const std::string & tag_name,
467 : unsigned int index = 0) const;
468 :
469 : /**
470 : * Returns evaluations of a tagged vector at the requested variable's degree of freedom indices
471 : * @param var_name Name of coupled variable
472 : * @param tag_name vector tag name
473 : * @return Reference to a ArrayVariableValue for the coupled variable
474 : */
475 : const ArrayVariableValue & coupledVectorTagArrayDofValue(const std::string & var_name,
476 : const std::string & tag_name,
477 : unsigned int comp = 0) const;
478 :
479 : /**
480 : * Returns the dof values for all the coupled variables desired for a given tag
481 : * @param var_names Name(s) of coupled variable(s)
482 : * @param tag vector tag ID
483 : * @return Vector of VariableValue pointers for each variable in \p var_name
484 : */
485 : std::vector<const VariableValue *> coupledVectorTagDofValues(const std::string & var_names,
486 : TagID tag) const;
487 :
488 : std::vector<const VariableValue *> coupledVectorTagDofValues(const std::string & var_names,
489 : const std::string & tag_name) const;
490 :
491 : /**
492 : * Returns value of a coupled variable for a given tag. This couples the diag vector of matrix
493 : * @param var_names Name(s) of coupled variable(s)
494 : * @param tag matrix tag ID
495 : * @param index Index of the desired variable in the vector of coupled variables
496 : * @return Reference to a VariableValue for the coupled variable
497 : * @see Kernel::_u
498 : */
499 : virtual const VariableValue &
500 : coupledMatrixTagValue(const std::string & var_names, TagID tag, unsigned int index = 0) const;
501 :
502 : virtual const VariableValue & coupledMatrixTagValue(const std::string & var_names,
503 : const std::string & tag_name,
504 : unsigned int index = 0) const;
505 :
506 : /**
507 : * Returns the diagonal matrix values for all the coupled variables desired for a given tag
508 : * @param var_names Name(s) of coupled variable(s)
509 : * @param tag matrix tag ID
510 : * @return Vector of VariableValue pointers for each variable in \p var_name
511 : */
512 : std::vector<const VariableValue *> coupledMatrixTagValues(const std::string & var_names,
513 : TagID tag) const;
514 :
515 : std::vector<const VariableValue *> coupledMatrixTagValues(const std::string & var_names,
516 : const std::string & tag_name) const;
517 :
518 : /**
519 : * Returns value of a coupled vector variable
520 : * @param var_name Name of coupled vector variable
521 : * @param comp Component number for vector of coupled vector variables
522 : * @return Reference to a VectorVariableValue for the coupled vector variable
523 : * @see VectorKernel::_u
524 : */
525 : virtual const VectorVariableValue & coupledVectorValue(const std::string & var_name,
526 : unsigned int comp = 0) const;
527 :
528 : /**
529 : * Returns value of a coupled array variable
530 : * @param var_name Name of coupled array variable
531 : * @param comp Component number for vector of coupled array variables
532 : * @return Reference to a ArrayVariableValue for the coupled vector variable
533 : * @see ArrayKernel::_u
534 : */
535 : virtual const ArrayVariableValue & coupledArrayValue(const std::string & var_name,
536 : unsigned int comp = 0) const;
537 :
538 : /**
539 : * Returns the values for all of a coupled array variable's components
540 : * @param var_name Name of coupled array variable
541 : * @return Vector of ArrayVariableValue pointers for each component of \p var_name
542 : */
543 : std::vector<const ArrayVariableValue *> coupledArrayValues(const std::string & var_name) const;
544 :
545 : /**
546 : * Returns a *writable* MooseVariable object for a nodal or elemental variable. Use
547 : * var.setNodalValue(val[, idx]) in both cases (!) to set the solution DOF values. Only one
548 : * object can obtain a writable reference in a simulation. Note that the written values will
549 : * not ba available in the same system loop! E.g. values written using this API by a nodal
550 : * AuxKernel will not be updated for other nodal AuxKernels during the same iteration over all
551 : * nodes.
552 : * @param var_name Name of coupled variable
553 : * @param comp Component number for vector of coupled variables
554 : * @return Reference to a MooseWritableVariable for the coupled variable
555 : * @see Kernel::value
556 : */
557 : MooseWritableVariable & writableVariable(const std::string & var_name, unsigned int comp = 0);
558 :
559 : /**
560 : * Returns a *writable* reference to a coupled variable for writing to multiple
561 : * AuxVariables from a single AuxKernel or a UserObject. Only one object can obtain
562 : * a writable reference in a simulation.
563 : * @param var_name Name of coupled variable
564 : * @param comp Component number for vector of coupled variables
565 : * @return Reference to a VariableValue for the coupled variable
566 : * @see Kernel::value
567 : */
568 : virtual VariableValue & writableCoupledValue(const std::string & var_name, unsigned int comp = 0);
569 :
570 : /**
571 : * Checks that the passed in variable is only accessed writable by one object in a given subdomain
572 : */
573 : void checkWritableVar(MooseWritableVariable * var);
574 :
575 : /**
576 : * Returns an old value from previous time step of a coupled variable
577 : * @param var_name Name of coupled variable
578 : * @param comp Component number for vector of coupled variables
579 : * @return Reference to a VariableValue containing the old value of the coupled variable
580 : * @see Kernel::valueOld
581 : */
582 : virtual const VariableValue & coupledValueOld(const std::string & var_name,
583 : unsigned int comp = 0) const;
584 :
585 : /**
586 : * Returns the old values for all of a coupled variable's components
587 : * @param var_name Name of coupled variable
588 : * @return Vector of VariableValue pointers for each component of \p var_name
589 : */
590 : std::vector<const VariableValue *> coupledValuesOld(const std::string & var_name) const;
591 :
592 : /**
593 : * Returns the old values for all of a coupled vector variable's components
594 : * @param var_name Name of coupled vector variable
595 : * @return Vector of VectorVariableValue pointers for each component of \p var_name
596 : */
597 : std::vector<const VectorVariableValue *>
598 : coupledVectorValuesOld(const std::string & var_name) const;
599 :
600 : /**
601 : * Returns an old value from two time steps previous of a coupled variable
602 : * @param var_name Name of coupled variable
603 : * @param comp Component number for vector of coupled variables
604 : * @return Reference to a VariableValue containing the older value of the coupled variable
605 : * @see Kernel::valueOlder
606 : */
607 : virtual const VariableValue & coupledValueOlder(const std::string & var_name,
608 : unsigned int comp = 0) const;
609 :
610 : /**
611 : * Returns the older values for all of a coupled variable's components
612 : * @param var_name Name of coupled variable
613 : * @return Vector of VariableValue pointers for each component of \p var_name
614 : */
615 : std::vector<const VariableValue *> coupledValuesOlder(const std::string & var_name) const;
616 :
617 : /**
618 : * Returns value of previous Newton iterate of a coupled variable
619 : * @param var_name Name of coupled variable
620 : * @param comp Component number for vector of coupled variables
621 : * @return Reference to a VariableValue containing the older value of the coupled variable
622 : */
623 : virtual const VariableValue & coupledValuePreviousNL(const std::string & var_name,
624 : unsigned int comp = 0) const;
625 :
626 : /**
627 : * Returns an old value from previous time step of a coupled vector variable
628 : * @param var_name Name of coupled variable
629 : * @param comp Component number for vector of coupled variables
630 : * @return Reference to a VectorVariableValue containing the old value of the coupled variable
631 : * @see VectorKernel::_u_old
632 : */
633 : virtual const VectorVariableValue & coupledVectorValueOld(const std::string & var_name,
634 : unsigned int comp = 0) const;
635 :
636 : /**
637 : * Returns an old value from two time steps previous of a coupled vector variable
638 : * @param var_name Name of coupled variable
639 : * @param comp Component number for vector of coupled variables
640 : * @return Reference to a VectorVariableValue containing the older value of the coupled variable
641 : * @see VectorKernel::_u_older
642 : */
643 : virtual const VectorVariableValue & coupledVectorValueOlder(const std::string & var_name,
644 : unsigned int comp = 0) const;
645 :
646 : /**
647 : * Returns an old value from previous time step of a coupled array variable
648 : * @param var_name Name of coupled array variable
649 : * @param comp Component number for vector of coupled array variables
650 : * @return Reference to a ArrayVariableValue containing the old value of the coupled variable
651 : * @see ArrayKernel::_u_old
652 : */
653 : virtual const ArrayVariableValue & coupledArrayValueOld(const std::string & var_name,
654 : unsigned int comp = 0) const;
655 :
656 : /**
657 : * Returns an old value from two time steps previous of a coupled array variable
658 : * @param var_name Name of coupled array variable
659 : * @param comp Component number for vector of coupled array variables
660 : * @return Reference to a ArrayVariableValue containing the older value of the coupled variable
661 : * @see ArrayKernel::_u_older
662 : */
663 : virtual const ArrayVariableValue & coupledArrayValueOlder(const std::string & var_name,
664 : unsigned int comp = 0) const;
665 :
666 : /**
667 : * Returns gradient of a coupled variable
668 : * @param var_name Name of coupled variable
669 : * @param comp Component number for vector of coupled variables
670 : * @return Reference to a VariableGradient containing the gradient of the coupled variable
671 : * @see Kernel::gradient
672 : */
673 : virtual const VariableGradient & coupledGradient(const std::string & var_name,
674 : unsigned int comp = 0) const;
675 :
676 : /**
677 : * Returns the gradients for all of a coupled variable's components
678 : * @param var_name Name of coupled variable
679 : * @return Vector of VariableGradient pointers for each component of \p var_name
680 : */
681 : std::vector<const VariableGradient *> coupledGradients(const std::string & var_name) const;
682 :
683 : /**
684 : * Returns gradient of a coupled variable for use in Automatic Differentiation
685 : * @param var_name Name of coupled variable
686 : * @param comp Component number for vector of coupled variables
687 : * @return Reference to an ADVariableGradient containing the gradient of the coupled variable
688 : * @see Kernel::gradient
689 : */
690 : const ADVariableGradient & adCoupledGradient(const std::string & var_name,
691 : unsigned int comp = 0) const;
692 :
693 : /**
694 : * Returns gradient of a coupled variable's time derivative for use in Automatic Differentiation
695 : * @param var_name Name of coupled variable
696 : * @param comp Component number for vector of coupled variables
697 : * @return Reference to an ADVariableGradient containing the gradient of the coupled variable's
698 : * time derivative
699 : */
700 : const ADVariableGradient & adCoupledGradientDot(const std::string & var_name,
701 : unsigned int comp = 0) const;
702 :
703 : /**
704 : * Returns the gradients for all of a coupled variable's components for use in Automatic
705 : * Differentiation
706 : * @param var_name Name of coupled variable
707 : * @return Vector of ADVariableGradient pointers for each component of \p var_name
708 : */
709 : std::vector<const ADVariableGradient *> adCoupledGradients(const std::string & var_name) const;
710 :
711 : /**
712 : * Returns gradient of a coupled variable for use in templated automatic differentiation
713 : * @param var_name Name of coupled variable
714 : * @param comp Component number for vector of coupled variables
715 : * @return Reference to a VariableGradient containing the gradient of the coupled variable
716 : * @see Kernel::gradient
717 : */
718 : template <bool is_ad>
719 : const GenericVariableGradient<is_ad> & coupledGenericGradient(const std::string & var_name,
720 : unsigned int comp = 0) const;
721 :
722 : /**
723 : * Returns the gradients for all of a coupled variable's components for use in templated automatic
724 : * differentiation
725 : * @param var_name Name of coupled variable
726 : * @return Vector of VariableGradient pointers for each component of \p var_name
727 : */
728 : template <bool is_ad>
729 : std::vector<const GenericVariableGradient<is_ad> *>
730 : coupledGenericGradients(const std::string & var_name) const;
731 :
732 : /**
733 : * Returns gradient of a coupled vector variable for use in Automatic Differentiation
734 : * @param var_name Name of coupled vector variable
735 : * @param comp Component number for vector of coupled vector variables
736 : * @return Reference to a VectorVariableGradient containing the gradient of the coupled variable
737 : * @see Kernel::gradient
738 : */
739 : const ADVectorVariableGradient & adCoupledVectorGradient(const std::string & var_name,
740 : unsigned int comp = 0) const;
741 :
742 : /**
743 : * Returns second derivatives of a coupled variable for use in Automatic Differentiation
744 : * @param var_name Name of coupled variable
745 : * @param comp Component number for vector of coupled variables
746 : * @return Reference to a VariableSecond containing the second derivatives of the coupled variable
747 : */
748 : const ADVariableSecond & adCoupledSecond(const std::string & var_name,
749 : unsigned int comp = 0) const;
750 :
751 : /**
752 : * Returns second derivatives of a coupled vector variable for use in Automatic Differentiation
753 : * @param var_name Name of coupled vector variable
754 : * @param comp Component number for vector of coupled vector variables
755 : * @return Reference to a VectorVariableSecond containing the second derivatives of the coupled
756 : * variable
757 : */
758 : const ADVectorVariableSecond & adCoupledVectorSecond(const std::string & var_name,
759 : unsigned int comp = 0) const;
760 :
761 : /**
762 : * Returns an old gradient from previous time step of a coupled variable
763 : * @param var_name Name of coupled variable
764 : * @param comp Component number for vector of coupled variables
765 : * @return Reference to a VariableGradient containing the old gradient of the coupled variable
766 : * @see Kernel::gradientOld
767 : */
768 : virtual const VariableGradient & coupledGradientOld(const std::string & var_name,
769 : unsigned int comp = 0) const;
770 :
771 : /**
772 : * Returns the old gradients for all of a coupled variable's components
773 : * @param var_name Name of coupled variable
774 : * @return Vector of VariableGradient pointers for each component of \p var_name
775 : */
776 : std::vector<const VariableGradient *> coupledGradientsOld(const std::string & var_name) const;
777 :
778 : /**
779 : * Returns an old gradient from two time steps previous of a coupled variable
780 : * @param var_name Name of coupled variable
781 : * @param comp Component number for vector of coupled variables
782 : * @return Reference to a VariableGradient containing the older gradient of the coupled variable
783 : * @see Kernel::gradientOlder
784 : */
785 : virtual const VariableGradient & coupledGradientOlder(const std::string & var_name,
786 : unsigned int comp = 0) const;
787 :
788 : /**
789 : * Returns gradient of a coupled variable for previous Newton iterate
790 : * @param var_name Name of coupled variable
791 : * @param comp Component number for vector of coupled variables
792 : * @return Reference to a VariableGradient containing the gradient of the coupled variable
793 : */
794 : virtual const VariableGradient & coupledGradientPreviousNL(const std::string & var_name,
795 : unsigned int comp = 0) const;
796 :
797 : /**
798 : * Time derivative of the gradient of a coupled variable
799 : * @param var_name Name of coupled variable
800 : * @param comp Component number for vector of coupled variables
801 : * @return Reference to a VariableGradient containing the time derivative of the gradient of a
802 : * coupled variable
803 : */
804 : virtual const VariableGradient & coupledGradientDot(const std::string & var_name,
805 : unsigned int comp = 0) const;
806 :
807 : /**
808 : * Second time derivative of the gradient of a coupled variable
809 : * @param var_name Name of coupled variable
810 : * @param comp Component number for vector of coupled variables
811 : * @return Reference to a VariableGradient containing the time derivative of the gradient of a
812 : * coupled variable
813 : */
814 : virtual const VariableGradient & coupledGradientDotDot(const std::string & var_name,
815 : unsigned int comp = 0) const;
816 :
817 : /**
818 : * Returns gradient of a coupled vector variable
819 : * @param var_name Name of coupled vector variable
820 : * @param comp Component number for vector of coupled vector variables
821 : * @return Reference to a VectorVariableGradient containing the gradient of the coupled vector
822 : * variable
823 : */
824 : virtual const VectorVariableGradient & coupledVectorGradient(const std::string & var_name,
825 : unsigned int comp = 0) const;
826 :
827 : /**
828 : * Returns an old gradient from previous time step of a coupled vector variable
829 : * @param var_name Name of coupled vector variable
830 : * @param comp Component number for vector of coupled vector variables
831 : * @return Reference to a VectorVariableGradient containing the old gradient of the coupled vector
832 : * variable
833 : */
834 : virtual const VectorVariableGradient & coupledVectorGradientOld(const std::string & var_name,
835 : unsigned int comp = 0) const;
836 :
837 : /**
838 : * Returns an old gradient from two time steps previous of a coupled vector variable
839 : * @param var_name Name of coupled vector variable
840 : * @param comp Component number for vector of coupled vector variables
841 : * @return Reference to a VectorVariableGradient containing the older gradient of the coupled
842 : * vector variable
843 : */
844 : virtual const VectorVariableGradient & coupledVectorGradientOlder(const std::string & var_name,
845 : unsigned int comp = 0) const;
846 :
847 : /**
848 : * Returns gradient of a coupled array variable
849 : * @param var_name Name of coupled array variable
850 : * @param comp Component number for vector of coupled array variables
851 : * @return Reference to a VectorVariableGradient containing the gradient of the coupled array
852 : * variable
853 : */
854 : virtual const ArrayVariableGradient & coupledArrayGradient(const std::string & var_name,
855 : unsigned int comp = 0) const;
856 :
857 : /**
858 : * Returns an old gradient from previous time step of a coupled array variable
859 : * @param var_name Name of coupled array variable
860 : * @param comp Component number for vector of coupled array variables
861 : * @return Reference to a VectorVariableGradient containing the old gradient of the coupled array
862 : * variable
863 : */
864 : virtual const ArrayVariableGradient & coupledArrayGradientOld(const std::string & var_name,
865 : unsigned int comp = 0) const;
866 :
867 : /**
868 : * Returns an old gradient from two time steps previous of a coupled array variable
869 : * @param var_name Name of coupled array variable
870 : * @param comp Component number for vector of coupled array variables
871 : * @return Reference to a ArrayVariableGradient containing the older gradient of the coupled
872 : * array variable
873 : */
874 : virtual const ArrayVariableGradient & coupledArrayGradientOlder(const std::string & var_name,
875 : unsigned int comp = 0) const;
876 :
877 : /**
878 : * Retun a gradient of a coupled array variable's time derivative
879 : * @param var_name Name of coupled array variable
880 : * @param comp Component number for vector of coupled array variables
881 : * @return Reference to a ArrayVariableGradient containing the gradient of the time derivative
882 : * the coupled array variable
883 : */
884 : virtual const ArrayVariableGradient & coupledArrayGradientDot(const std::string & var_name,
885 : unsigned int comp = 0) const;
886 :
887 : /**
888 : * Returns curl of a coupled variable
889 : * @param var_name Name of coupled variable
890 : * @param comp Component number for vector of coupled variables
891 : * @return Reference to a VectorVariableCurl containing the curl of the coupled variable
892 : * @see Kernel::_curl_u
893 : */
894 : virtual const VectorVariableCurl & coupledCurl(const std::string & var_name,
895 : unsigned int comp = 0) const;
896 :
897 : /**
898 : * Returns an old curl from previous time step of a coupled variable
899 : * @param var_name Name of coupled variable
900 : * @param comp Component number for vector of coupled variables
901 : * @return Reference to a VectorVariableCurl containing the old curl of the coupled variable
902 : * @see Kernel::_curl_u_old
903 : */
904 : virtual const VectorVariableCurl & coupledCurlOld(const std::string & var_name,
905 : unsigned int comp = 0) const;
906 :
907 : /**
908 : * Returns an old curl from two time steps previous of a coupled variable
909 : * @param var_name Name of coupled variable
910 : * @param comp Component number for vector of coupled variables
911 : * @return Reference to a VectorVariableCurl containing the older curl of the coupled variable
912 : * @see Kernel::_curl_u_older
913 : */
914 : virtual const VectorVariableCurl & coupledCurlOlder(const std::string & var_name,
915 : unsigned int comp = 0) const;
916 :
917 : /**
918 : * Returns curl of a coupled variable for use in objects utilizing Automatic Differentiation
919 : * @param var_name Name of coupled variable
920 : * @param comp Component number for vector of coupled variables
921 : * @return Reference to an ADVectorVariableCurl containing the curl of the coupled variable
922 : * @see Kernel::_curl_u
923 : */
924 : const ADVectorVariableCurl & adCoupledCurl(const std::string & var_name,
925 : unsigned int comp = 0) const;
926 :
927 : /**
928 : * Returns divergence of a coupled variable
929 : * @param var_name Name of coupled variable
930 : * @param comp Component number for vector of coupled variables
931 : * @return Reference to a VectorVariableDivergence containing the divergence of the coupled
932 : * variable
933 : * @see Kernel::_div_u
934 : */
935 : virtual const VectorVariableDivergence & coupledDiv(const std::string & var_name,
936 : unsigned int comp = 0) const;
937 :
938 : /**
939 : * Returns an old divergence from previous time step of a coupled variable
940 : * @param var_name Name of coupled variable
941 : * @param comp Component number for vector of coupled variables
942 : * @return Reference to a VectorVariableDivergence containing the old divergence of the coupled
943 : * variable
944 : * @see Kernel::_div_u_old
945 : */
946 : virtual const VectorVariableDivergence & coupledDivOld(const std::string & var_name,
947 : unsigned int comp = 0) const;
948 :
949 : /**
950 : * Returns an old divergence from two time steps previous of a coupled variable
951 : * @param var_name Name of coupled variable
952 : * @param comp Component number for vector of coupled variables
953 : * @return Reference to a VectorVariableDivergence containing the older divergence of the coupled
954 : * variable
955 : * @see Kernel::_div_u_older
956 : */
957 : virtual const VectorVariableDivergence & coupledDivOlder(const std::string & var_name,
958 : unsigned int comp = 0) const;
959 :
960 : /**
961 : * Returns second spatial derivatives of a coupled variable
962 : * @param var_name Name of coupled variable
963 : * @param comp Component number for vector of coupled variables
964 : * @return Reference to a VariableSecond containing the second derivative of the coupled variable
965 : * @see Kernel::second
966 : */
967 : virtual const VariableSecond & coupledSecond(const std::string & var_name,
968 : unsigned int comp = 0) const;
969 :
970 : /**
971 : * Returns an old second spatial derivatives from previous time step of a coupled variable
972 : * @param var_name Name of coupled variable
973 : * @param comp Component number for vector of coupled variables
974 : * @return Reference to a VariableSecond containing the old second derivative of the coupled
975 : * variable
976 : * @see Kernel::secondOld
977 : */
978 : virtual const VariableSecond & coupledSecondOld(const std::string & var_name,
979 : unsigned int comp = 0) const;
980 :
981 : /**
982 : * Returns an old second derivative from two time steps previous of a coupled variable
983 : * @param var_name Name of coupled variable
984 : * @param comp Component number for vector of coupled variables
985 : * @return Reference to a VariableSecond containing the older second derivative of the coupled
986 : * variable
987 : * @see Kernel::secondOlder
988 : */
989 : virtual const VariableSecond & coupledSecondOlder(const std::string & var_name,
990 : unsigned int comp = 0) const;
991 :
992 : /**
993 : * Returns second derivative of a coupled variable for the previous Newton iterate
994 : * @param var_name Name of coupled variable
995 : * @param comp Component number for vector of coupled variables
996 : * @return Reference to a VariableSecond containing the second derivative of the coupled variable
997 : */
998 : virtual const VariableSecond & coupledSecondPreviousNL(const std::string & var_name,
999 : unsigned int comp = 0) const;
1000 :
1001 : /**
1002 : * Time derivative of a coupled variable
1003 : * @param var_name Name of coupled variable
1004 : * @param comp Component number for vector of coupled variables
1005 : * @return Reference to a VariableValue containing the time derivative of the coupled variable
1006 : */
1007 : virtual const VariableValue & coupledDot(const std::string & var_name,
1008 : unsigned int comp = 0) const;
1009 :
1010 : /**
1011 : * Returns the time derivatives for all of a coupled variable's components
1012 : * @param var_name Name of coupled variable
1013 : * @return Vector of VariableValue pointers for each component of \p var_name
1014 : */
1015 : std::vector<const VariableValue *> coupledDots(const std::string & var_name) const;
1016 :
1017 : /**
1018 : * Second time derivative of a coupled variable
1019 : * @param var_name Name of coupled variable
1020 : * @param comp Component number for vector of coupled variables
1021 : * @return Reference to a VariableValue containing the second time derivative of the coupled
1022 : * variable
1023 : */
1024 : virtual const VariableValue & coupledDotDot(const std::string & var_name,
1025 : unsigned int comp = 0) const;
1026 :
1027 : /**
1028 : * Old time derivative of a coupled variable
1029 : * @param var_name Name of coupled variable
1030 : * @param comp Component number for vector of coupled variables
1031 : * @return Reference to a VariableValue containing the old time derivative of the coupled variable
1032 : */
1033 : virtual const VariableValue & coupledDotOld(const std::string & var_name,
1034 : unsigned int comp = 0) const;
1035 :
1036 : /**
1037 : * Old second time derivative of a coupled variable
1038 : * @param var_name Name of coupled variable
1039 : * @param comp Component number for vector of coupled variables
1040 : * @return Reference to a VariableValue containing the old second time derivative of the coupled
1041 : * variable
1042 : */
1043 : virtual const VariableValue & coupledDotDotOld(const std::string & var_name,
1044 : unsigned int comp = 0) const;
1045 :
1046 : /**
1047 : * Time derivative of a coupled variable for ad simulations
1048 : * @param var_name Name of coupled variable
1049 : * @param comp Component number for vector of coupled variables
1050 : * @return Reference to a VariableValue containing the time derivative of the coupled variable
1051 : * @see Kernel::dot
1052 : */
1053 : const ADVariableValue & adCoupledDot(const std::string & var_name, unsigned int comp = 0) const;
1054 :
1055 : /**
1056 : * Returns the time derivatives for all of a coupled variable's components for ad simulations
1057 : * @param var_name Name of coupled variable
1058 : * @return Vector of VariableValue pointers for each component of \p var_name
1059 : */
1060 : std::vector<const ADVariableValue *> adCoupledDots(const std::string & var_name) const;
1061 :
1062 : /**
1063 : * Second time derivative of a coupled variable for ad simulations
1064 : * @param var_name Name of coupled variable
1065 : * @param comp Component number for vector of coupled variables
1066 : * @return Reference to an ADVariableValue containing the second time derivative of the coupled
1067 : * variable
1068 : */
1069 : const ADVariableValue & adCoupledDotDot(const std::string & var_name,
1070 : unsigned int comp = 0) const;
1071 :
1072 : /**
1073 : * Time derivative of a vector coupled variable for ad simulations
1074 : * @param var_name Name of vector coupled variable
1075 : * @param comp Component number
1076 : * @return Reference to a VectorVariableValue containing the time derivative of the coupled
1077 : * variable
1078 : * @see Kernel::dot
1079 : */
1080 : const ADVectorVariableValue & adCoupledVectorDot(const std::string & var_name,
1081 : unsigned int comp = 0) const;
1082 :
1083 : /**
1084 : * Time derivative of a coupled vector variable
1085 : * @param var_name Name of coupled vector variable
1086 : * @param comp Component number for vector of coupled vector variables
1087 : * @return Reference to a VectorVariableValue containing the time derivative of the coupled
1088 : * variable
1089 : */
1090 : virtual const VectorVariableValue & coupledVectorDot(const std::string & var_name,
1091 : unsigned int comp = 0) const;
1092 :
1093 : /**
1094 : * Second time derivative of a coupled vector variable
1095 : * @param var_name Name of coupled vector variable
1096 : * @param comp Component number for vector of coupled vector variables
1097 : * @return Reference to a VectorVariableValue containing the time derivative of the coupled
1098 : * variable
1099 : */
1100 : virtual const VectorVariableValue & coupledVectorDotDot(const std::string & var_name,
1101 : unsigned int comp = 0) const;
1102 :
1103 : /**
1104 : * Old time derivative of a coupled vector variable
1105 : * @param var_name Name of coupled vector variable
1106 : * @param comp Component number for vector of coupled vector variables
1107 : * @return Reference to a VectorVariableValue containing the time derivative of the coupled
1108 : * variable
1109 : */
1110 : virtual const VectorVariableValue & coupledVectorDotOld(const std::string & var_name,
1111 : unsigned int comp = 0) const;
1112 :
1113 : /**
1114 : * Old second time derivative of a coupled vector variable
1115 : * @param var_name Name of coupled vector variable
1116 : * @param comp Component number for vector of coupled vector variables
1117 : * @return Reference to a VectorVariableValue containing the time derivative of the coupled
1118 : * variable
1119 : */
1120 : virtual const VectorVariableValue & coupledVectorDotDotOld(const std::string & var_name,
1121 : unsigned int comp = 0) const;
1122 :
1123 : /**
1124 : * Time derivative of a coupled vector variable with respect to the coefficients
1125 : * @param var_name Name of coupled vector variable
1126 : * @param comp Component number for vector of coupled vector variables
1127 : * @return Reference to a VariableValue containing the time derivative of the coupled
1128 : * vector variable with respect to the coefficients
1129 : */
1130 : virtual const VariableValue & coupledVectorDotDu(const std::string & var_name,
1131 : unsigned int comp = 0) const;
1132 :
1133 : /**
1134 : * Second time derivative of a coupled vector variable with respect to the coefficients
1135 : * @param var_name Name of coupled vector variable
1136 : * @param comp Component number for vector of coupled vector variables
1137 : * @return Reference to a VariableValue containing the time derivative of the coupled vector
1138 : * variable with respect to the coefficients
1139 : */
1140 : virtual const VariableValue & coupledVectorDotDotDu(const std::string & var_name,
1141 : unsigned int comp = 0) const;
1142 :
1143 : /**
1144 : * Time derivative of a coupled array variable
1145 : * @param var_name Name of coupled array variable
1146 : * @param comp Component number for vector of coupled array variables
1147 : * @return Reference to a ArrayVariableValue containing the time derivative of the coupled
1148 : * variable
1149 : */
1150 : virtual const ArrayVariableValue & coupledArrayDot(const std::string & var_name,
1151 : unsigned int comp = 0) const;
1152 :
1153 : /**
1154 : * Second time derivative of a coupled array variable
1155 : * @param var_name Name of coupled array variable
1156 : * @param comp Component number for vector of coupled array variables
1157 : * @return Reference to a ArrayVariableValue containing the time derivative of the coupled
1158 : * variable
1159 : */
1160 : virtual const ArrayVariableValue & coupledArrayDotDot(const std::string & var_name,
1161 : unsigned int comp = 0) const;
1162 :
1163 : /**
1164 : * Old time derivative of a coupled array variable
1165 : * @param var_name Name of coupled array variable
1166 : * @param comp Component number for vector of coupled array variables
1167 : * @return Reference to a ArrayVariableValue containing the time derivative of the coupled
1168 : * variable
1169 : */
1170 : virtual const ArrayVariableValue & coupledArrayDotOld(const std::string & var_name,
1171 : unsigned int comp = 0) const;
1172 :
1173 : /**
1174 : * Old second time derivative of a coupled array variable
1175 : * @param var_name Name of coupled array variable
1176 : * @param comp Component number for vector of coupled array variables
1177 : * @return Reference to a ArrayVariableValue containing the time derivative of the coupled
1178 : * variable
1179 : */
1180 : virtual const ArrayVariableValue & coupledArrayDotDotOld(const std::string & var_name,
1181 : unsigned int comp = 0) const;
1182 :
1183 : /**
1184 : * Time derivative of a coupled variable with respect to the coefficients
1185 : * @param var_name Name of coupled variable
1186 : * @param comp Component number for vector of coupled variables
1187 : * @return Reference to a VariableValue containing the time derivative of the coupled variable
1188 : * with respect to the coefficients
1189 : */
1190 : virtual const VariableValue & coupledDotDu(const std::string & var_name,
1191 : unsigned int comp = 0) const;
1192 :
1193 : /**
1194 : * Second time derivative of a coupled variable with respect to the coefficients
1195 : * @param var_name Name of coupled variable
1196 : * @param comp Component number for vector of coupled variables
1197 : * @return Reference to a VariableValue containing the time derivative of the coupled variable
1198 : * with respect to the coefficients
1199 : */
1200 : virtual const VariableValue & coupledDotDotDu(const std::string & var_name,
1201 : unsigned int comp = 0) const;
1202 :
1203 : /**
1204 : * Time derivative of a coupled array variable with respect to the coefficients
1205 : * @param var_name Name of coupled array variable
1206 : * @param comp Component number for vector of coupled array variables
1207 : * @return Reference to a ArrayVariableValue containing the time derivative of the coupled
1208 : * variable
1209 : */
1210 : const VariableValue & coupledArrayDotDu(const std::string & var_name,
1211 : unsigned int comp = 0) const;
1212 :
1213 : /**
1214 : * Returns nodal values of a coupled variable
1215 : * @param var_name Name of coupled variable
1216 : * @param comp Component number for vector of coupled variables
1217 : * @return Reference to a VariableValue for the coupled variable
1218 : */
1219 : template <typename T>
1220 : const T & coupledNodalValue(const std::string & var_name, unsigned int comp = 0) const;
1221 :
1222 : /**
1223 : * Returns AD nodal values of a coupled variable
1224 : * @param var_name Name of coupled variable
1225 : * @param comp Component number for vector of coupled variables
1226 : * @return Reference to a VariableValue for the coupled variable
1227 : */
1228 : template <typename T>
1229 : const typename Moose::ADType<T>::type & adCoupledNodalValue(const std::string & var_name,
1230 : unsigned int comp = 0) const;
1231 :
1232 : /**
1233 : * Returns an old nodal value from previous time step of a coupled variable
1234 : * @param var_name Name of coupled variable
1235 : * @param comp Component number for vector of coupled variables
1236 : * @return Reference to a VariableValue containing the old value of the coupled variable
1237 : */
1238 : template <typename T>
1239 : const T & coupledNodalValueOld(const std::string & var_name, unsigned int comp = 0) const;
1240 :
1241 : /**
1242 : * Returns an old nodal value from two time steps previous of a coupled variable
1243 : * @param var_name Name of coupled variable
1244 : * @param comp Component number for vector of coupled variables
1245 : * @return Reference to a VariableValue containing the older value of the coupled variable
1246 : */
1247 : template <typename T>
1248 : const T & coupledNodalValueOlder(const std::string & var_name, unsigned int comp = 0) const;
1249 :
1250 : /**
1251 : * Returns nodal values of a coupled variable for previous Newton iterate
1252 : * @param var_name Name of coupled variable
1253 : * @param comp Component number for vector of coupled variables
1254 : * @return Reference to a VariableValue for the coupled variable
1255 : */
1256 : template <typename T>
1257 : const T & coupledNodalValuePreviousNL(const std::string & var_name, unsigned int comp = 0) const;
1258 :
1259 : /**
1260 : * Nodal values of time derivative of a coupled variable
1261 : * @param var_name Name of coupled variable
1262 : * @param comp Component number for vector of coupled variables
1263 : * @return Reference to a VariableValue containing the nodal values of time derivative of the
1264 : * coupled variable
1265 : */
1266 : template <typename T>
1267 : const T & coupledNodalDot(const std::string & var_name, unsigned int comp = 0) const;
1268 :
1269 : /**
1270 : * Nodal values of second time derivative of a coupled variable
1271 : * @param var_name Name of coupled variable
1272 : * @param comp Component number for vector of coupled variables
1273 : * @return Reference to a VariableValue containing the nodal values of second time derivative of
1274 : * the coupled variable
1275 : */
1276 : virtual const VariableValue & coupledNodalDotDot(const std::string & var_name,
1277 : unsigned int comp = 0) const;
1278 :
1279 : /**
1280 : * Nodal values of old time derivative of a coupled variable
1281 : * @param var_name Name of coupled variable
1282 : * @param comp Component number for vector of coupled variables
1283 : * @return Reference to a VariableValue containing the nodal values of time derivative of the
1284 : * coupled variable
1285 : */
1286 : virtual const VariableValue & coupledNodalDotOld(const std::string & var_name,
1287 : unsigned int comp = 0) const;
1288 :
1289 : /**
1290 : * Nodal values of old second time derivative of a coupled variable
1291 : * @param var_name Name of coupled variable
1292 : * @param comp Component number for vector of coupled variables
1293 : * @return Reference to a VariableValue containing the nodal values of second time derivative of
1294 : * the coupled variable
1295 : */
1296 : virtual const VariableValue & coupledNodalDotDotOld(const std::string & var_name,
1297 : unsigned int comp = 0) const;
1298 : // coupled-dof-values-begin
1299 : /**
1300 : * Returns DoFs in the current solution vector of a coupled variable for the local element
1301 : * @param var_name Name of coupled variable
1302 : * @param comp Component number for vector of coupled variables
1303 : * @return Reference to a VariableValue for the DoFs of the coupled variable
1304 : */
1305 : virtual const VariableValue & coupledDofValues(const std::string & var_name,
1306 : unsigned int comp = 0) const;
1307 :
1308 : /**
1309 : * Returns DoFs in the current solution vector of all of a coupled variable's components for the
1310 : * local element
1311 : * @param var_name Name of coupled variable
1312 : * @return Vector of VariableValue pointers for each component of the coupled variable
1313 : */
1314 : std::vector<const VariableValue *> coupledAllDofValues(const std::string & var_name) const;
1315 :
1316 : /**
1317 : * Returns DoFs in the old solution vector of a coupled variable for the local element
1318 : * @param var_name Name of coupled variable
1319 : * @param comp Component number for vector of coupled variables
1320 : * @return Reference to a VariableValue for the old DoFs of the coupled variable
1321 : */
1322 : virtual const VariableValue & coupledDofValuesOld(const std::string & var_name,
1323 : unsigned int comp = 0) const;
1324 :
1325 : /**
1326 : * Returns DoFs in the old solution vector of all of a coupled variable's components for the local
1327 : * element
1328 : * @param var_name Name of coupled variable
1329 : * @return Vector of VariableValue pointers for each compontnet of the coupled variable
1330 : */
1331 : std::vector<const VariableValue *> coupledAllDofValuesOld(const std::string & var_name) const;
1332 :
1333 : /**
1334 : * Returns DoFs in the older solution vector of a coupled variable for the local element
1335 : * @param var_name Name of coupled variable
1336 : * @param comp Component number for vector of coupled variables
1337 : * @return Reference to a VariableValue for the older DoFs of the coupled variable
1338 : */
1339 : virtual const VariableValue & coupledDofValuesOlder(const std::string & var_name,
1340 : unsigned int comp = 0) const;
1341 :
1342 : /**
1343 : * Returns DoFs in the older solution vector of all of a coupled variable's components for the
1344 : * local element
1345 : * @param var_name Name of coupled variable
1346 : * @return Vector of VariableValue pointers for each component of the coupled variable
1347 : */
1348 : std::vector<const VariableValue *> coupledAllDofValuesOlder(const std::string & var_name) const;
1349 :
1350 : /**
1351 : * Returns DoFs in the current solution vector of a coupled array variable for the local element
1352 : * @param var_name Name of coupled array variable
1353 : * @param comp Component number for vector of coupled array variables
1354 : * @return Reference to a VariableValue for the DoFs of the coupled variable
1355 : */
1356 : virtual const ArrayVariableValue & coupledArrayDofValues(const std::string & var_name,
1357 : unsigned int comp = 0) const;
1358 : // coupled-dof-values-end
1359 :
1360 : /**
1361 : * Returns DOF value of a coupled variable for use in Automatic Differentiation
1362 : * @param var_name Name of coupled variable
1363 : * @param comp Component number for vector of coupled variables
1364 : * @return Reference to an ADVariableValue for the DoFs of the coupled variable
1365 : */
1366 : virtual const ADVariableValue & adCoupledDofValues(const std::string & var_name,
1367 : unsigned int comp = 0) const;
1368 :
1369 : /**
1370 : * method that returns _zero to RESIDUAL computing objects and _ad_zero to JACOBIAN
1371 : * computing objects
1372 : */
1373 : const ADVariableValue & adZeroValue() const;
1374 :
1375 : /**
1376 : * method that returns _grad_zero to RESIDUAL computing objects and _ad_grad_zero to
1377 : * JACOBIAN computing objects
1378 : */
1379 : const ADVariableGradient & adZeroGradient() const;
1380 :
1381 : /**
1382 : * Retrieve a zero second for automatic differentiation
1383 : */
1384 : const ADVariableSecond & adZeroSecond() const;
1385 :
1386 : /**
1387 : * Returns zero value templated with automatic differentiation boolean
1388 : * @return Reference to a const GenericVariableValue
1389 : */
1390 : template <bool is_ad>
1391 : const GenericVariableValue<is_ad> & genericZeroValue();
1392 :
1393 : /**
1394 : * Returns zero gradient templated with automatic differentiation boolean
1395 : * @return Reference to a const GenericVariableValue
1396 : */
1397 : template <bool is_ad>
1398 : const GenericVariableGradient<is_ad> & genericZeroGradient();
1399 :
1400 : /**
1401 : * Returns zero second derivative templated with automatic differentiation boolean
1402 : * @return Reference to a const GenericVariableValue
1403 : */
1404 : template <bool is_ad>
1405 : const GenericVariableSecond<is_ad> & genericZeroSecond();
1406 :
1407 : protected:
1408 : // Reference to the interface's input parameters
1409 : const InputParameters & _c_parameters;
1410 :
1411 : /// The name of the object this interface is part of
1412 : const std::string & _c_name;
1413 : /// The type of the object this interface is part of
1414 : const std::string & _c_type;
1415 :
1416 : // Reference to FEProblemBase
1417 : FEProblemBase & _c_fe_problem;
1418 :
1419 : /// Pointer to the system object if the moose object this is an interface for has one
1420 : const SystemBase * const _c_sys;
1421 :
1422 : /// Coupled vars whose values we provide
1423 : std::unordered_map<std::string, std::vector<MooseVariableFieldBase *>> _coupled_vars;
1424 :
1425 : /// Vector of all coupled variables
1426 : std::vector<MooseVariableFieldBase *> _coupled_moose_vars;
1427 :
1428 : /// Vector of standard coupled variables
1429 : std::vector<MooseVariable *> _coupled_standard_moose_vars;
1430 :
1431 : /// Vector of vector coupled variables
1432 : std::vector<VectorMooseVariable *> _coupled_vector_moose_vars;
1433 :
1434 : /// Vector of array coupled variables
1435 : std::vector<ArrayMooseVariable *> _coupled_array_moose_vars;
1436 :
1437 : /// Vector of all finite volume coupled variables
1438 : std::vector<MooseVariableField<Real> *> _coupled_fv_moose_vars;
1439 :
1440 : /// map from new to deprecated variable names
1441 : const std::unordered_map<std::string, std::string> & _new_to_deprecated_coupled_vars;
1442 :
1443 : /// True if we provide coupling to nodal values
1444 : bool _c_nodal;
1445 :
1446 : /// True if implicit value is required
1447 : bool _c_is_implicit;
1448 :
1449 : // Argument to allow element-to-nodal coupling
1450 : const bool _c_allow_element_to_nodal_coupling;
1451 :
1452 : /// Thread ID of the thread using this object
1453 : THREAD_ID _c_tid;
1454 :
1455 : /// Will hold the default value for optional coupled variables.
1456 : mutable std::unordered_map<std::string, std::vector<std::unique_ptr<VariableValue>>>
1457 : _default_value;
1458 :
1459 : /// Will hold the default value for optional coupled variables for automatic differentiation.
1460 : mutable std::unordered_map<std::string, std::unique_ptr<MooseArray<ADReal>>> _ad_default_value;
1461 :
1462 : /// Will hold the default value for optional vector coupled variables.
1463 : mutable std::unordered_map<std::string, std::unique_ptr<VectorVariableValue>>
1464 : _default_vector_value;
1465 :
1466 : /// Will hold the default value for optional array coupled variables.
1467 : mutable std::unordered_map<std::string, std::unique_ptr<ArrayVariableValue>> _default_array_value;
1468 :
1469 : /// Will hold the default value for optional vector coupled variables for automatic differentiation.
1470 : mutable std::unordered_map<std::string, std::unique_ptr<MooseArray<ADRealVectorValue>>>
1471 : _ad_default_vector_value;
1472 :
1473 : /**
1474 : * This will always be zero because the default values for optionally coupled variables is always
1475 : * constant and this is used for time derivative info
1476 : */
1477 : mutable VariableValue _default_value_zero;
1478 :
1479 : /// This will always be zero because the default values for optionally coupled variables is always constant
1480 : mutable VariableGradient _default_gradient;
1481 :
1482 : /// This will always be zero because the default values for optionally coupled variables is always constant
1483 : mutable MooseArray<ADRealVectorValue> _ad_default_gradient;
1484 :
1485 : /// This will always be zero because the default values for optionally coupled vector variables is always constant
1486 : mutable MooseArray<ADRealTensorValue> _ad_default_vector_gradient;
1487 :
1488 : /// This will always be zero because the default values for optionally coupled variables is always constant
1489 : mutable VariableSecond _default_second;
1490 :
1491 : /// This will always be zero because the default values for optionally coupled variables is always constant
1492 : mutable MooseArray<ADRealTensorValue> _ad_default_second;
1493 :
1494 : /// This will always be zero because the default values for optionally coupled vector variables is always constant
1495 : mutable MooseArray<ADRealVectorValue> _ad_default_curl;
1496 :
1497 : /// Zero value of a variable
1498 : const VariableValue & _zero;
1499 : const VariablePhiValue & _phi_zero;
1500 : const MooseArray<ADReal> & _ad_zero;
1501 :
1502 : /// Zero gradient of a variable
1503 : const VariableGradient & _grad_zero;
1504 : const MooseArray<ADRealVectorValue> & _ad_grad_zero;
1505 :
1506 : /// Zero gradient of trial function
1507 : const VariablePhiGradient & _grad_phi_zero;
1508 :
1509 : /// Zero second derivative of a variable
1510 : const VariableSecond & _second_zero;
1511 : const MooseArray<ADRealTensorValue> & _ad_second_zero;
1512 : /// Zero second derivative of a test function
1513 : const VariablePhiSecond & _second_phi_zero;
1514 : /// Zero value of a vector variable
1515 : const VectorVariableValue & _vector_zero;
1516 : /// Zero value of the curl of a vector variable
1517 : const VectorVariableCurl & _vector_curl_zero;
1518 :
1519 : /**
1520 : * This will always be zero because the default values for optionally coupled variables is always
1521 : * constant and this is used for time derivative info
1522 : */
1523 : mutable VectorVariableValue _default_vector_value_zero;
1524 :
1525 : /// This will always be zero because the default values for optionally coupled variables is always constant
1526 : mutable VectorVariableGradient _default_vector_gradient;
1527 :
1528 : /// This will always be zero because the default values for optionally coupled variables is always constant
1529 : mutable VectorVariableCurl _default_vector_curl;
1530 :
1531 : /// This will always be zero because the default values for optionally coupled variables is always constant
1532 : mutable VectorVariableDivergence _default_div;
1533 :
1534 : /**
1535 : * This will always be zero because the default values for optionally coupled variables is always
1536 : * constant and this is used for time derivative info
1537 : */
1538 : ArrayVariableValue _default_array_value_zero;
1539 :
1540 : /// This will always be zero because the default values for optionally coupled variables is always constant
1541 : ArrayVariableGradient _default_array_gradient;
1542 :
1543 : /**
1544 : * Check that the right kind of variable is being coupled in
1545 : *
1546 : * @param var_name The name of the coupled variable
1547 : */
1548 : bool
1549 : checkVar(const std::string & var_name, unsigned int comp = 0, unsigned int comp_bound = 0) const;
1550 :
1551 : private:
1552 : /**
1553 : * Generic helper method to get vector tag values based on tag ID
1554 : */
1555 : template <typename T>
1556 : const typename OutputTools<T>::VariableValue &
1557 : vectorTagValueHelper(const std::string & var_names, TagID tag, unsigned int index = 0) const;
1558 :
1559 : /**
1560 : * Generic helper method to get vector tag values based on tag name
1561 : */
1562 : template <typename T>
1563 : const typename OutputTools<T>::VariableValue & vectorTagValueHelper(const std::string & var_names,
1564 : const std::string & tag_name,
1565 : unsigned int index = 0) const;
1566 :
1567 : /**
1568 : * Generic helper method to get vector tag degree of freedom values based on tag ID
1569 : */
1570 : template <typename T>
1571 : const typename OutputTools<T>::VariableValue &
1572 : vectorTagDofValueHelper(const std::string & var_name, TagID tag, unsigned int comp = 0) const;
1573 :
1574 : /**
1575 : * Generic helper method to get vector tag degree of freedom values based on tag name
1576 : */
1577 : template <typename T>
1578 : const typename OutputTools<T>::VariableValue & vectorTagDofValueHelper(
1579 : const std::string & var_name, const std::string & tag_name, unsigned int comp = 0) const;
1580 :
1581 : /**
1582 : * Method that may request additional solution states from the variable's system depending on the
1583 : * value of \p tag_name. E.g. if the tag name corresponds to old or older variable solution
1584 : * values, then we must request more states
1585 : */
1586 : template <typename T>
1587 : void
1588 : requestStates(const std::string & var_name, const TagName & tag_name, const unsigned int comp);
1589 :
1590 : enum class FuncAge
1591 : {
1592 : Curr,
1593 : Old,
1594 : Older,
1595 : };
1596 :
1597 : enum class VarType
1598 : {
1599 : Ignore,
1600 : Gradient,
1601 : Second,
1602 : GradientDot,
1603 : Dot,
1604 : };
1605 :
1606 : void checkFuncType(const std::string var_name, VarType t, FuncAge age) const;
1607 :
1608 : protected:
1609 : /**
1610 : * Deprecated method. Use \p getFieldVar instead
1611 : * Extract pointer to a base coupled field variable. Could be either a finite volume or finite
1612 : * element variable
1613 : * @param var_name Name of parameter desired
1614 : * @param comp Component number of multiple coupled variables
1615 : * @return Pointer to the desired variable
1616 : */
1617 : const MooseVariableFieldBase * getFEVar(const std::string & var_name, unsigned int comp) const;
1618 :
1619 : /*
1620 : * Extract pointer to a base coupled field variable. Could be either a finite volume or finite
1621 : * element variable
1622 : * @param var_name Name of parameter desired
1623 : * @param comp Component number of multiple coupled variables
1624 : * @return Pointer to the desired variable
1625 : */
1626 : const MooseVariableFieldBase * getFieldVar(const std::string & var_name, unsigned int comp) const;
1627 :
1628 : /*
1629 : * Extract pointer to a base coupled field variable. Could be either a finite volume or finite
1630 : * element variable
1631 : * @param var_name Name of variable desired
1632 : * @param comp Component number of multiple coupled variables
1633 : * @return Pointer to the desired variable
1634 : */
1635 : MooseVariableFieldBase * getFieldVar(const std::string & var_name, unsigned int comp);
1636 :
1637 : /**
1638 : * Helper that that be used to retrieve a variable of arbitrary type \p T
1639 : */
1640 : template <typename T>
1641 : const T * getVarHelper(const std::string & var_name, unsigned int comp) const;
1642 :
1643 : /**
1644 : * Helper that can be used to retrieve a variable of arbitrary type \p T
1645 : */
1646 : template <typename T>
1647 : T * getVarHelper(const std::string & var_name, unsigned int comp);
1648 :
1649 : /**
1650 : * Extract pointer to a coupled variable
1651 : * @param var_name Name of parameter desired
1652 : * @param comp Component number of multiple coupled variables
1653 : * @return Pointer to the desired variable
1654 : */
1655 : MooseVariable * getVar(const std::string & var_name, unsigned int comp);
1656 :
1657 : /**
1658 : * Extract pointer to a coupled vector variable
1659 : * @param var_name Name of parameter desired
1660 : * @param comp Component number of multiple coupled variables
1661 : * @return Pointer to the desired variable
1662 : */
1663 : VectorMooseVariable * getVectorVar(const std::string & var_name, unsigned int comp);
1664 :
1665 : /**
1666 : * Extract pointer to a coupled array variable
1667 : * @param var_name Name of parameter desired
1668 : * @param comp Component number of multiple coupled variables
1669 : * @return Pointer to the desired variable
1670 : */
1671 : ArrayMooseVariable * getArrayVar(const std::string & var_name, unsigned int comp);
1672 :
1673 : /**
1674 : * Extract pointer to a coupled variable
1675 : * @param var_name Name of parameter desired
1676 : * @param comp Component number of multiple coupled variables
1677 : * @return Pointer to the desired variable
1678 : */
1679 : const MooseVariable * getVar(const std::string & var_name, unsigned int comp) const;
1680 :
1681 : /**
1682 : * Extract pointer to a coupled vector variable
1683 : * @param var_name Name of parameter desired
1684 : * @param comp Component number of multiple coupled variables
1685 : * @return Pointer to the desired variable
1686 : */
1687 : const VectorMooseVariable * getVectorVar(const std::string & var_name, unsigned int comp) const;
1688 :
1689 : /**
1690 : * Extract pointer to a coupled array variable
1691 : * @param var_name Name of parameter desired
1692 : * @param comp Component number of multiple coupled variables
1693 : * @return Pointer to the desired variable
1694 : */
1695 : const ArrayMooseVariable * getArrayVar(const std::string & var_name, unsigned int comp) const;
1696 :
1697 : /**
1698 : * Checks to make sure that the current Executioner has set "_is_transient" when old/older values
1699 : * are coupled in.
1700 : * @param name the name of the variable
1701 : * @param fn_name The name of the function that called this method - used in the error message
1702 : */
1703 : void validateExecutionerType(const std::string & name, const std::string & fn_name) const;
1704 :
1705 : template <typename T, typename Func>
1706 3276 : std::vector<T> coupledVectorHelper(const std::string & var_name, const Func & func) const
1707 : {
1708 3276 : const auto components = coupledComponents(var_name);
1709 3276 : std::vector<T> vals(components);
1710 28859 : for (MooseIndex(components) comp = 0; comp < components; ++comp)
1711 25583 : vals[comp] = func(comp);
1712 3276 : return vals;
1713 0 : }
1714 :
1715 : /// Whether or not this object is a "neighbor" object: ie all of it's coupled values should be neighbor values
1716 : bool _coupleable_neighbor;
1717 :
1718 : public:
1719 : /**
1720 : * Helper method to return (and insert if necessary) the default value for Automatic
1721 : * Differentiation for an uncoupled variable.
1722 : * @param var_name the name of the variable for which to retrieve a default value
1723 : * @return VariableValue * a pointer to the associated VariableValue.
1724 : */
1725 : const ADVariableValue * getADDefaultValue(const std::string & var_name) const;
1726 :
1727 : /**
1728 : * Helper method to return (and insert if necessary) the default vector value for Automatic
1729 : * Differentiation for an uncoupled variable.
1730 : * @param var_name the name of the vector variable for which to retrieve a default value
1731 : * @return VectorVariableValue * a pointer to the associated VectorVariableValue.
1732 : */
1733 : const ADVectorVariableValue * getADDefaultVectorValue(const std::string & var_name) const;
1734 :
1735 : /**
1736 : * Helper method to return (and insert if necessary) the default gradient for Automatic
1737 : * Differentiation for an uncoupled variable.
1738 : * @param var_name the name of the variable for which to retrieve a default gradient
1739 : * @return Reference to a ADVariableGradient containing zero entries for the default values
1740 : */
1741 : const ADVariableGradient & getADDefaultGradient() const;
1742 :
1743 : /**
1744 : * Helper method to return (and insert if necessary) the default gradient for Automatic
1745 : * Differentiation for an uncoupled vector variable.
1746 : * @param var_name the name of the vector variable for which to retrieve a default gradient
1747 : * @return Reference to a ADVectorVariableGradient containing zero entries for the default values
1748 : */
1749 : const ADVectorVariableGradient & getADDefaultVectorGradient() const;
1750 :
1751 : /**
1752 : * Helper method to return (and insert if necessary) the default second derivatives for Automatic
1753 : * Differentiation for an uncoupled variable.
1754 : * @param var_name the name of the variable for which to retrieve a default second derivative
1755 : * @return Reference to a ADVariableSecond containing zero entries for the default values
1756 : */
1757 : const ADVariableSecond & getADDefaultSecond() const;
1758 :
1759 : /**
1760 : * Helper method to return (and insert if necessary) the default curl value for Automatic
1761 : * Differentiation for an uncoupled variable.
1762 : * @param var_name the name of the vector variable for which to retrieve a default value
1763 : * @return Reference to a ADVectorVariableCurl containing zero entries for the default values
1764 : */
1765 : const ADVectorVariableCurl & getADDefaultCurl() const;
1766 :
1767 : private:
1768 : /**
1769 : * Helper method to return (and insert if necessary) the default value
1770 : * for an uncoupled variable.
1771 : * @param var_name the name of the variable for which to retrieve a default value
1772 : * @return a pointer to the associated VariableValue.
1773 : */
1774 : const VariableValue * getDefaultValue(const std::string & var_name, unsigned int comp) const;
1775 :
1776 : /**
1777 : * Helper method to return (and insert if necessary) the default value
1778 : * for an uncoupled vector variable.
1779 : * @param var_name the name of the vector variable for which to retrieve a default value
1780 : * @return a pointer to the associated VectorVariableValue.
1781 : */
1782 : const VectorVariableValue * getDefaultVectorValue(const std::string & var_name) const;
1783 :
1784 : /**
1785 : * Helper method to return (and insert if necessary) the default value
1786 : * for an uncoupled array variable.
1787 : * @param var_name the name of the vector variable for which to retrieve a default value
1788 : * @return a pointer to the associated VectorVariableValue.
1789 : */
1790 : const ArrayVariableValue * getDefaultArrayValue(const std::string & var_name) const;
1791 :
1792 : /**
1793 : * Get nodal default value
1794 : */
1795 : template <typename T>
1796 : const T & getDefaultNodalValue(const std::string & var_name, unsigned int comp = 0) const;
1797 :
1798 : template <typename T>
1799 : const Moose::Functor<T> & getDefaultFunctor(const std::string & var_name) const;
1800 :
1801 : /// Maximum qps for any element in this system
1802 : unsigned int _coupleable_max_qps;
1803 :
1804 : /// Unique indices for optionally coupled vars that weren't provided
1805 : std::unordered_map<std::string, std::vector<unsigned int>> _optional_var_index;
1806 :
1807 : /// Scalar variables coupled into this object (for error checking)
1808 : std::unordered_map<std::string, std::vector<MooseVariableScalar *>> _c_coupled_scalar_vars;
1809 :
1810 : std::set<TagID> _fe_coupleable_vector_tags;
1811 :
1812 : std::set<TagID> _fe_coupleable_matrix_tags;
1813 :
1814 : /// Whether the MooseObject is a finite volume object
1815 : const bool _is_fv;
1816 :
1817 : const MooseObject * const _obj;
1818 :
1819 : /// vector tag names for which we need to request older solution states from the system
1820 : const std::set<std::string> _older_state_tags = {Moose::OLD_SOLUTION_TAG,
1821 : Moose::OLDER_SOLUTION_TAG};
1822 :
1823 : /// keep a set of allocated writable variable references to make sure only one object can obtain them per thread
1824 : std::vector<std::set<MooseWritableVariable *>> _writable_coupled_variables;
1825 :
1826 : /**
1827 : * kokkos-related variables and methods
1828 : */
1829 : private:
1830 : const Real _kokkos_default_value_zero = 0;
1831 :
1832 : #ifdef MOOSE_KOKKOS_SCOPE
1833 : Moose::Kokkos::Variable kokkosCoupledVectorTagVariable(const std::string & var_name,
1834 : const std::string & tag_name,
1835 : unsigned int comp) const;
1836 : Moose::Kokkos::Variable kokkosCoupledVectorTagVariables(const std::string & var_name,
1837 : const std::string & tag_name) const;
1838 : Moose::Kokkos::Variable kokkosZeroVariable() const;
1839 :
1840 : public:
1841 : Moose::Kokkos::VariableValue kokkosCoupledVectorTagValueByName(const std::string & var_name,
1842 : const std::string & tag_name,
1843 : unsigned int comp = 0) const;
1844 : Moose::Kokkos::VariableValue
1845 : kokkosCoupledVectorTagValuesByName(const std::string & var_name,
1846 : const std::string & tag_name) const;
1847 : Moose::Kokkos::VariableGradient kokkosCoupledVectorTagGradientByName(const std::string & var_name,
1848 : const std::string & tag_name,
1849 : unsigned int comp = 0) const;
1850 : Moose::Kokkos::VariableGradient
1851 : kokkosCoupledVectorTagGradientsByName(const std::string & var_name,
1852 : const std::string & tag_name) const;
1853 : Moose::Kokkos::VariableValue kokkosCoupledVectorTagNodalValueByName(const std::string & var_name,
1854 : const std::string & tag_name,
1855 : unsigned int comp = 0) const;
1856 : Moose::Kokkos::VariableValue
1857 : kokkosCoupledVectorTagNodalValuesByName(const std::string & var_name,
1858 : const std::string & tag_name) const;
1859 : Moose::Kokkos::VariableValue kokkosCoupledVectorTagDofValueByName(const std::string & var_name,
1860 : const std::string & tag_name,
1861 : unsigned int comp = 0) const;
1862 : Moose::Kokkos::VariableValue
1863 : kokkosCoupledVectorTagDofValuesByName(const std::string & var_name,
1864 : const std::string & tag_name) const;
1865 :
1866 : Moose::Kokkos::VariableValue kokkosCoupledVectorTagValue(const std::string & var_name,
1867 : const std::string & tag_param_name,
1868 : unsigned int comp = 0) const;
1869 : Moose::Kokkos::VariableValue
1870 : kokkosCoupledVectorTagValues(const std::string & var_name,
1871 : const std::string & tag_param_name) const;
1872 : Moose::Kokkos::VariableGradient kokkosCoupledVectorTagGradient(const std::string & var_name,
1873 : const std::string & tag_param_name,
1874 : unsigned int comp = 0) const;
1875 : Moose::Kokkos::VariableGradient
1876 : kokkosCoupledVectorTagGradients(const std::string & var_name,
1877 : const std::string & tag_param_name) const;
1878 : Moose::Kokkos::VariableValue kokkosCoupledVectorTagNodalValue(const std::string & var_name,
1879 : const std::string & tag_param_name,
1880 : unsigned int comp = 0) const;
1881 : Moose::Kokkos::VariableValue
1882 : kokkosCoupledVectorTagNodalValues(const std::string & var_name,
1883 : const std::string & tag_param_name) const;
1884 : Moose::Kokkos::VariableValue kokkosCoupledVectorTagDofValue(const std::string & var_name,
1885 : const std::string & tag_param_name,
1886 : unsigned int comp = 0) const;
1887 : Moose::Kokkos::VariableValue
1888 : kokkosCoupledVectorTagDofValues(const std::string & var_name,
1889 : const std::string & tag_param_name) const;
1890 :
1891 : Moose::Kokkos::VariableValue kokkosCoupledValue(const std::string & var_name,
1892 : unsigned int comp = 0) const;
1893 : Moose::Kokkos::VariableValue kokkosCoupledValues(const std::string & var_name) const;
1894 : Moose::Kokkos::VariableGradient kokkosCoupledGradient(const std::string & var_name,
1895 : unsigned int comp = 0) const;
1896 : Moose::Kokkos::VariableGradient kokkosCoupledGradients(const std::string & var_name) const;
1897 : Moose::Kokkos::VariableValue kokkosCoupledNodalValue(const std::string & var_name,
1898 : unsigned int comp = 0) const;
1899 : Moose::Kokkos::VariableValue kokkosCoupledNodalValues(const std::string & var_name) const;
1900 : Moose::Kokkos::VariableValue kokkosCoupledDofValue(const std::string & var_name,
1901 : unsigned int comp = 0) const;
1902 : Moose::Kokkos::VariableValue kokkosCoupledDofValues(const std::string & var_name) const;
1903 :
1904 : Moose::Kokkos::VariableValue kokkosCoupledValueOld(const std::string & var_name,
1905 : unsigned int comp = 0) const;
1906 : Moose::Kokkos::VariableValue kokkosCoupledValuesOld(const std::string & var_name) const;
1907 : Moose::Kokkos::VariableGradient kokkosCoupledGradientOld(const std::string & var_name,
1908 : unsigned int comp = 0) const;
1909 : Moose::Kokkos::VariableGradient kokkosCoupledGradientsOld(const std::string & var_name) const;
1910 : Moose::Kokkos::VariableValue kokkosCoupledNodalValueOld(const std::string & var_name,
1911 : unsigned int comp = 0) const;
1912 : Moose::Kokkos::VariableValue kokkosCoupledNodalValuesOld(const std::string & var_name) const;
1913 : Moose::Kokkos::VariableValue kokkosCoupledDofValueOld(const std::string & var_name,
1914 : unsigned int comp = 0) const;
1915 : Moose::Kokkos::VariableValue kokkosCoupledDofValuesOld(const std::string & var_name) const;
1916 :
1917 : Moose::Kokkos::VariableValue kokkosCoupledValueOlder(const std::string & var_name,
1918 : unsigned int comp = 0) const;
1919 : Moose::Kokkos::VariableValue kokkosCoupledValuesOlder(const std::string & var_name) const;
1920 : Moose::Kokkos::VariableGradient kokkosCoupledGradientOlder(const std::string & var_name,
1921 : unsigned int comp = 0) const;
1922 : Moose::Kokkos::VariableGradient kokkosCoupledGradientsOlder(const std::string & var_name) const;
1923 : Moose::Kokkos::VariableValue kokkosCoupledNodalValueOlder(const std::string & var_name,
1924 : unsigned int comp = 0) const;
1925 : Moose::Kokkos::VariableValue kokkosCoupledNodalValuesOlder(const std::string & var_name) const;
1926 : Moose::Kokkos::VariableValue kokkosCoupledDofValueOlder(const std::string & var_name,
1927 : unsigned int comp = 0) const;
1928 : Moose::Kokkos::VariableValue kokkosCoupledDofValuesOlder(const std::string & var_name) const;
1929 :
1930 : Moose::Kokkos::VariableValue kokkosCoupledDot(const std::string & var_name,
1931 : unsigned int comp = 0) const;
1932 : Moose::Kokkos::VariableValue kokkosCoupledDots(const std::string & var_name) const;
1933 : Moose::Kokkos::VariableValue kokkosCoupledNodalDot(const std::string & var_name,
1934 : unsigned int comp = 0) const;
1935 : Moose::Kokkos::VariableValue kokkosCoupledNodalDots(const std::string & var_name) const;
1936 :
1937 : Moose::Kokkos::Scalar<const Real> kokkosCoupledDotDu(const std::string & var_name,
1938 : unsigned int comp = 0) const;
1939 :
1940 : Moose::Kokkos::VariableValue kokkosZeroValue() const;
1941 : Moose::Kokkos::VariableGradient kokkosZeroGradient() const;
1942 : Moose::Kokkos::VariableValue kokkosZeroNodalValue() const;
1943 : #endif
1944 : };
1945 :
1946 : template <typename T>
1947 : T *
1948 166748 : Coupleable::getVarHelper(const std::string & var_name_in, unsigned int comp)
1949 : {
1950 166748 : const auto var_name = _c_parameters.checkForRename(var_name_in);
1951 166748 : auto name_to_use = var_name;
1952 :
1953 : // First check for supplied name
1954 166748 : if (!checkVar(var_name, comp, 0))
1955 : {
1956 : // See if there is an associated deprecated name that the user may have used instead
1957 2302 : auto it = _new_to_deprecated_coupled_vars.find(var_name);
1958 2302 : if (it == _new_to_deprecated_coupled_vars.end())
1959 2302 : return nullptr;
1960 : else
1961 : {
1962 0 : auto deprecated_name = it->second;
1963 0 : if (checkVar(deprecated_name, comp, 0))
1964 0 : name_to_use = deprecated_name;
1965 : else
1966 0 : return nullptr;
1967 0 : }
1968 : }
1969 :
1970 164430 : auto coupled_vars_it = _coupled_vars.find(name_to_use);
1971 :
1972 : mooseAssert(coupled_vars_it != _coupled_vars.end(),
1973 : "Trying to get a coupled var " << name_to_use << " that doesn't exist");
1974 :
1975 164430 : if (auto coupled_var = dynamic_cast<T *>(coupled_vars_it->second[comp]))
1976 164430 : return coupled_var;
1977 : else
1978 : {
1979 0 : for (auto & var : _coupled_standard_moose_vars)
1980 0 : if (var->name() == name_to_use)
1981 0 : mooseError("The named variable is a standard variable, try a "
1982 : "'coupled[Value/Gradient/Dot/etc]...' function instead");
1983 0 : for (auto & var : _coupled_vector_moose_vars)
1984 0 : if (var->name() == name_to_use)
1985 0 : mooseError("The named variable is a vector variable, try a "
1986 : "'coupledVector[Value/Gradient/Dot/etc]...' function instead");
1987 0 : for (auto & var : _coupled_array_moose_vars)
1988 0 : if (var->name() == name_to_use)
1989 0 : mooseError("The named variable is an array variable, try a "
1990 : "'coupledArray[Value/Gradient/Dot/etc]...' function instead");
1991 0 : for (auto & var : _coupled_fv_moose_vars)
1992 0 : if (var->name() == name_to_use)
1993 0 : mooseError("The named variable is a finite volume variable, which the coupled[...] routine "
1994 : "used does not support. Try using the functor system routines instead.");
1995 0 : mooseError(
1996 : "Variable '", name_to_use, "' is of a different C++ type than you tried to fetch it as.");
1997 : }
1998 166732 : }
1999 :
2000 : template <typename T>
2001 : const T *
2002 153524 : Coupleable::getVarHelper(const std::string & var_name, unsigned int comp) const
2003 : {
2004 153524 : return const_cast<Coupleable *>(this)->getVarHelper<T>(var_name, comp);
2005 : }
|