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 120 : AddFluidPropertiesInterrogatorAction::validParams() 29 : { 30 120 : InputParameters params = Action::validParams(); 31 240 : params.addRequiredParam<UserObjectName>("fp", 32 : "The name of the fluid properties object to query."); 33 240 : params.addParam<Real>("rho", "Density"); 34 240 : params.addParam<Real>("rhou", "Momentum density; rho * u"); 35 240 : params.addParam<Real>("rhoE", "Total energy density: rho * E"); 36 240 : params.addParam<Real>("e", "Specific internal energy"); 37 240 : params.addParam<Real>("p", "Pressure"); 38 240 : params.addParam<Real>("T", "Temperature"); 39 240 : params.addParam<Real>("vel", "Velocity"); 40 240 : params.addParam<std::vector<Real>>("x_ncg", "Mass fractions of NCGs"); 41 240 : params.addParam<unsigned int>("precision", 10, "Precision for printing values"); 42 240 : params.addParam<bool>("json", false, "Output in JSON format"); 43 : 44 120 : params.addClassDescription("Action that sets up the fluid properties interrogator"); 45 : 46 120 : return params; 47 0 : } 48 : 49 120 : AddFluidPropertiesInterrogatorAction::AddFluidPropertiesInterrogatorAction( 50 120 : const InputParameters & params) 51 120 : : 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 120 : ExecFlagEnum exec_enum = Output::getDefaultExecFlagEnum(); 59 480 : exec_enum = {EXEC_INITIAL, EXEC_TIMESTEP_END}; 60 240 : pars.addParam<ExecFlagEnum>("execute_on", exec_enum, "(Does not need to be set)"); 61 240 : pars.addParam<bool>("print_perf_log", false, "(Does not need to be set)"); 62 240 : pars.addParam<bool>("print_linear_residuals", false, "(Does not need to be set)"); 63 240 : } 64 : 65 : void 66 956 : AddFluidPropertiesInterrogatorAction::act() 67 : { 68 : // Set up an arbitrary mesh 69 956 : if (_current_task == "setup_mesh") 70 : { 71 120 : const std::string class_name = "GeneratedMesh"; 72 120 : InputParameters params = _factory.getValidParams(class_name); 73 240 : params.set<MooseEnum>("dim") = "1"; 74 120 : _mesh = _factory.create<MooseMesh>(class_name, "mesh", params); 75 120 : } 76 : // Initialize the arbitrary mesh 77 836 : else if (_current_task == "init_mesh") 78 : { 79 120 : _mesh->init(); 80 : } 81 : // Create a "solve=false" FEProblem 82 716 : else if (_current_task == "create_problem") 83 : { 84 120 : const std::string class_name = "FEProblem"; 85 120 : InputParameters params = _factory.getValidParams(class_name); 86 120 : params.set<MooseMesh *>("mesh") = _mesh.get(); 87 120 : params.set<bool>("use_nonlinear") = true; 88 120 : params.set<bool>("solve") = false; 89 120 : _problem = _factory.create<FEProblemBase>(class_name, "Problem", params); 90 120 : _problem->setKernelCoverageCheck(FEProblemBase::CoverageCheckMode::FALSE); 91 120 : } 92 : // Add the fluid properties interrogator user object 93 596 : else if (_current_task == "add_user_object") 94 : { 95 120 : addFluidPropertiesInterrogatorObject(); 96 : } 97 : // Set up an arbitrary steady executioner 98 476 : else if (_current_task == "setup_executioner") 99 : { 100 120 : const std::string class_name = "Steady"; 101 120 : InputParameters params = _factory.getValidParams(class_name); 102 120 : params.set<FEProblemBase *>("_fe_problem_base") = _problem.get(); 103 120 : params.set<FEProblem *>("_fe_problem") = (std::dynamic_pointer_cast<FEProblem>(_problem)).get(); 104 : std::shared_ptr<Executioner> executioner = 105 120 : _factory.create<Executioner>(class_name, "Executioner", params); 106 120 : _app.setExecutioner(std::move(executioner)); 107 120 : } 108 : // Create a console that executes only on FINAL and does not print system info 109 356 : else if (_current_task == "add_fp_output") 110 : { 111 118 : OutputWarehouse & output_warehouse = _app.getOutputWarehouse(); 112 236 : 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 954 : } 138 : 139 : void 140 120 : AddFluidPropertiesInterrogatorAction::addFluidPropertiesInterrogatorObject() const 141 : { 142 120 : const std::string class_name = "FluidPropertiesInterrogator"; 143 120 : InputParameters params = _factory.getValidParams(class_name); 144 360 : params.set<UserObjectName>("fp") = getParam<UserObjectName>("fp"); 145 : // Only pass parameters that were supplied to this action 146 240 : if (isParamValid("rho")) 147 100 : params.set<Real>("rho") = getParam<Real>("rho"); 148 240 : if (isParamValid("rhou")) 149 24 : params.set<Real>("rhou") = getParam<Real>("rhou"); 150 240 : if (isParamValid("rhoE")) 151 24 : params.set<Real>("rhoE") = getParam<Real>("rhoE"); 152 240 : if (isParamValid("e")) 153 52 : params.set<Real>("e") = getParam<Real>("e"); 154 240 : if (isParamValid("p")) 155 136 : params.set<Real>("p") = getParam<Real>("p"); 156 240 : if (isParamValid("T")) 157 116 : params.set<Real>("T") = getParam<Real>("T"); 158 240 : if (isParamValid("vel")) 159 4 : params.set<Real>("vel") = getParam<Real>("vel"); 160 240 : if (isParamValid("x_ncg")) 161 72 : params.set<std::vector<Real>>("x_ncg") = getParam<std::vector<Real>>("x_ncg"); 162 240 : params.set<unsigned int>("precision") = getParam<unsigned int>("precision"); 163 240 : params.set<bool>("json") = getParam<bool>("json"); 164 120 : _problem->addUserObject(class_name, "fp_interrogator", params); 165 236 : }