https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MultiAppGeneralFieldUserObjectTransfer.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
11
12// MOOSE includes
13#include "DisplacedProblem.h"
14#include "FEProblem.h"
15#include "MooseMesh.h"
16#include "MooseTypes.h"
17#include "MooseVariableFE.h"
18#include "UserObject.h"
19#include "Positions.h"
20
21#include "libmesh/system.h"
22#include "libmesh/mesh_function.h"
23
25
28{
31 "Transfers user object spatial evaluations from an origin app onto a variable in the target "
32 "application.");
33
34 params.set<std::vector<VariableName>>("source_variable") = std::vector<VariableName>{};
35 params.suppressParameter<std::vector<VariableName>>("source_variable");
36 params.addRequiredParam<UserObjectName>("source_user_object",
37 "The UserObject you want to transfer values from. "
38 "It must implement the SpatialValue() class routine");
39
41
42 // Blanket ban on origin boundary restriction. User objects tend to extend beyond boundaries,
43 // and be able to be evaluated within a volume rather than only on a boundary
44 // This could be re-enabled for spatial user objects that are only defined on boundaries
45 params.suppressParameter<std::vector<BoundaryName>>("from_boundaries");
46 return params;
47}
48
50 const InputParameters & parameters)
51 : MultiAppGeneralFieldTransfer(parameters),
52 _user_object_name(getParam<UserObjectName>("source_user_object"))
53{
54 if (_to_var_names.size() > 1)
55 paramError("variable", "Only one variable at a time is supported by this transfer");
56
57 // Block restriction does not make sense if we're ok with extrapolating
58 if (isParamValid("from_blocks") && !_source_app_must_contain_point &&
59 !parameters.isParamSetByUser("extrapolation_constant"))
60 paramError("from_app_must_contain_point",
61 "Source block restriction cannot be used at the same type as allowing extrapolation"
62 " of values for a user object transfer (with 'from_app_must_contain_point=false') "
63 " unless an extrapolation constant is provided (with 'extrapolation_constant')");
64
65 // Nearest point isn't well defined for sending app-based data from main app to a multiapp
66 if (_nearest_positions_obj && isParamValid("to_multi_app") && !isParamValid("from_multi_app"))
67 paramError("use_nearest_position",
68 "Cannot use nearest-position algorithm when sending from the main application");
69}
70
71void
91
92void
100
101void
103 const unsigned int /*var_index*/,
104 const std::vector<std::pair<Point, unsigned int>> & incoming_points,
105 std::vector<std::pair<Real, Real>> & outgoing_vals)
106{
107 evaluateInterpValuesWithUserObjects(_local_bboxes, incoming_points, outgoing_vals);
108}
109
110void
112 const std::vector<BoundingBox> & local_bboxes,
113 const std::vector<std::pair<Point, unsigned int>> & incoming_points,
114 std::vector<std::pair<Real, Real>> & outgoing_vals)
115{
116 dof_id_type i_pt = 0;
117 for (auto & [pt, mesh_div] : incoming_points)
118 {
119 bool point_found = false;
120 outgoing_vals[i_pt].second = GeneralFieldTransfer::OutOfMeshValue;
121
122 // Loop on all local origin problems until:
123 // - we've found the point in an app and the value at that point is valid
124 // - or if looking for conflicts between apps, we must check them all
125 for (MooseIndex(_from_problems.size()) i_from = 0;
126 i_from < _from_problems.size() &&
128 ++i_from)
129 {
130 // User object spatialValue() evaluations do not provide a distance
131 Real distance = 1;
132 // Check spatial restrictions
133 if (!acceptPointInOriginMesh(i_from, local_bboxes, pt, mesh_div, distance))
134 continue;
135 else
136 {
137 // Get user object from the local problem
138 const UserObject & user_object =
140
141 // Use spatial value routine to compute the origin value to transfer
142 const auto local_pt =
143 getPointInSourceAppFrame(pt, i_from, "User object spatial value evaluation");
144 auto val = user_object.spatialValue(local_pt);
145
146 // Look for overlaps. The check is not active outside of overlap search because in that
147 // case we accept the first value from the lowest ranked process
148 // NOTE: There is no guarantee this will be the final value used among all problems
149 // but we register an overlap as soon as two values are possible from this rank
150 if (detectConflict(val, outgoing_vals[i_pt].first, distance, outgoing_vals[i_pt].second))
151 {
153 registerConflict(i_from, 0, pt, distance, true);
154 else
155 registerConflict(i_from, 0, local_pt, distance, true);
156 }
157
158 // No need to consider decision factors if value is invalid
160 continue;
161 else
162 point_found = true;
163
164 // Assign value
165 if (distance < outgoing_vals[i_pt].second)
166 {
167 outgoing_vals[i_pt].first = val;
168 outgoing_vals[i_pt].second = distance;
169 }
170 }
171 }
172
173 if (!point_found)
174 outgoing_vals[i_pt] = {GeneralFieldTransfer::OutOfMeshValue,
176
177 // Move to next point
178 i_pt++;
179 }
180}
181
182std::string
184{
185 return "user object '" + _user_object_name + "'";
186}
const ExecFlagType EXEC_TRANSFER
Definition Moose.C:57
registerMooseObject("MooseApp", MultiAppGeneralFieldUserObjectTransfer)
virtual void computeUserObjectByName(const ExecFlagType &type, const Moose::AuxGroup &group, const std::string &name)
Compute an user object with the given name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
const std::vector< AuxVariableName > _to_var_names
Name of variables transferring to.
It is a general field transfer.
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.
bool _source_app_must_contain_point
Whether the source app mesh must actually contain the points for them to be considered or whether the...
void registerConflict(unsigned int problem, dof_id_type dof_id, Point p, Real dist, bool local)
Register a potential value conflict, e.g.
virtual void execute() override
Execute the transfer.
bool acceptPointInOriginMesh(unsigned int i_from, const std::vector< BoundingBox > &local_bboxes, const Point &pt, const unsigned int mesh_div, Real &distance) const
const bool _use_bounding_boxes
Whether to use bounding boxes to determine the applications that may receive point requests then send...
void extractLocalFromBoundingBoxes(std::vector< BoundingBox > &local_bboxes)
bool _search_value_conflicts
Whether to look for conflicts between origin points, multiple valid values for a target point.
Transfers values computed in the origin mesh by the source user object spatialValue() routine at loca...
virtual void execute() override
Execute the transfer.
const std::string _user_object_name
Name of the source user object in all the source problems.
MultiAppGeneralFieldUserObjectTransfer(const InputParameters &parameters)
void evaluateInterpValuesWithUserObjects(const std::vector< BoundingBox > &local_bboxes, const std::vector< std::pair< Point, unsigned int > > &incoming_points, std::vector< std::pair< Real, Real > > &outgoing_vals)
virtual std::string getDataSourceName(unsigned int var_index) const override
Return a human-readable description of the data source (variable, functor, user object,...
virtual void evaluateInterpValues(const unsigned int, const std::vector< std::pair< Point, unsigned int > > &incoming_points, std::vector< std::pair< Real, Real > > &outgoing_vals) override
virtual void prepareEvaluationOfInterpValues(const unsigned int) override
void errorIfObjectExecutesOnTransferInSourceApp(const std::string &object_name) const
Error if executing this MooseObject on EXEC_TRANSFER in a source multiapp (from_multiapp,...
std::vector< FEProblemBase * > _from_problems
static void addUserObjectExecutionCheckParam(InputParameters &params)
Add the execution order check parameter (to skip the warning if needed)
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...
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.
@ FROM_MULTIAPP
Definition Transfer.h:71
@ TO_MULTIAPP
Definition Transfer.h:70
FEProblemBase & _fe_problem
Definition Transfer.h:97
MooseEnum _current_direction
Definition Transfer.h:106
const UserObjectBase & getUserObjectBase(const std::string &param_name, bool is_dependency=true) const
Get an user object with a given parameter param_name.
Base class for user-specific data.
Definition UserObject.h:20
virtual Real spatialValue(const Point &) const
Optional interface function for "evaluating" a UserObject at a spatial position.
Definition UserObject.h:36
@ POST_AUX
Definition MooseTypes.h:761
@ PRE_AUX
Definition MooseTypes.h:760
Real distance(const Point &p)