27 #include "libmesh/numeric_vector.h" 32 using namespace Moose;
36 template <
typename OutputType>
41 params.
set<
bool>(
"fv") =
true;
47 template <
typename OutputType>
50 _needs_cell_gradients(false),
51 _grad_container(this->_sys.gradientContainer()),
52 _sys_num(this->_sys.number()),
53 _solution(this->_sys.currentSolution()),
62 _grad_phi_face_neighbor(
68 if (!dynamic_cast<LinearSystem *>(&
_sys) && !dynamic_cast<AuxiliarySystem *>(&
_sys))
70 "The assigned system is not a linear or an auxiliary system! Linear variables " 71 "can only be assigned to linear or auxiliary systems!");
72 _element_data = std::make_unique<MooseVariableDataLinearFV<OutputType>>(
74 _neighbor_data = std::make_unique<MooseVariableDataLinearFV<OutputType>>(
78 mooseError(
"MooseLinearVariableFV does not support threading at the moment!");
81 template <
typename OutputType>
90 template <
typename OutputType>
97 "The variable should be defined on the element's subdomain! This typically occurs when the " 98 "user wants to evaluate the elements right next to the boundary of two variables (block " 99 "boundary). The subdomain which is queried: " +
100 Moose::stringify(this->activeSubdomains()) +
" the subdomain of the element " +
107 const auto & global_soln = (state.
state == 0)
108 ? *this->_sys.currentSolution()
111 return global_soln(elem_info.
dofIndices()[this->_sys_num][this->_var_num]);
114 template <
typename OutputType>
118 if (_needs_cell_gradients)
120 _cell_gradient.zero();
121 for (
const auto i :
make_range(this->_mesh.dimension()))
123 (*_grad_container[i])(elem_info.
dofIndices()[this->_sys_num][this->_var_num]);
126 return _cell_gradient;
129 template <
typename OutputType>
133 const bool var_defined_on_elem = this->hasBlocks(fi.
elem().subdomain_id());
137 const auto elem_one_grad = gradSln(*elem_one);
140 if (elem_two && this->hasBlocks(elem_two->subdomain_id()))
142 const auto elem_two_grad = gradSln(*elem_two);
146 return elem_one_grad;
149 template <
typename OutputType>
154 cacheBoundaryBCMap();
157 template <
typename OutputType>
163 mooseAssert(fi,
"The face information must be non-null");
165 const auto face_type = fi->
faceType(std::make_pair(this->_var_num, this->_sys_num));
169 else if (
auto * bc_pointer = this->getBoundaryCondition(*fi->
boundaryIDs().begin()))
171 mooseAssert(fi->
boundaryIDs().size() == 1,
"We should only have one boundary on every face.");
172 bc_pointer->setupFaceData(fi, face_type);
173 return bc_pointer->computeBoundaryValue();
179 const auto & elem_info = this->_mesh.elemInfo(fi->
elemPtr()->id());
180 return getElemValue(elem_info, state);
184 const auto & elem_info = this->_mesh.elemInfo(fi->
neighborPtr()->id());
185 return getElemValue(elem_info, state);
191 template <
typename OutputType>
199 template <
typename OutputType>
203 timeIntegratorError();
214 template <
typename OutputType>
218 _boundary_id_to_bc.clear();
219 std::vector<LinearFVBoundaryCondition *> bcs;
225 auto base_query = this->_subproblem.getMooseApp()
228 .template condition<AttribSystem>(
"LinearFVBoundaryCondition")
229 .
template condition<AttribThread>(_tid)
230 .template condition<AttribVar>(_var_num)
231 .
template condition<AttribSysNum>(this->_sys.number());
233 for (
const auto bnd_id : this->_mesh.getBoundaryIDs())
235 auto base_query_copy = base_query;
236 base_query_copy.template condition<AttribBoundaries>(std::set<BoundaryID>({bnd_id}))
238 mooseAssert(bcs.size() <= 1,
"cannot have multiple BCs on the same boundary");
240 _boundary_id_to_bc.emplace(bnd_id, bcs[0]);
244 template <
typename OutputType>
248 const auto iter = _boundary_id_to_bc.find(bd_id);
249 if (iter == _boundary_id_to_bc.end())
255 template <
typename OutputType>
259 return this->_assembly.elem();
262 template <
typename OutputType>
267 if (
auto it = _boundary_id_to_bc.find(bnd_id); it != _boundary_id_to_bc.end())
268 if (dynamic_cast<LinearFVAdvectionDiffusionFunctorDirichletBC *>(it->second))
281 template <
typename OutputType>
284 std::vector<dof_id_type> & dof_indices)
const 287 const auto & elem_info = this->_mesh.elemInfo(elem->id());
288 dof_indices.push_back(elem_info.dofIndices()[this->_sys_num][this->number()]);
291 template <
typename OutputType>
295 _element_data->setDofValue(
value, index);
298 template <
typename OutputType>
302 _element_data->setDofValues(values);
305 template <
typename OutputType>
309 _element_data->clearDofIndices();
312 template <
typename OutputType>
316 return _element_data->dofValues();
319 template <
typename OutputType>
323 return _neighbor_data->dofValues();
326 template <
typename OutputType>
330 return _element_data->dofValuesOld();
333 template <
typename OutputType>
337 return _element_data->dofValuesOlder();
340 template <
typename OutputType>
344 return _element_data->dofValuesPreviousNL();
347 template <
typename OutputType>
351 return _neighbor_data->dofValuesOld();
354 template <
typename OutputType>
358 return _neighbor_data->dofValuesOlder();
361 template <
typename OutputType>
365 return _neighbor_data->dofValuesPreviousNL();
368 template <
typename OutputType>
372 timeIntegratorError();
375 template <
typename OutputType>
379 timeIntegratorError();
382 template <
typename OutputType>
386 timeIntegratorError();
389 template <
typename OutputType>
393 timeIntegratorError();
396 template <
typename OutputType>
400 timeIntegratorError();
403 template <
typename OutputType>
407 timeIntegratorError();
410 template <
typename OutputType>
414 timeIntegratorError();
417 template <
typename OutputType>
421 timeIntegratorError();
424 template <
typename OutputType>
428 timeIntegratorError();
431 template <
typename OutputType>
435 timeIntegratorError();
438 template <
typename OutputType>
442 timeIntegratorError();
445 template <
typename OutputType>
449 timeIntegratorError();
452 template <
typename OutputType>
457 _element_data->computeValues();
460 template <
typename OutputType>
465 _element_data->computeValues();
468 template <
typename OutputType>
473 _neighbor_data->computeValues();
476 template <
typename OutputType>
481 _neighbor_data->computeValues();
484 template <
typename OutputType>
491 template <
typename OutputType>
498 template <
typename OutputType>
505 template <
typename OutputType>
506 const std::vector<dof_id_type> &
509 return _element_data->dofIndices();
512 template <
typename OutputType>
513 const std::vector<dof_id_type> &
516 return _neighbor_data->dofIndices();
519 template <
typename OutputType>
526 template <
typename OutputType>
530 unsigned int state = 0;
531 state =
std::max(state, _element_data->oldestSolutionStateRequested());
532 state =
std::max(state, _neighbor_data->oldestSolutionStateRequested());
536 template <
typename OutputType>
540 _element_data->clearDofIndices();
541 _neighbor_data->clearDofIndices();
544 template <
typename OutputType>
551 template <
typename OutputType>
558 template <
typename OutputType>
565 template <
typename OutputType>
566 const std::vector<dof_id_type> &
572 template <
typename OutputType>
579 template <
typename OutputType>
583 _element_data->insert(vector);
586 template <
typename OutputType>
590 mooseError(
"We don't support value insertion to residuals in MooseLinearVariableFV!");
593 template <
typename OutputType>
597 mooseError(
"We don't support value addition to residuals in MooseLinearVariableFV!");
600 template <
typename OutputType>
604 _element_data->setActiveTags(vtags);
605 _neighbor_data->setActiveTags(vtags);
608 template <
typename OutputType>
615 template <
typename OutputType>
622 template <
typename OutputType>
629 template <
typename OutputType>
636 template <
typename OutputType>
640 return _element_data->vectorTagValue(tag);
643 template <
typename OutputType>
647 return _element_data->vectorTagDofValue(tag);
650 template <
typename OutputType>
654 return _element_data->matrixTagValue(tag);
657 template <
typename OutputType>
661 mooseError(
"We don't currently implement second derivatives for FV");
664 template <
typename OutputType>
668 mooseError(
"We don't currently implement curl for FV");
671 template <
typename OutputType>
675 mooseError(
"We don't currently implement divergence for FV");
678 template <
typename OutputType>
682 mooseError(
"We don't currently implement second derivatives for FV");
685 template <
typename OutputType>
689 mooseError(
"We don't currently implement second derivatives for FV");
692 template <
typename OutputType>
696 mooseError(
"We don't currently implement second derivatives for FV");
699 template <
typename OutputType>
706 template <
typename OutputType>
713 template <
typename OutputType>
720 template <
typename OutputType>
727 template <
typename OutputType>
734 template <
typename OutputType>
741 template <
typename OutputType>
748 template <
typename OutputType>
755 template <
typename OutputType>
762 template <
typename OutputType>
769 template <
typename OutputType>
776 template <
typename OutputType>
783 template <
typename OutputType>
790 template <
typename OutputType>
797 template <
typename OutputType>
804 template <
typename OutputType>
811 template <
typename OutputType>
818 template <
typename OutputType>
825 template <
typename OutputType>
832 template <
typename OutputType>
839 template <
typename OutputType>
846 template <
typename OutputType>
853 template <
typename OutputType>
860 template <
typename OutputType>
867 template <
typename OutputType>
874 template <
typename OutputType>
881 template <
typename OutputType>
888 template <
typename OutputType>
895 template <
typename OutputType>
899 _element_data->sizeMatrixTagData();
virtual const DoFValue & vectorTagDofValue(TagID tag) const override
virtual void clearAllDofIndices() override final
typename OutputTools< typename Moose::ADType< T >::type >::VariableSecond ADTemplateVariableSecond
const Elem *const & elem() const
Return the current element.
virtual const MooseArray< libMesh::Number > & dofValuesDuDotDotDuNeighbor() const override
virtual void setActiveTags(const std::set< TagID > &vtags) override
Set the active vector tags.
typename OutputTools< typename Moose::ADType< T >::type >::VariableCurl ADTemplateVariableCurl
virtual bool isExtrapolatedBoundaryFace(const FaceInfo &fi, const Elem *elem, const Moose::StateArg &state) const override
Returns whether this (sided) face is an extrapolated boundary face for this functor.
virtual const DoFValue & dofValuesOldNeighbor() const override
virtual void computeElemValuesFace() override
Compute values at facial quadrature points.
Base class for boundary conditions for linear FV systems.
virtual const MooseArray< OutputType > & nodalValueOlderArray() const override
virtual const ADTemplateVariableCurl< OutputType > & adCurlSln() const override
AD curl solution getter.
const std::set< BoundaryID > & boundaryIDs() const
Const getter for every associated boundary ID.
virtual DotType evaluateDot(const ElemArg &elem, const StateArg &) const override final
Evaluate the functor time derivative with a given element.
virtual const FieldVariableValue & sln() const override
virtual const DoFValue & dofValuesOlder() const override
virtual bool isDirichletBoundaryFace(const FaceInfo &fi) const
If the variable has a dirichlet boundary condition at face described by fi .
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Class for stuff related to variables.
virtual const MooseArray< OutputType > & nodalValueArray() const override
Methods for retrieving values of variables at the nodes in a MooseArray for AuxKernelBase.
virtual const Elem *const & currentElem() const override
Current element this variable is evaluated at.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
virtual void setDofValues(const DenseVector< OutputData > &values) override
Set local DOF values and evaluate the values on quadrature points.
virtual const ADTemplateVariableGradient< OutputType > & adGradSlnDot() const override
AD grad of time derivative solution getter.
virtual const DoFValue & dofValuesDotOld() const override
virtual const FieldVariablePhiSecond & secondPhiFace() const override final
Return the rank-2 tensor of second derivatives of the variable's shape functions on an element face...
typename MooseVariableField< OutputType >::FieldVariablePhiSecond FieldVariablePhiSecond
const Elem & elem() const
const FieldVariablePhiDivergence & divPhi() const override final
Divergence of the shape functions.
virtual const FieldVariablePhiSecond & secondPhiFaceNeighbor() const override final
Return the rank-2 tensor of second derivatives of the variable's shape functions on a neighboring ele...
virtual const ADTemplateVariableValue< OutputType > & adSln() const override
AD solution getter.
virtual const FieldVariableGradient & gradSlnOldNeighbor() const override
virtual const DoFValue & nodalMatrixTagValue(TagID tag) const override
const ElemInfo * neighborInfo() const
virtual const DoFValue & dofValues() const override
dof values getters
registerMooseObject("MooseApp", MooseLinearVariableFVReal)
typename OutputTools< typename Moose::ADType< T >::type >::VariableValue ADTemplateVariableValue
virtual const MooseArray< ADReal > & adDofValues() const override
Return the AD dof values.
virtual void getDofIndices(const Elem *elem, std::vector< dof_id_type > &dof_indices) const override
virtual const DoFValue & dofValuesPreviousNL() const override
const ElemInfo * elemInfo() const
virtual void setNodalValue(const OutputType &value, unsigned int idx=0) override
LinearFVBoundaryCondition * getBoundaryCondition(const BoundaryID bd_id) const
Get the boundary condition object which corresponds to the given boundary ID.
virtual const std::vector< dof_id_type > & dofIndicesNeighbor() const final
Get neighbor DOF indices for currently selected element.
virtual const DoFValue & dofValuesDotNeighbor() const override
virtual const FieldVariablePhiSecond & secondPhi() const override final
Return the rank-2 tensor of second derivatives of the variable's elemental shape functions.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
libMesh::CompareTypes< T, T2 >::supertype linearInterpolation(const T &value1, const T2 &value2, const FaceInfo &fi, const bool one_is_elem, const InterpMethod interp_method=InterpMethod::Average)
A simple linear interpolation of values between cell centers to a cell face.
DualNumber< Real, DNDerivativeType, true > ADReal
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
virtual void clearDofIndices() override
Clear out the dof indices.
virtual const std::vector< dof_id_type > & dofIndices() const final
Get local DoF indices.
virtual void computeElemValues() override
Compute values at interior quadrature points.
auto max(const L &left, const R &right)
virtual const ADTemplateVariableCurl< OutputType > & adCurlSlnNeighbor() const override
AD curl neighbor solution getter.
Moose::DOFType< Real >::type OutputData
static InputParameters validParams()
virtual const MooseArray< libMesh::Number > & dofValuesDuDotDuNeighbor() const override
virtual const FieldVariablePhiSecond & secondPhiNeighbor() const override final
Return the rank-2 tensor of second derivatives of the variable's shape functions on a neighboring ele...
virtual const ADTemplateVariableValue< OutputType > & adUDotDot() const override
AD second time derivative getter.
virtual const ADTemplateVariableGradient< OutputType > & adGradSlnNeighbor() const override
AD grad neighbor solution getter.
This data structure is used to store geometric and variable related metadata about each cell face in ...
virtual const FieldVariableValue & slnOld() const override
typename MooseVariableField< OutputType >::FieldVariablePhiValue FieldVariablePhiValue
const Elem * neighborPtr() const
void timeIntegratorError() const
Throw an error when somebody requests time-related data from this variable.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
A structure defining a "face" evaluation calling argument for Moose functors.
virtual const MooseArray< ADReal > & adDofValuesNeighbor() const override
Return the AD neighbor dof values.
virtual void insertLower(libMesh::NumericVector< libMesh::Number > &vector) override
Insert the currently cached degree of freedom values for a lower-dimensional element into the provide...
const FaceInfo * fi
a face information object which defines our location in space
virtual const FieldVariablePhiValue & phiLower() const override
Return the variable's shape functions on a lower-dimensional element.
SystemBase & _sys
System this variable is part of.
SolutionIterationType iteration_type
The solution iteration type, e.g. time or nonlinear.
boundary_id_type BoundaryID
virtual const FieldVariableValue & matrixTagValue(TagID tag) const override
typename OutputTools< typename Moose::ADType< T >::type >::VariableGradient ADTemplateVariableGradient
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
std::unique_ptr< MooseVariableDataLinearFV< OutputType > > _element_data
Holder for all the data associated with the "main" element.
virtual const ADTemplateVariableGradient< OutputType > & adGradSlnNeighborDot() const override
AD grad of time derivative neighbor solution getter.
A structure that is used to evaluate Moose functors logically at an element/cell center.
typename MooseVariableField< OutputType >::FieldVariableGradient FieldVariableGradient
MooseLinearVariableFV(const InputParameters ¶meters)
virtual const dof_id_type & nodalDofIndex() const override final
virtual const MooseArray< libMesh::Number > & dofValuesDuDotDu() const override
virtual const ADTemplateVariableSecond< OutputType > & adSecondSln() const override
AD second solution getter.
const FieldVariablePhiValue & curlPhi() const override final
Curl of the shape functions.
virtual const DoFValue & dofValuesDotDotNeighbor() const override
std::string stringify(const T &t)
conversion to string
virtual void setDofValue(const OutputData &, unsigned int) override
Degree of freedom value setters.
virtual const std::vector< dof_id_type > & dofIndicesLower() const override final
Get dof indices for the current lower dimensional element (this is meaningful when performing mortar ...
virtual const FieldVariableValue & slnNeighbor() const override
virtual const FieldVariableGradient & gradSlnNeighbor() const override
neighbor solution gradients
virtual const FieldVariableGradient & gradSlnOld() const override
const Elem * elemPtr() const
virtual const MooseArray< OutputType > & nodalValueOldArray() const override
virtual const DoFValue & dofValuesOlderNeighbor() const override
const std::vector< std::vector< dof_id_type > > & dofIndices() const
virtual const DoFValue & dofValuesDotDotOldNeighbor() const override
virtual void computeNodalNeighborValues() override final
Compute nodal values of this variable in the neighbor.
virtual void add(libMesh::NumericVector< libMesh::Number > &vector) override
Add the currently cached degree of freedom values into the provided vector.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void computeNeighborValuesFace() override
Compute values at facial quadrature points for the neighbor.
virtual const DoFValue & dofValuesNeighbor() const override
virtual const FieldVariableValue & vectorTagValue(TagID tag) const override
tag values getters
Assembly & _assembly
Assembly data.
virtual void sizeMatrixTagData() override
Size data structures related to matrix tagging.
std::unique_ptr< MooseVariableDataLinearFV< OutputType > > _neighbor_data
Holder for all the data associated with the "neighbor" element.
Moose::ADType< OutputType >::type ValueType
virtual void computeNodalValues() override final
Compute nodal values of this variable.
virtual void setLowerDofValues(const DenseVector< OutputData > &values) override
Set local DOF values for a lower dimensional element and evaluate the values on quadrature points...
static InputParameters validParams()
virtual const DoFValue & dofValuesOld() const override
virtual const dof_id_type & nodalDofIndexNeighbor() const override final
typename MooseVariableField< OutputType >::FieldVariablePhiDivergence FieldVariablePhiDivergence
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
Get the solution value for the provided element and seed the derivative for the corresponding dof ind...
virtual void computeLowerDValues() override final
compute values at quadrature points on the lower dimensional element
void cacheBoundaryBCMap()
Setup the boundary to Dirichlet BC map.
const Elem *const & neighbor() const
Return the neighbor element.
virtual std::size_t phiLowerSize() const override final
Return the number of shape functions on the lower dimensional element for this variable.
virtual const DoFValue & dofValuesDot() const override
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
typename MooseVariableField< OutputType >::FieldVariableValue FieldVariableValue
virtual const DoFValue & dofValuesPreviousNLNeighbor() const override
virtual const DoFValue & dofValuesDotOldNeighbor() const override
virtual void insert(libMesh::NumericVector< libMesh::Number > &vector) override
Insert the currently cached degree of freedom values into the provided vector.
virtual const ADTemplateVariableValue< OutputType > & adUDotNeighbor() const override
AD neighbor time derivative getter.
State argument for evaluating functors.
virtual const OutputTools< T >::VariableSecond & second()
The second derivative of the variable this object is operating on.
virtual const ADTemplateVariableValue< OutputType > & adSlnNeighbor() const override
AD neighbor solution getter.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual const DoFValue & dofValuesDotDot() const override
virtual const ADTemplateVariableSecond< OutputType > & adSecondSlnNeighbor() const override
AD second neighbor solution getter.
virtual void computeNeighborValues() override
Compute values at quadrature points for the neighbor.
Class used for caching additional information for elements such as the volume and centroid...
virtual const MooseArray< libMesh::Number > & dofValuesDuDotDotDu() const override
virtual unsigned int oldestSolutionStateRequested() const override final
The oldest solution state that is requested for this variable (0 = current, 1 = old, 2 = older, etc).
virtual const DoFValue & dofValuesDotDotOld() const override
void interpolate(InterpMethod m, T &result, const T2 &value1, const T3 &value2, const FaceInfo &fi, const bool one_is_elem)
Provides interpolation of face values for non-advection-specific purposes (although it can/will still...
virtual const MooseArray< ADReal > & adDofValuesDot() const override
Return the AD time derivatives at dofs.
typename MooseVariableField< OutputType >::DoFValue DoFValue
virtual const FieldVariableValue & slnOlder() const override
virtual const ADTemplateVariableValue< OutputType > & adUDot() const override
AD time derivative getter.
virtual const FieldVariableGradient & gradSln() const override
element gradients
virtual const ADTemplateVariableGradient< OutputType > & adGradSln() const override
AD grad solution getter.
Moose::ShapeType< Real >::type OutputShape
virtual const DoFValue & nodalVectorTagValue(TagID) const override
SubdomainID subdomain_id() const
We return the subdomain ID of the corresponding libmesh element.
unsigned int state
The state.
virtual const FieldVariableValue & slnOldNeighbor() const override
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const
Returns which side(s) the given variable-system number pair is defined on for this face...
virtual ValueType evaluate(const ElemArg &elem, const StateArg &) const override final
Evaluate the functor with a given element.
virtual const ADTemplateVariableValue< OutputType > & adUDotDotNeighbor() const override
AD neighbor second time derivative getter.