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 
25 {
27  params.addRequiredParam<PostprocessorName>(
28  "postprocessor", "The name of the Postprocessors on the sub-app to transfer from/to.");
29  params.addRequiredParam<VectorPostprocessorName>("vector_postprocessor",
30  "The name of the VectorPostprocessor in "
31  "the MultiApp to transfer values "
32  "from/to.");
33  params.addRequiredParam<std::string>(
34  "vector_name", "Named vector quantity to transfer from/to in VectorPostprocessor.");
35  params.addClassDescription("This transfer distributes the N values of a "
36  "VectorPostprocessor to Postprocessors located in "
37  "N sub-apps or"
38  " collects Postprocessor values from N sub-apps "
39  "into a VectorPostprocessor");
40  return params;
41 }
42 
44  const InputParameters & parameters)
45  : MultiAppTransfer(parameters),
46  _sub_pp_name(getParam<PostprocessorName>("postprocessor")),
47  _master_vpp_name(getParam<VectorPostprocessorName>("vector_postprocessor")),
48  _vector_name(getParam<std::string>("vector_name"))
49 {
50  if (_directions.size() != 1)
51  paramError("direction", "This transfer is only unidirectional");
52 }
53 
54 void
56 {
57  const VectorPostprocessorValue & vpp =
58  getToMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name,
59  _vector_name);
60 
61  if (vpp.size() != getToMultiApp()->numGlobalApps())
62  mooseError("VectorPostprocessor ",
64  " and number of sub-apps do not match: ",
65  vpp.size(),
66  "/",
67  getToMultiApp()->numGlobalApps());
68 
69  for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); ++i)
70  if (getToMultiApp()->hasLocalApp(i))
71  getToMultiApp()->appProblemBase(i).setPostprocessorValueByName(_sub_pp_name, vpp[i]);
72 }
73 
74 void
76 {
77  const VectorPostprocessorValue & vpp =
78  getFromMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name,
79  _vector_name);
80 
81  if (vpp.size() != getFromMultiApp()->numGlobalApps())
82  mooseError("VectorPostprocessor ",
84  " and number of sub-apps do not match: ",
85  vpp.size(),
86  "/",
87  getFromMultiApp()->numGlobalApps());
88 
89  VectorPostprocessorValue value(getFromMultiApp()->numGlobalApps(), 0.0);
90  for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); ++i)
91  if (getFromMultiApp()->hasLocalApp(i))
92  value[i] = getFromMultiApp()->appProblemBase(i).getPostprocessorValueByName(_sub_pp_name);
93 
94  for (auto & v : value)
95  _communicator.sum(v);
96 
97  getFromMultiApp()->problemBase().setVectorPostprocessorValueByName(
99 }
100 
101 void
103 {
104  TIME_SECTION(
105  "MultiAppVectorPostprocessorTransfer::execute()", 5, "Transferring a vector postprocessor");
106 
109  else
111 }
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
MooseEnum _current_direction
Definition: Transfer.h:106
const std::string & _vector_name
Specific vector to transfer among the vectors in the parent VPP.
registerMooseObject("MooseApp", MultiAppVectorPostprocessorTransfer)
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
const Parallel::Communicator & _communicator
const VectorPostprocessorName & _master_vpp_name
Name of the VectorPostprocessor on the parent app.
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...
const PostprocessorName & _sub_pp_name
Name of the postprocessor on the MultiApp.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Copies the values of a VectorPostprocessor from the parent application to postprocessors on each suba...
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 ...
virtual void execute() override
Execute the transfer.
static InputParameters validParams()
std::vector< Real > VectorPostprocessorValue
Definition: MooseTypes.h:192
MultiMooseEnum _directions
The directions this Transfer is to be executed on.
Definition: Transfer.h:110
Base class for all MultiAppTransfer objects.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
MultiAppVectorPostprocessorTransfer(const InputParameters &parameters)