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