Skip to content

Commit

Permalink
Merge branch 'gpu2' into gpu3
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber committed Apr 23, 2024
2 parents 4125f2e + 33aed49 commit fe2911a
Show file tree
Hide file tree
Showing 19 changed files with 1,126 additions and 556 deletions.
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
TrixiBase = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284"
TrixiParticles = "66699cd8-9c01-4e9d-a059-b96c86d16b3a"

[compat]
Documenter = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/TrixiParticles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export GridNeighborhoodSearch, TrivialNeighborhoodSearch
export examples_dir, validation_dir, trixi_include
export trixi2vtk
export RectangularTank, RectangularShape, SphereShape
export VoxelSphere, RoundSphere, reset_wall!
export VoxelSphere, RoundSphere, reset_wall!, extrude_geometry
export SourceTermDamping
export ShepardKernelCorrection, KernelCorrection, AkinciFreeSurfaceCorrection,
GradientCorrection, BlendedGradientCorrection, MixedKernelGradientCorrection
Expand Down
8 changes: 4 additions & 4 deletions src/callbacks/post_process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ function PostprocessCallback(; interval::Integer=0, dt=0.0, exclude_boundary=tru
exclude_boundary, funcs, filename, output_directory,
append_timestamp, write_csv, write_json)
if dt > 0
# Add a `tstop` every `dt`, and save the final solution.
# Add a `tstop` every `dt`, and save the final solution
return PeriodicCallback(post_callback, dt,
initialize=initialize_postprocess_callback!,
save_positions=(false, false), final_affect=true)
else
# The first one is the condition, the second the affect!
# The first one is the `condition`, the second the `affect!`
return DiscreteCallback(post_callback, post_callback,
save_positions=(false, false),
initialize=initialize_postprocess_callback!)
Expand Down Expand Up @@ -214,7 +214,7 @@ function initialize_postprocess_callback!(cb::PostprocessCallback, u, t, integra
return nothing
end

# condition with interval
# `condition` with interval
function (pp::PostprocessCallback)(u, t, integrator)
(; interval) = pp

Expand Down Expand Up @@ -260,7 +260,7 @@ function (pp::PostprocessCallback)(integrator)
write_postprocess_callback(pp)
end

# Tell OrdinaryDiffEq that u has not been modified
# Tell OrdinaryDiffEq that `u` has not been modified
u_modified!(integrator, false)
end

Expand Down
67 changes: 59 additions & 8 deletions src/callbacks/solution_saving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
-1)

if length(save_times) > 0
return PresetTimeCallback(save_times, solution_callback)
# See the large comment below for an explanation why we use `finalize` here
return PresetTimeCallback(save_times, solution_callback, finalize=solution_callback)
elseif dt > 0
# Add a `tstop` every `dt`, and save the final solution.
# Add a `tstop` every `dt`, and save the final solution
return PeriodicCallback(solution_callback, dt,
initialize=initialize_save_cb!,
save_positions=(false, false),
final_affect=save_final_solution)
else
# The first one is the condition, the second the affect!
# The first one is the `condition`, the second the `affect!`
return DiscreteCallback(solution_callback, solution_callback,
save_positions=(false, false),
initialize=initialize_save_cb!)
Expand All @@ -132,27 +133,27 @@ function initialize_save_cb!(solution_callback::SolutionSavingCallback, u, t, in

# Save initial solution
if solution_callback.save_initial_solution
# Update systems to compute quantities like density and pressure.
# Update systems to compute quantities like density and pressure
semi = integrator.p
v_ode, u_ode = u.x
update_systems_and_nhs(v_ode, u_ode, semi, t)

# Apply the callback.
# Apply the callback
solution_callback(integrator)
end

return nothing
end

# condition
# `condition`
function (solution_callback::SolutionSavingCallback)(u, t, integrator)
(; interval, save_final_solution) = solution_callback

return condition_integrator_interval(integrator, interval,
save_final_solution=save_final_solution)
end

# affect!
# `affect!`
function (solution_callback::SolutionSavingCallback)(integrator)
(; interval, output_directory, custom_quantities, write_meta_data,
verbose, prefix, latest_saved_iter, max_coordinates) = solution_callback
Expand Down Expand Up @@ -183,12 +184,30 @@ function (solution_callback::SolutionSavingCallback)(integrator)
max_coordinates=max_coordinates,
custom_quantities...)

# Tell OrdinaryDiffEq that u has not been modified
# Tell OrdinaryDiffEq that `u` has not been modified
u_modified!(integrator, false)

return nothing
end

# `finalize`
# This is a hack to make dispatch on a `PresetTimeCallback` possible.
#
# The type of the returned `DiscreteCallback` is
# `DiscreteCallback{typeof(condition), typeof(affect!), typeof(initialize), typeof(finalize)}`.
# For the `PeriodicCallback`, `typeof(affect!)` contains the type of the
# `SolutionSavingCallback`. The `PresetTimeCallback` uses anonymous functions as `condition`
# and `affect!`, so this doesn't work here.
#
# This hacky workaround makes use of the type parameter `typeof(finalize)` above.
# It's set to `FINALIZE_DEFAULT` by default in the `PresetTimeCallback`, which is a function
# that just returns `nothing`.
# Instead, we pass the `SolutionSavingCallback` as `finalize`, and define it to also just
# return `nothing` when called as `initialize`.
function (finalize::SolutionSavingCallback)(c, u, t, integrator)
return nothing
end

function Base.show(io::IO, cb::DiscreteCallback{<:Any, <:SolutionSavingCallback})
@nospecialize cb # reduce precompilation time

Expand All @@ -205,6 +224,14 @@ function Base.show(io::IO,
print(io, "SolutionSavingCallback(dt=", solution_saving.interval, ")")
end

function Base.show(io::IO,
cb::DiscreteCallback{<:Any, <:Any, <:Any, <:SolutionSavingCallback})
@nospecialize cb # reduce precompilation time

solution_saving = cb.finalize
print(io, "SolutionSavingCallback(save_times=", solution_saving.save_times, ")")
end

function Base.show(io::IO, ::MIME"text/plain",
cb::DiscreteCallback{<:Any, <:SolutionSavingCallback})
@nospecialize cb # reduce precompilation time
Expand All @@ -229,6 +256,30 @@ function Base.show(io::IO, ::MIME"text/plain",
end
end

function Base.show(io::IO, ::MIME"text/plain",
cb::DiscreteCallback{<:Any, <:Any, <:Any, <:SolutionSavingCallback})
@nospecialize cb # reduce precompilation time

if get(io, :compact, false)
show(io, cb)
else
solution_saving = cb.finalize
cq = collect(solution_saving.custom_quantities)

setup = [
"save_times" => solution_saving.save_times,
"custom quantities" => isempty(cq) ? nothing : cq,
"save initial solution" => solution_saving.save_initial_solution ?
"yes" : "no",
"save final solution" => solution_saving.save_final_solution ? "yes" :
"no",
"output directory" => abspath(solution_saving.output_directory),
"prefix" => solution_saving.prefix,
]
summary_box(io, "SolutionSavingCallback", setup)
end
end

function Base.show(io::IO, ::MIME"text/plain",
cb::DiscreteCallback{<:Any,
<:PeriodicCallbackAffect{<:SolutionSavingCallback}})
Expand Down
Loading

0 comments on commit fe2911a

Please sign in to comment.