www.mooseframework.org
MultiAppPostprocessorTransfer.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 "MooseTypes.h"
19 #include "FEProblem.h"
20 #include "MultiApp.h"
21 
22 // libMesh
23 #include "libmesh/meshfree_interpolation.h"
24 #include "libmesh/system.h"
25 
26 template <>
29 {
31  params.addRequiredParam<PostprocessorName>(
32  "from_postprocessor",
33  "The name of the Postprocessor in the Master to transfer the value from.");
34  params.addRequiredParam<PostprocessorName>(
35  "to_postprocessor",
36  "The name of the Postprocessor in the MultiApp to transfer the value to. "
37  " This should most likely be a Reporter Postprocessor.");
38  MooseEnum reduction_type("average sum maximum minimum");
39  params.addParam<MooseEnum>("reduction_type",
40  reduction_type,
41  "The type of reduction to perform to reduce postprocessor "
42  "values from multiple SubApps to a single value");
43  return params;
44 }
45 
47  : MultiAppTransfer(parameters),
48  _from_pp_name(getParam<PostprocessorName>("from_postprocessor")),
49  _to_pp_name(getParam<PostprocessorName>("to_postprocessor")),
50  _reduction_type(getParam<MooseEnum>("reduction_type"))
51 {
53  if (!_reduction_type.isValid())
54  mooseError("In MultiAppPostprocessorTransfer, must specify 'reduction_type' if direction = "
55  "from_multiapp");
56 }
57 
58 void
60 {
61  _console << "Beginning PostprocessorTransfer " << name() << std::endl;
62 
63  switch (_direction)
64  {
65  case TO_MULTIAPP:
66  {
67  FEProblemBase & from_problem = _multi_app->problemBase();
68 
69  Real pp_value = from_problem.getPostprocessorValue(_from_pp_name);
70 
71  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
72  if (_multi_app->hasLocalApp(i))
73  _multi_app->appProblemBase(i).getPostprocessorValue(_to_pp_name) = pp_value;
74  break;
75  }
76  case FROM_MULTIAPP:
77  {
78  FEProblemBase & to_problem = _multi_app->problemBase();
79 
80  Real reduced_pp_value;
81  switch (_reduction_type)
82  {
83  case AVERAGE:
84  case SUM:
85  reduced_pp_value = 0;
86  break;
87  case MAXIMUM:
88  reduced_pp_value = -std::numeric_limits<Real>::max();
89  break;
90  case MINIMUM:
91  reduced_pp_value = std::numeric_limits<Real>::max();
92  break;
93  default:
94  mooseError(
95  "Can't get here unless someone adds a new enum and fails to add it to this switch");
96  }
97 
98  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
99  {
100  if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor())
101  {
102  Real curr_pp_value = _multi_app->appProblemBase(i).getPostprocessorValue(_from_pp_name);
103  switch (_reduction_type)
104  {
105  case AVERAGE:
106  case SUM:
107  reduced_pp_value += curr_pp_value;
108  break;
109  case MAXIMUM:
110  reduced_pp_value = std::max(curr_pp_value, reduced_pp_value);
111  break;
112  case MINIMUM:
113  reduced_pp_value = std::min(curr_pp_value, reduced_pp_value);
114  break;
115  default:
116  mooseError("Can't get here unless someone adds a new enum and fails to add it to "
117  "this switch");
118  }
119  }
120  }
121 
122  switch (_reduction_type)
123  {
124  case AVERAGE:
125  _communicator.sum(reduced_pp_value);
126  reduced_pp_value /= static_cast<Real>(_multi_app->numGlobalApps());
127  break;
128  case SUM:
129  _communicator.sum(reduced_pp_value);
130  break;
131  case MAXIMUM:
132  _communicator.max(reduced_pp_value);
133  break;
134  case MINIMUM:
135  _communicator.min(reduced_pp_value);
136  break;
137  default:
138  mooseError(
139  "Can't get here unless someone adds a new enum and fails to add it to this switch");
140  }
141 
142  to_problem.getPostprocessorValue(_to_pp_name) = reduced_pp_value;
143  break;
144  }
145  }
146 
147  _console << "Finished PostprocessorTransfer " << name() << std::endl;
148 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
virtual bool isValid() const override
IsValid.
Definition: MooseEnum.h:110
InputParameters validParams< MultiAppPostprocessorTransfer >()
MultiAppPostprocessorTransfer(const InputParameters &parameters)
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...
MooseEnum _direction
Whether we&#39;re transferring to or from the MultiApp.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
InputParameters validParams< MultiAppTransfer >()
Base class for all MultiAppTransfer objects.
PostprocessorValue & getPostprocessorValue(const PostprocessorName &name)
Get a reference to the value associated with the postprocessor.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual void execute() override
Execute the transfer.