https://mooseframework.inl.gov
MultiAppVectorPostprocessorTransfer.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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");
41 
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 {
59  const VectorPostprocessorValue & vpp =
60  getToMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name,
61  _vector_name);
62 
63  // Execute VPP if it was specified to execute on transfers
67 
68  if (vpp.size() != getToMultiApp()->numGlobalApps())
69  mooseError("VectorPostprocessor ",
71  " and number of sub-apps do not match: ",
72  vpp.size(),
73  "/",
74  getToMultiApp()->numGlobalApps());
75 
76  for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); ++i)
77  if (getToMultiApp()->hasLocalApp(i))
78  getToMultiApp()->appProblemBase(i).setPostprocessorValueByName(_sub_pp_name, vpp[i]);
79 }
80 
81 void
83 {
84  const VectorPostprocessorValue & vpp =
85  getFromMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name,
86  _vector_name);
88 
89  if (vpp.size() != getFromMultiApp()->numGlobalApps())
90  mooseError("VectorPostprocessor ",
92  " and number of sub-apps do not match: ",
93  vpp.size(),
94  "/",
95  getFromMultiApp()->numGlobalApps());
96 
97  VectorPostprocessorValue value(getFromMultiApp()->numGlobalApps(), 0.0);
98  for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); ++i)
99  {
100  // To avoid duplication and thus a wrong pp value after summing value accross procs, we should
101  // ensure that value[i] is only set by one procs. To do this, we check isFirstLocalRank to see
102  // if the current proc is the first rank that subapp i lives on.
103  if (getFromMultiApp()->hasLocalApp(i) && getFromMultiApp()->isFirstLocalRank())
104  value[i] = getFromMultiApp()->appProblemBase(i).getPostprocessorValueByName(_sub_pp_name);
105  }
106 
107  // Sum to distribute entries of 'value' accross all procs
108  for (auto & v : value)
109  _communicator.sum(v);
110 
111  getFromMultiApp()->problemBase().setVectorPostprocessorValueByName(
113 }
114 
115 void
117 {
118  TIME_SECTION(
119  "MultiAppVectorPostprocessorTransfer::execute()", 5, "Transferring a vector postprocessor");
120 
123  else
125 }
const ExecFlagType EXEC_TRANSFER
Definition: Moose.C:53
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.
static void addUserObjectExecutionCheckParam(InputParameters &params)
Add the execution order check parameter (to skip the warning if needed)
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...
void checkParentAppUserObjectExecuteOn(const std::string &object_name) const
Checks the execute_on flags for user object transfers with user objects on the source app which is al...
FEProblemBase & _fe_problem
Definition: Transfer.h:97
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.
void errorIfObjectExecutesOnTransferInSourceApp(const std::string &object_name) const
Error if executing this MooseObject on EXEC_TRANSFER in a source multiapp (from_multiapp, e.g.
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:203
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...
virtual void computeUserObjectByName(const ExecFlagType &type, const Moose::AuxGroup &group, const std::string &name)
Compute an user object with the given name.
MultiAppVectorPostprocessorTransfer(const InputParameters &parameters)