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 _nodal_aux_storage(_app.getExecuteOnEnum(), numThreads()),
48 _mortar_nodal_aux_storage(_app.getExecuteOnEnum(), numThreads()),
49 _elemental_aux_storage(_app.getExecuteOnEnum(), numThreads()),
50 _nodal_vec_aux_storage(_app.getExecuteOnEnum(), numThreads()),
51 _elemental_vec_aux_storage(_app.getExecuteOnEnum(), numThreads()),
52 _nodal_array_aux_storage(_app.getExecuteOnEnum(), numThreads()),
53 _elemental_array_aux_storage(_app.getExecuteOnEnum(), numThreads())
54#ifdef MOOSE_KOKKOS_ENABLED
56 _kokkos_nodal_aux_storage(_app.getExecuteOnEnum(), 1),
57 _kokkos_elemental_aux_storage(_app.getExecuteOnEnum(), 1)
60 _nodal_vars.resize(this->numThreads());
61 _elem_vars.resize(this->numThreads());
63 if (!_fe_problem.defaultGhosting())
65 auto & dof_map = _sys.get_dof_map();
66 dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
67 dof_map.set_implicit_neighbor_dofs(
false);
83 TIME_SECTION(
"initialSetup", 3,
"Initializing Auxiliary System");
89 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
116#ifdef MOOSE_KOKKOS_ENABLED
136 const bool skip_current_to_old)
153 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
165#ifdef MOOSE_KOKKOS_ENABLED
176 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
188#ifdef MOOSE_KOKKOS_ENABLED
199 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
217 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
229#ifdef MOOSE_KOKKOS_ENABLED
240 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
252#ifdef MOOSE_KOKKOS_ENABLED
270#ifdef MOOSE_KOKKOS_ENABLED
283 const std::string & name,
290 if (var_type ==
"MooseVariableScalar")
297 auto * var =
_vars[tid].getActualFieldVariable<RealVectorValue>(
name);
300 if (var->feType().family == LAGRANGE_VEC)
315 if (var->feType().family == LAGRANGE)
325 if (avar->feType().family == LAGRANGE)
336 const std::string & name,
341 const auto & base = parameters.
getBase();
342 if (base ==
"AuxKernel" || base ==
"Bounds")
344 std::shared_ptr<AuxKernel> kernel =
346 if (kernel->isNodal())
348 if (kernel->isMortar())
357 else if (base ==
"VectorAuxKernel")
359 std::shared_ptr<VectorAuxKernel> kernel =
361 if (kernel->isNodal())
363 if (kernel->isMortar())
364 mooseError(
"Vector mortar aux kernels not yet implemented");
371 else if (base ==
"ArrayAuxKernel")
373 std::shared_ptr<ArrayAuxKernel> kernel =
375 if (kernel->isNodal())
377 if (kernel->isMortar())
378 mooseError(
"Vector mortar aux kernels not yet implemented");
386 "Attempting to add AuxKernel of type '" + kernel_name +
"' and name '" +
name +
387 "' to the auxiliary system with invalid _moose_base: " + base);
393 const std::string & name,
398 std::shared_ptr<AuxScalarKernel> kernel =
408 var->computeElemValues();
413 var->computeElemValues();
421 var->computeElemValuesFace();
426 var->reinitAuxNeighbor();
427 var->computeElemValuesFace();
463 if (
_vars[0].scalars().size() > 0)
469 ti->computeTimeDerivatives();
472 if (
_vars[0].fieldVariables().size() > 0)
482#ifdef MOOSE_KOKKOS_ENABLED
496 ti->computeTimeDerivatives();
506 std::set<std::string> depend_objects;
510 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
512 for (
const auto & aux : auxs)
514 const std::set<UserObjectName> & uo = aux->getDependObjects();
515 depend_objects.insert(uo.begin(), uo.end());
521 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
523 for (
const auto & aux : auxs)
525 const std::set<UserObjectName> & uo = aux->getDependObjects();
526 depend_objects.insert(uo.begin(), uo.end());
532 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
534 for (
const auto & aux : auxs)
536 const std::set<UserObjectName> & uo = aux->getDependObjects();
537 depend_objects.insert(uo.begin(), uo.end());
543 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
545 for (
const auto & aux : auxs)
547 const std::set<UserObjectName> & uo = aux->getDependObjects();
548 depend_objects.insert(uo.begin(), uo.end());
554 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
556 for (
const auto & aux : auxs)
558 const std::set<UserObjectName> & uo = aux->getDependObjects();
559 depend_objects.insert(uo.begin(), uo.end());
565 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
567 for (
const auto & aux : auxs)
569 const std::set<UserObjectName> & uo = aux->getDependObjects();
570 depend_objects.insert(uo.begin(), uo.end());
576 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
578 for (
const auto & aux : auxs)
580 const std::set<UserObjectName> & uo = aux->getDependObjects();
581 depend_objects.insert(uo.begin(), uo.end());
585#ifdef MOOSE_KOKKOS_ENABLED
588 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
590 for (
const auto & aux : auxs)
592 const std::set<UserObjectName> & uo = aux->getDependObjects();
593 depend_objects.insert(uo.begin(), uo.end());
599 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
601 for (
const auto & aux : auxs)
603 const std::set<UserObjectName> & uo = aux->getDependObjects();
604 depend_objects.insert(uo.begin(), uo.end());
609 return depend_objects;
615 std::set<std::string> depend_objects;
619 const std::vector<std::shared_ptr<AuxKernel>> & 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<VectorAuxKernel>> & auxs =
632 for (
const auto & aux : auxs)
634 const std::set<UserObjectName> & uo = aux->getDependObjects();
635 depend_objects.insert(uo.begin(), uo.end());
641 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
643 for (
const auto & aux : auxs)
645 const std::set<UserObjectName> & uo = aux->getDependObjects();
646 depend_objects.insert(uo.begin(), uo.end());
652 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
_nodal_aux_storage.getActiveObjects();
653 for (
const auto & aux : auxs)
655 const std::set<UserObjectName> & uo = aux->getDependObjects();
656 depend_objects.insert(uo.begin(), uo.end());
662 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
664 for (
const auto & aux : auxs)
666 const std::set<UserObjectName> & uo = aux->getDependObjects();
667 depend_objects.insert(uo.begin(), uo.end());
673 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
675 for (
const auto & aux : auxs)
677 const std::set<UserObjectName> & uo = aux->getDependObjects();
678 depend_objects.insert(uo.begin(), uo.end());
684 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
686 for (
const auto & aux : auxs)
688 const std::set<UserObjectName> & uo = aux->getDependObjects();
689 depend_objects.insert(uo.begin(), uo.end());
693#ifdef MOOSE_KOKKOS_ENABLED
696 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
698 for (
const auto & aux : auxs)
700 const std::set<UserObjectName> & uo = aux->getDependObjects();
701 depend_objects.insert(uo.begin(), uo.end());
707 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
709 for (
const auto & aux : auxs)
711 const std::set<UserObjectName> & uo = aux->getDependObjects();
712 depend_objects.insert(uo.begin(), uo.end());
717 return depend_objects;
724 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.
getActiveObjects(0);
726 std::set<TagID> needed_sc_var_matrix_tags;
727 std::set<TagID> needed_sc_var_vector_tags;
728 for (
const auto & obj : objects)
730 auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
731 needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
733 auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
734 needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
758 TIME_SECTION(
"computeScalarVars", 1);
768 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
772 for (
const auto & obj : objects)
776 for (
const auto & var : scalar_vars)
792 TIME_SECTION(
"computeNodalVars", 3);
795 computeNodalVarsHelper<AuxKernel>(nodal);
801 TIME_SECTION(
"computeNodalVecVars", 3);
804 computeNodalVarsHelper<VectorAuxKernel>(nodal);
811 computeNodalVarsHelper<ArrayAuxKernel>(nodal);
817 TIME_SECTION(
"computeMortarNodalVars", 3);
822 "We don't allow creation of block restricted mortar nodal aux kernels.");
827 for (
const auto & [bnd_id, mortar_nodal_auxes] :
829 for (
const auto index : index_range(mortar_nodal_auxes))
836 _fe_problem, mortar_nodal_warehouse, bnd_id, index);
842 "Auxiliary variable computation:\n" +
843 std::string(e.
what()));
845 catch (MetaPhysicL::LogicError & e)
849 catch (std::exception & e)
853 if (!strstr(e.
what(),
"Jacobian") && !strstr(e.
what(),
"singular") &&
854 !strstr(e.
what(),
"det != 0"))
858 "nodal Auxiliary variable computation:\n" +
859 std::string(e.
what()));
875 TIME_SECTION(
"computeElementalVars", 3);
878 computeElementalVarsHelper<AuxKernel>(elemental);
884 TIME_SECTION(
"computeElementalVecVars", 3);
887 computeElementalVarsHelper<VectorAuxKernel>(elemental);
894 computeElementalVarsHelper<ArrayAuxKernel>(elemental);
899 std::vector<dof_id_type> & ,
900 std::vector<dof_id_type> &
908 Order order = CONSTANT;
909 std::vector<MooseVariableFEBase *>
vars =
_vars[0].fieldVariables();
910 for (
const auto & var :
vars)
914 FEType fe_type = var->feType();
915 if (fe_type.default_quadrature_order() > order)
916 order = fe_type.default_quadrature_order();
937template <
typename AuxKernelType>
955 "Auxiliary variable computation:\n" +
956 std::string(e.
what()));
970 TIME_SECTION(
"computeElementalVecVars", 3);
983 "elemental Auxiliary variable computation:\n" +
984 std::string(e.
what()));
996template <
typename AuxKernelType>
1017 TIME_SECTION(
"computeBoundaryObjects", 3);
1035 std::vector<Number> & rel_diff_norms)
const
1041 for (
const auto n : make_range(
nVariables()))
1044 std::vector<dof_id_type> local_indices_n;
1046 Number diff_norm_n = 0;
1049 for (
const auto local_index : local_indices_n)
1051 const Number & value =
solution()(local_index);
1052 const Number & value_old =
solutionOld()(local_index);
1053 diff_norm_n += Utility::pow<2, Number>(value - value_old);
1054 norm_n += Utility::pow<2, Number>(value);
1059 diff_norm_n = sqrt(diff_norm_n);
1060 norm_n = sqrt(norm_n);
1061 rel_diff_norms[n] = diff_norm_n > 0 ? diff_norm_n / norm_n : 0.0;
1067template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
1071template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
boundary_id_type BoundaryID
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
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
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.
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _nodal_array_aux_storage
void clearScalarVariableCoupleableTags()
virtual void compute(ExecFlagType type) override
Compute auxiliary variables.
void kokkosCompute(ExecFlagType type)
virtual void copyAdditionalStateBackwards(Moose::SolutionIterationType iteration_type, bool skip_current_to_old) override
Copy system-owned state not represented by solution vectors.
void computeMortarNodalVars(ExecFlagType type)
void computeElementalVars(ExecFlagType type)
void computeElementalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
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.
ExecuteMooseObjectWarehouse< AuxKernel > _elemental_aux_storage
void computeNodalVecVars(ExecFlagType type)
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
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _elemental_array_aux_storage
ExecuteMooseObjectWarehouse< VectorAuxKernel > _elemental_vec_aux_storage
ExecuteMooseObjectWarehouse< AuxKernel > _nodal_aux_storage
void computeElementalVecVars(ExecFlagType type)
void buildKokkosAuxStages()
Group the active Kokkos auxiliary kernels of each execution flag into stages that can each be compute...
ExecuteMooseObjectWarehouse< VectorAuxKernel > _nodal_vec_aux_storage
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.
ExecuteMooseObjectWarehouse< AuxKernel > _mortar_nodal_aux_storage
virtual ~AuxiliarySystem()
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.
void computeElementalArrayVars(ExecFlagType type)
void computeNodalVars(ExecFlagType type)
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.
std::vector< std::vector< MooseVariableFEBase * > > _nodal_vars
virtual void serializeSolution()
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 computeNodalArrayVars(ExecFlagType type)
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 computeNodalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
This class evaluates a single mortar nodal aux kernel.
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
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.
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::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
bool hasActiveBoundaryObjects(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)
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...
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