LCOV - code coverage report
Current view: top level - src/transfers - MultiAppVectorPostprocessorTransfer.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 42 50 84.0 %
Date: 2025-07-17 01:28:37 Functions: 5 5 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             : #include "MultiAppVectorPostprocessorTransfer.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseTypes.h"
      14             : #include "FEProblem.h"
      15             : #include "MultiApp.h"
      16             : 
      17             : // libMesh
      18             : #include "libmesh/meshfree_interpolation.h"
      19             : #include "libmesh/system.h"
      20             : 
      21             : registerMooseObject("MooseApp", MultiAppVectorPostprocessorTransfer);
      22             : 
      23             : InputParameters
      24       14353 : MultiAppVectorPostprocessorTransfer::validParams()
      25             : {
      26       14353 :   InputParameters params = MultiAppTransfer::validParams();
      27       14353 :   params.addRequiredParam<PostprocessorName>(
      28             :       "postprocessor", "The name of the Postprocessors on the sub-app to transfer from/to.");
      29       14353 :   params.addRequiredParam<VectorPostprocessorName>("vector_postprocessor",
      30             :                                                    "The name of the VectorPostprocessor in "
      31             :                                                    "the MultiApp to transfer values "
      32             :                                                    "from/to.");
      33       14353 :   params.addRequiredParam<std::string>(
      34             :       "vector_name", "Named vector quantity to transfer from/to in VectorPostprocessor.");
      35       14353 :   params.addClassDescription("This transfer distributes the N values of a "
      36             :                              "VectorPostprocessor to Postprocessors located in "
      37             :                              "N sub-apps or"
      38             :                              " collects Postprocessor values from N sub-apps "
      39             :                              "into a VectorPostprocessor");
      40       14353 :   return params;
      41           0 : }
      42             : 
      43          44 : MultiAppVectorPostprocessorTransfer::MultiAppVectorPostprocessorTransfer(
      44          44 :     const InputParameters & parameters)
      45             :   : MultiAppTransfer(parameters),
      46          44 :     _sub_pp_name(getParam<PostprocessorName>("postprocessor")),
      47          44 :     _master_vpp_name(getParam<VectorPostprocessorName>("vector_postprocessor")),
      48          88 :     _vector_name(getParam<std::string>("vector_name"))
      49             : {
      50          44 :   if (_directions.size() != 1)
      51           0 :     paramError("direction", "This transfer is only unidirectional");
      52          44 : }
      53             : 
      54             : void
      55          20 : MultiAppVectorPostprocessorTransfer::executeToMultiapp()
      56             : {
      57             :   const VectorPostprocessorValue & vpp =
      58          20 :       getToMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name,
      59             :                                                                        _vector_name);
      60             : 
      61             :   // Execute VPP if it was specified to execute on transfers
      62          20 :   _fe_problem.computeUserObjectByName(EXEC_TRANSFER, Moose::PRE_AUX, _master_vpp_name);
      63          20 :   _fe_problem.computeUserObjectByName(EXEC_TRANSFER, Moose::POST_AUX, _master_vpp_name);
      64             : 
      65          20 :   if (vpp.size() != getToMultiApp()->numGlobalApps())
      66           0 :     mooseError("VectorPostprocessor ",
      67             :                _master_vpp_name,
      68             :                " and number of sub-apps do not match: ",
      69           0 :                vpp.size(),
      70             :                "/",
      71           0 :                getToMultiApp()->numGlobalApps());
      72             : 
      73          60 :   for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); ++i)
      74          40 :     if (getToMultiApp()->hasLocalApp(i))
      75          24 :       getToMultiApp()->appProblemBase(i).setPostprocessorValueByName(_sub_pp_name, vpp[i]);
      76          20 : }
      77             : 
      78             : void
      79          20 : MultiAppVectorPostprocessorTransfer::executeFromMultiapp()
      80             : {
      81             :   const VectorPostprocessorValue & vpp =
      82          20 :       getFromMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name,
      83             :                                                                          _vector_name);
      84          20 :   errorIfObjectExecutesOnTransferInSourceApp(_sub_pp_name);
      85             : 
      86          16 :   if (vpp.size() != getFromMultiApp()->numGlobalApps())
      87           0 :     mooseError("VectorPostprocessor ",
      88             :                _master_vpp_name,
      89             :                " and number of sub-apps do not match: ",
      90           0 :                vpp.size(),
      91             :                "/",
      92           0 :                getFromMultiApp()->numGlobalApps());
      93             : 
      94          16 :   VectorPostprocessorValue value(getFromMultiApp()->numGlobalApps(), 0.0);
      95          48 :   for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); ++i)
      96             :   {
      97             :     // To avoid duplication and thus a wrong pp value after summing value accross procs, we should
      98             :     // ensure that value[i] is only set by one procs. To do this, we check isFirstLocalRank to see
      99             :     // if the current proc is the first rank that subapp i lives on.
     100          32 :     if (getFromMultiApp()->hasLocalApp(i) && getFromMultiApp()->isFirstLocalRank())
     101          16 :       value[i] = getFromMultiApp()->appProblemBase(i).getPostprocessorValueByName(_sub_pp_name);
     102             :   }
     103             : 
     104             :   // Sum to distribute entries of 'value' accross all procs
     105          48 :   for (auto & v : value)
     106          32 :     _communicator.sum(v);
     107             : 
     108          32 :   getFromMultiApp()->problemBase().setVectorPostprocessorValueByName(
     109          16 :       _master_vpp_name, _vector_name, value);
     110          16 : }
     111             : 
     112             : void
     113          40 : MultiAppVectorPostprocessorTransfer::execute()
     114             : {
     115          40 :   TIME_SECTION(
     116             :       "MultiAppVectorPostprocessorTransfer::execute()", 5, "Transferring a vector postprocessor");
     117             : 
     118          40 :   if (_current_direction == FROM_MULTIAPP)
     119          20 :     executeFromMultiapp();
     120             :   else
     121          20 :     executeToMultiapp();
     122          36 : }

Generated by: LCOV version 1.14