Line data Source code
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 : 20 : InputParameters 21 1040 : OptimizationAction::validParams() 22 : { 23 1040 : InputParameters params = Action::validParams(); 24 1040 : params.addClassDescription( 25 : "Action for performing some common functions for running optimization simulations."); 26 2080 : params.addParam<bool>( 27 : "auto_create_mesh", 28 2080 : true, 29 : "Automatically setup the Mesh block for a main application without a simulation."); 30 2080 : params.addParam<bool>( 31 : "auto_create_problem", 32 2080 : true, 33 : "Automatically setup the Problem block for a main application without a simulation."); 34 1040 : return params; 35 0 : } 36 : 37 1040 : OptimizationAction::OptimizationAction(const InputParameters & params) : Action(params) {} 38 : 39 : void 40 1040 : OptimizationAction::act() 41 : { 42 : // [Mesh] 43 3120 : if (_current_task == "auto_create_mesh" && getParam<bool>("auto_create_mesh") && 44 2080 : !_awh.hasActions("setup_mesh")) 45 : { 46 : // Build the Action parameters 47 475 : InputParameters action_params = _action_factory.getValidParams("SetupMeshAction"); 48 475 : action_params.set<std::string>("type") = "GeneratedMesh"; 49 : 50 : // Associate errors with "solve_type" 51 475 : associateWithParameter("auto_create_mesh", action_params); 52 : 53 : // Create The Action 54 : auto action = std::static_pointer_cast<MooseObjectAction>( 55 950 : _action_factory.create("SetupMeshAction", "Mesh", action_params)); 56 : 57 : // Set the object parameters 58 : InputParameters & params = action->getObjectParams(); 59 950 : params.set<MooseEnum>("dim") = "1"; 60 475 : params.set<unsigned int>("nx") = 1; 61 : 62 : // Add Action to the warehouse 63 1425 : _awh.addActionBlock(action); 64 475 : } 65 : 66 : // [Problem] 67 2170 : else if (_current_task == "auto_create_problem" && getParam<bool>("auto_create_problem") && 68 1605 : !_awh.hasActions("create_problem")) 69 : { 70 : // Build the Action parameters 71 511 : InputParameters action_params = _action_factory.getValidParams("CreateProblemAction"); 72 : 73 : // Associate errors with "solve_type" 74 511 : associateWithParameter("auto_create_problem", action_params); 75 : 76 : // Create the action 77 : auto action = std::static_pointer_cast<MooseObjectAction>( 78 1022 : _action_factory.create("CreateProblemAction", "Problem", action_params)); 79 : 80 : // Set the object parameters 81 : InputParameters & params = action->getObjectParams(); 82 1022 : params.set<MooseEnum>("kernel_coverage_check") = "false"; 83 511 : params.set<bool>("skip_nl_system_check") = true; 84 : 85 : // Add Action to the warehouse 86 1533 : _awh.addActionBlock(action); 87 511 : } 88 1040 : }