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 "SubChannelAddVariablesAction.h" 11 : #include "ActionWarehouse.h" 12 : #include "ActionFactory.h" 13 : #include "AddAuxVariableAction.h" 14 : #include "FEProblemBase.h" 15 : #include "SubChannelApp.h" 16 : #include "AddMeshGeneratorAction.h" 17 : 18 : registerMooseAction("SubChannelApp", SubChannelAddVariablesAction, "add_aux_variable"); 19 : 20 : InputParameters 21 297 : SubChannelAddVariablesAction::validParams() 22 : { 23 297 : InputParameters params = Action::validParams(); 24 297 : params.addClassDescription("Adds the variables associated with the subchannel problem"); 25 594 : params.addParam<bool>("full_output", false, "Add optional subchannel output variables"); 26 297 : return params; 27 0 : } 28 : 29 297 : SubChannelAddVariablesAction::SubChannelAddVariablesAction(const InputParameters & parameters) 30 : : Action(parameters), 31 297 : _fe_family(AddAuxVariableAction::getAuxVariableFamilies()), 32 297 : _fe_order(AddAuxVariableAction::getAuxVariableOrders()) 33 : { 34 297 : } 35 : 36 : void 37 4452 : SubChannelAddVariablesAction::addAuxVariable(const std::string & var_name, 38 : const std::vector<SubdomainName> & blocks) 39 : { 40 4452 : const auto & aux_actions = _awh.getActions<AddAuxVariableAction>(); 41 : 42 7167 : for (const auto * aux_action : aux_actions) 43 2822 : if (aux_action->name() == var_name) 44 : return; 45 : 46 4345 : auto params = _factory.getValidParams("MooseVariable"); 47 4345 : params.set<MooseEnum>("family") = _fe_family; 48 4345 : params.set<MooseEnum>("order") = _fe_order; 49 4345 : params.set<std::vector<SubdomainName>>("block") = blocks; 50 : 51 4345 : _problem->addAuxVariable("MooseVariable", var_name, params); 52 4452 : } 53 : 54 : void 55 297 : SubChannelAddVariablesAction::act() 56 : { 57 : bool pin_mesh_exist = false; 58 : bool duct_mesh_exist = false; 59 : 60 : std::vector<SubdomainName> fluid_blocks; 61 : std::vector<SubdomainName> pin_blocks; 62 : std::vector<SubdomainName> duct_blocks; 63 : 64 297 : const auto & mesh_actions = _awh.getActions<AddMeshGeneratorAction>(); 65 : 66 820 : for (const auto * mesh_action : mesh_actions) 67 : { 68 1046 : if (!mesh_action->parameters().isParamValid("type")) 69 0 : continue; 70 : 71 523 : const auto & generator_type = mesh_action->getParam<std::string>("type"); 72 : 73 523 : if (generator_type == "SCMQuadSubChannelMeshGenerator" || 74 377 : generator_type == "SCMTriSubChannelMeshGenerator") 75 : { 76 : // Use the user-provided mesh generator block name 77 594 : fluid_blocks = {mesh_action->name()}; 78 : } 79 : 80 523 : if (generator_type == "SCMTriPinMeshGenerator" || generator_type == "SCMQuadPinMeshGenerator") 81 : { 82 : pin_mesh_exist = true; 83 : // Use the user-provided mesh generator block name 84 326 : pin_blocks = {mesh_action->name()}; 85 : } 86 : 87 523 : if (generator_type == "SCMTriDuctMeshGenerator" || generator_type == "SCMQuadDuctMeshGenerator") 88 : { 89 : duct_mesh_exist = true; 90 : // Use the user-provided mesh generator block name 91 126 : duct_blocks = {mesh_action->name()}; 92 : } 93 : } 94 : 95 : // Backward-compatible fallback if no explicit subchannel mesh generator name was found 96 297 : if (fluid_blocks.empty()) 97 0 : fluid_blocks = {"sub_channel"}; 98 : 99 : std::vector<std::pair<std::string, std::vector<SubdomainName>>> vars_to_add; 100 : 101 : // Always-fluid variables 102 297 : vars_to_add.push_back({SubChannelApp::MASS_FLOW_RATE, fluid_blocks}); 103 297 : vars_to_add.push_back({SubChannelApp::SURFACE_AREA, fluid_blocks}); 104 297 : vars_to_add.push_back({SubChannelApp::SUM_CROSSFLOW, fluid_blocks}); 105 297 : vars_to_add.push_back({SubChannelApp::PRESSURE, fluid_blocks}); 106 297 : vars_to_add.push_back({SubChannelApp::WETTED_PERIMETER, fluid_blocks}); 107 297 : vars_to_add.push_back({SubChannelApp::ENTHALPY, fluid_blocks}); 108 297 : vars_to_add.push_back({SubChannelApp::TEMPERATURE, fluid_blocks}); 109 297 : vars_to_add.push_back({SubChannelApp::DENSITY, fluid_blocks}); 110 297 : vars_to_add.push_back({SubChannelApp::VISCOSITY, fluid_blocks}); 111 297 : vars_to_add.push_back({SubChannelApp::DISPLACEMENT, fluid_blocks}); 112 : 113 : // q_prime lives on pins if pins exist, otherwise on the fluid mesh 114 297 : if (pin_mesh_exist) 115 326 : vars_to_add.push_back({SubChannelApp::LINEAR_HEAT_RATE, pin_blocks}); 116 : else 117 268 : vars_to_add.push_back({SubChannelApp::LINEAR_HEAT_RATE, fluid_blocks}); 118 : 119 : // Pin-only variables 120 297 : if (pin_mesh_exist) 121 : { 122 163 : vars_to_add.push_back({SubChannelApp::PIN_TEMPERATURE, pin_blocks}); 123 163 : vars_to_add.push_back({SubChannelApp::PIN_DIAMETER, pin_blocks}); 124 : // HTC is a subchannel-average output stored on the fluid mesh. 125 326 : vars_to_add.push_back({SubChannelApp::HEAT_TRANSFER_COEFFICIENT, fluid_blocks}); 126 : } 127 : 128 : // Duct-only variables 129 297 : if (duct_mesh_exist) 130 : { 131 63 : vars_to_add.push_back({SubChannelApp::DUCT_HEAT_FLUX, duct_blocks}); 132 126 : vars_to_add.push_back({SubChannelApp::DUCT_TEMPERATURE, duct_blocks}); 133 : } 134 : 135 594 : if (getParam<bool>("full_output")) 136 : { 137 285 : vars_to_add.push_back({SubChannelApp::PRESSURE_DROP, fluid_blocks}); 138 570 : vars_to_add.push_back({SubChannelApp::FRICTION_FACTOR, fluid_blocks}); 139 : } 140 : 141 4749 : for (const auto & var_info : vars_to_add) 142 4452 : addAuxVariable(var_info.first, var_info.second); 143 297 : }