www.mooseframework.org
MultiAppScalarToAuxScalarTransfer.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 // MOOSE includes
13 #include "FEProblem.h"
14 #include "MooseTypes.h"
15 #include "MooseVariableScalar.h"
16 #include "MultiApp.h"
17 #include "SystemBase.h"
18 
19 #include "libmesh/meshfree_interpolation.h"
20 #include "libmesh/system.h"
21 
22 // Define the input parameters
24 
25 template <>
28 {
30  params.addRequiredParam<VariableName>("source_variable",
31  "The name of the scalar variable in the MultiApp to "
32  "transfer the value from.");
33  params.addRequiredParam<VariableName>("to_aux_scalar",
34  "The name of the scalar Aux variable in the MultiApp to "
35  "transfer the value to.");
36  return params;
37 }
38 
40  const InputParameters & parameters)
41  : MultiAppTransfer(parameters),
42  _from_variable_name(getParam<VariableName>("source_variable")),
43  _to_aux_name(getParam<VariableName>("to_aux_scalar"))
44 {
45 }
46 
47 void
49 {
50  _console << "Beginning ScalarToAuxScalarTransfer " << name() << std::endl;
51 
52  // Perform action based on the transfer direction
53  switch (_direction)
54  {
55  // MasterApp -> SubApp
56  case TO_MULTIAPP:
57  {
58  // Extract the scalar variable that is being transferred
59  FEProblemBase & from_problem = _multi_app->problemBase();
60  MooseVariableScalar * from_variable =
62 
63  // Loop through each of the sub apps
64  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
65  if (_multi_app->hasLocalApp(i))
66  {
67  // Get reference to the scalar variable that will be written
68  MooseVariableScalar * to_variable =
69  &_multi_app->appProblemBase(i).getScalarVariable(_tid, _to_aux_name);
70 
71  to_variable->reinit();
72 
73  // Determine number of DOFs that we're going to read and write
74  auto && to_dof = to_variable->dofIndices();
75  auto & from_values = from_variable->sln();
76 
77  // Check that the DOF matches
78  if (from_variable->sln().size() != to_variable->sln().size())
79  mooseError("Order of SCALAR variables do not match for sending and "
80  "receiving data for the "
81  "MultiAppScalarToAuxScalarTransfer!");
82 
83  for (MooseIndex(from_values) j = 0; j < from_values.size(); ++j)
84  to_variable->sys().solution().set(to_dof[j], from_values[j]);
85 
86  to_variable->sys().solution().close();
87  }
88  break;
89  }
90 
91  // SubApp -> MasterApp
92  case FROM_MULTIAPP:
93  {
94  // The AuxVariable that will be read from the subApp
95  MooseVariableScalar * to_variable =
96  &_multi_app->problemBase().getScalarVariable(_tid, _to_aux_name);
97 
98  // Ensure that the variable is up to date
99  to_variable->reinit();
100 
101  // The dof indices for the scalar variable of interest
102  auto && to_dof = to_variable->dofIndices();
103 
104  // Loop over each sub-app and populate the AuxVariable values
105  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
106  {
107  if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor())
108  {
109  // Extract the scalar variable that is being transferred
110  FEProblemBase & from_problem = _multi_app->appProblemBase(i);
111  MooseVariableScalar * from_variable =
113 
114  // Loop over the scalar aux variable that we're going to write
115  auto & from_values = from_variable->sln();
116 
117  // Check that DOFs match
118  if (from_variable->sln().size() != to_variable->sln().size())
119  mooseError("Order of SCALAR variables do not match for sending and "
120  "receiving data for the "
121  "MultiAppScalarToAuxScalarTransfer!");
122 
123  for (MooseIndex(from_values) j = 0; j < from_values.size(); ++j)
124  to_variable->sys().solution().set(to_dof[j], from_values[j]);
125  }
126  }
127  to_variable->sys().solution().close();
128 
129  break;
130  }
131  }
132 
133  _console << "Finished ScalarToAuxScalarTransfer " << name() << std::endl;
134 }
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...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
Copies the value of a SCALAR variable from one App to another.
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...
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:259
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) override
Returns the scalar variable reference from whichever system contains it.
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
THREAD_ID _tid
Definition: Transfer.h:72
InputParameters validParams< MultiAppScalarToAuxScalarTransfer >()
InputParameters validParams< MultiAppTransfer >()
Base class for all MultiAppTransfer objects.
Class for scalar variables (they are different).
virtual NumericVector< Number > & solution()=0
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
const MooseEnum _direction
Whether we&#39;re transferring to or from the MultiApp.
SystemBase & sys()
Get the system this variable is part of.
registerMooseObject("MooseApp", MultiAppScalarToAuxScalarTransfer)