LCOV - code coverage report
Current view: top level - src/mfem/transfers - MFEMMultiAppTransfer.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 46 50 92.0 %
Date: 2026-05-29 20:35:17 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        9834 : MFEMMultiAppTransfer::validParams()
      19             : {
      20        9834 :   InputParameters params = MultiAppTransfer::validParams();
      21       39336 :   params.addRequiredParam<std::vector<VariableName>>("variables",
      22             :                                                      "Variable(s) to store transferred values in.");
      23       29502 :   params.addRequiredParam<std::vector<VariableName>>("source_variables",
      24             :                                                      "Variable(s) to transfer from.");
      25        9834 :   return params;
      26           0 : }
      27             : 
      28         721 : MFEMMultiAppTransfer::MFEMMultiAppTransfer(InputParameters const & params)
      29             :   : MultiAppTransfer(params),
      30         721 :     _from_var_names(getParam<std::vector<VariableName>>("source_variables")),
      31        2884 :     _to_var_names(getParam<std::vector<VariableName>>("variables"))
      32             : {
      33         721 :   if (numToVar() != numFromVar())
      34           0 :     paramError("source_variables", "Number of variables transferred must be same in both systems.");
      35         721 : }
      36             : 
      37             : void
      38         831 : MFEMMultiAppTransfer::execute()
      39             : {
      40        4155 :   TIME_SECTION("MFEMMultiAppTransfer::execute", 5, "Perform transfer to and/or from subapps.");
      41         831 :   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         704 :     case FROM_MULTIAPP:
      53        1408 :       for (const auto i : make_range(getFromMultiApp()->numGlobalApps()))
      54         704 :         if (getFromMultiApp()->hasLocalApp(i))
      55             :         {
      56         704 :           setActiveToProblem(getFromMultiApp()->problemBase(), 0);
      57         704 :           setActiveFromProblem(getFromMultiApp()->appProblemBase(i), i);
      58         704 :           transferVariables(/*is_target_local=*/true);
      59             :         }
      60         704 :       break;
      61         107 :     case BETWEEN_MULTIAPP:
      62         107 :       bool transfers_done = false;
      63         214 :       for (const auto from_app_id : make_range(getFromMultiApp()->numGlobalApps()))
      64         107 :         if (getFromMultiApp()->hasLocalApp(from_app_id))
      65         264 :           for (const auto to_app_id : make_range(getToMultiApp()->numGlobalApps()))
      66             :           {
      67         157 :             bool is_target_local = getToMultiApp()->hasLocalApp(to_app_id);
      68         157 :             setActiveFromProblem(getFromMultiApp()->appProblemBase(from_app_id), from_app_id);
      69         157 :             if (is_target_local)
      70         135 :               setActiveToProblem(getToMultiApp()->appProblemBase(to_app_id), to_app_id);
      71         157 :             transferVariables(is_target_local);
      72         157 :             transfers_done |= is_target_local;
      73             :           }
      74         107 :       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         107 :       break;
      78             :   }
      79         831 : }
      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