LCOV - code coverage report
Current view: top level - src/transfers - MultiAppCloneReporterTransfer.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 77 88 87.5 %
Date: 2025-07-17 01:28:37 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       14751 : MultiAppCloneReporterTransfer::validParams()
      19             : {
      20       14751 :   InputParameters params = MultiAppTransfer::validParams();
      21       14751 :   params += ReporterTransferInterface::validParams();
      22       14751 :   params.addClassDescription(
      23             :       "Declare and transfer reporter data from sub-application(s) to main application.");
      24       14751 :   params.addRequiredParam<std::vector<ReporterName>>(
      25             :       "from_reporters",
      26             :       "List of the reporter names (object_name/value_name) to transfer the value from.");
      27       14751 :   params.addRequiredParam<std::string>(
      28             :       "to_reporter", "Reporter object to reference when declaring reporter values.");
      29             : 
      30       14751 :   params.addParam<std::string>("prefix",
      31             :                                "Use the supplied string as the prefix for reporter "
      32             :                                "name rather than the transfer name.");
      33             : 
      34       44253 :   params.addParam<MultiMooseEnum>(
      35             :       "reporter_type",
      36       29502 :       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       14751 :   params.suppressParameter<MultiMooseEnum>("direction");
      42       14751 :   return params;
      43           0 : }
      44             : 
      45         243 : MultiAppCloneReporterTransfer::MultiAppCloneReporterTransfer(const InputParameters & parameters)
      46             :   : MultiAppTransfer(parameters),
      47             :     ReporterTransferInterface(this),
      48         243 :     _from_reporter_names(getParam<std::vector<ReporterName>>("from_reporters")),
      49         243 :     _to_obj_name(getParam<std::string>("to_reporter")),
      50         486 :     _to_reporter_names(isParamValid("prefix")
      51         243 :                            ? getReporterNamesHelper(getParam<std::string>("prefix"),
      52             :                                                     _to_obj_name,
      53             :                                                     _from_reporter_names)
      54         486 :                            : getReporterNamesHelper(_name, _to_obj_name, _from_reporter_names))
      55             : {
      56             :   // Deprecating direction proves fatal for this parameter for this class
      57         243 :   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         243 :   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         243 : }
      65             : 
      66             : void
      67         243 : MultiAppCloneReporterTransfer::initialSetup()
      68             : {
      69         243 :   MultiAppTransfer::initialSetup();
      70             : 
      71         243 :   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         504 :   if (isParamValid("from_multi_app") && !getFromMultiApp()->hasApp() &&
      77         261 :       !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         243 :   const UserObject & uo = _fe_problem.getUserObjectBase(_to_obj_name);
      83         243 :   if (!dynamic_cast<const Reporter *>(&uo))
      84           0 :     paramError("to_reporter", "This object must be a Reporter object.");
      85             : 
      86         243 :   const auto multi_app = getMultiApp();
      87         243 :   const dof_id_type n = multi_app->numGlobalApps();
      88             : 
      89         909 :   for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
      90        2763 :     for (MooseIndex(n) i = 0; i < n; i++)
      91        2097 :       if (multi_app->hasLocalApp(i))
      92        1494 :         addReporterTransferMode(
      93         747 :             _from_reporter_names[r], REPORTER_MODE_ROOT, multi_app->appProblemBase(i));
      94             : 
      95         243 :   if (multi_app->hasApp())
      96             :   {
      97         837 :     for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
      98        1089 :       for (MooseIndex(n) i = 0; i < n; i++)
      99        1089 :         if (multi_app->hasLocalApp(i))
     100             :         {
     101         612 :           if (n > 1)
     102         846 :             declareVectorClone(_from_reporter_names[r],
     103         423 :                                _to_reporter_names[r],
     104         423 :                                multi_app->appProblemBase(i),
     105             :                                multi_app->problemBase(),
     106             :                                REPORTER_MODE_DISTRIBUTED);
     107             :           else
     108         378 :             declareClone(_from_reporter_names[r],
     109         189 :                          _to_reporter_names[r],
     110         189 :                          multi_app->appProblemBase(i),
     111             :                          multi_app->problemBase(),
     112             :                          REPORTER_MODE_ROOT);
     113         612 :           break;
     114             :         }
     115             :   }
     116             :   else
     117             :   {
     118          18 :     const auto & types = getParam<MultiMooseEnum>("reporter_type");
     119          18 :     if (types.size() != _from_reporter_names.size())
     120           0 :       paramError("reporter_type", "This parameter must be the same length as 'from_reporters'");
     121          72 :     for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
     122             :     {
     123          54 :       if (n > 1)
     124         108 :         declareVectorClone(
     125          54 :             _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         243 :   if (n > 1 && multi_app->isRootProcessor())
     132         531 :     for (const auto & rn : _to_reporter_names)
     133         387 :       resizeReporter(rn, multi_app->problemBase(), multi_app->numLocalApps());
     134         243 : }
     135             : 
     136             : void
     137           0 : MultiAppCloneReporterTransfer::executeToMultiapp()
     138             : {
     139           0 : }
     140             : 
     141             : void
     142         216 : MultiAppCloneReporterTransfer::executeFromMultiapp()
     143             : {
     144         216 :   if (!getFromMultiApp()->isRootProcessor())
     145          72 :     return;
     146             : 
     147         144 :   const dof_id_type begin = getFromMultiApp()->firstLocalApp();
     148         144 :   const dof_id_type end = begin + getFromMultiApp()->numLocalApps();
     149             : 
     150         536 :   for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
     151         856 :     for (dof_id_type i = begin; i < end; ++i)
     152             :     {
     153         464 :       if (getFromMultiApp()->numGlobalApps() > 1)
     154         832 :         transferToVectorReporter(_from_reporter_names[r],
     155         416 :                                  _to_reporter_names[r],
     156         832 :                                  getFromMultiApp()->appProblemBase(i),
     157         832 :                                  getFromMultiApp()->problemBase(),
     158             :                                  i - begin);
     159             :       else
     160          96 :         transferReporter(_from_reporter_names[r],
     161          48 :                          _to_reporter_names[r],
     162          96 :                          getFromMultiApp()->appProblemBase(i),
     163          96 :                          getFromMultiApp()->problemBase());
     164             :     }
     165             : }
     166             : 
     167             : void
     168         216 : MultiAppCloneReporterTransfer::execute()
     169             : {
     170         216 :   TIME_SECTION("MultiAppCloneReporterTransfer::execute()", 5, "Transferring reporters");
     171             : 
     172         216 :   if (_current_direction == FROM_MULTIAPP)
     173         216 :     executeFromMultiapp();
     174             :   else
     175           0 :     executeToMultiapp();
     176         216 : }

Generated by: LCOV version 1.14