Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
warisa-r committed Sep 7, 2024
2 parents 84aefce + c04bb62 commit 695d806
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 16 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
- '1.10'
- '1.9'
os:
- ubuntu-latest
- macos-latest
- windows-latest
arch:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 12 additions & 3 deletions examples/sod_shock_tube_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ using ShockwaveProperties
using Unitful
using ShockwaveDetection

flow_data = FlowData("example/data/sod_shock_left_1d.tape", false)
# Create a NoiseData instance
#noise_data = NoiseData(0.01, Normal(0, 1)) # 1% noise intensity, Gaussian distribution

shock_positions_over_time = detect(flow_data, GradientShockDetectionAlgo(0.5))
anim = create_wave_animation_with_shock(flow_data, shock_positions_over_time)
flow_data = FlowData("examples/data/sod_shock_left_1d.tape", false)

point_detect_algo = GradientShockDetectionAlgo(0.5)

detection = detect(flow_data, point_detect_algo)

#plot_shock_fits_over_time(flow_data, detection, true)

shock_positions_over_time = detect(flow_data, point_detect_algo)
anim = create_wave_animation_with_shock(flow_data, detection)
7 changes: 4 additions & 3 deletions examples/supersonic_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ detection_alg = GradientShockDetectionAlgo(0.2)
#anim = create_wave_animation(flow_data)

# Plot the shock create_wave_animation
shock_positions_over_time = detect(flow_data, detection_alg)
anim_with_shock = create_wave_animation_with_shock(flow_data, shock_positions_over_time)
create_heatmap_evo_with_shock(flow_data, shock_positions_over_time, :density_field)
#shock_positions_over_time = detect(flow_data, detection_alg)
detection = detect(flow_data, detection_alg)
anim_with_shock = create_wave_animation_with_shock(flow_data, detection)
#create_heatmap_evo_with_shock(flow_data, shock_positions_over_time, :density_field)
# Check each member of shock_positions_over_time
2 changes: 1 addition & 1 deletion src/ShockwaveDetection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export cluster_shock_points
export fit_shock_clusters_over_time
export create_wave_animation, create_wave_animation_with_shock, create_heatmap_evo, create_heatmap_evo_with_shock, plot_shock_fits_over_time
export ShockDetectionResult2D, detect

export ShockDetectionResult1D, detect

include("input.jl")
include("variable_utils.jl")
Expand Down
59 changes: 51 additions & 8 deletions src/pipeline.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
#TODO: pipeline 1D shock detection too
abstract type AbstractShockDetectionResult end

struct ShockDetectionResult2D
struct ShockDetectionResult2D <: AbstractShockDetectionResult
shock_positions_over_time::Vector{Any}
shock_clusters_over_time::Vector{Any}
shock_fits_over_time::Vector{Any}
end

# Pipeline is only for 2D shock detection now
struct ShockDetectionResult1D <: AbstractShockDetectionResult
shock_positions_over_time::Vector{Any}
end

"""
detect(flow_data::FlowData, shock_point_algo::Abstract2DShockDetectionAlgo, cluster_algo::DBSCANAlgo)
Detects shocks in 2D flow data, clusters the shockpoints and applies fitting to the cluster.
# Arguments
- `flow_data::FlowData`: A `FlowData` object containing the 2D flow field data.
- `shock_point_algo::Abstract2DShockDetectionAlgo`: An algorithm for detecting shock points in 2D flow data.
- `cluster_algo::DBSCANAlgo`: A clustering algorithm (e.g., DBSCAN) to group detected shock points into clusters.
# Returns
- `ShockDetectionResult2D`: An object containing:
- `shock_positions_over_time`: Detected shock points over time.
- `shock_clusters_over_time`: Clusters of shock points over time.
- `shock_fits_over_time`: Fitted shock curves over time.
# Description
This function detects shock points in 2D flow data using a specified shock detection algorithm. Detected shock points are clustered using the provided `DBSCANAlgo`, and then the clusters are fitted to create a smooth representation of the shock over time.
"""
function detect(flow_data::FlowData, shock_point_algo::Abstract2DShockDetectionAlgo, cluster_algo::DBSCANAlgo)
has_obstacle = false
if isnothing(flow_data.u)
has_obstacle = true
end
has_obstacle = isnothing(flow_data.u) # Check if the flow data has an obstacle
shock_positions_over_time = detect_shock_points(flow_data, shock_point_algo, has_obstacle)
shock_clusters_over_time = cluster_shock_points(cluster_algo, shock_positions_over_time, flow_data)
shock_fits_over_time = fit_shock_clusters_over_time(shock_clusters_over_time)

return ShockDetectionResult2D(shock_positions_over_time, shock_clusters_over_time, shock_fits_over_time)
end
end

"""
detect(flow_data::FlowData, shock_point_algo::Abstract1DShockDetectionAlgo)
Detects shocks in 1D flow data.
# Arguments
- `flow_data::FlowData`: A `FlowData` object containing the 1D flow field data.
- `shock_point_algo::Abstract1DShockDetectionAlgo`: An algorithm for detecting shock points in 1D flow data.
# Returns
- `ShockDetectionResult1D`: An object containing:
- `shock_positions_over_time`: Detected shock points over time.
# Description
This function detects shock points in 1D flow data using a specified shock detection algorithm.
"""
function detect(flow_data::FlowData, shock_point_algo::Abstract1DShockDetectionAlgo)
has_obstacle = isnothing(flow_data.u) # Check if the flow data has an obstacle
shock_positions_over_time = detect_shock_points(flow_data, shock_point_algo, has_obstacle)

return ShockDetectionResult1D(shock_positions_over_time)
end
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ end
rm("density_velocity_pressure_over_time_with_shock_positions.gif")
end

@testset "1D supersonic shock detection" begin
flow_data = FlowData(joinpath(DATA_DIR, "supersonic_shock_2.tape"), false)
point_detect_algo = GradientShockDetectionAlgo(0.2)
detection = detect(flow_data, point_detect_algo)
anim = create_wave_animation_with_shock(flow_data, detection)
rm("density_velocity_pressure_over_time_with_shock_positions.gif")
end

@testset "2D shock detection" begin
flow_data = FlowData(joinpath(DATA_DIR, "sod_shock_right_2d.tape"), false)
point_detect_algo = ImageProcessingShockDetectionAlgo(0.5, :prewitt)
Expand Down

0 comments on commit 695d806

Please sign in to comment.