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