LCOV - code coverage report
Current view: top level - src/userobjects - UserObjectInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 863ef6 Lines: 57 61 93.4 %
Date: 2025-10-15 18:16:15 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       59644 : UserObjectInterface::validParams()
      20             : {
      21       59644 :   return emptyInputParameters();
      22             : }
      23             : 
      24      569637 : UserObjectInterface::UserObjectInterface(const MooseObject * moose_object)
      25      569637 :   : _uoi_moose_object(*moose_object),
      26     1708911 :     _uoi_feproblem(*_uoi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>(
      27             :         "_fe_problem_base")),
      28      569637 :     _uoi_tid(_uoi_moose_object.parameters().have_parameter<THREAD_ID>("_tid")
      29      569637 :                  ? _uoi_moose_object.parameters().get<THREAD_ID>("_tid")
      30      569637 :                  : 0)
      31             : {
      32      569637 : }
      33             : 
      34             : #ifdef MOOSE_KOKKOS_ENABLED
      35      200105 : UserObjectInterface::UserObjectInterface(const UserObjectInterface & object,
      36      200105 :                                          const Moose::Kokkos::FunctorCopy &)
      37      200105 :   : _uoi_moose_object(object._uoi_moose_object),
      38      200105 :     _uoi_feproblem(object._uoi_feproblem),
      39      200105 :     _uoi_tid(object._uoi_tid)
      40             : {
      41      200105 : }
      42             : #endif
      43             : 
      44             : UserObjectName
      45        8015 : UserObjectInterface::getUserObjectName(const std::string & param_name) const
      46             : {
      47        8015 :   const auto & params = _uoi_moose_object.parameters();
      48             : 
      49        8015 :   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        8011 :   UserObjectName name;
      59        8011 :   if (params.isType<UserObjectName>(param_name))
      60        8007 :     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        8007 :   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       16645 : UserObjectInterface::hasUserObjectByName(const UserObjectName & object_name) const
      85             : {
      86       16645 :   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        7965 : UserObjectInterface::getUserObjectBase(const std::string & param_name,
      97             :                                        const bool is_dependency) const
      98             : {
      99        7965 :   const auto object_name = getUserObjectName(param_name);
     100        7957 :   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       15906 :   return getUserObjectBaseByName(object_name, is_dependency);
     105        7953 : }
     106             : 
     107             : const UserObject &
     108        8572 : UserObjectInterface::getUserObjectBaseByName(const UserObjectName & object_name,
     109             :                                              const bool is_dependency) const
     110             : {
     111        8572 :   if (!hasUserObjectByName(object_name))
     112           4 :     _uoi_moose_object.mooseError(
     113             :         "The requested UserObject with the name \"", object_name, "\" was not found.");
     114             : 
     115        8568 :   const auto & uo_base_tid0 = _uoi_feproblem.getUserObjectBase(object_name, /* tid = */ 0);
     116        8568 :   if (is_dependency)
     117        8536 :     addUserObjectDependencyHelper(uo_base_tid0);
     118             : 
     119        8568 :   const THREAD_ID tid = uo_base_tid0.needThreadedCopy() ? _uoi_tid : 0;
     120        8568 :   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