Skip to content

Commit

Permalink
improve structs typing
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat committed Dec 18, 2024
1 parent 59a7695 commit 6bb4486
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/particles.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
abstract type AbstractParticles end

"""
struct Particles{Backend,N,M,I,T1,T2} <: AbstractParticles
Particles{Backend,N,I,T1,T2} <: AbstractParticles
A struct representing a collection of particles.
Expand All @@ -14,7 +14,7 @@ A struct representing a collection of particles.
- `min_xcell`: Minimum number of particles per cell
- `np`: Number of particles
"""
struct Particles{Backend,N,M,I,T1,T2} <: AbstractParticles
struct Particles{Backend,N,I,T1,T2} <: AbstractParticles
coords::NTuple{N,T1}
index::T2
nxcell::I
Expand All @@ -23,15 +23,15 @@ struct Particles{Backend,N,M,I,T1,T2} <: AbstractParticles
np::I

function Particles(
backend,
::Type{B},
coords::NTuple{N,T1},
index::T2,
nxcell::I,
max_xcell::I,
min_xcell::I,
np::I,
) where {N,I,T1,T2}
return new{backend,N,max_xcell,I,T1,T2}(
) where {B,N,I,T1,T2}
return new{B,N,I,T1,T2}(
coords, index, nxcell, max_xcell, min_xcell, np
)
end
Expand All @@ -40,7 +40,7 @@ end
function Particles(coords, index::CPUCellArray, nxcell, max_xcell, min_xcell, np)
return Particles(CPUBackend, coords, index, nxcell, max_xcell, min_xcell, np)
end
struct MarkerChain{Backend,N,M,I,T1,T2,T3,TV} <: AbstractParticles
struct MarkerChain{Backend,N,I,T1,T2,T3,TV} <: AbstractParticles
coords::NTuple{N,T1} # current x-coord in 2D, (x,y)
coords0::NTuple{N,T1} # x-coord in 2D, (x,y) from the previous time step
h_vertices::T2 # topography at the vertices of the grid (current)
Expand All @@ -51,7 +51,7 @@ struct MarkerChain{Backend,N,M,I,T1,T2,T3,TV} <: AbstractParticles
min_xcell::I

function MarkerChain(
backend,
::Type{B},
coords::NTuple{N,T1},
coords0::NTuple{N,T1},
h_vertices::T2,
Expand All @@ -60,8 +60,8 @@ struct MarkerChain{Backend,N,M,I,T1,T2,T3,TV} <: AbstractParticles
index::T3,
min_xcell::I,
max_xcell::I,
) where {N,I,T1,T2,T3,TV}
return new{backend,N,max_xcell,I,T1,T2,T3,TV}(
) where {B,N,I,T1,T2,T3,TV}
return new{B,N,I,T1,T2,T3,TV}(
coords, coords0, h_vertices, h_vertices0, cell_vertices, index, max_xcell, min_xcell
)
end
Expand All @@ -75,20 +75,18 @@ struct PassiveMarkers{Backend,T} <: AbstractParticles
coords::T
np::Int64

function PassiveMarkers(backend, coords::NTuple{N,T}) where {N,T}
function PassiveMarkers(::Type{B}, coords::NTuple{N,T}) where {B,N,T}
# np = length(coords[1].data)
np = length(coords[1])
return new{backend,typeof(coords)}(coords, np)
return new{B,typeof(coords)}(coords, np)
end
function PassiveMarkers(backend, coords::AbstractArray)
function PassiveMarkers(::Type{B}, coords::AbstractArray) where B
np = length(coords)
return new{backend,typeof(coords)}(coords, np)
return new{B,typeof(coords)}(coords, np)
end
end

function PassiveMarkers(coords::Union{AbstractArray,NTuple{N,T}}) where {N,T}
return PassiveMarkers(CPUBackend, coords)
end
PassiveMarkers(coords::Union{AbstractArray,NTuple{N,T}}) where {N,T} = PassiveMarkers(CPUBackend, coords)

# useful functions

Expand Down Expand Up @@ -127,4 +125,4 @@ end
Base.@_inline_meta
cell_index(x[i], xv[i])
end
end
end

0 comments on commit 6bb4486

Please sign in to comment.