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 274 : SubChannelAddVariablesAction::validParams() 22 : { 23 274 : InputParameters params = Action::validParams(); 24 274 : params.addClassDescription("Adds the variables associated with the subchannel problem"); 25 548 : params.addParam<bool>("full_output", false, "Add optional subchannel output variables"); 26 274 : return params; 27 0 : } 28 : 29 274 : SubChannelAddVariablesAction::SubChannelAddVariablesAction(const InputParameters & parameters) 30 : : Action(parameters), 31 274 : _fe_family(AddAuxVariableAction::getAuxVariableFamilies()), 32 274 : _fe_order(AddAuxVariableAction::getAuxVariableOrders()) 33 : { 34 274 : } 35 : 36 : void 37 4459 : SubChannelAddVariablesAction::addAuxVariable(const std::string & var_name, 38 : const std::vector<SubdomainName> & blocks) 39 : { 40 4459 : const auto & aux_actions = _awh.getActions<AddAuxVariableAction>(); 41 : 42 9096 : for (const auto * aux_action : aux_actions) 43 4994 : if (aux_action->name() == var_name) 44 : return; 45 : 46 4102 : auto params = _factory.getValidParams("MooseVariable"); 47 4102 : params.set<MooseEnum>("family") = _fe_family; 48 4102 : params.set<MooseEnum>("order") = _fe_order; 49 4102 : params.set<std::vector<SubdomainName>>("block") = blocks; 50 : 51 4102 : _problem->addAuxVariable("MooseVariable", var_name, params); 52 4459 : } 53 : 54 : void 55 274 : 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 274 : const auto & mesh_actions = _awh.getActions<AddMeshGeneratorAction>(); 65 : 66 611 : for (const auto * mesh_action : mesh_actions) 67 : { 68 674 : if (!mesh_action->parameters().isParamValid("type")) 69 0 : continue; 70 : 71 337 : const auto & generator_type = mesh_action->getParam<std::string>("type"); 72 : 73 337 : if (generator_type == "SCMQuadAssemblyMeshGenerator") 74 : { 75 274 : fluid_blocks = {"subchannel"}; 76 : const auto & mesh_generator_params = mesh_action->getObjectParams(); 77 137 : const auto nx = mesh_generator_params.get<unsigned int>("nx"); 78 137 : const auto ny = mesh_generator_params.get<unsigned int>("ny"); 79 137 : if (nx > 1 && ny > 1) 80 : { 81 : pin_mesh_exist = true; 82 256 : pin_blocks = {"fuel_pins"}; 83 : } 84 : } 85 200 : else if (generator_type == "SCMTriAssemblyMeshGenerator") 86 : { 87 274 : fluid_blocks = {"subchannel"}; 88 : pin_mesh_exist = true; 89 274 : pin_blocks = {"fuel_pins"}; 90 : } 91 63 : else if (generator_type == "SCMQuadSubChannelMeshGenerator" || 92 63 : generator_type == "SCMTriSubChannelMeshGenerator") 93 : { 94 : // Use the user-provided mesh generator block name 95 0 : fluid_blocks = {mesh_action->name()}; 96 : } 97 : 98 337 : if (generator_type == "SCMTriPinMeshGenerator" || generator_type == "SCMQuadPinMeshGenerator") 99 : { 100 : pin_mesh_exist = true; 101 : // Use the user-provided mesh generator block name 102 0 : pin_blocks = {mesh_action->name()}; 103 : } 104 : 105 337 : if (generator_type == "SCMTriDuctMeshGenerator" || generator_type == "SCMQuadDuctMeshGenerator") 106 : { 107 : duct_mesh_exist = true; 108 : // Use the user-provided mesh generator block name 109 126 : duct_blocks = {mesh_action->name()}; 110 : } 111 : } 112 : 113 : // Backward-compatible fallback if no explicit subchannel mesh generator name was found 114 274 : if (fluid_blocks.empty()) 115 0 : fluid_blocks = {"subchannel"}; 116 : 117 : std::vector<std::pair<std::string, std::vector<SubdomainName>>> vars_to_add; 118 : 119 : // Always-fluid variables 120 274 : vars_to_add.push_back({SubChannelApp::MASS_FLOW_RATE, fluid_blocks}); 121 274 : vars_to_add.push_back({SubChannelApp::SURFACE_AREA, fluid_blocks}); 122 274 : vars_to_add.push_back({SubChannelApp::SUM_CROSSFLOW, fluid_blocks}); 123 274 : vars_to_add.push_back({SubChannelApp::PRESSURE, fluid_blocks}); 124 274 : vars_to_add.push_back({SubChannelApp::WETTED_PERIMETER, fluid_blocks}); 125 274 : vars_to_add.push_back({SubChannelApp::ENTHALPY, fluid_blocks}); 126 274 : vars_to_add.push_back({SubChannelApp::TEMPERATURE, fluid_blocks}); 127 274 : vars_to_add.push_back({SubChannelApp::DENSITY, fluid_blocks}); 128 274 : vars_to_add.push_back({SubChannelApp::VISCOSITY, fluid_blocks}); 129 274 : vars_to_add.push_back({SubChannelApp::DISPLACEMENT, fluid_blocks}); 130 : 131 : // q_prime lives on pins if pins exist, otherwise on the fluid mesh 132 274 : if (pin_mesh_exist) 133 530 : vars_to_add.push_back({SubChannelApp::LINEAR_HEAT_RATE, pin_blocks}); 134 : else 135 18 : vars_to_add.push_back({SubChannelApp::LINEAR_HEAT_RATE, fluid_blocks}); 136 : 137 : // Pin-only variables 138 274 : if (pin_mesh_exist) 139 : { 140 265 : vars_to_add.push_back({SubChannelApp::PIN_TEMPERATURE, pin_blocks}); 141 265 : vars_to_add.push_back({SubChannelApp::PIN_DIAMETER, pin_blocks}); 142 : // HTC is a subchannel-average output stored on the fluid mesh. 143 530 : vars_to_add.push_back({SubChannelApp::HEAT_TRANSFER_COEFFICIENT, fluid_blocks}); 144 : } 145 : 146 : // Duct-only variables 147 274 : if (duct_mesh_exist) 148 : { 149 63 : vars_to_add.push_back({SubChannelApp::DUCT_HEAT_FLUX, duct_blocks}); 150 126 : vars_to_add.push_back({SubChannelApp::DUCT_TEMPERATURE, duct_blocks}); 151 : } 152 : 153 548 : if (getParam<bool>("full_output")) 154 : { 155 262 : vars_to_add.push_back({SubChannelApp::PRESSURE_DROP, fluid_blocks}); 156 524 : vars_to_add.push_back({SubChannelApp::FRICTION_FACTOR, fluid_blocks}); 157 : } 158 : 159 4733 : for (const auto & var_info : vars_to_add) 160 4459 : addAuxVariable(var_info.first, var_info.second); 161 274 : }