-
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
9 changed files
with
162 additions
and
431 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 was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
examples/tree_2d_dgsem/elixir_advection_amr_visualization_makie.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,78 @@ | ||
|
||
using OrdinaryDiffEq | ||
using Trixi | ||
using GLMakie | ||
|
||
############################################################################### | ||
# semidiscretization of the linear advection equation | ||
|
||
advection_velocity = (0.2, -0.7) | ||
equations = LinearScalarAdvectionEquation2D(advection_velocity) | ||
|
||
function initial_condition_gauss_largedomain(x, t, | ||
equation::LinearScalarAdvectionEquation2D) | ||
# Store translated coordinate for easy use of exact solution | ||
domain_length = SVector(10, 10) | ||
x_trans = Trixi.x_trans_periodic_2d(x - equation.advection_velocity * t, domain_length) | ||
|
||
return SVector(exp(-(x_trans[1]^2 + x_trans[2]^2))) | ||
end | ||
initial_condition = initial_condition_gauss_largedomain | ||
|
||
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) | ||
|
||
coordinates_min = (-5.0, -5.0) | ||
coordinates_max = (5.0, 5.0) | ||
mesh = TreeMesh(coordinates_min, coordinates_max, | ||
initial_refinement_level = 3, | ||
n_cells_max = 30_000) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) | ||
|
||
############################################################################### | ||
# ODE solvers, callbacks etc. | ||
|
||
tspan = (0.0, 200.0) | ||
ode = semidiscretize(semi, tspan) | ||
|
||
summary_callback = SummaryCallback() | ||
|
||
analysis_interval = 100 | ||
analysis_callback = AnalysisCallback(semi, interval = analysis_interval, | ||
extra_analysis_integrals = (entropy,)) | ||
|
||
alive_callback = AliveCallback(analysis_interval = analysis_interval) | ||
|
||
save_solution = SaveSolutionCallback(interval = 100, | ||
save_initial_solution = true, | ||
save_final_solution = true, | ||
solution_variables = cons2prim) | ||
|
||
# Enable in-situ visualization with a new plot generated every 20 time steps | ||
# and additional plotting options passed as keyword arguments | ||
visualization = VisualizationCallback(interval = 100, clims = (0, 1), | ||
plot_creator = Trixi.show_plot_makie) | ||
|
||
amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first), | ||
base_level = 3, | ||
med_level = 4, med_threshold = 0.1, | ||
max_level = 5, max_threshold = 0.6) | ||
amr_callback = AMRCallback(semi, amr_controller, | ||
interval = 5, | ||
adapt_initial_condition = true, | ||
adapt_initial_condition_only_refine = true) | ||
|
||
stepsize_callback = StepsizeCallback(cfl = 1.6) | ||
|
||
callbacks = CallbackSet(summary_callback, | ||
analysis_callback, alive_callback, | ||
save_solution, visualization, | ||
amr_callback, stepsize_callback); | ||
|
||
############################################################################### | ||
# run the simulation | ||
|
||
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false), | ||
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback | ||
save_everystep = false, callback = callbacks); | ||
summary_callback() # print the timer summary |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
# Package extension for adding Makie-based features to Trixi.jl | ||
module TrixiGLMakieExt | ||
|
||
# Required for visualization code | ||
using GLMakie | ||
|
||
# Use functions that are to be extended and additional symbols that are not exported | ||
using Trixi: Trixi, @unpack, @muladd | ||
|
||
@muladd begin | ||
#! format: noindent | ||
|
||
# converts a single int into a tuple of ints, to get a square arrangement | ||
# example: f(1) = (1,1) f(2) = (2,1) f(3) = (2,2) f(4) = (1,2) | ||
function makieLayoutHelper(n) | ||
if n == 1 | ||
return (1, 1) | ||
end | ||
t = makieLayoutHelper(n - 1) | ||
if t[1] == 1 | ||
return (t[2] + 1, 1) | ||
elseif t[1] > t[2] | ||
return (t[1], t[2] + 1) | ||
elseif t[2] >= t[1] | ||
return (t[1] - 1, t[2]) | ||
end | ||
end | ||
|
||
function Trixi.show_plot_makie(visualization_callback, plot_data, variable_names; | ||
show_mesh = true, plot_arguments = Dict{Symbol, Any}(), | ||
time = nothing, timestep = nothing) | ||
if visualization_callback.figure === nothing | ||
@info "Creating new GLMakie figure" | ||
visualization_callback.figure = GLMakie.Figure() | ||
for v in 1:size(variable_names)[1] | ||
push!(visualization_callback.axis, | ||
GLMakie.Axis(visualization_callback.figure[makieLayoutHelper(v)...], | ||
title = variable_names[v])) | ||
end | ||
GLMakie.display(visualization_callback.figure) | ||
end | ||
|
||
@unpack axis = visualization_callback | ||
for v in 1:size(variable_names)[1] | ||
GLMakie.heatmap!(axis[v], plot_data.x, plot_data.y, plot_data.data[v]) | ||
end | ||
sleep(1) | ||
|
||
# TODO: handle `show_mesh` | ||
end | ||
end # @muladd | ||
end # module TrixiGLMakieExt |
Oops, something went wrong.