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())
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")
272 if (FEInterface::field_type(fe_type) ==
TYPE_VECTOR)
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();
480 std::set<std::string>
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;
589 std::set<std::string>
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);
814 Threads::parallel_reduce(bnd_nodes, mnabt);
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();
914 template <
typename AuxKernelType>
927 Threads::parallel_reduce(range, eavt);
932 "Auxiliary variable computation:\n" +
933 std::string(e.
what()));
947 TIME_SECTION(
"computeElementalVecVars", 3);
955 Threads::parallel_reduce(bnd_elems, eabt);
960 "elemental Auxiliary variable computation:\n" +
961 std::string(e.
what()));
973 template <
typename AuxKernelType>
984 Threads::parallel_reduce(range, navt);
994 TIME_SECTION(
"computeBoundaryObjects", 3);
1001 Threads::parallel_reduce(bnd_nodes, nabt);
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;
1044 template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
1048 template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
std::string name(const ElemQuality q)
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
void rebuildLinearFVGradientStorage()
Rebuild persistent raw and temporary gradient storage after mesh/DOF changes.
ExecuteMooseObjectWarehouse< AuxKernel > _nodal_aux_storage
ExecuteMooseObjectWarehouse< AuxKernel > _mortar_nodal_aux_storage
virtual void timestepSetup() override
libMesh::ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
virtual void clearActiveScalarVariableCoupleableVectorTags(const THREAD_ID tid) override
void computeNodalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
virtual const char * what() const
Get out the error message.
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void computeScalarVars(ExecFlagType type)
void sort(THREAD_ID tid=0)
Performs a sort using the DependencyResolver.
This class evaluates a single mortar nodal aux kernel.
NumericVector< Number > & solution()
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶meters)
Canonical method for adding a variable.
virtual void copyCurrentIntoPreviousNL()
Copies the current solution into the previous nonlinear iteration solution.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
virtual void clearActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid) override
void updateActive(THREAD_ID tid=0) override
Updates the active objects storage.
virtual void setActiveScalarVariableCoupleableMatrixTags(std::set< TagID > &mtags, 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
void local_variable_indices(T &idx, const MeshBase &mesh, unsigned int var_num) const
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
virtual void reinit() override
Reinitialize the system when the degrees of freedom in this system have changed.
AuxiliarySystem(FEProblemBase &subproblem, const std::string &name)
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _nodal_array_aux_storage
virtual void updateActive(THREAD_ID tid)
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 void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
const NumericVector< Number > *const & currentSolution() const override
The solution vector that is currently being operated on.
Order default_quadrature_order() const
void computeElementalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
const Parallel::Communicator & _communicator
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const NumericVector< Number > * _current_solution
solution vector from nonlinear solver
Base class for a system (of equations)
ExecuteMooseObjectWarehouse< AuxScalarKernel > _aux_scalar_storage
bool needMaterialOnSide(BoundaryID bnd_id)
Indicated whether this system needs material properties on boundaries.
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
Reinit an element assembly info.
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > _raw_grad_container
Persisted raw cell-centered gradient components keyed by spatial direction.
std::unique_ptr< NumericVector< Number > > _serialized_solution
Serialized version of the solution vector, or nullptr if a serialized solution is not needed...
virtual void residualSetup() override
libMesh::ConstNodeRange * getLocalNodeRange()
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
FEProblemBase & _fe_problem
void computeMortarNodalVars(ExecFlagType type)
dof_id_type n_dofs() const
virtual unsigned int nVariables() const
Get the number of variables in this system.
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
virtual const std::string & name() const
virtual void jacobianSetup()
ExecuteMooseObjectWarehouse< AuxKernelBase > _kokkos_elemental_aux_storage
void setScalarVariableCoupleableTags(ExecFlagType type)
void clearScalarVariableCoupleableTags()
std::set< std::string > getDependObjects()
virtual void jacobianSetup() override
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _elemental_array_aux_storage
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...
void computeNodalArrayVars(ExecFlagType type)
virtual std::unique_ptr< Base > create()=0
void computeElementalVars(ExecFlagType type)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Base class for making kernels that work on auxiliary scalar variables.
boundary_id_type BoundaryID
virtual void timestepSetup(THREAD_ID tid=0) const
virtual libMesh::Order getMinQuadratureOrder() override
Get the minimum quadrature order for evaluating elemental auxiliary variables.
virtual void setActiveScalarVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
void kokkosCompute(ExecFlagType type)
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void addVariable(const std::string &var_type, const std::string &name, InputParameters ¶meters) override
Canonical method for adding a variable.
Interface for objects interacting with the PerfGraph.
void jacobianSetup(THREAD_ID tid=0) const override
Convenience methods for calling object setup methods.
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
virtual void reinitElemFace(const Elem *elem, unsigned int side, THREAD_ID tid) override
Reinit assembly info for a side of an element.
virtual ~AuxiliarySystem()
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< MooseVariableFEBase * > > _nodal_vars
virtual void initialSetup() override
Setup Functions.
ExecuteMooseObjectWarehouse< VectorAuxKernel > _nodal_vec_aux_storage
std::vector< std::vector< MooseVariableFieldBase * > > _elem_vars
Elemental variables.
ExecuteMooseObjectWarehouse< AuxKernelBase > _kokkos_nodal_aux_storage
FEProblemBase & _fe_problem
the governing finite element/volume problem
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Provides a way for users to bail out of the current solve.
virtual void subdomainSetup()
void addKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds an auxiliary kernel.
Class for containing MooseEnum item information.
bool hasActiveObjects(THREAD_ID tid=0) const
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
virtual void compute(ExecFlagType type) override
Compute auxiliary variables.
IntRange< T > make_range(T beg, T end)
void computeNodalVars(ExecFlagType type)
std::unique_ptr< NumericVector< Number > > current_local_solution
virtual const NumericVector< Number > * solutionPreviousNewton() const
virtual void customSetup(const ExecFlagType &exec_type)
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a scalar kernel.
ExecuteMooseObjectWarehouse< AuxKernel > _elemental_aux_storage
virtual void customSetup(const ExecFlagType &exec_type) override
libMesh::StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement * > * getBoundaryElementRange()
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual void serializeSolution()
void computeNodalVecVars(ExecFlagType type)
void computeElementalArrayVars(ExecFlagType type)
ExecuteMooseObjectWarehouse< VectorAuxKernel > _elemental_vec_aux_storage
NumericVector< Number > & solutionOld()
virtual void initialSetup()
Setup Functions.
bool defaultGhosting()
Whether or not the user has requested default ghosting ot be on.
virtual Real & dt() const
const DofMap & get_dof_map() const
virtual void residualSetup()
void residualSetup(THREAD_ID tid=0) const override
virtual void subdomainSetup(THREAD_ID tid=0) const
libMesh::StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
auto index_range(const T &sizable)
void variableWiseRelativeSolutionDifferenceNorm(std::vector< Number > &var_diffs) const
Computes and stores ||current - old|| / ||current|| for each variable in the given vector...
const Elem & get(const ElemType type_in)
void computeElementalVecVars(ExecFlagType type)
virtual void subdomainSetup() override
void computeGradients()
Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.
Shared storage and allocation logic for linear finite-volume cell gradients for variables in the syst...
virtual void timestepSetup()
virtual void localize(std::vector< T > &v_local) const=0