Skip to content

Commit

Permalink
Merge pull request #15 from warisa-r/obstacle_visualization
Browse files Browse the repository at this point in the history
add visualization for obstacle
  • Loading branch information
warisa-r authored Sep 2, 2024
2 parents facfd4e + 52512e2 commit de8b809
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
5 changes: 3 additions & 2 deletions examples/obstacle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ using ShockwaveProperties
using Euler2D:Euler2D

flow_data = FlowData("examples/data/obstacle/circular_obstacle_radius_1.celltape")
point_detect_algo = ImageProcessingShockDetectionAlgo(0.5, :prewitt)
point_detect_algo = ImageProcessingShockDetectionAlgo(0.2, :prewitt)
dbscan_algo = DBSCANAlgo(0.25, 3, 10)

detection = detect(flow_data, point_detect_algo, dbscan_algo)

plot_shock_fits_over_time(flow_data, detection, false)
#plot_shock_fits_over_time(flow_data, detection, false)
create_heatmap_evo_with_shock(flow_data, detection, :density_field, true, false)
3 changes: 1 addition & 2 deletions src/variable_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function convert_to_primitive(u_values::Array{T, 3}, ncells, nsteps, mach_to_m_s
return density_field, velocity_field, pressure_field
end

#TODO: make this more efficient. Either make it shorter or thread this??
function convert_to_primitive(u_values::Array{T, 4}, ncells, nsteps, mach_to_m_s=true) where T
u_prim = similar(u_values)
@threads for x in 1:ncells[1]
Expand Down Expand Up @@ -84,7 +83,7 @@ function convert_to_primitive(sim_data, nsteps, mach_to_m_s=false)
pressure_field = []


for t in 1:nsteps
@threads for t in 1:nsteps
density_t = [x !== nothing ? ustrip(x) : NaN for x in Euler2D.density_field(sim_data, t)]
pressure_t = Euler2D.pressure_field(sim_data, t, DRY_AIR)
velocity_t = [x !== nothing ? ustrip(x) : NaN for x in Euler2D.velocity_field(sim_data, t)]
Expand Down
21 changes: 20 additions & 1 deletion src/visualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,32 @@ function create_heatmap_evo_2D(flow_data, field)
end
end

"""
create_heatmap_evo_with_shock(flow_data, detection, field::Symbol = :density_field, show_curve = true, show_normal_vector = true; T=Float64)
Create a heatmap evolution plot with shock detection for 1D or 2D flow data.
# Arguments
- `flow_data`: A `FlowData` object containing the flow field data.
- `detection`: A detection object containing shock detection results.
- `field::Symbol`: The field to visualize. Default is `:density_field`.
- `show_curve::Bool`: Whether to show the shock curve in the plot. Default is `true`.
- `show_normal_vector::Bool`: Whether to show the normal vector in the plot. Default is `true`.
- `T`: The data type of the flow field. Default is `Float64`.
# Description
This function creates a heatmap evolution plot with shock detection for either 1D or 2D flow data. It determines the dimensionality of the flow data and calls the appropriate helper function to generate the plot.
- For 1D flow data (`Array{T, 3}`), it calls `create_heatmap_evo_with_shock_1D`.
- For 2D flow data (`Array{T, 4}`) or from flow data of .celltape files with obstacles, it calls `create_heatmap_evo_with_shock_2D`.
"""
function create_heatmap_evo_with_shock(flow_data, detection, field::Symbol = :density_field, show_curve = true, show_normal_vector = true; T= Float64)
if typeof(flow_data.u) == Array{T, 3}
# Handle the 1D flow case
#TODO: pipeline of detection in 1D case hasnt been implemented yet. It should contain the field shock_positions_over_time as well!
shock_positions_over_time = detection.shock_positions_over_time
create_heatmap_evo_with_shock_1D(flow_data, shock_positions_over_time, field)
elseif typeof(flow_data.u) == Array{T, 4}
elseif typeof(flow_data.u) == Array{T, 4} || isnothing(flow_data.u)
# Handle the 2D flow case
create_heatmap_evo_with_shock_2D(flow_data, detection, field, show_curve, show_normal_vector)
else
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ end
dbscan_algo = DBSCANAlgo(0.25, 3, 10)
detection = detect(flow_data, point_detect_algo, dbscan_algo)
plot_shock_fits_over_time(flow_data, detection, true)

@testset "obstacle shock detection" begin
flow_data = FlowData(joinpath(DATA_DIR, "circular_obstacle_radius_1.celltape"), false)
point_detect_algo = ImageProcessingShockDetectionAlgo(0.2, :prewitt)
dbscan_algo = DBSCANAlgo(0.25, 3, 10)
detection = detect(flow_data, point_detect_algo, dbscan_algo)
plot_shock_fits_over_time(flow_data, detection, false)
create_heatmap_evo_with_shock(flow_data, detection, :density_field, true, false)
rm("density_field_evolution.gif")
end

0 comments on commit de8b809

Please sign in to comment.