https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMMultiAppTransfer.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#include "MFEMProblem.h"
14#include "DisplacedProblem.h"
15#include "libmesh/int_range.h"
16
19{
21 params.addRequiredParam<std::vector<VariableName>>("variables",
22 "Variable(s) to store transferred values in.");
23 params.addRequiredParam<std::vector<VariableName>>("source_variables",
24 "Variable(s) to transfer from.");
25 return params;
26}
27
29 : MultiAppTransfer(params),
30 _from_var_names(getParam<std::vector<VariableName>>("source_variables")),
31 _to_var_names(getParam<std::vector<VariableName>>("variables"))
32{
33 if (numToVar() != numFromVar())
34 paramError("source_variables", "Number of variables transferred must be same in both systems.");
35}
36
37void
39{
40 TIME_SECTION("MFEMMultiAppTransfer::execute", 5, "Perform transfer to and/or from subapps.");
41 switch (_current_direction)
42 {
43 case TO_MULTIAPP:
44 for (const auto i : make_range(getToMultiApp()->numGlobalApps()))
45 if (getToMultiApp()->hasLocalApp(i))
46 {
47 setActiveToProblem(getToMultiApp()->appProblemBase(i), i);
48 setActiveFromProblem(getToMultiApp()->problemBase(), 0);
49 transferVariables(/*is_target_local=*/true);
50 }
51 break;
52 case FROM_MULTIAPP:
53 for (const auto i : make_range(getFromMultiApp()->numGlobalApps()))
54 if (getFromMultiApp()->hasLocalApp(i))
55 {
56 setActiveToProblem(getFromMultiApp()->problemBase(), 0);
57 setActiveFromProblem(getFromMultiApp()->appProblemBase(i), i);
58 transferVariables(/*is_target_local=*/true);
59 }
60 break;
62 bool transfers_done = false;
63 for (const auto from_app_id : make_range(getFromMultiApp()->numGlobalApps()))
64 if (getFromMultiApp()->hasLocalApp(from_app_id))
65 for (const auto to_app_id : make_range(getToMultiApp()->numGlobalApps()))
66 {
67 bool is_target_local = getToMultiApp()->hasLocalApp(to_app_id);
68 setActiveFromProblem(getFromMultiApp()->appProblemBase(from_app_id), from_app_id);
69 if (is_target_local)
70 setActiveToProblem(getToMultiApp()->appProblemBase(to_app_id), to_app_id);
71 transferVariables(is_target_local);
72 transfers_done |= is_target_local;
73 }
74 if (!transfers_done)
75 mooseError("BETWEEN_MULTIAPP transfer not supported if there is not at least one subapp "
76 "per multiapp involved on each rank");
77 break;
78 }
79}
80
81EquationSystems &
83{
84 if (use_displaced)
85 {
86 if (!problem.getDisplacedProblem())
87 mooseError("No displaced problem to provide a displaced equation system");
88 return problem.getDisplacedProblem()->es();
89 }
90 else
91 return problem.es();
92}
93
94#endif
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual libMesh::EquationSystems & es() override
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void setActiveFromProblem(FEProblemBase &from_problem, const unsigned int global_app_index)
Set current problem to fetch source variables from.
void setActiveToProblem(FEProblemBase &to_problem, const unsigned int global_app_index)
Set current problem to fetch destination variables from.
unsigned int numToVar() const
Return for the number of destination variables.
MFEMMultiAppTransfer(InputParameters const &params)
static InputParameters validParams()
virtual void transferVariables(bool is_target_local)=0
Transfer all variables from active source problem to active destination problem.
libMesh::EquationSystems & getlibMeshEquationSystem(FEProblemBase &problem, bool use_displaced) const
Get libMesh EquationSystem, which may or may not be displaced.
void execute() override
Set active source and destination problems, and execute variable transfer.
unsigned int numFromVar() const
Return the number of source variables.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
Base class for all MultiAppTransfer objects.
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
static InputParameters validParams()
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
@ FROM_MULTIAPP
Definition Transfer.h:71
@ TO_MULTIAPP
Definition Transfer.h:70
@ BETWEEN_MULTIAPP
Definition Transfer.h:72
MooseEnum _current_direction
Definition Transfer.h:106