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 2626 : INSFVEnthalpyFunctorMaterial::validParams()
22 : {
23 2626 : InputParameters params = FunctorMaterial::validParams();
24 2626 : 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 2626 : params.addRequiredParam<MooseFunctorName>(NS::density, "The value for the density");
29 5252 : params.addParam<MooseFunctorName>("temperature", "the temperature");
30 2626 : params.addParam<MooseFunctorName>(
31 : NS::cp, NS::cp, "The constant value for the specific heat capacity");
32 2626 : params.addParam<MooseFunctorName>(
33 : NS::enthalpy_density, NS::enthalpy_density, "the name of the (extensive) enthalpy");
34 2626 : 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 5252 : params.addParam<bool>("assumed_constant_cp", true, "Whether to assume cp is constant");
40 2626 : params.addParam<UserObjectName>(
41 : NS::fluid, "Fluid properties, to be used when cp is not constant to compute enthalpy");
42 2626 : params.addParam<MooseFunctorName>(
43 : NS::pressure, "Pressure functor, to be used when cp is not constant to compute enthalpy");
44 5252 : params.addParam<MooseFunctorName>(
45 5252 : 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 2626 : return params;
50 0 : }
51 :
52 1404 : INSFVEnthalpyFunctorMaterial::INSFVEnthalpyFunctorMaterial(const InputParameters & parameters)
53 : : FunctorMaterial(parameters),
54 1404 : _assumed_constant_cp(getParam<bool>("assumed_constant_cp")),
55 1404 : _fp(isParamValid(NS::fluid)
56 1404 : ? &UserObjectInterface::getUserObject<SinglePhaseFluidProperties>(NS::fluid)
57 : : nullptr),
58 1404 : _rho(getFunctor<ADReal>(NS::density)),
59 5556 : _temperature(isParamValid("temperature") ? &getFunctor<ADReal>("temperature") : nullptr),
60 1462 : _pressure(isParamValid(NS::pressure) ? &getFunctor<ADReal>(NS::pressure) : nullptr),
61 1404 : _cp(getFunctor<ADReal>(NS::cp)),
62 1404 : _h(isParamValid(NS::specific_enthalpy + "_in")
63 1496 : ? &getFunctor<ADReal>(NS::specific_enthalpy + "_in")
64 1404 : : nullptr)
65 : {
66 : // We have to use a warning because fp is often in the global parameters
67 1404 : if (_assumed_constant_cp && _fp)
68 20 : paramWarning(
69 : "fp", "No need to specify fluid properties if assuming the specific enthalpy is constant");
70 1404 : 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 1402 : 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 1402 : if (_assumed_constant_cp)
80 : {
81 : const auto & rho_h =
82 3984 : addFunctorProperty<ADReal>(NS::enthalpy_density,
83 23414698 : [this](const auto & r, const auto & t)
84 23414698 : { return _rho(r, t) * _cp(r, t) * (*_temperature)(r, t); });
85 :
86 3984 : const auto & h = addFunctorProperty<ADReal>(NS::specific_enthalpy,
87 833912 : [this](const auto & r, const auto & t)
88 833912 : { return _cp(r, t) * (*_temperature)(r, t); });
89 :
90 3984 : addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
91 2272850 : [this](const auto & r, const auto & t)
92 2272850 : { return _cp(r, t) * (*_temperature).dot(r, t); });
93 :
94 3984 : addFunctorProperty<ADReal>(
95 1716 : "rho_cp_temp", [&rho_h](const auto & r, const auto & t) -> ADReal { return rho_h(r, t); });
96 :
97 3984 : 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 74 : else if (_h)
102 : {
103 138 : addFunctorProperty<ADReal>(NS::enthalpy_density,
104 211496 : [this](const auto & r, const auto & t)
105 211496 : { return _rho(r, t) * (*_h)(r, t); });
106 :
107 138 : 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 138 : addFunctorProperty<ADReal>(NS::T_fluid,
112 2702106 : [this](const auto & r, const auto & t) -> ADReal
113 2702106 : { 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 84 : addFunctorProperty<ADReal>(
119 : NS::enthalpy_density,
120 739220 : [this](const auto & r, const auto & t)
121 739220 : { return _rho(r, t) * _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t)); });
122 :
123 84 : addFunctorProperty<ADReal>(NS::specific_enthalpy,
124 194900 : [this](const auto & r, const auto & t) {
125 194900 : return _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t));
126 : });
127 :
128 112 : addFunctorProperty<ADReal>(
129 56 : NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
130 194400 : [this](const auto & r, const auto & t)
131 : {
132 : ADReal h, dh_dp, dh_dT;
133 194400 : _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t), h, dh_dp, dh_dT);
134 583200 : return dh_dT * (*_temperature).dot(r, t) + dh_dp * _pressure->dot(r, t);
135 : });
136 : }
137 8264 : }
|