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