LCOV - code coverage report
Current view: top level - src/mfem/transfers - MFEMMultiAppTransfer.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 26ef6a Lines: 46 50 92.0 %
Date: 2026-06-24 21:19:51 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             : #ifdef MOOSE_MFEM_ENABLED
      11             : 
      12             : #include "MFEMMultiAppTransfer.h"
      13             : #include "MFEMProblem.h"
      14             : #include "DisplacedProblem.h"
      15             : #include "libmesh/int_range.h"
      16             : 
      17             : InputParameters
      18        9850 : MFEMMultiAppTransfer::validParams()
      19             : {
      20        9850 :   InputParameters params = MultiAppTransfer::validParams();
      21       39400 :   params.addRequiredParam<std::vector<VariableName>>("variables",
      22             :                                                      "Variable(s) to store transferred values in.");
      23       29550 :   params.addRequiredParam<std::vector<VariableName>>("source_variables",
      24             :                                                      "Variable(s) to transfer from.");
      25        9850 :   return params;
      26           0 : }
      27             : 
      28         729 : MFEMMultiAppTransfer::MFEMMultiAppTransfer(InputParameters const & params)
      29             :   : MultiAppTransfer(params),
      30         729 :     _from_var_names(getParam<std::vector<VariableName>>("source_variables")),
      31        2916 :     _to_var_names(getParam<std::vector<VariableName>>("variables"))
      32             : {
      33         729 :   if (numToVar() != numFromVar())
      34           0 :     paramError("source_variables", "Number of variables transferred must be same in both systems.");
      35         729 : }
      36             : 
      37             : void
      38         840 : MFEMMultiAppTransfer::execute()
      39             : {
      40        4200 :   TIME_SECTION("MFEMMultiAppTransfer::execute", 5, "Perform transfer to and/or from subapps.");
      41         840 :   switch (_current_direction)
      42             :   {
      43          20 :     case TO_MULTIAPP:
      44          40 :       for (const auto i : make_range(getToMultiApp()->numGlobalApps()))
      45          20 :         if (getToMultiApp()->hasLocalApp(i))
      46             :         {
      47          20 :           setActiveToProblem(getToMultiApp()->appProblemBase(i), i);
      48          20 :           setActiveFromProblem(getToMultiApp()->problemBase(), 0);
      49          20 :           transferVariables(/*is_target_local=*/true);
      50             :         }
      51          20 :       break;
      52         711 :     case FROM_MULTIAPP:
      53        1422 :       for (const auto i : make_range(getFromMultiApp()->numGlobalApps()))
      54         711 :         if (getFromMultiApp()->hasLocalApp(i))
      55             :         {
      56         711 :           setActiveToProblem(getFromMultiApp()->problemBase(), 0);
      57         711 :           setActiveFromProblem(getFromMultiApp()->appProblemBase(i), i);
      58         711 :           transferVariables(/*is_target_local=*/true);
      59             :         }
      60         711 :       break;
      61         109 :     case BETWEEN_MULTIAPP:
      62         109 :       bool transfers_done = false;
      63         218 :       for (const auto from_app_id : make_range(getFromMultiApp()->numGlobalApps()))
      64         109 :         if (getFromMultiApp()->hasLocalApp(from_app_id))
      65         272 :           for (const auto to_app_id : make_range(getToMultiApp()->numGlobalApps()))
      66             :           {
      67         163 :             bool is_target_local = getToMultiApp()->hasLocalApp(to_app_id);
      68         163 :             setActiveFromProblem(getFromMultiApp()->appProblemBase(from_app_id), from_app_id);
      69         163 :             if (is_target_local)
      70         141 :               setActiveToProblem(getToMultiApp()->appProblemBase(to_app_id), to_app_id);
      71         163 :             transferVariables(is_target_local);
      72         163 :             transfers_done |= is_target_local;
      73             :           }
      74         109 :       if (!transfers_done)
      75           0 :         mooseError("BETWEEN_MULTIAPP transfer not supported if there is not at least one subapp "
      76             :                    "per multiapp involved on each rank");
      77         109 :       break;
      78             :   }
      79         840 : }
      80             : 
      81             : EquationSystems &
      82         963 : MFEMMultiAppTransfer::getlibMeshEquationSystem(FEProblemBase & problem, bool use_displaced) const
      83             : {
      84         963 :   if (use_displaced)
      85             :   {
      86          99 :     if (!problem.getDisplacedProblem())
      87           0 :       mooseError("No displaced problem to provide a displaced equation system");
      88          99 :     return problem.getDisplacedProblem()->es();
      89             :   }
      90             :   else
      91         864 :     return problem.es();
      92             : }
      93             : 
      94             : #endif

Generated by: LCOV version 1.14