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

Generated by: LCOV version 1.14