Skip to content

Commit

Permalink
type generalization 60%
Browse files Browse the repository at this point in the history
  • Loading branch information
warisa-r committed Sep 16, 2024
1 parent da3bfed commit a0e1d3c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 2 additions & 0 deletions examples/obstacle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using ShockwaveDetection
using ShockwaveProperties
using Euler2D:Euler2D

ENV["JULIA_NUM_THREADS"] = "4"

flow_data = FlowData("examples/data/obstacle/funky_square.celltape")
point_detect_algo = ImageProcessingShockDetectionAlgo(0.2, :prewitt)
dbscan_algo = DBSCANAlgo(0.25, 50, 40)
Expand Down
14 changes: 7 additions & 7 deletions src/cluster.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Clustering

"""
struct DBSCANAlgo
struct DBSCANAlgo{T}
A structure that keeps all the necessary parameters for the DBSCAN clustering algorithm.
# Fields
- `radius::Float64`: The radius within which to search for neighboring points.
- `radius::T`: The radius within which to search for neighboring points.
- `min_neighbors::Int`: The minimum number of neighbors required to form a dense region.
- `min_cluster_size::Int`: The minimum number of points required to form a cluster.
Expand All @@ -17,14 +17,14 @@ A structure that keeps all the necessary parameters for the DBSCAN clustering al
# Example
algo = DBSCANAlgo(radius=1.0, min_neighbors=5, min_cluster_size=15)
"""
struct DBSCANAlgo
radius::Float64
struct DBSCANAlgo{T}
radius::T
min_neighbors::Int
min_cluster_size::Int

# Inner constructor with default values
function DBSCANAlgo(radius::Float64 = 0.5, min_neighbors::Int=3, min_cluster_size::Int=10)
new(radius, min_neighbors, min_cluster_size)
# Inner constructor with default values
function DBSCANAlgo(radius::T = 0.5, min_neighbors::Int = 3, min_cluster_size::Int = 10) where T
new{T}(radius, min_neighbors, min_cluster_size)
end
end #struct DBSCANAlgo

Expand Down
10 changes: 4 additions & 6 deletions src/fitting.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using LsqFit
using LinearAlgebra

struct Fitting
struct Fitting{T}
model::Function
parameters::Array{Float64}
error::Float64
range::Tuple{Float64, Float64}
parameters::Array{T}
error::T
range::Tuple{T, T}
end

#TODO: hline_model

# The angle of the end point and the starting point is needed to determine the proper shape
# For other models, only range of x suffices
function circle_model(xy, p)
Expand Down
4 changes: 1 addition & 3 deletions src/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ This function detects shock points in 2D flow data using a specified shock detec
function detect(flow_data::FlowData, shock_point_algo::Abstract2DShockDetectionAlgo, cluster_algo::DBSCANAlgo)
to = TimerOutput()

has_obstacle = isnothing(flow_data.u) # Check if the flow data has an obstacle

@timeit to "Detect Shock Points(2D)" begin
shock_positions_over_time = detect_shock_points(flow_data, shock_point_algo, has_obstacle)
shock_positions_over_time = detect_shock_points(flow_data, shock_point_algo)
end

@timeit to "Cluster Shock Points" begin
Expand Down
10 changes: 5 additions & 5 deletions src/shock_point_detectors/2D/image_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function replace_nan_with_mean!(matrix)
end

"""
struct ImageProcessingShockDetectionAlgo <: Abstract2DShockDetectionAlgo
struct ImageProcessingShockDetectionAlgo{T} <: Abstract2DShockDetectionAlgo
A structure that represents the image processing shock detection algorithm.
# Fields
- `threshold::Float64`: The threshold value for detecting shocks.
- `threshold::T`: The threshold value for detecting shocks.
- `kernelname::Symbol`: The name of the kernel to be used for image processing (e.g., `:sobel`, `:prewitt`).
# Description
Expand All @@ -40,8 +40,8 @@ This struct is used to configure the image processing shock detection algorithm.
# Example
algo = ImageProcessingShockDetectionAlgo(threshold=0.5, kernelname=:sobel)
"""
struct ImageProcessingShockDetectionAlgo <: Abstract2DShockDetectionAlgo
threshold::Float64
struct ImageProcessingShockDetectionAlgo{T} <: Abstract2DShockDetectionAlgo
threshold::T
kernelname::Symbol
end # ImageProcessingShockDetectionAlgo

Expand Down Expand Up @@ -98,7 +98,7 @@ function detect_discon_at_timestep(density_at_t, velocity_at_t, pressure_at_t, a
return high_gradient_intersection
end

function detect_shock_points(flow_data::FlowData, alg::ImageProcessingShockDetectionAlgo, has_obstacle)
function detect_shock_points(flow_data::FlowData, alg::ImageProcessingShockDetectionAlgo)
# Unpack all the values from the detector
nsteps = flow_data.nsteps
density_field = flow_data.density_field
Expand Down

0 comments on commit a0e1d3c

Please sign in to comment.