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 4859 : INSFVEnthalpyFunctorMaterial::validParams()
22 : {
23 4859 : InputParameters params = FunctorMaterial::validParams();
24 4859 : 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 4859 : params.addRequiredParam<MooseFunctorName>(NS::density, "The value for the density");
29 9718 : params.addRequiredParam<MooseFunctorName>("temperature", "the temperature");
30 4859 : params.addParam<MooseFunctorName>(
31 : NS::cp, NS::cp, "The constant value for the specific heat capacity");
32 4859 : params.addParam<MooseFunctorName>(
33 : NS::enthalpy_density, NS::enthalpy_density, "the name of the (extensive) enthalpy");
34 4859 : params.addParam<MooseFunctorName>(
35 : NS::specific_enthalpy, NS::specific_enthalpy, "the name of the specific enthalpy");
36 :
37 : // To handle non constant cp
38 9718 : params.addParam<bool>("assumed_constant_cp", true, "Whether to assume cp is constant");
39 4859 : params.addParam<UserObjectName>(
40 : NS::fluid, "Fluid properties, to be used when cp is not constant to compute enthalpy");
41 4859 : params.addParam<MooseFunctorName>(
42 : NS::pressure, "Pressure functor, to be used when cp is not constant to compute enthalpy");
43 9718 : params.addParam<MooseFunctorName>(
44 9718 : NS::specific_enthalpy + "_in",
45 : "Specific enthalpy functor, to be used when cp is not constant to compute the enthalpy, as "
46 : "an alternative to using a 'fp' FluidProperties object");
47 :
48 4859 : return params;
49 0 : }
50 :
51 2647 : INSFVEnthalpyFunctorMaterial::INSFVEnthalpyFunctorMaterial(const InputParameters & parameters)
52 : : FunctorMaterial(parameters),
53 2647 : _assumed_constant_cp(getParam<bool>("assumed_constant_cp")),
54 2647 : _fp(isParamValid(NS::fluid)
55 2647 : ? &UserObjectInterface::getUserObject<SinglePhaseFluidProperties>(NS::fluid)
56 : : nullptr),
57 2647 : _rho(getFunctor<ADReal>(NS::density)),
58 5294 : _temperature(getFunctor<ADReal>("temperature")),
59 5362 : _pressure(isParamValid("pressure") ? &getFunctor<ADReal>("pressure") : nullptr),
60 2647 : _cp(getFunctor<ADReal>(NS::cp)),
61 2647 : _h(isParamValid(NS::specific_enthalpy + "_in")
62 2695 : ? &getFunctor<ADReal>(NS::specific_enthalpy + "_in")
63 2647 : : nullptr)
64 : {
65 : // We have to use a warning because fp is often in the global parameters
66 2647 : if (_assumed_constant_cp && _fp)
67 44 : paramWarning(
68 : "fp", "No need to specify fluid properties if assuming the specific enthalpy is constant");
69 2647 : if (!_assumed_constant_cp && ((!_fp || !_pressure) && !_h))
70 2 : paramError("fp",
71 : "Must specify both fluid properties and pressure or an enthalpy functor if not "
72 : "assuming the specific enthalpy is constant");
73 :
74 2645 : if (_assumed_constant_cp)
75 : {
76 : const auto & rho_h =
77 7761 : addFunctorProperty<ADReal>(NS::enthalpy_density,
78 33966398 : [this](const auto & r, const auto & t)
79 33966398 : { return _rho(r, t) * _cp(r, t) * _temperature(r, t); });
80 :
81 7761 : const auto & h = addFunctorProperty<ADReal>(NS::specific_enthalpy,
82 1092198 : [this](const auto & r, const auto & t)
83 1092198 : { return _cp(r, t) * _temperature(r, t); });
84 :
85 7761 : addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
86 3175760 : [this](const auto & r, const auto & t)
87 3175760 : { return _cp(r, t) * _temperature.dot(r, t); });
88 :
89 7761 : addFunctorProperty<ADReal>(
90 2574 : "rho_cp_temp", [&rho_h](const auto & r, const auto & t) -> ADReal { return rho_h(r, t); });
91 :
92 7761 : addFunctorProperty<ADReal>("cp_temp",
93 0 : [&h](const auto & r, const auto & t) -> ADReal { return h(r, t); });
94 : }
95 58 : else if (_h)
96 : {
97 72 : addFunctorProperty<ADReal>(NS::enthalpy_density,
98 1464 : [this](const auto & r, const auto & t)
99 1464 : { return _rho(r, t) * (*_h)(r, t); });
100 :
101 72 : addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
102 0 : [this](const auto & r, const auto & t) { return _h->dot(r, t); });
103 : }
104 : else
105 : {
106 102 : addFunctorProperty<ADReal>(
107 : NS::enthalpy_density,
108 552360 : [this](const auto & r, const auto & t)
109 552360 : { return _rho(r, t) * _fp->h_from_p_T((*_pressure)(r, t), _temperature(r, t)); });
110 :
111 102 : addFunctorProperty<ADReal>(NS::specific_enthalpy,
112 145800 : [this](const auto & r, const auto & t)
113 145800 : { return _fp->h_from_p_T((*_pressure)(r, t), _temperature(r, t)); });
114 :
115 136 : addFunctorProperty<ADReal>(
116 68 : NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
117 145200 : [this](const auto & r, const auto & t)
118 : {
119 : Real h, dh_dp, dh_dT;
120 145200 : _fp->h_from_p_T((*_pressure)(r, t).value(), _temperature(r, t).value(), h, dh_dp, dh_dT);
121 290400 : return dh_dT * _temperature.dot(r, t) + dh_dp * _pressure->dot(r, t);
122 : });
123 : }
124 15730 : }
|