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