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

Cb refactor #675

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
52 changes: 52 additions & 0 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,58 @@ end
(save_final_solution && isfinished(integrator)))
end

function validate_interval_and_dt(interval, dt)
if interval == 0 && dt == 0.0
throw(ArgumentError("Both interval and dt cannot be zero. Specify at least one."))
end
if interval < 0 || dt < 0
throw(ArgumentError("Negative interval or dt values are not supported."))
end
if dt > 0 && interval > 0
throw(ArgumentError("Setting both interval and dt is not supported."))
end
end

mutable struct OutputConfig
output_directory::String
filename::String
prefix::String
append_timestamp::Bool
verbose::Bool

function OutputConfig(;
output_directory::String="out",
filename::String="output",
prefix::String="",
append_timestamp::Bool=false,
verbose::Bool=false)
new(output_directory, filename, prefix, append_timestamp, verbose)
end
end

function build_filepath(config::OutputConfig; extension::String="")
# Prepare output directory
output_directory = config.output_directory

# Add timestamp subdirectory if required
if config.append_timestamp
timestamp = Dates.format(Dates.now(), "YY-mm-ddTHHMMSS")
output_directory = joinpath(output_directory, timestamp)
mkpath(output_directory)
end

# Combine prefix and filename
base_filename = config.prefix * config.filename

# Add file extension if provided
if !isempty(extension)
base_filename *= "." * extension
end

# Construct the full path
return joinpath(output_directory, base_filename)
end

include("info.jl")
include("solution_saving.jl")
include("density_reinit.jl")
Expand Down
4 changes: 1 addition & 3 deletions src/callbacks/density_reinit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ end

function DensityReinitializationCallback(particle_system; interval::Integer=0, dt=0.0,
reinit_initial_solution=true)
if dt > 0 && interval > 0
error("Setting both interval and dt is not supported!")
end
validate_interval_and_dt(interval, dt)

if dt > 0
interval = Float64(dt)
Expand Down
Loading
Loading