LCOV - code coverage report
Current view: top level - include/transfers - SerializedSolutionTransfer.h (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 2 5 40.0 %
Date: 2025-07-25 05:00:46 Functions: 2 5 40.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             : // MOOSE includes
      13             : #include "ParallelSolutionStorage.h"
      14             : #include "StochasticToolsTransfer.h"
      15             : #include "SolutionContainer.h"
      16             : #include "UserObjectInterface.h"
      17             : 
      18             : // Forward declarations
      19             : class ParallelSolutionStorage;
      20             : 
      21             : /**
      22             :  * This class is responsible for serializing solutions coming from subapps on
      23             :  * specific processors. It is designed to serve as an interface between
      24             :  * SolutionContainer and ParallelSolutionStorage objects.
      25             :  */
      26             : class SerializedSolutionTransfer : public StochasticToolsTransfer
      27             : {
      28             : public:
      29             :   static InputParameters validParams();
      30             : 
      31             :   SerializedSolutionTransfer(const InputParameters & parameters);
      32             : 
      33             :   virtual void initialSetup() override;
      34             :   virtual void execute() override;
      35             : 
      36             :   ///@{
      37             :   /**
      38             :    * Methods used when running in batch mode (see SamplerFullSolveMultiApp)
      39             :    */
      40         310 :   void initializeFromMultiapp() override {}
      41             :   void executeFromMultiapp() override;
      42         310 :   void finalizeFromMultiapp() override {}
      43             : 
      44           0 :   void initializeToMultiapp() override {}
      45           0 :   void executeToMultiapp() override {}
      46           0 :   void finalizeToMultiapp() override {}
      47             :   ///@}
      48             : 
      49             : protected:
      50             :   /// The storage on the main application where the serialized solutions should be
      51             :   /// transferred
      52             :   ParallelSolutionStorage * _parallel_storage;
      53             : 
      54             :   /// The names of the variables which should be extracted from the solution vector
      55             :   std::vector<VariableName> _variable_names;
      56             : 
      57             :   /// Link to the storage spaces on the subapplications (will only hold one in batch mode)
      58             :   std::vector<SolutionContainer *> _solution_container;
      59             : 
      60             : private:
      61             :   /// Serialize on the root processor of the subapplication and transfer the result to the main application
      62             :   void transferToSubAppRoot(FEProblemBase & app_problem,
      63             :                             SolutionContainer & solution_container,
      64             :                             const dof_id_type global_i);
      65             : 
      66             :   /**
      67             :    * Serialize on methodically determined rank of the subapp and transfer to the main application.
      68             :    * Example: Let's say we have 5 samples and 3 processors on a sub-application.
      69             :    * In this case, we will serialize the first two on rank 1, the second two on rank
      70             :    * 2 and the last one on rank 3.
      71             :    */
      72             :   void transferInParallel(FEProblemBase & app_problem,
      73             :                           SolutionContainer & solution_container,
      74             :                           const dof_id_type global_i);
      75             : 
      76             :   /**
      77             :    * Initializes the solution container if the multiapp is run in normal mode. We need this because
      78             :    * in normal mode we don't have a function for initialization besides `initialSetup()`, which
      79             :    * is execute every time regardless of the multiapp settings.
      80             :    */
      81             :   void initializeInNormalMode();
      82             : 
      83             :   /// This routine queries the solution container addresses from the subapps. We need to redo this
      84             :   /// every time initialSetup() (batch-reset) is called on the subapp because the address
      85             :   /// of SolutionContainer changes. Considering that the transfer doesn't know the multiapp
      86             :   /// setting, we use the same approach for batch-restore as well, which might be a little
      87             :   /// wasteful if the execution of the subapps is very fast (usually not the case).
      88             :   void initializeInBatchMode();
      89             : 
      90             :   /// Return the system which contains the given variable. It can either be a flavor of
      91             :   /// a nonlinear system or the auxiliary system.
      92             :   /// @param vname The name of the variable whose system is queried
      93             :   SystemBase & getSystem(FEProblemBase & app_problem, const VariableName & vname);
      94             : 
      95             :   /// User-selected switch that determines if we want to serialize on the root of the subapp
      96             :   /// only or distribute the solutions between all the ranks of the subapp.
      97             :   const bool _serialize_on_root;
      98             : };

Generated by: LCOV version 1.14