www.mooseframework.org
MultiAppCopyTransfer.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "MultiAppCopyTransfer.h"
16 
17 // MOOSE includes
18 #include "DisplacedProblem.h"
19 #include "FEProblem.h"
20 #include "MooseMesh.h"
21 #include "MooseTypes.h"
22 #include "MooseVariable.h"
23 #include "MultiApp.h"
24 #include "NonlinearSystem.h"
25 
26 #include "libmesh/system.h"
27 #include "libmesh/id_types.h"
28 
29 template <>
32 {
34  params.addRequiredParam<VariableName>("variable",
35  "The variable to store the transferred values in.");
36  params.addRequiredParam<VariableName>("source_variable", "The variable to transfer from.");
37  params.addClassDescription(
38  "Copies variables (nonlinear and auxiliary) between multiapps that have identical meshes.");
39  return params;
40 }
41 
43  : MultiAppTransfer(parameters),
44  _to_var_name(getParam<VariableName>("variable")),
45  _from_var_name(getParam<VariableName>("source_variable"))
46 {
47 }
48 
49 void
51 {
53 }
54 
55 void
56 MultiAppCopyTransfer::transferDofObject(libMesh::DofObject * to_object,
57  libMesh::DofObject * from_object,
58  MooseVariable & to_var,
59  MooseVariable & from_var)
60 {
61  if (to_object->n_dofs(to_var.sys().number(), to_var.number()) >
62  0) // If this variable has dofs at this node
63  for (unsigned int comp = 0; comp < to_object->n_comp(to_var.sys().number(), to_var.number());
64  ++comp)
65  {
66  dof_id_type dof = to_object->dof_number(to_var.sys().number(), to_var.number(), comp);
67  dof_id_type from_dof =
68  from_object->dof_number(from_var.sys().number(), from_var.number(), comp);
69  Real from_value = from_var.sys().solution()(from_dof);
70  to_var.sys().solution().set(dof, from_value);
71  }
72 }
73 
74 void
76 {
77  // Populate the to/from variables needed to perform the transfer
78  MooseVariable & to_var = to_problem.getVariable(0, _to_var_name);
79  MeshBase & to_mesh = to_problem.mesh().getMesh();
80 
81  MooseVariable & from_var = from_problem.getVariable(0, _from_var_name);
82  MeshBase & from_mesh = from_problem.mesh().getMesh();
83 
84  // Check integrity
85  if (to_var.feType() != from_var.feType())
86  mooseError("The variables must be the same type (order and family).");
87 
88  if ((to_mesh.n_nodes() != from_mesh.n_nodes()) || (to_mesh.n_elem() != from_mesh.n_elem()))
89  mooseError("The meshes must be identical to utilize MultiAppCopyTransfer.");
90 
91  // Transfer node dofs
92  MeshBase::const_node_iterator node_it = to_mesh.local_nodes_begin();
93  MeshBase::const_node_iterator node_end = to_mesh.local_nodes_end();
94  for (; node_it != node_end; ++node_it)
95  transferDofObject(*node_it, from_mesh.node_ptr((*node_it)->id()), to_var, from_var);
96 
97  // Transfer elem dofs
98  MeshBase::const_element_iterator elem_it = to_mesh.local_elements_begin();
99  MeshBase::const_element_iterator elem_end = to_mesh.local_elements_end();
100  Elem * to_elem;
101  Elem * from_elem;
102  for (; elem_it != elem_end; ++elem_it)
103  {
104  to_elem = *elem_it;
105  from_elem = from_mesh.elem_ptr(to_elem->id());
106  mooseAssert(to_elem->type() == from_elem->type(), "The elements must be the same type.");
107  transferDofObject(to_elem, from_elem, to_var, from_var);
108  }
109 
110  to_var.sys().solution().close();
111  to_var.sys().update();
112 }
113 
114 void
116 {
117  _console << "Beginning MultiAppCopyTransfer " << name() << std::endl;
118 
119  if (_direction == TO_MULTIAPP)
120  {
121  FEProblemBase & from_problem = _multi_app->problemBase();
122  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
123  if (_multi_app->hasLocalApp(i))
124  transfer(_multi_app->appProblemBase(i), from_problem);
125  }
126 
127  else if (_direction == FROM_MULTIAPP)
128  {
129  FEProblemBase & to_problem = _multi_app->problemBase();
130  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
131  if (_multi_app->hasLocalApp(i))
132  transfer(to_problem, _multi_app->appProblemBase(i));
133  }
134 
135  _console << "Finished MultiAppCopyTransfer " << name() << std::endl;
136 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
const VariableName & _to_var_name
The name of the variable to transfer to.
void variableIntegrityCheck(const AuxVariableName &var_name) const
Utility to verify that the vEariable in the destination system exists.
const FEType & feType() const
Get the type of finite element object.
Class for stuff related to variables.
Definition: MooseVariable.h:43
void transfer(FEProblemBase &to_problem, FEProblemBase &from_problem)
Performs the transfer of a variable between two problems.
void transferDofObject(libMesh::DofObject *to_object, libMesh::DofObject *from_object, MooseVariable &to_var, MooseVariable &from_var)
Performs the transfer of values between a node or element.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::shared_ptr< MultiApp > _multi_app
The MultiApp this Transfer is transferring data to or from.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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...
virtual void update()
Update the system (doing libMesh magic)
Definition: SystemBase.C:665
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
MooseEnum _direction
Whether we&#39;re transferring to or from the MultiApp.
virtual void initialSetup() override
Performs basic error checking that the variable exists on MultiApp.
MultiAppCopyTransfer(const InputParameters &parameters)
virtual unsigned int number()
Gets the number of this system.
Definition: SystemBase.C:604
unsigned int number() const
Get variable number coming from libMesh.
virtual void execute() override
Performs the transfer of a variable (Nonlinear or Auxiliary) to/from the Multiapp.
InputParameters validParams< MultiAppTransfer >()
Base class for all MultiAppTransfer objects.
InputParameters validParams< MultiAppCopyTransfer >()
virtual MooseMesh & mesh() override
virtual NumericVector< Number > & solution()=0
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
const VariableName & _from_var_name
Name of variable transfering from.
SystemBase & sys()
Get the system this variable is part of.
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested variable which may be in any system. ...