Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed cons2entropy files and implemented entropy2cons for CompressibleEulerMulticomponent1D and CompressibleEulerMulticomponent2D #1767

Merged
merged 14 commits into from
Dec 14, 2023
Merged
78 changes: 72 additions & 6 deletions src/equations/compressible_euler_multicomponent_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ end
# Convert conservative variables to entropy
@inline function cons2entropy(u, equations::CompressibleEulerMulticomponentEquations1D)
@unpack cv, gammas, gas_constants = equations

rho_v1, rho_e = u

rho = density(u, equations)
Expand All @@ -480,21 +481,86 @@ end
s = log(p) - gamma * log(rho) - log(gas_constant)
rho_p = rho / p
T = (rho_e - 0.5 * rho * v_square) / (help1)
entrop_rho = SVector{ncomponents(equations), real(equations)}(gas_constant *
((gamma - s) /
(gamma - 1.0) -
(0.5 * v_square *
rho_p))

entrop_rho = SVector{ncomponents(equations), real(equations)}((cv[i] *
(1 - log(T)) +
gas_constants[i] *
(1 + log(u[i + 2])) -
v1^2 / (2 * T))
for i in eachcomponent(equations))

w1 = gas_constant * v1 * rho_p
w2 = gas_constant * (-1.0 * rho_p)
w2 = gas_constant * (-rho_p)

entrop_other = SVector{2, real(equations)}(w1, w2)

return vcat(entrop_other, entrop_rho)
end

# Convert entropy variables to conservative variables
@inline function entropy2cons(w, equations::CompressibleEulerMulticomponentEquations1D)
@unpack gammas, gas_constants, cv, cp = equations
T = -1 / w[2]
v1 = w[1] * T
cons_rho = SVector{ncomponents(equations), real(equations)}(exp(1 /
gas_constants[i] *
(-cv[i] *
log(-w[2]) -
cp[i] + w[i + 2] -
0.5 * w[1]^2 /
w[2]))
for i in eachcomponent(equations))

rho = zero(cons_rho[1])
help1 = zero(cons_rho[1])
help2 = zero(cons_rho[1])
p = zero(cons_rho[1])
for i in eachcomponent(equations)
rho += cons_rho[i]
help1 += cons_rho[i] * cv[i] * gammas[i]
help2 += cons_rho[i] * cv[i]
p += cons_rho[i] * gas_constants[i] * T
end
u1 = rho * v1
gamma = help1 / help2
u2 = p / (gamma - 1) + 0.5 * rho * v1^2
cons_other = SVector{2, real(equations)}(u1, u2)
return vcat(cons_other, cons_rho)
end

@inline function total_entropy(u, equations::CompressibleEulerMulticomponentEquations1D)
@unpack cv, gammas, gas_constants = equations
rho_v1, rho_e = u
rho = density(u, equations)
T = temperature(u, equations)

total_entropy = zero(u[1])
for i in eachcomponent(equations)
total_entropy -= u[i + 2] * (cv[i] * log(T) - gas_constants[i] * log(u[i + 2]))
end

return total_entropy
end

@inline function temperature(u, equations::CompressibleEulerMulticomponentEquations1D)
@unpack cv, gammas, gas_constants = equations

rho_v1, rho_e = u

rho = density(u, equations)
help1 = zero(rho)

for i in eachcomponent(equations)
help1 += u[i + 2] * cv[i]
end

v1 = rho_v1 / rho
v_square = v1^2
T = (rho_e - 0.5 * rho * v_square) / help1

return T
end

"""
totalgamma(u, equations::CompressibleEulerMulticomponentEquations1D)

Expand Down
80 changes: 74 additions & 6 deletions src/equations/compressible_euler_multicomponent_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -665,22 +665,57 @@ end
s = log(p) - gamma * log(rho) - log(gas_constant)
rho_p = rho / p
T = (rho_e - 0.5 * rho * v_square) / (help1)
entrop_rho = SVector{ncomponents(equations), real(equations)}(gas_constant *
((gamma - s) /
(gamma - 1.0) -
(0.5 * v_square *
rho_p))

entrop_rho = SVector{ncomponents(equations), real(equations)}((cv[i] *
(1 - log(T)) +
gas_constants[i] *
(1 + log(u[i + 3])) -
v_square / (2 * T))
for i in eachcomponent(equations))

w1 = gas_constant * v1 * rho_p
w2 = gas_constant * v2 * rho_p
w3 = gas_constant * rho_p * (-1)
w3 = gas_constant * (-rho_p)

entrop_other = SVector{3, real(equations)}(w1, w2, w3)

return vcat(entrop_other, entrop_rho)
end

# Convert entropy variables to conservative variables
@inline function entropy2cons(w, equations::CompressibleEulerMulticomponentEquations2D)
@unpack gammas, gas_constants, cp, cv = equations
T = -1 / w[3]
v1 = w[1] * T
v2 = w[2] * T
v_squared = v1^2 + v2^2
cons_rho = SVector{ncomponents(equations), real(equations)}(exp((w[i + 3] -
cv[i] *
(1 - log(T)) +
v_squared /
(2 * T)) /
gas_constants[i] -
1)
for i in eachcomponent(equations))

rho = zero(cons_rho[1])
help1 = zero(cons_rho[1])
help2 = zero(cons_rho[1])
p = zero(cons_rho[1])
for i in eachcomponent(equations)
rho += cons_rho[i]
help1 += cons_rho[i] * cv[i] * gammas[i]
help2 += cons_rho[i] * cv[i]
p += cons_rho[i] * gas_constants[i] * T
end
u1 = rho * v1
u2 = rho * v2
gamma = help1 / help2
u3 = p / (gamma - 1) + 0.5 * rho * v_squared
cons_other = SVector{3, real(equations)}(u1, u2, u3)
return vcat(cons_other, cons_rho)
end

# Convert primitive to conservative variables
@inline function prim2cons(prim, equations::CompressibleEulerMulticomponentEquations2D)
@unpack cv, gammas = equations
Expand All @@ -700,6 +735,39 @@ end
return vcat(cons_other, cons_rho)
end

@inline function total_entropy(u, equations::CompressibleEulerMulticomponentEquations2D)
@unpack cv, gammas, gas_constants = equations
rho = density(u, equations)
T = temperature(u, equations)

total_entropy = zero(u[1])
for i in eachcomponent(equations)
total_entropy -= u[i + 3] * (cv[i] * log(T) - gas_constants[i] * log(u[i + 3]))
end

return total_entropy
end

@inline function temperature(u, equations::CompressibleEulerMulticomponentEquations2D)
@unpack cv, gammas, gas_constants = equations

rho_v1, rho_v2, rho_e = u

rho = density(u, equations)
help1 = zero(rho)

for i in eachcomponent(equations)
help1 += u[i + 3] * cv[i]
end

v1 = rho_v1 / rho
v2 = rho_v2 / rho
v_square = v1^2 + v2^2
T = (rho_e - 0.5 * rho * v_square) / help1

return T
end

"""
totalgamma(u, equations::CompressibleEulerMulticomponentEquations2D)

Expand Down
Loading
Loading