19 #include "libmesh/parallel_algebra.h" 20 #include "libmesh/mesh_tools.h" 27 "The name of the MultiApp to transfer data with",
28 "Use to_multiapp & from_multiapp parameters now");
29 params.
addParam<MultiAppName>(
"from_multi_app",
"The name of the MultiApp to receive data from");
30 params.
addParam<MultiAppName>(
"to_multi_app",
"The name of the MultiApp to transfer the data to");
37 params.
setDocString(
"execute_on", exec_enum.getDocString());
40 "check_multiapp_execute_on",
42 "When false the check between the multiapp and transfer execute on flags is not performed.");
43 params.
addParam<
bool>(
"displaced_source_mesh",
45 "Whether or not to use the displaced mesh for the source mesh.");
46 params.
addParam<
bool>(
"displaced_target_mesh",
48 "Whether or not to use the displaced mesh for the target mesh.");
60 "Multiply bounding box width (in all directions) by the prescribed factor. Values less than " 61 "1 will shrink the bounding box; values greater than 1 will enlarge the bounding box. It is " 62 "generally not advised to ever shrink the bounding box. On the other hand it may be helpful " 63 "to enlarge the bounding box. Larger bounding boxes will lead to more accurate determination " 64 "of the closest node/element with the tradeoff of more communication.");
71 "skip_coordinate_collapsing",
73 "Whether to skip coordinate collapsing (translation and rotation are still performed, only " 74 "XYZ, RZ etc collapsing is skipped) when performing mapping and inverse " 75 "mapping coordinate transformation operations. This parameter should only " 76 "be set by users who really know what they're doing.");
82 _skip_coordinate_collapsing(getParam<bool>(
"skip_coordinate_collapsing")),
83 _displaced_source_mesh(getParam<bool>(
"displaced_source_mesh")),
84 _displaced_target_mesh(getParam<bool>(
"displaced_target_mesh")),
85 _bbox_factor(isParamValid(
"bbox_factor") ? getParam<
Real>(
"bbox_factor") : 1)
102 mooseError(
"from_multi_app and/or to_multi_app must be specified");
121 "BETWEN_MULTIAPP transfers should be specified using to/from_multi_app");
125 if (getParam<bool>(
"check_multiapp_execute_on"))
148 "The deprecated 'direction' parameter is meant to be used in conjunction with the " 149 "'multi_app' parameter");
152 "The deprecated 'direction' parameter is not meant to be used in conjunction with " 153 "the 'from_multi_app' or 'to_multi_app' parameters");
163 mooseWarning(
"MultiAppTransfer execute_on flags do not match associated from_multi_app " 164 "execute_on flags"));
169 mooseWarning(
"MultiAppTransfer execute_on flags do not match associated to_multi_app " 170 "execute_on flags"));
177 mooseWarning(
"MultiAppTransfer execute_on flags do not match associated to_multi_app " 178 "and from_multi_app execute_on flags"));
184 bool variable_found =
false;
185 bool has_an_app =
false;
194 variable_found =
true;
199 for (
unsigned int i = 0; i <
_to_multi_app->numGlobalApps(); i++)
204 variable_found =
true;
207 if (!variable_found && has_an_app)
208 mooseError(
"Cannot find variable ", var_name,
" for ",
name(),
" Transfer");
268 "I believe these should be the same. If not, then it will be difficult to define a " 269 "canonical reference frame.");
296 from_app_transform_construction_data =
298 ?
_to_multi_app->problemBase().coordTransform().minimalDataDescription()
299 :
_from_multi_app->appProblemBase(0).coordTransform().minimalDataDescription();
302 std::make_unique<MooseAppCoordTransform>(from_app_transform_construction_data);
306 to_app_transform_construction_data =
308 ?
_from_multi_app->problemBase().coordTransform().minimalDataDescription()
309 :
_to_multi_app->appProblemBase(0).coordTransform().minimalDataDescription();
312 std::make_unique<MooseAppCoordTransform>(to_app_transform_construction_data);
323 auto create_multiapp_transforms = [
this](
auto & transforms,
324 const auto & moose_app_transform,
325 const bool is_parent_app_transform,
326 const MultiApp *
const multiapp =
nullptr)
328 mooseAssert(is_parent_app_transform || multiapp,
329 "Coordinate transform must be created either for child app or parent app");
330 if (is_parent_app_transform)
332 transforms.push_back(std::make_unique<MultiAppCoordTransform>(moose_app_transform));
338 mooseAssert(transforms.size() == 0,
"transforms should not be initialized at this point");
339 for (
const auto i :
make_range(multiapp->numGlobalApps()))
341 transforms.push_back(std::make_unique<MultiAppCoordTransform>(moose_app_transform));
342 auto & transform = transforms[i];
344 if (multiapp->usingPositions())
345 transform->setTranslationVector(multiapp->position(i));
352 create_multiapp_transforms(
359 create_multiapp_transforms(
364 create_multiapp_transforms(
366 create_multiapp_transforms(
377 "' has non-translation transformations but it does not implement coordinate " 378 "transformations using the 'MooseAppCoordTransform' class. Your data transfers " 379 "will not be performed in the expected transformed frame");
391 check_transform_compatibility(*from_transform);
398 check_transform_compatibility(*to_transform);
406 std::vector<unsigned int> & map,
407 std::vector<FEProblemBase *> & problems,
408 std::vector<Point> & positions)
410 for (
unsigned int i_app = 0; i_app < multi_app.
numGlobalApps(); i_app++)
417 map.push_back(i_app);
418 problems.push_back(&subapp_problem);
420 positions.push_back(multi_app.
position(i_app));
429 mooseError(
"There is no to_multiapp to get info from");
438 mooseError(
"There is no from_multiapp to get info from");
452 const auto extension_factor = factor - 1;
461 for (
auto & box : bboxes)
473 auto width = box.second - box.first;
474 box.second += width * extension_factor;
475 box.first -= width * extension_factor;
479 std::vector<BoundingBox>
482 std::vector<std::pair<Point, Point>> bb_points(
_from_meshes.size());
487 BoundingBox bbox = MeshTools::create_local_bounding_box(*
_from_meshes[i]);
496 bb_points[i] =
static_cast<std::pair<Point, Point>
>(bbox);
503 std::vector<BoundingBox> bboxes(bb_points.size());
504 for (
unsigned int i = 0; i < bb_points.size(); i++)
505 bboxes[i] = static_cast<BoundingBox>(bb_points[i]);
513 std::vector<BoundingBox>
516 std::vector<std::pair<Point, Point>> bb_points(
_from_meshes.size());
517 const Real min_r = std::numeric_limits<Real>::lowest();
523 Point
min(max_r, max_r, max_r);
524 Point
max(min_r, min_r, min_r);
525 bool at_least_one =
false;
529 for (
const auto & bnode : bnd_nodes)
531 if (bnode->_bnd_id == boundary_id &&
532 bnode->_node->processor_id() ==
_from_meshes[i]->processor_id())
535 const auto & node = *bnode->_node;
544 BoundingBox bbox(
min,
max);
557 bb_points[i] =
static_cast<std::pair<Point, Point>
>(bbox);
564 std::vector<BoundingBox> bboxes(bb_points.size());
565 for (
unsigned int i = 0; i < bb_points.size(); i++)
566 bboxes[i] = static_cast<BoundingBox>(bb_points[i]);
574 std::vector<unsigned int>
577 std::vector<unsigned int> froms_per_proc;
585 return froms_per_proc;
588 NumericVector<Real> &
591 mooseAssert(
_to_multi_app,
"getTransferVector only works for transfers to multiapps");
598 const VariableName & var_name,
599 const std::string & param_name)
const 603 if (param_name.empty())
604 mooseError(
"The variable '", var_name,
"' does not exist.");
606 paramError(param_name,
"The variable '", var_name,
"' does not exist.");
612 unsigned int local_i_to,
613 const std::string & phase)
const 616 if (to_transform->hasCoordinateSystemTypeChange())
619 mooseInfo(phase +
" cannot use the point in the target app frame due to the " 620 "non-uniqueness of the coordinate collapsing reverse mapping." 621 " Coordinate collapse is ignored for this operation");
622 to_transform->skipCoordinateCollapsing(
true);
623 const auto target_point = to_transform->mapBack(p);
624 to_transform->skipCoordinateCollapsing(
false);
628 return to_transform->mapBack(p);
635 "Out of bounds local from-app index");
643 "Out of bounds local to-app index");
NumericVector< Real > & getTransferVector(unsigned int i_local, std::string var_name)
If we are transferring to a multiapp, return the appropriate solution vector.
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
std::vector< std::unique_ptr< MultiAppCoordTransform > > _to_transforms
bool hasLocalApp(unsigned int global_app) const
Whether or not the given global app number is on this processor.
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
void extendBoundingBoxes(const Real factor, std::vector< BoundingBox > &bboxes) const
Extends bounding boxes to avoid missing points.
A MultiMooseEnum object to hold "execute_on" flags.
std::unique_ptr< MooseAppCoordTransform > _to_moose_app_transform
The moose coordinate transformation object describing rotations, scaling, and coordinate system of th...
const bool _skip_coordinate_collapsing
Whether to skip coordinate collapsing (transformations of coordinates between applications using diff...
MooseEnum _current_direction
unsigned int getLocalSourceAppIndex(unsigned int i_from) const
Return the local app index from the global index in the "from-multiapp" transfer direction We use the...
void mooseInfo(Args &&... args) const
std::vector< EquationSystems * > _to_es
void checkMultiAppExecuteOn()
Helper method for checking the 'check_multiapp_execute_on' flag.
std::shared_ptr< MultiApp > _from_multi_app
The MultiApps this Transfer is transferring data to or from.
MultiAppTransfer(const InputParameters ¶meters)
std::vector< 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
processor_id_type rank() const
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
FEProblemBase & _fe_problem
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
std::vector< Point > _from_positions
const Parallel::Communicator & _communicator
std::shared_ptr< MultiApp > _multi_app
Deprecated class attribute for compatibility with the apps.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
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.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
auto max(const L &left, const R &right)
std::shared_ptr< MultiApp > getMultiApp(const std::string &multi_app_name) const
Get a MultiApp object by name.
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 ¶m_name="") const
Helper for checking a problem for a variable.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
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.
virtual bool usesMooseAppCoordTransform() const
Whether this transfer handles non-translation-based transformations, e.g.
processor_id_type n_processors() const
std::vector< MooseMesh * > _from_meshes
void variableIntegrityCheck(const AuxVariableName &var_name) const
Utility to verify that the variable in the destination system exists.
unsigned int numGlobalApps() const
void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup...
boundary_id_type BoundaryID
void getFromMultiAppInfo()
std::unique_ptr< MooseAppCoordTransform > _from_moose_app_transform
The moose coordinate transformation object describing rotations, scaling, and coordinate system of th...
const ExecFlagEnum & getExecuteOnEnum() const
Return the execute on MultiMooseEnum for this object.
std::vector< unsigned int > getFromsPerProc()
Return the number of "from" domains that each processor owns.
static InputParameters validParams()
const std::string & type() const
Get the type of this class.
FEProblemBase & appProblemBase(unsigned int app)
Get the FEProblemBase for the global app desired.
unsigned int getGlobalSourceAppIndex(unsigned int i_from) const
Return the global app index from the local index in the "from-multiapp" transfer direction.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
std::shared_ptr< MultiApp > _to_multi_app
static InputParameters validParams()
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
static void transformBoundingBox(BoundingBox &box, const MultiAppCoordTransform &transform)
Transform a bounding box according to the transformations in the provided coordinate transformation o...
bool usingPositions() const
Whether or not this MultiApp is using positions or its own way for constructing sub-apps.
std::vector< Point > _to_positions
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
MultiMooseEnum _directions
The directions this Transfer is to be executed on.
Real _bbox_factor
Extend (or contract) bounding box by a factor in all directions Greater than one values of this membe...
void push_back(const std::string &names)
Insert operators Operator to insert (push_back) values into the enum.
std::vector< EquationSystems * > _from_es
std::vector< std::unique_ptr< MultiAppCoordTransform > > _from_transforms
IntRange< T > make_range(T beg, T end)
bool _displaced_source_mesh
True if displaced mesh is used for the source mesh, otherwise false.
const ExecFlagType EXEC_SAME_AS_MULTIAPP
std::vector< unsigned int > _from_local2global_map
Given local app index, returns global app index.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
static void addBBoxFactorParam(InputParameters ¶ms)
Add the bounding box factor parameter to the supplied input parameters.
const InputParameters & parameters() const
Get the parameters of the object.
static void addSkipCoordCollapsingParam(InputParameters ¶ms)
Add the option to skip coordinate collapsing in coordinate transformation operations.
static void transformBoundingBox(BoundingBox &box, const MultiAppCoordTransform &transform)
Transform a bounding box according to the transformations in the provided coordinate transformation o...
virtual void checkSiblingsTransferSupported() const
Whether the transfer supports siblings transfer.
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
A MultiApp represents one or more MOOSE applications that are running simultaneously.
virtual void getAppInfo()
This method will fill information into the convenience member variables (_to_problems, _from_meshes, etc.)
auto min(const L &left, const R &right)
std::vector< FEProblemBase * > _from_problems
auto index_range(const T &sizable)
const Point & position(unsigned int app) const
The physical position of a global App number.
std::vector< MooseMesh * > _to_meshes
Base class for all Transfer objects.