27#include "libmesh/quadrature_gauss.h"
28#include "libmesh/node_range.h"
29#include "libmesh/numeric_vector.h"
30#include "libmesh/default_coupling.h"
31#include "libmesh/string_to_enum.h"
32#include "libmesh/fe_interface.h"
45 _sys(subproblem.es().add_system<
System>(
name)),
46 _current_solution(_sys.current_local_solution.
get()),
47 _aux_scalar_storage(_app.getExecuteOnEnum()),
48 _nodal_aux_storage(_app.getExecuteOnEnum()),
49 _mortar_nodal_aux_storage(_app.getExecuteOnEnum()),
50 _elemental_aux_storage(_app.getExecuteOnEnum()),
51 _nodal_vec_aux_storage(_app.getExecuteOnEnum()),
52 _elemental_vec_aux_storage(_app.getExecuteOnEnum()),
53 _nodal_array_aux_storage(_app.getExecuteOnEnum()),
54 _elemental_array_aux_storage(_app.getExecuteOnEnum())
55#ifdef MOOSE_KOKKOS_ENABLED
57 _kokkos_nodal_aux_storage(_app.getExecuteOnEnum()),
58 _kokkos_elemental_aux_storage(_app.getExecuteOnEnum())
64 if (!_fe_problem.defaultGhosting())
66 auto & dof_map = _sys.get_dof_map();
67 dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
68 dof_map.set_implicit_neighbor_dofs(
false);
77 TIME_SECTION(
"initialSetup", 3,
"Initializing Auxiliary System");
110#ifdef MOOSE_KOKKOS_ENABLED
143#ifdef MOOSE_KOKKOS_ENABLED
166#ifdef MOOSE_KOKKOS_ENABLED
207#ifdef MOOSE_KOKKOS_ENABLED
230#ifdef MOOSE_KOKKOS_ENABLED
248#ifdef MOOSE_KOKKOS_ENABLED
259 const std::string & name,
264 auto fe_type =
FEType(Utility::string_to_enum<Order>(parameters.
get<
MooseEnum>(
"order")),
265 Utility::string_to_enum<FEFamily>(parameters.
get<
MooseEnum>(
"family")));
267 if (var_type ==
"MooseVariableScalar")
292 if (var->feType().family ==
LAGRANGE)
302 if (avar->feType().family ==
LAGRANGE)
313 const std::string & name,
318 const auto & base = parameters.
getBase();
319 if (base ==
"AuxKernel" || base ==
"Bounds")
321 std::shared_ptr<AuxKernel> kernel =
323 if (kernel->isNodal())
325 if (kernel->isMortar())
334 else if (base ==
"VectorAuxKernel")
336 std::shared_ptr<VectorAuxKernel> kernel =
338 if (kernel->isNodal())
340 if (kernel->isMortar())
341 mooseError(
"Vector mortar aux kernels not yet implemented");
348 else if (base ==
"ArrayAuxKernel")
350 std::shared_ptr<ArrayAuxKernel> kernel =
352 if (kernel->isNodal())
354 if (kernel->isMortar())
355 mooseError(
"Vector mortar aux kernels not yet implemented");
363 "Attempting to add AuxKernel of type '" + kernel_name +
"' and name '" +
name +
364 "' to the auxiliary system with invalid _moose_base: " + base);
370 const std::string & name,
375 std::shared_ptr<AuxScalarKernel> kernel =
385 var->computeElemValues();
390 var->computeElemValues();
398 var->computeElemValuesFace();
403 var->reinitAuxNeighbor();
404 var->computeElemValuesFace();
440 if (
_vars[0].scalars().size() > 0)
446 ti->computeTimeDerivatives();
449 if (
_vars[0].fieldVariables().size() > 0)
459#ifdef MOOSE_KOKKOS_ENABLED
473 ti->computeTimeDerivatives();
483 std::set<std::string> depend_objects;
487 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
489 for (
const auto & aux : auxs)
491 const std::set<UserObjectName> & uo = aux->getDependObjects();
492 depend_objects.insert(uo.begin(), uo.end());
498 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
500 for (
const auto & aux : auxs)
502 const std::set<UserObjectName> & uo = aux->getDependObjects();
503 depend_objects.insert(uo.begin(), uo.end());
509 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
511 for (
const auto & aux : auxs)
513 const std::set<UserObjectName> & uo = aux->getDependObjects();
514 depend_objects.insert(uo.begin(), uo.end());
520 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
522 for (
const auto & aux : auxs)
524 const std::set<UserObjectName> & uo = aux->getDependObjects();
525 depend_objects.insert(uo.begin(), uo.end());
531 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
533 for (
const auto & aux : auxs)
535 const std::set<UserObjectName> & uo = aux->getDependObjects();
536 depend_objects.insert(uo.begin(), uo.end());
542 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
544 for (
const auto & aux : auxs)
546 const std::set<UserObjectName> & uo = aux->getDependObjects();
547 depend_objects.insert(uo.begin(), uo.end());
553 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
555 for (
const auto & aux : auxs)
557 const std::set<UserObjectName> & uo = aux->getDependObjects();
558 depend_objects.insert(uo.begin(), uo.end());
562#ifdef MOOSE_KOKKOS_ENABLED
565 const std::vector<std::shared_ptr<AuxKernelBase>> & 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<AuxKernelBase>> & auxs =
578 for (
const auto & aux : auxs)
580 const std::set<UserObjectName> & uo = aux->getDependObjects();
581 depend_objects.insert(uo.begin(), uo.end());
586 return depend_objects;
592 std::set<std::string> depend_objects;
596 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
598 for (
const auto & aux : auxs)
600 const std::set<UserObjectName> & uo = aux->getDependObjects();
601 depend_objects.insert(uo.begin(), uo.end());
607 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
609 for (
const auto & aux : auxs)
611 const std::set<UserObjectName> & uo = aux->getDependObjects();
612 depend_objects.insert(uo.begin(), uo.end());
618 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
620 for (
const auto & aux : auxs)
622 const std::set<UserObjectName> & uo = aux->getDependObjects();
623 depend_objects.insert(uo.begin(), uo.end());
629 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
_nodal_aux_storage.getActiveObjects();
630 for (
const auto & aux : auxs)
632 const std::set<UserObjectName> & uo = aux->getDependObjects();
633 depend_objects.insert(uo.begin(), uo.end());
639 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
641 for (
const auto & aux : auxs)
643 const std::set<UserObjectName> & uo = aux->getDependObjects();
644 depend_objects.insert(uo.begin(), uo.end());
650 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
652 for (
const auto & aux : auxs)
654 const std::set<UserObjectName> & uo = aux->getDependObjects();
655 depend_objects.insert(uo.begin(), uo.end());
661 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
663 for (
const auto & aux : auxs)
665 const std::set<UserObjectName> & uo = aux->getDependObjects();
666 depend_objects.insert(uo.begin(), uo.end());
670#ifdef MOOSE_KOKKOS_ENABLED
673 const std::vector<std::shared_ptr<AuxKernelBase>> & 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<AuxKernelBase>> & auxs =
686 for (
const auto & aux : auxs)
688 const std::set<UserObjectName> & uo = aux->getDependObjects();
689 depend_objects.insert(uo.begin(), uo.end());
694 return depend_objects;
701 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.
getActiveObjects(0);
703 std::set<TagID> needed_sc_var_matrix_tags;
704 std::set<TagID> needed_sc_var_vector_tags;
705 for (
const auto & obj : objects)
707 auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
708 needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
710 auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
711 needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
735 TIME_SECTION(
"computeScalarVars", 1);
745 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
749 for (
const auto & obj : objects)
753 for (
const auto & var : scalar_vars)
769 TIME_SECTION(
"computeNodalVars", 3);
772 computeNodalVarsHelper<AuxKernel>(nodal);
778 TIME_SECTION(
"computeNodalVecVars", 3);
781 computeNodalVarsHelper<VectorAuxKernel>(nodal);
788 computeNodalVarsHelper<ArrayAuxKernel>(nodal);
794 TIME_SECTION(
"computeMortarNodalVars", 3);
799 "We don't allow creation of block restricted mortar nodal aux kernels.");
804 for (
const auto & [bnd_id, mortar_nodal_auxes] :
806 for (
const auto index :
index_range(mortar_nodal_auxes))
813 _fe_problem, mortar_nodal_warehouse, bnd_id, index);
819 "Auxiliary variable computation:\n" +
820 std::string(e.
what()));
822 catch (MetaPhysicL::LogicError & e)
826 catch (std::exception & e)
830 if (!strstr(e.
what(),
"Jacobian") && !strstr(e.
what(),
"singular") &&
831 !strstr(e.
what(),
"det != 0"))
835 "nodal Auxiliary variable computation:\n" +
836 std::string(e.
what()));
852 TIME_SECTION(
"computeElementalVars", 3);
855 computeElementalVarsHelper<AuxKernel>(elemental);
861 TIME_SECTION(
"computeElementalVecVars", 3);
864 computeElementalVarsHelper<VectorAuxKernel>(elemental);
871 computeElementalVarsHelper<ArrayAuxKernel>(elemental);
876 std::vector<dof_id_type> & ,
877 std::vector<dof_id_type> &
886 std::vector<MooseVariableFEBase *>
vars =
_vars[0].fieldVariables();
887 for (
const auto & var :
vars)
891 FEType fe_type = var->feType();
914template <
typename AuxKernelType>
932 "Auxiliary variable computation:\n" +
933 std::string(e.
what()));
947 TIME_SECTION(
"computeElementalVecVars", 3);
960 "elemental Auxiliary variable computation:\n" +
961 std::string(e.
what()));
973template <
typename AuxKernelType>
994 TIME_SECTION(
"computeBoundaryObjects", 3);
1012 std::vector<Number> & rel_diff_norms)
const
1021 std::vector<dof_id_type> local_indices_n;
1026 for (
const auto local_index : local_indices_n)
1030 diff_norm_n += Utility::pow<2, Number>(value - value_old);
1031 norm_n += Utility::pow<2, Number>(value);
1036 diff_norm_n = sqrt(diff_norm_n);
1037 norm_n = sqrt(norm_n);
1038 rel_diff_norms[n] = diff_norm_n > 0 ? diff_norm_n / norm_n : 0.0;
1044template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
1048template 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)
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.
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)
ExecuteMooseObjectWarehouse< VectorAuxKernel > _nodal_vec_aux_storage
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 initialSetup() override
Setup Functions.
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 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
Shared storage and allocation logic for linear finite-volume cell gradients for variables in the syst...
void rebuildLinearFVGradientStorage()
Rebuild persistent raw and temporary gradient storage after mesh/DOF changes.
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > _raw_grad_container
Persisted raw cell-centered gradient components keyed by spatial direction.
void computeGradients()
Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.
Class for containing MooseEnum item information.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
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 timestepSetup()
virtual void jacobianSetup()
virtual void residualSetup()
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
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
static FEFieldType field_type(const FEType &fe_type)
Order default_quadrature_order() const
virtual std::unique_ptr< Base > create()=0
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
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())
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
auto index_range(const T &sizable)
IntRange< T > make_range(T beg, T end)
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error