https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
35
41
42void
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
66void
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
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", MultiAppMFEMCopyTransfer)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
Virtual base class for MultiApp transfers to and/or from MFEMProblems.
const VariableName & getToVarName(int i) const
Getter for destination variable name.
unsigned int numToVar() const
Return for the number of destination variables.
static InputParameters validParams()
const VariableName & getFromVarName(int i) const
Getter for source variable name.
virtual FEProblemBase & getActiveToProblem()
Getter for current problem containing destination variables.
virtual FEProblemBase & getActiveFromProblem()
Getter for current problem containing source variables.
std::shared_ptr< mfem::ParComplexGridFunction > getComplexGridFunction(const std::string &name)
std::shared_ptr< mfem::ParGridFunction > getGridFunction(const std::string &name)
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
Transfer to copy MFEMVariables between multiapps.
virtual MFEMProblem & getActiveToProblem() override
Set current MFEM problem to fetch destination variables from.
virtual void transferVariables(bool is_target_local) override
Transfer all variables from active source problem to active destination problem.
void checkSiblingsTransferSupported() const override
Check number of source and target child apps match for sibling transfer.
MultiAppMFEMCopyTransfer(InputParameters const &params)
static InputParameters validParams()
virtual MFEMProblem & getActiveFromProblem() override
Set current MFEM problem to fetch source variables from.
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
Moose::MFEM::ComplexGridFunctions cmplx_gridfunctions
Moose::MFEM::GridFunctions gridfunctions