https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
11#include "AddSamplerAction.h"
12#include "FEProblem.h"
13
14registerMooseAction("StochasticToolsApp", AdaptiveSamplerAction, "add_user_object");
15registerMooseAction("StochasticToolsApp", AdaptiveSamplerAction, "add_postprocessor");
16
19{
21 params.addClassDescription("Adds extra objects pertaining to adaptive samplers.");
22 return params;
23}
24
26
27void
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")
const ExecFlagType EXEC_TIMESTEP_END
std::vector< const T * > getActions()
static InputParameters validParams()
MooseApp & _app
std::shared_ptr< FEProblemBase > & _problem
const std::string & _current_task
static InputParameters validParams()
virtual void act() override
AdaptiveSamplerAction(const InputParameters &params)
static std::set< SamplerName > adaptiveSamplerNames()
Returns the names of all the existing adaptive samplers.
static PostprocessorName adaptiveSamplingCompletedPostprocessorName()
Returns the name of the AdaptiveSamplingCompletedPostprocessor.
InputParameters getValidParams(const std::string &name) const
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
ActionWarehouse & actionWarehouse()
const std::string & name() const
void mooseError(Args &&... args) const
Factory & _factory