From 98e58f9b725f55e74219e5bb78de7e12fdac2613 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Wed, 29 May 2024 11:58:01 +0200 Subject: [PATCH 1/4] Add type `GPUSystem` to determine if a system is stored on the CPU or GPU (#532) * Add type `GPUSystem` to determine if a system is stored on the CPU or GPU * Fix systems and tests * Reformat * Fix tests * Fix n-body system * Reformat --- examples/n_body/n_body_system.jl | 2 +- src/general/general.jl | 13 +++++++++---- src/general/semidiscretization.jl | 2 ++ src/schemes/boundary/system.jl | 19 ++++++++++--------- .../fluid/entropically_damped_sph/system.jl | 2 +- .../fluid/weakly_compressible_sph/system.jl | 2 +- .../solid/discrete_element_method/system.jl | 6 +++--- .../solid/total_lagrangian_sph/system.jl | 2 +- test/general/semidiscretization.jl | 6 +++--- 9 files changed, 31 insertions(+), 23 deletions(-) diff --git a/examples/n_body/n_body_system.jl b/examples/n_body/n_body_system.jl index 96b6cdebf..caf40a62e 100644 --- a/examples/n_body/n_body_system.jl +++ b/examples/n_body/n_body_system.jl @@ -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 diff --git a/src/general/general.jl b/src/general/general.jl index 4c9531683..dfe52e06a 100644 --- a/src/general/general.jl +++ b/src/general/general.jl @@ -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) diff --git a/src/general/semidiscretization.jl b/src/general/semidiscretization.jl index a3ce1e056..6a1d703b2 100644 --- a/src/general/semidiscretization.jl +++ b/src/general/semidiscretization.jl @@ -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) diff --git a/src/schemes/boundary/system.jl b/src/schemes/boundary/system.jl index a1bec02e9..cade5fbe9 100644 --- a/src/schemes/boundary/system.jl +++ b/src/schemes/boundary/system.jl @@ -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 @@ -68,10 +67,12 @@ 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 @@ -79,9 +80,9 @@ struct BoundaryDEMSystem{NDIMS, ELTYPE <: Real, ARRAY1D, ARRAY2D} <: BoundarySys 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 diff --git a/src/schemes/fluid/entropically_damped_sph/system.jl b/src/schemes/fluid/entropically_damped_sph/system.jl index 15c765040..f59bca7d3 100644 --- a/src/schemes/fluid/entropically_damped_sph/system.jl +++ b/src/schemes/fluid/entropically_damped_sph/system.jl @@ -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 diff --git a/src/schemes/fluid/weakly_compressible_sph/system.jl b/src/schemes/fluid/weakly_compressible_sph/system.jl index 63a32e6db..cb9a1da87 100644 --- a/src/schemes/fluid/weakly_compressible_sph/system.jl +++ b/src/schemes/fluid/weakly_compressible_sph/system.jl @@ -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} diff --git a/src/schemes/solid/discrete_element_method/system.jl b/src/schemes/solid/discrete_element_method/system.jl index a7cd2868f..5aadfcfcc 100644 --- a/src/schemes/solid/discrete_element_method/system.jl +++ b/src/schemes/solid/discrete_element_method/system.jl @@ -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 @@ -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) diff --git a/src/schemes/solid/total_lagrangian_sph/system.jl b/src/schemes/solid/total_lagrangian_sph/system.jl index fe949b9f1..5b3021b1c 100644 --- a/src/schemes/solid/total_lagrangian_sph/system.jl +++ b/src/schemes/solid/total_lagrangian_sph/system.jl @@ -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] diff --git a/test/general/semidiscretization.jl b/test/general/semidiscretization.jl index 8a74de0ab..633a0e240 100644 --- a/test/general/semidiscretization.jl +++ b/test/general/semidiscretization.jl @@ -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() @@ -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 From 1ba317bf8d2d0c6218128c911cf77176e9e0c399 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Wed, 29 May 2024 13:09:32 +0200 Subject: [PATCH 2/4] Clean up callback conditions (#538) --- src/callbacks/callbacks.jl | 3 +-- src/callbacks/density_reinit.jl | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/callbacks/callbacks.jl b/src/callbacks/callbacks.jl index f86f9a586..1aefdff72 100644 --- a/src/callbacks/callbacks.jl +++ b/src/callbacks/callbacks.jl @@ -21,8 +21,7 @@ end # (total #steps) (#accepted steps) # We need to check the number of accepted steps since callbacks are not # activated after a rejected step. - return interval > 0 && (((integrator.stats.naccept % interval == 0) && - !(integrator.stats.naccept == 0 && integrator.iter > 0)) || + return interval > 0 && ((integrator.stats.naccept % interval == 0) || (save_final_solution && isfinished(integrator))) end diff --git a/src/callbacks/density_reinit.jl b/src/callbacks/density_reinit.jl index 5e9f98027..5c8a7b5e1 100644 --- a/src/callbacks/density_reinit.jl +++ b/src/callbacks/density_reinit.jl @@ -89,13 +89,7 @@ end function (reinit_callback::DensityReinitializationCallback{Int})(u, t, integrator) (; interval) = reinit_callback - # With error-based step size control, some steps can be rejected. Thus, - # `integrator.iter >= integrator.stats.naccept` - # (total #steps) (#accepted steps) - # We need to check the number of accepted steps since callbacks are not - # activated after a rejected step. - return interval > 0 && ((integrator.stats.naccept % interval == 0) && - !(integrator.stats.naccept == 0 && integrator.iter > 0)) + return condition_integrator_interval(integrator, interval, save_final_solution=false) end # condition with dt From 17d95b6af731ec68593c9cb2add01df22433e379 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 10:02:59 +0200 Subject: [PATCH 3/4] Bump julia-actions/cache from 1 to 2 (#541) Bumps [julia-actions/cache](https://github.com/julia-actions/cache) from 1 to 2. - [Release notes](https://github.com/julia-actions/cache/releases) - [Changelog](https://github.com/julia-actions/cache/blob/main/devdocs/making_a_new_release.md) - [Commits](https://github.com/julia-actions/cache/compare/v1...v2) --- updated-dependencies: - dependency-name: julia-actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/Documenter.yml | 2 +- .github/workflows/FormatCheck.yml | 2 +- .github/workflows/ci.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index 4cc31a611..a748be851 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -34,7 +34,7 @@ jobs: with: version: '1' show-versioninfo: true - - uses: julia-actions/cache@v1 + - uses: julia-actions/cache@v2 - name: Build package uses: julia-actions/julia-buildpkg@v1 - name: Install dependencies diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index 5000913d4..bdd275a5c 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -19,7 +19,7 @@ jobs: with: version: '1' - run: julia -e 'using InteractiveUtils; versioninfo(verbose=true)' - - uses: julia-actions/cache@v1 + - uses: julia-actions/cache@v2 - name: Install JuliaFormatter and format # This will use the latest version by default but you can set the version like so: # diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5832a20f..b115c6937 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} - - uses: julia-actions/cache@v1 + - uses: julia-actions/cache@v2 - name: Build package uses: julia-actions/julia-buildpkg@v1 - name: Run unit tests From ad902882bb9a4365670ee8535abff9ea8de2d8d3 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Thu, 13 Jun 2024 16:07:49 +0200 Subject: [PATCH 4/4] Update Michael's affiliation to U of Augsburg (#545) --- .zenodo.json | 2 +- CODE_OF_CONDUCT.md | 4 ++-- README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.zenodo.json b/.zenodo.json index ecb62381e..1b2cefaeb 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -20,7 +20,7 @@ "orcid": "0000-0001-6083-7038" }, { - "affiliation": "Applied and Computational Mathematics, RWTH Aachen University, Germany", + "affiliation": "High-Performance Scientific Computing, University of Augsburg, Germany", "name": "Schlottke-Lakemper, Michael", "orcid": "0000-0002-3195-2536" }, diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 5c74bcf79..e9f99ce1b 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -60,7 +60,7 @@ representative at an online or offline event. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to -[Michael Schlottke-Lakemper](mailto:m.schlottke-lakemper@acom.rwth-aachen.de), +[Michael Schlottke-Lakemper](mailto:michael.schlottke-lakemper@uni-a.de), [Sven Berger](mailto:sven.berger@hereon.de), or any other of the principal developers responsible for enforcement listed in [AUTHORS.md](AUTHORS.md). @@ -128,4 +128,4 @@ enforcement ladder](https://github.com/mozilla/diversity). For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. \ No newline at end of file +https://www.contributor-covenant.org/translations. diff --git a/README.md b/README.md index 9f5defe1a..b40e68fbc 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ with the help of TrixiParticles.jl, please cite it as ## Authors Erik Faulhaber (University of Cologne) and Niklas Neher (HLRS) implemented the foundations for TrixiParticles.jl and are principal developers along with Sven Berger (hereon). -The project was started by Michael Schlottke-Lakemper (RWTH Aachen University/HLRS) +The project was started by Michael Schlottke-Lakemper (University of Augsburg) and Gregor Gassner (University of Cologne), who provide scientific direction and technical advice. The full list of contributors can be found in [AUTHORS.md](AUTHORS.md).