www.mooseframework.org
StochasticToolsTransfer.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
10 #include "MultiApp.h"
11 #include "Sampler.h"
14 
17 {
19  params.set<bool>("check_multiapp_execute_on", true) = false; // see comments in constructor
20  params.addParam<SamplerName>("sampler", "A the Sampler object that Transfer is associated..");
21  return params;
22 }
23 
25  : MultiAppTransfer(parameters), SamplerInterface(this)
26 {
27  // Since sampler lives in the main app, it's unclear what sibling transfer should look like
28  if (hasFromMultiApp() && hasToMultiApp())
29  mooseError("Transfers between multiapp are not currently supported for this transfer type");
30 
31  const auto multi_app = hasFromMultiApp() ? getFromMultiApp() : getToMultiApp();
32 
33  // When the MultiApp is running in batch mode the execute flags for the transfer object must
34  // be removed. If not the 'regular' transfer that occurs will potentially destroy data
35  // populated during the calls from the MultiApp in batch mode. To prevent the Transfer from
36  // running the execute flags must be removed. This is done automatically here, unless
37  // 'execute_on' was modified by the user, which an error is produced.
38  if (multi_app->isParamValid("mode") &&
39  (multi_app->getParam<MooseEnum>("mode") == "batch-reset" ||
40  multi_app->getParam<MooseEnum>("mode") == "batch-restore"))
41  {
42  if (parameters.isParamSetByUser("execute_on"))
43  paramError("execute_on",
44  "The 'execute_on' parameter for the '",
45  name(),
46  "' transfer was set, but the parent MultiApp object (",
47  multi_app->name(),
48  ") is running in 'batch' mode. For this case the 'execute_on' parameter must not "
49  "be set by the user or set to NONE.");
50  else
51  {
52  ExecFlagEnum & exec_flags = const_cast<ExecFlagEnum &>(getParam<ExecFlagEnum>("execute_on"));
53  exec_flags = EXEC_NONE;
54  }
55  }
56 
57  // In the validParams method above the 'check_multiapp_execute_on' is disabled. This is required
58  // to allow for the error above to be triggered. If the 'execute_on' is set by the without
59  // the 'check_multiapp_execute_on' flag the above if statement may not be reached. Therefore,
60  // a bit of a trick is performed to allow the above check to run first and then the regular
61  // check.
62  //
63  // If the else statement is reached then the user is not running in batch mode, so the
64  // 'check_multiapp_execute_on' is a valid check to perform. If the 'check_multiapp_execute_on'
65  // has not been set, then the user wants the check to be performed, so do it.
66  else if (!parameters.isParamSetByUser("check_multiapp_execute_on"))
68 
69  // Determine the Sampler
70  if (isParamValid("sampler"))
71  {
72  _sampler_ptr = &(getSampler("sampler"));
73 
74  SamplerTransientMultiApp * ptr_transient =
75  dynamic_cast<SamplerTransientMultiApp *>(multi_app.get());
76  SamplerFullSolveMultiApp * ptr_fullsolve =
77  dynamic_cast<SamplerFullSolveMultiApp *>(multi_app.get());
78 
79  if (!ptr_transient && !ptr_fullsolve)
80  mooseError("The 'multi_app' parameter must provide either a 'SamplerTransientMultiApp' or "
81  "'SamplerFullSolveMultiApp' object.");
82 
83  if ((ptr_transient && &(ptr_transient->getSampler("sampler")) != _sampler_ptr) ||
84  (ptr_fullsolve && &(ptr_fullsolve->getSampler("sampler")) != _sampler_ptr))
85  mooseError("The supplied 'multi_app' must have the same Sampler object as this Transfer.");
86  }
87 
88  else
89  {
90  paramWarning("sampler",
91  "Support for the 'StochasticToolsTransfer' objects without the 'sampler' input "
92  "parameter is being removed, please update your input file(s).");
93 
94  std::shared_ptr<SamplerTransientMultiApp> ptr_transient =
95  std::dynamic_pointer_cast<SamplerTransientMultiApp>(multi_app);
96  std::shared_ptr<SamplerFullSolveMultiApp> ptr_fullsolve =
97  std::dynamic_pointer_cast<SamplerFullSolveMultiApp>(multi_app);
98 
99  if (!ptr_transient && !ptr_fullsolve)
100  mooseError("The 'multi_app' parameter must provide either a 'SamplerTransientMultiApp' or "
101  "'SamplerFullSolveMultiApp' object.");
102 
103  if (ptr_transient)
104  _sampler_ptr = &(ptr_transient->getSampler("sampler"));
105  else
106  _sampler_ptr = &(ptr_fullsolve->getSampler("sampler"));
107  }
108 }
109 
110 void
112 {
113 }
114 
115 void
117 {
118 }
119 
120 void
122 {
123 }
124 
125 void
127 {
128 }
129 
130 void
132 {
133 }
134 
135 void
137 {
138 }
Sampler * _sampler_ptr
Pointer to the Sampler object used by the SamplerTransientMultiApp or SamplerFullSolveMultiApp.
virtual void initializeFromMultiapp()
Methods for transferring data from sub-applications to the master application.
const std::shared_ptr< MultiApp > getFromMultiApp() const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const ExecFlagType EXEC_NONE
void checkMultiAppExecuteOn()
T & set(const std::string &name, bool quiet_mode=false)
const std::shared_ptr< MultiApp > getToMultiApp() const
bool hasFromMultiApp() const
virtual const std::string & name() const
bool isParamValid(const std::string &name) const
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
static InputParameters validParams()
bool isParamSetByUser(const std::string &name) const
T & getSampler(const std::string &name)
bool hasToMultiApp() const
void mooseError(Args &&... args) const
const InputParameters & parameters() const
void paramWarning(const std::string &param, Args... args) const
StochasticToolsTransfer(const InputParameters &parameters)
virtual void initializeToMultiapp()
Methods for transferring data to sub-applications to the master application.