https://mooseframework.inl.gov
MultiAppMFEMCopyTransfer.C
Go to the documentation of this file.
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 
13 
15 
18 {
20  params.addClassDescription("Copies variable values from one MFEM application to another");
21  return params;
22 }
23 
25  : MFEMMultiAppTransfer(params)
26 {
27  checkValidTransferProblemTypes<Moose::FEBackend::MFEM, Moose::FEBackend::MFEM>();
28 }
29 
32 {
34 }
35 
38 {
40 }
41 
42 void
44 {
45  auto getGF = [&](MFEMProblem & problem, const std::string & name) -> mfem::Vector &
46  {
47  if (problem.getProblemData().gridfunctions.Has(name))
48  return *problem.getGridFunction(name);
50  return *problem.getComplexGridFunction(name);
51  mooseError("No real or complex variable named '", name, "' found.");
52  };
53 
54  for (const auto v : make_range(numToVar()))
55  {
56  mfem::Vector & from_var = getGF(getActiveFromProblem(), getFromVarName(v));
57  mfem::Vector & to_var = getGF(getActiveToProblem(), getToVarName(v));
58 
59  if (from_var.Size() != to_var.Size())
60  mooseError("'", getFromVarName(v), "' and '", getToVarName(v), "' differ in no. of DoFs.");
61 
62  to_var = from_var;
63  }
64 }
65 
66 void
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  if (getFromMultiApp()->numGlobalApps() == getToMultiApp()->numGlobalApps())
72  {
73  for (const auto i : make_range(getToMultiApp()->numGlobalApps()))
74  if (getFromMultiApp()->hasLocalApp(i) != getToMultiApp()->hasLocalApp(i))
75  mooseError("Child application allocation on parallel processes must be the same to support "
76  "siblings variable field copy transfer");
77  }
78  else
79  mooseError("Number of source and target child apps must match for siblings transfer");
80 }
81 
82 #endif
std::shared_ptr< mfem::ParGridFunction > getGridFunction(const std::string &name)
Definition: MFEMProblem.h:332
Virtual base class for MultiApp transfers to and/or from MFEMProblems.
virtual void transferVariables(bool is_target_local) override
Transfer all variables from active source problem to active destination problem.
Moose::MFEM::ComplexGridFunctions cmplx_gridfunctions
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem...
Definition: MFEMProblem.h:263
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
virtual FEProblemBase & getActiveFromProblem()
Getter for current problem containing source variables.
virtual MFEMProblem & getActiveToProblem() override
Set current MFEM problem to fetch destination variables from.
virtual FEProblemBase & getActiveToProblem()
Getter for current problem containing destination variables.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
unsigned int numToVar() const
Return for the number of destination variables.
Transfer to copy MFEMVariables between multiapps.
virtual MFEMProblem & getActiveFromProblem() override
Set current MFEM problem to fetch source variables from.
MultiAppMFEMCopyTransfer(InputParameters const &params)
void checkSiblingsTransferSupported() const override
Check number of source and target child apps match for sibling transfer.
std::shared_ptr< mfem::ParComplexGridFunction > getComplexGridFunction(const std::string &name)
Definition: MFEMProblem.h:340
const VariableName & getFromVarName(int i) const
Getter for source variable name.
static InputParameters validParams()
const VariableName & getToVarName(int i) const
Getter for destination variable name.
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
registerMooseObject("MooseApp", MultiAppMFEMCopyTransfer)
Moose::MFEM::GridFunctions gridfunctions
static InputParameters validParams()