https://mooseframework.inl.gov
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"
14 #include "MeshChangedInterface.h"
15 #include "MooseVariableDataBase.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 
30 class FaceInfo;
31 class SystemBase;
32 class TimeIntegrator;
33 class Assembly;
34 
35 template <typename>
36 class MooseVariableFV;
37 
38 namespace libMesh
39 {
40 class QBase;
41 }
42 
43 namespace Moose
44 {
45 template <typename T>
46 void
47 initDofIndices(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 
57 namespace
58 {
59 template <typename T, typename T2>
60 void
61 assignForAllQps(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 
68 template <typename OutputType>
70 {
71 public:
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 
173  const FieldVariableCurl & curlSln(Moose::SolutionState state) const;
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 
232  OutputData
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 
283 protected:
284  virtual const MooseVariableFV<OutputType> & var() const override { return _var; }
285 
286 private:
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;
339  mutable bool _need_ad_grad_u_dot;
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 
465 
466  friend void Moose::initDofIndices<>(MooseVariableDataFV<OutputType> &, const Elem &);
467 };
468 
470 
471 template <typename OutputType>
472 inline 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 
484 template <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 
500 template <typename OutputType>
501 const std::vector<dof_id_type> &
503 {
504  return const_cast<MooseVariableDataFV<OutputType> *>(this)->initDofIndices();
505 }
506 
507 template <typename OutputType>
508 unsigned int
510 {
511  return dofIndices().size();
512 }
void initDofIndices(T &data, const Elem &elem)
typename OutputTools< typename Moose::ADType< T >::type >::VariableSecond ADTemplateVariableSecond
Definition: MooseTypes.h:654
const VariableValue & duDotDu() const
libMesh::FEContinuity getContinuity() const override
Return the variable continuity.
const unsigned int _var_num
FieldVariableValue _u_dot
u_dot (time derivative)
const std::vector< dof_id_type > & initDofIndices()
FieldVariableGradient _grad_u_dotdot
const FieldVariableValue & uDotOld() const
VariableValue _du_dotdot_du
derivative of u_dotdot wrt u
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
Definition: TheWarehouse.h:209
FieldVariableValue _u_dotdot_old
u_dotdot_old (second time derivative)
const MooseArray< ADReal > & adDofValuesDot() const
Return the AD dof time derivatives.
Keeps track of stuff related to assembling.
Definition: Assembly.h:109
void computeIncrementAtQps(const libMesh::NumericVector< libMesh::Number > &increment_vec)
Compute and store incremental change in solution at QPs based on increment_vec.
bool needsAD() const
Returns whether this data structure needs automatic differentiation calculations. ...
bool hasDoFsOnNodes() const override
Whether this data is associated with a variable that has DoFs on nodes.
const FieldVariableValue & uDot() const
const MooseVariableFV< OutputType > & _var
A const reference to the owning MooseVariableFV object.
const ADTemplateVariableSecond< OutputType > & adSecondSln() const
const MooseArray< ADReal > & adDofValues() const
Return the AD dof values.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
void setDofValue(const OutputData &value, unsigned int index)
dof value setters
OutputType type
Definition: MooseTypes.h:297
OutputType type
Definition: MooseTypes.h:286
bool hasDirichletBC() const
checks if a Dirichlet BC exists on this face
const bool _displaced
Whether this variable is being calculated on a displaced system.
unsigned int numberOfDofs() const
const MooseArray< libMesh::Number > & dofValuesDuDotDu() const
const FieldVariableValue & uDotDotOld() const
void setGeometry(Moose::GeometryType gm_type)
Set the geometry type before calculating variables values.
const Assembly & _assembly
MooseArray< ADReal > _ad_dof_values
virtual const MooseVariableFV< OutputType > & var() const override
typename OutputTools< typename Moose::ADType< T >::type >::VariableValue ADTemplateVariableValue
Definition: MooseTypes.h:648
bool _has_dirichlet_bc
if this variable has a dirichlet bc defined on a particular face
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
MooseArray< OutputSecond > FieldVariableSecond
ElementType
Definition: MooseTypes.h:812
Base class for a system (of equations)
Definition: SystemBase.h:85
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:42
A structure for storing the various lists that contain the names of the items to be exported...
FieldVariableSecond _second_u
second_u
FieldVariableCurl _curl_u
curl_u
const TimeIntegrator *const _time_integrator
Pointer to time integrator.
TheWarehouse::QueryCache _fv_flux_kernel_query_cache
Cached warehouse query for FVFluxKernels.
void getDofIndices(const Elem *elem, std::vector< dof_id_type > &dof_indices) const
MooseArray< ADReal > _ad_dofs_dot
const ADTemplateVariableValue< OutputType > & adUDot() const
FieldVariableCurl _curl_u_older
const ADTemplateVariableGradient< OutputType > & adGradSlnDot() const
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:37
libMesh::TensorTools::IncrementRank< OutputShape >::type OutputShapeGradient
FieldVariableValue _u_dotdot
u_dotdot (second time derivative)
const FieldVariableValue & sln(Moose::SolutionState state) const
Local solution value.
Interface for notifications that the mesh has changed.
ADTemplateVariableGradient< OutputShape > _ad_grad_u_dot
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
ADTemplateVariableValue< OutputShape > _ad_u_dot
libMesh::TensorTools::IncrementRank< OutputGradient >::type OutputSecond
void setDofValues(const DenseVector< OutputData > &values)
Set local DOF values and evaluate the values on quadrature points.
const VariableValue & duDotDotDu() const
MooseArray< OutputType > FieldVariableCurl
const libMesh::FEType & _fe_type
void prepareIC()
prepare the initial condition
typename OutputTools< typename Moose::ADType< T >::type >::VariableGradient ADTemplateVariableGradient
Definition: MooseTypes.h:651
ADReal _ad_real_dummy
A dummy ADReal variable.
const FieldVariableValue & uDotDot() const
MooseArray< OutputData > DofValue
FieldVariableSecond _second_u_older
const MooseArray< libMesh::Number > & dofValuesDuDotDotDu() const
const FieldVariableValue & increment() const
Increment getter.
bool isNodal() const override
void computeValues()
compute the variable values
FieldVariableSecond _second_u_old
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:343
libMesh::TensorTools::IncrementRank< OutputShapeGradient >::type OutputShapeSecond
FieldVariableValue _increment
Increment in the variable used in dampers.
FieldVariableSecond _second_u_previous_nl
Moose::DOFType< OutputType >::type OutputData
libMesh::TensorTools::IncrementRank< OutputType >::type OutputGradient
const DofValue & dofValuesDotDot() const
const libMesh::QBase * _qrule
The quadrature rule.
Base class for time integrators.
Moose::ElementType _element_type
The element type this object is storing data for. This is either Element, Neighbor, or Lower.
GeometryType
Definition: MooseTypes.h:277
void meshChanged() override
Called on this object when the mesh changes.
Moose::ShapeType< OutputType >::type OutputShape
libMesh::TensorTools::DecrementRank< OutputType >::type OutputDivergence
SolutionState
Definition: MooseTypes.h:261
bool _need_second
SolutionState second_u flags.
FieldVariableGradient _grad_u_dot
grad_u dots
libMesh::FEContinuity _continuity
Continuity type of the variable.
void computeValuesFace(const FaceInfo &fi)
compute the variable values
MooseVariableDataFV(const MooseVariableFV< OutputType > &var, SystemBase &sys, THREAD_ID tid, Moose::ElementType element_type, const Elem *const &elem)
bool safeToComputeADUDot() const
Helper method that tells us whether it&#39;s safe to compute _ad_u_dot.
IntRange< T > make_range(T beg, T end)
const std::vector< dof_id_type > & dofIndices() const
OutputData getElementalValue(const Elem *elem, Moose::SolutionState state, unsigned int idx=0) const
libMesh::TensorTools::DecrementRank< OutputShape >::type OutputShapeDivergence
MooseArray< OutputGradient > FieldVariableGradient
FieldVariableValue _u_dot_old
u_dot_old (time derivative)
ADTemplateVariableSecond< OutputShape > _ad_second_u
MooseArray< OutputDivergence > FieldVariableDivergence
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
MooseArray< ADReal > _ad_dofs_dotdot
const ADTemplateVariableGradient< OutputType > & adGradSln() const
const Elem *const & _elem
The current elem.
ADTemplateVariableValue< OutputShape > _ad_u
AD u.
This class provides variable solution values for other classes/objects to bind to when looping over f...
const FieldVariableCurl & curlSln(Moose::SolutionState state) const
Local solution curl getter.
const ADTemplateVariableValue< OutputType > & adUDotDot() const
VariableValue _du_dot_du
derivative of u_dot wrt u
const FieldVariableSecond & secondSln(Moose::SolutionState state) const
Local solution second spatial derivative getter.
FieldVariableCurl _curl_u_old
std::vector< dof_id_type > _dof_indices
The dof indices for the current element.
void computeAD(const unsigned int num_dofs, const unsigned int nqp)
compute AD things
const FieldVariableGradient & gradSlnDot() const
Local time derivative of solution gradient getter.
const DofValue & dofValuesDotOld() const
MooseArray< OutputType > FieldVariableValue
const DofValue & dofValuesDot() const
const ADTemplateVariableValue< OutputType > & adSln() const
ADTemplateVariableGradient< OutputShape > _ad_grad_u
bool _need_curl
curl flags
const FieldVariableGradient & gradSlnDotDot() const
Local second time derivative of solution gradient getter.
const Elem * _prev_elem
used to keep track of when dof indices are out of date
unsigned int THREAD_ID
Definition: MooseTypes.h:237
TheWarehouse::QueryCache _fv_elemental_kernel_query_cache
Cached warehouse query for FVElementalKernels.
ADTemplateVariableValue< OutputShape > _ad_u_dotdot
const DofValue & dofValuesDotDotOld() const
void fetchADDofValues()
Helper methods for assigning nodal values from their corresponding solution values (dof values as the...
const Elem *const & currentElem() const
The current element.
const ADReal _ad_zero
A zero AD variable.