-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,261 additions
and
117 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ authors = ["Warisa <[email protected]> and contributors"] | |
version = "1.0.0-DEV" | ||
|
||
[deps] | ||
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
ShockwaveProperties = "77d2bf28-a3e9-4b9c-9fcf-b85f74cc8a50" | ||
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" | ||
|
||
[compat] | ||
julia = "1.9" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
using ShockwaveDetection | ||
using ShockwaveDetection | ||
|
||
x0_xmax, t_values, u_values, dims_u = read_output_file("examples/data/euler_scenario_1.out") | ||
density_field, velocity_field, pressure_field = convert_to_primitive(u_values) | ||
|
||
# Plot the animation of the properties over time | ||
anim = create_wave_animation(x0_xmax, t_values, density_field, velocity_field, pressure_field) | ||
|
||
#Plot the shock create_wave_animation | ||
shock_positions_over_time = detect_shock(density_field, velocity_field, pressure_field, x0_xmax, t_values) | ||
anim_with_shock = create_wave_animation_with_shock(x0_xmax, t_values, density_field, velocity_field, pressure_field, shock_positions_over_time) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
using ShockwaveDetection | ||
using ShockwaveDetection | ||
|
||
x0_xmax, t_values, u_values, dims_u = read_output_file("examples/data/euler_scenario_2.out") | ||
density_field, velocity_field, pressure_field = convert_to_primitive(u_values) | ||
|
||
# Plot the animation of the properties over time | ||
anim = create_wave_animation(x0_xmax, t_values, density_field, velocity_field, pressure_field) | ||
|
||
#Plot the shock create_wave_animation | ||
shock_positions_over_time = detect_shock(density_field, velocity_field, pressure_field, x0_xmax, t_values) | ||
anim_with_shock = create_wave_animation_with_shock(x0_xmax, t_values, density_field, velocity_field, pressure_field, shock_positions_over_time) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
module ShockwaveDetection | ||
|
||
# Write your package code here. | ||
export write_output | ||
export read_output_file | ||
export convert_to_primitive | ||
export detect_shock | ||
export create_wave_animation, create_wave_animation_with_shock | ||
|
||
|
||
include("dummy.jl") | ||
include("input.jl") | ||
include("variable_utils.jl") | ||
include("detect_shock.jl") | ||
include("visualize.jl") | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function write_output() | ||
return "Hello from Julia!" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
read_output_file(filename) | ||
Reads data from an output file. | ||
# Arguments | ||
- `filename::String`: The path to the output file. | ||
# Returns | ||
- `x0_xmax::Vector{Float64}`: A vector containing the first and last x values. | ||
- `t_values::Vector{Float64}`: A vector containing the time values. | ||
- `u_values::Array{Float64, 3}`: A 3D array containing the u values. | ||
- `dims_u::Vector{Int}`: A vector containing the dimensions of the u values (N_u x N_x). | ||
This function reads data from the specified output file generated from 1d_plots.jl that use Euler2D.jl to solve, which is assumed to have a specific format. | ||
It reads the dimensions of the u values, the first and last x values, the number of time steps, the time values, and the u values themselves. | ||
It reshapes the u values into a 3D array and returns all the read data. | ||
""" | ||
function read_output_file(filename) | ||
open(filename, "r") do f | ||
dims_u = Vector{Int}(undef, 2) | ||
read!(f, dims_u) | ||
|
||
# Read the first and last x values | ||
x0_xmax = Vector{Float64}(undef, 2) | ||
read!(f, x0_xmax) | ||
|
||
# Read the number of time steps | ||
num_timesteps = Vector{Int}(undef, 1) | ||
read!(f, num_timesteps) | ||
|
||
# Read the time values | ||
t_values = Vector{Float64}(undef, num_timesteps[1]) | ||
read!(f, t_values) | ||
|
||
# Read the u values | ||
u_values = Vector{Float64}(undef, prod(dims_u)*num_timesteps[1]) | ||
read!(f, u_values) | ||
|
||
|
||
# Reshape u_values to a 3D array | ||
u_values = reshape(u_values, dims_u[1], dims_u[2], num_timesteps[1]) # N_u x N_x x N_t as u a vector of 3 is written in range of x according to each time step | ||
|
||
|
||
return x0_xmax, t_values, u_values, dims_u | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using ShockwaveProperties: primitive_state_vector, pressure, speed_of_sound, DRY_AIR | ||
using Unitful: ustrip | ||
|
||
""" | ||
convert_to_primitive(u_values) | ||
Converts conserved state variables to primitive variables. | ||
# Arguments | ||
- `u_values::Array{Float64, 3}`: A 3D array containing the conserved state variables (density, momentum, total energy) at each point x and time t. | ||
# Returns | ||
- `density_field::Array{Float64, 2}`: A 2D array containing the density field. | ||
- `velocity_field::Array{Float64, 2}`: A 2D array containing the velocity field. | ||
- `pressure_field::Array{Float64, 2}`: A 2D array containing the pressure field. | ||
Euler equations are typically represented in a "conserved" form, where the vector u contains (density, momentum, total energy) at each point x and time t. This function converts these conserved state variables to primitive variables (density, velocity, pressure) in order to calculate delta1 and delta2 according to [6]. | ||
The `u_values` parameter is a 3D array representing the conserved state variables at each point x and time t. This function iterates over each time step and calculates the primitive state vector for density, velocity, and pressure using appropriate transformations. The resulting primitive variables are stored in separate arrays `density_field`, `velocity_field`, and `pressure_field`, and returned. | ||
""" | ||
function convert_to_primitive(u_values) | ||
u_prim = zeros(size(u_values)) | ||
for i in 1:size(u_values, 2) | ||
for j in 1:size(u_values, 3) | ||
# primitive_state_vector returns value without units | ||
u_p_M_T = primitive_state_vector(u_values[:, i, j]; gas=DRY_AIR) | ||
p_u = pressure(u_p_M_T[1], u_p_M_T[3]; gas=DRY_AIR) | ||
# Store density | ||
u_prim[1, i, j] = u_p_M_T[1] | ||
# Convert Mach to m/s using speed_of_sound | ||
u_prim[2, i, j] = u_p_M_T[2] * ustrip(speed_of_sound(u_p_M_T[3]; gas=DRY_AIR)) | ||
# Strip the unit of pressure so that it can be stored in an empty array | ||
u_prim[3, i, j] = ustrip(p_u) | ||
end | ||
end | ||
|
||
# Extract the density, velocity, and pressure fields | ||
density_field = u_prim[1, :, :] | ||
velocity_field = u_prim[2, :, :] | ||
pressure_field = u_prim[3, :, :] | ||
return density_field, velocity_field, pressure_field | ||
end |
Oops, something went wrong.