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.");
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;
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++)
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!");
269 mooseAssert(standard_var->
sln().
size() == 1,
"No values in u!");
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];
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];
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() == 1,
367 "The variable must be a constant monomial with one DoF on an element");
369 "We should have pulled all the data we needed.");
virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
const libMesh::FEType & feType() const
Get the type of finite element object.
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.
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
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 ...
void meshChanged() override
Called on this object when the mesh changes.
NumericVector< Number > & solution()
MooseEnum _current_direction
registerMooseObject("MooseApp", MultiAppVariableValueSamplePostprocessorTransfer)
const std::set< TagID > & getActiveFEVariableCoupleableVectorTags(const THREAD_ID tid) const
const InputParameters & parameters() const
Get the parameters of the object.
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one...
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
virtual void getDofIndices(const Elem *, std::vector< dof_id_type > &) const
FEProblemBase & _fe_problem
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
const Parallel::Communicator & _communicator
MultiAppVariableValueSamplePostprocessorTransfer(const InputParameters ¶meters)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
virtual void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup...
Real distance(const Point &p)
auto max(const L &left, const R &right)
std::vector< processor_id_type > _postprocessor_to_processor_id
Entries in this vector correspond to the processor ID that owns the application/postprocessor corresp...
Samples a variable's value in the parent application domain at the point where the MultiApp (for each...
const bool _map_comp_to_child
Whether or not to map groups of child applications to each component of an array variable.
uint8_t processor_id_type
virtual bool isVector() const =0
const std::string & name() const
Get the name of the class.
unsigned int size() const
The number of elements that can currently be stored in the array.
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...
Interface for notifications that the mesh has changed.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
void min(const T &r, T &o, Request &req) const
void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup...
const FieldVariableValue & sln() const override
element solutions
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
std::unordered_set< unsigned int > _needed_postprocessors
The postprocessors that this process needs for its active local elements.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
virtual bool isArray() const
bool absoluteFuzzyLessThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within an absolute tolerance...
virtual void execute() override
Execute the transfer.
MooseVariableFieldBase & _var
the moose variable
PostprocessorName _postprocessor_name
the name of the postprocessor on the sub-applications
AuxVariableName _var_name
the name of the variable on the main-application
void setupPostprocessorCommunication()
Sets up the postprocessor to processor ID communication pattern data member _postprocessor_to_process...
bool isValueSet(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
unsigned int getVariableComponent(unsigned int index) const
Maps the child application index to the parent application variable component.
AuxiliarySystem & getAuxiliarySystem()
static InputParameters validParams()
virtual bool hasVariable(const std::string &var_name) const
Query a system for a variable.
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
void cacheElemToPostprocessorData()
Method that caches data regarding the element to postprocess relationship.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
virtual const FieldVariableValue & sln() const =0
MultiMooseEnum _directions
The directions this Transfer is to be executed on.
void max(const T &r, T &o, Request &req) const
Base class for all MultiAppTransfer objects.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
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...
const TagName SOLUTION_TAG
virtual std::unique_ptr< libMesh::PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default)...
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...
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
processor_id_type processor_id() const
unsigned int _apps_per_component
The number of applications associated with a component of the variable when doing array variable samp...
SystemBase & sys()
Get the system this variable is part of.
processor_id_type processor_id() const
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, const THREAD_ID tid) override
void ErrorVector unsigned int
auto index_range(const T &sizable)