22#include "libmesh/meshfree_interpolation.h"
23#include "libmesh/system.h"
36 "Samples the value of a variable within the main application at each sub-application "
37 "position and transfers the value to a postprocessor on the sub-application(s) when "
38 "performing the to-multiapp transfer. Reconstructs the value of a CONSTANT MONOMIAL "
39 "variable associating the value of each element to the value of the postprocessor "
40 "in the closest sub-application whem performing the from-multiapp transfer.");
43 "The name of the postprocessor in the MultiApp to transfer the value to. "
44 "This should most likely be a Reciever Postprocessor.");
45 params.
addRequiredParam<VariableName>(
"source_variable",
"The variable to transfer from.");
47 "source_variable_component",
49 "The component of source variable, may be non-zero for array variables.");
51 "map_array_variable_components_to_child_apps",
53 "When true, groups of sub-applications will be associated with different components of the "
54 "supplied array variable in 'source_variable'. For instance, if there are 9 sub-applications "
55 "and 3 components in the variable, sub-apps 0-2 will go to component 0, 3-5 will go to 1, "
56 "and 6-8 will go to 2.");
64 _postprocessor_name(getParam<PostprocessorName>(
"postprocessor")),
65 _var_name(getParam<VariableName>(
"source_variable")),
66 _comp(getParam<unsigned
int>(
"source_variable_component")),
67 _var(_fe_problem.getVariable(0, _var_name)),
68 _map_comp_to_child(getParam<bool>(
"map_array_variable_components_to_child_apps"))
71 paramError(
"direction",
"This transfer is only unidirectional");
79 "Variable must be in CONSTANT MONOMIAL when transferring from a postprocessor "
83 paramError(
"source_variable",
"Variable must be an auxiliary variable");
86 mooseError(
"MultiAppVariableValueSamplePostprocessorTransfer has not been made to support "
90 paramError(
"map_array_variable_components_to_child_apps",
91 "'source_variable' must be an array variable when mapping array variable components "
92 "to child applications.");
94 paramError(
"map_array_variable_components_to_child_apps",
95 "'source_variable_component' is invalid when mapping array variable components to "
96 "child applications.");
109 std::numeric_limits<processor_id_type>::max());
110 for (
const auto i :
make_range(num_global_apps))
116 for (
const auto i :
make_range(num_global_apps))
119 "Every element in the vector should have been set.");
122 "If I owned this app, then the processor id value should be my own");
135 unsigned int multiapp_pos_id = 0;
136 for (
auto & elem :
as_range(
mesh.active_local_elements_begin(),
mesh.active_local_elements_end()))
146 unsigned int count = 0;
151 if (MooseUtils::absoluteFuzzyLessThan(current_distance,
distance))
157 else if (MooseUtils::absoluteFuzzyEqual(current_distance,
distance))
162 "The distances of an element to more than one sub-applications are too close "
165 "'. The code chooses the sub-application with the smallest ID to set "
166 "the variable on the element, which may created undesired variable solutions."
167 "\nHaving different positions for sub-applications, "
168 "a centroid-based MultiApp or adding block restriction to the variable can "
169 "be used to resolve this warning.");
188 paramError(
"map_array_variable_components_to_child_apps",
189 "The number of sub-applications (",
191 ") is not divisible by the number of components in '",
211 TIME_SECTION(
"MultiAppVariableValueSamplePostprocessorTransfer::execute()",
213 "Transferring a variable to a postprocessor through sampling");
226 mooseError(
"MultiAppVariableValueSamplePostprocessorTransfer does not support transfer of "
238 pl->enable_out_of_mesh_mode();
240 for (
unsigned int i = 0; i <
getToMultiApp()->numGlobalApps(); i++)
242 Real value = -std::numeric_limits<Real>::max();
248 std::vector<Point> point_vec(1, multi_app_position);
251 const Elem * elem = (*pl)(multi_app_position);
263 "Component must be smaller than the number of components of array variable!");
264 mooseAssert(array_var->
sln().size() == 1,
"No values in u!");
268 value = standard_var->
sln()[0];
269 mooseAssert(standard_var->
sln().
size() == 1,
"No values in u!");
292 std::vector<Real> pp_values(n_subapps, std::numeric_limits<Real>::max());
298 std::unordered_map<processor_id_type, std::vector<unsigned int>> postprocessor_queries;
303 postprocessor_queries[proc_id].push_back(needed_postprocessor);
306 auto gather_data = [&pp_values
312 const std::vector<unsigned int> & postprocessor_ids,
313 std::vector<Real> & postprocessor_values)
315 mooseAssert(pid != this->
processor_id(),
"Should not be pulling from self");
316 postprocessor_values.resize(postprocessor_ids.size());
317 for (
const auto i :
index_range(postprocessor_ids))
319 const auto pp_id = postprocessor_ids[i];
320 const auto pp_value = pp_values[pp_id];
322 pp_value != std::numeric_limits<Real>::max(),
323 "If we are getting queried for postprocessor data, then we better have a valid"
324 "postprocesor value.");
325 postprocessor_values[i] = pp_value;
329 auto act_on_data = [&pp_values
335 const std::vector<unsigned int> & postprocessor_ids,
336 const std::vector<Real> & postprocessor_values)
338 mooseAssert(pid != this->
processor_id(),
"Should not be returning a query from self");
339 mooseAssert(postprocessor_ids.size() == postprocessor_values.size(),
340 "should be a 1-to-1 query-to-response");
341 for (
const auto i :
index_range(postprocessor_ids))
343 const auto pp_id = postprocessor_ids[i];
344 const auto pp_value = postprocessor_values[i];
345 mooseAssert(pp_value != std::numeric_limits<Real>::max(),
346 "If we are returning postprocessor data, then we better have a valid"
347 "postprocesor value.");
348 pp_values[pp_id] = pp_value;
352 constexpr Real example = 0;
354 _communicator, postprocessor_queries, gather_data, act_on_data, &example);
359 as_range(
mesh.active_local_elements_begin(),
mesh.active_local_elements_end()))
364 std::vector<dof_id_type> dof_indices;
366 mooseAssert(dof_indices.size() ==
_var.
count(),
367 "The variable must be a constant monomial with one DoF on an element per "
370 "We should have pulled all the data we needed.");
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
registerMooseObject("MooseApp", MultiAppVariableValueSamplePostprocessorTransfer)
void ErrorVector unsigned int
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, const THREAD_ID tid) override
virtual ArrayMooseVariable & getArrayVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested ArrayMooseVariable which may be in any system.
AuxiliarySystem & getAuxiliarySystem()
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
virtual MooseMesh & mesh() override
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
Interface for notifications that the mesh has changed.
unsigned int size() const
The number of elements that can currently be stored in the array.
const InputParameters & parameters() const
Get the parameters of the object.
const std::string & name() const
Get the name of the class.
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 ...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
virtual std::unique_ptr< libMesh::PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default),...
const libMesh::FEType & feType() const
Get the type of finite element object.
virtual bool isArray() const
SystemBase & sys()
Get the system this variable is part of.
virtual void getDofIndices(const Elem *, std::vector< dof_id_type > &) const
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one.
const FieldVariableValue & sln() const override
element solutions
virtual bool isVector() const =0
Class for stuff related to variables.
virtual const FieldVariableValue & sln() const =0
Base class for all MultiAppTransfer objects.
void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup.
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
static InputParameters validParams()
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
Samples a variable's value in the parent application domain at the point where the MultiApp (for each...
std::vector< processor_id_type > _postprocessor_to_processor_id
Entries in this vector correspond to the processor ID that owns the application/postprocessor corresp...
const bool _map_comp_to_child
Whether or not to map groups of child applications to each component of an array variable.
MultiAppVariableValueSamplePostprocessorTransfer(const InputParameters ¶meters)
virtual void execute() override
Execute the transfer.
unsigned int getVariableComponent(unsigned int index) const
Maps the child application index to the parent application variable component.
void setupPostprocessorCommunication()
Sets up the postprocessor to processor ID communication pattern data member _postprocessor_to_process...
virtual void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup.
void meshChanged() override
Called on this object when the mesh changes.
AuxVariableName _var_name
the name of the variable on the main-application
static InputParameters validParams()
PostprocessorName _postprocessor_name
the name of the postprocessor on the sub-applications
void cacheElemToPostprocessorData()
Method that caches data regarding the element to postprocess relationship.
std::vector< unsigned int > _cached_multiapp_pos_ids
Sub-application ids of all local active elements in the main-application When _map_comp_to_child == t...
MooseVariableFieldBase & _var
the moose variable
unsigned int _apps_per_component
The number of applications associated with a component of the variable when doing array variable samp...
std::unordered_set< unsigned int > _needed_postprocessors
The postprocessors that this process needs for its active local elements.
bool isValueSet(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
const std::set< TagID > & getActiveFEVariableCoupleableVectorTags(const THREAD_ID tid) const
virtual bool hasVariable(const std::string &var_name) const
Query a system for a variable.
NumericVector< Number > & solution()
void max(const T &r, T &o, Request &req) const
void min(const T &r, T &o, Request &req) const
MultiMooseEnum _directions
The directions this Transfer is to be executed on.
FEProblemBase & _fe_problem
MooseEnum _current_direction
processor_id_type processor_id() const
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
const TagName SOLUTION_TAG
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
auto index_range(const T &sizable)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
IntRange< T > make_range(T beg, T end)
Real distance(const Point &p)