https://mooseframework.inl.gov
Loading...
Searching...
No Matches
IncompressibleEnergySPScalarKernel.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
11
12#include "ScalarCoupleable.h"
14
17
18template <bool is_ad>
21{
23 params.addClassDescription("Implements a generic energy solve over a 1D flow path segment.");
24 params.addCoupledVar("mass_flow_rate",
25 {},
26 "Mass flow rate in component. Takes a "
27 "scalar variable name");
28 params.addCoupledVar("inlet_temperature",
29 {},
30 "Fluid temperature of nominal inlet segment/component (N-1). Takes a "
31 "scalar variable name");
32 params.addCoupledVar("outlet_temperature",
33 {},
34 "Fluid temperature of nominal outlet segment/component (N+1). Takes a "
35 "scalar variable name");
36 params.addCoupledVar("wall_temperature",
37 {},
38 "Wall temperature adjacent to fluid. Takes a "
39 "scalar variable name");
40 params.addParam<bool>(
41 "is_implicit",
42 false,
43 "Whether an explicit (previous value calculation) or implicit (current value) is used");
44 params.addRequiredParam<MooseFunctorName>("reference_pressure", "system reference pressure [Pa]");
45 params.addRequiredParam<UserObjectName>("fp", "The name of the user object for fluid properties");
46 params.addRequiredParam<MooseFunctorName>("area", "Segment/Component flow area [m^2]");
47 params.addRequiredParam<MooseFunctorName>("perimeter", "Segment/Component wetted perimeter [m]");
48 params.addRequiredParam<MooseFunctorName>("length", "Segment/Component length [m]");
49
50 return params;
51}
52
53template <bool is_ad>
55 const InputParameters & parameters)
56 : Base(parameters),
57 _fp(this->template getUserObject<SinglePhaseFluidProperties>("fp")),
58 _m(ScalarCoupleable::coupledGenericScalarValue<is_ad>("mass_flow_rate")),
59 _Tup(ScalarCoupleable::coupledGenericScalarValue<is_ad>("inlet_temperature")),
60 _Tdown(ScalarCoupleable::coupledGenericScalarValue<is_ad>("outlet_temperature")),
61 _Tw(ScalarCoupleable::coupledGenericScalarValue<is_ad>("wall_temperature")),
62 _is_implicit(this->template getParam<bool>("is_implicit")),
63 _Pref(this->template getFunctor<GenericReal<is_ad>>("reference_pressure")),
64 _area(this->template getFunctor<GenericReal<is_ad>>("area")),
65 _perimeter(this->template getFunctor<GenericReal<is_ad>>("perimeter")),
66 _length(this->template getFunctor<GenericReal<is_ad>>("length"))
67{
68}
69
70template <bool is_ad>
73{
74 GenericReal<is_ad> energy_residual = 0;
75 const Moose::ElemArg qp = Moose::ElemArg();
76 const int i = 0;
77 const auto state = _is_implicit ? Moose::currentState() : Moose::oldState();
78 // start by getting fluid properties
79 const auto in = 1.0 / 2.0 * (1 - abs(_m[i]) / _m[i]) * _Tdown[i] +
80 1.0 / 2.0 * (1 + abs(_m[i]) / _m[i]) * _Tup[i];
81 const auto mu = _fp.mu_from_p_T(_Pref(qp, state), (Base::_u[i] + in) / 2);
82 const auto rho = _fp.rho_from_p_T(_Pref(qp, state), (Base::_u[i] + in) / 2);
83 const auto cp = _fp.cp_from_p_T(_Pref(qp, state), (Base::_u[i] + in) / 2);
84 const auto k = _fp.k_from_p_T(_Pref(qp, state), (Base::_u[i] + in) / 2);
85
86 // Compute HTC quantities
87 const auto Dh = 4.0 * _area(qp, state) / _perimeter(qp, state);
88 const auto G = abs(_m[i]) / _area(qp, state);
89 const auto Re = G * Dh / mu;
90 const auto Pr = mu * cp / k;
91 // Heat transfer to fluid (Dittus-Boelter)
92 const auto h = 0.023 * pow(Re, 0.8) * pow(Pr, 0.4) * k / Dh;
93 const auto q = h * _perimeter(qp, state) / 2.0 * (2.0 * _Tw[i] - Base::_u[i] - in);
94 // Advection component
95 energy_residual += (_m[i] / 2.0 * (1 - abs(_m[i]) / _m[i]) * _Tdown[i] -
96 _m[i] / 2.0 * (1 + abs(_m[i]) / _m[i]) * _Tup[i] + abs(_m[i]) * Base::_u[i]) /
97 _length(qp, state) / _area(qp, state) / rho;
98 // Wall heat transfer
99 energy_residual -= q / _area(qp, state) / rho / cp;
100
101 return energy_residual;
102}
103
104template <bool is_ad>
105Real
107{
108 if constexpr (!is_ad)
109 {
110 Real energy_jacob = 0;
111 const Moose::ElemArg qp = Moose::ElemArg();
112 const int i = 0;
113 const auto state = _is_implicit ? Moose::currentState() : Moose::oldState();
114 // start by getting fluid properties
115 const auto in = 1.0 / 2.0 * (1 - abs(_m[i]) / _m[i]) * _Tdown[i] +
116 1.0 / 2.0 * (1 + abs(_m[i]) / _m[i]) * _Tup[i];
117 const auto mu = _fp.mu_from_p_T(_Pref(qp, state), (Base::_u[i] + in) / 2);
118 const auto rho = _fp.rho_from_p_T(_Pref(qp, state), (Base::_u[i] + in) / 2);
119 const auto cp = _fp.cp_from_p_T(_Pref(qp, state), (Base::_u[i] + in) / 2);
120 const auto k = _fp.k_from_p_T(_Pref(qp, state), (Base::_u[i] + in) / 2);
121
122 // Decide flow regime for HTC
123 const auto Dh = 4.0 * _area(qp, state) / _perimeter(qp, state);
124 const auto G = abs(_m[i]) / _area(qp, state);
125 const auto Re = G * Dh / mu;
126 const auto Pr = mu * cp / k;
127 // Heat transfer to fluid (Dittus-Boelter)
128 const auto h = 0.023 * pow(Re, 0.8) * pow(Pr, 0.4) * k / Dh;
129 const auto q = -h * _perimeter(qp, state) / 2.0;
130 // Advection component
131 energy_jacob += abs(_m[i]) / _length(qp, state) / _area(qp, state) / rho;
132 // Wall heat transfer
133 energy_jacob -= q / _area(qp, state) / rho / cp;
134
135 return energy_jacob;
136 }
137 else
138 {
139 mooseError("computeQpJacobian() should not be called in AD mode");
140 return 0;
141 }
142}
143
144template <>
145Real
147{
148 mooseError("Internal error, calling computeQpJacobian in AD class.");
149 return 0.0;
150}
151
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const double mu
const double Re
const double rho
registerMooseObject("ThermalHydraulicsApp", IncompressibleEnergySPScalarKernel)
void mooseError(Args &&... args)
Moose::GenericType< Real, is_ad > GenericReal
static InputParameters validParams()
Path-integrated incompressible energy kernel.
IncompressibleEnergySPScalarKernelTempl(const InputParameters &parameters)
virtual GenericReal< is_ad > computeQpResidual() override
typename std::conditional< is_ad, ADScalarKernel, ScalarKernel >::type Base
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
Common class for single phase fluid properties.
StateArg oldState()
StateArg currentState()