https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MooseVariableDataFV.h
Go to the documentation of this file.
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#include "MooseArray.h"
13#include "MooseTypes.h"
16#include "TheWarehouse.h"
17
18#include "libmesh/tensor_tools.h"
19#include "libmesh/vector_value.h"
20#include "libmesh/tensor_value.h"
21#include "libmesh/type_n_tensor.h"
22#include "libmesh/fe_type.h"
23#include "libmesh/dof_map.h"
24#include "libmesh/enum_fe_family.h"
25#include "SubProblem.h"
26
27#include <functional>
28#include <vector>
29
30class FaceInfo;
31class SystemBase;
32class TimeIntegrator;
33class Assembly;
34
35template <typename>
36class MooseVariableFV;
37
38namespace libMesh
39{
40class QBase;
41}
42
43namespace Moose
44{
45template <typename T>
46void
47initDofIndices(T & data, const Elem & elem)
48{
49 if (data._prev_elem != &elem)
50 {
51 data._dof_map.dof_indices(&elem, data._dof_indices, data._var_num);
52 data._prev_elem = &elem;
53 }
54}
55}
56
57namespace
58{
59template <typename T, typename T2>
60void
61assignForAllQps(const T & value, T2 & array, const unsigned int nqp)
62{
63 for (const auto qp : make_range(nqp))
64 array[qp] = value;
65}
66}
67
68template <typename OutputType>
70{
71public:
72 // type for gradient, second and divergence of template class OutputType
76
77 // shortcut for types storing values on quadrature points
83
84 // shape function type for the template class OutputType
86
87 // type for gradient, second and divergence of shape functions of template class OutputType
91
92 // DoF value type for the template class OutputType
95
97 SystemBase & sys,
98 THREAD_ID tid,
99 Moose::ElementType element_type,
100 const Elem * const & elem);
101
102 bool isNodal() const override { return false; }
103 bool hasDoFsOnNodes() const override { return false; }
105
109 bool needsAD() const { return _need_ad; }
110
115 void setGeometry(Moose::GeometryType gm_type);
116
118
122 void computeValuesFace(const FaceInfo & fi);
123
127 void computeValues();
128
132 void computeAD(const unsigned int num_dofs, const unsigned int nqp);
133
135
139 const Elem * const & currentElem() const { return _elem; }
140
144 void prepareIC();
145
147
151 const FieldVariableValue & sln(Moose::SolutionState state) const;
152
156 const FieldVariableGradient & gradSlnDot() const;
157
161 const FieldVariableGradient & gradSlnDotDot() const;
162
168
174
179
184
186 {
187 mooseError("Gradient of time derivative not yet implemented for FV");
188 }
189
195
197
199
200 const FieldVariableValue & uDot() const;
201
202 const FieldVariableValue & uDotDot() const;
203
204 const FieldVariableValue & uDotOld() const;
205
206 const FieldVariableValue & uDotDotOld() const;
207
208 const VariableValue & duDotDu() const
209 {
210 _need_du_dot_du = true;
211 return _du_dot_du;
212 }
213
214 const VariableValue & duDotDotDu() const
215 {
216 _need_du_dotdot_du = true;
217 return _du_dotdot_du;
218 }
219
223 void setDofValues(const DenseVector<OutputData> & values);
224
226
229 void setDofValue(const OutputData & value, unsigned int index);
231
233 getElementalValue(const Elem * elem, Moose::SolutionState state, unsigned int idx = 0) const;
234
236
237 void getDofIndices(const Elem * elem, std::vector<dof_id_type> & dof_indices) const;
238 const std::vector<dof_id_type> & dofIndices() const;
239 unsigned int numberOfDofs() const;
241 {
242 _dof_indices.clear();
243 _prev_elem = nullptr;
244 }
245
247
248 const DofValue & dofValuesDot() const;
249 const DofValue & dofValuesDotOld() const;
250 const DofValue & dofValuesDotDot() const;
251 const DofValue & dofValuesDotDotOld() const;
254
258 const MooseArray<ADReal> & adDofValues() const;
259
263 const MooseArray<ADReal> & adDofValuesDot() const;
264
266
271 const FieldVariableValue & increment() const { return _increment; }
272
277
279 bool hasDirichletBC() const { return _has_dirichlet_bc; }
280
281 void meshChanged() override;
282
283protected:
284 virtual const MooseVariableFV<OutputType> & var() const override { return _var; }
285
286private:
287 void initializeSolnVars();
288
294 void fetchADDofValues();
295
299 bool safeToComputeADUDot() const;
300
303
305
306 const unsigned int _var_num;
307
309
312
315
318
321
323 mutable bool _need_second;
324 mutable bool _need_second_old;
325 mutable bool _need_second_older;
327
329 mutable bool _need_curl;
330 mutable bool _need_curl_old;
331 mutable bool _need_curl_older;
332
334 mutable bool _need_ad;
335 mutable bool _need_ad_u;
336 mutable bool _need_ad_u_dot;
337 mutable bool _need_ad_u_dotdot;
338 mutable bool _need_ad_grad_u;
340 mutable bool _need_ad_second_u;
341
345
351
356
367
368 // time derivatives
369
372
375
378
381
384
387
390
394 const Elem * const & _elem;
396 mutable const Elem * _prev_elem = nullptr;
397
398 const std::vector<dof_id_type> & initDofIndices();
399
402
404 const bool _displaced;
405
408
411
416
417 using MooseVariableDataBase<OutputType>::_sys;
418 using MooseVariableDataBase<OutputType>::_subproblem;
423 using MooseVariableDataBase<OutputType>::_vector_tag_u;
427 using MooseVariableDataBase<OutputType>::_matrix_tag_u;
429 using MooseVariableDataBase<OutputType>::_dof_indices;
434 using MooseVariableDataBase<OutputType>::_solution_tag;
438 using MooseVariableDataBase<OutputType>::_dof_map;
439 using MooseVariableDataBase<OutputType>::_need_u_dot;
459 using MooseVariableDataBase<OutputType>::_tid;
465
466 friend void Moose::initDofIndices<>(MooseVariableDataFV<OutputType> &, const Elem &);
467};
468
470
471template <typename OutputType>
472inline bool
474{
475 // If we don't have a time integrator then we have no way to calculate _ad_u_dot because we rely
476 // on calls to TimeIntegrator::computeADTimeDerivatives. Another potential situation where
477 // _ad_u_dot computation is potentially troublesome is if we are an auxiliary variable which uses
478 // the auxiliary system copy of the time integrator. Some derived time integrator classes do setup
479 // in their solve() method, and that solve() method only happens for the nonlinear system copy of
480 // the time integrator.
481 return _time_integrator && (_var.kind() == Moose::VAR_SOLVER);
482}
483
484template <typename OutputType>
487{
488 // Generally speaking, we need u dot information when computing u dot dot
489 adUDot();
490
491 _need_ad = _need_ad_u_dotdot = true;
492
493 if (!safeToComputeADUDot())
494 // We will just copy the value of _u_dotdot into _ad_u_dotdot
495 _need_u_dotdot = true;
496
497 return _ad_u_dotdot;
498}
499
500template <typename OutputType>
501const std::vector<dof_id_type> &
503{
504 return const_cast<MooseVariableDataFV<OutputType> *>(this)->initDofIndices();
505}
506
507template <typename OutputType>
508unsigned int
510{
511 return dofIndices().size();
512}
DualNumber< Real, DNDerivativeType, true > ADReal
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
OutputTools< Real >::VariableValue VariableValue
Definition MooseTypes.h:348
typename OutputTools< typename Moose::ADType< T >::type >::VariableSecond ADTemplateVariableSecond
Definition MooseTypes.h:659
typename OutputTools< typename Moose::ADType< T >::type >::VariableValue ADTemplateVariableValue
Definition MooseTypes.h:653
unsigned int THREAD_ID
Definition MooseTypes.h:237
typename OutputTools< typename Moose::ADType< T >::type >::VariableGradient ADTemplateVariableGradient
Definition MooseTypes.h:656
std::array< Real, 2 > values
Definition MortarUtils.C:52
Keeps track of stuff related to assembling.
Definition Assembly.h:110
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
Interface for notifications that the mesh has changed.
forward declarations
Definition MooseArray.h:18
OutputType _nodal_value_dotdot
nodal values of u_dotdot
std::vector< dof_id_type > _dof_indices
The dof indices for the current element.
OutputType _nodal_value_dot_old
nodal values of u_dot_old
bool _need_dof_values_dot
local solution flags
std::vector< FieldVariableValue > _vector_tag_u
TagID _previous_nl_solution_tag
The vector tag ID corresponding to the previous nonlinear iteration's solution vector.
DofValues _dof_values_dotdot
second time derivative of the solution values
TagID _old_solution_tag
The vector tag ID corresponding to the old solution vector.
SystemBase & _sys
The MOOSE system which ultimately holds the vectors and matrices relevant to this variable data.
std::vector< FieldVariableValue > _matrix_tag_u
std::vector< bool > _need_matrix_tag_u
void fetchDofValues()
Helper methods for assigning dof values from their corresponding solution values.
const libMesh::DofMap & _dof_map
The degree of freedom map from libMesh.
OutputType _nodal_value_dotdot_old
nodal values of u_dotdot_old
std::vector< DofValues > _vector_tags_dof_u
TagID _solution_tag
The vector tag ID corresponding to the solution vector.
std::vector< bool > _need_matrix_tag_dof_u
std::vector< DofValues > _matrix_tags_dof_u
TagID _older_solution_tag
The vector tag ID corresponding to the older solution vector.
std::vector< bool > _need_vector_tag_u
DofValues _dof_values_dot_old
the previous time step's solution value time derivative
DofValues _dof_values_dot
time derivative of the solution values
MooseArray< libMesh::Number > _dof_du_dotdot_du
derivatives of the solution value second time derivative with respect to the degrees of freedom
std::vector< FieldVariableGradient > _vector_tag_grad
DofValues _dof_values_dotdot_old
the previous time step's solution value second time derivative
std::set< TagID > _required_vector_tags
The set of vector tags (residual + solution) we need to evaluate.
const THREAD_ID _tid
The thread ID that this object is on.
std::vector< bool > _need_vector_tag_dof_u
bool _need_grad_dot
gradient dot flags
OutputType _nodal_value_dot
nodal values of u_dot
const SubProblem & _subproblem
The subproblem which we can query for information related to tagged vectors and matrices.
bool _has_dof_values
Whether we currently have degree of freedom values stored in our local containers (corresponding to t...
MooseArray< libMesh::Number > _dof_du_dot_du
derivatives of the solution value time derivative with respect to the degrees of freedom
std::vector< bool > _need_vector_tag_grad
const ADReal _ad_zero
A zero AD variable.
const Assembly & _assembly
const FieldVariableValue & uDotDot() const
VariableValue _du_dotdot_du
derivative of u_dotdot wrt u
FieldVariableGradient _grad_u_dotdot
void computeValues()
compute the variable values
libMesh::FEContinuity _continuity
Continuity type of the variable.
const ADTemplateVariableGradient< OutputType > & adGradSlnDot() const
bool safeToComputeADUDot() const
Helper method that tells us whether it's safe to compute _ad_u_dot.
MooseArray< ADReal > _ad_dof_values
bool _has_dirichlet_bc
if this variable has a dirichlet bc defined on a particular face
libMesh::TensorTools::IncrementRank< OutputShape >::type OutputShapeGradient
void setGeometry(Moose::GeometryType gm_type)
Set the geometry type before calculating variables values.
MooseArray< OutputType > FieldVariableCurl
FieldVariableValue _u_dotdot
u_dotdot (second time derivative)
ADTemplateVariableGradient< OutputShape > _ad_grad_u_dot
const Elem *const & _elem
The current elem.
void computeIncrementAtQps(const libMesh::NumericVector< libMesh::Number > &increment_vec)
Compute and store incremental change in solution at QPs based on increment_vec.
const DofValue & dofValuesDot() const
ADTemplateVariableValue< OutputShape > _ad_u_dot
void fetchADDofValues()
Helper methods for assigning nodal values from their corresponding solution values (dof values as the...
const MooseArray< libMesh::Number > & dofValuesDuDotDu() const
Moose::DOFType< OutputType >::type OutputData
bool hasDoFsOnNodes() const override
Whether this data is associated with a variable that has DoFs on nodes.
Moose::ElementType _element_type
The element type this object is storing data for. This is either Element, Neighbor,...
FieldVariableSecond _second_u_previous_nl
const FieldVariableValue & uDotDotOld() const
const MooseArray< libMesh::Number > & dofValuesDuDotDotDu() const
const DofValue & dofValuesDotDotOld() const
virtual const MooseVariableFV< OutputType > & var() const override
ADTemplateVariableGradient< OutputShape > _ad_grad_u
const Elem *const & currentElem() const
The current element.
VariableValue _du_dot_du
derivative of u_dot wrt u
FieldVariableValue _u_dot_old
u_dot_old (time derivative)
const VariableValue & duDotDu() const
unsigned int numberOfDofs() const
bool _need_second
SolutionState second_u flags.
const MooseArray< ADReal > & adDofValues() const
Return the AD dof values.
MooseArray< ADReal > _ad_dofs_dotdot
const libMesh::FEType & _fe_type
const FieldVariableGradient & gradSlnDotDot() const
Local second time derivative of solution gradient getter.
MooseArray< ADReal > _ad_dofs_dot
ADTemplateVariableValue< OutputShape > _ad_u_dotdot
libMesh::FEContinuity getContinuity() const override
Return the variable continuity.
FieldVariableValue _u_dotdot_old
u_dotdot_old (second time derivative)
FieldVariableCurl _curl_u
curl_u
const DofValue & dofValuesDotOld() const
void computeValuesFace(const FaceInfo &fi)
compute the variable values
const bool _displaced
Whether this variable is being calculated on a displaced system.
const std::vector< dof_id_type > & dofIndices() const
FieldVariableCurl _curl_u_older
const ADTemplateVariableValue< OutputType > & adUDotDot() const
const MooseArray< ADReal > & adDofValuesDot() const
Return the AD dof time derivatives.
void meshChanged() override
Called on this object when the mesh changes.
const MooseVariableFV< OutputType > & _var
A const reference to the owning MooseVariableFV object.
const FieldVariableValue & uDotOld() const
const VariableValue & duDotDotDu() const
void computeAD(const unsigned int num_dofs, const unsigned int nqp)
compute AD things
ADReal _ad_real_dummy
A dummy ADReal variable.
libMesh::TensorTools::IncrementRank< OutputGradient >::type OutputSecond
MooseArray< OutputType > FieldVariableValue
const libMesh::QBase * _qrule
The quadrature rule.
libMesh::TensorTools::DecrementRank< OutputType >::type OutputDivergence
FieldVariableValue _u_dot
u_dot (time derivative)
FieldVariableSecond _second_u_old
FieldVariableGradient _grad_u_dot
grad_u dots
const TimeIntegrator *const _time_integrator
Pointer to time integrator.
FieldVariableValue _increment
Increment in the variable used in dampers.
MooseArray< OutputGradient > FieldVariableGradient
const ADTemplateVariableValue< OutputType > & adUDot() const
TheWarehouse::QueryCache _fv_flux_kernel_query_cache
Cached warehouse query for FVFluxKernels.
FieldVariableSecond _second_u
second_u
libMesh::TensorTools::IncrementRank< OutputShapeGradient >::type OutputShapeSecond
const ADTemplateVariableValue< OutputType > & adSln() const
libMesh::TensorTools::DecrementRank< OutputShape >::type OutputShapeDivergence
void setDofValues(const DenseVector< OutputData > &values)
Set local DOF values and evaluate the values on quadrature points.
bool needsAD() const
Returns whether this data structure needs automatic differentiation calculations.
const FieldVariableCurl & curlSln(Moose::SolutionState state) const
Local solution curl getter.
const FieldVariableValue & sln(Moose::SolutionState state) const
Local solution value.
FieldVariableCurl _curl_u_old
MooseArray< OutputDivergence > FieldVariableDivergence
const Elem * _prev_elem
used to keep track of when dof indices are out of date
OutputData getElementalValue(const Elem *elem, Moose::SolutionState state, unsigned int idx=0) const
ADTemplateVariableValue< OutputShape > _ad_u
AD u.
Moose::ShapeType< OutputType >::type OutputShape
void setDofValue(const OutputData &value, unsigned int index)
dof value setters
libMesh::TensorTools::IncrementRank< OutputType >::type OutputGradient
const FieldVariableValue & uDot() const
MooseArray< OutputSecond > FieldVariableSecond
const std::vector< dof_id_type > & initDofIndices()
TheWarehouse::QueryCache _fv_elemental_kernel_query_cache
Cached warehouse query for FVElementalKernels.
const FieldVariableSecond & secondSln(Moose::SolutionState state) const
Local solution second spatial derivative getter.
const FieldVariableGradient & gradSlnDot() const
Local time derivative of solution gradient getter.
ADTemplateVariableSecond< OutputShape > _ad_second_u
const ADTemplateVariableGradient< OutputType > & adGradSln() const
const unsigned int _var_num
void getDofIndices(const Elem *elem, std::vector< dof_id_type > &dof_indices) const
const DofValue & dofValuesDotDot() const
bool isNodal() const override
MooseArray< OutputData > DofValue
void prepareIC()
prepare the initial condition
FieldVariableSecond _second_u_older
const FieldVariableValue & increment() const
Increment getter.
bool hasDirichletBC() const
checks if a Dirichlet BC exists on this face
const ADTemplateVariableSecond< OutputType > & adSecondSln() const
This class provides variable solution values for other classes/objects to bind to when looping over f...
Base class for a system (of equations)
Definition SystemBase.h:87
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
Base class for time integrators.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
SolutionState
Definition MooseTypes.h:262
@ VAR_SOLVER
Definition MooseTypes.h:770
void initDofIndices(T &data, const Elem &elem)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
IntRange< T > make_range(T beg, T end)
OutputType type
Definition MooseTypes.h:302
OutputType type
Definition MooseTypes.h:291
A structure for storing the various lists that contain the names of the items to be exported.