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 "ADRealForward.h" 11 : #include "ADWallFrictionColebrookWhiteMaterial.h" 12 : #include "Numerics.h" 13 : #include <cmath> 14 : 15 : registerMooseObject("ThermalHydraulicsApp", ADWallFrictionColebrookWhiteMaterial); 16 : 17 : InputParameters 18 105 : ADWallFrictionColebrookWhiteMaterial::validParams() 19 : { 20 105 : InputParameters params = Material::validParams(); 21 105 : params.addClassDescription( 22 : "Computes the Darcy friction factor using the Colebrook-White correlation."); 23 210 : params.addRequiredParam<MaterialPropertyName>("rho", "Density"); 24 210 : params.addRequiredParam<MaterialPropertyName>("vel", "x-component of the velocity"); 25 210 : params.addRequiredParam<MaterialPropertyName>("D_h", "hydraulic diameter"); 26 : 27 210 : params.addRequiredParam<MaterialPropertyName>("f_D", "Darcy friction factor material property"); 28 210 : params.addRequiredParam<MaterialPropertyName>("mu", "Dynamic viscosity material property"); 29 : 30 210 : params.addParam<Real>("roughness", 0, "Surface roughness"); 31 210 : params.declareControllable("roughness"); 32 : 33 210 : params.addParam<Real>("rtol", 1e-14, "Relative tolerance for implicit solve."); 34 210 : params.addParam<unsigned int>("max_iterations", 20, "Max iterations for iterative solve."); 35 210 : MooseEnum max_its_behavior{"error warn accept", "error"}; 36 210 : params.addParam<MooseEnum>("max_iterations_behavior", 37 : max_its_behavior, 38 : "Whether to error, warn or accept when max iterations is reached"); 39 105 : return params; 40 105 : } 41 : 42 83 : ADWallFrictionColebrookWhiteMaterial::ADWallFrictionColebrookWhiteMaterial( 43 83 : const InputParameters & parameters) 44 : : Material(parameters), 45 166 : _f_D_name(getParam<MaterialPropertyName>("f_D")), 46 83 : _f_D(declareADProperty<Real>(_f_D_name)), 47 : 48 166 : _mu(getADMaterialProperty<Real>("mu")), 49 166 : _rho(getADMaterialProperty<Real>("rho")), 50 166 : _vel(getADMaterialProperty<Real>("vel")), 51 166 : _D_h(getADMaterialProperty<Real>("D_h")), 52 166 : _roughness(getParam<Real>("roughness")), 53 166 : _max_its(getParam<unsigned int>("max_iterations")), 54 166 : _max_its_behavior(getParam<MooseEnum>("max_iterations_behavior")), 55 249 : _tol(getParam<Real>("rtol")) 56 : { 57 83 : if (_tol < 0. || _tol >= 1.) 58 2 : mooseError("Colebrook-White friction factor relative tolerance must be between 0 and 1"); 59 81 : } 60 : 61 : void 62 17 : ADWallFrictionColebrookWhiteMaterial::computeQpProperties() 63 : { 64 17 : ADReal Re = THM::Reynolds(1, _rho[_qp], _vel[_qp], _D_h[_qp], _mu[_qp]); 65 17 : if (Re < 4000.) 66 : { 67 2 : mooseDoOnce(mooseWarning("Calculated Reynolds number below 4000 (", 68 : Re, 69 : "), consider using different friction factor")); 70 : } 71 : 72 : // Colebrook-white equation has implicit formulation must use iteration 73 15 : ADReal & f_D = _f_D[_qp]; 74 15 : ADReal f_D_old = 0; 75 15 : f_D = 0.01; // initial guess 76 : 77 : unsigned int it = 0; 78 100 : for (; it < _max_its; ++it) 79 : { 80 90 : f_D_old = f_D; 81 540 : f_D = pow(-2. * log10(_roughness / (3.7 * _D_h[_qp]) + 2.51 / (Re * sqrt(f_D))), -2.); 82 180 : if (abs(f_D - f_D_old) / f_D < _tol) 83 : break; 84 : } 85 : 86 15 : if (it == _max_its) 87 : { 88 10 : if (_max_its_behavior == "error") 89 2 : mooseError("Colebrook-White friction factor maximum iterations reached: ", _max_its, "."); 90 8 : else if (_max_its_behavior == "warn") 91 2 : mooseDoOnce(mooseWarning( 92 : "Colebrook-White friction factor maximum iterations reached: ", _max_its, ".")); 93 : } 94 11 : }