LCOV - code coverage report
Current view: top level - src/userobjects - UserObject.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 59 64 92.2 %
Date: 2025-07-17 01:28:37 Functions: 8 9 88.9 %
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 "UserObject.h"
      11             : #include "SubProblem.h"
      12             : #include "Assembly.h"
      13             : #include "NonlinearSystemBase.h"
      14             : 
      15             : #include "libmesh/sparse_matrix.h"
      16             : 
      17             : InputParameters
      18     9560974 : UserObject::validParams()
      19             : {
      20     9560974 :   InputParameters params = MooseObject::validParams();
      21     9560974 :   params += ReporterInterface::validParams();
      22             : 
      23             :   // Add the SetupInterface parameter, 'execute_on', and set it to a default of 'timestep_end'
      24     9560974 :   params += SetupInterface::validParams();
      25     9560974 :   params.set<ExecFlagEnum>("execute_on", true) = EXEC_TIMESTEP_END;
      26             : 
      27    28682922 :   params.addParam<bool>("use_displaced_mesh",
      28    19121948 :                         false,
      29             :                         "Whether or not this object should use the "
      30             :                         "displaced mesh for computation.  Note that "
      31             :                         "in the case this is true but no "
      32             :                         "displacements are provided in the Mesh block "
      33             :                         "the undisplaced mesh will still be used.");
      34             : 
      35             :   // Execution parameters
      36    28682922 :   params.addParam<bool>("allow_duplicate_execution_on_initial",
      37    19121948 :                         false,
      38             :                         "In the case where this UserObject is depended upon by an initial "
      39             :                         "condition, allow it to be executed twice during the initial setup (once "
      40             :                         "before the IC and again after mesh adaptivity (if applicable).");
      41     9560974 :   params.declareControllable("enable");
      42             : 
      43     9560974 :   params.addParam<bool>("force_preaux", false, "Forces the UserObject to be executed in PREAUX");
      44     9560974 :   params.addParam<bool>("force_postaux", false, "Forces the UserObject to be executed in POSTAUX");
      45    28682922 :   params.addParam<bool>(
      46    19121948 :       "force_preic", false, "Forces the UserObject to be executed in PREIC during initial setup");
      47    28682922 :   params.addParam<int>(
      48             :       "execution_order_group",
      49    19121948 :       0,
      50             :       "Execution order groups are executed in increasing order (e.g., the lowest "
      51             :       "number is executed first). Note that negative group numbers may be used to execute groups "
      52             :       "before the default (0) group. Please refer to the user object documentation "
      53             :       "for ordering of user object execution within a group.");
      54             : 
      55     9560974 :   params.registerBase("UserObject");
      56     9560974 :   params.registerSystemAttributeName("UserObject");
      57             : 
      58     9560974 :   params.addParamNamesToGroup("execute_on force_preaux force_postaux force_preic "
      59             :                               "allow_duplicate_execution_on_initial execution_order_group",
      60             :                               "Execution scheduling");
      61     9560974 :   params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
      62     9560974 :   return params;
      63           0 : }
      64             : 
      65       74191 : UserObject::UserObject(const InputParameters & parameters)
      66             :   : MooseObject(parameters),
      67             :     SetupInterface(this),
      68             :     FunctionInterface(this),
      69             :     UserObjectInterface(this),
      70             :     PostprocessorInterface(this),
      71             :     VectorPostprocessorInterface(this),
      72             :     ReporterInterface(this),
      73             :     DistributionInterface(this),
      74             :     SamplerInterface(this),
      75             :     Restartable(this, "UserObjects"),
      76             :     MeshMetaDataInterface(this),
      77             :     MeshChangedInterface(parameters),
      78             :     MeshDisplacedInterface(parameters),
      79             :     PerfGraphInterface(this),
      80       74191 :     _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
      81       74191 :     _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
      82       74191 :     _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
      83       74191 :     _tid(parameters.get<THREAD_ID>("_tid")),
      84       74191 :     _assembly(_subproblem.assembly(_tid, 0)),
      85       74191 :     _coord_sys(_assembly.coordSystem()),
      86      148382 :     _duplicate_initial_execution(getParam<bool>("allow_duplicate_execution_on_initial"))
      87             : {
      88             :   // Check the pre/post aux flag
      89       74191 :   if (getParam<bool>("force_preaux") && getParam<bool>("force_postaux"))
      90           0 :     paramError("force_preaux",
      91             :                "A user object may be specified as executing before or after "
      92             :                "AuxKernels, not both.");
      93             : 
      94       74191 :   _supplied_uo.insert(name());
      95       74191 : }
      96             : 
      97             : std::set<UserObjectName>
      98        5011 : UserObject::getDependObjects() const
      99             : {
     100        5011 :   std::set<UserObjectName> all;
     101        5086 :   for (auto & v : _depend_uo)
     102             :   {
     103          75 :     all.insert(v);
     104          75 :     auto & uo = UserObjectInterface::getUserObjectBaseByName(v);
     105             : 
     106             :     // Add dependencies of other objects, but don't allow it to call itself. This can happen
     107             :     // through the PostprocessorInterface if a Postprocessor calls getPostprocessorValueByName
     108             :     // with it's own name. This happens in the Receiver, which could use the FEProblem version of
     109             :     // the get method, but this is a fix that prevents an infinite loop occurring by accident for
     110             :     // future objects.
     111          75 :     if (uo.name() != name())
     112             :     {
     113          75 :       auto uos = uo.getDependObjects();
     114          88 :       for (auto & t : uos)
     115          13 :         all.insert(t);
     116          75 :     }
     117             :   }
     118        5011 :   return all;
     119           0 : }
     120             : 
     121             : void
     122        1088 : UserObject::addUserObjectDependencyHelper(const UserObject & uo) const
     123             : {
     124        1088 :   _depend_uo.insert(uo.name());
     125        1088 : }
     126             : 
     127             : void
     128        7554 : UserObject::addPostprocessorDependencyHelper(const PostprocessorName & name) const
     129             : {
     130        7554 :   _depend_uo.insert(name);
     131        7554 : }
     132             : 
     133             : void
     134        1831 : UserObject::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
     135             : {
     136        1831 :   _depend_uo.insert(name);
     137        1831 : }
     138             : 
     139             : void
     140         392 : UserObject::addReporterDependencyHelper(const ReporterName & reporter_name)
     141             : {
     142         392 :   _depend_uo.insert(reporter_name.getObjectName());
     143         392 : }
     144             : 
     145             : void
     146        3414 : UserObject::setPrimaryThreadCopy(UserObject * primary)
     147             : {
     148        3414 :   if (!_primary_thread_copy && primary != this)
     149        3414 :     _primary_thread_copy = primary;
     150        3414 : }
     151             : 
     152             : unsigned int
     153           0 : UserObject::systemNumber() const
     154             : {
     155           0 :   return _sys.number();
     156             : }

Generated by: LCOV version 1.14