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 "INSFVEnthalpyFunctorMaterial.h"
11 : #include "NS.h"
12 : #include "SinglePhaseFluidProperties.h"
13 :
14 : registerMooseObjectRenamed("NavierStokesApp",
15 : INSFVEnthalpyMaterial,
16 : "02/01/2024 00:00",
17 : INSFVEnthalpyFunctorMaterial);
18 : registerMooseObject("NavierStokesApp", INSFVEnthalpyFunctorMaterial);
19 :
20 : InputParameters
21 4890 : INSFVEnthalpyFunctorMaterial::validParams()
22 : {
23 4890 : InputParameters params = FunctorMaterial::validParams();
24 4890 : params.addClassDescription(
25 : "This is the material class used to compute enthalpy for the "
26 : "incompressible/weakly-compressible finite-volume implementation of the Navier-Stokes "
27 : "equations.");
28 4890 : params.addRequiredParam<MooseFunctorName>(NS::density, "The value for the density");
29 9780 : params.addParam<MooseFunctorName>("temperature", "the temperature");
30 4890 : params.addParam<MooseFunctorName>(
31 : NS::cp, NS::cp, "The constant value for the specific heat capacity");
32 4890 : params.addParam<MooseFunctorName>(
33 : NS::enthalpy_density, NS::enthalpy_density, "the name of the (extensive) enthalpy");
34 4890 : params.addParam<MooseFunctorName>(NS::specific_enthalpy,
35 : NS::specific_enthalpy,
36 : "the name of the specific enthalpy, for defining it.");
37 :
38 : // To handle non constant cp
39 9780 : params.addParam<bool>("assumed_constant_cp", true, "Whether to assume cp is constant");
40 4890 : params.addParam<UserObjectName>(
41 : NS::fluid, "Fluid properties, to be used when cp is not constant to compute enthalpy");
42 4890 : params.addParam<MooseFunctorName>(
43 : NS::pressure, "Pressure functor, to be used when cp is not constant to compute enthalpy");
44 9780 : params.addParam<MooseFunctorName>(
45 9780 : NS::specific_enthalpy + "_in",
46 : "Specific enthalpy functor, to be used when cp is not constant to compute the enthalpy, as "
47 : "an alternative to using a 'fp' FluidProperties object");
48 :
49 4890 : return params;
50 0 : }
51 :
52 2667 : INSFVEnthalpyFunctorMaterial::INSFVEnthalpyFunctorMaterial(const InputParameters & parameters)
53 : : FunctorMaterial(parameters),
54 2667 : _assumed_constant_cp(getParam<bool>("assumed_constant_cp")),
55 2667 : _fp(isParamValid(NS::fluid)
56 2667 : ? &UserObjectInterface::getUserObject<SinglePhaseFluidProperties>(NS::fluid)
57 : : nullptr),
58 2667 : _rho(getFunctor<ADReal>(NS::density)),
59 10536 : _temperature(isParamValid("temperature") ? &getFunctor<ADReal>("temperature") : nullptr),
60 2767 : _pressure(isParamValid(NS::pressure) ? &getFunctor<ADReal>(NS::pressure) : nullptr),
61 2667 : _cp(getFunctor<ADReal>(NS::cp)),
62 2667 : _h(isParamValid(NS::specific_enthalpy + "_in")
63 2847 : ? &getFunctor<ADReal>(NS::specific_enthalpy + "_in")
64 2667 : : nullptr)
65 : {
66 : // We have to use a warning because fp is often in the global parameters
67 2667 : if (_assumed_constant_cp && _fp)
68 44 : paramWarning(
69 : "fp", "No need to specify fluid properties if assuming the specific enthalpy is constant");
70 2667 : if (!_assumed_constant_cp && ((!_fp || !_pressure) && !_h))
71 2 : paramError("fp",
72 : "Must specify both fluid properties and pressure or an enthalpy functor if not "
73 : "assuming the specific enthalpy is constant");
74 2665 : if (!_temperature && (_assumed_constant_cp || !_h))
75 0 : paramError("temperature",
76 : "Temperature must be specified if assuming constant specific heat or if not "
77 : "specifying the enthalpy functor");
78 :
79 2665 : if (_assumed_constant_cp)
80 : {
81 : const auto & rho_h =
82 7623 : addFunctorProperty<ADReal>(NS::enthalpy_density,
83 33966398 : [this](const auto & r, const auto & t)
84 33966398 : { return _rho(r, t) * _cp(r, t) * (*_temperature)(r, t); });
85 :
86 7623 : const auto & h = addFunctorProperty<ADReal>(NS::specific_enthalpy,
87 1092198 : [this](const auto & r, const auto & t)
88 1092198 : { return _cp(r, t) * (*_temperature)(r, t); });
89 :
90 7623 : addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
91 3175760 : [this](const auto & r, const auto & t)
92 3175760 : { return _cp(r, t) * (*_temperature).dot(r, t); });
93 :
94 7623 : addFunctorProperty<ADReal>(
95 2574 : "rho_cp_temp", [&rho_h](const auto & r, const auto & t) -> ADReal { return rho_h(r, t); });
96 :
97 7623 : addFunctorProperty<ADReal>("cp_temp",
98 0 : [&h](const auto & r, const auto & t) -> ADReal { return h(r, t); });
99 : }
100 : // We did specify h_in, likely because solving for specific enthalpy
101 124 : else if (_h)
102 : {
103 270 : addFunctorProperty<ADReal>(NS::enthalpy_density,
104 316878 : [this](const auto & r, const auto & t)
105 316878 : { return _rho(r, t) * (*_h)(r, t); });
106 :
107 270 : addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
108 0 : [this](const auto & r, const auto & t) { return _h->dot(r, t); });
109 :
110 : // Note that we don't pick the fluid temperature name
111 270 : addFunctorProperty<ADReal>(NS::T_fluid,
112 4053159 : [this](const auto & r, const auto & t) -> ADReal
113 4053159 : { return _fp->T_from_p_h((*_pressure)(r, t), (*_h)(r, t)); });
114 : }
115 : // We did not specify h, or assume a constant cp, we are solving for temperature but using h(p,T)
116 : else
117 : {
118 102 : addFunctorProperty<ADReal>(
119 : NS::enthalpy_density,
120 552360 : [this](const auto & r, const auto & t)
121 552360 : { return _rho(r, t) * _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t)); });
122 :
123 102 : addFunctorProperty<ADReal>(NS::specific_enthalpy,
124 145800 : [this](const auto & r, const auto & t) {
125 145800 : return _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t));
126 : });
127 :
128 136 : addFunctorProperty<ADReal>(
129 68 : NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
130 145200 : [this](const auto & r, const auto & t)
131 : {
132 : ADReal h, dh_dp, dh_dT;
133 145200 : _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t), h, dh_dp, dh_dT);
134 435600 : return dh_dT * (*_temperature).dot(r, t) + dh_dp * _pressure->dot(r, t);
135 : });
136 : }
137 15742 : }
|