https://mooseframework.inl.gov
AdaptiveSamplerAction.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 
10 #include "AdaptiveSamplerAction.h"
11 #include "AddSamplerAction.h"
12 #include "FEProblem.h"
13 
14 registerMooseAction("StochasticToolsApp", AdaptiveSamplerAction, "add_user_object");
15 registerMooseAction("StochasticToolsApp", AdaptiveSamplerAction, "add_postprocessor");
16 
19 {
21  params.addClassDescription("Adds extra objects pertaining to adaptive samplers.");
22  return params;
23 }
24 
26 
27 void
29 {
30  const auto samplers = _app.actionWarehouse().getActions<AddSamplerAction>();
31  SamplerName sampler_name;
32 
33  // determine whether the sampler is an adaptive sampler
34  for (auto & sampler : samplers)
35  if (adaptiveSamplerNames().count(sampler->getMooseObjectType()) > 0)
36  {
37  if (!sampler_name.empty())
38  mooseError("The case with multiple adaptive samplers is not currently supported");
39  sampler_name = sampler->name();
40  }
41 
42  if (sampler_name.empty())
43  return;
44 
45  if (_current_task == "add_user_object")
46  {
47  InputParameters params = _factory.getValidParams("Terminator");
48  params.set<std::string>("expression") = adaptiveSamplingCompletedPostprocessorName() + " > 0";
49  params.set<std::string>("message") = "Sampling completed!";
50  params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_END};
51  _problem->addUserObject("Terminator", "_terminate" + sampler_name, params);
52  }
53  else if (_current_task == "add_postprocessor")
54  {
55  InputParameters params = _factory.getValidParams("AdaptiveSamplingCompletedPostprocessor");
56  params.set<SamplerName>("sampler") = sampler_name;
57  params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_END};
58  params.set<std::vector<OutputName>>("outputs") = {"none"};
59  _problem->addUserObject("AdaptiveSamplingCompletedPostprocessor",
61  params);
62  }
63 }
registerMooseAction("StochasticToolsApp", AdaptiveSamplerAction, "add_user_object")
AdaptiveSamplerAction(const InputParameters &params)
MooseApp & _app
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
static InputParameters validParams()
static std::set< SamplerName > adaptiveSamplerNames()
Returns the names of all the existing adaptive samplers.
const ExecFlagType EXEC_TIMESTEP_END
Factory & _factory
static InputParameters validParams()
const std::string & _current_task
ActionWarehouse & actionWarehouse()
virtual void act() override
static PostprocessorName adaptiveSamplingCompletedPostprocessorName()
Returns the name of the AdaptiveSamplingCompletedPostprocessor.
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
std::vector< const T *> getActions()