https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ADIncompressibleEnergySPScalarKernel.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
16
19{
22 "Assembles transport equation for the fluid temperature over a 1D flow path segment.");
23 params.addCoupledVar("mass_flow_rate",
24 {},
25 "Mass flow rate in component. Takes a "
26 "scalar variable name");
27 params.addCoupledVar("inlet_temperature",
28 {},
29 "Fluid temperature of nominal inlet segment/component (N-1). Takes a "
30 "scalar variable name");
31 params.addCoupledVar("outlet_temperature",
32 {},
33 "Fluid temperature of nominal outlet segment/component (N+1). Takes a "
34 "scalar variable name");
35 params.addCoupledVar("wall_temperature",
36 {},
37 "Wall temperature adjacent to fluid. Takes a "
38 "scalar variable name");
39 params.addParam<bool>(
40 "is_implicit",
41 true,
42 "Whether an explicit (previous value calculation) or implicit (current value) is used");
43 params.addRequiredParam<MooseFunctorName>("reference_pressure", "system reference pressure [Pa]");
44 params.addRequiredParam<UserObjectName>("fp", "The name of the user object for fluid properties");
45 params.addParam<UserObjectName>("reference_fp",
46 "Liquid-phase fluid properties; see momentum kernel.");
47 params.addRequiredParam<MooseFunctorName>("area", "Segment/Component flow area [m^2]");
48 params.addRequiredParam<MooseFunctorName>("perimeter", "Segment/Component wetted perimeter [m]");
49 params.addRequiredParam<MooseFunctorName>("length", "Segment/Component length [m]");
50 params.addRequiredParam<MooseFunctorName>("heat_transfer_coefficient",
51 "Heat transfer coefficient of the fluid [W/(m^2-K)]");
52 params.addParam<bool>(
53 "use_fluid_node_temp",
54 true,
55 "Whether to use fluid node temperature for wall heat transfer or a segment-averaged value. "
56 "Must match the setting of the coupled ADPipeInnerWallTemperatureScalarKernel so wall and "
57 "fluid exchange the same heat.");
58
59 return params;
60}
61
63 const InputParameters & parameters)
64 : Base(parameters),
65 _fp(this->template getUserObject<SinglePhaseFluidProperties>("fp")),
66 _fp_ref(isParamValid("reference_fp") ? &getUserObjectByName<SinglePhaseFluidProperties>(
67 getParam<UserObjectName>("reference_fp"))
68 : nullptr),
69 _m(ScalarCoupleable::adCoupledScalarValue("mass_flow_rate")),
70 _Tup(ScalarCoupleable::adCoupledScalarValue("inlet_temperature")),
71 _Tdown(ScalarCoupleable::adCoupledScalarValue("outlet_temperature")),
72 _Tw(ScalarCoupleable::adCoupledScalarValue("wall_temperature")),
73 _is_implicit(this->template getParam<bool>("is_implicit")),
74 _Pref(this->template getFunctor<ADReal>("reference_pressure")),
75 _area(this->template getFunctor<ADReal>("area")),
76 _perimeter(this->template getFunctor<ADReal>("perimeter")),
77 _length(this->template getFunctor<ADReal>("length")),
78 _h(this->template getFunctor<ADReal>("heat_transfer_coefficient"))
79{
80}
81
84{
85 ADReal energy_residual = 0;
86 const Moose::PointArg arg = {Point(1, 2, 3)};
87 const int i = 0;
88 const auto state = _is_implicit ? Moose::currentState() : Moose::oldState();
89 // start by getting fluid properties
90 const auto in = 1.0 / 2.0 * (1 - _m[i] / sqrt(_m[i] * _m[i] + 1.0e-08)) * _Tdown[i] +
91 1.0 / 2.0 * (1 + _m[i] / sqrt(_m[i] * _m[i] + 1.0e-08)) * _Tup[i];
92 // Bulk temperature seen by the wall: segment average or node temperature
93 const bool node_bulk = getParam<bool>("use_fluid_node_temp");
94 const auto Tm = node_bulk ? ADReal(Base::_u[i]) : ADReal((Base::_u[i] + in) / 2);
95 const auto P = _Pref(arg, state);
96 const auto rho = _fp.rho_from_p_T(P, Tm);
97 const auto cp = _fp.cp_from_p_T(P, Tm);
98 const auto rho_ref = _fp_ref ? _fp_ref->rho_from_p_T(P, Tm) : rho;
99
100 // Heat transfer to fluid (Dittus-Boelter)
101 const auto q = _h(arg, state) * _perimeter(arg, state) * (_Tw[i] - Tm);
102 // Advection component
103 energy_residual += (_m[i] / 2.0 * (1 - _m[i] / sqrt(_m[i] * _m[i] + 1.0e-08)) * _Tdown[i] -
104 _m[i] / 2.0 * (1 + _m[i] / sqrt(_m[i] * _m[i] + 1.0e-08)) * _Tup[i] +
105 _m[i] * _m[i] / sqrt(_m[i] * _m[i] + 1.0e-08) * Base::_u[i]) /
106 _length(arg, state) / _area(arg, state) / rho_ref;
107 // Wall heat transfer
108 energy_residual -= q / _area(arg, state) / rho / cp;
109
110 return energy_residual;
111}
112
113Real
115{
116 mooseError("Internal error, calling computeQpJacobian in AD class.");
117 return 0.0;
118}
registerMooseObject("ThermalHydraulicsApp", ADIncompressibleEnergySPScalarKernel)
DualNumber< Real, DNDerivativeType, true > ADReal
const double rho
const bool _is_implicit
Property state integration flag.
const ADVariableValue & _Tdown
Coupled temperature of the downstream segment.
const ADVariableValue & _Tup
Coupled temperature of the upstream segment.
const Moose::Functor< ADReal > & _Pref
System reference pressure.
ADIncompressibleEnergySPScalarKernel(const InputParameters &parameters)
const Moose::Functor< ADReal > & _h
Heat transfer coefficient from functor material.
const SinglePhaseFluidProperties & _fp
Fluid properties object.
const SinglePhaseFluidProperties * _fp_ref
Pure liquid fluid properties reference (for draining problems, not for multiphase flow)
const Moose::Functor< ADReal > & _length
Length of the segment.
const ADVariableValue & _Tw
Coupled temperature of the component wall.
const ADVariableValue & _m
Coupled mass flow rate through the segment.
const Moose::Functor< ADReal > & _perimeter
Wetted perimeter of the segment.
const Moose::Functor< ADReal > & _area
Flow area of the segment.
const ADVariableValue & _u
static InputParameters validParams()
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)
void mooseError(Args &&... args) const
Common class for single phase fluid properties.
StateArg oldState()
StateArg currentState()