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 "AddFluidPropertiesInterrogatorAction.h" 11 : #include "Executioner.h" 12 : #include "FEProblem.h" 13 : 14 : registerMooseAction("FluidPropertiesApp", AddFluidPropertiesInterrogatorAction, "setup_mesh"); 15 : registerMooseAction("FluidPropertiesApp", AddFluidPropertiesInterrogatorAction, "init_mesh"); 16 : registerMooseAction("FluidPropertiesApp", AddFluidPropertiesInterrogatorAction, "create_problem"); 17 : registerMooseAction("FluidPropertiesApp", AddFluidPropertiesInterrogatorAction, "add_user_object"); 18 : registerMooseAction("FluidPropertiesApp", 19 : AddFluidPropertiesInterrogatorAction, 20 : "setup_executioner"); 21 : registerMooseAction("FluidPropertiesApp", AddFluidPropertiesInterrogatorAction, "add_fp_output"); 22 : registerMooseAction("FluidPropertiesApp", AddFluidPropertiesInterrogatorAction, "common_output"); 23 : registerMooseAction("FluidPropertiesApp", 24 : AddFluidPropertiesInterrogatorAction, 25 : "add_output_aux_variables"); 26 : 27 : InputParameters 28 158 : AddFluidPropertiesInterrogatorAction::validParams() 29 : { 30 158 : InputParameters params = Action::validParams(); 31 316 : params.addRequiredParam<UserObjectName>("fp", 32 : "The name of the fluid properties object to query."); 33 316 : params.addParam<Real>("rho", "Density"); 34 316 : params.addParam<Real>("rhou", "Momentum density; rho * u"); 35 316 : params.addParam<Real>("rhoE", "Total energy density: rho * E"); 36 316 : params.addParam<Real>("e", "Specific internal energy"); 37 316 : params.addParam<Real>("p", "Pressure"); 38 316 : params.addParam<Real>("T", "Temperature"); 39 316 : params.addParam<Real>("vel", "Velocity"); 40 316 : params.addParam<std::vector<Real>>("x_ncg", "Mass fractions of NCGs"); 41 316 : params.addParam<unsigned int>("precision", 10, "Precision for printing values"); 42 316 : params.addParam<bool>("json", false, "Output in JSON format"); 43 : 44 158 : params.addClassDescription("Action that sets up the fluid properties interrogator"); 45 : 46 158 : return params; 47 0 : } 48 : 49 158 : AddFluidPropertiesInterrogatorAction::AddFluidPropertiesInterrogatorAction( 50 158 : const InputParameters & params) 51 158 : : Action(params) 52 : { 53 : // Currently these parameters are required by the constructor of Console, which 54 : // assumes that the action satisfying task "add_output" has these parameters. 55 : // However, these parameters are not meant to be seen by the user, so they 56 : // are added here, instead of in validParams(), with the help of const_cast. 57 : InputParameters & pars = const_cast<InputParameters &>(parameters()); 58 158 : ExecFlagEnum exec_enum = Output::getDefaultExecFlagEnum(); 59 632 : exec_enum = {EXEC_INITIAL, EXEC_TIMESTEP_END}; 60 316 : pars.addParam<ExecFlagEnum>("execute_on", exec_enum, "(Does not need to be set)"); 61 316 : pars.addParam<bool>("print_perf_log", false, "(Does not need to be set)"); 62 316 : pars.addParam<bool>("print_linear_residuals", false, "(Does not need to be set)"); 63 316 : } 64 : 65 : void 66 1260 : AddFluidPropertiesInterrogatorAction::act() 67 : { 68 : // Set up an arbitrary mesh 69 1260 : if (_current_task == "setup_mesh") 70 : { 71 158 : const std::string class_name = "GeneratedMesh"; 72 158 : InputParameters params = _factory.getValidParams(class_name); 73 316 : params.set<MooseEnum>("dim") = "1"; 74 158 : _mesh = _factory.create<MooseMesh>(class_name, "mesh", params); 75 158 : } 76 : // Initialize the arbitrary mesh 77 1102 : else if (_current_task == "init_mesh") 78 : { 79 158 : _mesh->init(); 80 : } 81 : // Create a "solve=false" FEProblem 82 944 : else if (_current_task == "create_problem") 83 : { 84 158 : const std::string class_name = "FEProblem"; 85 158 : InputParameters params = _factory.getValidParams(class_name); 86 158 : params.set<MooseMesh *>("mesh") = _mesh.get(); 87 158 : params.set<bool>("use_nonlinear") = true; 88 158 : params.set<bool>("solve") = false; 89 158 : _problem = _factory.create<FEProblemBase>(class_name, "Problem", params); 90 158 : _problem->setKernelCoverageCheck(FEProblemBase::CoverageCheckMode::FALSE); 91 158 : } 92 : // Add the fluid properties interrogator user object 93 786 : else if (_current_task == "add_user_object") 94 : { 95 158 : addFluidPropertiesInterrogatorObject(); 96 : } 97 : // Set up an arbitrary steady executioner 98 628 : else if (_current_task == "setup_executioner") 99 : { 100 158 : const std::string class_name = "Steady"; 101 158 : InputParameters params = _factory.getValidParams(class_name); 102 158 : params.set<FEProblemBase *>("_fe_problem_base") = _problem.get(); 103 158 : params.set<FEProblem *>("_fe_problem") = (std::dynamic_pointer_cast<FEProblem>(_problem)).get(); 104 : std::shared_ptr<Executioner> executioner = 105 158 : _factory.create<Executioner>(class_name, "Executioner", params); 106 158 : _app.setExecutioner(std::move(executioner)); 107 158 : } 108 : // Create a console that executes only on FINAL and does not print system info 109 470 : else if (_current_task == "add_fp_output") 110 : { 111 156 : OutputWarehouse & output_warehouse = _app.getOutputWarehouse(); 112 312 : if (!output_warehouse.hasOutput("console")) 113 : { 114 0 : const std::string class_name = "Console"; 115 0 : InputParameters params = _factory.getValidParams(class_name); 116 0 : params.addPrivateParam<FEProblemBase *>("_fe_problem_base", _problem.get()); 117 0 : params.set<std::string>("file_base") = _app.getOutputFileBase(); 118 0 : params.set<ExecFlagEnum>("execute_on") = EXEC_FINAL; 119 0 : params.set<MultiMooseEnum>("system_info") = ""; 120 0 : std::shared_ptr<Output> output = _factory.create<Output>(class_name, "Console", params); 121 0 : output_warehouse.addOutput(output); 122 0 : } 123 : } 124 : else if (_current_task == "common_output") 125 : { 126 : // This action must satisfy this task to prevent CommonOutputAction from 127 : // acting, which performs a static cast that assumes that the action 128 : // satisfying the task "add_output" is derived from MooseObjectAction, 129 : // which is now false. 130 : } 131 : else if (_current_task == "add_output_aux_variables") 132 : { 133 : // This action must satisfy this task to prevent MaterialOutputAction from 134 : // acting, which assumes that the action satisfying "add_output" can be 135 : // dynamic_cast-ed to type "AddOutputAction", which is now false. 136 : } 137 1258 : } 138 : 139 : void 140 158 : AddFluidPropertiesInterrogatorAction::addFluidPropertiesInterrogatorObject() const 141 : { 142 158 : const std::string class_name = "FluidPropertiesInterrogator"; 143 158 : InputParameters params = _factory.getValidParams(class_name); 144 474 : params.set<UserObjectName>("fp") = getParam<UserObjectName>("fp"); 145 : // Only pass parameters that were supplied to this action 146 316 : if (isParamValid("rho")) 147 132 : params.set<Real>("rho") = getParam<Real>("rho"); 148 316 : if (isParamValid("rhou")) 149 32 : params.set<Real>("rhou") = getParam<Real>("rhou"); 150 316 : if (isParamValid("rhoE")) 151 32 : params.set<Real>("rhoE") = getParam<Real>("rhoE"); 152 316 : if (isParamValid("e")) 153 68 : params.set<Real>("e") = getParam<Real>("e"); 154 316 : if (isParamValid("p")) 155 180 : params.set<Real>("p") = getParam<Real>("p"); 156 316 : if (isParamValid("T")) 157 152 : params.set<Real>("T") = getParam<Real>("T"); 158 316 : if (isParamValid("vel")) 159 4 : params.set<Real>("vel") = getParam<Real>("vel"); 160 316 : if (isParamValid("x_ncg")) 161 96 : params.set<std::vector<Real>>("x_ncg") = getParam<std::vector<Real>>("x_ncg"); 162 316 : params.set<unsigned int>("precision") = getParam<unsigned int>("precision"); 163 316 : params.set<bool>("json") = getParam<bool>("json"); 164 158 : _problem->addUserObject(class_name, "fp_interrogator", params); 165 312 : }