LCOV - code coverage report
Current view: top level - src/auxkernels - AuxKernelBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31761 (28487c) with base 701993 Lines: 95 98 96.9 %
Date: 2025-11-11 13:51:07 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          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             : #include "AuxKernelBase.h"
      11             : 
      12             : // local includes
      13             : #include "FEProblem.h"
      14             : #include "SubProblem.h"
      15             : #include "AuxiliarySystem.h"
      16             : #include "MooseTypes.h"
      17             : #include "Assembly.h"
      18             : 
      19             : InputParameters
      20     2247436 : AuxKernelBase::validParams()
      21             : {
      22     2247436 :   InputParameters params = MooseObject::validParams();
      23     2247436 :   params += BlockRestrictable::validParams();
      24     2247436 :   params += BoundaryRestrictable::validParams();
      25     2247436 :   params += RandomInterface::validParams();
      26     2247436 :   params += MeshChangedInterface::validParams();
      27     2247436 :   params += MaterialPropertyInterface::validParams();
      28     2247436 :   params += FunctorInterface::validParams();
      29     2247436 :   params += GeometricSearchInterface::validParams();
      30             : 
      31             :   // Add the SetupInterface parameter 'execute_on' with 'linear' and 'timestep_end'
      32     2247436 :   params += SetupInterface::validParams();
      33     2247436 :   ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on", true);
      34     2247436 :   exec_enum.addAvailableFlags(EXEC_PRE_DISPLACE);
      35     6742308 :   exec_enum = {EXEC_LINEAR, EXEC_TIMESTEP_END};
      36     6742308 :   params.setDocString("execute_on", exec_enum.getDocString());
      37             : 
      38     8989744 :   params.addRequiredParam<AuxVariableName>("variable",
      39             :                                            "The name of the variable that this object applies to");
      40             : 
      41     6742308 :   params.addParam<bool>("use_displaced_mesh",
      42     4494872 :                         false,
      43             :                         "Whether or not this object should use the "
      44             :                         "displaced mesh for computation.  Note that "
      45             :                         "in the case this is true but no "
      46             :                         "displacements are provided in the Mesh block "
      47             :                         "the undisplaced mesh will still be used.");
      48     8989744 :   params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
      49     4494872 :   params.addParam<bool>("check_boundary_restricted",
      50     4494872 :                         true,
      51             :                         "Whether to check for multiple element sides on the boundary "
      52             :                         "in the case of a boundary restricted, element aux variable. "
      53             :                         "Setting this to false will allow contribution to a single element's "
      54             :                         "elemental value(s) from multiple boundary sides on the same element "
      55             :                         "(example: when the restricted boundary exists on two or more sides "
      56             :                         "of an element, such as at a corner of a mesh");
      57             : 
      58     6742308 :   params.addRelationshipManager("GhostLowerDElems",
      59             :                                 Moose::RelationshipManagerType::GEOMETRIC |
      60             :                                     Moose::RelationshipManagerType::ALGEBRAIC);
      61             : 
      62     6742308 :   params.declareControllable("enable"); // allows Control to enable/disable this type of object
      63     4494872 :   params.registerSystemAttributeName("AuxKernel");
      64             : 
      65     2247436 :   params.registerBase("AuxKernel");
      66             : 
      67     2247436 :   return params;
      68     2247436 : }
      69             : 
      70       76424 : AuxKernelBase::AuxKernelBase(const InputParameters & parameters)
      71             :   : MooseObject(parameters),
      72             :     BlockRestrictable(this),
      73       76420 :     BoundaryRestrictable(this, getVariableHelper(parameters).isNodal()),
      74             :     SetupInterface(this),
      75             :     CoupleableMooseVariableDependencyIntermediateInterface(this,
      76       76420 :                                                            getVariableHelper(parameters).isNodal()),
      77             :     FunctionInterface(this),
      78             :     UserObjectInterface(this),
      79             :     TransientInterface(this),
      80             :     MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
      81             :     PostprocessorInterface(this),
      82             :     DependencyResolverInterface(),
      83             :     RandomInterface(parameters,
      84      305680 :                     *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
      85       76420 :                     parameters.get<THREAD_ID>("_tid"),
      86       76420 :                     getVariableHelper(parameters).isNodal()),
      87             :     GeometricSearchInterface(this),
      88             :     Restartable(this, "AuxKernels"),
      89             :     MeshChangedInterface(parameters),
      90             :     VectorPostprocessorInterface(this),
      91             :     ElementIDInterface(this),
      92             :     NonADFunctorInterface(this),
      93             : 
      94      152840 :     _var(getVariableHelper(parameters)),
      95       76420 :     _bnd(boundaryRestricted()),
      96      152840 :     _check_boundary_restricted(getParam<bool>("check_boundary_restricted")),
      97       76420 :     _coincident_lower_d_calc(_bnd && !_var.isNodal() && _var.isLowerD()),
      98      305680 :     _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
      99      305680 :     _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
     100      305680 :     _nl_sys(*getCheckedPointerParam<SystemBase *>("_nl_sys")),
     101       76420 :     _aux_sys(static_cast<AuxiliarySystem &>(_sys)),
     102       76420 :     _tid(parameters.get<THREAD_ID>("_tid")),
     103       76420 :     _assembly(_subproblem.assembly(_tid, 0)),
     104      764204 :     _mesh(_subproblem.mesh())
     105             : {
     106       76420 :   addMooseVariableDependency(&_var);
     107       76420 :   _supplied_vars.insert(parameters.get<AuxVariableName>("variable"));
     108             : 
     109       76420 :   if (_bnd && !_var.isNodal() && !_coincident_lower_d_calc && _check_boundary_restricted)
     110             :   {
     111             :     // when the variable is elemental and this aux kernel operates on boundaries,
     112             :     // we need to check that no elements are visited more than once through visiting
     113             :     // all the sides on the boundaries
     114        1368 :     auto boundaries = _mesh.getMesh().get_boundary_info().build_side_list();
     115        1368 :     std::set<dof_id_type> elements;
     116      195823 :     for (const auto & t : boundaries)
     117             :     {
     118      194459 :       if (hasBoundary(std::get<2>(t)))
     119             :       {
     120       72803 :         const auto eid = std::get<0>(t);
     121       72803 :         const auto stat = elements.insert(eid);
     122       72803 :         if (!stat.second) // already existed in the set
     123           4 :           mooseError(
     124             :               "Boundary restricted auxiliary kernel '",
     125           4 :               name(),
     126             :               "' has element (id=",
     127             :               eid,
     128             :               ") connected with more than one boundary sides.\nTo skip this error check, "
     129             :               "set 'check_boundary_restricted = false'.\nRefer to the AuxKernel "
     130             :               "documentation on boundary restricted aux kernels for understanding this error.");
     131             :       }
     132             :     }
     133        1364 :   }
     134             : 
     135             :   // Check for supported variable types
     136             :   // Any 'nodal' family that actually has DoFs outside of nodes, or gradient dofs at nodes is
     137             :   // not properly set by AuxKernelTempl::compute
     138             :   // NOTE: We could add a few exceptions, lower order from certain unsupported families and on
     139             :   //       certain element types only have value-DoFs on nodes
     140       76416 :   const auto type = _var.feType();
     141       76416 :   if (_var.isNodal() && !((type.family == LAGRANGE) || (type.order <= FIRST)))
     142           0 :     paramError("variable",
     143           0 :                "Variable family " + Moose::stringify(type.family) + " is not supported at order " +
     144           0 :                    Moose::stringify(type.order) + " by the AuxKernel system.");
     145       76416 : }
     146             : 
     147             : #ifdef MOOSE_KOKKOS_ENABLED
     148       17319 : AuxKernelBase::AuxKernelBase(const AuxKernelBase & object, const Moose::Kokkos::FunctorCopy & key)
     149             :   : MooseObject(object, key),
     150             :     BlockRestrictable(object, key),
     151             :     BoundaryRestrictable(object, key),
     152             :     SetupInterface(object, key),
     153             :     CoupleableMooseVariableDependencyIntermediateInterface(object, key),
     154             :     FunctionInterface(object, key),
     155             :     UserObjectInterface(object, key),
     156             :     TransientInterface(object, key),
     157             :     MaterialPropertyInterface(object, key),
     158             :     PostprocessorInterface(object, key),
     159             :     DependencyResolverInterface(object, key),
     160             :     RandomInterface(object, key),
     161             :     GeometricSearchInterface(object, key),
     162             :     Restartable(object, key),
     163             :     MeshChangedInterface(object, key),
     164             :     VectorPostprocessorInterface(object, key),
     165             :     ElementIDInterface(object, key),
     166             :     NonADFunctorInterface(object, key),
     167             : 
     168       17319 :     _var(object._var),
     169       17319 :     _bnd(object._bnd),
     170       17319 :     _check_boundary_restricted(object._check_boundary_restricted),
     171       17319 :     _coincident_lower_d_calc(object._coincident_lower_d_calc),
     172       17319 :     _subproblem(object._subproblem),
     173       17319 :     _sys(object._sys),
     174       17319 :     _nl_sys(object._nl_sys),
     175       17319 :     _aux_sys(object._aux_sys),
     176       17319 :     _tid(object._tid),
     177       17319 :     _assembly(object._assembly),
     178       17319 :     _mesh(object._mesh)
     179             : {
     180       17319 : }
     181             : #endif
     182             : 
     183             : const std::set<std::string> &
     184      248290 : AuxKernelBase::getRequestedItems()
     185             : {
     186      248290 :   return _depend_vars;
     187             : }
     188             : 
     189             : const std::set<std::string> &
     190      248290 : AuxKernelBase::getSuppliedItems()
     191             : {
     192      248290 :   return _supplied_vars;
     193             : }
     194             : 
     195             : void
     196        9136 : AuxKernelBase::coupledCallback(const std::string & var_name, bool is_old) const
     197             : {
     198        9136 :   if (!is_old)
     199             :   {
     200        8902 :     const auto & var_names = getParam<std::vector<VariableName>>(var_name);
     201        8902 :     _depend_vars.insert(var_names.begin(), var_names.end());
     202             :   }
     203        9136 : }
     204             : 
     205             : void
     206        5424 : AuxKernelBase::addUserObjectDependencyHelper(const UserObject & uo) const
     207             : {
     208        5424 :   _depend_uo.insert(uo.name());
     209        5504 :   for (const auto & indirect_dependent : uo.getDependObjects())
     210        5504 :     _depend_uo.insert(indirect_dependent);
     211        5424 : }
     212             : 
     213             : void
     214         235 : AuxKernelBase::addPostprocessorDependencyHelper(const PostprocessorName & name) const
     215             : {
     216         235 :   getUserObjectBaseByName(name); // getting the UO will call addUserObjectDependencyHelper()
     217         235 : }
     218             : 
     219             : void
     220         250 : AuxKernelBase::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
     221             : {
     222         250 :   getUserObjectBaseByName(name); // getting the UO will call addUserObjectDependencyHelper()
     223         250 : }
     224             : 
     225             : MooseVariableFieldBase &
     226      305684 : AuxKernelBase::getVariableHelper(const InputParameters & parameters)
     227             : {
     228     1222728 :   return parameters.getCheckedPointerParam<SystemBase *>("_sys")->getVariable(
     229      611364 :       parameters.get<THREAD_ID>("_tid"), parameters.get<AuxVariableName>("variable"));
     230             : }

Generated by: LCOV version 1.14