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

work in progress #6

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77"
26 changes: 14 additions & 12 deletions src/DiscSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@ module DiscSimulations
using LinearAlgebra
using Plots
using Printf

include("solution.jl")

include("burgers/utils.jl")
#include("burgers/spectral.jl")
#include("burgers/simple.jl")
include("simpleGravitySim/simulation.jl")
include("younsi-2012.jl")
include("Euler_with_source.jl")
include("burgers/trixi.jl")

##need to add functype constructors??
using TruncatedStacktraces
TruncatedStacktraces.VERBOSE[] = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


#struct Parameters{T,DensityFuncType,SourceFuncType}
struct Parameters{T}
Expand All @@ -36,6 +26,18 @@ main(p::Parameters, ::BurgersSimulation) = BurgerTrixi.solve_disc(p.N, p.xmax)
main(p::Parameters, ::EulerWithSourceSimulation) = EulerSource.solve_euler(p.source)
main(p::Parameters, ::SimpleGravitySimulation) = SimpleGravitySimulation.solve_gravity_sim(p.ρ)

include("solution.jl")

include("burgers/utils.jl")
include("burgers/trixi.jl")
#include("burgers/spectral.jl")
#include("burgers/simple.jl")
include("simpleGravitySim/simpleGravity.jl")
include("simpleGravitySim/simulation.jl")
include("younsi-2012.jl")
include("Euler_with_source.jl")


export Parameters, SimulationType, BurgersSimulation, EulerWithSourceSimulation, SimpleGravitySimulation

end # module DiscSimulations
17 changes: 6 additions & 11 deletions src/burgers/trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ using DifferentialEquations
using Plots
using Printf

include("utils.jl")
using .BurgerUtils
import DiscSimulations:
STANDARD_BURGER_INIT, STANDARD_BURGER_TSPAN, DiscSolution, OneDimension

include("../solution.jl")

#import DiscSimulations:
# BurgerUtils.STANDARD_BURGER_INIT, BurgerUtils.STANDARD_BURGER_TSPAN, DiscSolution, OneDimension

function setup(N, x_max, init = BurgerUtils.STANDARD_BURGER_INIT, t_span = BurgerUtils.STANDARD_BURGER_TSPAN)
function setup(N, x_max, init = STANDARD_BURGER_INIT, t_span = STANDARD_BURGER_TSPAN)
x_min = 0.0

equations = InviscidBurgersEquation1D()
Expand All @@ -22,12 +17,12 @@ function setup(N, x_max, init = BurgerUtils.STANDARD_BURGER_INIT, t_span = Burge
mesh = TreeMesh(x_min, x_max, initial_refinement_level = 3, n_cells_max = N)
semi = SemidiscretizationHyperbolic(mesh, equations, (x, t, eqs) -> init(x), solver)

problem = semidiscretize(semi, t_span)
ode = semidiscretize(semi, t_span)

semi, problem
semi, ode
end

function solve_disc(N, x_max, init = BurgerUtils.STANDARD_BURGER_INIT, t_span = BurgerUtils.STANDARD_BURGER_TSPAN)
function solve_disc(N, x_max, init = STANDARD_BURGER_INIT, t_span = STANDARD_BURGER_TSPAN)
semi, problem = setup(N, x_max, init, t_span)
sol = solve(problem, RDPK3SpFSAL49(), abstol = 1.0e-7, reltol = 1.0e-7)
return DiscSolution(sol, semi, OneDimension())
Expand Down
8 changes: 1 addition & 7 deletions src/burgers/utils.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module BurgerUtils

function central_difference(Δu, N)
lower = -ones(Float64, N - 1)
mid = zeros(Float64, N)
Expand All @@ -11,8 +9,4 @@ function STANDARD_BURGER_INIT(x)
@. 1 - cos(x)
end

const STANDARD_BURGER_TSPAN = (0.0, 1.0)

end # module BurgerUtils

export BurgerUtils
const STANDARD_BURGER_TSPAN = (0.0, 1.0)
4 changes: 2 additions & 2 deletions src/simpleGravitySim/simulation.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module simpleGravitySimulation

include("./simpleGravity.jl")
using .simpleGravity
import DiscSimulations:
simpleGravity
using Trixi
using OrdinaryDiffEq
using Plots
Expand Down
23 changes: 13 additions & 10 deletions src/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,33 @@ function DiscSolution(sol, semi, dimension_type::AbstractDimension)
end

#1D version of plot
function dataplot(solution::DiscSolution{<:OneDimension}, t)
return PlotData1D(solution.sol(t), solution.semi)
function dataplot(solution::DiscSolution{<:OneDimension}, solver, t)
return PlotData1D(solver(t), solution.semi)
end

#2D version of plot
function dataplot(solution::DiscSolution{<:TwoDimension}, t)
return PlotData2D(solution.sol(t), solution.semi)
function dataplot(solution::DiscSolution{<:TwoDimension}, solver, t)
return PlotData2D(solver(t), solution.semi)
end

dataplot(solution::DiscSolution{<:AbstractDimension}, t) = error("Unknown simulation type: $(typeof(t))")

function plotgif(solution, tmin, tmax, kwargs...)
function plotgif(solution::DiscSolution, tmin, tmax)#, kwargs...)
fjebaker marked this conversation as resolved.
Show resolved Hide resolved
ts = range(tmin, tmax, 150)
solver = @time solution.sol
frames = Plots.@animate for t in ts
pd = dataplot(solution, t)
pd = dataplot(solution, solver, t)
plot(
pd,
label = Printf.@sprintf("t = %1.2f", t),
kwargs
#ylims = (-1, 1.1),
legend = :topright
#kwargs
)
end
gif(frames, "temp.gif", fps = 10) |> display
end

#function Base.show(io::IO, sol::DiscSolution)
# println(io, sol.sol, sol.semi)
#end
function Base.show(io::IO, sol::DiscSolution)
println(io, string(typeof(sol)))
end
fjebaker marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions src/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ source_zero(u, x, t, equations) = SVector(0, 0, 0)
params = DiscSimulations.Parameters(512, 0.0, 2π, initial_condition_sine, source_zero)

solution = DiscSimulations.main(params, DiscSimulations.BurgersSimulation())
DiscSimulations.Base.show(IO, solution)
DiscSimulations.plotgif(solution, 0.0, 2.0)
s = DiscSimulations.DiscSolution(solution.sol, solution.semi, DiscSimulations.OneDimension())
kwargs = ["ylims = (-1, 1.1)", "legend = :topright"]
DiscSimulations.plotgif(s, 0.0, 2.0)#, kwargs)
Binary file modified temp.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.