-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
183 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
include("alive.jl") | ||
include("analysis.jl") | ||
include("save_solution.jl") | ||
include("stepsize.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
# TODO: Taal, implement, save AMR indicator values | ||
# TODO: Taal, refactor, allow saving arbitrary functions of the conservative variables | ||
mutable struct SaveSolutionCallback | ||
save_initial_solution::Bool | ||
save_final_solution::Bool | ||
output_directory::String | ||
solution_variables::Symbol | ||
end | ||
|
||
|
||
function Base.show(io::IO, cb::DiscreteCallback{Condition,Affect!}) where {Condition, Affect!<:SaveSolutionCallback} | ||
stepsize_callback = cb.affect! | ||
print(io, "SaveSolutionCallback") | ||
end | ||
# TODO: Taal bikeshedding, implement a method with more information and the signature | ||
# function Base.show(io::IO, ::MIME"text/plain", cb::DiscreteCallback{Condition,Affect!}) where {Condition, Affect!<:StepsizeCallback} | ||
# end | ||
|
||
|
||
function SaveSolutionCallback(; solution_interval=0, | ||
save_initial_solution=true, | ||
save_final_solution=true, | ||
output_directory="out", | ||
solution_variables=:primitive) | ||
condition = (u, t, integrator) -> solution_interval > 0 && ((integrator.iter % solution_interval == 0) || (save_final_solution && t == integrator.sol.prob.tspan[2])) | ||
|
||
solution_callback = SaveSolutionCallback(save_initial_solution, save_final_solution, | ||
output_directory, solution_variables) | ||
|
||
DiscreteCallback(condition, solution_callback, | ||
save_positions=(false,false), | ||
initialize=initialize!) | ||
end | ||
|
||
|
||
function initialize!(cb::DiscreteCallback{Condition,Affect!}, u, t, integrator) where {Condition, Affect!<:SaveSolutionCallback} | ||
reset_timer!(timer()) | ||
solution_callback = cb.affect! | ||
|
||
mkpath(solution_callback.output_directory) | ||
|
||
semi = integrator.p | ||
@unpack mesh = semi | ||
mesh.unsaved_changes = true | ||
|
||
if solution_callback.save_initial_solution | ||
solution_callback(integrator) | ||
end | ||
|
||
return nothing | ||
end | ||
|
||
|
||
function (solution_callback::SaveSolutionCallback)(integrator) | ||
@unpack u, t, dt, iter = integrator | ||
semi = integrator.p | ||
@unpack mesh, equations, solver, cache = semi | ||
|
||
@timeit_debug timer() "I/O" begin | ||
if mesh.unsaved_changes | ||
mesh.current_filename = save_mesh_file(mesh, solution_callback.output_directory, iter) | ||
mesh.unsaved_changes = false | ||
end | ||
|
||
save_solution_file(u, t, dt, iter, mesh, equations, solver, cache, solution_callback) | ||
end | ||
|
||
return nothing | ||
end | ||
|
||
|
||
# function save_mesh_file(mesh::TreeMesh, output_directory, timestep=-1) in io/io.jl | ||
# | ||
|
||
include("save_solution_dg.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
function save_solution_file(u, time, dt, timestep, | ||
mesh, equations, dg::DG, cache, | ||
solution_callback) | ||
@unpack output_directory, solution_variables = solution_callback | ||
|
||
# Filename without extension based on current time step | ||
filename = joinpath(output_directory, @sprintf("solution_%06d.h5", timestep)) | ||
|
||
# Convert time and time step size to floats | ||
time = convert(Float64, time) | ||
dt = convert(Float64, dt) | ||
|
||
# Open file (clobber existing content) | ||
h5open(filename, "w") do file | ||
# Add context information as attributes | ||
attrs(file)["ndims"] = ndims(mesh) | ||
attrs(file)["equations"] = get_name(equations) | ||
attrs(file)["polydeg"] = polydeg(dg) | ||
attrs(file)["n_vars"] = nvariables(equations) | ||
attrs(file)["n_elements"] = nelements(dg, cache) | ||
attrs(file)["mesh_file"] = splitdir(mesh.current_filename)[2] | ||
attrs(file)["time"] = time | ||
attrs(file)["dt"] = dt | ||
attrs(file)["timestep"] = timestep | ||
|
||
# Convert to primitive variables if requested | ||
if solution_variables === :conservative | ||
data = u | ||
varnames = varnames_cons(equations) | ||
elseif solution_variables === :primitive | ||
# Reinterpret the solution array as an array of conservative variables, | ||
# compute the primitive variables via broadcasting, and reinterpret the | ||
# result as a plain array of floating point numbers | ||
data = Array(reinterpret(eltype(u), | ||
cons2prim.(reinterpret(SVector{nvariables(equations),eltype(u)}, u), | ||
Ref(equations)))) | ||
varnames = varnames_prim(equations) | ||
else | ||
error("Unknown solution_variables $solution_variables") | ||
end | ||
|
||
# Store each variable of the solution | ||
for v in eachvariable(equations) | ||
# Convert to 1D array | ||
file["variables_$v"] = vec(data[v, .., :]) | ||
|
||
# Add variable name as attribute | ||
var = file["variables_$v"] | ||
attrs(var)["name"] = varnames[v] | ||
end | ||
|
||
# TODO: Taal implement, save element variables | ||
# Store element variables | ||
# for (v, (key, element_variables)) in enumerate(cache.element_variables) | ||
# # Add to file | ||
# file["element_variables_$v"] = element_variables | ||
|
||
# # Add variable name as attribute | ||
# var = file["element_variables_$v"] | ||
# attrs(var)["name"] = string(key) | ||
# end | ||
end | ||
|
||
return filename | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters