https://mooseframework.inl.gov
ADWallFrictionColebrookWhiteMaterial.C
Go to the documentation of this file.
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"
12 #include "Numerics.h"
13 #include <cmath>
14 
16 
19 {
21  params.addClassDescription(
22  "Computes the Darcy friction factor using the Colebrook-White correlation.");
23  params.addRequiredParam<MaterialPropertyName>("rho", "Density");
24  params.addRequiredParam<MaterialPropertyName>("vel", "x-component of the velocity");
25  params.addRequiredParam<MaterialPropertyName>("D_h", "hydraulic diameter");
26 
27  params.addRequiredParam<MaterialPropertyName>("f_D", "Darcy friction factor material property");
28  params.addRequiredParam<MaterialPropertyName>("mu", "Dynamic viscosity material property");
29 
30  params.addParam<Real>("roughness", 0, "Surface roughness");
31  params.declareControllable("roughness");
32 
33  params.addParam<Real>("rtol", 1e-14, "Relative tolerance for implicit solve.");
34  params.addParam<unsigned int>("max_iterations", 20, "Max iterations for iterative solve.");
35  MooseEnum max_its_behavior{"error warn accept", "error"};
36  params.addParam<MooseEnum>("max_iterations_behavior",
37  max_its_behavior,
38  "Whether to error, warn or accept when max iterations is reached");
39  return params;
40 }
41 
43  const InputParameters & parameters)
44  : Material(parameters),
45  _f_D_name(getParam<MaterialPropertyName>("f_D")),
46  _f_D(declareADProperty<Real>(_f_D_name)),
47 
48  _mu(getADMaterialProperty<Real>("mu")),
49  _rho(getADMaterialProperty<Real>("rho")),
50  _vel(getADMaterialProperty<Real>("vel")),
51  _D_h(getADMaterialProperty<Real>("D_h")),
52  _roughness(getParam<Real>("roughness")),
53  _max_its(getParam<unsigned int>("max_iterations")),
54  _max_its_behavior(getParam<MooseEnum>("max_iterations_behavior")),
55  _tol(getParam<Real>("rtol"))
56 {
57  if (_tol < 0. || _tol >= 1.)
58  mooseError("Colebrook-White friction factor relative tolerance must be between 0 and 1");
59 }
60 
61 void
63 {
65  if (Re < 4000.)
66  {
67  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  ADReal & f_D = _f_D[_qp];
74  ADReal f_D_old = 0;
75  f_D = 0.01; // initial guess
76 
77  unsigned int it = 0;
78  for (; it < _max_its; ++it)
79  {
80  f_D_old = f_D;
81  f_D = pow(-2. * log10(_roughness / (3.7 * _D_h[_qp]) + 2.51 / (Re * sqrt(f_D))), -2.);
82  if (abs(f_D - f_D_old) / f_D < _tol)
83  break;
84  }
85 
86  if (it == _max_its)
87  {
88  if (_max_its_behavior == "error")
89  mooseError("Colebrook-White friction factor maximum iterations reached: ", _max_its, ".");
90  else if (_max_its_behavior == "warn")
91  mooseDoOnce(mooseWarning(
92  "Colebrook-White friction factor maximum iterations reached: ", _max_its, "."));
93  }
94 }
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
const ADMaterialProperty< Real > & _rho
Density of the phase.
const unsigned int _max_its
max iterations for iterative solve
const Real & _roughness
Roughness of the surface.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const ADMaterialProperty< Real > & _D_h
Hydraulic diameter.
auto Reynolds(const T1 &volume_fraction, const T2 &rho, const T3 &vel, const T4 &D_h, const T5 &mu)
Compute Reynolds number.
Definition: Numerics.h:118
Computes drag coefficient using the Colebrook-White formula for the Darcy friction factor...
void addRequiredParam(const std::string &name, const std::string &doc_string)
unsigned int _qp
const ADMaterialProperty< Real > & _mu
Dynamic viscosity.
static InputParameters validParams()
const double Re
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
ADWallFrictionColebrookWhiteMaterial(const InputParameters &parameters)
const ADMaterialProperty< Real > & _vel
Velocity (x-component)
void mooseWarning(Args &&... args) const
const Real _tol
Tolerance for implicit solve.
MooseEnum _max_its_behavior
Whether to error, warn or accept on reaching max its.
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
registerMooseObject("ThermalHydraulicsApp", ADWallFrictionColebrookWhiteMaterial)
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
void ErrorVector unsigned int