https://mooseframework.inl.gov
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 
12 #include "MFEMMultiAppTransfer.h"
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 
37 void
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;
61  case BETWEEN_MULTIAPP:
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 
81 EquationSystems &
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
unsigned int numFromVar() const
Return the number of source variables.
libMesh::EquationSystems & getlibMeshEquationSystem(FEProblemBase &problem, bool use_displaced) const
Get libMesh EquationSystem, which may or may not be displaced.
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
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:467
MooseEnum _current_direction
Definition: Transfer.h:106
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.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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...
unsigned int numToVar() const
Return for the number of destination variables.
virtual libMesh::EquationSystems & es() override
void setActiveToProblem(FEProblemBase &to_problem, const unsigned int global_app_index)
Set current problem to fetch destination variables from.
MFEMMultiAppTransfer(InputParameters const &params)
static InputParameters validParams()
void setActiveFromProblem(FEProblemBase &from_problem, const unsigned int global_app_index)
Set current problem to fetch source variables from.
static InputParameters validParams()
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
Base class for all MultiAppTransfer objects.
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
virtual void transferVariables(bool is_target_local)=0
Transfer all variables from active source problem to active destination problem.
void execute() override
Set active source and destination problems, and execute variable transfer.