LCOV - code coverage report
Current view: top level - src/transfers - ReporterTransferInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 92 112 82.1 %
Date: 2025-07-17 01:28:37 Functions: 15 16 93.8 %
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 "ReporterTransferInterface.h"
      11             : 
      12             : #include "UserObject.h"
      13             : #include "Reporter.h"
      14             : #include "Transfer.h"
      15             : 
      16             : InputParameters
      17       29704 : ReporterTransferInterface::validParams()
      18             : {
      19       29704 :   InputParameters params = emptyInputParameters();
      20       29704 :   return params;
      21             : }
      22             : 
      23         559 : ReporterTransferInterface::ReporterTransferInterface(const Transfer * transfer)
      24         559 :   : _rti_transfer(*transfer)
      25             : {
      26         559 : }
      27             : 
      28             : void
      29        1567 : ReporterTransferInterface::addReporterTransferMode(const ReporterName & name,
      30             :                                                    const ReporterMode & mode,
      31             :                                                    FEProblemBase & problem)
      32             : {
      33        1567 :   checkHasReporterValue(name, problem);
      34        1567 :   problem.getReporterData(ReporterData::WriteKey())
      35        1567 :       .getReporterStateBase(name)
      36        1567 :       .addConsumer(mode, _rti_transfer);
      37        1567 : }
      38             : 
      39             : void
      40        2768 : ReporterTransferInterface::transferReporter(const ReporterName & from_reporter,
      41             :                                             const ReporterName & to_reporter,
      42             :                                             const FEProblemBase & from_problem,
      43             :                                             FEProblemBase & to_problem,
      44             :                                             unsigned int time_index)
      45             : {
      46        2768 :   checkHasReporterValue(from_reporter, from_problem);
      47        2768 :   checkHasReporterValue(to_reporter, to_problem);
      48        2768 :   from_problem.getReporterData()
      49        2768 :       .getReporterContextBase(from_reporter)
      50        2768 :       .transfer(to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, time_index);
      51        2768 : }
      52             : 
      53             : void
      54         608 : ReporterTransferInterface::transferToVectorReporter(const ReporterName & from_reporter,
      55             :                                                     const ReporterName & to_reporter,
      56             :                                                     const FEProblemBase & from_problem,
      57             :                                                     FEProblemBase & to_problem,
      58             :                                                     dof_id_type index,
      59             :                                                     unsigned int time_index)
      60             : {
      61         608 :   checkHasReporterValue(from_reporter, from_problem);
      62         608 :   checkHasReporterValue(to_reporter, to_problem);
      63         608 :   from_problem.getReporterData()
      64         608 :       .getReporterContextBase(from_reporter)
      65         608 :       .transferToVector(
      66             :           to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, index, time_index);
      67         608 : }
      68             : 
      69             : void
      70         192 : ReporterTransferInterface::transferFromVectorReporter(const ReporterName & from_reporter,
      71             :                                                       const ReporterName & to_reporter,
      72             :                                                       const FEProblemBase & from_problem,
      73             :                                                       FEProblemBase & to_problem,
      74             :                                                       dof_id_type index,
      75             :                                                       unsigned int time_index)
      76             : {
      77         192 :   checkHasReporterValue(from_reporter, from_problem);
      78         192 :   checkHasReporterValue(to_reporter, to_problem);
      79         192 :   from_problem.getReporterData()
      80         192 :       .getReporterContextBase(from_reporter)
      81         192 :       .transferFromVector(
      82             :           to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, index, time_index);
      83         192 : }
      84             : 
      85             : void
      86         666 : ReporterTransferInterface::hideVariableHelper(const ReporterName & reporter,
      87             :                                               FEProblemBase & problem)
      88             : {
      89         666 :   if (problem.hasUserObject(reporter.getObjectName()))
      90             :   {
      91             :     Reporter * rep =
      92         666 :         dynamic_cast<Reporter *>(&problem.getUserObject<UserObject>(reporter.getObjectName()));
      93         666 :     if (rep)
      94        1332 :       rep->buildOutputHideVariableList({reporter.getCombinedName()});
      95             :   }
      96        1332 : }
      97             : 
      98             : void
      99         189 : ReporterTransferInterface::declareClone(const ReporterName & from_reporter,
     100             :                                         const ReporterName & to_reporter,
     101             :                                         const FEProblemBase & from_problem,
     102             :                                         FEProblemBase & to_problem,
     103             :                                         const ReporterMode & mode)
     104             : {
     105         189 :   checkHasReporterValue(from_reporter, from_problem);
     106         189 :   from_problem.getReporterData()
     107         189 :       .getReporterContextBase(from_reporter)
     108         189 :       .declareClone(
     109         189 :           to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, mode, _rti_transfer);
     110             : 
     111             :   // Hide variables (if requested in parameters) if name is associated with a reporter object
     112         189 :   hideVariableHelper(to_reporter, to_problem);
     113         189 : }
     114             : 
     115             : void
     116           0 : ReporterTransferInterface::declareClone(const ReporterName & rname,
     117             :                                         FEProblemBase & problem,
     118             :                                         const std::string & type,
     119             :                                         const ReporterMode & mode)
     120             : {
     121           0 :   ReporterData & rdata = problem.getReporterData(ReporterData::WriteKey());
     122           0 :   if (type == "bool")
     123           0 :     rdata.declareReporterValue<bool, ReporterGeneralContext<bool>>(rname, mode, _rti_transfer);
     124           0 :   else if (type == "integer")
     125           0 :     rdata.declareReporterValue<int, ReporterGeneralContext<int>>(rname, mode, _rti_transfer);
     126           0 :   else if (type == "real")
     127           0 :     rdata.declareReporterValue<Real, ReporterGeneralContext<Real>>(rname, mode, _rti_transfer);
     128           0 :   else if (type == "string")
     129           0 :     rdata.declareReporterValue<std::string, ReporterGeneralContext<std::string>>(
     130           0 :         rname, mode, _rti_transfer);
     131             :   else
     132           0 :     _rti_transfer.mooseError("Unknown reporter type, ", type, ".");
     133             : 
     134             :   // Hide variables (if requested in parameters) if name is associated with a reporter object
     135           0 :   hideVariableHelper(rname, problem);
     136           0 : }
     137             : 
     138             : void
     139         423 : ReporterTransferInterface::declareVectorClone(const ReporterName & from_reporter,
     140             :                                               const ReporterName & to_reporter,
     141             :                                               const FEProblemBase & from_problem,
     142             :                                               FEProblemBase & to_problem,
     143             :                                               const ReporterMode & mode)
     144             : {
     145         423 :   checkHasReporterValue(from_reporter, from_problem);
     146         423 :   from_problem.getReporterData()
     147         423 :       .getReporterContextBase(from_reporter)
     148         423 :       .declareVectorClone(
     149         423 :           to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, mode, _rti_transfer);
     150             : 
     151             :   // Hide variables (if requested in parameters) if name is associated with a reporter object
     152         423 :   hideVariableHelper(to_reporter, to_problem);
     153         423 : }
     154             : 
     155             : void
     156          54 : ReporterTransferInterface::declareVectorClone(const ReporterName & rname,
     157             :                                               FEProblemBase & problem,
     158             :                                               const std::string & type,
     159             :                                               const ReporterMode & mode)
     160             : {
     161          54 :   ReporterData & rdata = problem.getReporterData(ReporterData::WriteKey());
     162          54 :   if (type == "bool")
     163           0 :     rdata.declareReporterValue<std::vector<bool>, ReporterVectorContext<bool>>(
     164           0 :         rname, mode, _rti_transfer);
     165          54 :   else if (type == "integer")
     166          18 :     rdata.declareReporterValue<std::vector<int>, ReporterVectorContext<int>>(
     167          18 :         rname, mode, _rti_transfer);
     168          36 :   else if (type == "real")
     169          18 :     rdata.declareReporterValue<std::vector<Real>, ReporterVectorContext<Real>>(
     170          18 :         rname, mode, _rti_transfer);
     171          18 :   else if (type == "string")
     172          18 :     rdata.declareReporterValue<std::vector<std::string>, ReporterVectorContext<std::string>>(
     173          18 :         rname, mode, _rti_transfer);
     174             :   else
     175           0 :     _rti_transfer.mooseError("Unknown reporter type, ", type, ".");
     176             : 
     177             :   // Hide variables (if requested in parameters) if name is associated with a reporter object
     178          54 :   hideVariableHelper(rname, problem);
     179          54 : }
     180             : 
     181             : void
     182         453 : ReporterTransferInterface::resizeReporter(const ReporterName & name,
     183             :                                           FEProblemBase & problem,
     184             :                                           dof_id_type n)
     185             : {
     186         453 :   checkHasReporterValue(name, problem);
     187         453 :   problem.getReporterData(ReporterData::WriteKey()).getReporterContextBase(name).resize(n);
     188         453 : }
     189             : void
     190          66 : ReporterTransferInterface::clearVectorReporter(const ReporterName & name, FEProblemBase & problem)
     191             : {
     192          66 :   checkHasReporterValue(name, problem);
     193          66 :   problem.getReporterData(ReporterData::WriteKey()).getReporterContextBase(name).clear();
     194          66 : }
     195             : 
     196             : void
     197          66 : ReporterTransferInterface::sumVectorReporter(const ReporterName & name, FEProblemBase & problem)
     198             : {
     199          66 :   checkHasReporterValue(name, problem);
     200          66 :   problem.getReporterData(ReporterData::WriteKey()).getReporterContextBase(name).vectorSum();
     201          66 : }
     202             : 
     203             : std::vector<ReporterName>
     204         243 : ReporterTransferInterface::getReporterNamesHelper(std::string prefix,
     205             :                                                   const std::string & obj_name,
     206             :                                                   const std::vector<ReporterName> & rep_names)
     207             : {
     208         243 :   if (!prefix.empty())
     209         243 :     prefix += ":";
     210         243 :   std::vector<ReporterName> rnames;
     211         243 :   rnames.reserve(rep_names.size());
     212         909 :   for (const auto & rn : rep_names)
     213         666 :     rnames.emplace_back(obj_name, prefix + rn.getObjectName() + ":" + rn.getValueName());
     214         243 :   return rnames;
     215           0 : }
     216             : 
     217             : void
     218        9900 : ReporterTransferInterface::checkHasReporterValue(const ReporterName & reporter,
     219             :                                                  const FEProblemBase & problem) const
     220             : {
     221        9900 :   if (!problem.getReporterData().hasReporterValue(reporter))
     222           0 :     _rti_transfer.mooseError("Reporter with the name \"",
     223             :                              reporter,
     224             :                              "\" within app \"",
     225           0 :                              problem.getMooseApp().name(),
     226             :                              "\" was not found.");
     227        9900 : }

Generated by: LCOV version 1.14