Skip to content

Commit

Permalink
Merge branch 'main' into threaded-macro-gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber committed Jun 19, 2024
2 parents 8e8efa8 + 39bc798 commit 6f6e02d
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]),
or any other of the principal developers responsible for enforcement listed in
[AUTHORS.md](AUTHORS.md).
Expand Down Expand Up @@ -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.
https://www.contributor-covenant.org/translations.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ SciMLBase = "1, 2"
StaticArrays = "1"
StrideArrays = "0.1"
TimerOutputs = "0.5"
TrixiBase = "0.1"
TrixiBase = "0.1.3"
WriteVTK = "1"
julia = "1.9"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
4 changes: 2 additions & 2 deletions examples/n_body/n_body_benchmark_trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end
filename = tempname()
open(filename, "w") do f
redirect_stderr(f) do
TrixiParticles.TimerOutputs.disable_debug_timings(TrixiParticles)
TrixiParticles.disable_debug_timings()
end
end

Expand All @@ -124,6 +124,6 @@ end
# Enable timers again
open(filename, "w") do f
redirect_stderr(f) do
TrixiParticles.TimerOutputs.enable_debug_timings(TrixiParticles)
TrixiParticles.enable_debug_timings()
end
end
4 changes: 2 additions & 2 deletions examples/n_body/n_body_solar_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ callbacks = CallbackSet(info_callback, saving_callback)
filename = tempname()
open(filename, "w") do f
redirect_stderr(f) do
TrixiParticles.TimerOutputs.disable_debug_timings(TrixiParticles)
TrixiParticles.disable_debug_timings()
end
end

Expand All @@ -63,6 +63,6 @@ sol = solve(ode, SymplecticEuler(),
# Enable timers again
open(filename, "w") do f
redirect_stderr(f) do
TrixiParticles.TimerOutputs.enable_debug_timings(TrixiParticles)
TrixiParticles.enable_debug_timings()
end
end
22 changes: 22 additions & 0 deletions examples/postprocessing/interpolation_plane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,25 @@ plot_3d = Plots.plot(scatter_3d, xlabel="X", ylabel="Y", zlabel="Z",

combined_plot = Plots.plot(plot1, plot2, plot3, plot_3d, layout=(2, 2),
size=(1000, 1500), margin=3mm)

# If we want to save planes at regular intervals, we can use the postprocessing callback.
function save_interpolated_plane(v, u, t, system)
# Size of the patch to be interpolated
interpolation_start = [0.0, 0.0]
interpolation_end = [tank_size[1], tank_size[2]]

# The resolution the plane is interpolated to. In this case twice the original resolution.
resolution = 0.5 * fluid_particle_spacing

file_id = ceil(Int, t * 10000)
interpolate_plane_2d_vtk(interpolation_start, interpolation_end, resolution,
semi, system, v, u, filename="plane_$file_id.vti")
return nothing
end

save_interpolation_cb = PostprocessCallback(; dt=0.1, write_file_interval=0,
save_interpolated_plane)

trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid", "dam_break_2d.jl"), tspan=(0.0, 0.2),
extra_callback=save_interpolation_cb, fluid_particle_spacing=0.01)
3 changes: 2 additions & 1 deletion src/TrixiParticles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ using SciMLBase: CallbackSet, DiscreteCallback, DynamicalODEProblem, u_modified!
using StaticArrays: @SMatrix, SMatrix, setindex
using StrideArrays: PtrArray, StaticInt
using TimerOutputs: TimerOutput, TimerOutputs, print_timer, reset_timer!
using TrixiBase: trixi_include
using TrixiBase: trixi_include, @trixi_timeit, timer, timeit_debug_enabled,
disable_debug_timings, enable_debug_timings
@reexport using PointNeighbors: TrivialNeighborhoodSearch, GridNeighborhoodSearch
using PointNeighbors: PointNeighbors, for_particle_neighbor
using WriteVTK: vtk_grid, MeshCell, VTKCellTypes, paraview_collection, vtk_save
Expand Down
15 changes: 10 additions & 5 deletions src/callbacks/post_process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct PostprocessCallback{I, F}
append_timestamp :: Bool
write_csv :: Bool
write_json :: Bool
git_hash :: Ref{String}
end

function PostprocessCallback(; interval::Integer=0, dt=0.0, exclude_boundary=true,
Expand All @@ -94,7 +95,8 @@ function PostprocessCallback(; interval::Integer=0, dt=0.0, exclude_boundary=tru
post_callback = PostprocessCallback(interval, write_file_interval,
Dict{String, Vector{Any}}(), Float64[],
exclude_boundary, funcs, filename, output_directory,
append_timestamp, write_csv, write_json)
append_timestamp, write_csv, write_json,
Ref("UnknownVersion"))
if dt > 0
# Add a `tstop` every `dt`, and save the final solution
return PeriodicCallback(post_callback, dt,
Expand Down Expand Up @@ -209,9 +211,12 @@ function initialize_postprocess_callback!(cb, u, t, integrator)
end

function initialize_postprocess_callback!(cb::PostprocessCallback, u, t, integrator)
cb.git_hash[] = compute_git_hash()

# Apply the callback
cb(integrator)
return nothing

return cb
end

# `condition` with interval
Expand Down Expand Up @@ -281,7 +286,7 @@ function write_postprocess_callback(pp::PostprocessCallback)
mkpath(pp.output_directory)

data = Dict{String, Any}()
write_meta_data!(data)
write_meta_data!(data, pp.git_hash[])
prepare_series_data!(data, pp)

time_stamp = ""
Expand Down Expand Up @@ -331,9 +336,9 @@ function create_series_dict(values, times, system_name="")
"time" => times)
end

function write_meta_data!(data)
function write_meta_data!(data, git_hash)
meta_data = Dict("solver_name" => "TrixiParticles.jl",
"solver_version" => get_git_hash(),
"solver_version" => git_hash,
"julia_version" => string(VERSION))

data["meta"] = meta_data
Expand Down
16 changes: 8 additions & 8 deletions src/callbacks/solution_saving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ mutable struct SolutionSavingCallback{I, CQ}
max_coordinates :: Float64
custom_quantities :: CQ
latest_saved_iter :: Int
git_hash :: Ref{String}
end

function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
Expand All @@ -102,7 +103,7 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
save_initial_solution, save_final_solution,
write_meta_data, verbose, output_directory,
prefix, max_coordinates, custom_quantities,
-1)
-1, Ref("UnknownVersion"))

if length(save_times) > 0
# See the large comment below for an explanation why we use `finalize` here
Expand Down Expand Up @@ -131,6 +132,7 @@ end
function initialize_save_cb!(solution_callback::SolutionSavingCallback, u, t, integrator)
# Reset `latest_saved_iter`
solution_callback.latest_saved_iter = -1
solution_callback.git_hash[] = compute_git_hash()

# Save initial solution
if solution_callback.save_initial_solution
Expand All @@ -156,7 +158,7 @@ end

# `affect!`
function (solution_callback::SolutionSavingCallback)(integrator)
(; interval, output_directory, custom_quantities, write_meta_data,
(; interval, output_directory, custom_quantities, write_meta_data, git_hash,
verbose, prefix, latest_saved_iter, max_coordinates) = solution_callback

vu_ode = integrator.u
Expand All @@ -178,12 +180,10 @@ function (solution_callback::SolutionSavingCallback)(integrator)
println("Writing solution to $output_directory at t = $(integrator.t)")
end

@trixi_timeit timer() "save solution" trixi2vtk(vu_ode, semi, integrator.t; iter=iter,
output_directory=output_directory,
prefix=prefix,
write_meta_data=write_meta_data,
max_coordinates=max_coordinates,
custom_quantities...)
@trixi_timeit timer() "save solution" trixi2vtk(vu_ode, semi, integrator.t;
iter, output_directory, prefix,
write_meta_data, git_hash=git_hash[],
max_coordinates, custom_quantities...)

# Tell OrdinaryDiffEq that `u` has not been modified
u_modified!(integrator, false)
Expand Down
31 changes: 0 additions & 31 deletions src/general/file_system.jl

This file was deleted.

1 change: 0 additions & 1 deletion src/general/general.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ include("corrections.jl")
include("smoothing_kernels.jl")
include("initial_condition.jl")
include("interpolation.jl")
include("file_system.jl")
include("custom_quantities.jl")
include("neighborhood_search.jl")
60 changes: 18 additions & 42 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,6 @@ function print_startup_message()
println(s)
end

# Enable debug timings `@trixi_timeit timer() "name" stuff...`.
# This allows us to disable timings completely by executing
# `TimerOutputs.disable_debug_timings(TrixiParticles)`
# and to enable them again by executing
# `TimerOutputs.enable_debug_timings(TrixiParticles)`
timeit_debug_enabled() = true

# Store main timer for global timing of functions
const main_timer = TimerOutput()

# Always call timer() to hide implementation details
timer() = main_timer

# @trixi_timeit timer() "some label" expression
#
# Basically the same as a special case of `@timeit_debug` from
# [TimerOutputs.jl](https://github.com/KristofferC/TimerOutputs.jl),
# but without `try ... finally ... end` block. Thus, it's not exception-safe,
# but it also avoids some related performance problems. Since we do not use
# exception handling in TrixiParticles, that's not really an issue.
#
# Copied from [Trixi.jl](https://github.com/trixi-framework/Trixi.jl).
macro trixi_timeit(timer_output, label, expr)
timeit_block = quote
if timeit_debug_enabled()
local to = $(esc(timer_output))
local enabled = to.enabled
if enabled
local accumulated_data = $(TimerOutputs.push!)(to, $(esc(label)))
end
local b0 = $(TimerOutputs.gc_bytes)()
local t0 = $(TimerOutputs.time_ns)()
end
local val = $(esc(expr))
if timeit_debug_enabled() && enabled
$(TimerOutputs.do_accumulate!)(accumulated_data, t0, b0)
$(TimerOutputs.pop!)(to)
end
val
end
end

"""
@threaded system for ... end
Expand Down Expand Up @@ -223,3 +181,21 @@ end
function type2string(type)
return string(nameof(typeof(type)))
end

function compute_git_hash()
pkg_directory = pkgdir(@__MODULE__)
git_directory = joinpath(pkg_directory, ".git")

# Check if the .git directory exists
if !isdir(git_directory)
return "UnknownVersion"
end

try
git_cmd = Cmd(`git describe --tags --always --first-parent --dirty`,
dir=pkg_directory)
return string(readchomp(git_cmd))
catch e
return "UnknownVersion"
end
end
Loading

0 comments on commit 6f6e02d

Please sign in to comment.