LCOV - code coverage report
Current view: top level - src/mfem/transfers - MultiAppMFEMCopyTransfer.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 30 35 85.7 %
Date: 2026-05-29 20:35:17 Functions: 7 7 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 "MultiAppMFEMCopyTransfer.h"
      13             : 
      14             : registerMooseObject("MooseApp", MultiAppMFEMCopyTransfer);
      15             : 
      16             : InputParameters
      17        2306 : MultiAppMFEMCopyTransfer::validParams()
      18             : {
      19        2306 :   InputParameters params = MFEMMultiAppTransfer::validParams();
      20        2306 :   params.addClassDescription("Copies variable values from one MFEM application to another");
      21        2306 :   return params;
      22           0 : }
      23             : 
      24         104 : MultiAppMFEMCopyTransfer::MultiAppMFEMCopyTransfer(InputParameters const & params)
      25         104 :   : MFEMMultiAppTransfer(params)
      26             : {
      27         104 :   checkValidTransferProblemTypes<MFEMProblem, MFEMProblem>();
      28         104 : }
      29             : 
      30             : MFEMProblem &
      31         104 : MultiAppMFEMCopyTransfer::getActiveFromProblem()
      32             : {
      33         104 :   return static_cast<MFEMProblem &>(MFEMMultiAppTransfer::getActiveFromProblem());
      34             : }
      35             : 
      36             : MFEMProblem &
      37         104 : MultiAppMFEMCopyTransfer::getActiveToProblem()
      38             : {
      39         104 :   return static_cast<MFEMProblem &>(MFEMMultiAppTransfer::getActiveToProblem());
      40             : }
      41             : 
      42             : void
      43         104 : MultiAppMFEMCopyTransfer::transferVariables(bool /*is_target_local*/)
      44             : {
      45         208 :   auto getGF = [&](MFEMProblem & problem, const std::string & name) -> mfem::Vector &
      46             :   {
      47         208 :     if (problem.getProblemData().gridfunctions.Has(name))
      48         180 :       return *problem.getGridFunction(name);
      49          28 :     if (problem.getProblemData().cmplx_gridfunctions.Has(name))
      50          28 :       return *problem.getComplexGridFunction(name);
      51           0 :     mooseError("No real or complex variable named '", name, "' found.");
      52         104 :   };
      53             : 
      54         208 :   for (const auto v : make_range(numToVar()))
      55             :   {
      56         104 :     mfem::Vector & from_var = getGF(getActiveFromProblem(), getFromVarName(v));
      57         104 :     mfem::Vector & to_var = getGF(getActiveToProblem(), getToVarName(v));
      58             : 
      59         104 :     if (from_var.Size() != to_var.Size())
      60           0 :       mooseError("'", getFromVarName(v), "' and '", getToVarName(v), "' differ in no. of DoFs.");
      61             : 
      62         104 :     to_var = from_var;
      63             :   }
      64         104 : }
      65             : 
      66             : void
      67          13 : MultiAppMFEMCopyTransfer::checkSiblingsTransferSupported() const
      68             : {
      69             :   // Check that we are in the supported configuration: same number of source and target apps
      70             :   // The allocation of the child apps on the processors must be the same
      71          13 :   if (getFromMultiApp()->numGlobalApps() == getToMultiApp()->numGlobalApps())
      72             :   {
      73          26 :     for (const auto i : make_range(getToMultiApp()->numGlobalApps()))
      74          13 :       if (getFromMultiApp()->hasLocalApp(i) != getToMultiApp()->hasLocalApp(i))
      75           0 :         mooseError("Child application allocation on parallel processes must be the same to support "
      76             :                    "siblings variable field copy transfer");
      77             :   }
      78             :   else
      79           0 :     mooseError("Number of source and target child apps must match for siblings transfer");
      80          13 : }
      81             : 
      82             : #endif

Generated by: LCOV version 1.14