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 "HeatStructureBase.h" 11 : #include "ConstantFunction.h" 12 : 13 : InputParameters 14 1874 : HeatStructureBase::validParams() 15 : { 16 1874 : InputParameters params = Component2D::validParams(); 17 1874 : params += HeatStructureInterface::validParams(); 18 : 19 3748 : params.addParam<Real>("T_rel_step_tol", 1e-5, "Temperature relative step tolerance"); 20 3748 : params.addParam<Real>("res_tol", 1e-5, "Residual tolerance"); 21 : 22 1874 : return params; 23 0 : } 24 : 25 936 : HeatStructureBase::HeatStructureBase(const InputParameters & params) 26 936 : : Component2D(params), HeatStructureInterface(this), _number_of_hs(_n_regions) 27 : { 28 936 : } 29 : 30 : void 31 915 : HeatStructureBase::init() 32 : { 33 : Component2D::init(); 34 915 : HeatStructureInterface::init(); 35 915 : } 36 : 37 : void 38 903 : HeatStructureBase::check() const 39 : { 40 903 : Component2D::check(); 41 903 : HeatStructureInterface::check(); 42 903 : } 43 : 44 : const unsigned int & 45 0 : HeatStructureBase::getIndexFromName(const std::string & name) const 46 : { 47 0 : return _name_index.at(name); 48 : } 49 : 50 : bool 51 3948 : HeatStructureBase::usingSecondOrderMesh() const 52 : { 53 3948 : return HeatConductionModel::feType().order == SECOND; 54 : } 55 : 56 : Convergence * 57 10 : HeatStructureBase::getNonlinearConvergence() const 58 : { 59 20 : if (!isParamValid("solid_properties")) 60 0 : mooseError("ComponentsConvergence may only be used if 'solid_properties' is provided."); 61 : 62 20 : return &getTHMProblem().getConvergence(nonlinearConvergenceName()); 63 : } 64 : 65 : void 66 795 : HeatStructureBase::addVariables() 67 : { 68 795 : HeatStructureInterface::addVariables(); 69 795 : } 70 : 71 : void 72 795 : HeatStructureBase::addMooseObjects() 73 : { 74 795 : HeatStructureInterface::addMooseObjects(); 75 : 76 1590 : if (isParamValid("solid_properties")) 77 : { 78 1438 : const auto sp_names = getParam<std::vector<UserObjectName>>("solid_properties"); 79 1438 : const auto T_ref = getParam<std::vector<Real>>("solid_properties_T_ref"); 80 1790 : for (unsigned int i = 0; i < sp_names.size(); i++) 81 1071 : addConstantDensitySolidPropertiesMaterial(sp_names[i], T_ref[i], i); 82 : 83 : // add objects needed for ComponentsConvergence 84 719 : addNonlinearStepFunctorMaterial(HeatConductionModel::TEMPERATURE, "hs_T_step", true); 85 719 : const auto & blocks = getSubdomainNames(); 86 1790 : for (const auto i : make_range(blocks.size())) 87 : { 88 1071 : addAverageElementSizePostprocessor(blocks[i]); 89 3213 : addMaximumFunctorPostprocessor("hs_T_step", blocks[i] + "_T_step", T_ref[i], {blocks[i]}); 90 1071 : addResidualNormPostprocessor(blocks[i], sp_names[i], T_ref[i]); 91 : } 92 : 93 : std::vector<PostprocessorName> pp_names; 94 : std::vector<std::string> descriptions; 95 : std::vector<Real> tolerances; 96 1790 : for (const auto i : make_range(blocks.size())) 97 : { 98 2142 : pp_names.push_back(blocks[i] + "_T_step"); 99 1071 : descriptions.push_back("T step (" + blocks[i] + ")"); 100 3213 : tolerances.push_back(getParam<Real>("T_rel_step_tol")); 101 : } 102 1790 : for (const auto i : make_range(blocks.size())) 103 : { 104 2142 : pp_names.push_back(blocks[i] + "_res"); 105 1071 : descriptions.push_back("residual (" + blocks[i] + ")"); 106 3213 : tolerances.push_back(getParam<Real>("res_tol")); 107 : } 108 719 : addMultiPostprocessorConvergence(pp_names, descriptions, tolerances); 109 719 : } 110 795 : } 111 : 112 : void 113 1071 : HeatStructureBase::addConstantDensitySolidPropertiesMaterial(const UserObjectName & sp_name, 114 : const Real & T_ref, 115 : unsigned int i_region) const 116 : { 117 1071 : const auto blocks = getSubdomainNames(); 118 1071 : const auto region_names = getNames(); 119 : 120 1071 : const std::string class_name = "ADConstantDensityThermalSolidPropertiesMaterial"; 121 1071 : InputParameters params = _factory.getValidParams(class_name); 122 3213 : params.set<std::vector<SubdomainName>>("block") = {blocks[i_region]}; 123 3213 : params.set<std::vector<VariableName>>("temperature") = {HeatConductionModel::TEMPERATURE}; 124 1071 : params.set<UserObjectName>("sp") = sp_name; 125 1071 : params.set<Real>("T_ref") = T_ref; 126 1071 : getTHMProblem().addMaterial( 127 1071 : class_name, genName(name(), class_name, region_names[i_region]), params); 128 2142 : } 129 : 130 : void 131 1071 : HeatStructureBase::addAverageElementSizePostprocessor(const SubdomainName & block) 132 : { 133 1071 : const std::string class_name = "AverageElementSize"; 134 1071 : InputParameters params = _factory.getValidParams(class_name); 135 3213 : params.set<std::vector<SubdomainName>>("block") = {block}; 136 2142 : params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; 137 3213 : params.set<std::vector<OutputName>>("outputs") = {"none"}; 138 1071 : getTHMProblem().addPostprocessor(class_name, block + "_havg", params); 139 2142 : } 140 : 141 : void 142 1071 : HeatStructureBase::addResidualNormPostprocessor(const SubdomainName & block, 143 : const UserObjectName & sp_name, 144 : Real T_ref) 145 : { 146 1071 : const std::string class_name = "NormalizedHeatStructureResidualNorm"; 147 1071 : InputParameters params = _factory.getValidParams(class_name); 148 2142 : params.set<VariableName>("variable") = HeatConductionModel::TEMPERATURE; 149 3213 : params.set<std::vector<SubdomainName>>("block") = {block}; 150 2142 : params.set<MooseEnum>("norm_type") = "l_inf"; 151 1071 : params.set<Real>("T_ref") = T_ref; 152 1071 : params.set<UserObjectName>("solid_properties") = sp_name; 153 3213 : params.set<PostprocessorName>("ref_elem_size") = block + "_havg"; 154 2142 : params.set<ExecFlagEnum>("execute_on") = EXEC_NONLINEAR_CONVERGENCE; 155 3213 : params.set<std::vector<OutputName>>("outputs") = {"none"}; 156 1071 : getTHMProblem().addPostprocessor(class_name, block + "_res", params); 157 2142 : }