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