www.mooseframework.org
MultiAppVectorPostprocessorTransfer.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 
24 
27 {
29  params.addRequiredParam<PostprocessorName>(
30  "postprocessor", "The name of the Postprocessors on the sub-app to transfer from/to.");
31  params.addRequiredParam<VectorPostprocessorName>("vector_postprocessor",
32  "The name of the VectorPostprocessor in "
33  "the MultiApp to transfer values "
34  "from/to.");
35  params.addRequiredParam<std::string>(
36  "vector_name", "Named vector quantity to transfer from/to in VectorPostprocessor.");
37  params.addClassDescription("This transfer distributes the N values of a "
38  "VectorPostprocessor to Postprocessors located in "
39  "N sub-apps or"
40  " collects Postprocessor values from N sub-apps "
41  "into a VectorPostprocessor");
42  return params;
43 }
44 
46  const InputParameters & parameters)
47  : MultiAppTransfer(parameters),
48  _sub_pp_name(getParam<PostprocessorName>("postprocessor")),
49  _master_vpp_name(getParam<VectorPostprocessorName>("vector_postprocessor")),
50  _vector_name(getParam<std::string>("vector_name"))
51 {
52  if (_directions.size() != 1)
53  paramError("direction", "This transfer is only unidirectional");
54 }
55 
56 void
58 {
60  _multi_app->problemBase().getVectorPostprocessorValue(_master_vpp_name, _vector_name, false);
61 
62  if (vpp.size() != _multi_app->numGlobalApps())
63  mooseError("VectorPostprocessor ",
65  " and number of sub-apps do not match: ",
66  vpp.size(),
67  "/",
68  _multi_app->numGlobalApps());
69 
70  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); ++i)
71  if (_multi_app->hasLocalApp(i))
72  _multi_app->appProblemBase(i).getPostprocessorValue(_sub_pp_name) = vpp[i];
73 }
74 
75 void
77 {
79  _multi_app->problemBase().getVectorPostprocessorValue(_master_vpp_name, _vector_name, false);
80 
81  if (vpp.size() != _multi_app->numGlobalApps())
82  mooseError("VectorPostprocessor ",
84  " and number of sub-apps do not match: ",
85  vpp.size(),
86  "/",
87  _multi_app->numGlobalApps());
88 
89  // set all values to zero to make communication easier
90  for (auto & v : vpp)
91  v = 0.0;
92 
93  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); ++i)
94  if (_multi_app->hasLocalApp(i))
95  vpp[i] = _multi_app->appProblemBase(i).getPostprocessorValue(_sub_pp_name);
96 
97  for (auto & v : vpp)
98  _communicator.sum(v);
99 }
100 
101 void
103 {
104  _console << "Beginning VectorPostprocessorTransfer " << name() << std::endl;
105 
108  else
110 
111  _console << "Finished PostprocessorTransfer " << name() << std::endl;
112 }
MultiAppVectorPostprocessorTransfer::_vector_name
const std::string & _vector_name
Definition: MultiAppVectorPostprocessorTransfer.h:40
Transfer::FROM_MULTIAPP
Definition: Transfer.h:72
MultiAppVectorPostprocessorTransfer::executeFromMultiapp
virtual void executeFromMultiapp()
Definition: MultiAppVectorPostprocessorTransfer.C:76
MultiAppVectorPostprocessorTransfer::MultiAppVectorPostprocessorTransfer
MultiAppVectorPostprocessorTransfer(const InputParameters &parameters)
Definition: MultiAppVectorPostprocessorTransfer.C:45
FEProblem.h
registerMooseObject
registerMooseObject("MooseApp", MultiAppVectorPostprocessorTransfer)
MultiAppTransfer::_multi_app
std::shared_ptr< MultiApp > _multi_app
The MultiApp this Transfer is transferring data to or from.
Definition: MultiAppTransfer.h:55
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
MultiAppVectorPostprocessorTransfer::_master_vpp_name
const VectorPostprocessorName & _master_vpp_name
Definition: MultiAppVectorPostprocessorTransfer.h:39
defineLegacyParams
defineLegacyParams(MultiAppVectorPostprocessorTransfer)
MultiAppVectorPostprocessorTransfer::_sub_pp_name
const PostprocessorName & _sub_pp_name
Definition: MultiAppVectorPostprocessorTransfer.h:38
Transfer::_current_direction
MooseEnum _current_direction
Definition: Transfer.h:106
MooseObject::paramError
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseObject.h:215
ConsoleStreamInterface::_console
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Definition: ConsoleStreamInterface.h:31
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
MultiMooseEnum::size
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
Definition: MultiMooseEnum.C:233
InputParameters::addClassDescription
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Definition: InputParameters.C:70
VectorPostprocessorValue
std::vector< Real > VectorPostprocessorValue
Definition: MooseTypes.h:190
MultiAppVectorPostprocessorTransfer::validParams
static InputParameters validParams()
Definition: MultiAppVectorPostprocessorTransfer.C:26
MultiAppVectorPostprocessorTransfer.h
MultiApp.h
MultiAppTransfer
Base class for all MultiAppTransfer objects.
Definition: MultiAppTransfer.h:35
MultiAppTransfer::validParams
static InputParameters validParams()
Definition: MultiAppTransfer.C:25
std
Definition: TheWarehouse.h:80
MultiAppVectorPostprocessorTransfer::execute
virtual void execute() override
Execute the transfer.
Definition: MultiAppVectorPostprocessorTransfer.C:102
MultiAppVectorPostprocessorTransfer::executeToMultiapp
virtual void executeToMultiapp()
Definition: MultiAppVectorPostprocessorTransfer.C:57
MultiAppVectorPostprocessorTransfer
Copies the values of a VectorPostprocessor from the Master to postprocessors on each MultiApp or coll...
Definition: MultiAppVectorPostprocessorTransfer.h:25
Transfer::_directions
const MultiMooseEnum _directions
The directions this Transfer is to be executed on.
Definition: Transfer.h:110
MooseTypes.h
InputParameters::addRequiredParam
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...
Definition: InputParameters.h:1176
MooseObject::name
virtual const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:70