LCOV - code coverage report
Current view: top level - src/userobjects - UserObjectInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 57 61 93.4 %
Date: 2025-11-03 17:23:24 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       60124 : UserObjectInterface::validParams()
      20             : {
      21       60124 :   return emptyInputParameters();
      22             : }
      23             : 
      24      571507 : UserObjectInterface::UserObjectInterface(const MooseObject * moose_object)
      25      571507 :   : _uoi_moose_object(*moose_object),
      26     1714521 :     _uoi_feproblem(*_uoi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>(
      27             :         "_fe_problem_base")),
      28      571507 :     _uoi_tid(_uoi_moose_object.parameters().have_parameter<THREAD_ID>("_tid")
      29      571507 :                  ? _uoi_moose_object.parameters().get<THREAD_ID>("_tid")
      30      571507 :                  : 0)
      31             : {
      32      571507 : }
      33             : 
      34             : #ifdef MOOSE_KOKKOS_ENABLED
      35      223399 : UserObjectInterface::UserObjectInterface(const UserObjectInterface & object,
      36      223399 :                                          const Moose::Kokkos::FunctorCopy &)
      37      223399 :   : _uoi_moose_object(object._uoi_moose_object),
      38      223399 :     _uoi_feproblem(object._uoi_feproblem),
      39      223399 :     _uoi_tid(object._uoi_tid)
      40             : {
      41      223399 : }
      42             : #endif
      43             : 
      44             : UserObjectName
      45        8031 : UserObjectInterface::getUserObjectName(const std::string & param_name) const
      46             : {
      47        8031 :   const auto & params = _uoi_moose_object.parameters();
      48             : 
      49        8031 :   if (!params.isParamValid(param_name))
      50           4 :     _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           4 :                                  _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        8027 :   UserObjectName name;
      59        8027 :   if (params.isType<UserObjectName>(param_name))
      60        8023 :     name = params.get<UserObjectName>(param_name);
      61           4 :   else if (params.isType<PostprocessorName>(param_name))
      62           0 :     name = params.get<PostprocessorName>(param_name);
      63           4 :   else if (params.isType<VectorPostprocessorName>(param_name))
      64           0 :     name = params.get<VectorPostprocessorName>(param_name);
      65           4 :   else if (params.isType<std::string>(param_name))
      66           0 :     name = params.get<std::string>(param_name);
      67             :   else
      68           4 :     _uoi_moose_object.paramError(
      69             :         param_name,
      70             :         "Parameter of type \"",
      71           4 :         params.type(param_name),
      72             :         "\" is not an expected type for getting the name of a UserObject.");
      73             : 
      74        8023 :   return name;
      75           0 : }
      76             : 
      77             : bool
      78          20 : UserObjectInterface::hasUserObject(const std::string & param_name) const
      79             : {
      80          20 :   return hasUserObjectByName(getUserObjectName(param_name));
      81             : }
      82             : 
      83             : bool
      84       16689 : UserObjectInterface::hasUserObjectByName(const UserObjectName & object_name) const
      85             : {
      86       16689 :   return _uoi_feproblem.hasUserObject(object_name);
      87             : }
      88             : 
      89             : const UserObject &
      90          76 : UserObjectInterface::getUserObjectFromFEProblem(const UserObjectName & object_name) const
      91             : {
      92          76 :   return _uoi_feproblem.getUserObjectBase(object_name);
      93             : }
      94             : 
      95             : const UserObject &
      96        7981 : UserObjectInterface::getUserObjectBase(const std::string & param_name,
      97             :                                        const bool is_dependency) const
      98             : {
      99        7981 :   const auto object_name = getUserObjectName(param_name);
     100        7973 :   if (!hasUserObjectByName(object_name))
     101           4 :     _uoi_moose_object.paramError(
     102             :         param_name, "The requested UserObject with the name \"", object_name, "\" was not found.");
     103             : 
     104       15938 :   return getUserObjectBaseByName(object_name, is_dependency);
     105        7969 : }
     106             : 
     107             : const UserObject &
     108        8600 : UserObjectInterface::getUserObjectBaseByName(const UserObjectName & object_name,
     109             :                                              const bool is_dependency) const
     110             : {
     111        8600 :   if (!hasUserObjectByName(object_name))
     112           4 :     _uoi_moose_object.mooseError(
     113             :         "The requested UserObject with the name \"", object_name, "\" was not found.");
     114             : 
     115        8596 :   const auto & uo_base_tid0 = _uoi_feproblem.getUserObjectBase(object_name, /* tid = */ 0);
     116        8596 :   if (is_dependency)
     117        8564 :     addUserObjectDependencyHelper(uo_base_tid0);
     118             : 
     119        8596 :   const THREAD_ID tid = uo_base_tid0.needThreadedCopy() ? _uoi_tid : 0;
     120        8596 :   return _uoi_feproblem.getUserObjectBase(object_name, tid);
     121             : }
     122             : 
     123             : const std::string &
     124           8 : UserObjectInterface::userObjectType(const UserObject & uo) const
     125             : {
     126           8 :   return uo.type();
     127             : }
     128             : 
     129             : const std::string &
     130           8 : UserObjectInterface::userObjectName(const UserObject & uo) const
     131             : {
     132           8 :   return uo.name();
     133             : }
     134             : 
     135             : void
     136           8 : UserObjectInterface::mooseObjectError(const std::string & param_name, std::stringstream & oss) const
     137             : {
     138           8 :   if (_uoi_moose_object.parameters().isParamValid(param_name))
     139           4 :     _uoi_moose_object.paramError(param_name, oss.str());
     140             :   else
     141           4 :     _uoi_moose_object.mooseError(oss.str());
     142             : }

Generated by: LCOV version 1.14