28#include "libmesh/quadrature_gauss.h"
29#include "libmesh/node_range.h"
30#include "libmesh/numeric_vector.h"
31#include "libmesh/default_coupling.h"
32#include "libmesh/string_to_enum.h"
33#include "libmesh/fe_interface.h"
44 _sys(subproblem.es().add_system<System>(
name)),
45 _current_solution(_sys.current_local_solution.
get()),
46 _aux_scalar_storage(_app.getExecuteOnEnum(), numThreads())
47#ifdef MOOSE_KOKKOS_ENABLED
49 _kokkos_nodal_aux_storage(_app.getExecuteOnEnum(), 1),
50 _kokkos_elemental_aux_storage(_app.getExecuteOnEnum(), 1)
53 _nodal_vars.resize(this->numThreads());
54 _elem_vars.resize(this->numThreads());
56 if (!_fe_problem.defaultGhosting())
58 auto & dof_map = _sys.get_dof_map();
59 dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
60 dof_map.set_implicit_neighbor_dofs(
false);
76 TIME_SECTION(
"initialSetup", 3,
"Initializing Auxiliary System");
82 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
92#ifdef MOOSE_KOKKOS_ENABLED
103std::vector<AuxKernelBase *>
106 std::vector<AuxKernelBase *> sorted;
107 std::set<AuxKernelBase *> seen;
119 .condition<AttribThread>(tid)
121 .condition<AttribSorted>(
true)
123 std::vector<AuxKernelBase *> flag_kernels;
126 for (
auto *
const aux : flag_kernels)
127 if (seen.insert(aux).second)
128 sorted.push_back(aux);
135 .condition<AttribThread>(tid)
137 std::vector<AuxKernelBase *> all_kernels;
140 for (
auto *
const aux : all_kernels)
141 if (seen.insert(aux).second)
142 sorted.push_back(aux);
155 const bool skip_current_to_old)
172 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
176 aux->timestepSetup();
179#ifdef MOOSE_KOKKOS_ENABLED
190 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
194 aux->customSetup(exec_type);
197#ifdef MOOSE_KOKKOS_ENABLED
208 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
212 aux->subdomainSetup();
221 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
225 aux->jacobianSetup();
228#ifdef MOOSE_KOKKOS_ENABLED
239 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
243 aux->residualSetup();
246#ifdef MOOSE_KOKKOS_ENABLED
259#ifdef MOOSE_KOKKOS_ENABLED
272 const std::string & name,
279 if (var_type ==
"MooseVariableScalar")
286 auto * var =
_vars[tid].getActualFieldVariable<RealVectorValue>(
name);
289 if (var->feType().family == LAGRANGE_VEC)
304 if (var->feType().family == LAGRANGE)
314 if (avar->feType().family == LAGRANGE)
325 const std::string & name,
330 const auto & base = parameters.
getBase();
331 if (base ==
"AuxKernel" || base ==
"Bounds")
333 std::shared_ptr<AuxKernel> kernel =
338 else if (base ==
"VectorAuxKernel")
340 std::shared_ptr<VectorAuxKernel> kernel =
342 if (kernel->isNodal() && kernel->isMortar())
343 mooseError(
"Vector mortar aux kernels not yet implemented");
347 else if (base ==
"ArrayAuxKernel")
349 std::shared_ptr<ArrayAuxKernel> kernel =
351 if (kernel->isNodal() && kernel->isMortar())
352 mooseError(
"Vector mortar aux kernels not yet implemented");
357 "Attempting to add AuxKernel of type '" + kernel_name +
"' and name '" +
name +
358 "' to the auxiliary system with invalid _moose_base: " + base);
366 const std::string & name,
371 std::shared_ptr<AuxScalarKernel> kernel =
381 var->computeElemValues();
386 var->computeElemValues();
394 var->computeElemValuesFace();
399 var->reinitAuxNeighbor();
400 var->computeElemValuesFace();
436 if (
_vars[0].scalars().size() > 0)
442 ti->computeTimeDerivatives();
445 if (
_vars[0].fieldVariables().size() > 0)
457#ifdef MOOSE_KOKKOS_ENABLED
473 ti->computeTimeDerivatives();
483 std::set<std::string> depend_objects;
487 std::vector<AuxKernel *> auxkernels;
493 .condition<AttribThread>(0)
494 .queryIntoUnsorted(auxkernels);
495 for (
const auto & aux : auxkernels)
497 const std::set<UserObjectName> & uo = aux->getDependObjects();
498 depend_objects.insert(uo.begin(), uo.end());
504 std::vector<VectorAuxKernel *> vec_auxkernels;
510 .condition<AttribThread>(0)
511 .queryIntoUnsorted(vec_auxkernels);
512 for (
const auto & aux : vec_auxkernels)
514 const std::set<UserObjectName> & uo = aux->getDependObjects();
515 depend_objects.insert(uo.begin(), uo.end());
521 std::vector<ArrayAuxKernel *> array_auxkernels;
527 .condition<AttribThread>(0)
528 .queryIntoUnsorted(array_auxkernels);
529 for (
const auto & aux : array_auxkernels)
531 const std::set<UserObjectName> & uo = aux->getDependObjects();
532 depend_objects.insert(uo.begin(), uo.end());
536#ifdef MOOSE_KOKKOS_ENABLED
539 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
541 for (
const auto & aux : auxs)
543 const std::set<UserObjectName> & uo = aux->getDependObjects();
544 depend_objects.insert(uo.begin(), uo.end());
550 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
552 for (
const auto & aux : auxs)
554 const std::set<UserObjectName> & uo = aux->getDependObjects();
555 depend_objects.insert(uo.begin(), uo.end());
560 return depend_objects;
566 std::set<std::string> depend_objects;
570 std::vector<AuxKernel *> auxkernels;
576 .queryIntoUnsorted(auxkernels);
577 for (
const auto & aux : auxkernels)
579 const std::set<UserObjectName> & uo = aux->getDependObjects();
580 depend_objects.insert(uo.begin(), uo.end());
586 std::vector<VectorAuxKernel *> vec_auxkernels;
592 .queryIntoUnsorted(vec_auxkernels);
593 for (
const auto & aux : vec_auxkernels)
595 const std::set<UserObjectName> & uo = aux->getDependObjects();
596 depend_objects.insert(uo.begin(), uo.end());
602 std::vector<ArrayAuxKernel *> array_auxkernels;
608 .queryIntoUnsorted(array_auxkernels);
609 for (
const auto & aux : array_auxkernels)
611 const std::set<UserObjectName> & uo = aux->getDependObjects();
612 depend_objects.insert(uo.begin(), uo.end());
616#ifdef MOOSE_KOKKOS_ENABLED
619 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
621 for (
const auto & aux : auxs)
623 const std::set<UserObjectName> & uo = aux->getDependObjects();
624 depend_objects.insert(uo.begin(), uo.end());
630 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
632 for (
const auto & aux : auxs)
634 const std::set<UserObjectName> & uo = aux->getDependObjects();
635 depend_objects.insert(uo.begin(), uo.end());
640 return depend_objects;
647 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.
getActiveObjects(0);
649 std::set<TagID> needed_sc_var_matrix_tags;
650 std::set<TagID> needed_sc_var_vector_tags;
651 for (
const auto & obj : objects)
653 auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
654 needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
656 auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
657 needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
681 TIME_SECTION(
"computeScalarVars", 1);
691 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
695 for (
const auto & obj : objects)
699 for (
const auto & var : scalar_vars)
715 TIME_SECTION(
"computeNodalVars", 3);
723 .condition<AttribExecutionOrderGroup>(group);
724 computeNodalVarsHelper<AuxKernel>(
query);
730 TIME_SECTION(
"computeNodalVecVars", 3);
738 .condition<AttribExecutionOrderGroup>(group);
739 computeNodalVarsHelper<VectorAuxKernel>(
query);
745 TIME_SECTION(
"computeNodalArrayVars", 3);
753 .condition<AttribExecutionOrderGroup>(group);
754 computeNodalVarsHelper<ArrayAuxKernel>(
query);
760 TIME_SECTION(
"computeMortarNodalVars", 3);
768 .condition<AttribExecutionOrderGroup>(group);
774 std::vector<AuxKernel *> mortar_nodal_auxs;
777 if (mortar_nodal_auxs.empty())
780 std::map<BoundaryID, std::size_t> num_kernels_by_boundary;
781 for (
auto * aux : mortar_nodal_auxs)
782 for (
const auto bnd_id : aux->boundaryIDs())
783 ++num_kernels_by_boundary[bnd_id];
786 for (
const auto & [bnd_id, num_kernels] : num_kernels_by_boundary)
787 for (
const auto index : make_range(num_kernels))
799 "Auxiliary variable computation:\n" +
800 std::string(e.
what()));
802 catch (MetaPhysicL::LogicError & e)
806 catch (std::exception & e)
810 if (!strstr(e.
what(),
"Jacobian") && !strstr(e.
what(),
"singular") &&
811 !strstr(e.
what(),
"det != 0"))
815 "nodal Auxiliary variable computation:\n" +
816 std::string(e.
what()));
831 TIME_SECTION(
"computeElementalVars", 3);
839 .condition<AttribExecutionOrderGroup>(group);
840 computeElementalVarsHelper<AuxKernel>(
query);
846 TIME_SECTION(
"computeElementalVecVars", 3);
854 .condition<AttribExecutionOrderGroup>(group);
855 computeElementalVarsHelper<VectorAuxKernel>(
query);
867 .condition<AttribExecutionOrderGroup>(group);
868 computeElementalVarsHelper<ArrayAuxKernel>(
query);
873 std::vector<dof_id_type> & ,
874 std::vector<dof_id_type> &
882 Order order = CONSTANT;
883 std::vector<MooseVariableFEBase *>
vars =
_vars[0].fieldVariables();
884 for (
const auto & var :
vars)
888 FEType fe_type = var->feType();
889 if (fe_type.default_quadrature_order() > order)
890 order = fe_type.default_quadrature_order();
900 std::vector<AuxKernel *> elem_auxkernels;
906 .condition<AttribBoundaries>(bnd_id,
true)
907 .queryIntoUnsorted(elem_auxkernels);
908 if (!elem_auxkernels.empty())
911 std::vector<VectorAuxKernel *> elem_vec_auxkernels;
917 .condition<AttribBoundaries>(bnd_id,
true)
918 .queryIntoUnsorted(elem_vec_auxkernels);
919 return !elem_vec_auxkernels.empty();
929template <
typename AuxKernelType>
942 std::vector<AuxKernelType *> block_auxs;
945 if (block_auxs.size())
958 "Auxiliary variable computation:\n" +
959 std::string(e.
what()));
971 std::vector<AuxKernelType *> boundary_auxs;
975 .queryIntoUnsorted(boundary_auxs);
977 if (boundary_auxs.size())
979 TIME_SECTION(
"computeElementalVecVars", 3);
992 "elemental Auxiliary variable computation:\n" +
993 std::string(e.
what()));
1005template <
typename AuxKernelType>
1018 std::vector<AuxKernelType *> block_auxs;
1021 if (block_auxs.size())
1036 std::vector<AuxKernelType *> boundary_auxs;
1040 .queryIntoUnsorted(boundary_auxs);
1042 if (boundary_auxs.size())
1044 TIME_SECTION(
"computeBoundaryObjects", 3);
1061 std::vector<Number> & rel_diff_norms)
const
1067 for (
const auto n : make_range(
nVariables()))
1070 std::vector<dof_id_type> local_indices_n;
1072 Number diff_norm_n = 0;
1075 for (
const auto local_index : local_indices_n)
1077 const Number & value =
solution()(local_index);
1078 const Number & value_old =
solutionOld()(local_index);
1079 diff_norm_n += Utility::pow<2, Number>(value - value_old);
1080 norm_n += Utility::pow<2, Number>(value);
1085 diff_norm_n = sqrt(diff_norm_n);
1086 norm_n = sqrt(norm_n);
1087 rel_diff_norms[n] = diff_norm_n > 0 ? diff_norm_n / norm_n : 0.0;
1091template void AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(
const TheWarehouse::Query &);
1094template void AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(
const TheWarehouse::Query &);
1095template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
const TheWarehouse::Query &);
@ Nodal
Execution categories.
boundary_id_type BoundaryID
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
AttribBoundaries tracks all boundary IDs associated with an object.
@ UnrestrictedOnly
Only objects that are not boundary restricted, whatever the query boundaries.
@ RestrictedOnly
Only objects restricted to one of the query boundaries.
static const ExecFlagType EXEC_ALL
Execute flag that is used to represent all flags when querying AttribExecOns.
Base class for making kernels that work on auxiliary scalar variables.
virtual void copyCurrentIntoPreviousNL()
Copies the current solution into the previous nonlinear iteration solution.
bool needMaterialOnSide(BoundaryID bnd_id)
Indicated whether this system needs material properties on boundaries.
virtual void jacobianSetup() override
void computeElementalVars(ExecFlagType type, int group)
virtual void residualSetup() override
void computeScalarVars(ExecFlagType type)
void addKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds an auxiliary kernel.
void clearScalarVariableCoupleableTags()
virtual void compute(ExecFlagType type) override
Compute auxiliary variables.
virtual void copyAdditionalStateBackwards(Moose::SolutionIterationType iteration_type, bool skip_current_to_old) override
Copy system-owned state not represented by solution vectors.
const NumericVector< Number > * _current_solution
solution vector from nonlinear solver
virtual void subdomainSetup() override
ExecuteMooseObjectWarehouse< AuxKernelBase > _kokkos_elemental_aux_storage
virtual libMesh::Order getMinQuadratureOrder() override
Get the minimum quadrature order for evaluating elemental auxiliary variables.
virtual void initSolutionState() override
Initializes the solution state.
std::vector< AuxKernelBase * > sortedAuxKernels(THREAD_ID tid, bool active_only)
Get every AuxKernel, of any value type, on a thread, in dependency order.
void variableWiseRelativeSolutionDifferenceNorm(std::vector< Number > &var_diffs) const
Computes and stores ||current - old|| / ||current|| for each variable in the given vector.
void setScalarVariableCoupleableTags(ExecFlagType type)
std::set< std::string > getDependObjects()
virtual void customSetup(const ExecFlagType &exec_type) override
void computeNodalVecVars(ExecFlagType type, int group)
void computeElementalVecVars(ExecFlagType type, int group)
void computeMortarNodalVars(ExecFlagType type, int group)
void buildKokkosAuxStages()
Group the active Kokkos auxiliary kernels of each execution flag into stages that can each be compute...
virtual void restoreAdditionalStates() override
Restore system-owned state not represented by solution vectors.
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a scalar kernel.
AuxiliarySystem(FEProblemBase &subproblem, const std::string &name)
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
Reinit an element assembly info.
virtual ~AuxiliarySystem()
std::set< int > _execution_order_groups
Execution order groups present within the simulation.
virtual void addVariable(const std::string &var_type, const std::string &name, InputParameters ¶meters) override
Canonical method for adding a variable.
ExecuteMooseObjectWarehouse< AuxKernelBase > _kokkos_nodal_aux_storage
const NumericVector< Number > *const & currentSolution() const override
The solution vector that is currently being operated on.
virtual void updateActive(THREAD_ID tid)
virtual void augmentSparsity(libMesh::SparsityPattern::Graph &, std::vector< dof_id_type > &, std::vector< dof_id_type > &) override
Will modify the sparsity pattern to add logical geometric connections.
std::vector< std::vector< MooseVariableFieldBase * > > _elem_vars
Elemental variables.
void computeNodalVarsHelper(const TheWarehouse::Query &query)
std::vector< std::vector< MooseVariableFEBase * > > _nodal_vars
virtual void serializeSolution()
void computeNodalVars(ExecFlagType type, int group)
ExecuteMooseObjectWarehouse< AuxScalarKernel > _aux_scalar_storage
virtual void reinitElemFace(const Elem *elem, unsigned int side, THREAD_ID tid) override
Reinit assembly info for a side of an element.
void computeElementalArrayVars(ExecFlagType type, int group)
virtual void timestepSetup() override
virtual void initialSetup() override
Setup Functions.
virtual void reinit() override
Reinitialize the system when the degrees of freedom in this system have changed.
void kokkosCompute(ExecFlagType type, int group)
void computeElementalVarsHelper(const TheWarehouse::Query &query)
void computeNodalArrayVars(ExecFlagType type, int group)
This class evaluates a single mortar nodal aux kernel.
const std::set< ExecFlagType > & items() const
Reference the all the available items.
void jacobianSetup(THREAD_ID tid=0) const override
Convenience methods for calling object setup methods.
void updateActive(THREAD_ID tid=0) override
Updates the active objects storage.
void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
void residualSetup(THREAD_ID tid=0) const override
void sort(THREAD_ID tid=0)
Performs a sort using the DependencyResolver.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void setActiveScalarVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
virtual void reinitScalars(const THREAD_ID tid, bool reinit_for_derivative_reordering=false) override
fills the VariableValue arrays for scalar variables from the solution vector
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class,...
virtual Real & dt() const
virtual void setActiveScalarVariableCoupleableMatrixTags(std::set< TagID > &mtags, const THREAD_ID tid) override
virtual void clearActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid) override
TheWarehouse & theWarehouse() const
virtual void clearActiveScalarVariableCoupleableVectorTags(const THREAD_ID tid) override
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
Registration, update, and allocation logic for linear finite-volume cell gradients.
void computeGradients()
Compute and finalize all registered linear FV gradient fields.
void rebuildLinearFVGradientStorage()
Rebuild cached gradient values and reusable scratch storage after mesh/DOF changes.
void copyPreviousGradientStates(Moose::SolutionIterationType iteration_type, bool skip_current_to_old)
Copy published gradient values into requested older states.
bool hasLinearFVGradients() const
Whether any linear finite-volume gradient fields have been registered to this object.
void restoreGradientStates()
Restore current gradients from state one after a failed timestep.
void initializeLinearFVGradientHistoryStorage()
Register named system vectors for requested historical gradient states.
void initializeLinearFVGradientStorage()
Initialize private current and replacement gradient storage.
const ExecFlagEnum & getExecuteOnEnum() const
Return the app level ExecFlagEnum, this contains all the available flags for the app.
Class for containing MooseEnum item information.
Provides a way for users to bail out of the current solve.
virtual const char * what() const
Get out the error message.
libMesh::ConstNodeRange * getLocalNodeRange()
libMesh::StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
const libMesh::ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems,...
libMesh::StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement * > * getBoundaryElementRange()
bool hasActiveObjects(THREAD_ID tid=0) const
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread.
A storage container for MooseObjects that inherit from SetupInterface.
virtual void timestepSetup(THREAD_ID tid=0) const
virtual void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
Class for stuff related to variables.
Interface for objects interacting with the PerfGraph.
Base class for a system (of equations)
std::unique_ptr< NumericVector< Number > > _serialized_solution
Serialized version of the solution vector, or nullptr if a serialized solution is not needed.
FEProblemBase & _fe_problem
the governing finite element/volume problem
virtual void subdomainSetup()
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
virtual unsigned int nVariables() const
Get the number of variables in this system.
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶meters)
Canonical method for adding a variable.
virtual void customSetup(const ExecFlagType &exec_type)
NumericVector< Number > & solutionOld()
virtual void initialSetup()
Setup Functions.
virtual void initSolutionState()
Initializes the solution state.
virtual void timestepSetup()
virtual void jacobianSetup()
virtual void residualSetup()
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
THREAD_ID numThreads() const
virtual const NumericVector< Number > * solutionPreviousNewton() const
virtual const std::string & name() const
NumericVector< Number > & solution()
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.
std::vector< T * > & queryIntoUnsorted(std::vector< T * > &results, Args &&... args)
queryInto executes the query and stores the results in the given vector.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
void add(std::shared_ptr< MooseObject > obj)
add adds a new object to the warehouse and stores attributes/metadata about it for running queries/fi...
std::vector< T * > & queryInto(const std::vector< std::unique_ptr< Attribute > > &conds, std::vector< T * > &results)
queryInto takes the given conditions (i.e.
std::size_t queryID(const std::vector< std::unique_ptr< Attribute > > &conds)
void local_variable_indices(T &idx, const MeshBase &mesh, unsigned int var_num) const
virtual void localize(std::vector< T > &v_local) const=0
const Parallel::Communicator & _communicator
std::unique_ptr< NumericVector< Number > > current_local_solution
dof_id_type n_dofs() const
const DofMap & get_dof_map() const
libMesh::FEType variableFEType(const InputParameters ¶ms)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const BoundaryID ANY_BOUNDARY_ID
std::string name(const ElemQuality q)
const Elem & get(const ElemType type_in)
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Tnew cast_ref(Told &oldvar)
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error