www.mooseframework.org
MultiAppScalarToAuxScalarTransfer.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 
16 
17 // MOOSE includes
18 #include "FEProblem.h"
19 #include "MooseTypes.h"
20 #include "MooseVariableScalar.h"
21 #include "MultiApp.h"
22 #include "SystemBase.h"
23 
24 #include "libmesh/meshfree_interpolation.h"
25 #include "libmesh/system.h"
26 
27 // Define the input parameters
28 template <>
31 {
33  params.addRequiredParam<VariableName>("source_variable",
34  "The name of the scalar variable in the MultiApp to "
35  "transfer the value from.");
36  params.addRequiredParam<VariableName>("to_aux_scalar",
37  "The name of the scalar Aux variable in the MultiApp to "
38  "transfer the value to.");
39  return params;
40 }
41 
43  const InputParameters & parameters)
44  : MultiAppTransfer(parameters),
45  _from_variable_name(getParam<VariableName>("source_variable")),
46  _to_aux_name(getParam<VariableName>("to_aux_scalar"))
47 {
48 }
49 
50 void
52 {
53  _console << "Beginning ScalarToAuxScalarTransfer " << name() << std::endl;
54 
55  // Perform action based on the transfer direction
56  switch (_direction)
57  {
58  // MasterApp -> SubApp
59  case TO_MULTIAPP:
60  {
61  // Extract the scalar variable that is being transferred
62  FEProblemBase & from_problem = _multi_app->problemBase();
63  MooseVariableScalar * from_variable =
65 
66  // Loop through each of the sub apps
67  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
68  if (_multi_app->hasLocalApp(i))
69  {
70  // Get reference to the scalar variable that will be written
71  MooseVariableScalar * to_variable =
72  &_multi_app->appProblemBase(i).getScalarVariable(_tid, _to_aux_name);
73 
74  to_variable->reinit();
75 
76  // Determine number of DOFs that we're going to read and write
77  std::vector<dof_id_type> & to_dof = to_variable->dofIndices();
78  auto & from_values = from_variable->sln();
79 
80  // Check that the DOF matches
81  if (from_variable->sln().size() != to_variable->sln().size())
82  mooseError("Order of SCALAR variables do not match for sending and "
83  "receiving data for the "
84  "MultiAppScalarToAuxScalarTransfer!");
85 
86  for (auto j = beginIndex(from_values); j < from_values.size(); ++j)
87  to_variable->sys().solution().set(to_dof[j], from_values[j]);
88 
89  to_variable->sys().solution().close();
90  }
91  break;
92  }
93 
94  // SubApp -> MasterApp
95  case FROM_MULTIAPP:
96  {
97  // The AuxVariable that will be read from the subApp
98  MooseVariableScalar * to_variable =
99  &_multi_app->problemBase().getScalarVariable(_tid, _to_aux_name);
100 
101  // Ensure that the variable is up to date
102  to_variable->reinit();
103 
104  // The dof indices for the scalar variable of interest
105  std::vector<dof_id_type> & to_dof = to_variable->dofIndices();
106 
107  // Loop over each sub-app and populate the AuxVariable values
108  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
109  {
110  if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor())
111  {
112  // Extract the scalar variable that is being transferred
113  FEProblemBase & from_problem = _multi_app->appProblemBase(i);
114  MooseVariableScalar * from_variable =
116 
117  // Loop over the scalar aux variable that we're going to write
118  auto & from_values = from_variable->sln();
119 
120  // Check that DOFs match
121  if (from_variable->sln().size() != to_variable->sln().size())
122  mooseError("Order of SCALAR variables do not match for sending and "
123  "receiving data for the "
124  "MultiAppScalarToAuxScalarTransfer!");
125 
126  for (auto j = beginIndex(from_values); j < from_values.size(); ++j)
127  to_variable->sys().solution().set(to_dof[j], from_values[j]);
128  }
129  }
130  to_variable->sys().solution().close();
131 
132  break;
133  }
134  }
135 
136  _console << "Finished ScalarToAuxScalarTransfer " << name() << std::endl;
137 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
VariableName _to_aux_name
The name of the variable to which the scalar values are being transfered.
VariableValue & sln()
MultiAppScalarToAuxScalarTransfer(const InputParameters &parameters)
virtual void execute() override
Execute the transfer.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
VariableName _from_variable_name
The name of the variable from which the values are being transfered.
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...
MooseEnum _direction
Whether we&#39;re transferring to or from the MultiApp.
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) override
Returns the scalar variable reference from whichever system contains it.
THREAD_ID _tid
Definition: Transfer.h:78
std::vector< dof_id_type > & dofIndices()
InputParameters validParams< MultiAppScalarToAuxScalarTransfer >()
InputParameters validParams< MultiAppTransfer >()
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
Base class for all MultiAppTransfer objects.
Class for scalar variables (they are different).
virtual NumericVector< Number > & solution()=0
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
SystemBase & sys()
Get the system this variable is part of.