https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FlowModelGasMixUtils.h
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
10#pragma once
11
14#include "THMIndicesGasMix.h"
15
17
19{
20
27template <bool is_ad>
28std::vector<GenericReal<is_ad>>
31{
32 const auto & xirhoA = U[THMGasMix1D::XIRHOA];
33 const auto & rhoA = U[THMGasMix1D::RHOA];
34 const auto & rhouA = U[THMGasMix1D::RHOUA];
35 const auto & rhoEA = U[THMGasMix1D::RHOEA];
36 const auto & A = U[THMGasMix1D::AREA];
37
38 const auto xi = xirhoA / rhoA;
39 const auto rho = rhoA / A;
40 const auto vel = rhouA / rhoA;
41 const auto v = 1.0 / rho;
42 const auto e = rhoEA / rhoA - 0.5 * vel * vel;
43 const auto p = fp.p_from_v_e(v, e, {xi});
44 const auto T = fp.T_from_v_e(v, e, {xi});
45
46 std::vector<GenericReal<is_ad>> W(THMGasMix1D::N_PRIM_VARS);
49 W[THMGasMix1D::VELOCITY] = vel;
51
52 return W;
53}
54
62template <bool is_ad>
63std::vector<GenericReal<is_ad>>
65 const GenericReal<is_ad> & A,
67{
68 const auto & xi = W[THMGasMix1D::MASS_FRACTION];
69 const auto & p = W[THMGasMix1D::PRESSURE];
70 const auto & T = W[THMGasMix1D::TEMPERATURE];
71 const auto & vel = W[THMGasMix1D::VELOCITY];
72
73 const auto rho = fp.rho_from_p_T(p, T, {xi});
74 const auto rhoA = rho * A;
75 const auto e = fp.e_from_p_rho(p, rho, {xi});
76 const auto E = e + 0.5 * vel * vel;
77
78 std::vector<GenericReal<is_ad>> U(THMGasMix1D::N_FLUX_INPUTS);
79 U[THMGasMix1D::XIRHOA] = xi * rhoA;
80 U[THMGasMix1D::RHOA] = rhoA;
81 U[THMGasMix1D::RHOUA] = rhoA * vel;
82 U[THMGasMix1D::RHOEA] = rhoA * E;
84
85 return U;
86}
87
95template <bool is_ad>
96std::vector<GenericReal<is_ad>>
98 const GenericReal<is_ad> & A,
100{
101 const auto & xi = W[THMGasMix1D::MASS_FRACTION];
102 const auto & p = W[THMGasMix1D::PRESSURE];
103 const auto & T = W[THMGasMix1D::TEMPERATURE];
104 const auto & vel = W[THMGasMix1D::VELOCITY];
105
106 const auto rho = fp.rho_from_p_T(p, T, {xi});
107 const auto e = fp.e_from_p_rho(p, rho, {xi});
108 const auto E = e + 0.5 * vel * vel;
109
110 std::vector<ADReal> F(THMGasMix1D::N_FLUX_OUTPUTS, 0.0);
111 F[THMGasMix1D::SPECIES] = xi * rho * vel * A;
112 F[THMGasMix1D::MASS] = rho * vel * A;
113 F[THMGasMix1D::MOMENTUM] = (rho * vel * vel + p) * A;
114 F[THMGasMix1D::ENERGY] = vel * (rho * E + p) * A;
115
116 return F;
117}
118
126template <bool is_ad>
127std::vector<GenericReal<is_ad>>
129 const std::vector<MooseVariable *> & U_vars,
130 bool is_implicit)
131{
132 mooseAssert(elem, "The supplied element is a nullptr.");
133
134 std::vector<GenericReal<is_ad>> U(THMGasMix1D::N_FLUX_INPUTS, 0.0);
135
136 if (is_implicit)
137 {
138 for (const auto i : make_range(THMGasMix1D::N_FLUX_INPUTS))
139 {
140 mooseAssert(U_vars[i], "The supplied variable is a nullptr.");
141 U[i] = U_vars[i]->getElementalValue(elem);
142 }
143
144 std::vector<dof_id_type> dof_indices;
145
146 const std::vector<unsigned int> ind = {
148 for (const auto j : index_range(ind))
149 {
150 const auto i = ind[j];
151 U_vars[i]->dofMap().dof_indices(elem, dof_indices, U_vars[i]->number());
152 Moose::derivInsert(U[i].derivatives(), dof_indices[0], 1.0);
153 }
154 }
155 else
156 {
157 for (const auto i : make_range(THMGasMix1D::N_FLUX_INPUTS))
158 U[i] = U_vars[i]->getElementalValueOld(elem);
159 }
160
161 return U;
162}
163
164template <bool is_ad>
168{
169 mooseAssert(fp.getNumberOfSecondaryVapors() == 1,
170 "This function assumes there is a single secondary fluid.");
171 const SinglePhaseFluidProperties & fp_primary = fp.getPrimaryFluidProperties();
172 const SinglePhaseFluidProperties & fp_secondary = fp.getSecondaryFluidProperties();
173
174 const GenericReal<is_ad> xi_primary = 1 - xi_secondary;
175
176 const GenericReal<is_ad> moles_primary = xi_primary / fp_primary.molarMass();
177 const GenericReal<is_ad> moles_secondary = xi_secondary / fp_secondary.molarMass();
178
179 return moles_secondary / (moles_primary + moles_secondary);
180}
181}
const Real p
const double rho
const double T
const double v
Moose::GenericType< Real, is_ad > GenericReal
Point xi
Common class for single phase fluid properties.
virtual Real molarMass() const
Molar mass [kg/mol].
Base class for fluid properties of vapor mixtures.
std::vector< GenericReal< is_ad > > getElementalSolutionVector(const Elem *elem, const std::vector< MooseVariable * > &U_vars, bool is_implicit)
Gets the elemental conservative solution vector.
std::vector< GenericReal< is_ad > > computeConservativeSolution(const std::vector< GenericReal< is_ad > > &W, const GenericReal< is_ad > &A, const VaporMixtureFluidProperties &fp)
Computes the conservative solution vector from the primitive solution vector.
GenericReal< is_ad > computeSecondaryMoleFraction(const GenericReal< is_ad > &xi_secondary, const VaporMixtureFluidProperties &fp)
std::vector< GenericReal< is_ad > > computePrimitiveSolution(const std::vector< GenericReal< is_ad > > &U, const VaporMixtureFluidProperties &fp)
Computes the primitive solution vector from the conservative solution vector.
std::vector< GenericReal< is_ad > > computeFluxFromPrimitive(const std::vector< GenericReal< is_ad > > &W, const GenericReal< is_ad > &A, const VaporMixtureFluidProperties &fp)
Computes the numerical flux vector from the primitive solution vector.
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N > > &derivs, libMesh::dof_id_type index, Real value)
static const unsigned int N_FLUX_OUTPUTS
Number of numerical flux function outputs.
static const unsigned int N_FLUX_INPUTS
Number of numerical flux function inputs.
static const unsigned int N_PRIM_VARS