www.mooseframework.org
MultiAppPostprocessorToAuxScalarTransfer.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<PostprocessorName>(
34  "from_postprocessor",
35  "The name of the Postprocessor in the Master to transfer the value from.");
36  params.addRequiredParam<VariableName>(
37  "to_aux_scalar",
38  "The name of the scalar Aux variable in the MultiApp to transfer the value to.");
39  return params;
40 }
41 
43  const InputParameters & parameters)
44  : MultiAppTransfer(parameters),
45  _from_pp_name(getParam<PostprocessorName>("from_postprocessor")),
46  _to_aux_name(getParam<VariableName>("to_aux_scalar"))
47 {
48 }
49 
50 void
52 {
53  _console << "Beginning PostprocessorToAuxScalarTransfer " << 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 postprocessor that is being transferd
62  FEProblemBase & from_problem = _multi_app->problemBase();
63  Real pp_value = from_problem.getPostprocessorValue(_from_pp_name);
64 
65  // Loop through each of the sub apps
66  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
67  if (_multi_app->hasLocalApp(i))
68  {
69  // Get reference to the AuxVariable where the postprocessor will be passed
70  MooseVariableScalar & scalar =
71  _multi_app->appProblemBase(i).getScalarVariable(_tid, _to_aux_name);
72 
73  scalar.reinit();
74 
75  // Set all values of the AuxVariable to the value of the postprocessor
76  scalar.setValues(pp_value);
77 
78  // Update the solution
79  scalar.insert(scalar.sys().solution());
80  scalar.sys().solution().close();
81  }
82  break;
83  }
84 
85  // SubApp -> MasterApp
86  case FROM_MULTIAPP:
87  {
88  // The number of sub applications
89  unsigned int num_apps = _multi_app->numGlobalApps();
90 
91  // The AuxVariable for storing the postprocessor values from the sub app
92  MooseVariableScalar & scalar =
93  _multi_app->problemBase().getScalarVariable(_tid, _to_aux_name);
94 
95  // Ensure that the variable is up to date
96  scalar.reinit();
97 
98  // The dof indices for the scalar variable of interest
99  std::vector<dof_id_type> & dof = scalar.dofIndices();
100 
101  // Error if there is a size mismatch between the scalar AuxVariable and the number of sub apps
102  if (num_apps != scalar.sln().size())
103  mooseError("The number of sub apps (",
104  num_apps,
105  ") must be equal to the order of the scalar AuxVariable (",
106  scalar.order(),
107  ")");
108 
109  // Loop over each sub-app and populate the AuxVariable values from the postprocessors
110  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
111  if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor())
112  // Note: This can't be done using MooseScalarVariable::insert() because different
113  // processors will be setting dofs separately.
114  scalar.sys().solution().set(
115  dof[i], _multi_app->appProblemBase(i).getPostprocessorValue(_from_pp_name));
116 
117  scalar.sys().solution().close();
118 
119  break;
120  }
121  }
122 
123  _console << "Finished PostprocessorToAuxScalarTransfer " << name() << std::endl;
124 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
virtual void execute() override
Execute the transfer.
VariableValue & sln()
VariableName _to_aux_name
The name of the variable to which the postprocessor is being transfered.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
PostprocessorName _from_pp_name
The name of the postprocessor that the transfer originates.
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...
MultiAppPostprocessorToAuxScalarTransfer(const InputParameters &parameters)
InputParameters validParams< MultiAppPostprocessorToAuxScalarTransfer >()
MooseEnum _direction
Whether we&#39;re transferring to or from the MultiApp.
void setValues(Number value)
Set all of the values of this scalar variable to the same value.
Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int...
THREAD_ID _tid
Definition: Transfer.h:78
std::vector< dof_id_type > & dofIndices()
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 insert(NumericVector< Number > &soln)
PostprocessorValue & getPostprocessorValue(const PostprocessorName &name)
Get a reference to the value associated with the postprocessor.
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.