LCOV - code coverage report
Current view: top level - include/transfers - ReporterTransferInterface.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 2 2 100.0 %
Date: 2025-07-17 01:28:37 Functions: 1 1 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             : #pragma once
      11             : 
      12             : #include "ReporterData.h"
      13             : #include "FEProblemBase.h"
      14             : 
      15             : // Forward declarations
      16             : class Transfer;
      17             : 
      18             : /*
      19             :  * This transfer serves as a base class for transferring reporter values between
      20             :  * multiapps. This includes reporters, vector postprocessors, and postprocessors.
      21             :  *
      22             :  * The underlying purpose fo this class is to avoid using non-const access to ReporterData
      23             :  * through FEProblemBase to set reporter data. Instead, we simply have this class
      24             :  * as a friend to ReporterData::WriteKey and provide these protected functions for derived
      25             :  * classes. This avoids any old object modifying reporter data.
      26             :  */
      27             : class ReporterTransferInterface
      28             : {
      29             : public:
      30             :   static InputParameters validParams();
      31             :   ReporterTransferInterface(const Transfer * transfer);
      32             : 
      33             : protected:
      34       14751 :   static MultiMooseEnum standardTransferTypes()
      35             :   {
      36       14751 :     return MultiMooseEnum("bool=0 integer=1 real=2 string=3");
      37             :   }
      38             : 
      39             :   /*
      40             :    * This function allows derived objects to decide how the "from" reporters should be transferred.
      41             :    * I.e. whether we are transferring the entire data or part of it. Without calling this
      42             :    * early (constructor is preferred) there could be unintended behaiviour for
      43             :    * non-broadcasted data like VPPs.
      44             :    *
      45             :    * @param ReporterType data type of the reporter
      46             :    * @param name reporter name
      47             :    * @param problem The FEProblem that references the reporter data
      48             :    */
      49             :   void addReporterTransferMode(const ReporterName & name,
      50             :                                const ReporterMode & mode,
      51             :                                FEProblemBase & problem);
      52             : 
      53             :   /*
      54             :    * Transferring reporter value between FEProblems, mainly used for multiapps
      55             :    *
      56             :    * @param from_reporter reporter name on main app
      57             :    * @param to_reporter reporter name on sub app
      58             :    * @param from_problem The FEProblem that references the reporter data with the value
      59             :    * @param to_problem The FEProblem that references the reporter data to transfer to
      60             :    * @param time_index time index of transfer (default is lastest data)
      61             :    */
      62             :   void transferReporter(const ReporterName & from_reporter,
      63             :                         const ReporterName & to_reporter,
      64             :                         const FEProblemBase & from_problem,
      65             :                         FEProblemBase & to_problem,
      66             :                         unsigned int time_index = 0);
      67             : 
      68             :   /*
      69             :    * Transferring reporter value from one FEProblems to a vector reporter value from another,
      70             :    * mainly used for multiapps.
      71             :    *
      72             :    * @param from_reporter reporter name on main app
      73             :    * @param to_reporter reporter name on sub app
      74             :    * @param from_problem The FEProblem that references the reporter data with the value
      75             :    * @param to_problem The FEProblem that references the reporter data to transfer to
      76             :    * @param index the element index of the vector reporter
      77             :    * @param time_index time index of transfer (default is lastest data)
      78             :    */
      79             :   void transferToVectorReporter(const ReporterName & from_reporter,
      80             :                                 const ReporterName & to_reporter,
      81             :                                 const FEProblemBase & from_problem,
      82             :                                 FEProblemBase & to_problem,
      83             :                                 dof_id_type index,
      84             :                                 unsigned int time_index = 0);
      85             : 
      86             :   /*
      87             :    * Transferring reporter value from one vector reporter value to a single
      88             :    * reporter value.
      89             :    *
      90             :    * @param from_reporter reporter name on main app
      91             :    * @param to_reporter reporter name on sub app
      92             :    * @param from_problem The FEProblem that references the reporter data with the value
      93             :    * @param to_problem The FEProblem that references the reporter data to transfer to
      94             :    * @param index the element index of the vector reporter
      95             :    * @param time_index time index of transfer (default is lastest data)
      96             :    */
      97             :   void transferFromVectorReporter(const ReporterName & from_reporter,
      98             :                                   const ReporterName & to_reporter,
      99             :                                   const FEProblemBase & from_problem,
     100             :                                   FEProblemBase & to_problem,
     101             :                                   dof_id_type index,
     102             :                                   unsigned int time_index = 0);
     103             : 
     104             :   /*
     105             :    * Helper for declaring a new reporter value in a FEProblem that is the same type
     106             :    * as the reporter value in another FEProblem.
     107             :    *
     108             :    * @param from_reporter reporter name to clone type
     109             :    * @param to_reporter reporter name of the clone
     110             :    * @param from_problem The FEProblem that references the reporter data with the value
     111             :    * @param to_problem The FEProblem that references the reporter data to declare clone
     112             :    * @param mode ReporterMode to declare value as
     113             :    */
     114             :   void declareClone(const ReporterName & from_reporter,
     115             :                     const ReporterName & to_reporter,
     116             :                     const FEProblemBase & from_problem,
     117             :                     FEProblemBase & to_problem,
     118             :                     const ReporterMode & mode);
     119             : 
     120             :   /*
     121             :    * Helper for declaring a new reporter value in a FEProblem that has specified type.
     122             :    *
     123             :    * @param reporter_name reporter name of the clone
     124             :    * @param fe_problem The FEProblem that references the reporter data to declare clone
     125             :    * @param type The type of reporter to declare
     126             :    * @param mode ReporterMode to declare value as
     127             :    */
     128             :   void declareClone(const ReporterName & rname,
     129             :                     FEProblemBase & problem,
     130             :                     const std::string & type,
     131             :                     const ReporterMode & mode);
     132             : 
     133             :   /*
     134             :    * Helper for declaring a new vector reporter value in a FEProblem that contains
     135             :    * the same type as the reporter value in another FEProblem.
     136             :    *
     137             :    * @param from_reporter reporter name to clone type
     138             :    * @param to_reporter reporter name of the vector clone
     139             :    * @param from_problem The FEProblem that references the reporter data with the value
     140             :    * @param to_problem The FEProblem that references the reporter data to declare value
     141             :    * @param mode ReporterMode to declare value as
     142             :    */
     143             :   void declareVectorClone(const ReporterName & from_reporter,
     144             :                           const ReporterName & to_reporter,
     145             :                           const FEProblemBase & from_problem,
     146             :                           FEProblemBase & to_problem,
     147             :                           const ReporterMode & mode);
     148             : 
     149             :   /*
     150             :    * Helper for declaring a new reporter value in a FEProblem that has specified type.
     151             :    *
     152             :    * @param reporter_name reporter name of the vector clone
     153             :    * @param fe_problem The FEProblem that references the reporter data to declare vector clone
     154             :    * @param type The type of reporter to declare the vector
     155             :    * @param mode ReporterMode to declare value as
     156             :    */
     157             :   void declareVectorClone(const ReporterName & rname,
     158             :                           FEProblemBase & problem,
     159             :                           const std::string & type,
     160             :                           const ReporterMode & mode);
     161             : 
     162             :   /*
     163             :    * Resize vector reporter value
     164             :    *
     165             :    * @param name Name of reporter
     166             :    * @param problem FEProblem that contains the reporter value
     167             :    * @param n New size of vector
     168             :    */
     169             :   void resizeReporter(const ReporterName & name, FEProblemBase & problem, dof_id_type n);
     170             : 
     171             :   /*
     172             :    * Clear vector reporter value
     173             :    *
     174             :    * @param name Name of reporter
     175             :    * @param problem FEProblem that contains the reporter value
     176             :    */
     177             :   void clearVectorReporter(const ReporterName & name, FEProblemBase & problem);
     178             : 
     179             :   /*
     180             :    * Sum vector reporter value
     181             :    *
     182             :    * @param name Name of reporter
     183             :    * @param problem FEProblem that contains the reporter value
     184             :    */
     185             :   void sumVectorReporter(const ReporterName & name, FEProblemBase & problem);
     186             : 
     187             :   /*
     188             :    * Helper for declaring reporter names when transfer is cloning values.
     189             :    * The result names will be:
     190             :    *      names[i] = obj_name/prefix:rep_name[i].getObjectName():rep_name[i].getValueName()
     191             :    *
     192             :    * @param prefix A string to prefix the reporter value name with.
     193             :    *               Typically the transfer name or user supplied.
     194             :    * @param obj_name The reporter object name that emulates holding the data
     195             :    * @param rep_names The list of reporter names that are being cloned
     196             :    *
     197             :    * @return A list of declarable reporter names
     198             :    */
     199             :   std::vector<ReporterName> getReporterNamesHelper(std::string prefix,
     200             :                                                    const std::string & obj_name,
     201             :                                                    const std::vector<ReporterName> & rep_names);
     202             : 
     203             :   /**
     204             :    * Checks if the problem \p problem has a Reporter value with the name \p reporter.
     205             :    */
     206             :   void checkHasReporterValue(const ReporterName & reporter, const FEProblemBase & problem) const;
     207             : 
     208             : private:
     209             :   /**
     210             :    * Helper for hiding the variables in the problem \p problem if the Reporter with name
     211             :    * \p reporter is associated with a Reporter object (not a PP or VPP)
     212             :    */
     213             :   void hideVariableHelper(const ReporterName & reporter, FEProblemBase & problem);
     214             : 
     215             :   /// The Transfer that this interface is associated with
     216             :   const Transfer & _rti_transfer;
     217             : };

Generated by: LCOV version 1.14