Skip to content

Commit

Permalink
Format advection basic
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyuxie committed Aug 20, 2024
1 parent 3aa884c commit 0b13dff
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use Blue style
style = "blue"
# Use SciML style
style = "sciml"

# Additional Options
yas_style_nesting = true
Expand Down
87 changes: 46 additions & 41 deletions examples/advection_basic_1d.jl
Original file line number Diff line number Diff line change
@@ -1,55 +1,60 @@
using Trixi, TrixiGPU
using OrdinaryDiffEq

# The example is taken from the Trixi.jl

###############################################################################
# semidiscretization of the linear advection equation

advection_velocity = 1.0
equations = LinearScalarAdvectionEquation1D(advection_velocity)

solver = DGSEM(; polydeg=3, surface_flux=flux_lax_friedrichs)
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = -1.0
coordinates_max = 1.0
coordinates_min = -1.0 # minimum coordinate
coordinates_max = 1.0 # maximum coordinate

mesh = TreeMesh(
coordinates_min, coordinates_max; initial_refinement_level=4, n_cells_max=30_000
)
# Create a uniformly refined mesh with periodic boundaries
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 4,
n_cells_max = 30_000) # set maximum capacity of tree data structure

semi = SemidiscretizationHyperbolic(
mesh, equations, initial_condition_convergence_test, solver
)
# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
solver)

tspan = (0.0, 1.0)
###############################################################################
# ODE solvers, callbacks etc.

ode = semidiscretize_gpu(semi, tspan) # from TrixiGPU.jl
# Create ODE problem with time span from 0.0 to 1.0
ode = semidiscretize_gpu(semi, (0.0, 1.0)) # from TrixiGPU.jl

# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(
semi;
interval=analysis_interval,
extra_analysis_errors=(:l2_error_primitive, :linf_error_primitive),
)

alive_callback = AliveCallback(; analysis_interval=analysis_interval)

save_solution = SaveSolutionCallback(;
interval=100,
save_initial_solution=true,
save_final_solution=true,
solution_variables=cons2prim,
)

stepsize_callback = StepsizeCallback(; cfl=0.8)

callbacks = CallbackSet(
summary_callback, analysis_callback, alive_callback, save_solution, stepsize_callback
)

sol = solve(
ode,
CarpenterKennedy2N54(; williamson_condition=false);
dt=1.0,
save_everystep=false,
callback=callbacks,
);
summary_callback()
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_callback = AnalysisCallback(semi, interval = 100)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
save_solution = SaveSolutionCallback(interval = 100,
solution_variables = cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
stepsize_callback = StepsizeCallback(cfl = 1.6)

# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
stepsize_callback)

###############################################################################
# run the simulation

# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
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);

# Print the timer summary
summary_callback()
67 changes: 42 additions & 25 deletions examples/advection_basic_2d.jl
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
using Trixi, TrixiGPU
using OrdinaryDiffEq

# The example is taken from the Trixi.jl

###############################################################################
# semidiscretization of the linear advection equation

advection_velocity = (0.2, -0.7)
equations = LinearScalarAdvectionEquation2D(advection_velocity)

solver = DGSEM(; polydeg=3, surface_flux=flux_lax_friedrichs)
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = (-1.0, -1.0)
coordinates_max = (1.0, 1.0)
coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))

mesh = TreeMesh(
coordinates_min, coordinates_max; initial_refinement_level=4, n_cells_max=30_000
)
# Create a uniformly refined mesh with periodic boundaries
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 4,
n_cells_max = 30_000) # set maximum capacity of tree data structure

semi = SemidiscretizationHyperbolic(
mesh, equations, initial_condition_convergence_test, solver
)
# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
solver)

tspan = (0.0, 1.0)
###############################################################################
# ODE solvers, callbacks etc.

ode = semidiscretize_gpu(semi, tspan) # from TrixiGPU.jl
# Create ODE problem with time span from 0.0 to 1.0
ode = semidiscretize_gpu(semi, (0.0, 1.0)) # from TrixiGPU.jl

# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

analysis_callback = AnalysisCallback(semi; interval=100)
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_callback = AnalysisCallback(semi, interval = 100)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
save_solution = SaveSolutionCallback(interval = 100,
solution_variables = cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
stepsize_callback = StepsizeCallback(cfl = 1.6)

save_solution = SaveSolutionCallback(; interval=100, solution_variables=cons2prim)
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
stepsize_callback)

stepsize_callback = StepsizeCallback(; cfl=1.6)
###############################################################################
# run the simulation

callbacks = CallbackSet(
summary_callback, analysis_callback, save_solution, stepsize_callback
)
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
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);

sol = solve(
ode,
CarpenterKennedy2N54(; williamson_condition=false);
dt=1.0,
save_everystep=false,
callback=callbacks,
);
summary_callback()
# Print the timer summary
summary_callback()
67 changes: 42 additions & 25 deletions examples/advection_basic_3d.jl
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
using Trixi, TrixiGPU
using OrdinaryDiffEq

# The example is taken from the Trixi.jl

###############################################################################
# semidiscretization of the linear advection equation

advection_velocity = (0.2, -0.7, 0.5)
equations = LinearScalarAdvectionEquation3D(advection_velocity)

solver = DGSEM(; polydeg=3, surface_flux=flux_lax_friedrichs)
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = (-1.0, -1.0, -1.0)
coordinates_max = (1.0, 1.0, 1.0)
coordinates_min = (-1.0, -1.0, -1.0) # minimum coordinates (min(x), min(y), min(z))
coordinates_max = (1.0, 1.0, 1.0) # maximum coordinates (max(x), max(y), max(z))

mesh = TreeMesh(
coordinates_min, coordinates_max; initial_refinement_level=3, n_cells_max=30_000
)
# Create a uniformly refined mesh with periodic boundaries
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 3,
n_cells_max = 30_000) # set maximum capacity of tree data structure

semi = SemidiscretizationHyperbolic(
mesh, equations, initial_condition_convergence_test, solver
)
# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
solver)

tspan = (0.0, 1.0)
###############################################################################
# ODE solvers, callbacks etc.

ode = semidiscretize_gpu(semi, tspan) # from TrixiGPU.jl
# Create ODE problem with time span from 0.0 to 1.0
ode = semidiscretize_gpu(semi, (0.0, 1.0)) # from TrixiGPU.jl

# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

analysis_callback = AnalysisCallback(semi; interval=100)
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_callback = AnalysisCallback(semi, interval = 100)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
save_solution = SaveSolutionCallback(interval = 100,
solution_variables = cons2prim)
#
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
stepsize_callback = StepsizeCallback(cfl = 1.2)

save_solution = SaveSolutionCallback(; interval=100, solution_variables=cons2prim)
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
stepsize_callback)

stepsize_callback = StepsizeCallback(; cfl=1.2)
###############################################################################
# run the simulation

callbacks = CallbackSet(
summary_callback, analysis_callback, save_solution, stepsize_callback
)
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
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);

sol = solve(
ode,
CarpenterKennedy2N54(; williamson_condition=false);
dt=1.0,
save_everystep=false,
callback=callbacks,
);
summary_callback()
# Print the timer summary
summary_callback()

0 comments on commit 0b13dff

Please sign in to comment.