Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : // MOOSE includes 13 : #include "SystemBase.h" 14 : #include "ExecuteMooseObjectWarehouse.h" 15 : #include "PerfGraphInterface.h" 16 : 17 : #include "libmesh/system.h" 18 : #include "libmesh/transient_system.h" 19 : 20 : // Forward declarations 21 : template <typename ComputeValueType> 22 : class AuxKernelTempl; 23 : typedef AuxKernelTempl<Real> AuxKernel; 24 : typedef AuxKernelTempl<RealVectorValue> VectorAuxKernel; 25 : typedef AuxKernelTempl<RealEigenVector> ArrayAuxKernel; 26 : class FEProblemBase; 27 : class TimeIntegrator; 28 : class AuxScalarKernel; 29 : 30 : // libMesh forward declarations 31 : namespace libMesh 32 : { 33 : template <typename T> 34 : class NumericVector; 35 : } 36 : 37 : /** 38 : * A system that holds auxiliary variables 39 : * 40 : */ 41 : class AuxiliarySystem : public SystemBase, public PerfGraphInterface 42 : { 43 : public: 44 : AuxiliarySystem(FEProblemBase & subproblem, const std::string & name); 45 : virtual ~AuxiliarySystem(); 46 : 47 : virtual void initialSetup() override; 48 : virtual void timestepSetup() override; 49 : virtual void customSetup(const ExecFlagType & exec_type) override; 50 : virtual void subdomainSetup() override; 51 : virtual void residualSetup() override; 52 : virtual void jacobianSetup() override; 53 : virtual void updateActive(THREAD_ID tid); 54 : 55 : virtual void addVariable(const std::string & var_type, 56 : const std::string & name, 57 : InputParameters & parameters) override; 58 : 59 : /** 60 : * Adds an auxiliary kernel 61 : * @param kernel_name The type of the kernel 62 : * @param name The name of the kernel 63 : * @param parameters Parameters for this kernel 64 : */ 65 : void addKernel(const std::string & kernel_name, 66 : const std::string & name, 67 : InputParameters & parameters); 68 : 69 : /** 70 : * Adds a scalar kernel 71 : * @param kernel_name The type of the kernel 72 : * @param name The name of the kernel 73 : * @param parameters Kernel parameters 74 : */ 75 : void addScalarKernel(const std::string & kernel_name, 76 : const std::string & name, 77 : InputParameters & parameters); 78 : 79 : virtual void reinitElem(const Elem * elem, THREAD_ID tid) override; 80 : virtual void reinitElemFace(const Elem * elem, unsigned int side, THREAD_ID tid) override; 81 : 82 11682028 : const NumericVector<Number> * const & currentSolution() const override 83 : { 84 11682028 : return _current_solution; 85 : } 86 : 87 : virtual void serializeSolution(); 88 : 89 : // This is an empty function since the Aux system doesn't have a matrix! 90 : virtual void augmentSparsity(libMesh::SparsityPattern::Graph & /*sparsity*/, 91 : std::vector<dof_id_type> & /*n_nz*/, 92 : std::vector<dof_id_type> & /*n_oz*/) override; 93 : 94 : /** 95 : * Compute auxiliary variables 96 : * @param type Time flag of which variables should be computed 97 : */ 98 : virtual void compute(ExecFlagType type) override; 99 : 100 : /** 101 : * Get a list of dependent UserObjects for this exec type 102 : * @param type Execution flag type 103 : * @return a set of dependent user objects 104 : */ 105 : std::set<std::string> getDependObjects(ExecFlagType type); 106 : std::set<std::string> getDependObjects(); 107 : 108 : /** 109 : * Get the minimum quadrature order for evaluating elemental auxiliary variables 110 : */ 111 : virtual libMesh::Order getMinQuadratureOrder() override; 112 : 113 : /** 114 : * Indicated whether this system needs material properties on boundaries. 115 : * @return Boolean if IntegratedBCs are active 116 : */ 117 : bool needMaterialOnSide(BoundaryID bnd_id); 118 : 119 76289 : virtual libMesh::System & sys() { return _sys; } 120 : 121 4790583 : virtual libMesh::System & system() override { return _sys; } 122 571192439 : virtual const libMesh::System & system() const override { return _sys; } 123 : 124 : /// Copies the current solution into the previous nonlinear iteration solution 125 : virtual void copyCurrentIntoPreviousNL(); 126 : 127 : void setScalarVariableCoupleableTags(ExecFlagType type); 128 : 129 : void clearScalarVariableCoupleableTags(); 130 : 131 : const ExecuteMooseObjectWarehouse<AuxKernel> & nodalAuxWarehouse() const; 132 : const ExecuteMooseObjectWarehouse<VectorAuxKernel> & nodalVectorAuxWarehouse() const; 133 : const ExecuteMooseObjectWarehouse<ArrayAuxKernel> & nodalArrayAuxWarehouse() const; 134 : 135 : const ExecuteMooseObjectWarehouse<AuxKernel> & elemAuxWarehouse() const; 136 : const ExecuteMooseObjectWarehouse<VectorAuxKernel> & elemVectorAuxWarehouse() const; 137 : const ExecuteMooseObjectWarehouse<ArrayAuxKernel> & elemArrayAuxWarehouse() const; 138 : 139 : /// Computes and stores ||current - old|| / ||current|| for each variable in the given vector 140 : /// @param var_diffs a vector being filled with the L2 norm of the solution difference 141 : void variableWiseRelativeSolutionDifferenceNorm(std::vector<Number> & var_diffs) const; 142 : 143 : protected: 144 : void computeScalarVars(ExecFlagType type); 145 : void computeNodalVars(ExecFlagType type); 146 : void computeMortarNodalVars(ExecFlagType type); 147 : void computeNodalVecVars(ExecFlagType type); 148 : void computeNodalArrayVars(ExecFlagType type); 149 : void computeElementalVars(ExecFlagType type); 150 : void computeElementalVecVars(ExecFlagType type); 151 : void computeElementalArrayVars(ExecFlagType type); 152 : 153 : template <typename AuxKernelType> 154 : void computeElementalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse); 155 : 156 : template <typename AuxKernelType> 157 : void computeNodalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse); 158 : 159 : libMesh::System & _sys; 160 : 161 : /// solution vector from nonlinear solver 162 : const NumericVector<Number> * _current_solution; 163 : 164 : /// The current states of the solution (0 = current, 1 = old, etc) 165 : std::vector<NumericVector<Number> *> _solution_state; 166 : 167 : // Variables 168 : std::vector<std::vector<MooseVariableFEBase *>> _nodal_vars; 169 : 170 : ///@{ 171 : /** 172 : * Elemental variables. These may be either finite element or finite volume variables 173 : */ 174 : std::vector<std::vector<MooseVariableFieldBase *>> _elem_vars; 175 : ///@} 176 : 177 : // Storage for AuxScalarKernel objects 178 : ExecuteMooseObjectWarehouse<AuxScalarKernel> _aux_scalar_storage; 179 : 180 : // Storage for AuxKernel objects 181 : ExecuteMooseObjectWarehouse<AuxKernel> _nodal_aux_storage; 182 : ExecuteMooseObjectWarehouse<AuxKernel> _mortar_nodal_aux_storage; 183 : ExecuteMooseObjectWarehouse<AuxKernel> _elemental_aux_storage; 184 : 185 : // Storage for VectorAuxKernel objects 186 : ExecuteMooseObjectWarehouse<VectorAuxKernel> _nodal_vec_aux_storage; 187 : ExecuteMooseObjectWarehouse<VectorAuxKernel> _elemental_vec_aux_storage; 188 : 189 : // Storage for ArrayAuxKernel objects 190 : ExecuteMooseObjectWarehouse<ArrayAuxKernel> _nodal_array_aux_storage; 191 : ExecuteMooseObjectWarehouse<ArrayAuxKernel> _elemental_array_aux_storage; 192 : 193 : friend class ComputeIndicatorThread; 194 : friend class ComputeMarkerThread; 195 : friend class FlagElementsThread; 196 : friend class ComputeNodalKernelsThread; 197 : friend class ComputeNodalKernelBcsThread; 198 : friend class ComputeNodalKernelJacobiansThread; 199 : friend class ComputeNodalKernelBCJacobiansThread; 200 : 201 56498 : NumericVector<Number> & solutionInternal() const override { return *_sys.solution; } 202 : }; 203 : 204 : inline const ExecuteMooseObjectWarehouse<AuxKernel> & 205 55129 : AuxiliarySystem::nodalAuxWarehouse() const 206 : { 207 55129 : return _nodal_aux_storage; 208 : } 209 : 210 : inline const ExecuteMooseObjectWarehouse<VectorAuxKernel> & 211 55129 : AuxiliarySystem::nodalVectorAuxWarehouse() const 212 : { 213 55129 : return _nodal_vec_aux_storage; 214 : } 215 : 216 : inline const ExecuteMooseObjectWarehouse<ArrayAuxKernel> & 217 55129 : AuxiliarySystem::nodalArrayAuxWarehouse() const 218 : { 219 55129 : return _nodal_array_aux_storage; 220 : } 221 : 222 : inline const ExecuteMooseObjectWarehouse<AuxKernel> & 223 55087 : AuxiliarySystem::elemAuxWarehouse() const 224 : { 225 55087 : return _elemental_aux_storage; 226 : } 227 : 228 : inline const ExecuteMooseObjectWarehouse<VectorAuxKernel> & 229 55087 : AuxiliarySystem::elemVectorAuxWarehouse() const 230 : { 231 55087 : return _elemental_vec_aux_storage; 232 : } 233 : 234 : inline const ExecuteMooseObjectWarehouse<ArrayAuxKernel> & 235 55087 : AuxiliarySystem::elemArrayAuxWarehouse() const 236 : { 237 55087 : return _elemental_array_aux_storage; 238 : }