24 #include "libmesh/point_locator_base.h" 25 #include "libmesh/enum_point_locator_type.h" 48 "Factor to inflate or deflate the source app bounding boxes");
50 "fixed_bounding_box_size",
51 "fixed_bounding_box_size >= 0",
52 "Override source app bounding box size(s) for searches. App bounding boxes will still be " 53 "centered on the same coordinates. Only non-zero components passed will override.");
55 "extrapolation_constant",
57 "Constant to use when no source app can provide a valid value for a target location.");
60 params.
addParam<std::vector<SubdomainName>>(
62 "Subdomain restriction to transfer from (defaults to all the origin app domain)");
63 params.
addParam<std::vector<SubdomainName>>(
64 "to_blocks",
"Subdomain restriction to transfer to, (defaults to all the target app domain)");
67 params.
addParam<std::vector<BoundaryName>>(
69 "The boundary we are transferring from (if not specified, whole domain is used).");
70 params.
addParam<std::vector<BoundaryName>>(
72 "The boundary we are transferring to (if not specified, whole domain is used).");
73 MooseEnum nodes_or_sides(
"nodes sides",
"sides");
76 "Whether elemental variable boundary restriction is considered by " 77 "element side or element nodes");
80 params.
addParam<MeshDivisionName>(
"from_mesh_division",
81 "Mesh division object on the origin application");
82 params.
addParam<MeshDivisionName>(
"to_mesh_division",
83 "Mesh division object on the target application");
84 MooseEnum mesh_division_uses(
"spatial_restriction matching_division matching_subapp_index none",
88 "How to use the source mesh division in the transfer. See object " 89 "documentation for description of each option");
92 "How to use the target mesh division in the transfer. See object " 93 "documentation for description of each option");
96 params.
addParam<std::vector<unsigned int>>(
"source_variable_components",
97 std::vector<unsigned int>(),
98 "The source array or vector variable component(s).");
99 params.
addParam<std::vector<unsigned int>>(
"target_variable_components",
100 std::vector<unsigned int>(),
101 "The target array or vector variable component(s).");
107 "Whether or not to send a point to all the domains. If true, all the processors will be " 108 "checked for a given point." 109 "The code will be slow if this flag is on but it will give a better solution.");
113 "Whether or not to error in the case that a target point is not found in the source domain.");
114 params.
addParam<
bool>(
"use_bounding_boxes",
116 "When set to false, bounding boxes will not be used to restrict the source " 117 "of the transfer. Either source applications must be set using the " 118 "from_mesh_division parameter, or a greedy search must be used.");
122 "When True, transfers from a child application will work by finding the nearest (using " 123 "the `position` + mesh centroid) sub-app and query that app for the value to transfer.");
125 "use_nearest_position",
126 "Name of the the Positions object (in main app) such that transfers to/from a child " 127 "application will work by finding the nearest position to a target and query only the " 128 "app / points closer to this position than to any other position for the value to transfer.");
130 "from_app_must_contain_point",
132 "Wether on not the origin mesh must contain the point to evaluate data at. If false, this " 133 "allows for interpolation between origin app meshes. Origin app bounding boxes are still " 134 "considered so you may want to increase them with 'fixed_bounding_box_size'");
135 params.
addParam<
bool>(
"search_value_conflicts",
137 "Whether to look for potential conflicts between two valid and different " 138 "source values for any target point");
140 "value_conflicts_output",
142 "Maximum number of conflicts to output if value-conflicts, from equidistant sources to a " 143 "given transfer target location, search is turned on");
146 "to_blocks from_blocks to_boundaries from_boundaries elemental_boundary_restriction " 147 "from_mesh_division from_mesh_division_usage to_mesh_division to_mesh_division_usage",
148 "Transfer spatial restriction");
150 "greedy_search use_bounding_boxes use_nearest_app use_nearest_position " 151 "search_value_conflicts",
154 "Extrapolation behavior");
161 _from_var_components(getParam<
std::vector<unsigned
int>>(
"source_variable_components")),
162 _to_var_components(getParam<
std::vector<unsigned
int>>(
"target_variable_components")),
163 _use_bounding_boxes(getParam<bool>(
"use_bounding_boxes")),
164 _use_nearest_app(getParam<bool>(
"use_nearest_app")),
165 _nearest_positions_obj(
166 isParamValid(
"use_nearest_position")
167 ? &_fe_problem.getPositionsObject(getParam<PositionsName>(
"use_nearest_position"))
169 _source_app_must_contain_point(getParam<bool>(
"from_app_must_contain_point")),
170 _from_mesh_division_behavior(getParam<
MooseEnum>(
"from_mesh_division_usage")),
171 _to_mesh_division_behavior(getParam<
MooseEnum>(
"to_mesh_division_usage")),
172 _elemental_boundary_restriction_on_sides(
173 getParam<
MooseEnum>(
"elemental_boundary_restriction") ==
"sides"),
174 _greedy_search(getParam<bool>(
"greedy_search")),
175 _search_value_conflicts(getParam<bool>(
"search_value_conflicts")),
176 _already_output_search_value_conflicts(false),
177 _search_value_conflicts_max_log(getParam<unsigned
int>(
"value_conflicts_output")),
178 _error_on_miss(getParam<bool>(
"error_on_miss")),
179 _default_extrapolation_value(getParam<
Real>(
"extrapolation_constant")),
180 _bbox_factor(getParam<
Real>(
"bbox_factor")),
181 _fixed_bbox_size(isParamValid(
"fixed_bounding_box_size")
182 ? getParam<
std::vector<
Real>>(
"fixed_bounding_box_size")
187 paramError(
"variable",
"The number of variables to transfer to and from should be equal");
192 "This parameter must be equal to the number of source variables");
195 "This parameter must be equal to the number of target variables");
201 paramError(
"use_nearest_app",
"Cannot use nearest-app and nearest-position together");
204 "Should have a 'from_multiapp' when using the nearest-app informed search");
205 auto pos_params =
_app.
getFactory().getValidParams(
"MultiAppPositions");
206 pos_params.set<std::vector<MultiAppName>>(
"multiapps") = {
getFromMultiApp()->name()};
216 "Extrapolation (nearest-source options, outside-app source) parameters have " 217 "been passed, but no subapp bounding box expansion parameters have been passed.");
222 "Cannot pass additional bounding box parameters (sizes, expansion, etc) if we are " 223 "not using bounding boxes");
238 auto &
blocks = getParam<std::vector<SubdomainName>>(
"from_blocks");
239 std::vector<SubdomainID> ids = from_moose_mesh.getSubdomainIDs(
blocks);
242 paramError(
"from_blocks",
"Some blocks were not found in the mesh");
247 auto & boundary_names = getParam<std::vector<BoundaryName>>(
"from_boundaries");
248 std::vector<BoundaryID> boundary_ids = from_moose_mesh.getBoundaryIDs(boundary_names);
251 paramError(
"from_boundaries",
"Some boundaries were not found in the mesh");
256 const auto & mesh_div_name = getParam<MeshDivisionName>(
"from_mesh_division");
262 mooseInfo(
"'from_mesh_division_usage' is set to use a spatial restriction but the " 263 "'from_mesh_division' for source app of global index " +
265 " covers the entire mesh. Do not expect any restriction from a mesh " 266 "division that covers the entire mesh");
271 "Source mesh division cannot match target mesh division if no target mesh " 272 "division is specified");
277 "Cannot match source mesh division index to target subapp index if there is " 278 "only one target: the parent app (not a subapp)");
281 mooseWarning(
"Attempting to match target subapp index with the number of source mesh " 282 "divisions, which is " +
284 " while there are " + std::to_string(
getToMultiApp()->numGlobalApps()) +
290 "We do not support using target subapp index for source division behavior and " 291 "matching the division index for the target mesh division behavior.");
294 paramError(
"from_mesh_division_usage",
"User must specify a 'from_mesh_division_usage'");
298 "'from_mesh_division' must be specified if the usage method is specified");
307 auto &
blocks = getParam<std::vector<SubdomainName>>(
"to_blocks");
308 std::vector<SubdomainID> ids = to_moose_mesh.getSubdomainIDs(
blocks);
311 paramError(
"to_blocks",
"Some blocks were not found in the mesh");
316 auto & boundary_names = getParam<std::vector<BoundaryName>>(
"to_boundaries");
317 std::vector<BoundaryID> boundary_ids = to_moose_mesh.getBoundaryIDs(boundary_names);
320 paramError(
"to_boundaries",
"Some boundaries were not found in the mesh");
325 const auto & mesh_div_name = getParam<MeshDivisionName>(
"to_mesh_division");
331 mooseInfo(
"'to_mesh_division_usage' is set to use a spatial restriction but the " 332 "'to_mesh_division' for target application of global index " +
334 " covers the entire mesh. Do not expect any restriction from a mesh " 335 "division that covers the entire mesh");
341 "Target mesh division cannot match source mesh division if no source mesh " 342 "division is specified");
345 mooseWarning(
"Source and target mesh divisions do not have the same number of bins. If " 346 "this is what you expect, please reach out to a MOOSE or app developer to " 347 "ensure appropriate use");
353 "to_mesh_division_usage",
354 "Cannot match target mesh division index to source subapp index if there is only one " 355 "source: the parent app (not a subapp)");
357 mooseWarning(
"Attempting to match source subapp index with the number of target mesh " 358 "divisions, which is " +
360 " while there are " + std::to_string(
getFromMultiApp()->numGlobalApps()) +
364 "from_mesh_division_usage",
365 "We do not support using source subapp index for the target division behavior and " 366 "matching the division index for the source mesh division behavior.");
369 paramError(
"to_mesh_division_usage",
"User must specify a 'to_mesh_division_usage'");
373 "'to_mesh_division' must be specified if usage method '" +
388 paramError(
"source_variable_components",
"Component must be passed for an array variable");
391 "Component passed is larger than size of variable");
404 paramError(
"target_variable_components",
"Component must be passed for an array variable");
407 "Component passed is larger than size of variable");
441 "MultiAppGeneralFieldTransfer::execute()_" +
name(), 5,
"Transfer execution " +
name());
491 mooseAssert(i <
_var_size,
"The variable of index " << i <<
" does not exist");
507 auto gather_functor =
509 const std::vector<std::pair<Point, unsigned int>> & incoming_locations,
510 std::vector<std::pair<Real, Real>> & outgoing_vals)
512 outgoing_vals.resize(
513 incoming_locations.size(),
524 auto action_functor = [
this, &i, &dofobject_to_valsvec, &interp_caches, &distance_caches](
526 const std::vector<std::pair<Point, unsigned int>> & my_outgoing_points,
527 const std::vector<std::pair<Real, Real>> & incoming_vals)
537 dofobject_to_valsvec,
544 const std::pair<Real, Real> * ex =
nullptr;
545 libMesh::Parallel::pull_parallel_vector_data(
546 comm(), outgoing_points, gather_functor, action_functor, ex);
558 std::set<processor_id_type> & processors)
585 for (
unsigned int i_from = from0; i_from < from0 +
_froms_per_proc[i_proc]; ++i_from)
589 processors.insert(i_proc);
592 mooseAssert(i_from <
getFromMultiApp()->numGlobalApps(),
"We should not reach this");
597 "Should only be one source processor when using more processors than source apps");
611 if (
distance < nearest_max_distance)
615 unsigned int from0 = 0;
619 for (
unsigned int i_from = from0; i_from < from0 +
_froms_per_proc[i_proc]; ++i_from)
626 processors.insert(i_proc);
637 processors.insert(i_proc);
652 if (target_div == saved_target_div)
655 saved_target_div = target_div;
662 processors.insert(i_proc);
668 mooseError(
"No algorithm were selected to find which processes may send value data " 669 "for a each target point. Please either specify using bounding boxes, " 670 "greedy search, or to_mesh_division-based parameters");
675 "Cannot find a source application to provide a value at point: ",
678 "It must be that mismatched meshes, between the source and target application, are being " 679 "used.\nIf you are using the bounding boxes or nearest-app heuristics, or mesh-divisions, " 680 "please consider using the greedy_search to confirm. Then consider choosing a different " 681 "transfer type.\nThis check can be turned off by setting 'error_on_miss' to false. The " 682 "'extrapolation_constant' parameter will be used to set the local value at missed points.");
688 const unsigned int problem_id,
691 std::set<processor_id_type> processors;
699 for (
const auto pid : processors)
702 unsigned int required_source_division = 0;
716 outgoing_points[pid].push_back(std::pair<Point, unsigned int>(point, required_source_division));
747 auto sys_num = to_sys->
number();
754 const auto & to_mesh = to_moose_mesh.getMesh();
757 if (fe_type.order >
CONSTANT && !is_nodal)
762 const std::vector<unsigned int> varvec(1, var_num);
768 request_gather(*to_sys, f, &g, nullsetter, varvec);
772 mooseError(
"Higher order discontinuous elemental variables are not supported for " 774 "restricted transfers");
779 mooseError(
"Higher order variable support not implemented for target mesh division " 780 "unless the mesh is fully covered / indexed in the mesh division. This must be " 781 "set programmatically in the MeshDivision object used.");
786 ? to_mesh.active_local_elements_begin()
787 : to_mesh.active_local_subdomain_set_elements_begin(
_to_blocks);
790 ? to_mesh.active_local_elements_end()
791 : to_mesh.active_local_subdomain_set_elements_end(
_to_blocks);
795 request_gather.
project(to_elem_range);
802 (*
_to_transforms[global_i_to])(p), point_id++, i_to, outgoing_points);
806 mooseError(
"We don't currently support variables with gradient degrees of freedom");
810 for (
const auto & node : to_mesh.local_node_ptr_range())
813 if (node->n_dofs(sys_num, var_num) < 1)
834 (*
_to_transforms[global_i_to])(*node), node->id(), i_to, outgoing_points);
839 for (
const auto & elem :
840 as_range(to_mesh.local_elements_begin(), to_mesh.local_elements_end()))
843 if (elem->n_dofs(sys_num, var_num) < 1)
875 unsigned int local_start = 0;
881 local_bboxes[i_from] =
_from_bboxes[local_start + i_from];
887 const unsigned int var_index,
888 std::vector<PointInfo> & pointInfoVec,
889 const std::vector<std::pair<Point, unsigned int>> & point_requests,
890 const std::vector<std::pair<Real, Real>> & incoming_vals,
895 mooseAssert(pointInfoVec.size() == incoming_vals.size(),
896 "Number of dof objects does not equal to the number of incoming values");
899 for (
const auto & pointinfo : pointInfoVec)
902 const auto problem_id = pointinfo.problem_id;
903 const auto dof_object_id = pointinfo.dof_object_id;
912 if (fe_type.order >
CONSTANT && !is_nodal)
915 InterpCache & value_cache = interp_caches[problem_id];
916 InterpCache & distance_cache = distance_caches[problem_id];
918 point_requests[val_offset].first);
919 const Number val = incoming_vals[val_offset].first;
922 if (!distance_cache.
hasKey(p))
931 registerConflict(problem_id, dof_object_id, p, incoming_vals[val_offset].second,
false);
941 value_cache[p] = val;
942 distance_cache[p] = incoming_vals[val_offset].second;
954 const DofObject * dof_object_ptr =
nullptr;
955 const auto sys_num = to_sys.number();
958 dof_object_ptr = to_mesh.
node_ptr(dof_object_id);
961 dof_object_ptr = to_mesh.
elem_ptr(dof_object_id);
966 mooseAssert(dof_object_ptr->
n_dofs(sys_num, var_num) == 1,
967 "Unexpectedly found " << dof_object_ptr->
n_dofs(sys_num, var_num)
968 <<
"dofs instead of 1");
971 auto & dofobject_to_val = dofobject_to_valsvec[problem_id];
974 auto values_ptr = dofobject_to_val.find(dof_object_id);
976 if (values_ptr == dofobject_to_val.end())
979 auto & val = dofobject_to_val[dof_object_id];
981 val.interp = incoming_vals[val_offset].first;
985 val.distance = incoming_vals[val_offset].second;
989 auto & val = values_ptr->second;
993 incoming_vals[val_offset].first,
995 incoming_vals[val_offset].second))
1001 "Registration of received equi-distant value conflict");
1002 registerConflict(problem_id, dof_object_id, p, incoming_vals[val_offset].second,
false);
1017 val.interp = incoming_vals[val_offset].first;
1019 val.distance = incoming_vals[val_offset].second;
1042 const unsigned int var_index,
1054 const auto potential_conflict = *conflict_it;
1055 bool overlap_found =
false;
1058 const unsigned int problem_id = std::get<0>(potential_conflict);
1059 const dof_id_type dof_object_id = std::get<1>(potential_conflict);
1060 const Point p = std::get<2>(potential_conflict);
1071 if (fe_type.order >
CONSTANT && !is_nodal)
1073 auto cached_distance = distance_caches[problem_id].find(p);
1074 if (cached_distance == distance_caches[problem_id].end())
1075 mooseError(
"Conflict point was not found in the map of all origin-target distances");
1078 overlap_found =
true;
1082 dofobject_to_valsvec[problem_id].find(dof_object_id)->second.distance,
distance))
1083 overlap_found =
true;
1095 const unsigned int var_index,
1110 std::vector<std::tuple<Point, Real>> potential_conflicts;
1118 const auto potential_conflict = *conflict_it;
1119 const unsigned int i_from = std::get<0>(potential_conflict);
1120 Point p = std::get<2>(potential_conflict);
1131 potential_conflicts.push_back(std::make_tuple(p,
distance));
1135 std::sort(potential_conflicts.begin(), potential_conflicts.end());
1136 potential_conflicts.erase(unique(potential_conflicts.begin(),
1137 potential_conflicts.end(),
1141 std::abs(std::get<1>(l) - std::get<1>(r)) < TOLERANCE;
1143 potential_conflicts.end());
1145 std::vector<std::tuple<Point, Real>> real_conflicts;
1146 real_conflicts.reserve(potential_conflicts.size());
1149 for (
auto conflict_it = potential_conflicts.begin(); conflict_it != potential_conflicts.end();
1153 auto potential_conflict = *conflict_it;
1154 const Point p = std::get<0>(potential_conflict);
1159 bool target_found =
false;
1160 bool conflict_real =
false;
1175 if (fe_type.order >
CONSTANT && !is_nodal)
1178 auto cached_distance = distance_caches[i_to].find(local_p);
1179 if (cached_distance != distance_caches[i_to].end())
1181 target_found =
true;
1185 conflict_real =
true;
1193 auto pl =
_to_problems[i_to]->mesh().getPointLocator();
1194 pl->enable_out_of_mesh_mode();
1197 auto node = pl->locate_node(local_p);
1200 dof_object_id = node->id();
1204 auto elem = (*pl)(local_p);
1206 dof_object_id = elem->id();
1208 pl->disable_out_of_mesh_mode();
1215 if (dofobject_to_valsvec[i_to].find(dof_object_id) == dofobject_to_valsvec[i_to].end())
1218 target_found =
true;
1222 dofobject_to_valsvec[i_to].find(dof_object_id)->second.distance,
distance))
1223 conflict_real =
true;
1227 if (target_found && conflict_real)
1228 real_conflicts.push_back(potential_conflict);
1241 const auto potential_conflict = *conflict_it;
1242 const unsigned int i_from = std::get<0>(potential_conflict);
1243 Point p = std::get<2>(potential_conflict);
1252 if (std::find_if(real_conflicts.begin(),
1253 real_conflicts.end(),
1258 }) == real_conflicts.end())
1267 const unsigned int var_index,
1280 unsigned int num_outputs = 0;
1281 std::string local_conflicts_string =
"";
1282 std::string potential_reasons =
1283 "Are some points in target mesh equidistant from the sources " 1284 "(nodes/centroids/apps/positions, depending on transfer) in origin mesh(es)?\n";
1286 potential_reasons +=
"Are multiple subapps overlapping?\n";
1289 const unsigned int problem_id = std::get<0>(conflict);
1290 Point p = std::get<2>(conflict);
1293 std::string origin_domain_message;
1302 origin_domain_message =
"In source child app " + std::to_string(app_id) +
" mesh,";
1312 origin_domain_message =
"In target app mesh,";
1315 origin_domain_message =
"In reference (post-coordinate collapse) mesh,";
1318 origin_domain_message =
"In source parent app mesh,";
1321 local_conflicts_string += origin_domain_message +
" point: (" + std::to_string(p(0)) +
1322 ", " + std::to_string(p(1)) +
", " + std::to_string(p(2)) +
1323 "), equi-distance: " + std::to_string(std::get<3>(conflict)) +
1326 local_conflicts_string +=
1327 "Maximum output of the search for value conflicts has been reached. Further conflicts " 1328 "will not be output.\nIncrease 'search_value_conflicts_max_log' to output more.";
1331 std::string source_str =
"unknown";
1335 source_str =
"user object '" + getParam<UserObjectName>(
"source_user_object") +
"'";
1338 ", multiple valid values from equidistant points were " 1339 "found in the origin mesh for source " +
1341 " target points.\n" + potential_reasons +
"Conflicts detected at :\n" +
1342 local_conflicts_string);
1348 unsigned int num_outputs = 0;
1349 std::string received_conflicts_string =
"";
1350 std::string potential_reasons =
1351 "Are some points in target mesh equidistant from the sources " 1352 "(nodes/centroids/apps/positions, depending on transfer) in origin mesh(es)?\n";
1354 potential_reasons +=
"Are multiple subapps overlapping?\n";
1358 const unsigned int problem_id = std::get<0>(conflict);
1359 const Point p = std::get<2>(conflict);
1362 std::string target_domain_message;
1366 target_domain_message =
"In target child app " + std::to_string(app_id) +
" mesh,";
1369 target_domain_message =
"In target parent app mesh,";
1372 received_conflicts_string += target_domain_message +
" point: (" + std::to_string(p(0)) +
1373 ", " + std::to_string(p(1)) +
", " + std::to_string(p(2)) +
1374 "), equi-distance: " + std::to_string(std::get<3>(conflict)) +
1377 received_conflicts_string +=
1378 "Maximum output of the search for value conflicts has been reached. Further conflicts " 1379 "will not be output.\nIncrease 'search_value_conflicts_max_log' to output more.";
1382 ", multiple valid values from equidistant points were " 1383 "received for target variable '" +
1385 " target points.\n" + potential_reasons +
"Conflicts detected at :\n" +
1386 received_conflicts_string);
1392 mooseInfo(
"Automated diagnosis did not detect floating point indetermination in transfer");
1395 "Automated diagnosis did not detect any floating point indetermination in " 1396 "the transfer. You may consider turning it off using `search_value_conflicts=false` " 1397 "to improve performance/scalability.");
1408 const unsigned int var_index,
1417 auto & dofobject_to_val = dofobject_to_valsvec[problem_id];
1429 auto sys_num = to_sys->
number();
1434 if (fe_type.order >
CONSTANT && !is_nodal)
1444 const std::vector<unsigned int> varvec(1, var_num);
1450 set_solution(*to_sys, f,
nullptr, setter, varvec);
1454 ? to_mesh.active_local_elements_begin()
1455 : to_mesh.active_local_subdomain_set_elements_begin(
_to_blocks);
1458 ? to_mesh.active_local_elements_end()
1459 : to_mesh.active_local_subdomain_set_elements_end(
_to_blocks);
1463 set_solution.
project(active_local_elem_range);
1467 for (
const auto & val_pair : dofobject_to_val)
1469 const auto dof_object_id = val_pair.first;
1473 dof_object = to_mesh.
node_ptr(dof_object_id);
1475 dof_object = to_mesh.
elem_ptr(dof_object_id);
1477 const auto dof = dof_object->
dof_number(sys_num, var_num, 0);
1478 const auto val = val_pair.second.interp;
1483 const auto target_location =
1487 const auto info_msg =
"\nThis check can be turned off by setting 'error_on_miss' to " 1488 "false. The 'extrapolation_constant' parameter will be used to set " 1489 "the local value at missed points.";
1494 " could be located. Node details:\n",
1495 _to_meshes[problem_id]->nodePtr(dof_object_id)->get_info(),
1502 " could be located. Element details:\n",
1503 _to_meshes[problem_id]->elemPtr(dof_object_id)->get_info(),
1531 const std::vector<BoundingBox> & local_bboxes,
1533 const unsigned int only_from_mesh_div,
1534 Real & distance)
const 1542 const auto transformed_pt =
_from_transforms[from_global_num]->mapBack(pt);
1560 Point nearest_position_source;
1571 mooseError(
"Rotation and scaling currently unsupported with nearest positions transfer.");
1574 const Real distance_to_position_nearest_source = (pt - nearest_position_source).
norm();
1575 const Real distance_to_nearest_position = (pt - nearest_position).
norm();
1582 distance_to_nearest_position))
1586 distance = distance_to_position_nearest_source;
1592 !
inMesh(pl, transformed_pt))
1603 const Elem * elem = (*pl)(point);
1604 return (elem !=
nullptr);
1609 const Elem * elem)
const 1617 const Elem * elem)
const 1625 const Node * node)
const 1627 const auto & node_blocks =
mesh.getNodeBlockIds(*node);
1628 std::set<SubdomainID> u;
1629 std::set_intersection(
blocks.begin(),
1631 node_blocks.begin(),
1633 std::inserter(u, u.begin()));
1640 const Point & point)
const 1643 return (elem !=
nullptr);
1649 const Node * node)
const 1652 std::vector<BoundaryID> vec_to_fill;
1654 std::set<BoundaryID> vec_to_fill_set(vec_to_fill.begin(), vec_to_fill.end());
1655 std::set<BoundaryID> u;
1656 std::set_intersection(boundaries.begin(),
1658 vec_to_fill_set.begin(),
1659 vec_to_fill_set.end(),
1660 std::inserter(u, u.begin()));
1667 const Elem * elem)
const 1671 std::vector<BoundaryID> vec_to_fill;
1672 std::vector<BoundaryID> vec_to_fill_temp;
1677 vec_to_fill.insert(vec_to_fill.end(), vec_to_fill_temp.begin(), vec_to_fill_temp.end());
1683 vec_to_fill.insert(vec_to_fill.end(), vec_to_fill_temp.begin(), vec_to_fill_temp.end());
1685 std::set<BoundaryID> vec_to_fill_set(vec_to_fill.begin(), vec_to_fill.end());
1688 std::set<BoundaryID> u;
1689 std::set_intersection(boundaries.begin(),
1691 vec_to_fill_set.begin(),
1692 vec_to_fill_set.end(),
1693 std::inserter(u, u.begin()));
1699 const std::set<SubdomainID> & block_restriction,
1702 const Point & point)
const 1706 if (block_restriction.empty())
1707 elem = (*pl)(point);
1709 elem = (*pl)(point, &block_restriction);
1718 const Point & pt,
const unsigned int i_local,
const unsigned int only_from_this_mesh_div)
const 1732 source_mesh_div != only_from_this_mesh_div)
1737 source_mesh_div != only_from_this_mesh_div)
1751 paramError(
"skip_coordinate_collapsing",
"Coordinate collapsing not implemented");
1762 Real distance_to_position_at_index = (pt - nearest_position_at_index).
norm();
1763 const Real distance_to_nearest_position = (pt - nearest_position).
norm();
1766 distance_to_nearest_position))
1769 else if (nearest_position == nearest_position_at_index)
1776 nearest_position_at_index,
1777 " detected near point ",
1787 std::array<Point, 2> source_points = {{bbox.first, bbox.second}};
1789 std::array<Point, 8> all_points;
1790 for (
unsigned int x = 0; x < 2; x++)
1791 for (
unsigned int y = 0; y < 2; y++)
1792 for (
unsigned int z = 0; z < 2; z++)
1793 all_points[x + 2 * y + 4 * z] =
1794 Point(source_points[x](0), source_points[y](1), source_points[z](2));
1796 Real max_distance = 0.;
1798 for (
unsigned int i = 0; i < 8; i++)
1805 return max_distance;
1811 std::array<Point, 2> source_points = {{bbox.first, bbox.second}};
1813 std::array<Point, 8> all_points;
1814 for (
unsigned int x = 0; x < 2; x++)
1815 for (
unsigned int y = 0; y < 2; y++)
1816 for (
unsigned int z = 0; z < 2; z++)
1817 all_points[x + 2 * y + 4 * z] =
1818 Point(source_points[x](0), source_points[y](1), source_points[z](2));
1822 for (
unsigned int i = 0; i < 8; i++)
1829 return min_distance;
1832 std::vector<BoundingBox>
1835 std::vector<std::pair<Point, Point>> bb_points(
_from_meshes.size());
1836 const Real min_r = std::numeric_limits<Real>::lowest();
1843 bool at_least_one =
false;
1846 for (
const auto & elem :
as_range(from_mesh.getMesh().local_elements_begin(),
1847 from_mesh.getMesh().local_elements_end()))
1857 at_least_one =
true;
1870 if ((from_mesh.getUniqueCoordSystem() ==
Moose::COORD_RZ) && (LIBMESH_DIM == 3))
1890 bb_points[j] =
static_cast<std::pair<Point, Point>
>(bbox);
1897 std::vector<BoundingBox> bboxes(bb_points.size());
1898 for (
const auto i :
make_range(bb_points.size()))
1899 bboxes[i] =
static_cast<BoundingBox>(bb_points[i]);
1906 for (
const auto j :
make_range(bboxes.size()))
1908 const auto current_width = (bboxes[j].second - bboxes[j].first)(i);
1916 std::vector<unsigned int>
1919 std::vector<unsigned int> global_app_start_per_proc(1, -1);
1923 return global_app_start_per_proc;
1929 mooseAssert(var_index <
_from_var_names.size(),
"No source variable at this index");
1939 mooseAssert(var_index <
_to_var_names.size(),
"No target variable at this index");
1955 const auto bbox = to_mesh->getInflatedProcessorBoundingBox();
1961 return max_dimension;
1967 Real current_distance,
1968 Real new_distance)
const
std::vector< BoundingBox > _from_bboxes
Bounding boxes for all source applications.
std::vector< std::unique_ptr< MultiAppCoordTransform > > _to_transforms
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
virtual void evaluateInterpValues(const std::vector< std::pair< Point, unsigned int >> &incoming_points, std::vector< std::pair< Real, Real >> &outgoing_vals)=0
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
void examineReceivedValueConflicts(const unsigned int var_index, const DofobjectToInterpValVec &dofobject_to_valsvec, const InterpCaches &distance_caches)
Remove potential value conflicts that did not materialize because another source was closer Several e...
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
const Point & getNearestPosition(const Point &target, bool initial) const
Find the nearest Position for a given point.
void cacheOutgoingPointInfo(const Point point, const dof_id_type dof_object_id, const unsigned int problem_id, ProcessorToPointVec &outgoing_points)
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
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.
bool _source_app_must_contain_point
Whether the source app mesh must actually contain the points for them to be considered or whether the...
const bool _skip_coordinate_collapsing
Whether to skip coordinate collapsing (transformations of coordinates between applications using diff...
void registerConflict(unsigned int problem, dof_id_type dof_id, Point p, Real dist, bool local)
Register a potential value conflict, e.g.
VariableName getFromVarName(unsigned int var_index)
Get the source variable name, with the suffix for array/vector variables.
void mooseInfo(Args &&... args) const
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
void locatePointReceivers(const Point point, std::set< processor_id_type > &processors)
std::vector< std::unique_ptr< libMesh::PointLocatorBase > > _from_point_locators
Point locators, useful to examine point location with regards to domain restriction.
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one...
const std::vector< VariableName > _from_var_names
Name of variables transferring from.
virtual void execute() override
Execute the transfer.
MultiAppGeneralFieldTransfer(const InputParameters ¶meters)
std::vector< FEProblemBase * > _to_problems
processor_id_type rank() const
Number BetterOutOfMeshValue
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
const Parallel::Communicator & comm() const
bool acceptPointMeshDivision(const Point &pt, const unsigned int i_local, const unsigned int only_from_this_mesh_div) const
Whether a point lies inside the mesh division delineated by the MeshDivision object.
virtual void postExecute()
Add some extra work if necessary after execute().
std::vector< unsigned int > getGlobalStartAppPerProc() const
Get global index for the first app each processes owns Requires a global communication, must be called on every domain simultaneously.
FEProblemBase & _fe_problem
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
static InputParameters validParams()
This class provides an interface for common operations on field variables of both FE and FV types wit...
const Point & getPosition(unsigned int index, bool initial) const
Getter for a single position at a known index.
const Parallel::Communicator & _communicator
std::vector< Real > _fixed_bbox_size
Set the bounding box sizes manually.
std::vector< const MeshDivision * > _from_mesh_divisions
Division of the origin mesh.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
std::vector< const MeshDivision * > _to_mesh_divisions
Division of the target mesh.
unsigned int _var_size
The number of variables to transfer.
std::vector< Point > & points_requested()
const BoundaryInfo & get_boundary_info() const
const Real _default_extrapolation_value
Value to use when no received data is valid for a target location.
bool inMesh(const libMesh::PointLocatorBase *const pl, const Point &pt) const
bool closestToPosition(unsigned int pos_index, const Point &pt) const
Whether a point is closest to a position at the index specified than any other position.
bool hasFromMultiApp() const
Whether the transfer owns a non-null from_multi_app.
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
const std::vector< unsigned int > _from_var_components
Origin array/vector variable components.
Real distance(const Point &p)
virtual const std::string & name() const
Get the name of the class.
virtual void getAppInfo() override
This method will fill information into the convenience member variables (_to_problems, _from_meshes, etc.)
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.
VariableName getToVarName(unsigned int var_index)
Get the target variable name, with the suffix for array/vector variables.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
std::set< BoundaryID > _from_boundaries
Origin boundary(ies) restriction.
void outputValueConflicts(const unsigned int var_index, const DofobjectToInterpValVec &dofobject_to_valsvec, const InterpCaches &distance_caches)
Report on conflicts between overlapping child apps, equidistant origin points etc.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
auto max(const L &left, const R &right)
std::vector< unsigned int > _to_local2global_map
Given local app index, returns global app index.
const Positions * _nearest_positions_obj
unsigned int variable_number(std::string_view var) const
Real bboxMinDistance(const Point &p, const BoundingBox &bbox) const
Compute minimum distance.
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.
void extractOutgoingPoints(const unsigned int var_index, ProcessorToPointVec &outgoing_points)
std::set< SubdomainID > _to_blocks
Target block(s) restriction.
unsigned int n_dofs(const unsigned int s, const unsigned int var=libMesh::invalid_uint) const
processor_id_type size() const
std::unordered_map< processor_id_type, std::vector< std::pair< Point, unsigned int > > > ProcessorToPointVec
A map from pid to a set of points.
Point getMaxToProblemsBBoxDimensions() const
Obtains the max dimensions to scale all points in the mesh.
virtual void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup...
uint8_t processor_id_type
dof_id_type dof_object_id
virtual void prepareEvaluationOfInterpValues(const unsigned int var_index)=0
const std::vector< unsigned int > _to_var_components
Target array/vector variable components.
processor_id_type n_processors() const
Real bboxMaxDistance(const Point &p, const BoundingBox &bbox) const
Compute max distance.
unsigned int getNearestPositionIndex(const Point &target, bool initial) const
Find the nearest Position index for a given point.
unsigned int number() const
libMesh::EquationSystems & getEquationSystem(FEProblemBase &problem, bool use_displaced) const
Returns the Problem's equation system, displaced or not Be careful! If you transfer TO a displaced sy...
bool isBetterOutOfMeshValue(Number val)
std::vector< MooseMesh * > _from_meshes
std::vector< std::tuple< unsigned int, dof_id_type, Point, Real > > _local_conflicts
Keeps track of all local equidistant points to requested points, creating an indetermination in which...
const bool _use_bounding_boxes
Whether to use bounding boxes to determine the applications that may receive point requests then send...
Value request recording base class.
bool acceptPointInOriginMesh(unsigned int i_from, const std::vector< BoundingBox > &local_bboxes, const Point &pt, const unsigned int mesh_div, Real &distance) const
void project(const ConstElemRange &range)
virtual unsigned int n_nodes() const=0
std::set< BoundaryID > _to_boundaries
Target boundary(ies) restriction.
std::vector< unsigned int > _froms_per_proc
Number of source/from applications per processor. This vector is indexed by processor id...
std::vector< std::tuple< unsigned int, dof_id_type, Point, Real > > _received_conflicts
Keeps track of all received conflicts.
const Point & min() const
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
std::vector< std::unordered_map< dof_id_type, InterpInfo > > DofobjectToInterpValVec
A vector, indexed by to-problem id, of maps from dof object to interpolation values.
Real _bbox_factor
How much we should relax bounding boxes.
bool _error_on_miss
Error out when some points can not be located.
const std::vector< AuxVariableName > _to_var_names
Name of variables transferring to.
static libMesh::System * find_sys(libMesh::EquationSystems &es, const std::string &var_name)
Small helper function for finding the system containing the variable.
std::unique_ptr< NumericVector< Number > > solution
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
std::vector< unsigned int > getFromsPerProc()
Return the number of "from" domains that each processor owns.
virtual void init() override
Transfers variables on possibly different meshes while conserving a user defined property (Postproces...
bool _search_value_conflicts
Whether to look for conflicts between origin points, multiple valid values for a target point...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
unsigned int getGlobalSourceAppIndex(unsigned int i_from) const
Return the global app index from the local index in the "from-multiapp" transfer direction.
MooseApp & _app
The MOOSE application this is associated with.
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 ...
An unordered map indexed by Point, eg 3 floating point numbers Because floating point rounding errors...
void transferVariable(unsigned int i)
Performs the transfer for the variable of index i.
std::string stringify(const T &t)
conversion to string
unsigned int INVALID_DIVISION_INDEX
Invalid subdomain id to return when outside the mesh division.
void examineLocalValueConflicts(const unsigned int var_index, const DofobjectToInterpValVec &dofobject_to_valsvec, const InterpCaches &distance_caches)
Remove potential value conflicts that did not materialize because another source was closer Several e...
bool detectConflict(Real value_1, Real value_2, Real distance_1, Real distance_2) const
Detects whether two source values are valid and equidistant for a desired target location.
std::vector< BoundingBox > getRestrictedFromBoundingBoxes() const
Get from bounding boxes for given domains and boundaries.
SimpleRange< NodeRefIter > node_ref_range()
virtual const Elem * elem_ptr(const dof_id_type i) const=0
virtual unsigned int n_sides() const=0
bool isParamSetByUser(const std::string &nm) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
virtual void addReporter(const std::string &type, const std::string &name, InputParameters ¶meters)
Add a Reporter object to the simulation.
bool absolute_fuzzy_equals(const T &var1, const T2 &var2, const Real tol=TOLERANCE *TOLERANCE)
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
subdomain_id_type subdomain_id() const
bool _already_output_search_value_conflicts
Whether we already output the search value conflicts.
const MooseEnum & _to_mesh_division_behavior
How to use the target mesh divisions to restrict the transfer.
virtual void postExecute() override
Add some extra work if necessary after execute().
const Node * node_ptr(const unsigned int i) const
std::vector< std::unique_ptr< MultiAppCoordTransform > > _from_transforms
IntRange< T > make_range(T beg, T end)
bool hasToMultiApp() const
Whether the transfer owns a non-null to_multi_app.
Value request response base class.
bool _displaced_source_mesh
True if displaced mesh is used for the source mesh, otherwise false.
std::set< SubdomainID > _from_blocks
Origin block(s) restriction.
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.
const unsigned int _search_value_conflicts_max_log
How many conflicts are output to console.
std::vector< InterpCache > InterpCaches
A vector of such caches, indexed by to_problem.
static InputParameters validParams()
std::unique_ptr< NumericVector< Number > > current_local_solution
void extractLocalFromBoundingBoxes(std::vector< BoundingBox > &local_bboxes)
const InputParameters & parameters() const
Get the parameters of the object.
void extendBoundingBoxes(const Real factor, std::vector< libMesh::BoundingBox > &bboxes) const
Extends bounding boxes to avoid missing points.
std::vector< MooseVariableFieldBase * > _to_variables
The target variables.
ProcessorToPointInfoVec _processor_to_pointInfoVec
A map from processor to pointInfo vector.
const bool _elemental_boundary_restriction_on_sides
Whether elemental variable boundary restriction is considered by element side or element nodes...
virtual void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup...
void prepareToTransfer()
Initialize supporting attributes like bounding boxes, processor app indexes etc.
virtual const Node * node_ptr(const dof_id_type i) const=0
processor_id_type processor_id() const
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)
const DofMap & get_dof_map() const
void setSolutionVectorValues(const unsigned int var_index, const DofobjectToInterpValVec &dofobject_to_valsvec, const InterpCaches &interp_caches)
unsigned int hasKey(Point p)
bool onBoundaries(const std::set< BoundaryID > &boundaries, const MooseMesh &mesh, const Node *node) const
std::vector< FEProblemBase * > _from_problems
void ErrorVector unsigned int
auto index_range(const T &sizable)
bool absoluteFuzzyGreaterThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within an absolute tolerance...
std::vector< MooseMesh * > _to_meshes
bool _greedy_search
Whether or not a greedy strategy will be used If true, all the partitions will be checked for a given...
void cacheIncomingInterpVals(processor_id_type pid, const unsigned int var_index, std::vector< PointInfo > &pointInfoVec, const std::vector< std::pair< Point, unsigned int >> &point_requests, const std::vector< std::pair< Real, Real >> &incoming_vals, DofobjectToInterpValVec &dofobject_to_valsvec, InterpCaches &interp_caches, InterpCaches &distance_caches)
std::vector< unsigned int > _global_app_start_per_proc
First app each processor owns, indexed by processor If no app on the processor, will have a -1 for th...
const MooseEnum & _from_mesh_division_behavior
How to use the origin mesh divisions to restrict the transfer.
bool inBlocks(const std::set< SubdomainID > &blocks, const Elem *elem) const
const bool _use_nearest_app
Whether to keep track of the distance from the requested point to the app position.
const ExecFlagType EXEC_INITIAL