/
MooseVariableField.h
389 lines (323 loc) · 13.3 KB
/
MooseVariableField.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
//* 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
#pragma once
#include "MooseTypes.h"
#include "MooseVariableFieldBase.h"
#include "SubProblem.h"
#include "MooseMesh.h"
#include "MooseVariableData.h"
#include "MooseFunctor.h"
#include "MeshChangedInterface.h"
#include "libmesh/numeric_vector.h"
#include "libmesh/dof_map.h"
#include "libmesh/elem.h"
#include "libmesh/quadrature.h"
#include "libmesh/dense_vector.h"
#include "libmesh/dense_vector.h"
/**
* Class for stuff related to variables
*
* Each variable can compute nodal or elemental (at QPs) values.
*
* OutputType OutputShape OutputData
* ----------------------------------------------------
* Real Real Real
* RealVectorValue RealVectorValue Real
* RealEigenVector Real RealEigenVector
*
*/
template <typename OutputType>
class MooseVariableField : public MooseVariableFieldBase,
public Moose::FunctorBase<typename Moose::ADType<OutputType>::type>,
public MeshChangedInterface
{
public:
// type for gradient, second and divergence of template class OutputType
typedef typename TensorTools::IncrementRank<OutputType>::type OutputGradient;
typedef typename TensorTools::IncrementRank<OutputGradient>::type OutputSecond;
typedef typename TensorTools::DecrementRank<OutputType>::type OutputDivergence;
// shortcut for types storing values on quadrature points
typedef MooseArray<OutputType> FieldVariableValue;
typedef MooseArray<OutputGradient> FieldVariableGradient;
typedef MooseArray<OutputSecond> FieldVariableSecond;
typedef MooseArray<OutputType> FieldVariableCurl;
typedef MooseArray<OutputDivergence> FieldVariableDivergence;
// shape function type for the template class OutputType
typedef typename Moose::ShapeType<OutputType>::type OutputShape;
// type for gradient, second and divergence of shape functions of template class OutputType
typedef typename TensorTools::IncrementRank<OutputShape>::type OutputShapeGradient;
typedef typename TensorTools::IncrementRank<OutputShapeGradient>::type OutputShapeSecond;
typedef typename TensorTools::DecrementRank<OutputShape>::type OutputShapeDivergence;
// shortcut for types storing shape function values on quadrature points
typedef MooseArray<std::vector<OutputShape>> FieldVariablePhiValue;
typedef MooseArray<std::vector<OutputShapeGradient>> FieldVariablePhiGradient;
typedef MooseArray<std::vector<OutputShapeSecond>> FieldVariablePhiSecond;
typedef MooseArray<std::vector<OutputShape>> FieldVariablePhiCurl;
typedef MooseArray<std::vector<OutputShapeDivergence>> FieldVariablePhiDivergence;
// shortcut for types storing test function values on quadrature points
// Note: here we assume the types are the same as of shape functions.
typedef MooseArray<std::vector<OutputShape>> FieldVariableTestValue;
typedef MooseArray<std::vector<OutputShapeGradient>> FieldVariableTestGradient;
typedef MooseArray<std::vector<OutputShapeSecond>> FieldVariableTestSecond;
typedef MooseArray<std::vector<OutputShape>> FieldVariableTestCurl;
typedef MooseArray<std::vector<OutputShapeDivergence>> FieldVariableTestDivergence;
// DoF value type for the template class OutputType
typedef typename Moose::DOFType<OutputType>::type OutputData;
typedef MooseArray<OutputData> DoFValue;
MooseVariableField(const InputParameters & parameters);
static InputParameters validParams();
virtual void setNodalValue(const OutputType & value, unsigned int idx = 0) = 0;
///@{
/**
* Degree of freedom value setters
*/
virtual void setDofValue(const OutputData & value, unsigned int index) = 0;
///@}
/**
* AD solution getter
*/
virtual const ADTemplateVariableValue<OutputType> & adSln() const = 0;
/**
* AD neighbor solution getter
*/
virtual const ADTemplateVariableValue<OutputType> & adSlnNeighbor() const = 0;
/**
* AD grad solution getter
*/
virtual const ADTemplateVariableGradient<OutputType> & adGradSln() const = 0;
/**
* AD grad of time derivative solution getter
*/
virtual const ADTemplateVariableGradient<OutputType> & adGradSlnDot() const = 0;
/**
* AD grad neighbor solution getter
*/
virtual const ADTemplateVariableGradient<OutputType> & adGradSlnNeighbor() const = 0;
/**
* AD grad of time derivative neighbor solution getter
*/
virtual const ADTemplateVariableGradient<OutputType> & adGradSlnNeighborDot() const = 0;
/**
* AD second solution getter
*/
virtual const ADTemplateVariableSecond<OutputType> & adSecondSln() const = 0;
/**
* AD second neighbor solution getter
*/
virtual const ADTemplateVariableSecond<OutputType> & adSecondSlnNeighbor() const = 0;
/**
* AD time derivative getter
*/
virtual const ADTemplateVariableValue<OutputType> & adUDot() const = 0;
/**
* AD second time derivative getter
*/
virtual const ADTemplateVariableValue<OutputType> & adUDotDot() const = 0;
/**
* AD neighbor time derivative getter
*/
virtual const ADTemplateVariableValue<OutputType> & adUDotNeighbor() const = 0;
/**
* AD neighbor second time derivative getter
*/
virtual const ADTemplateVariableValue<OutputType> & adUDotDotNeighbor() const = 0;
/**
* Return the AD dof values
*/
virtual const MooseArray<ADReal> & adDofValues() const = 0;
/**
* Return the AD neighbor dof values
*/
virtual const MooseArray<ADReal> & adDofValuesNeighbor() const = 0;
///@{
/**
* Methods for retrieving values of variables at the nodes in a MooseArray for AuxKernelBase
*/
virtual const MooseArray<OutputType> & nodalValueArray() const = 0;
virtual const MooseArray<OutputType> & nodalValueOldArray() const = 0;
virtual const MooseArray<OutputType> & nodalValueOlderArray() const = 0;
///@}
/**
* @return the current elemental solution
*/
virtual const FieldVariableValue & sln() const = 0;
/**
* @return the old elemental solution, e.g. that of the previous timestep
*/
virtual const FieldVariableValue & slnOld() const = 0;
/**
* @return the current neighbor solution
*/
virtual const FieldVariableValue & slnNeighbor() const = 0;
/**
* @return the old neighbor solution, e.g. that of the previous timestep
*/
virtual const FieldVariableValue & slnOldNeighbor() const = 0;
/**
* @return the older elemental solution, e.g. that of two timesteps ago
*/
virtual const FieldVariableValue & slnOlder() const = 0;
/// element gradients
virtual const FieldVariableGradient & gradSln() const = 0;
virtual const FieldVariableGradient & gradSlnOld() const = 0;
/// neighbor solution gradients
virtual const FieldVariableGradient & gradSlnNeighbor() const = 0;
virtual const FieldVariableGradient & gradSlnOldNeighbor() const = 0;
/**
* Whether or not this variable is computing any second derivatives.
*/
virtual bool computingSecond() const = 0;
/**
* Whether or not this variable is computing any curl quantities
*/
virtual bool computingCurl() const = 0;
/**
* Whether or not this variable is computing any divergence quantities
*/
virtual bool computingDiv() const = 0;
/**
* Return the variable's elemental shape functions
*/
virtual const FieldVariablePhiValue & phi() const = 0;
/**
* Return the gradients of the variable's elemental shape functions
*/
virtual const FieldVariablePhiGradient & gradPhi() const = 0;
/**
* Return the rank-2 tensor of second derivatives of the variable's elemental shape functions
*/
virtual const FieldVariablePhiSecond & secondPhi() const = 0;
/**
* Curl of the shape functions
*/
virtual const FieldVariablePhiValue & curlPhi() const = 0;
/**
* Divergence of the shape functions
*/
virtual const FieldVariablePhiDivergence & divPhi() const = 0;
/**
* Return the variable's shape functions on an element face
*/
virtual const FieldVariablePhiValue & phiFace() const = 0;
/**
* Return the gradients of the variable's shape functions on an element face
*/
virtual const FieldVariablePhiGradient & gradPhiFace() const = 0;
/**
* Return the rank-2 tensor of second derivatives of the variable's shape functions on an element
* face
*/
virtual const FieldVariablePhiSecond & secondPhiFace() const = 0;
/**
* Return the variable's shape functions on a neighboring element face
*/
virtual const FieldVariablePhiValue & phiFaceNeighbor() const = 0;
/**
* Return the gradients of the variable's shape functions on a neighboring element face
*/
virtual const FieldVariablePhiGradient & gradPhiFaceNeighbor() const = 0;
/**
* Return the rank-2 tensor of second derivatives of the variable's shape functions on a
* neighboring element face
*/
virtual const FieldVariablePhiSecond & secondPhiFaceNeighbor() const = 0;
/**
* Return the variable's shape functions on a neighboring element
*/
virtual const FieldVariablePhiValue & phiNeighbor() const = 0;
/**
* Return the gradients of the variable's shape functions on a neighboring element
*/
virtual const FieldVariablePhiGradient & gradPhiNeighbor() const = 0;
/**
* Return the rank-2 tensor of second derivatives of the variable's shape functions on a
* neighboring element
*/
virtual const FieldVariablePhiSecond & secondPhiNeighbor() const = 0;
/**
* Return the variable's shape functions on a lower-dimensional element
*/
virtual const FieldVariablePhiValue & phiLower() const = 0;
/**
* Set local DOF values and evaluate the values on quadrature points
*/
virtual void setDofValues(const DenseVector<OutputData> & values) = 0;
/**
* Whether or not this variable is actually using the shape function value.
*
* Currently hardcoded to true because we always compute the value.
*/
bool usesPhiNeighbor() const { return true; }
/**
* Whether or not this variable is actually using the shape function gradient.
*
* Currently hardcoded to true because we always compute the value.
*/
bool usesGradPhiNeighbor() const { return true; }
/**
* Whether or not this variable is actually using the shape function second derivatives.
*/
virtual bool usesSecondPhiNeighbor() const = 0;
///@{
/**
* dof values getters
*/
virtual const DoFValue & dofValues() const = 0;
virtual const DoFValue & dofValuesOld() const = 0;
virtual const DoFValue & dofValuesOlder() const = 0;
virtual const DoFValue & dofValuesPreviousNL() const = 0;
virtual const DoFValue & dofValuesNeighbor() const = 0;
virtual const DoFValue & dofValuesOldNeighbor() const = 0;
virtual const DoFValue & dofValuesOlderNeighbor() const = 0;
virtual const DoFValue & dofValuesPreviousNLNeighbor() const = 0;
virtual const DoFValue & dofValuesDot() const = 0;
virtual const DoFValue & dofValuesDotNeighbor() const = 0;
virtual const DoFValue & dofValuesDotOld() const = 0;
virtual const DoFValue & dofValuesDotOldNeighbor() const = 0;
virtual const DoFValue & dofValuesDotDot() const = 0;
virtual const DoFValue & dofValuesDotDotNeighbor() const = 0;
virtual const DoFValue & dofValuesDotDotOld() const = 0;
virtual const DoFValue & dofValuesDotDotOldNeighbor() const = 0;
virtual const MooseArray<Number> & dofValuesDuDotDu() const = 0;
virtual const MooseArray<Number> & dofValuesDuDotDuNeighbor() const = 0;
virtual const MooseArray<Number> & dofValuesDuDotDotDu() const = 0;
virtual const MooseArray<Number> & dofValuesDuDotDotDuNeighbor() const = 0;
/**
* tag values getters
*/
virtual const FieldVariableValue & vectorTagValue(TagID tag) const = 0;
virtual const DoFValue & nodalVectorTagValue(TagID tag) const = 0;
virtual const DoFValue & vectorTagDofValue(TagID tag) const = 0;
virtual void residualSetup() override;
virtual void jacobianSetup() override;
virtual void timestepSetup() override;
using MooseVariableFieldBase::hasBlocks;
/*
* Returns whether a variable is defined on a block as a functor.
* This makes the link between functor block restriction and the
* BlockRestrictable interface.
* @param id subdomain id we want to know whether the variable is defined on
* @return whether the variable is defined on this domain
*/
bool hasBlocks(const SubdomainID id) const override { return BlockRestrictable::hasBlocks(id); }
protected:
/**
* Get the solution corresponding to the provided state
*/
const NumericVector<Number> & getSolution(const Moose::StateArg & state) const;
/// the time integrator used for computing time derivatives
const TimeIntegrator * const _time_integrator;
/// A dummy ADReal variable
mutable ADReal _ad_real_dummy = 0;
};
#define usingMooseVariableFieldMembers \
usingMooseVariableFieldBaseMembers; \
using MooseVariableField<OutputType>::_time_integrator; \
using MooseVariableField<OutputType>::_ad_real_dummy; \
using MooseVariableField<OutputType>::getSolution