Quick Start

This guide provides a quick introduction to CompAir.jl with basic usage patterns and simple examples.

Loading the Package

using CompAir

Basic Concepts

CompAir.jl provides functions for analyzing compressible flow phenomena. Most functions follow consistent naming conventions and parameter patterns:

  • Mach number: Denoted as M or M1, M2 for upstream/downstream conditions
  • Heat capacity ratio: gamma (default: 1.4 for air)
  • Angles: Specified in degrees
  • Ratios: Property ratios like pressure, density, temperature

Isentropic Flow Relations

For a flow at Mach 2.0, calculate the stagnation property ratios:

M = 2.0

# Stagnation to static ratios
T0_T = t0_over_t(M)        # Temperature ratio
p0_p = p0_over_p(M)        # Pressure ratio  
rho0_rho = rho0_over_rho(M) # Density ratio

println("Isentropic Relations at M = $M:")
println("T₀/T = $(round(T0_T, digits=3))")
println("p₀/p = $(round(p0_p, digits=3))")
println("ρ₀/ρ = $(round(rho0_rho, digits=3))")

Output:

Isentropic Relations at M = 2.0:
T₀/T = 1.8
p₀/p = 7.824
ρ₀/ρ = 4.347

Normal Shock Analysis

Analyze a normal shock wave at Mach 3.0:

M1 = 3.0

# Complete normal shock analysis
M2, rho_ratio, p_ratio, p0_ratio = solve_normal(M1)

println("Normal Shock at M₁ = $M1:")
println("M₂ = $(round(M2, digits=3))")
println("ρ₂/ρ₁ = $(round(rho_ratio, digits=3))")
println("p₂/p₁ = $(round(p_ratio, digits=3))")
println("p₀₂/p₀₁ = $(round(p0_ratio, digits=3))")

Output:

Normal Shock at M₁ = 3.0:
M₂ = 0.475
ρ₂/ρ₁ = 3.857
p₂/p₁ = 10.333
p₀₂/p₀₁ = 0.328

Oblique Shock Analysis

Calculate oblique shock properties for Mach 2.5 flow over a 15° wedge:

M1 = 2.5
theta = 15.0  # wedge angle in degrees

# Solve oblique shock
M2, rho_ratio, p_ratio, p0_ratio, beta = solve_oblique(M1, theta)

println("Oblique Shock Analysis:")
println("M₁ = $M1, θ = $(theta)°")
println("Shock angle β = $(round(beta, digits=1))°")
println("M₂ = $(round(M2, digits=3))")
println("ρ₂/ρ₁ = $(round(rho_ratio, digits=3))")
println("p₂/p₁ = $(round(p_ratio, digits=3))")

Output:

Oblique Shock Analysis:
M₁ = 2.5, θ = 15.0°
Shock angle β = 36.9°
M₂ = 1.874
ρ₂/ρ₁ = 1.867
p₂/p₁ = 2.468

Prandtl-Meyer Expansion

Calculate expansion wave properties for Mach 2.0 flow turning through 20°:

M1 = 2.0
theta = 20.0  # turning angle in degrees

# Calculate downstream Mach number and pressure ratio
M2 = expand_mach2(M1, theta)
p_ratio = expand_p2(M1, theta)

println("Prandtl-Meyer Expansion:")
println("M₁ = $M1 → M₂ = $(round(M2, digits=3))")
println("p₁/p₂ = $(round(p_ratio, digits=3))")

Output:

Prandtl-Meyer Expansion:
M₁ = 2.0 → M₂ = 2.831
p₁/p₂ = 0.275

Atmospheric Properties

Calculate atmospheric conditions at different altitudes using the US Standard Atmosphere 1976:

# Calculate properties at sea level and 11 km altitude
altitudes = [0.0, 11.0]  # km

for alt in altitudes
    density, pressure, temperature, asound, viscosity = atmos1976_at(alt)
    
    println("Altitude: $(alt) km")
    println("  Density: $(round(density, digits=3)) kg/m³")
    println("  Pressure: $(round(pressure/1000, digits=1)) kPa")
    println("  Temperature: $(round(temperature, digits=1)) K")
    println("  Speed of sound: $(round(asound, digits=1)) m/s")
    println()
end

Output:

Altitude: 0.0 km
  Density: 1.225 kg/m³
  Pressure: 101.3 kPa
  Temperature: 288.2 K
  Speed of sound: 340.3 m/s

Altitude: 11.0 km
  Density: 0.364 kg/m³
  Pressure: 22.6 kPa
  Temperature: 216.7 K
  Speed of sound: 295.1 m/s

Nozzle Flow Analysis

Analyze nozzle flow for a given area ratio:

# Design exit Mach number
M_exit = 3.0
area_ratio = area_ratio_at(M_exit)

println("Nozzle Design:")
println("Exit Mach number: $M_exit")
println("Area ratio A/A*: $(round(area_ratio, digits=2))")

# Find Mach numbers for given area ratio
A_ratio = 5.0
M_subsonic = mach_by_area_ratio(A_ratio, 1.4, 0.1)    # subsonic solution
M_supersonic = mach_by_area_ratio(A_ratio, 1.4, 2.0)  # supersonic solution

println("\nFor A/A* = $A_ratio:")
println("Subsonic M = $(round(M_subsonic, digits=3))")
println("Supersonic M = $(round(M_supersonic, digits=3))")

Output:

Nozzle Design:
Exit Mach number: 3.0
Area ratio A/A*: 4.23

For A/A* = 5.0:
Subsonic M = 0.117
Supersonic M = 3.175

Working with Different Gases

Most functions accept a gamma parameter for different gases:

M = 2.0

# Air (γ = 1.4, default)
T0_T_air = t0_over_t(M)

# Helium (γ ≈ 1.67)
T0_T_helium = t0_over_t(M, 1.67)

println("Temperature ratios at M = $M:")
println("Air (γ=1.4): $(round(T0_T_air, digits=3))")
println("Helium (γ=1.67): $(round(T0_T_helium, digits=3))")

Output:

Temperature ratios at M = 2.0:
Air (γ=1.4): 1.8
Helium (γ=1.67): 2.34

Common Patterns

Error Handling

Functions will throw errors for invalid inputs:

try
    # This will fail - can't have oblique shock with impossible deflection
    solve_oblique(1.5, 45.0)  # θ too large for this Mach number
catch e
    println("Error: ", e)
end

Default Parameters

Most functions use sensible defaults:

# These are equivalent
p0_p_1 = p0_over_p(2.0, 1.4)  # explicit gamma
p0_p_2 = p0_over_p(2.0)       # default gamma=1.4

println(p0_p_1 == p0_p_2)  # true

Next Steps

Now that you understand the basics:

  1. Explore the Examples for more complex scenarios
  2. Check the source code for detailed function documentation with docstrings
  3. Refer to the README.md for complete API reference
  4. Look at the test files for additional usage examples