22 #include "libmesh/meshfree_interpolation.h" 23 #include "libmesh/system.h" 34 "Samples the value of a variable within the main application at each sub-application " 35 "position and transfers the value to a postprocessor on the sub-application(s) when " 36 "performing the to-multiapp transfer. Reconstructs the value of a CONSTANT MONOMIAL " 37 "variable associating the value of each element to the value of the postprocessor " 38 "in the closest sub-application whem performing the from-multiapp transfer.");
41 "The name of the postprocessor in the MultiApp to transfer the value to. " 42 "This should most likely be a Reciever Postprocessor.");
43 params.
addRequiredParam<VariableName>(
"source_variable",
"The variable to transfer from.");
45 "source_variable_component",
47 "The component of source variable, may be non-zero for array variables.");
49 "map_array_variable_components_to_child_apps",
51 "When true, groups of sub-applications will be associated with different components of the " 52 "supplied array variable in 'source_variable'. For instance, if there are 9 sub-applications " 53 "and 3 components in the variable, sub-apps 0-2 will go to component 0, 3-5 will go to 1, " 54 "and 6-8 will go to 2.");
62 _postprocessor_name(getParam<PostprocessorName>(
"postprocessor")),
63 _var_name(getParam<VariableName>(
"source_variable")),
64 _comp(getParam<unsigned
int>(
"source_variable_component")),
65 _var(_fe_problem.getVariable(0, _var_name)),
66 _map_comp_to_child(getParam<bool>(
"map_array_variable_components_to_child_apps"))
69 paramError(
"direction",
"This transfer is only unidirectional");
77 "Variable must be in CONSTANT MONOMIAL when transferring from a postprocessor " 81 paramError(
"source_variable",
"Variable must be an auxiliary variable");
84 mooseError(
"MultiAppVariableValueSamplePostprocessorTransfer has not been made to support " 88 paramError(
"map_array_variable_components_to_child_apps",
89 "'source_variable' must be an array variable when mapping array variable components " 90 "to child applications.");
92 paramError(
"map_array_variable_components_to_child_apps",
93 "'source_variable_component' is invalid when mapping array variable components to " 94 "child applications.");
108 for (
const auto i :
make_range(num_global_apps))
114 for (
const auto i :
make_range(num_global_apps))
117 "Every element in the vector should have been set.");
120 "If I owned this app, then the processor id value should be my own");
133 unsigned int multiapp_pos_id = 0;
134 for (
auto & elem :
as_range(
mesh.active_local_elements_begin(),
mesh.active_local_elements_end()))
144 unsigned int count = 0;
160 "The distances of an element to more than one sub-applications are too close " 163 "'. The code chooses the sub-application with the smallest ID to set " 164 "the variable on the element, which may created undesired variable solutions." 165 "\nHaving different positions for sub-applications, " 166 "a centroid-based MultiApp or adding block restriction to the variable can " 167 "be used to resolve this warning.");
185 paramError(
"map_array_variable_components_to_child_apps",
186 "The number of sub-applications (",
188 ") is not divisible by the number of components in '",
208 TIME_SECTION(
"MultiAppVariableValueSamplePostprocessorTransfer::execute()",
210 "Transferring a variable to a postprocessor through sampling");
223 mooseError(
"MultiAppVariableValueSamplePostprocessorTransfer does not support transfer of " 235 pl->enable_out_of_mesh_mode();
237 for (
unsigned int i = 0; i <
getToMultiApp()->numGlobalApps(); i++)
245 std::vector<Point> point_vec(1, multi_app_position);
248 const Elem * elem = (*pl)(multi_app_position);
250 if (elem && elem->processor_id() == from_mesh.
processor_id())
260 "Component must be smaller than the number of components of array variable!");
261 mooseAssert(array_var->
sln().
size() == 1,
"No values in u!");
266 mooseAssert(standard_var->
sln().
size() == 1,
"No values in u!");
295 std::unordered_map<processor_id_type, std::vector<unsigned int>> postprocessor_queries;
300 postprocessor_queries[proc_id].push_back(needed_postprocessor);
303 auto gather_data = [&pp_values
309 const std::vector<unsigned int> & postprocessor_ids,
310 std::vector<Real> & postprocessor_values)
312 mooseAssert(pid != this->
processor_id(),
"Should not be pulling from self");
313 postprocessor_values.resize(postprocessor_ids.size());
314 for (
const auto i :
index_range(postprocessor_ids))
316 const auto pp_id = postprocessor_ids[i];
317 const auto pp_value = pp_values[pp_id];
320 "If we are getting queried for postprocessor data, then we better have a valid" 321 "postprocesor value.");
322 postprocessor_values[i] = pp_value;
326 auto act_on_data = [&pp_values
332 const std::vector<unsigned int> & postprocessor_ids,
333 const std::vector<Real> & postprocessor_values)
335 mooseAssert(pid != this->
processor_id(),
"Should not be returning a query from self");
336 mooseAssert(postprocessor_ids.size() == postprocessor_values.size(),
337 "should be a 1-to-1 query-to-response");
338 for (
const auto i :
index_range(postprocessor_ids))
340 const auto pp_id = postprocessor_ids[i];
341 const auto pp_value = postprocessor_values[i];
343 "If we are returning postprocessor data, then we better have a valid" 344 "postprocesor value.");
345 pp_values[pp_id] = pp_value;
349 constexpr
Real example = 0;
351 _communicator, postprocessor_queries, gather_data, act_on_data, &example);
356 as_range(
mesh.active_local_elements_begin(),
mesh.active_local_elements_end()))
361 std::vector<dof_id_type> dof_indices;
363 mooseAssert(dof_indices.size() == 1,
364 "The variable must be a constant monomial with one DoF on an element");
366 "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)
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 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
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)
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)
virtual const std::string & name() const
Get the name of the class.
const FEType & feType() const
Get the type of finite element object.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
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...
virtual bool isArray() const =0
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
bool contains(const std::string &value) const
Contains methods for seeing if a value is in the MultiMooseEnum.
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...
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...
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 ...
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.
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.
const InputParameters & parameters() const
Get the parameters of the object.
const TagName SOLUTION_TAG
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.
virtual std::unique_ptr< PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default)...
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)