Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type GPUSystem to determine if a system is stored on the CPU or GPU #532

Merged
merged 8 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/n_body/n_body_system.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using TrixiParticles
using LinearAlgebra

struct NBodySystem{NDIMS, ELTYPE <: Real} <: TrixiParticles.System{NDIMS}
struct NBodySystem{NDIMS, ELTYPE <: Real} <: TrixiParticles.System{NDIMS, Nothing}
initial_condition :: InitialCondition{ELTYPE}
mass :: Array{ELTYPE, 1} # [particle]
G :: ELTYPE
Expand Down
13 changes: 9 additions & 4 deletions src/general/general.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
abstract type System{NDIMS} end
# Abstract supertype for all system types. We additionally store the type of the system's
# initial condition, which is `Nothing` when using KernelAbstractions.jl.
abstract type System{NDIMS, IC} end

abstract type FluidSystem{NDIMS} <: System{NDIMS} end
# When using KernelAbstractions.jl, the initial condition has been replaced by `nothing`
GPUSystem = System{NDIMS, Nothing} where {NDIMS}

abstract type FluidSystem{NDIMS, IC} <: System{NDIMS, IC} end
timer_name(::FluidSystem) = "fluid"

abstract type SolidSystem{NDIMS} <: System{NDIMS} end
abstract type SolidSystem{NDIMS, IC} <: System{NDIMS, IC} end
timer_name(::SolidSystem) = "solid"

abstract type BoundarySystem{NDIMS} <: System{NDIMS} end
abstract type BoundarySystem{NDIMS, IC} <: System{NDIMS, IC} end
timer_name(::BoundarySystem) = "boundary"

@inline function set_zero!(du)
Expand Down
2 changes: 2 additions & 0 deletions src/general/semidiscretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct Semidiscretization{S, RU, RV, NS}
end
end

GPUSemidiscretization = Semidiscretization{<:NTuple{<:Any, GPUSystem}}

function Semidiscretization(systems...; neighborhood_search=GridNeighborhoodSearch,
periodic_box_min_corner=nothing,
periodic_box_max_corner=nothing, threaded_nhs_update=true)
Expand Down
19 changes: 10 additions & 9 deletions src/schemes/boundary/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ The interaction between fluid and boundary particles is specified by the boundar
- `adhesion_coefficient`: Coefficient specifying the adhesion of a fluid to the surface.
Note: currently it is assumed that all fluids have the same adhesion coefficient.
"""
struct BoundarySPHSystem{BM, NDIMS, ELTYPE <: Real, IC, CO, M, IM, CA} <:
BoundarySystem{NDIMS}
struct BoundarySPHSystem{BM, NDIMS, ELTYPE, IC, CO, M, IM, CA} <: BoundarySystem{NDIMS, IC}
initial_condition :: IC
coordinates :: CO # Array{ELTYPE, 2}
boundary_model :: BM
Expand Down Expand Up @@ -68,20 +67,22 @@ The interaction between fluid and boundary particles is specified by the boundar
This is an experimental feature and may change in a future releases.

"""
struct BoundaryDEMSystem{NDIMS, ELTYPE <: Real, ARRAY1D, ARRAY2D} <: BoundarySystem{NDIMS}
coordinates :: ARRAY2D # [dimension, particle]
radius :: ARRAY1D # [particle]
normal_stiffness :: ELTYPE
struct BoundaryDEMSystem{NDIMS, ELTYPE <: Real, IC,
ARRAY1D, ARRAY2D} <: BoundarySystem{NDIMS, IC}
initial_condition :: IC
coordinates :: ARRAY2D # [dimension, particle]
radius :: ARRAY1D # [particle]
normal_stiffness :: ELTYPE

function BoundaryDEMSystem(initial_condition, normal_stiffness)
coordinates = initial_condition.coordinates
radius = 0.5 * initial_condition.particle_spacing *
ones(length(initial_condition.mass))
NDIMS = size(coordinates, 1)

return new{NDIMS, eltype(coordinates), typeof(radius), typeof(coordinates)}(coordinates,
radius,
normal_stiffness)
return new{NDIMS, eltype(coordinates), typeof(initial_condition),
typeof(radius), typeof(coordinates)}(initial_condition, coordinates,
radius, normal_stiffness)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/schemes/fluid/entropically_damped_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ See [Entropically Damped Artificial Compressibility for SPH](@ref edac) for more
gravity-like source terms.
"""
struct EntropicallyDampedSPHSystem{NDIMS, ELTYPE <: Real, IC, M, DC, K, V,
PF, ST, C} <: FluidSystem{NDIMS}
PF, ST, C} <: FluidSystem{NDIMS, IC}
initial_condition :: IC
mass :: M # Vector{ELTYPE}: [particle]
density_calculator :: DC
Expand Down
2 changes: 1 addition & 1 deletion src/schemes/fluid/weakly_compressible_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ See [Weakly Compressible SPH](@ref wcsph) for more details on the method.

"""
struct WeaklyCompressibleSPHSystem{NDIMS, ELTYPE <: Real, IC, MA, P, DC, SE, K,
V, DD, COR, PF, ST, SRFT, C} <: FluidSystem{NDIMS}
V, DD, COR, PF, ST, SRFT, C} <: FluidSystem{NDIMS, IC}
initial_condition :: IC
mass :: MA # Array{ELTYPE, 1}
pressure :: P # Array{ELTYPE, 1}
Expand Down
6 changes: 3 additions & 3 deletions src/schemes/solid/discrete_element_method/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ specified material properties and contact mechanics.
!!! warning "Experimental Implementation"
This is an experimental feature and may change in a future releases.
"""
struct DEMSystem{NDIMS, ELTYPE <: Real, ARRAY1D, ST} <: SolidSystem{NDIMS}
initial_condition :: InitialCondition{ELTYPE}
struct DEMSystem{NDIMS, ELTYPE <: Real, IC, ARRAY1D, ST} <: SolidSystem{NDIMS, IC}
initial_condition :: IC
mass :: ARRAY1D # [particle]
radius :: ARRAY1D # [particle]
elastic_modulus :: ELTYPE
Expand All @@ -53,7 +53,7 @@ struct DEMSystem{NDIMS, ELTYPE <: Real, ARRAY1D, ST} <: SolidSystem{NDIMS}
throw(ArgumentError("`acceleration` must be of length $NDIMS for a $(NDIMS)D problem"))
end

return new{NDIMS, ELTYPE, typeof(mass),
return new{NDIMS, ELTYPE, typeof(initial_condition), typeof(mass),
typeof(source_terms)}(initial_condition, mass, radius, elastic_modulus,
poissons_ratio, normal_stiffness,
damping_coefficient, acceleration_, source_terms)
Expand Down
2 changes: 1 addition & 1 deletion src/schemes/solid/total_lagrangian_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ See [Total Lagrangian SPH](@ref tlsph) for more details on the method.
where `beam` and `fixed_particles` are of type `InitialCondition`.
"""
struct TotalLagrangianSPHSystem{BM, NDIMS, ELTYPE <: Real, IC, ARRAY1D, ARRAY2D, ARRAY3D,
K, PF, ST} <: SolidSystem{NDIMS}
K, PF, ST} <: SolidSystem{NDIMS, IC}
initial_condition :: IC
initial_coordinates :: ARRAY2D # Array{ELTYPE, 2}: [dimension, particle]
current_coordinates :: ARRAY2D # Array{ELTYPE, 2}: [dimension, particle]
Expand Down
6 changes: 3 additions & 3 deletions test/general/semidiscretization.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Use `@trixi_testset` to isolate the mock functions in a separate namespace
@trixi_testset "Semidiscretization" begin
# Mock systems
struct System1 <: TrixiParticles.System{3} end
struct System2 <: TrixiParticles.System{3} end
struct System1 <: TrixiParticles.System{3, Nothing} end
struct System2 <: TrixiParticles.System{3, Nothing} end

system1 = System1()
system2 = System2()
Expand Down Expand Up @@ -39,7 +39,7 @@
struct BoundaryModelMock end

# Mock fluid system
struct FluidSystemMock <: TrixiParticles.FluidSystem{2} end
struct FluidSystemMock <: TrixiParticles.FluidSystem{2, Nothing} end

kernel = Val(:smoothing_kernel)
Base.ndims(::Val{:smoothing_kernel}) = 2
Expand Down
Loading