forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArrayMooseVariable.h
465 lines (384 loc) · 15.9 KB
/
ArrayMooseVariable.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
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#ifndef ARRAYMOOSEVARIABLE_H
#define ARRAYMOOSEVARIABLE_H
#include "MooseVariableBase.h"
#include "ParallelUniqueId.h"
#include "libmesh/dense_matrix.h"
#include "Eigen/Core"
// Forward declarations
class Assembly;
class SubProblem;
class SystemBase;
// libMesh forward declarations
namespace libMesh
{
class Elem;
class Node;
class QBase;
template <typename T> class NumericVector;
template <typename T> class DenseVector;
}
typedef MooseArray<Eigen::VectorXd> ArrayVariableValue;
typedef MooseArray<Eigen::Matrix<Real, Eigen::Dynamic, LIBMESH_DIM> > ArrayVariableGradient;
typedef MooseArray<RealTensor> ArrayVariableSecond;
// typedef MooseArray<std::vector<Real> > VariableTestValue;
// typedef MooseArray<std::vector<RealGradient> > VariableTestGradient;
// typedef MooseArray<std::vector<RealTensor> > VariableTestSecond;
//
// typedef MooseArray<std::vector<Real> > VariablePhiValue;
// typedef MooseArray<std::vector<RealGradient> > VariablePhiGradient;
// typedef MooseArray<std::vector<RealTensor> > VariablePhiSecond;
class Assembly;
class SubProblem;
class SystemBase;
/**
* Class for stuff related to variables
*
* Each variable can compute nodal or elemental (at QPs) values.
*/
class ArrayMooseVariable : public MooseVariableBase
{
public:
ArrayMooseVariable(unsigned int var_num, const FEType & fe_type, SystemBase & sys, Assembly & assembly, Moose::VarKindType var_kind);
virtual ~ArrayMooseVariable();
/**
* Clear out the dof indices. We do this in case this variable is not going to be prepared at all...
*/
void clearDofIndices();
void prepare();
void prepareNeighbor();
void prepareAux();
void prepareIC();
void reinitNode();
void reinitNodeNeighbor();
void reinitAux();
void reinitAuxNeighbor();
void reinitNodes(const std::vector<dof_id_type> & nodes);
void reinitNodesNeighbor(const std::vector<dof_id_type> & nodes);
const std::set<SubdomainID> & activeSubdomains();
/**
* Is the variable active on the subdomain?
* @param subdomain The subdomain id in question
* @return true if active on subdomain, false otherwise
*/
bool activeOnSubdomain(SubdomainID subdomain) const;
/**
* Is this variable nodal
* @return true if it nodal, otherwise false
*/
virtual bool isNodal() const override;
/**
* Current element this variable is evaluated at
*/
const Elem * & currentElem() { return _elem; }
/**
* Current side this variable is being evaluated on
*/
unsigned int & currentSide() { return _current_side; }
/**
* Current neighboring element
*/
const Elem * & neighbor() { return _neighbor; }
/**
* Whether or not this variable is computing any second derivatives.
*/
// bool computingSecond() { return _need_second || _need_second_old || _need_second_older; }
const VariablePhiValue & phi();
const VariablePhiGradient & gradPhi();
// const VariablePhiSecond & secondPhi();
const VariablePhiValue & phiFace();
const VariablePhiGradient & gradPhiFace();
// const VariablePhiSecond & secondPhiFace();
const VariablePhiValue & phiNeighbor();
const VariablePhiGradient & gradPhiNeighbor();
// const VariablePhiSecond & secondPhiNeighbor();
const VariablePhiValue & phiFaceNeighbor();
const VariablePhiGradient & gradPhiFaceNeighbor();
// const VariablePhiSecond & secondPhiFaceNeighbor();
const MooseArray<Point> & normals() { return _normals; }
// damping
ArrayVariableValue & increment() { return _increment; }
const ArrayVariableValue & sln() { return _u; }
const ArrayVariableValue & slnOld() { _need_u_old = true; return _u_old; }
const ArrayVariableValue & slnOlder() { _need_u_older = true;return _u_older; }
const ArrayVariableGradient & gradSln() { return _grad_u; }
const ArrayVariableGradient & gradSlnOld() { _need_grad_old = true; return _grad_u_old; }
const ArrayVariableGradient & gradSlnOlder() { _need_grad_older = true; return _grad_u_older; }
// const VariableSecond & secondSln() { _need_second = true; secondPhi(); secondPhiFace(); return _second_u; }
// const VariableSecond & secondSlnOld() { _need_second_old = true; secondPhi(); secondPhiFace(); return _second_u_old; }
// const VariableSecond & secondSlnOlder() { _need_second_older = true; secondPhi(); secondPhiFace(); return _second_u_older; }
const ArrayVariableValue & uDot() { return _u_dot; }
const ArrayVariableValue & duDotDu() { return _du_dot_du; }
const Node * & node() { return _node; }
dof_id_type & nodalDofIndex() { return _nodal_dof_index; }
bool isNodalDefined() { return _is_defined; }
const ArrayVariableValue & nodalSln() { return _nodal_u; }
const ArrayVariableValue & nodalSlnOld() { return _nodal_u_old; }
const ArrayVariableValue & nodalSlnOlder() { return _nodal_u_older; }
const ArrayVariableValue & nodalSlnDot() { return _nodal_u_dot; }
const ArrayVariableValue & nodalSlnDuDotDu() { return _nodal_du_dot_du; }
const ArrayVariableValue & nodalValue();
const ArrayVariableValue & nodalValueOld();
const ArrayVariableValue & nodalValueOlder();
const ArrayVariableValue & nodalValueDot();
const ArrayVariableValue & nodalValueNeighbor();
const ArrayVariableValue & nodalValueOldNeighbor();
const ArrayVariableValue & nodalValueOlderNeighbor();
const ArrayVariableValue & nodalValueDotNeighbor();
const ArrayVariableValue & slnNeighbor() { return _u_neighbor; }
const ArrayVariableValue & slnOldNeighbor() { _need_u_old_neighbor = true; return _u_old_neighbor; }
const ArrayVariableValue & slnOlderNeighbor() { _need_u_older_neighbor = true; return _u_older_neighbor; }
const ArrayVariableGradient & gradSlnNeighbor() { return _grad_u_neighbor; }
const ArrayVariableGradient & gradSlnOldNeighbor() { _need_grad_old_neighbor = true; return _grad_u_old_neighbor; }
const ArrayVariableGradient & gradSlnOlderNeighbor() { _need_grad_older_neighbor = true; return _grad_u_older_neighbor; }
// const VariableSecond & secondSlnNeighbor() { _need_second_neighbor = true; secondPhiFaceNeighbor(); return _second_u_neighbor; }
// const VariableSecond & secondSlnOldNeighbor() { _need_second_old_neighbor = true; secondPhiFaceNeighbor(); return _second_u_old_neighbor; }
// const VariableSecond & secondSlnOlderNeighbor() { _need_second_older_neighbor = true; secondPhiFaceNeighbor(); return _second_u_older_neighbor; }
const ArrayVariableValue & uDotNeighbor() { return _u_dot_neighbor; }
const ArrayVariableValue & duDotDuNeighbor() { return _du_dot_du_neighbor; }
const Node * & nodeNeighbor() { return _node_neighbor; }
dof_id_type & nodalDofIndexNeighbor() { return _nodal_dof_index_neighbor; }
bool isNodalNeighborDefined() { return _is_defined_neighbor; }
const ArrayVariableValue & nodalSlnNeighbor() { return _nodal_u_neighbor; }
const ArrayVariableValue & nodalSlnOldNeighbor() { return _nodal_u_old_neighbor; }
const ArrayVariableValue & nodalSlnOlderNeighbor() { return _nodal_u_older_neighbor; }
const ArrayVariableValue & nodalSlnDotNeighbor() { return _nodal_u_dot_neighbor; }
const ArrayVariableValue & nodalSlnDuDotDuNeighbor() { return _nodal_du_dot_du_neighbor; }
/**
* Compute values at interior quadrature points
*/
void computeElemValues();
// /**
// * Compute values at facial quadrature points
// */
// void computeElemValuesFace();
// /**
// * Compute values at facial quadrature points for the neighbor
// */
// void computeNeighborValuesFace();
// /**
// * Compute values at quadrature points for the neighbor
// */
// void computeNeighborValues();
// /**
// * Compute nodal values of this variable
// */
// void computeNodalValues();
// /**
// * Compute nodal values of this variable in the neighbor
// */
// void computeNodalNeighborValues();
// /**
// * Set the nodal value for this variable to keep everything up to date
// */
// void setNodalValue(Number value, unsigned int idx = 0);
// /**
// * Set values for this variable to keep everything up to date
// */
// void setNodalValue(const DenseVector<Number> & value);
//
// /**
// * Set the neighbor nodal value for this variable
// */
// void setNodalValueNeighbor(Number value);
// /**
// * Set the neighbor values for this variable
// */
// void setNodalValueNeighbor(const DenseVector<Number> & value);
//
// /**
// * Compute and store incremental change based on increment_vec
// */
// void computeIncrement(const NumericVector<Number> & increment_vec);
//
// /**
// * Get DOF indices for currently selected element
// * @return
// */
// std::vector<dof_id_type> & dofIndicesNeighbor() { return _dof_indices_neighbor; }
//
// unsigned int numberOfDofsNeighbor() { return _dof_indices_neighbor.size(); }
// void insert(NumericVector<Number> & residual);
// void add(NumericVector<Number> & residual);
// /**
// * Get the value of this variable at given node
// */
// DenseVector getNodalValue(const Node & node);
// /**
// * Get the old value of this variable at given node
// */
// DenseVector getNodalValueOld(const Node & node);
// /**
// * Get the t-2 value of this variable at given node
// */
// DenseVector getNodalValueOlder(const Node & node);
/**
* Compute the variable value at a point on an element
* @param elem The element we are computing on
* @param phi Evaluated shape functions at a point
* @return The variable value
*/
DenseVector<Real> getValue(const Elem * elem, const std::vector<std::vector<Real> > & phi) const;
DenseMatrix<Real> getGradient(const Elem * elem, const std::vector<std::vector<RealGradient> > & phi) const;
/**
* Retrieve the Elemental DOF
* @param elem The element we are computing on
* @return The variable value
*/
Number getElementalValue(const Elem * elem, unsigned int idx = 0) const;
/**
* Whether or not this variable is actually using the shape function value.
*
* Currently hardcoded to true because we always compute the value.
*/
bool usesPhi() { 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 usesGradPhi() { return true; }
/**
* Whether or not this variable is actually using the shape function second derivative.
*/
// bool usesSecondPhi() { return _need_second || _need_second_old || _need_second_older; }
protected:
/**
* Get dof indices for the variable
* @param elem Element whose DOFs we are requesting (input)
* @param dof_indices DOF indices for the given element (output)
*/
void getDofIndices(const Elem * elem, std::vector<dof_id_type> & dof_indices);
protected:
/// Thread ID
THREAD_ID _tid;
/// Quadrature rule for interior
QBase * & _qrule;
/// Quadrature rule for the face
QBase * & _qrule_face;
/// Quadrature rule for the neighbor
QBase * & _qrule_neighbor;
/// current element
const Elem * & _elem;
/// the side of the current element (valid when doing face assembly)
unsigned int & _current_side;
/// neighboring element
const Elem * & _neighbor;
/// DOF indices (neighbor)
std::vector<dof_id_type> _dof_indices_neighbor;
/// Cache of local dof indices for the first variable in the variable group
std::vector<dof_id_type> _local_dof_indices;
/// Interface to raw PetscVector data
Eigen::Map<Eigen::VectorXd> _mapped_values;
// Interface to the current gradient
Eigen::Map<Eigen::Vector3d> _mapped_grad_phi;
bool _need_u_old;
bool _need_u_older;
bool _need_grad_old;
bool _need_grad_older;
// bool _need_second;
// bool _need_second_old;
// bool _need_second_older;
bool _need_u_old_neighbor;
bool _need_u_older_neighbor;
bool _need_grad_old_neighbor;
bool _need_grad_older_neighbor;
// bool _need_second_neighbor;
// bool _need_second_old_neighbor;
// bool _need_second_older_neighbor;
bool _need_nodal_u;
bool _need_nodal_u_old;
bool _need_nodal_u_older;
bool _need_nodal_u_dot;
bool _need_nodal_u_neighbor;
bool _need_nodal_u_old_neighbor;
bool _need_nodal_u_older_neighbor;
bool _need_nodal_u_dot_neighbor;
// Shape function values, gradients. second derivatives
const VariablePhiValue & _phi;
const VariablePhiGradient & _grad_phi;
// const VariablePhiSecond * _second_phi;
// Values, gradients and second derivatives of shape function on faces
const VariablePhiValue & _phi_face;
const VariablePhiGradient & _grad_phi_face;
// const VariablePhiSecond * _second_phi_face;
// Values, gradients and second derivatives of shape function
const VariablePhiValue & _phi_neighbor;
const VariablePhiGradient & _grad_phi_neighbor;
// const VariablePhiSecond * _second_phi_neighbor;
// Values, gradients and second derivatives of shape function on faces
const VariablePhiValue & _phi_face_neighbor;
const VariablePhiGradient & _grad_phi_face_neighbor;
// const VariablePhiSecond * _second_phi_face_neighbor;
/// Normals at QPs on faces
const MooseArray<Point> & _normals;
ArrayVariableValue _u, _u_bak;
ArrayVariableValue _u_old, _u_old_bak;
ArrayVariableValue _u_older, _u_older_bak;
ArrayVariableGradient _grad_u, _grad_u_bak;
ArrayVariableGradient _grad_u_old, _grad_u_old_bak;
ArrayVariableGradient _grad_u_older, _grad_u_older_bak;
// ArrayVariableSecond _second_u, _second_u_bak;
// ArrayVariableSecond _second_u_old, _second_u_old_bak;
// ArrayVariableSecond _second_u_older, _second_u_older_bak;
ArrayVariableValue _u_neighbor;
ArrayVariableValue _u_old_neighbor;
ArrayVariableValue _u_older_neighbor;
ArrayVariableGradient _grad_u_neighbor;
ArrayVariableGradient _grad_u_old_neighbor;
ArrayVariableGradient _grad_u_older_neighbor;
// ArrayVariableSecond _second_u_neighbor;
// ArrayVariableSecond _second_u_old_neighbor;
// ArrayVariableSecond _second_u_older_neighbor;
// time derivatives
/// u_dot (time derivative)
ArrayVariableValue _u_dot, _u_dot_bak;
ArrayVariableValue _u_dot_neighbor, _u_dot_bak_neighbor;
/// derivative of u_dot wrt u
ArrayVariableValue _du_dot_du, _du_dot_du_bak;
ArrayVariableValue _du_dot_du_neighbor, _du_dot_du_bak_neighbor;
// nodal stuff
/// If the variable is defined at the node (used in compute nodal values)
bool _is_defined;
/// If true, the nodal value gets inserted on calling insert()
bool _has_nodal_value;
bool _has_nodal_value_neighbor;
const Node * & _node;
dof_id_type _nodal_dof_index;
ArrayVariableValue _nodal_u;
ArrayVariableValue _nodal_u_old;
ArrayVariableValue _nodal_u_older;
/// nodal values of u_dot
ArrayVariableValue _nodal_u_dot;
/// nodal values of derivative of u_dot wrt u
ArrayVariableValue _nodal_du_dot_du;
/// If the variable is defined at the neighbor node (used in compute nodal values)
bool _is_defined_neighbor;
const Node * & _node_neighbor;
dof_id_type _nodal_dof_index_neighbor;
ArrayVariableValue _nodal_u_neighbor;
ArrayVariableValue _nodal_u_old_neighbor;
ArrayVariableValue _nodal_u_older_neighbor;
ArrayVariableValue _nodal_u_dot_neighbor;
ArrayVariableValue _nodal_du_dot_du_neighbor;
/// if variable is nodal
bool _is_nodal;
// damping
ArrayVariableValue _increment;
friend class NodeFaceConstraint;
friend class ValueThresholdMarker;
friend class ValueRangeMarker;
};
#endif /* ARRAYMOOSEVARIABLE_H */