Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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");
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  // Execute VPP if it was specified to execute on transfers
64 
65  if (vpp.size() != getToMultiApp()->numGlobalApps())
66  mooseError("VectorPostprocessor ",
68  " and number of sub-apps do not match: ",
69  vpp.size(),
70  "/",
71  getToMultiApp()->numGlobalApps());
72 
73  for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); ++i)
74  if (getToMultiApp()->hasLocalApp(i))
75  getToMultiApp()->appProblemBase(i).setPostprocessorValueByName(_sub_pp_name, vpp[i]);
76 }
77 
78 void
80 {
81  const VectorPostprocessorValue & vpp =
82  getFromMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name,
83  _vector_name);
85 
86  if (vpp.size() != getFromMultiApp()->numGlobalApps())
87  mooseError("VectorPostprocessor ",
89  " and number of sub-apps do not match: ",
90  vpp.size(),
91  "/",
92  getFromMultiApp()->numGlobalApps());
93 
94  VectorPostprocessorValue value(getFromMultiApp()->numGlobalApps(), 0.0);
95  for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); ++i)
96  {
97  // To avoid duplication and thus a wrong pp value after summing value accross procs, we should
98  // ensure that value[i] is only set by one procs. To do this, we check isFirstLocalRank to see
99  // if the current proc is the first rank that subapp i lives on.
100  if (getFromMultiApp()->hasLocalApp(i) && getFromMultiApp()->isFirstLocalRank())
101  value[i] = getFromMultiApp()->appProblemBase(i).getPostprocessorValueByName(_sub_pp_name);
102  }
103 
104  // Sum to distribute entries of 'value' accross all procs
105  for (auto & v : value)
106  _communicator.sum(v);
107 
108  getFromMultiApp()->problemBase().setVectorPostprocessorValueByName(
110 }
111 
112 void
114 {
115  TIME_SECTION(
116  "MultiAppVectorPostprocessorTransfer::execute()", 5, "Transferring a vector postprocessor");
117 
120  else
122 }
const ExecFlagType EXEC_TRANSFER
Definition: Moose.C:51
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...
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)