LCOV - code coverage report
Current view: top level - src/transfers - MultiAppCloneReporterTransfer.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 77 88 87.5 %
Date: 2025-08-08 20:01:16 Functions: 5 6 83.3 %
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 "MultiAppCloneReporterTransfer.h"
      11             : #include "MultiApp.h"
      12             : #include "UserObject.h"
      13             : #include "Reporter.h"
      14             : 
      15             : registerMooseObject("MooseApp", MultiAppCloneReporterTransfer);
      16             : 
      17             : InputParameters
      18       14805 : MultiAppCloneReporterTransfer::validParams()
      19             : {
      20       14805 :   InputParameters params = MultiAppTransfer::validParams();
      21       14805 :   params += ReporterTransferInterface::validParams();
      22       14805 :   params.addClassDescription(
      23             :       "Declare and transfer reporter data from sub-application(s) to main application.");
      24       14805 :   params.addRequiredParam<std::vector<ReporterName>>(
      25             :       "from_reporters",
      26             :       "List of the reporter names (object_name/value_name) to transfer the value from.");
      27       14805 :   params.addRequiredParam<std::string>(
      28             :       "to_reporter", "Reporter object to reference when declaring reporter values.");
      29             : 
      30       14805 :   params.addParam<std::string>("prefix",
      31             :                                "Use the supplied string as the prefix for reporter "
      32             :                                "name rather than the transfer name.");
      33             : 
      34       44415 :   params.addParam<MultiMooseEnum>(
      35             :       "reporter_type",
      36       29610 :       standardTransferTypes(),
      37             :       "The type of the reporter on the sub-application. This parameter is not typically required, "
      38             :       "but if some processors do not have a sub-app, for instance if the max_procs_per_app "
      39             :       "parameter is used in the MultiApp, then this is required.");
      40             : 
      41       14805 :   params.suppressParameter<MultiMooseEnum>("direction");
      42       14805 :   return params;
      43           0 : }
      44             : 
      45         270 : MultiAppCloneReporterTransfer::MultiAppCloneReporterTransfer(const InputParameters & parameters)
      46             :   : MultiAppTransfer(parameters),
      47             :     ReporterTransferInterface(this),
      48         270 :     _from_reporter_names(getParam<std::vector<ReporterName>>("from_reporters")),
      49         270 :     _to_obj_name(getParam<std::string>("to_reporter")),
      50         540 :     _to_reporter_names(isParamValid("prefix")
      51         270 :                            ? getReporterNamesHelper(getParam<std::string>("prefix"),
      52             :                                                     _to_obj_name,
      53             :                                                     _from_reporter_names)
      54         540 :                            : getReporterNamesHelper(_name, _to_obj_name, _from_reporter_names))
      55             : {
      56             :   // Deprecating direction proves fatal for this parameter for this class
      57         270 :   if (isParamValid("multi_app"))
      58           0 :     paramError("multi_app",
      59             :                "The multi_app parameter is no longer valid for this class, use to_multi_app");
      60             : 
      61         270 :   if (isParamValid("to_multi_app"))
      62           0 :     paramError("to_multi_app",
      63             :                "Sibling or to_multiapp transfer have not been implemented for this transfer.");
      64         270 : }
      65             : 
      66             : void
      67         270 : MultiAppCloneReporterTransfer::initialSetup()
      68             : {
      69         270 :   MultiAppTransfer::initialSetup();
      70             : 
      71         270 :   if (isParamValid("to_multi_app") && !getToMultiApp()->hasApp() && !isParamValid("reporter_type"))
      72           0 :     mooseError("For a direct reporter clone, all processors must be associated with a "
      73             :                "sub-application. If you know the type of reporter being transferred, please "
      74             :                "consider using the 'reporter_type' parameter for an indirect clone.");
      75             : 
      76         560 :   if (isParamValid("from_multi_app") && !getFromMultiApp()->hasApp() &&
      77         290 :       !isParamValid("reporter_type"))
      78           0 :     mooseError("For a direct reporter clone, all processors must be associated with a "
      79             :                "sub-application. If you know the type of reporter being transferred, please "
      80             :                "consider using the 'reporter_type' parameter for an indirect clone.");
      81             : 
      82         270 :   const UserObject & uo = _fe_problem.getUserObjectBase(_to_obj_name);
      83         270 :   if (!dynamic_cast<const Reporter *>(&uo))
      84           0 :     paramError("to_reporter", "This object must be a Reporter object.");
      85             : 
      86         270 :   const auto multi_app = getMultiApp();
      87         270 :   const dof_id_type n = multi_app->numGlobalApps();
      88             : 
      89        1010 :   for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
      90        3070 :     for (MooseIndex(n) i = 0; i < n; i++)
      91        2330 :       if (multi_app->hasLocalApp(i))
      92        1660 :         addReporterTransferMode(
      93         830 :             _from_reporter_names[r], REPORTER_MODE_ROOT, multi_app->appProblemBase(i));
      94             : 
      95         270 :   if (multi_app->hasApp())
      96             :   {
      97         930 :     for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
      98        1210 :       for (MooseIndex(n) i = 0; i < n; i++)
      99        1210 :         if (multi_app->hasLocalApp(i))
     100             :         {
     101         680 :           if (n > 1)
     102         940 :             declareVectorClone(_from_reporter_names[r],
     103         470 :                                _to_reporter_names[r],
     104         470 :                                multi_app->appProblemBase(i),
     105             :                                multi_app->problemBase(),
     106             :                                REPORTER_MODE_DISTRIBUTED);
     107             :           else
     108         420 :             declareClone(_from_reporter_names[r],
     109         210 :                          _to_reporter_names[r],
     110         210 :                          multi_app->appProblemBase(i),
     111             :                          multi_app->problemBase(),
     112             :                          REPORTER_MODE_ROOT);
     113         680 :           break;
     114             :         }
     115             :   }
     116             :   else
     117             :   {
     118          20 :     const auto & types = getParam<MultiMooseEnum>("reporter_type");
     119          20 :     if (types.size() != _from_reporter_names.size())
     120           0 :       paramError("reporter_type", "This parameter must be the same length as 'from_reporters'");
     121          80 :     for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
     122             :     {
     123          60 :       if (n > 1)
     124         120 :         declareVectorClone(
     125          60 :             _to_reporter_names[r], multi_app->problemBase(), types[r], REPORTER_MODE_DISTRIBUTED);
     126             :       else
     127           0 :         declareClone(_to_reporter_names[r], multi_app->problemBase(), types[r], REPORTER_MODE_ROOT);
     128             :     }
     129             :   }
     130             : 
     131         270 :   if (n > 1 && multi_app->isRootProcessor())
     132         590 :     for (const auto & rn : _to_reporter_names)
     133         430 :       resizeReporter(rn, multi_app->problemBase(), multi_app->numLocalApps());
     134         270 : }
     135             : 
     136             : void
     137           0 : MultiAppCloneReporterTransfer::executeToMultiapp()
     138             : {
     139           0 : }
     140             : 
     141             : void
     142         243 : MultiAppCloneReporterTransfer::executeFromMultiapp()
     143             : {
     144         243 :   if (!getFromMultiApp()->isRootProcessor())
     145          81 :     return;
     146             : 
     147         162 :   const dof_id_type begin = getFromMultiApp()->firstLocalApp();
     148         162 :   const dof_id_type end = begin + getFromMultiApp()->numLocalApps();
     149             : 
     150         603 :   for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
     151         963 :     for (dof_id_type i = begin; i < end; ++i)
     152             :     {
     153         522 :       if (getFromMultiApp()->numGlobalApps() > 1)
     154         936 :         transferToVectorReporter(_from_reporter_names[r],
     155         468 :                                  _to_reporter_names[r],
     156         936 :                                  getFromMultiApp()->appProblemBase(i),
     157         936 :                                  getFromMultiApp()->problemBase(),
     158             :                                  i - begin);
     159             :       else
     160         108 :         transferReporter(_from_reporter_names[r],
     161          54 :                          _to_reporter_names[r],
     162         108 :                          getFromMultiApp()->appProblemBase(i),
     163         108 :                          getFromMultiApp()->problemBase());
     164             :     }
     165             : }
     166             : 
     167             : void
     168         243 : MultiAppCloneReporterTransfer::execute()
     169             : {
     170         243 :   TIME_SECTION("MultiAppCloneReporterTransfer::execute()", 5, "Transferring reporters");
     171             : 
     172         243 :   if (_current_direction == FROM_MULTIAPP)
     173         243 :     executeFromMultiapp();
     174             :   else
     175           0 :     executeToMultiapp();
     176         243 : }

Generated by: LCOV version 1.14