https://mooseframework.inl.gov
OptimizationAction.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 "OptimizationAction.h"
11 #include "ActionWarehouse.h"
12 #include "ActionFactory.h"
13 #include "MooseEnum.h"
14 #include "SetupMeshAction.h"
15 
16 registerMooseAction("OptimizationApp", OptimizationAction, "auto_create_mesh");
17 registerMooseAction("OptimizationApp", OptimizationAction, "auto_create_problem");
18 registerMooseAction("OptimizationApp", OptimizationAction, "auto_create_executioner");
19 
22 {
24  params.addClassDescription(
25  "Action for performing some common functions for running optimization simulations.");
26  params.addParam<bool>(
27  "auto_create_mesh",
28  true,
29  "Automatically setup the Mesh block for a main application without a simulation.");
30  params.addParam<bool>(
31  "auto_create_problem",
32  true,
33  "Automatically setup the Problem block for a main application without a simulation.");
34  return params;
35 }
36 
38 
39 void
41 {
42  // [Mesh]
43  if (_current_task == "auto_create_mesh" && getParam<bool>("auto_create_mesh") &&
44  !_awh.hasActions("setup_mesh"))
45  {
46  // Build the Action parameters
47  InputParameters action_params = _action_factory.getValidParams("SetupMeshAction");
48  action_params.set<std::string>("type") = "GeneratedMesh";
49 
50  // Associate errors with "solve_type"
51  associateWithParameter("auto_create_mesh", action_params);
52 
53  // Create The Action
54  auto action = std::static_pointer_cast<MooseObjectAction>(
55  _action_factory.create("SetupMeshAction", "Mesh", action_params));
56 
57  // Set the object parameters
58  InputParameters & params = action->getObjectParams();
59  params.set<MooseEnum>("dim") = "1";
60  params.set<unsigned int>("nx") = 1;
61 
62  // Add Action to the warehouse
63  _awh.addActionBlock(action);
64  }
65 
66  // [Problem]
67  else if (_current_task == "auto_create_problem" && getParam<bool>("auto_create_problem") &&
68  !_awh.hasActions("create_problem"))
69  {
70  // Build the Action parameters
71  InputParameters action_params = _action_factory.getValidParams("CreateProblemAction");
72 
73  // Associate errors with "solve_type"
74  associateWithParameter("auto_create_problem", action_params);
75 
76  // Create the action
77  auto action = std::static_pointer_cast<MooseObjectAction>(
78  _action_factory.create("CreateProblemAction", "Problem", action_params));
79 
80  // Set the object parameters
81  InputParameters & params = action->getObjectParams();
82  params.set<MooseEnum>("kernel_coverage_check") = "false";
83  params.set<bool>("skip_nl_system_check") = true;
84 
85  // Add Action to the warehouse
86  _awh.addActionBlock(action);
87  }
88 }
ActionWarehouse & _awh
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
InputParameters getValidParams(const std::string &name)
OptimizationAction(const InputParameters &params)
T & set(const std::string &name, bool quiet_mode=false)
registerMooseAction("OptimizationApp", OptimizationAction, "auto_create_mesh")
void addActionBlock(std::shared_ptr< Action > blk)
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters &parameters)
static InputParameters validParams()
Helper for performing common tasks for optimization simulations.
const std::string & _current_task
ActionFactory & _action_factory
bool hasActions(const std::string &task) const
static InputParameters validParams()
void associateWithParameter(const std::string &param_name, InputParameters &params) const
void addClassDescription(const std::string &doc_string)
virtual void act() override