LCOV - code coverage report
Current view: top level - src/transfers - MultiAppCopyTransfer.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 38 42 90.5 %
Date: 2025-07-17 01:28:37 Functions: 4 4 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             : // MOOSE includes
      11             : #include "MultiAppCopyTransfer.h"
      12             : #include "FEProblemBase.h"
      13             : #include "MultiApp.h"
      14             : #include "SystemBase.h"
      15             : 
      16             : #include "libmesh/id_types.h"
      17             : #include "libmesh/string_to_enum.h"
      18             : 
      19             : registerMooseObject("MooseApp", MultiAppCopyTransfer);
      20             : 
      21             : InputParameters
      22       15405 : MultiAppCopyTransfer::validParams()
      23             : {
      24       15405 :   InputParameters params = MultiAppDofCopyTransfer::validParams();
      25       15405 :   params.addRequiredParam<std::vector<AuxVariableName>>(
      26             :       "variable", "The auxiliary variable to store the transferred values in.");
      27       15405 :   params.addRequiredParam<std::vector<VariableName>>("source_variable",
      28             :                                                      "The variable to transfer from.");
      29             : 
      30       15405 :   params.addClassDescription(
      31             :       "Copies variables (nonlinear and auxiliary) between multiapps that have identical meshes.");
      32       15405 :   return params;
      33           0 : }
      34             : 
      35         576 : MultiAppCopyTransfer::MultiAppCopyTransfer(const InputParameters & parameters)
      36             :   : MultiAppDofCopyTransfer(parameters),
      37         564 :     _from_var_names(getParam<std::vector<VariableName>>("source_variable")),
      38        1140 :     _to_var_names(getParam<std::vector<AuxVariableName>>("variable"))
      39             : {
      40             :   /* Right now, most of derived transfers support one variable only */
      41         564 :   _to_var_name = _to_var_names.size() ? _to_var_names[0] : "INVALID";
      42         564 :   _from_var_name = _from_var_names.size() ? _from_var_names[0] : "INVALID";
      43         564 : }
      44             : 
      45             : void
      46        1873 : MultiAppCopyTransfer::execute()
      47             : {
      48        1873 :   TIME_SECTION("MultiAppCopyTransfer::execute()", 5, "Copies variables");
      49             : 
      50        1873 :   if (_current_direction == TO_MULTIAPP)
      51             :   {
      52         890 :     FEProblemBase & from_problem = getToMultiApp()->problemBase();
      53        1768 :     for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); i++)
      54         890 :       if (getToMultiApp()->hasLocalApp(i))
      55         890 :         transfer(getToMultiApp()->appProblemBase(i), from_problem);
      56             :   }
      57             : 
      58         983 :   else if (_current_direction == FROM_MULTIAPP)
      59             :   {
      60         923 :     FEProblemBase & to_problem = getFromMultiApp()->problemBase();
      61        1846 :     for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++)
      62         923 :       if (getFromMultiApp()->hasLocalApp(i))
      63         923 :         transfer(to_problem, getFromMultiApp()->appProblemBase(i));
      64             :   }
      65             : 
      66          60 :   else if (_current_direction == BETWEEN_MULTIAPP)
      67             :   {
      68          60 :     int transfers_done = 0;
      69         120 :     for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++)
      70             :     {
      71          60 :       if (getFromMultiApp()->hasLocalApp(i))
      72             :       {
      73          60 :         if (getToMultiApp()->hasLocalApp(i))
      74             :         {
      75          60 :           transfer(getToMultiApp()->appProblemBase(i), getFromMultiApp()->appProblemBase(i));
      76          60 :           transfers_done++;
      77             :         }
      78             :       }
      79             :     }
      80          60 :     if (!transfers_done)
      81           0 :       mooseError("BETWEEN_MULTIAPP transfer not supported if there is not at least one subapp "
      82             :                  "per multiapp involved on each rank");
      83             :   }
      84        1861 : }
      85             : 
      86             : void
      87          10 : MultiAppCopyTransfer::checkSiblingsTransferSupported() const
      88             : {
      89             :   // Check that we are in the supported configuration: same number of source and target apps
      90             :   // The allocation of the child apps on the processors must be the same
      91          10 :   if (getFromMultiApp()->numGlobalApps() == getToMultiApp()->numGlobalApps())
      92             :   {
      93          20 :     for (const auto i : make_range(getToMultiApp()->numGlobalApps()))
      94          10 :       if (getFromMultiApp()->hasLocalApp(i) + getToMultiApp()->hasLocalApp(i) == 1)
      95           0 :         mooseError("Child application allocation on parallel processes must be the same to support "
      96             :                    "siblings variable field copy transfer");
      97             :   }
      98             :   else
      99           0 :     mooseError("Number of source and target child apps must match for siblings transfer");
     100          10 : }

Generated by: LCOV version 1.14