https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MultiAppFXTransfer.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#include "FEProblemBase.h"
11#include "Function.h"
12#include "MultiApp.h"
13#include "UserObject.h"
14
15#include "MultiAppFXTransfer.h"
16
17registerMooseObject("FunctionalExpansionToolsApp", MultiAppFXTransfer);
18
21{
23
24 params.addClassDescription("Transfers coefficient arrays between objects that are derived from "
25 "MutableCoefficientsInterface; currently includes the following "
26 "types: FunctionSeries, FXBoundaryUserObject, and FXVolumeUserObject");
27
28 params.addRequiredParam<std::string>(
29 "this_app_object_name",
30 "Name of the MutableCoefficientsInterface-derived object in this app (LocalApp).");
31
32 params.addRequiredParam<std::string>(
33 "multi_app_object_name",
34 "Name of the MutableCoefficientsInterface-derived object in the MultiApp.");
35
36 // Sibling transfers not supported
37 params.suppressParameter<bool>("execute_after_from_multiapp");
38
39 return params;
40}
41
43 : MultiAppTransfer(parameters),
44 _this_app_object_name(getParam<std::string>("this_app_object_name")),
45 _multi_app_object_name(getParam<std::string>("multi_app_object_name")),
46 getMultiAppObject(NULL),
47 getSubAppObject(NULL)
48{
49 if (_directions.size() != 1)
50 paramError("direction", "This transfer is only unidirectional");
52 mooseError("This transfer does not currently support between_multiapp transfer");
53}
54
55void
57{
58 const auto multi_app = hasFromMultiApp() ? getFromMultiApp() : getToMultiApp();
59
60 // Search for the _this_app_object_name in the LocalApp
62 scanProblemBaseForObject(multi_app->problemBase(), _this_app_object_name, "MultiApp");
63 if (getMultiAppObject == NULL)
65 "Transfer '", name(), "': Cannot find object '", _this_app_object_name, "' in MultiApp");
66
67 // Search for the _multi_app_object_name in each of the MultiApps
68 for (std::size_t i = 0; i < multi_app->numGlobalApps(); ++i)
69 if (multi_app->hasLocalApp(i))
70 {
71 if (i == 0) // First time through, assign without checking against previous values
73 multi_app->appProblemBase(i), _multi_app_object_name, multi_app->name());
74 else if (getSubAppObject != scanProblemBaseForObject(multi_app->appProblemBase(i),
76 multi_app->name()))
77 mooseError("The name '",
79 "' is assigned to two different object types. Please modify your input file and "
80 "try again.");
81 }
82 if (getSubAppObject == NULL)
84 "Transfer '", name(), "': Cannot find object '", _multi_app_object_name, "' in SubApp");
85}
86
89 const std::string & object_name,
90 const std::string & app_name)
91{
92 /*
93 * For now we are only considering Functions and UserObjects, as they are the only types currently
94 * implemented with MutableCoefficientsInterface. Others may be added later.
95 *
96 * Functions:
97 * FunctionSeries
98 *
99 * UserObjects:
100 * FXBoundaryUserObject (via FXBaseUserObject)
101 * FXVolumeUserObject (via FXBaseUserObject)
102 */
104
105 // Check to see if the object with object_name is a Function
106 if (base.hasFunction(object_name))
107 {
108 Function & function = base.getFunction(object_name);
109 interface = dynamic_cast<MutableCoefficientsInterface *>(&function);
110
111 // Check to see if the function is a subclass of MutableCoefficientsInterface
112 if (interface)
114 else
115 mooseError("Function '",
116 object_name,
117 "' in '",
118 app_name,
119 "' does not inherit from MutableCoefficientsInterface.",
120 " Please change the function type and try again.");
121 }
122 // Check to see if the object with object_name is a UserObject
123 else if (base.hasUserObject(object_name))
124 {
125 // Get the non-const qualified UserObject, otherwise we would use getUserObject()
126 auto & user_object = base.getUserObject<UserObject>(object_name);
127 interface = dynamic_cast<MutableCoefficientsInterface *>(&user_object);
128
129 // Check to see if the userObject is a subclass of MutableCoefficientsInterface
130 if (interface)
132 else
133 mooseError("UserObject '",
134 object_name,
135 "' in '",
136 app_name,
137 "' does not inherit from MutableCoefficientsInterface.",
138 " Please change the function type and try again.");
139 }
140
141 return NULL;
142}
143
146 const std::string & object_name,
147 THREAD_ID thread)
148{
149 return dynamic_cast<MutableCoefficientsInterface &>(base.getFunction(object_name, thread));
150}
151
154 const std::string & object_name,
155 THREAD_ID thread)
156{
157 // Get the non-const qualified UserObject, otherwise we would use getUserObject()
158 auto & user_object = base.getUserObject<UserObject>(object_name, thread);
159 return dynamic_cast<MutableCoefficientsInterface &>(user_object);
160}
161
162void
164{
165 _console << "Beginning MultiAppFXTransfer: " << name() << std::endl;
166
167 switch (_current_direction)
168 {
169 // LocalApp -> MultiApp
170 case TO_MULTIAPP:
171 {
172 // Get a reference to the object in the LocalApp
173 const MutableCoefficientsInterface & from_object =
174 (this->*getMultiAppObject)(getToMultiApp()->problemBase(), _this_app_object_name, 0);
175
176 for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); ++i)
177 {
178 if (getToMultiApp()->hasLocalApp(i))
179 for (THREAD_ID t = 0; t < libMesh::n_threads(); ++t)
180 {
181 // Get a reference to the object in each MultiApp
182 MutableCoefficientsInterface & to_object = (this->*getSubAppObject)(
183 getToMultiApp()->appProblemBase(i), _multi_app_object_name, t);
184
185 if (to_object.isCompatibleWith(from_object))
186 to_object.importCoefficients(from_object);
187 else
188 mooseError("'",
190 "' is not compatible with '",
192 "'");
193 }
194 }
195 break;
196 }
197
198 // MultiApp -> LocalApp
199 case FROM_MULTIAPP:
200 {
201 /*
202 * For now we will assume that the transfers are 1:1 and the coefficients are synchronized
203 * among all instances, thus we only need to grab the set of coefficients from the first
204 * SubApp.
205 */
206 if (getFromMultiApp()->hasLocalApp(0))
207 {
208 // Get a reference to the first thread object in the first MultiApp
209 const MutableCoefficientsInterface & from_object = (this->*getSubAppObject)(
210 getFromMultiApp()->appProblemBase(0), _multi_app_object_name, 0);
211
212 for (THREAD_ID t = 0; t < libMesh::n_threads(); ++t)
213 {
214 // Get a reference to the object in each LocalApp instance
215 MutableCoefficientsInterface & to_object = (this->*getMultiAppObject)(
216 getFromMultiApp()->problemBase(), _this_app_object_name, t);
217
218 if (to_object.isCompatibleWith(from_object))
219 to_object.importCoefficients(from_object);
220 else
221 mooseError("'",
223 "' is not compatible with '",
225 "'");
226 }
227 }
228 break;
229 }
230 }
231
232 _console << "Finished MultiAppFXTransfer: " << name() << std::endl;
233}
unsigned int THREAD_ID
registerMooseObject("FunctionalExpansionToolsApp", MultiAppFXTransfer)
const ConsoleStream _console
T & getUserObject(const std::string &name, unsigned int tid=0) const
bool hasUserObject(const std::string &name) const
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
void suppressParameter(const std::string &name)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
const std::string & name() const
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
Transfers mutable coefficient arrays between supported object types.
virtual GetProblemObject scanProblemBaseForObject(FEProblemBase &base, const std::string &object_name, const std::string &app_name)
Searches an FEProblemBase for a MutableCoefficientsInterface-based object and returns a function poin...
MutableCoefficientsInterface & getMutableCoefficientsFunction(FEProblemBase &base, const std::string &object_name, THREAD_ID thread)
Gets a MutableCoefficientsInterface-based Function, intented for use via function pointer.
const std::string _multi_app_object_name
Name of the MutableCoefficientsInterface-derived object in the MultiApp.
GetProblemObject getSubAppObject
Function pointer for grabbing the SubApp object.
MutableCoefficientsInterface & getMutableCoefficientsUserOject(FEProblemBase &base, const std::string &object_name, THREAD_ID thread)
Gets a MutableCoefficientsInterface-based UserObject, intended for use via function pointer.
virtual void initialSetup() override
virtual void execute() override
const std::string _this_app_object_name
Name of the MutableCoefficientsInterface-derived object in the creating app.
MultiAppFXTransfer(const InputParameters &parameters)
static InputParameters validParams()
MutableCoefficientsInterface &(MultiAppFXTransfer::* GetProblemObject)(FEProblemBase &base, const std::string &object_name, THREAD_ID thread)
Function pointer typedef for functions used to find, convert, and return the appropriate MutableCoeff...
GetProblemObject getMultiAppObject
Function pointer for grabbing the MultiApp object.
bool hasToMultiApp() const
const std::shared_ptr< MultiApp > getToMultiApp() const
static InputParameters validParams()
const std::shared_ptr< MultiApp > getFromMultiApp() const
bool hasFromMultiApp() const
unsigned int size() const
This class is designed to provide a uniform interface for any class that uses an array of coefficient...
void importCoefficients(const MutableCoefficientsInterface &other)
Import the coefficients from another instance.
bool isCompatibleWith(const MutableCoefficientsInterface &other) const
Checks to see if another instance is compatible.
MultiMooseEnum _directions
MooseEnum _current_direction
unsigned int n_threads()