LCOV - code coverage report
Current view: top level - src/userobjects - UserObjectInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 63 68 92.6 %
Date: 2026-05-29 20:35:17 Functions: 12 12 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 "UserObjectInterface.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "FEProblemBase.h"
      14             : #include "DiscreteElementUserObject.h"
      15             : #include "ThreadedGeneralUserObject.h"
      16             : #include "MooseObject.h"
      17             : 
      18             : InputParameters
      19       12725 : UserObjectInterface::validParams()
      20             : {
      21       12725 :   return emptyInputParameters();
      22             : }
      23             : 
      24      530971 : UserObjectInterface::UserObjectInterface(const MooseObject * moose_object)
      25      530971 :   : _uoi_moose_object(*moose_object),
      26     1592913 :     _uoi_feproblem(*_uoi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>(
      27             :         "_fe_problem_base")),
      28      530971 :     _uoi_tid(_uoi_moose_object.parameters().have_parameter<THREAD_ID>("_tid")
      29      530971 :                  ? _uoi_moose_object.parameters().get<THREAD_ID>("_tid")
      30      530971 :                  : 0)
      31             : {
      32      530971 : }
      33             : 
      34             : #ifdef MOOSE_KOKKOS_ENABLED
      35      534450 : UserObjectInterface::UserObjectInterface(const UserObjectInterface & object,
      36      534450 :                                          const Moose::Kokkos::FunctorCopy &)
      37      534450 :   : _uoi_moose_object(object._uoi_moose_object),
      38      534450 :     _uoi_feproblem(object._uoi_feproblem),
      39      534450 :     _uoi_tid(object._uoi_tid)
      40             : {
      41      534450 : }
      42             : #endif
      43             : 
      44             : UserObjectName
      45        6271 : UserObjectInterface::getUserObjectName(const std::string & param_name) const
      46             : {
      47        6271 :   const auto & params = _uoi_moose_object.parameters();
      48             : 
      49        6271 :   if (!params.isParamValid(param_name))
      50           3 :     _uoi_moose_object.mooseError("Failed to get a parameter with the name \"",
      51             :                                  param_name,
      52             :                                  "\" when getting a UserObjectName.",
      53             :                                  "\n\nKnown parameters:\n",
      54           3 :                                  _uoi_moose_object.parameters());
      55             : 
      56             :   // Other interfaces will use this interface (PostprocessorInterface, VectorPostprocessorInterface)
      57             :   // to grab UOs with a specialized name, so we need to check them all
      58        6268 :   UserObjectName name;
      59        6268 :   if (params.isType<UserObjectName>(param_name))
      60        6265 :     name = params.get<UserObjectName>(param_name);
      61           3 :   else if (params.isType<PostprocessorName>(param_name))
      62           0 :     name = params.get<PostprocessorName>(param_name);
      63           3 :   else if (params.isType<VectorPostprocessorName>(param_name))
      64           0 :     name = params.get<VectorPostprocessorName>(param_name);
      65           3 :   else if (params.isType<std::string>(param_name))
      66           0 :     name = params.get<std::string>(param_name);
      67             :   else
      68           3 :     _uoi_moose_object.paramError(
      69             :         param_name,
      70             :         "Parameter of type \"",
      71           3 :         params.type(param_name),
      72             :         "\" is not an expected type for getting the name of a UserObject.");
      73             : 
      74        6265 :   return name;
      75           0 : }
      76             : 
      77             : bool
      78          18 : UserObjectInterface::hasUserObject(const std::string & param_name) const
      79             : {
      80          18 :   return hasUserObjectByName(getUserObjectName(param_name));
      81             : }
      82             : 
      83             : bool
      84       13297 : UserObjectInterface::hasUserObjectByName(const UserObjectName & object_name) const
      85             : {
      86       13297 :   bool flag = _uoi_feproblem.hasUserObject(object_name);
      87             : 
      88             : #ifdef MOOSE_KOKKOS_ENABLED
      89       10237 :   flag = flag || _uoi_feproblem.hasKokkosUserObject(object_name);
      90             : #endif
      91             : 
      92       13297 :   return flag;
      93             : }
      94             : 
      95             : const UserObjectBase &
      96       13657 : UserObjectInterface::getUserObjectFromFEProblem(const UserObjectName & object_name,
      97             :                                                 const THREAD_ID tid) const
      98             : {
      99       13657 :   const UserObjectBase * uo = nullptr;
     100             : 
     101       13657 :   if (_uoi_feproblem.hasUserObject(object_name))
     102       13657 :     uo = &_uoi_feproblem.getUserObjectBase(object_name, tid);
     103             : 
     104             : #ifdef MOOSE_KOKKOS_ENABLED
     105       10524 :   if (_uoi_feproblem.hasKokkosUserObject(object_name))
     106           0 :     uo = &_uoi_feproblem.getKokkosUserObject<UserObjectBase>(object_name);
     107             : #endif
     108             : 
     109             :   mooseAssert(uo, "getUserObjectFromFEProblem() could not find user object");
     110             : 
     111       13657 :   return *uo;
     112             : }
     113             : 
     114             : const UserObjectBase &
     115        6226 : UserObjectInterface::getUserObjectBase(const std::string & param_name,
     116             :                                        const bool is_dependency) const
     117             : {
     118        6226 :   const auto object_name = getUserObjectName(param_name);
     119        6220 :   if (!hasUserObjectByName(object_name))
     120           3 :     _uoi_moose_object.paramError(
     121             :         param_name, "The requested UserObject with the name \"", object_name, "\" was not found.");
     122             : 
     123       12434 :   return getUserObjectBaseByName(object_name, is_dependency);
     124        6217 : }
     125             : 
     126             : const UserObjectBase &
     127        6797 : UserObjectInterface::getUserObjectBaseByName(const UserObjectName & object_name,
     128             :                                              const bool is_dependency) const
     129             : {
     130        6797 :   if (!hasUserObjectByName(object_name))
     131           3 :     _uoi_moose_object.mooseError(
     132             :         "The requested UserObject with the name \"", object_name, "\" was not found.");
     133             : 
     134        6794 :   const auto & uo_base_tid0 = getUserObjectFromFEProblem(object_name);
     135        6794 :   if (is_dependency)
     136        6786 :     addUserObjectDependencyHelper(uo_base_tid0);
     137             : 
     138        6794 :   const THREAD_ID tid = uo_base_tid0.needThreadedCopy() ? _uoi_tid : 0;
     139        6794 :   return getUserObjectFromFEProblem(object_name, tid);
     140             : }
     141             : 
     142             : const std::string &
     143           6 : UserObjectInterface::userObjectType(const UserObjectBase & uo) const
     144             : {
     145           6 :   return uo.type();
     146             : }
     147             : 
     148             : const std::string &
     149           6 : UserObjectInterface::userObjectName(const UserObjectBase & uo) const
     150             : {
     151           6 :   return uo.name();
     152             : }
     153             : 
     154             : void
     155           6 : UserObjectInterface::mooseObjectError(const std::string & param_name, std::stringstream & oss) const
     156             : {
     157           6 :   if (_uoi_moose_object.parameters().isParamValid(param_name))
     158           3 :     _uoi_moose_object.paramError(param_name, oss.str());
     159             :   else
     160           3 :     _uoi_moose_object.mooseError(oss.str());
     161             : }

Generated by: LCOV version 1.14