/
Coupleable.h
1274 lines (1107 loc) · 48.8 KB
/
Coupleable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#ifndef COUPLEABLE_H
#define COUPLEABLE_H
#include <map>
#include "MooseTypes.h"
#include "MooseArray.h"
#include "MooseVariableFE.h"
#include "InputParameters.h"
#define usingCoupleableMembers \
using Coupleable::_zero; \
using Coupleable::_grad_zero; \
using Coupleable::isCoupled; \
using Coupleable::coupledComponents; \
using Coupleable::coupled; \
using Coupleable::coupledValue; \
using Coupleable::coupledValueOld; \
using Coupleable::coupledValueOlder; \
using Coupleable::coupledGradient; \
using Coupleable::coupledGradientOld; \
using Coupleable::coupledGradientOlder; \
using Coupleable::getVar
// Forward declarations
class MooseVariableScalar;
class MooseObject;
namespace libMesh
{
template <typename T>
class DenseVector;
}
#define adCoupledValue this->template adCoupledValueTemplate<compute_stage>
#define adCoupledGradient this->template adCoupledGradientTemplate<compute_stage>
#define adCoupledSecond this->template adCoupledSecondTemplate<compute_stage>
#define adCoupledDot this->template adCoupledDotTemplate<compute_stage>
#define adCoupledVectorDot this->template adCoupledVectorDotTemplate<compute_stage>
#define adCoupledVectorValue this->template adCoupledVectorValueTemplate<compute_stage>
#define adCoupledVectorGradient this->template adCoupledVectorGradientTemplate<compute_stage>
#define adCoupledVectorSecond this->template adCoupledVectorSecondTemplate<compute_stage>
#define adZeroValue this->template adZeroValueTemplate<compute_stage>
#define adZeroGradient this->template adZeroGradientTemplate<compute_stage>
#define adZeroSecond this->template adZeroSecondTemplate<compute_stage>
#define adCoupledNodalValue this->template adCoupledNodalValueTemplate<Real, compute_stage>
#define adCoupledNodalVectorValue \
this->template adCoupledNodalValueTemplate<RealVectorValue, compute_stage>
/**
* Interface for objects that needs coupling capabilities
*
*/
class Coupleable
{
public:
/**
* Constructing the object
* @param parameters Parameters that come from constructing the object
* @param nodal true if we need to couple with nodal values, otherwise false
*/
Coupleable(const MooseObject * moose_object, bool nodal);
/**
* Destructor for object
*/
virtual ~Coupleable();
/**
* Get the list of coupled variables
* @return The list of coupled variables
*/
const std::map<std::string, std::vector<MooseVariableFEBase *>> & getCoupledVars()
{
return _coupled_vars;
}
/**
* Get the list of all coupled variables
* @return The list of all coupled variables
*/
const std::vector<MooseVariableFEBase *> & getCoupledMooseVars() const
{
return _coupled_moose_vars;
}
/**
* Get the list of standard coupled variables
* @return The list of standard coupled variables
*/
const std::vector<MooseVariable *> & getCoupledStandardMooseVars() const
{
return _coupled_standard_moose_vars;
}
/**
* Get the list of vector coupled variables
* @return The list of vector coupled variables
*/
const std::vector<VectorMooseVariable *> & getCoupledVectorMooseVars() const
{
return _coupled_vector_moose_vars;
}
void addFEVariableCoupleableVectorTag(TagID tag) { _fe_coupleable_vector_tags.insert(tag); }
void addFEVariableCoupleableMatrixTag(TagID tag) { _fe_coupleable_matrix_tags.insert(tag); }
std::set<TagID> & getFEVariableCoupleableVectorTags() { return _fe_coupleable_vector_tags; }
std::set<TagID> & getFEVariableCoupleableMatrixTags() { return _fe_coupleable_matrix_tags; }
protected:
/**
* Returns true if a variables has been coupled as name.
* @param var_name The name the kernel wants to refer to the variable as.
* @param i By default 0, in general the index to test in a vector of MooseVariable pointers.
* @return True if a coupled variable has the supplied name
*/
virtual bool isCoupled(const std::string & var_name, unsigned int i = 0);
/**
* Number of coupled components
* @param var_name Name of the variable
* @return number of components this variable has (usually 1)
*/
unsigned int coupledComponents(const std::string & var_name);
virtual void coupledCallback(const std::string & var_name, bool is_old);
/**
* Returns the index for a coupled variable by name
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Index of coupled variable, if this is an optionally coupled variable that wasn't
* provided this will return a unique "invalid" index.
*/
virtual unsigned int coupled(const std::string & var_name, unsigned int comp = 0);
/**
* Returns value of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
* @see Kernel::_u
*/
virtual const VariableValue & coupledValue(const std::string & var_name, unsigned int comp = 0);
/**
* Returns value of a coupled variable for use in Automatic Differentiation
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
* @see Kernel::value
*/
template <ComputeStage compute_stage>
const ADVariableValue & adCoupledValueTemplate(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns value of a coupled vector variable for use in Automatic Differentiation
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
* @see Kernel::value
*/
template <ComputeStage compute_stage>
const ADVectorVariableValue & adCoupledVectorValueTemplate(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns value of a coupled variable for a given tag
* @param var_name Name of coupled variable
* @param tag vector tag ID
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
* @see Kernel::_u
*/
virtual const VariableValue &
coupledVectorTagValue(const std::string & var_name, TagID tag, unsigned int comp = 0);
/**
* Returns value of a coupled variable for a given tag. This couples the diag vector of matrix
* @param var_name Name of coupled variable
* @param tag matrix tag ID
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
* @see Kernel::_u
*/
virtual const VariableValue &
coupledMatrixTagValue(const std::string & var_name, TagID tag, unsigned int comp = 0);
/**
* Returns value of a coupled vector variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableValue for the coupled vector variable
* @see VectorKernel::_u
*/
virtual const VectorVariableValue & coupledVectorValue(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns a *writable* reference to a coupled variable. Note: you
* should not have to use this very often (use coupledValue()
* instead) but there are situations, such as writing to multiple
* AuxVariables from a single AuxKernel, where it is required.
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
* @see Kernel::value
*/
virtual VariableValue & writableCoupledValue(const std::string & var_name, unsigned int comp = 0);
/**
* Returns an old value from previous time step of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the old value of the coupled variable
* @see Kernel::valueOld
*/
virtual const VariableValue & coupledValueOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old value from two time steps previous of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the older value of the coupled variable
* @see Kernel::valueOlder
*/
virtual const VariableValue & coupledValueOlder(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns value of previous Newton iterate of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the older value of the coupled variable
*/
virtual const VariableValue & coupledValuePreviousNL(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old value from previous time step of a coupled vector variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VectorVariableValue containing the old value of the coupled variable
* @see Kernel::_u_old
*/
virtual const VectorVariableValue & coupledVectorValueOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old value from two time steps previous of a coupled vector variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VectorVariableValue containing the older value of the coupled variable
* @see Kernel::_u_older
*/
virtual const VectorVariableValue & coupledVectorValueOlder(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns gradient of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableGradient containing the gradient of the coupled variable
* @see Kernel::gradient
*/
virtual const VariableGradient & coupledGradient(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns gradient of a coupled variable for use in Automatic Differentation
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableGradient containing the gradient of the coupled variable
* @see Kernel::gradient
*/
template <ComputeStage compute_stage>
const ADVariableGradient & adCoupledGradientTemplate(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns gradient of a coupled vector variable for use in Automatic Differentation
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableGradient containing the gradient of the coupled variable
* @see Kernel::gradient
*/
template <ComputeStage compute_stage>
const ADVectorVariableGradient & adCoupledVectorGradientTemplate(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns second derivatives of a coupled variable for use in Automatic Differentation
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableSecond containing the second derivatives of the coupled variable
*/
template <ComputeStage compute_stage>
const ADVariableSecond & adCoupledSecondTemplate(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns second derivatives of a coupled vector variable for use in Automatic Differentation
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableSecond containing the second derivatives of the coupled
* variable
*/
template <ComputeStage compute_stage>
const ADVectorVariableSecond & adCoupledVectorSecondTemplate(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old gradient from previous time step of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableGradient containing the old gradient of the coupled variable
* @see Kernel::gradientOld
*/
virtual const VariableGradient & coupledGradientOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old gradient from two time steps previous of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableGradient containing the older gradient of the coupled variable
* @see Kernel::gradientOlder
*/
virtual const VariableGradient & coupledGradientOlder(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns gradient of a coupled variable for previous Newton iterate
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableGradient containing the gradient of the coupled variable
*/
virtual const VariableGradient & coupledGradientPreviousNL(const std::string & var_name,
unsigned int comp = 0);
/**
* Time derivative of the gradient of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableGradient containing the time derivative of the gradient of a
* coupled variable
*/
virtual const VariableGradient & coupledGradientDot(const std::string & var_name,
unsigned int comp = 0);
/**
* Second time derivative of the gradient of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableGradient containing the time derivative of the gradient of a
* coupled variable
*/
virtual const VariableGradient & coupledGradientDotDot(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns gradient of a coupled vector variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableGradient containing the gradient of the coupled vector
* variable
*/
virtual const VectorVariableGradient & coupledVectorGradient(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old gradient from previous time step of a coupled vector variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableGradient containing the old gradient of the coupled vector
* variable
*/
virtual const VectorVariableGradient & coupledVectorGradientOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old gradient from two time steps previous of a coupled vector variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableGradient containing the older gradient of the coupled
* vector variable
*/
virtual const VectorVariableGradient & coupledVectorGradientOlder(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns curl of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VectorVariableCurl containing the curl of the coupled variable
* @see Kernel::_curl_u
*/
virtual const VectorVariableCurl & coupledCurl(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old curl from previous time step of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VectorVariableCurl containing the old curl of the coupled variable
* @see Kernel::_curl_u_old
*/
virtual const VectorVariableCurl & coupledCurlOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old curl from two time steps previous of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VectorVariableCurl containing the older curl of the coupled variable
* @see Kernel::_curl_u_older
*/
virtual const VectorVariableCurl & coupledCurlOlder(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns second derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableSecond containing the second derivative of the coupled variable
* @see Kernel::second
*/
virtual const VariableSecond & coupledSecond(const std::string & var_name, unsigned int comp = 0);
/**
* Returns an old second derivative from previous time step of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableSecond containing the old second derivative of the coupled
* variable
* @see Kernel::secondOld
*/
virtual const VariableSecond & coupledSecondOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns an old second derivative from two time steps previous of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableSecond containing the older second derivative of the coupled
* variable
* @see Kernel::secondOlder
*/
virtual const VariableSecond & coupledSecondOlder(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns second derivative of a coupled variable for the previous Newton iterate
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableSecond containing the second derivative of the coupled variable
*/
virtual const VariableSecond & coupledSecondPreviousNL(const std::string & var_name,
unsigned int comp = 0);
/**
* Time derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the time derivative of the coupled variable
*/
virtual const VariableValue & coupledDot(const std::string & var_name, unsigned int comp = 0);
/**
* Second time derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the time derivative of the coupled variable
*/
virtual const VariableValue & coupledDotDot(const std::string & var_name, unsigned int comp = 0);
/**
* Old time derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the time derivative of the coupled variable
*/
virtual const VariableValue & coupledDotOld(const std::string & var_name, unsigned int comp = 0);
/**
* Old second time derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the time derivative of the coupled variable
*/
virtual const VariableValue & coupledDotDotOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Time derivative of a coupled variable for ad simulations
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the time derivative of the coupled variable
* @see Kernel::dot
*/
template <ComputeStage compute_stage>
const ADVariableValue & adCoupledDotTemplate(const std::string & var_name, unsigned int comp = 0);
/**
* Time derivative of a vector coupled variable for ad simulations
* @param var_name Name of vector coupled variable
* @param comp Component number
* @return Reference to a VectorVariableValue containing the time derivative of the coupled
* variable
* @see Kernel::dot
*/
template <ComputeStage compute_stage>
const ADVectorVariableValue & adCoupledVectorDotTemplate(const std::string & var_name,
unsigned int comp = 0);
/**
* Time derivative of a coupled vector variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableValue containing the time derivative of the coupled
* variable
*/
virtual const VectorVariableValue & coupledVectorDot(const std::string & var_name,
unsigned int comp = 0);
/**
* Second time derivative of a coupled vector variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableValue containing the time derivative of the coupled
* variable
*/
virtual const VectorVariableValue & coupledVectorDotDot(const std::string & var_name,
unsigned int comp = 0);
/**
* Old time derivative of a coupled vector variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableValue containing the time derivative of the coupled
* variable
*/
virtual const VectorVariableValue & coupledVectorDotOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Old second time derivative of a coupled vector variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a VectorVariableValue containing the time derivative of the coupled
* variable
*/
virtual const VectorVariableValue & coupledVectorDotDotOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Time derivative of a coupled variable with respect to the coefficients
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the time derivative of the coupled variable
* with respect to the coefficients
*/
virtual const VariableValue & coupledDotDu(const std::string & var_name, unsigned int comp = 0);
/**
* Second time derivative of a coupled variable with respect to the coefficients
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the time derivative of the coupled variable
* with respect to the coefficients
*/
virtual const VariableValue & coupledDotDotDu(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns nodal values of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
*/
template <typename T>
const T & coupledNodalValue(const std::string & var_name, unsigned int comp = 0);
/**
* Returns AD nodal values of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
*/
template <typename T, ComputeStage compute_stage>
const typename Moose::ValueType<T, compute_stage>::type &
adCoupledNodalValueTemplate(const std::string & var_name, unsigned int comp = 0);
/**
* Returns an old nodal value from previous time step of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the old value of the coupled variable
*/
template <typename T>
const T & coupledNodalValueOld(const std::string & var_name, unsigned int comp = 0);
/**
* Returns an old nodal value from two time steps previous of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the older value of the coupled variable
*/
template <typename T>
const T & coupledNodalValueOlder(const std::string & var_name, unsigned int comp = 0);
/**
* Returns nodal values of a coupled variable for previous Newton iterate
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the coupled variable
*/
template <typename T>
const T & coupledNodalValuePreviousNL(const std::string & var_name, unsigned int comp = 0);
/**
* Nodal values of time derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the nodal values of time derivative of the
* coupled variable
*/
template <typename T>
const T & coupledNodalDot(const std::string & var_name, unsigned int comp = 0);
/**
* Get nodal default value
*/
template <typename T>
const T & getNodalDefaultValue(const std::string & var_name, unsigned int comp = 0);
/**
* Nodal values of second time derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the nodal values of second time derivative of
* the coupled variable
*/
virtual const VariableValue & coupledNodalDotDot(const std::string & var_name,
unsigned int comp = 0);
/**
* Nodal values of old time derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the nodal values of time derivative of the
* coupled variable
*/
virtual const VariableValue & coupledNodalDotOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Nodal values of old second time derivative of a coupled variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue containing the nodal values of second time derivative of
* the coupled variable
*/
virtual const VariableValue & coupledNodalDotDotOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns DoFs in the current solution vector of a coupled variable for the local element
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the DoFs of the coupled variable
*/
virtual const VariableValue & coupledDofValues(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns DoFs in the old solution vector of a coupled variable for the local element
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the old DoFs of the coupled variable
*/
virtual const VariableValue & coupledDofValuesOld(const std::string & var_name,
unsigned int comp = 0);
/**
* Returns DoFs in the older solution vector of a coupled variable for the local element
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VariableValue for the older DoFs of the coupled variable
*/
virtual const VariableValue & coupledDofValuesOlder(const std::string & var_name,
unsigned int comp = 0);
/**
* Template method that returns _zero to RESIDUAL computing objects and _ad_zero to JACOBIAN
* computing objects
*/
template <ComputeStage compute_stage>
const ADVariableValue & adZeroValueTemplate();
/**
* Template method that returns _grad_zero to RESIDUAL computing objects and _ad_grad_zero to
* JACOBIAN computing objects
*/
template <ComputeStage compute_stage>
const ADVariableGradient & adZeroGradientTemplate();
/**
* Retrieve a zero second for automatic differentiation
*/
template <ComputeStage compute_stage>
const ADVariableSecond & adZeroSecondTemplate();
protected:
// Reference to the interface's input parameters
const InputParameters & _c_parameters;
/// The name of the object this interface is part of
const std::string & _c_name;
// Reference to FEProblemBase
FEProblemBase & _c_fe_problem;
/// Coupled vars whose values we provide
std::map<std::string, std::vector<MooseVariableFEBase *>> _coupled_vars;
/// Vector of all coupled variables
std::vector<MooseVariableFEBase *> _coupled_moose_vars;
/// Vector of standard coupled variables
std::vector<MooseVariable *> _coupled_standard_moose_vars;
/// Vector of vector coupled variables
std::vector<VectorMooseVariable *> _coupled_vector_moose_vars;
/// True if we provide coupling to nodal values
bool _c_nodal;
/// True if implicit value is required
bool _c_is_implicit;
/// Thread ID of the thread using this object
THREAD_ID _c_tid;
/// Will hold the default value for optional coupled variables.
std::map<std::string, std::vector<VariableValue *>> _default_value;
/// Will hold the default value for optional coupled variables for automatic differentiation.
std::map<std::string, MooseArray<DualReal> *> _ad_default_value;
/// Will hold the default value for optional vector coupled variables.
std::map<std::string, VectorVariableValue *> _default_vector_value;
/// Will hold the default value for optional vector coupled variables for automatic differentiation.
std::map<std::string, MooseArray<DualRealVectorValue> *> _ad_default_vector_value;
/**
* This will always be zero because the default values for optionally coupled variables is always
* constant and this is used for time derivative info
*/
VariableValue _default_value_zero;
/// This will always be zero because the default values for optionally coupled variables is always constant
VariableGradient _default_gradient;
/// This will always be zero because the default values for optionally coupled variables is always constant
MooseArray<DualRealVectorValue> _ad_default_gradient;
/// This will always be zero because the default values for optionally coupled vector variables is always constant
MooseArray<DualRealTensorValue> _ad_default_vector_gradient;
/// This will always be zero because the default values for optionally coupled variables is always constant
VariableSecond _default_second;
/// This will always be zero because the default values for optionally coupled variables is always constant
MooseArray<DualRealTensorValue> _ad_default_second;
/// Zero value of a variable
const VariableValue & _zero;
const MooseArray<DualReal> & _ad_zero;
/// Zero gradient of a variable
const VariableGradient & _grad_zero;
const MooseArray<DualRealVectorValue> & _ad_grad_zero;
/// Zero second derivative of a variable
const VariableSecond & _second_zero;
const MooseArray<DualRealTensorValue> & _ad_second_zero;
/// Zero second derivative of a test function
const VariablePhiSecond & _second_phi_zero;
/// Zero value of a vector variable
const VectorVariableValue & _vector_zero;
/// Zero value of the curl of a vector variable
const VectorVariableCurl & _vector_curl_zero;
/**
* This will always be zero because the default values for optionally coupled variables is always
* constant and this is used for time derivative info
*/
VectorVariableValue _default_vector_value_zero;
/// This will always be zero because the default values for optionally coupled variables is always constant
VectorVariableGradient _default_vector_gradient;
/// This will always be zero because the default values for optionally coupled variables is always constant
VectorVariableCurl _default_vector_curl;
/**
* Check that the right kind of variable is being coupled in
*
* @param var_name The name of the coupled variable
*/
void checkVar(const std::string & var_name);
/**
* Extract pointer to a base finite element coupled variable
* @param var_name Name of parameter desired
* @param comp Component number of multiple coupled variables
* @return Pointer to the desired variable
*/
MooseVariableFEBase * getFEVar(const std::string & var_name, unsigned int comp);
/**
* Helper that segues off to either getVar of getVectorVar depending on template paramter
*/
template <typename T>
MooseVariableFE<T> * getVarHelper(const std::string & var_name, unsigned int comp);
/**
* Extract pointer to a coupled variable
* @param var_name Name of parameter desired
* @param comp Component number of multiple coupled variables
* @return Pointer to the desired variable
*/
MooseVariable * getVar(const std::string & var_name, unsigned int comp);
/**
* Extract pointer to a coupled vector variable
* @param var_name Name of parameter desired
* @param comp Component number of multiple coupled variables
* @return Pointer to the desired variable
*/
VectorMooseVariable * getVectorVar(const std::string & var_name, unsigned int comp);
/**
* Checks to make sure that the current Executioner has set "_is_transient" when old/older values
* are coupled in.
* @param name the name of the variable
* @param fn_name The name of the function that called this method - used in the error message
*/
void validateExecutionerType(const std::string & name, const std::string & fn_name) const;
/// Whether or not this object is a "neighbor" object: ie all of it's coupled values should be neighbor values
bool _coupleable_neighbor;
private:
/**
* Helper method to return (and insert if necessary) the default value
* for an uncoupled variable.
* @param var_name the name of the variable for which to retrieve a default value
* @return a pointer to the associated VariableValue.
*/
VariableValue * getDefaultValue(const std::string & var_name, unsigned int comp);
public:
/**
* Helper method to return (and insert if necessary) the default value for Automatic
* Differentiation for an uncoupled variable.
* @param var_name the name of the variable for which to retrieve a default value
* @return VariableValue * a pointer to the associated VarirableValue.
*/
template <ComputeStage compute_stage>
ADVariableValue * getADDefaultValue(const std::string & var_name);
/**
* Helper method to return (and insert if necessary) the default vector value for Automatic
* Differentiation for an uncoupled variable.
* @param var_name the name of the vector variable for which to retrieve a default value
* @return VariableVectorValue * a pointer to the associated VarirableVectorValue.
*/
template <ComputeStage compute_stage>
ADVectorVariableValue * getADDefaultVectorValue(const std::string & var_name);
/**
* Helper method to return (and insert if necessary) the default gradient for Automatic
* Differentiation for an uncoupled variable.
* @param var_name the name of the variable for which to retrieve a default gradient
* @return VariableGradient * a pointer to the associated VariableGradient.
*/
template <ComputeStage compute_stage>
ADVariableGradient & getADDefaultGradient();
/**
* Helper method to return (and insert if necessary) the default gradient for Automatic
* Differentiation for an uncoupled vector variable.
* @param var_name the name of the vector variable for which to retrieve a default gradient
* @return VariableGradient * a pointer to the associated VectorVariableGradient.
*/
template <ComputeStage compute_stage>
ADVectorVariableGradient & getADDefaultVectorGradient();
/**
* Helper method to return (and insert if necessary) the default second derivatives for Automatic
* Differentiation for an uncoupled variable.
* @param var_name the name of the variable for which to retrieve a default second derivative
* @return VariableSecond * a pointer to the associated VariableSecond.
*/
template <ComputeStage compute_stage>
ADVariableSecond & getADDefaultSecond();
private:
/**
* Helper method to return (and insert if necessary) the default value
* for an uncoupled vector variable.
* @param var_name the name of the vector variable for which to retrieve a default value
* @return a pointer to the associated VectorVariableValue.
*/
VectorVariableValue * getDefaultVectorValue(const std::string & var_name);
/// Maximum qps for any element in this system
unsigned int _coupleable_max_qps;
/// Unique indices for optionally coupled vars that weren't provided
std::map<std::string, std::vector<unsigned int>> _optional_var_index;
/// Scalar variables coupled into this object (for error checking)
std::map<std::string, std::vector<MooseVariableScalar *>> _c_coupled_scalar_vars;
std::set<TagID> _fe_coupleable_vector_tags;
std::set<TagID> _fe_coupleable_matrix_tags;
};
template <ComputeStage compute_stage>
const ADVariableValue &
Coupleable::adCoupledValueTemplate(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name))
return *getADDefaultValue<compute_stage>(var_name);
coupledCallback(var_name, false);
MooseVariable * var = getVar(var_name, comp);
if (!_coupleable_neighbor)
{
if (_c_nodal)
mooseError("Not implemented");
else
{
if (_c_is_implicit)
return var->adSln<compute_stage>();
else
mooseError("Not implemented");
}
}
else
{
if (_c_nodal)
mooseError("Not implemented");
else
{
if (_c_is_implicit)
return var->adSlnNeighbor<compute_stage>();
else
mooseError("Not implemented");
}
}
}
template <ComputeStage compute_stage>
const ADVariableGradient &
Coupleable::adCoupledGradientTemplate(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return getADDefaultGradient<compute_stage>();
coupledCallback(var_name, false);
if (_c_nodal)
mooseError("Nodal variables do not have gradients");
MooseVariable * var = getVar(var_name, comp);
if (!_coupleable_neighbor)
{
if (_c_is_implicit)
return var->adGradSln<compute_stage>();
else
mooseError("Not implemented");