16#include "libmesh/id_types.h"
17#include "libmesh/string_to_enum.h"
26 "The tag of the solution vector to be transferred (default to the solution)");
29 "The tag of the solution vector to be transferred to (default to the solution)");
32 params.
addParam<std::vector<SubdomainName>>(
35 "Subdomain restriction to transfer from (defaults to all the origin app domain)");
36 params.
addParam<std::vector<SubdomainName>>(
39 "Subdomain restriction to transfer to, (defaults to all the target app domain)");
42 "Base class for copying degrees-of-freedom values (nonlinear and auxiliary) between apps "
43 "that have identical meshes.");
49 _has_block_restrictions(!getParam<
std::vector<SubdomainName>>(
"from_blocks").empty() ||
50 !getParam<
std::vector<SubdomainName>>(
"to_blocks").empty())
80 mooseError(
"The parallel types (distributed or replicated) of the meshes are not the same.");
87 mooseError(
"The number of processors used by the origin and target problems must be the "
88 "same to use MultiAppDofCopyTransfer-derived transfers. Check that the MultiApp "
89 "'max_procs_per_app' parameter is not restricting sub-apps to a different number "
90 "of processors than the parent app.");
95 const auto & from_block_names = getParam<std::vector<SubdomainName>>(
"from_blocks");
96 for (
const auto & b : from_block_names)
99 paramError(
"from_blocks",
"The block '", b,
"' was not found in the mesh");
101 if (from_block_names.size())
106 _from_blocks = std::set<SubdomainID>(block_vec.begin(), block_vec.end());
115 const auto & to_block_names = getParam<std::vector<SubdomainName>>(
"to_blocks");
116 for (
const auto & b : to_block_names)
119 paramError(
"to_blocks",
"The block '", b,
"' was not found in the mesh");
121 if (to_block_names.size())
126 _to_blocks = std::set<SubdomainID>(block_vec.begin(), block_vec.end());
143 paramError(
"from_blocks",
"Block restriction is not implemented for nodal variables");
150 paramError(
"to_blocks",
"Block restriction is not implemented for nodal variables");
158 mooseError(
"No transferred variables were specified, neither programmatically or through the "
159 "'source_variable' parameter");
161 mooseError(
"Number of variables transferred must be same in both systems.");
176 MeshBase & from_mesh = from_problem.
mesh().
getMesh();
182 auto & from_solution =
isParamValid(
"from_solution_tag")
184 getParam<TagName>(
"from_solution_tag")))
191 "'requires that the target variable '",
193 "' and the source variable'",
195 "' must be the same type "
196 "(order and family): ",
197 libMesh::Utility::enum_to_string<FEFamily>(to_var.
feType().
family),
201 "Corresponding transfer variables must be same field type (STANDARD | VECTOR | ARRAY).");
203 mooseError(
"Corresponding transfer variables must have same number of components.");
205 if ((to_mesh.n_nodes() != from_mesh.n_nodes()) || (to_mesh.n_elem() != from_mesh.n_elem()))
206 mooseError(
"The meshes must be identical to utilize MultiAppDofCopyTransfer::transfer.");
209 for (
const auto & node : as_range(to_mesh.local_nodes_begin(), to_mesh.local_nodes_end()))
211 node, from_mesh.node_ptr(node->id()), to_var, from_var, to_solution, from_solution);
214 for (
auto & to_elem : as_range(to_mesh.local_elements_begin(), to_mesh.local_elements_end()))
216 Elem * from_elem = from_mesh.elem_ptr(to_elem->id());
217 mooseAssert(to_elem->type() == from_elem->type(),
"The elements must be the same type.");
222 SubdomainID from_block = from_elem->subdomain_id();
231 transferDofObject(to_elem, from_elem, to_var, from_var, to_solution, from_solution);
244 NumericVector<Number> & to_solution,
245 NumericVector<Number> & from_solution)
247 for (
unsigned int vc = 0; vc < to_var.
count(); ++vc)
251 for (
unsigned int comp = 0;
256 dof_id_type from_dof =
258 Real from_value = from_solution(from_dof);
259 to_solution.set(dof, from_value);
subdomain_id_type SubdomainID
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
virtual MooseMesh & mesh() override
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 ...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
ParallelType getParallelType() const
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_names) const
Get the associated subdomainIDs for the subdomain names that are passed in.
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
const libMesh::FEType & feType() const
Get the type of finite element object.
SystemBase & sys()
Get the system this variable is part of.
unsigned int number() const
Get variable number coming from libMesh.
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one.
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual Moose::VarFieldType fieldType() const =0
Field type of this variable.
void transfer(FEProblemBase &to_problem, FEProblemBase &from_problem)
Performs the transfer of a variable between two problems if they have the same mesh.
const bool _has_block_restrictions
Whether block restriction is active.
static InputParameters validParams()
void transferDofObject(libMesh::DofObject *to_object, libMesh::DofObject *from_object, MooseVariableFieldBase &to_var, MooseVariableFieldBase &from_var, NumericVector< Number > &to_solution, NumericVector< Number > &from_solution)
Performs the transfer of values between a node or element.
MultiAppDofCopyTransfer(const InputParameters ¶meters)
std::set< SubdomainID > _to_blocks
Subdomain IDs of the blocks to transfer to.
std::set< SubdomainID > _from_blocks
Subdomain IDs of the blocks to transfer from.
void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup.
Intermediary class that allows variable names as inputs.
virtual std::vector< VariableName > getFromVarNames() const =0
Virtual function defining variables to be transferred.
virtual std::vector< AuxVariableName > getToVarNames() const =0
Virtual function defining variables to transfer to.
virtual void initialSetup()
Method called at the beginning of the simulation for checking integrity or doing one-time setup.
static InputParameters validParams()
void checkVariable(const FEProblemBase &fe_problem, const VariableName &var_name, const std::string ¶m_name="") const
Helper for checking a problem for a variable.
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
unsigned int number() const
Gets the number of this system.
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
NumericVector< Number > & solution()
void update()
Update the system (doing libMesh magic)
processor_id_type size() const
MooseEnum _current_direction
unsigned int n_comp(const unsigned int s, const unsigned int var) const
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
unsigned int n_dofs(const unsigned int s, const unsigned int var=libMesh::invalid_uint) const
const Parallel::Communicator & comm() const
bool hasSubdomainName(const MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
const SubdomainID INVALID_BLOCK_ID
std::string incompatVarMsg(MooseVariableFieldBase &var1, MooseVariableFieldBase &var2)
Builds and returns a string of the form: