https://mooseframework.inl.gov
MultiAppTransfer.h
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 #pragma once
11 
12 // MOOSE includes
13 #include "Transfer.h"
14 #include "MultiMooseEnum.h"
15 #include "MultiApp.h"
16 #include "MooseAppCoordTransform.h"
17 
18 #include "libmesh/bounding_box.h"
19 
20 class MooseMesh;
21 
31 class MultiAppTransfer : public Transfer
32 {
33 public:
35 
37 
41  void variableIntegrityCheck(const AuxVariableName & var_name, bool is_from_multiapp) const;
42 
43  void initialSetup() override;
44 
48  const std::shared_ptr<MultiApp> getMultiApp() const
49  {
51  mooseError("Unclear which app you want to retrieve from Transfer ", name());
52  else if (_from_multi_app)
53  return _from_multi_app;
54  else if (_to_multi_app)
55  return _to_multi_app;
56  else if (_multi_app)
57  return _multi_app;
58  else
59  mooseError("Should not get here, there should be a multiapp");
60  }
61 
65  const std::shared_ptr<MultiApp> getFromMultiApp() const
66  {
67  if (!_from_multi_app)
68  mooseError(
69  "A from_multiapp was requested but is unavailable. Check the from_multi_app parameter");
70  else
71  return _from_multi_app;
72  }
73 
77  const std::shared_ptr<MultiApp> getToMultiApp() const
78  {
79  if (!_to_multi_app)
80  mooseError(
81  "A to_multiapp was requested but is unavailable. Check the to_multi_app parameter");
82  else
83  return _to_multi_app;
84  }
85 
90  std::string getFromName() const
91  {
92  if (_from_multi_app)
93  return _from_multi_app->name();
94  else
95  return "Parent";
96  }
97 
102  std::string getToName() const
103  {
104  if (_to_multi_app)
105  return _to_multi_app->name();
106  else
107  return "Parent";
108  }
109 
113  bool hasFromMultiApp() const { return !(!_from_multi_app); }
114 
118  bool hasToMultiApp() const { return !(!_to_multi_app); }
119 
124  virtual void getAppInfo();
125 
130  static void addSkipCoordCollapsingParam(InputParameters & params);
131 
132 protected:
137 
141  static void addBBoxFactorParam(InputParameters & params);
142 
147  static void transformBoundingBox(libMesh::BoundingBox & box,
148  const MultiAppCoordTransform & transform);
149 
151  std::shared_ptr<MultiApp> _multi_app;
152 
153  std::vector<FEProblemBase *> _to_problems;
154  std::vector<FEProblemBase *> _from_problems;
155  std::vector<libMesh::EquationSystems *> _to_es;
156  std::vector<libMesh::EquationSystems *> _from_es;
157  std::vector<MooseMesh *> _to_meshes;
158  std::vector<MooseMesh *> _from_meshes;
159  std::vector<Point> _to_positions;
160  std::vector<Point> _from_positions;
161  std::vector<std::unique_ptr<MultiAppCoordTransform>> _to_transforms;
162  std::vector<std::unique_ptr<MultiAppCoordTransform>> _from_transforms;
163 
167 
172 
182 
184 
194  std::vector<libMesh::BoundingBox> getFromBoundingBoxes();
195  std::vector<libMesh::BoundingBox> getFromBoundingBoxes(BoundaryID boundary_id);
197 
202  std::vector<unsigned int> getFromsPerProc();
203 
208  libMesh::NumericVector<Real> & getTransferVector(unsigned int i_local, std::string var_name);
209 
211  std::vector<unsigned int> _to_local2global_map;
213  std::vector<unsigned int> _from_local2global_map;
214 
218  unsigned int getGlobalSourceAppIndex(unsigned int i_from) const;
222  unsigned int getGlobalTargetAppIndex(unsigned int i_to) const;
227  unsigned int getLocalSourceAppIndex(unsigned int i_from) const;
228 
232  virtual void checkSiblingsTransferSupported() const
233  {
234  mooseError("Siblings transfer not supported. You cannot transfer both from a multiapp to "
235  "another multiapp");
236  }
237 
243  void checkParentAppUserObjectExecuteOn(const std::string & object_name) const;
244 
252  void errorIfObjectExecutesOnTransferInSourceApp(const std::string & object_name) const;
253 
262  Point getPointInTargetAppFrame(const Point & p,
263  unsigned int local_i_to,
264  const std::string & phase) const;
265 
274  Point getPointInSourceAppFrame(const Point & p,
275  unsigned int local_i_from,
276  const std::string & phase) const;
277 
284  void checkMultiAppExecuteOn();
285 
294  void checkVariable(const FEProblemBase & fe_problem,
295  const VariableName & var_name,
296  const std::string & param_name = "") const;
297 
301  void extendBoundingBoxes(const Real factor, std::vector<libMesh::BoundingBox> & bboxes) const;
302 
303 private:
308  virtual bool usesMooseAppCoordTransform() const { return false; }
309 
316  const Point & p,
317  const std::string & phase) const;
318 
320  std::shared_ptr<MultiApp> _from_multi_app;
321  std::shared_ptr<MultiApp> _to_multi_app;
322 
323  void getFromMultiAppInfo();
324  void getToMultiAppInfo();
325 
328  std::unique_ptr<MooseAppCoordTransform> _from_moose_app_transform;
329 
332  std::unique_ptr<MooseAppCoordTransform> _to_moose_app_transform;
333 };
libMesh::NumericVector< Real > & getTransferVector(unsigned int i_local, std::string var_name)
If we are transferring to a multiapp, return the appropriate solution vector.
std::vector< std::unique_ptr< MultiAppCoordTransform > > _to_transforms
std::vector< libMesh::EquationSystems * > _to_es
std::unique_ptr< MooseAppCoordTransform > _to_moose_app_transform
The moose coordinate transformation object describing rotations, scaling, and coordinate system of th...
static void transformBoundingBox(libMesh::BoundingBox &box, const MultiAppCoordTransform &transform)
Transform a bounding box according to the transformations in the provided coordinate transformation o...
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
const bool _skip_coordinate_collapsing
Whether to skip coordinate collapsing (transformations of coordinates between applications using diff...
Point getPointInSourceAppFrame(const Point &p, unsigned int local_i_from, const std::string &phase) const
Get the source app point from a point in the reference frame.
void variableIntegrityCheck(const AuxVariableName &var_name, bool is_from_multiapp) const
Utility to verify that the variable in the destination system exists.
unsigned int getLocalSourceAppIndex(unsigned int i_from) const
Return the local app index from the global index in the "from-multiapp" transfer direction.
static void addUserObjectExecutionCheckParam(InputParameters &params)
Add the execution order check parameter (to skip the warning if needed)
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
void checkMultiAppExecuteOn()
Helper method for checking the &#39;check_multiapp_execute_on&#39; flag.
std::shared_ptr< MultiApp > _from_multi_app
The MultiApps this Transfer is transferring data to or from.
MultiAppTransfer(const InputParameters &parameters)
std::vector< libMesh::BoundingBox > getFromBoundingBoxes()
Return the bounding boxes of all the "from" domains, including all the domains not local to this proc...
std::vector< FEProblemBase * > _to_problems
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void checkParentAppUserObjectExecuteOn(const std::string &object_name) const
Checks the execute_on flags for user object transfers with user objects on the source app which is al...
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
std::vector< Point > _from_positions
std::shared_ptr< MultiApp > _multi_app
Deprecated class attribute for compatibility with the apps.
bool hasFromMultiApp() const
Whether the transfer owns a non-null from_multi_app.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Point getPointInTargetAppFrame(const Point &p, unsigned int local_i_to, const std::string &phase) const
Get the target app point from a point in the reference frame.
std::vector< unsigned int > _to_local2global_map
Given local app index, returns global app index.
void checkVariable(const FEProblemBase &fe_problem, const VariableName &var_name, const std::string &param_name="") const
Helper for checking a problem for a variable.
unsigned int getGlobalTargetAppIndex(unsigned int i_to) const
Return the global app index from the local index in the "to-multiapp" transfer direction.
bool _displaced_target_mesh
True if displaced mesh is used for the target mesh, otherwise false.
Point mapBackWithoutCollapsing(MultiAppCoordTransform &transform, const Point &p, const std::string &phase) const
Shared implementation for getPointInSourceAppFrame / getPointInTargetAppFrame.
virtual bool usesMooseAppCoordTransform() const
Whether this transfer handles non-translation-based transformations, e.g.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
std::vector< libMesh::EquationSystems * > _from_es
std::vector< MooseMesh * > _from_meshes
void errorIfObjectExecutesOnTransferInSourceApp(const std::string &object_name) const
Error if executing this MooseObject on EXEC_TRANSFER in a source multiapp (from_multiapp, e.g.
void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup...
boundary_id_type BoundaryID
std::unique_ptr< MooseAppCoordTransform > _from_moose_app_transform
The moose coordinate transformation object describing rotations, scaling, and coordinate system of th...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:93
std::vector< unsigned int > getFromsPerProc()
Return the number of "from" domains that each processor owns.
unsigned int getGlobalSourceAppIndex(unsigned int i_from) const
Return the global app index from the local index in the "from-multiapp" transfer direction.
std::shared_ptr< MultiApp > _to_multi_app
static InputParameters validParams()
std::string getFromName() const
Get the name of thing being transferred from.
std::string getToName() const
Get the name of thing being transferred to.
std::vector< Point > _to_positions
const std::shared_ptr< MultiApp > getMultiApp() const
Use this getter to obtain the MultiApp for transfers with a single direction.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Base class for all MultiAppTransfer objects.
Real _bbox_factor
Extend (or contract) bounding box by a factor in all directions Greater than one values of this membe...
std::vector< std::unique_ptr< MultiAppCoordTransform > > _from_transforms
bool hasToMultiApp() const
Whether the transfer owns a non-null to_multi_app.
bool _displaced_source_mesh
True if displaced mesh is used for the source mesh, otherwise false.
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
std::vector< unsigned int > _from_local2global_map
Given local app index, returns global app index.
static void addBBoxFactorParam(InputParameters &params)
Add the bounding box factor parameter to the supplied input parameters.
static void addSkipCoordCollapsingParam(InputParameters &params)
Add the option to skip coordinate collapsing in coordinate transformation operations Note: this is us...
void extendBoundingBoxes(const Real factor, std::vector< libMesh::BoundingBox > &bboxes) const
Extends bounding boxes to avoid missing points.
virtual void checkSiblingsTransferSupported() const
Whether the transfer supports siblings transfer.
virtual void getAppInfo()
This method will fill information into the convenience member variables (_to_problems, _from_meshes, etc.)
std::vector< FEProblemBase * > _from_problems
std::vector< MooseMesh * > _to_meshes
This class contains transformation information that only exists in a context in which there are multi...
Base class for all Transfer objects.
Definition: Transfer.h:36