Skip to content

Commit

Permalink
add the methods I actually needed; bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-fleming committed May 29, 2024
1 parent ea01a94 commit 0105feb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ShockwaveProperties"
uuid = "77d2bf28-a3e9-4b9c-9fcf-b85f74cc8a50"
authors = ["Alex Fleming <[email protected]> and contributors"]
version = "0.1.6"
version = "0.1.7"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
24 changes: 21 additions & 3 deletions src/cpg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,14 @@ pressure(ρ::Density, T::Temperature; gas::CaloricallyPerfectGas) = ρ * gas.R *

"""
pressure(ρe; gas::CaloricallyPerfectGas)
pressure(ρ, ρv, ρE; gas::CaloricallyPerfectGas)
Compute the pressure in a calorically perfect gas from its static internal energy density.
"""
pressure(ρe; gas::CaloricallyPerfectGas) = (gas.γ - 1) * Quantity(ρe, _units_ρE)
pressure(ρe::EnergyDensity; gas::CaloricallyPerfectGas) = (gas.γ - 1) * ρe
function pressure(ρ, ρv::AbstractVector, ρE; gas::CaloricallyPerfectGas)
return pressure(static_internal_energy_density(ρ, ρv, ρE); gas)
end

"""
pressure(state; gas::CaloricallyPerfectGas)
Expand Down Expand Up @@ -334,15 +338,29 @@ end
speed_of_sound::Density, P::Pressure; gas::CaloricallyPerfectGas) = sqrt(gas.γ * P / ρ)

"""
speed_of_sound(state::Union{ConservedState, PrimitiveState}; gas::CaloricallyPerfectGas)
speed_of_sound(ρ, ρv, ρE; gas::CaloricallyPerfectGas)
Compute the speed of sound from conserved state properties.
"""
function speed_of_sound(ρ, ρv::AbstractVector, ρE; gas::CaloricallyPerfectGas)
return speed_of_sound(ρ, pressure(ρ, ρv, ρE; gas); gas)
end

"""
speed_of_sound(state; gas::CaloricallyPerfectGas)
Compute the speed of sound in a gas at a given state.
*We assume that the gas is a non-dispersive medium.*
"""
function speed_of_sound(state; gas::CaloricallyPerfectGas)
return speed_of_sound(temperature(state; gas); gas)
function speed_of_sound(s::PrimitiveProps; gas::CaloricallyPerfectGas)
return speed_of_sound(temperature(s; gas); gas)
end

function speed_of_sound(u::ConservedProps; gas::CaloricallyPerfectGas)
return speed_of_sound(density(u), pressure(u; gas); gas)
end


## CONVERT PROPERTY REPRESENTATIONS

"""
Expand Down
23 changes: 22 additions & 1 deletion test/test_property_correctness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ using Unitful
(v1, v2) = test_items[i]
@test pressure(v1; gas = DRY_AIR) pressure(v2; gas = DRY_AIR)
@test temperature(v1; gas = DRY_AIR) temperature(v2; gas = DRY_AIR)
@test all(momentum_density(v1; gas=DRY_AIR) .≈ momentum_density(v2; gas=DRY_AIR))
@test all(
momentum_density(v1; gas = DRY_AIR) .≈ momentum_density(v2; gas = DRY_AIR),
)
@test all(velocity(v1; gas = DRY_AIR) .≈ velocity(v2; gas = DRY_AIR))
@test (
specific_internal_energy(v1; gas = DRY_AIR)
Expand Down Expand Up @@ -114,4 +116,23 @@ end
# F(u_l)⋅n̂ - F(u_r)⋅n̂ = 0 ⟹ F(u_l)⋅n̂ = F(u_r)⋅n̂
@test all(F(u_L) * n .≈ F(u_R) * n)
end
end

@testset "Speed of Sound" begin
gas = DRY_AIR
s = PrimitiveProps(1.225, [2.0, 0.0], 300.0)
u = ConservedProps(s; gas)

a_s = speed_of_sound(s; gas)
a_u = speed_of_sound(u; gas)

a_s_pressure = speed_of_sound(density(s), pressure(s; gas); gas)
a_u_pressure = speed_of_sound(density(u), pressure(u; gas); gas)

a_s_ie = speed_of_sound(density(s), momentum_density(s; gas), total_internal_energy_density(s; gas); gas)
a_u_ie = speed_of_sound(density(u), momentum_density(u), total_internal_energy_density(u); gas)

@test a_s a_u
@test a_s_pressure a_u_pressure
@test a_s_ie a_u_ie
end

0 comments on commit 0105feb

Please sign in to comment.