25 #include "libmesh/quadrature.h" 26 #include "libmesh/fe_base.h" 27 #include "libmesh/system.h" 28 #include "libmesh/type_n_tensor.h" 30 template <
typename OutputType>
35 const Elem *
const & elem)
40 _fe_type(_var.feType()),
41 _var_num(_var.number()),
42 _assembly(_subproblem.assembly(_tid, var.kind() ==
Moose::
VAR_SOLVER ? sys.number() : 0)),
43 _element_type(element_type),
46 _need_second_old(false),
47 _need_second_older(false),
48 _need_second_previous_nl(false),
50 _need_curl_old(false),
51 _need_curl_older(false),
59 _need_ad_u_dot(false),
60 _need_ad_u_dotdot(false),
61 _need_ad_grad_u(false),
62 _need_ad_grad_u_dot(false),
63 _need_ad_second_u(false),
64 _time_integrator(_sys.queryTimeIntegrator(_var_num)),
66 _displaced(dynamic_cast<const
DisplacedSystem *>(&_sys) ? true : false),
77 template <
typename OutputType>
85 _qrule = _assembly.qRule();
91 _qrule = _assembly.qRuleFace();
98 template <
typename OutputType>
102 if (_sys.solutionUDot())
104 _var.requireQpComputations();
109 mooseError(
"MooseVariableFE: Time derivative of solution (`u_dot`) is not stored. Please set " 110 "uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
113 template <
typename OutputType>
117 if (_sys.solutionUDotDot())
119 _var.requireQpComputations();
120 _need_u_dotdot =
true;
124 mooseError(
"MooseVariableFE: Second time derivative of solution (`u_dotdot`) is not stored. " 125 "Please set uDotDotRequested() to true in FEProblemBase before requesting " 129 template <
typename OutputType>
133 if (_sys.solutionUDotOld())
135 _var.requireQpComputations();
136 _need_u_dot_old =
true;
140 mooseError(
"MooseVariableFE: Old time derivative of solution (`u_dot_old`) is not stored. " 141 "Please set uDotOldRequested() to true in FEProblemBase before requesting " 145 template <
typename OutputType>
149 if (_sys.solutionUDotDotOld())
151 _var.requireQpComputations();
152 _need_u_dotdot_old =
true;
153 return _u_dotdot_old;
156 mooseError(
"MooseVariableFE: Old second time derivative of solution (`u_dotdot_old`) is not " 157 "stored. Please set uDotDotOldRequested() to true in FEProblemBase before " 158 "requesting `u_dotdot_old`");
161 template <
typename OutputType>
165 _var.requireQpComputations();
169 template <
typename OutputType>
173 if (_sys.solutionUDot())
175 _var.requireQpComputations();
176 _need_grad_dot =
true;
180 mooseError(
"MooseVariableFE: Time derivative of solution (`u_dot`) is not stored. Please set " 181 "uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
184 template <
typename OutputType>
188 if (_sys.solutionUDotDot())
190 _var.requireQpComputations();
191 _need_grad_dotdot =
true;
192 return _grad_u_dotdot;
195 mooseError(
"MooseVariableFE: Second time derivative of solution (`u_dotdot`) is not stored. " 196 "Please set uDotDotRequested() to true in FEProblemBase before requesting " 200 template <
typename OutputType>
204 _var.requireQpComputations();
215 _need_second_old =
true;
216 return _second_u_old;
221 _need_second_older =
true;
222 return _second_u_older;
227 _need_second_previous_nl =
true;
228 return _second_u_previous_nl;
238 template <
typename OutputType>
242 _var.requireQpComputations();
253 _need_curl_old =
true;
259 _need_curl_older =
true;
260 return _curl_u_older;
264 mooseError(
"We don't currently support curl from the previous non-linear iteration");
268 template <
typename OutputType>
272 auto && active_coupleable_matrix_tags =
273 _sys.subproblem().getActiveFEVariableCoupleableMatrixTags(_tid);
274 mooseAssert(_qrule,
"We should have a non-null qrule");
275 const auto nqp = _qrule->n_points();
277 for (
auto tag : _required_vector_tags)
278 if (_need_vector_tag_u[tag])
280 _vector_tag_u[tag].resize(nqp);
281 assignForAllQps(0, _vector_tag_u[tag], nqp);
284 for (
auto tag : active_coupleable_matrix_tags)
285 if (_need_matrix_tag_u[tag])
287 _matrix_tag_u[tag].resize(nqp);
288 assignForAllQps(0, _matrix_tag_u[tag], nqp);
293 _second_u.resize(nqp);
294 assignForAllQps(0, _second_u, nqp);
300 assignForAllQps(0, _curl_u, nqp);
303 if (_need_second_previous_nl)
305 _second_u_previous_nl.resize(nqp);
306 assignForAllQps(0, _second_u_previous_nl, nqp);
309 if (_subproblem.isTransient())
314 assignForAllQps(0, _u_dot, nqp);
319 _u_dotdot.resize(nqp);
320 assignForAllQps(0, _u_dotdot, nqp);
325 _u_dot_old.resize(nqp);
326 assignForAllQps(0, _u_dot_old, nqp);
329 if (_need_u_dotdot_old)
331 _u_dotdot_old.resize(nqp);
332 assignForAllQps(0, _u_dotdot_old, nqp);
337 _du_dot_du.resize(nqp);
338 assignForAllQps(0, _du_dot_du, nqp);
341 if (_need_du_dotdot_du)
343 _du_dotdot_du.resize(nqp);
344 assignForAllQps(0, _du_dotdot_du, nqp);
349 _grad_u_dot.resize(nqp);
350 assignForAllQps(0, _grad_u_dot, nqp);
353 if (_need_grad_dotdot)
355 _grad_u_dotdot.resize(nqp);
356 assignForAllQps(0, _grad_u_dotdot, nqp);
359 if (_need_second_old)
361 _second_u_old.resize(nqp);
362 assignForAllQps(0, _second_u_old, nqp);
367 _curl_u_old.resize(nqp);
368 assignForAllQps(0, _curl_u_old, nqp);
371 if (_need_second_older)
373 _second_u_older.resize(nqp);
374 assignForAllQps(0, _second_u_older, nqp);
379 template <
typename OutputType>
383 _has_dirichlet_bc =
false;
384 _dof_map.dof_indices(_elem, _dof_indices, _var_num);
410 template <
typename OutputType>
411 const std::vector<dof_id_type> &
418 template <
typename OutputType>
423 initializeSolnVars();
425 unsigned int num_dofs = _dof_indices.size();
433 mooseAssert(num_dofs == 1 && _vector_tags_dof_u[_solution_tag].size() == 1,
434 "There should only be one dof per elem for FV variables");
436 bool is_transient = _subproblem.isTransient();
437 const auto nqp = _qrule->n_points();
438 auto && active_coupleable_matrix_tags =
439 _sys.subproblem().getActiveFEVariableCoupleableMatrixTags(_tid);
441 bool second_required =
442 _need_second || _need_second_old || _need_second_older || _need_second_previous_nl;
443 bool curl_required = _need_curl || _need_curl_old;
450 _u_dot[qp] = _dof_values_dot[0];
453 _u_dotdot[qp] = _dof_values_dotdot[0];
456 _u_dot_old[qp] = _dof_values_dot_old[0];
458 if (_need_u_dotdot_old)
459 _u_dotdot_old[qp] = _dof_values_dotdot_old[0];
462 _du_dot_du[qp] = _dof_du_dot_du[0];
464 if (_need_du_dotdot_du)
465 _du_dotdot_du[qp] = _dof_du_dotdot_du[0];
473 if (_need_second_previous_nl)
474 _second_u_previous_nl[qp] = 0.;
478 if (_need_second_old)
479 _second_u_old[qp] = 0.;
481 if (_need_second_older)
482 _second_u_older[qp] = 0.;
491 if (is_transient && _need_curl_old)
492 _curl_u_old[qp] = 0.;
495 for (
auto tag : _required_vector_tags)
496 if (_need_vector_tag_u[tag])
497 _vector_tag_u[tag][qp] = _vector_tags_dof_u[tag][0];
499 for (
auto tag : active_coupleable_matrix_tags)
500 if (_need_matrix_tag_u[tag])
501 _matrix_tag_u[tag][qp] = _matrix_tags_dof_u[tag][0];
506 computeAD(num_dofs, nqp);
509 template <
typename OutputType>
519 std::vector<FVKernel *> ks;
520 _fv_elemental_kernel_query_cache.queryInto(ks);
523 _fv_flux_kernel_query_cache.queryInto(ks);
528 _ad_dof_values.resize(num_dofs);
533 _ad_grad_u.resize(nqp);
535 if (_need_ad_second_u)
536 _ad_second_u.resize(nqp);
540 _ad_dofs_dot.resize(num_dofs);
541 _ad_u_dot.resize(nqp);
544 if (_need_ad_u_dotdot)
546 _ad_dofs_dotdot.resize(num_dofs);
547 _ad_u_dotdot.resize(nqp);
550 if (_need_ad_second_u)
551 assignForAllQps(0, _ad_second_u, nqp);
554 assignForAllQps(_ad_zero, _ad_u_dot, nqp);
556 if (_need_ad_u_dotdot)
557 assignForAllQps(_ad_zero, _ad_u_dotdot, nqp);
559 const bool do_derivatives =
560 ADReal::do_derivatives && _sys.number() == _subproblem.currentNlSysNum();
562 for (
unsigned int i = 0; i < num_dofs; i++)
564 _ad_dof_values[i] = (*_sys.currentSolution())(_dof_indices[i]);
570 if (_need_ad_u_dot && safeToComputeADUDot() && _time_integrator->dt())
572 _ad_dofs_dot[i] = _ad_dof_values[i];
573 _time_integrator->computeADTimeDerivatives(_ad_dofs_dot[i],
575 _need_ad_u_dotdot ? _ad_dofs_dotdot[i]
581 assignForAllQps(_ad_dof_values[0], _ad_u, nqp);
591 if (safeToComputeADUDot())
593 assignForAllQps(_ad_dofs_dot[0], _ad_u_dot, nqp);
594 if (_need_ad_u_dotdot)
595 assignForAllQps(_ad_dofs_dotdot[0], _ad_u_dotdot, nqp);
599 assignForAllQps(_u_dot[0], _ad_u_dot, nqp);
600 if (_need_ad_u_dotdot)
601 assignForAllQps(_u_dotdot[0], _ad_u_dotdot, nqp);
606 template <
typename OutputType>
610 mooseAssert(index == 0,
"We only ever have one dof value locally");
611 _vector_tags_dof_u[_solution_tag][index] =
value;
612 _has_dof_values =
true;
614 auto & u = _vector_tag_u[_solution_tag];
624 template <
typename OutputType>
628 auto & dof_values = _vector_tags_dof_u[_solution_tag];
629 for (
unsigned int i = 0; i < values.size(); i++)
630 dof_values[i] = values(i);
631 _has_dof_values =
true;
634 template <
typename OutputType>
638 unsigned int idx)
const 640 std::vector<dof_id_type> dof_indices;
641 _dof_map.dof_indices(elem, dof_indices, _var_num);
646 return (*_sys.currentSolution())(dof_indices[
idx]);
649 return _sys.solutionOld()(dof_indices[
idx]);
652 return _sys.solutionOlder()(dof_indices[
idx]);
655 mooseError(
"PreviousNL not currently supported for getElementalValue");
659 template <
typename OutputType>
662 std::vector<dof_id_type> & dof_indices)
const 664 _dof_map.dof_indices(elem, dof_indices, _var_num);
667 template <
typename OutputType>
671 if (_sys.solutionUDot())
673 _need_dof_values_dot =
true;
674 return _dof_values_dot;
678 "MooseVariableDataFV: Time derivative of solution (`u_dot`) is not stored. Please set " 679 "uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
682 template <
typename OutputType>
686 if (_sys.solutionUDotDot())
688 _need_dof_values_dotdot =
true;
689 return _dof_values_dotdot;
693 "MooseVariableDataFV: Second time derivative of solution (`u_dotdot`) is not stored. " 694 "Please set uDotDotRequested() to true in FEProblemBase before requesting " 698 template <
typename OutputType>
702 if (_sys.solutionUDotOld())
704 _need_dof_values_dot_old =
true;
705 return _dof_values_dot_old;
708 mooseError(
"MooseVariableDataFV: Old time derivative of solution (`u_dot_old`) is not stored. " 709 "Please set uDotOldRequested() to true in FEProblemBase before requesting " 713 template <
typename OutputType>
717 if (_sys.solutionUDotDotOld())
719 _need_dof_values_dotdot_old =
true;
720 return _dof_values_dotdot_old;
724 "MooseVariableDataFV: Old second time derivative of solution (`u_dotdot_old`) is not " 725 "stored. Please set uDotDotOldRequested() to true in FEProblemBase before " 726 "requesting `u_dotdot_old`.");
729 template <
typename OutputType>
733 _need_dof_du_dot_du =
true;
734 return _dof_du_dot_du;
737 template <
typename OutputType>
741 _need_dof_du_dotdot_du =
true;
742 return _dof_du_dotdot_du;
745 template <
typename OutputType>
749 auto n = _dof_indices.size();
751 _ad_dof_values.resize(n);
753 const bool do_derivatives =
754 ADReal::do_derivatives && _sys.number() == _subproblem.currentNlSysNum();
756 for (decltype(n) i = 0; i < n; ++i)
758 _ad_dof_values[i] = _vector_tags_dof_u[_solution_tag][i];
764 template <
typename OutputType>
770 _vector_tags_dof_u[_solution_tag].resize(_dof_indices.size());
772 mooseAssert(_qrule,
"We should have a non-null qrule");
773 const auto nqp = _qrule->n_points();
774 _vector_tag_u[_solution_tag].resize(nqp);
777 template <
typename OutputType>
781 _prev_elem =
nullptr;
void initDofIndices(T &data, const Elem &elem)
Moose::DOFType< OutputType >::type OutputData
const std::vector< dof_id_type > & initDofIndices()
const FieldVariableValue & uDotOld() const
const FieldVariableValue & uDot() const
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void setDofValue(const OutputData &value, unsigned int index)
dof value setters
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 SubProblem & _subproblem
The subproblem which we can query for information related to tagged vectors and matrices.
Base class for a system (of equations)
void fetchADDoFValues()
Helper methods for assigning nodal values from their corresponding solution values (dof values as the...
TheWarehouse::QueryCache _fv_flux_kernel_query_cache
Cached warehouse query for FVFluxKernels.
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
void getDofIndices(const Elem *elem, std::vector< dof_id_type > &dof_indices) const
const DoFValue & dofValuesDotDot() const
This data structure is used to store geometric and variable related metadata about each cell face in ...
const FieldVariableValue & sln(Moose::SolutionState state) const
Local solution value.
Interface for notifications that the mesh has changed.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void setDofValues(const DenseVector< OutputData > &values)
Set local DOF values and evaluate the values on quadrature points.
void initializeSolnVars()
void prepareIC()
prepare the initial condition
const FieldVariableValue & uDotDot() const
const DoFValue & dofValuesDot() const
const DoFValue & dofValuesDotOld() const
const MooseArray< libMesh::Number > & dofValuesDuDotDotDu() const
const DoFValue & dofValuesDotDotOld() const
void computeValues()
compute the variable values
Moose::DOFType< OutputType >::type OutputData
void meshChanged() override
Called on this object when the mesh changes.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse...
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)
IntRange< T > make_range(T beg, T end)
OutputData getElementalValue(const Elem *elem, Moose::SolutionState state, unsigned int idx=0) const
const FieldVariableValue & sln(Moose::SolutionState state) const
Local solution getter.
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N >> &derivs, libMesh::dof_id_type index, Real value)
TheWarehouse & theWarehouse()
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
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 FieldVariableSecond & secondSln(Moose::SolutionState state) const
Local solution second spatial derivative getter.
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.
auto index_range(const T &sizable)
const FieldVariableGradient & gradSlnDotDot() const
Local second time derivative of solution gradient getter.
TheWarehouse::QueryCache _fv_elemental_kernel_query_cache
Cached warehouse query for FVElementalKernels.