https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MultiAppCopyTransfer.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// MOOSE includes
12#include "FEProblemBase.h"
13#include "MultiApp.h"
14#include "SystemBase.h"
15
16#include "libmesh/id_types.h"
17#include "libmesh/string_to_enum.h"
18
20
23{
25 params.addRequiredParam<std::vector<AuxVariableName>>(
26 "variable", "The auxiliary variable to store the transferred values in.");
27 params.addRequiredParam<std::vector<VariableName>>("source_variable",
28 "The variable to transfer from.");
29
31 "Copies variables (nonlinear and auxiliary) between multiapps that have identical meshes.");
32 return params;
33}
34
36 : MultiAppDofCopyTransfer(parameters),
37 _from_var_names(getParam<std::vector<VariableName>>("source_variable")),
38 _to_var_names(getParam<std::vector<AuxVariableName>>("variable"))
39{
40 /* Right now, most of derived transfers support one variable only */
41 _to_var_name = _to_var_names.size() ? _to_var_names[0] : "INVALID";
42 _from_var_name = _from_var_names.size() ? _from_var_names[0] : "INVALID";
43}
44
45void
47{
48 TIME_SECTION("MultiAppCopyTransfer::execute()", 5, "Copies variables");
49
51 {
52 FEProblemBase & from_problem = getToMultiApp()->problemBase();
53 for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); i++)
54 if (getToMultiApp()->hasLocalApp(i))
55 transfer(getToMultiApp()->appProblemBase(i), from_problem);
56 }
57
59 {
60 FEProblemBase & to_problem = getFromMultiApp()->problemBase();
61 for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++)
62 if (getFromMultiApp()->hasLocalApp(i))
63 transfer(to_problem, getFromMultiApp()->appProblemBase(i));
64 }
65
67 {
68 int transfers_done = 0;
69 for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++)
70 {
71 if (getFromMultiApp()->hasLocalApp(i))
72 {
73 if (getToMultiApp()->hasLocalApp(i))
74 {
75 transfer(getToMultiApp()->appProblemBase(i), getFromMultiApp()->appProblemBase(i));
76 transfers_done++;
77 }
78 }
79 }
80 if (!transfers_done)
81 mooseError("BETWEEN_MULTIAPP transfer not supported if there is not at least one subapp "
82 "per multiapp involved on each rank");
83 }
84}
85
86void
88{
89 // Check that we are in the supported configuration: same number of source and target apps
90 // The allocation of the child apps on the processors must be the same
91 if (getFromMultiApp()->numGlobalApps() == getToMultiApp()->numGlobalApps())
92 {
93 for (const auto i : make_range(getToMultiApp()->numGlobalApps()))
94 if (getFromMultiApp()->hasLocalApp(i) + getToMultiApp()->hasLocalApp(i) == 1)
95 mooseError("Child application allocation on parallel processes must be the same to support "
96 "siblings variable field copy transfer");
97 }
98 else
99 mooseError("Number of source and target child apps must match for siblings transfer");
100}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", MultiAppCopyTransfer)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Copy variables directly from one application to another, based on degree-of-freedom indexing TODO: Re...
virtual void checkSiblingsTransferSupported() const override
Whether the transfer supports siblings transfer.
static InputParameters validParams()
const std::vector< VariableName > _from_var_names
Name of variables transferring from.
const std::vector< AuxVariableName > _to_var_names
Name of variables transferring to.
virtual void execute() override
Performs the transfer of a variable (Nonlinear or Auxiliary) to/from the Multiapp.
MultiAppCopyTransfer(const InputParameters &parameters)
VariableName _from_var_name
Name of variables transferring from.
AuxVariableName _to_var_name
Name of variables transferring to.
Copy the fields directly from one application to another, based on degree-of-freedom indexing.
void transfer(FEProblemBase &to_problem, FEProblemBase &from_problem)
Performs the transfer of a variable between two problems if they have the same mesh.
static InputParameters validParams()
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.
@ 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