Skip to content

Commit

Permalink
Clean up and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoArtiano committed Sep 2, 2024
1 parent 18a4297 commit 956b81a
Show file tree
Hide file tree
Showing 11 changed files with 1,097 additions and 1,105 deletions.
118 changes: 59 additions & 59 deletions examples/structured_1d_dgsem/elixir_linear_acoustic_advection_1D.jl
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
using OrdinaryDiffEq
using Trixi
using Plots

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

a = 0.1
b = 1.0
equations = LinearAcousticAdvectionEquation1D(a,b)

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

coordinates_min = (0.0,) # minimum coordinate
coordinates_max = (1.0,) # maximum coordinate
cells_per_dimension = (4,)

# Create curved mesh with 16 cells
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)

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

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 1.0
ode = semidiscretize(semi, (0.0, 0.001));

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

# 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 = 0.0001)

# 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 = 0.001, # 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()
using OrdinaryDiffEq
using Trixi
using Plots

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

a = 0.1
b = 1.0
equations = LinearAcousticAdvectionEquation1D(a, b)

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

coordinates_min = (0.0,) # minimum coordinate
coordinates_max = (1.0,) # maximum coordinate
cells_per_dimension = (4,)

# Create curved mesh with 16 cells
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)

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

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 1.0
ode = semidiscretize(semi, (0.0, 0.001));

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

# 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 = 0.0001)

# 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 = 0.001, # 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()
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
using OrdinaryDiffEq
using Trixi
using Plots

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

a = 0.1
b = 1.0
equationsfull = LinearAcousticAdvectionEquation1D(a,b)
equationsslow = LinearAcousticAdvectionSlowEquation1D(a,b)
equationsfast = LinearAcousticAdvectionFastEquation1D(a,b)
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_rusanov)

coordinates_min = (0.0,) # minimum coordinate
coordinates_max = (1.0,) # maximum coordinate
cells_per_dimension = (128, )

# Create curved mesh with 16 cells
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)
boundary_conditions1 = boundary_condition_periodic
boundary_conditions2 = boundary_condition_periodic
# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolicSplit(mesh, (equationsslow, equationsfast), initial_condition_fast_slow, solver, solver; boundary_conditions = (boundary_conditions1,
boundary_conditions2))
###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 1.0
# ode = semidiscretizesplit(semifull,semislow, semifast, (0.0, 0.001));
ode = semidiscretize(semi, (0.0, 1.0));
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

# 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 = 0.1)

# 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 = Trixi.solve(ode, Trixi.SimpleIMEX(),
dt = 0.0195, # 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()
using OrdinaryDiffEq
using Trixi
using Plots

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

a = 0.1
b = 1.0
equationsfull = LinearAcousticAdvectionEquation1D(a, b)
equationsslow = LinearAcousticAdvectionSlowEquation1D(a, b)
equationsfast = LinearAcousticAdvectionFastEquation1D(a, b)
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_rusanov)

coordinates_min = (0.0,) # minimum coordinate
coordinates_max = (1.0,) # maximum coordinate
cells_per_dimension = (128,)

# Create curved mesh with 16 cells
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)
boundary_conditions1 = boundary_condition_periodic
boundary_conditions2 = boundary_condition_periodic
# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolicSplit(mesh, (equationsslow, equationsfast),
initial_condition_fast_slow, solver, solver;
boundary_conditions = (boundary_conditions1,
boundary_conditions2))
###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 1.0
# ode = semidiscretizesplit(semifull,semislow, semifast, (0.0, 0.001));
ode = semidiscretize(semi, (0.0, 1.0));
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

# 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 = 0.1)

# 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 = Trixi.solve(ode, Trixi.SimpleIMEX(),
dt = 0.0195, # 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()
56 changes: 29 additions & 27 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,17 @@ export AcousticPerturbationEquations2D,
IdealGlmMhdMulticomponentEquations1D, IdealGlmMhdMulticomponentEquations2D,
HyperbolicDiffusionEquations1D, HyperbolicDiffusionEquations2D,
HyperbolicDiffusionEquations3D,
LinearAcousticAdvectionEquation1D, LinearAcousticAdvectionFastEquation1D, LinearAcousticAdvectionSlowEquation1D
LinearScalarAdvectionEquation1D, LinearScalarAdvectionEquation2D,
LinearScalarAdvectionEquation3D,
InviscidBurgersEquation1D,
LatticeBoltzmannEquations2D, LatticeBoltzmannEquations3D,
ShallowWaterEquations1D, ShallowWaterEquations2D,
ShallowWaterEquationsQuasi1D,
LinearizedEulerEquations1D, LinearizedEulerEquations2D, LinearizedEulerEquations3D,
PolytropicEulerEquations2D,
TrafficFlowLWREquations1D
LinearAcousticAdvectionEquation1D, LinearAcousticAdvectionFastEquation1D,
LinearAcousticAdvectionSlowEquation1D
LinearScalarAdvectionEquation1D, LinearScalarAdvectionEquation2D,
LinearScalarAdvectionEquation3D,
InviscidBurgersEquation1D,
LatticeBoltzmannEquations2D, LatticeBoltzmannEquations3D,
ShallowWaterEquations1D, ShallowWaterEquations2D,
ShallowWaterEquationsQuasi1D,
LinearizedEulerEquations1D, LinearizedEulerEquations2D, LinearizedEulerEquations3D,
PolytropicEulerEquations2D,
TrafficFlowLWREquations1D

export LaplaceDiffusion1D, LaplaceDiffusion2D, LaplaceDiffusion3D,
CompressibleNavierStokesDiffusion1D, CompressibleNavierStokesDiffusion2D,
Expand All @@ -174,22 +175,22 @@ export GradientVariablesConservative, GradientVariablesPrimitive, GradientVariab

export flux, flux_central, flux_lax_friedrichs, flux_hll, flux_hllc, flux_hlle,
flux_godunov, flux_rusanov
flux_chandrashekar, flux_ranocha, flux_derigs_etal, flux_hindenlang_gassner,
flux_nonconservative_powell, flux_nonconservative_powell_local_symmetric,
flux_kennedy_gruber, flux_shima_etal, flux_ec,
flux_fjordholm_etal, flux_nonconservative_fjordholm_etal,
flux_wintermeyer_etal, flux_nonconservative_wintermeyer_etal,
flux_nonconservative_ersing_etal,
flux_chan_etal, flux_nonconservative_chan_etal, flux_winters_etal,
hydrostatic_reconstruction_audusse_etal, flux_nonconservative_audusse_etal,
FluxPlusDissipation, DissipationGlobalLaxFriedrichs, DissipationLocalLaxFriedrichs,
FluxLaxFriedrichs, max_abs_speed_naive,
FluxHLL, min_max_speed_naive, min_max_speed_davis, min_max_speed_einfeldt,
FluxLMARS,
FluxRotated,
flux_shima_etal_turbo, flux_ranocha_turbo,
FluxHydrostaticReconstruction,
FluxUpwind
flux_chandrashekar, flux_ranocha, flux_derigs_etal, flux_hindenlang_gassner,
flux_nonconservative_powell, flux_nonconservative_powell_local_symmetric,
flux_kennedy_gruber, flux_shima_etal, flux_ec,
flux_fjordholm_etal, flux_nonconservative_fjordholm_etal,
flux_wintermeyer_etal, flux_nonconservative_wintermeyer_etal,
flux_nonconservative_ersing_etal,
flux_chan_etal, flux_nonconservative_chan_etal, flux_winters_etal,
hydrostatic_reconstruction_audusse_etal, flux_nonconservative_audusse_etal,
FluxPlusDissipation, DissipationGlobalLaxFriedrichs, DissipationLocalLaxFriedrichs,
FluxLaxFriedrichs, max_abs_speed_naive,
FluxHLL, min_max_speed_naive, min_max_speed_davis, min_max_speed_einfeldt,
FluxLMARS,
FluxRotated,
flux_shima_etal_turbo, flux_ranocha_turbo,
FluxHydrostaticReconstruction,
FluxUpwind

export splitting_steger_warming, splitting_vanleer_haenel,
splitting_coirier_vanleer, splitting_lax_friedrichs,
Expand Down Expand Up @@ -249,7 +250,8 @@ export VolumeIntegralSubcellLimiting, BoundsCheckCallback,
export nelements, nnodes, nvariables,
eachelement, eachnode, eachvariable

export SemidiscretizationHyperbolic, semidiscretize, compute_coefficients, integrate, semidiscretizesplit
export SemidiscretizationHyperbolic, semidiscretize, compute_coefficients, integrate,
semidiscretizesplit

export SemidiscretizationHyperbolicParabolic

Expand Down
4 changes: 2 additions & 2 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ abstract type AbstractLinearAcousticAdvectionEquation{NDIMS, NVARS} <:
AbstractEquations{NDIMS, NVARS} end
include("linear_acoustic_advection_1d.jl")
abstract type AbstractLinearAcousticAdvectionSlowEquation{NDIMS, NVARS} <:
AbstractEquations{NDIMS, NVARS} end
AbstractEquations{NDIMS, NVARS} end
include("linear_acoustic_advection_slow_1d.jl")
abstract type AbstractLinearAcousticAdvectionFastEquation{NDIMS, NVARS} <:
AbstractEquations{NDIMS, NVARS} end
AbstractEquations{NDIMS, NVARS} end
include("linear_acoustic_advection_fast_1d.jl")

# Inviscid Burgers
Expand Down
34 changes: 17 additions & 17 deletions src/equations/linear_acoustic_advection_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ struct LinearAcousticAdvectionEquation1D{RealT <: Real} <:
b::RealT
end

function LinearAcousticAdvectionEquation1D(a::Real,b::Real)
LinearAcousticAdvectionEquation1D(a,b)
function LinearAcousticAdvectionEquation1D(a::Real, b::Real)
LinearAcousticAdvectionEquation1D(a, b)
end

function varnames(::typeof(cons2cons), ::LinearAcousticAdvectionEquation1D)
("v","p")
("v", "p")
end
varnames(::typeof(cons2prim), ::LinearAcousticAdvectionEquation1D) = ("v","p")
varnames(::typeof(cons2prim), ::LinearAcousticAdvectionEquation1D) = ("v", "p")

# Set initial conditions at physical location `x` for time `t`
function initial_condition_fast_slow(x, t, equation::LinearAcousticAdvectionEquation1D)
sigma = 0.1
x0 = 0.75
x1 = 0.25
p0 = exp(-((x[1]-x0)/sigma)^2)
p01 = exp(-((x[1]-x1)/sigma)^2)
p1 = p01*cos(7.0*2.0*pi*x[1]/sigma)
p0 = exp(-((x[1] - x0) / sigma)^2)
p01 = exp(-((x[1] - x1) / sigma)^2)
p1 = p01 * cos(7.0 * 2.0 * pi * x[1] / sigma)
p = p0 + p1
v = p/equation.b[1]
v = p / equation.b[1]

return SVector(v, p)
end
Expand All @@ -61,15 +61,16 @@ end

function flux_rusanov(u_ll, u_rr, orientation::Int,
equation::LinearAcousticAdvectionEquation1D)
v_ll, p_ll = u_ll
v_rr, p_rr = u_rr
a = equation.a
b = equation.b
f1 = 0.5*(a*v_ll + b*p_ll + a*v_rr + b*p_rr) - 0.5*(b+a)*(v_rr - v_ll)
f2 = 0.5*(a*p_ll + b*v_ll + a*p_rr + b*v_rr) - 0.5*(b+a)*(p_rr - p_ll)

return SVector(f1,f2)
v_ll, p_ll = u_ll
v_rr, p_rr = u_rr
a = equation.a
b = equation.b
f1 = 0.5 * (a * v_ll + b * p_ll + a * v_rr + b * p_rr) -
0.5 * (b + a) * (v_rr - v_ll)
f2 = 0.5 * (a * p_ll + b * v_ll + a * p_rr + b * v_rr) -
0.5 * (b + a) * (p_rr - p_ll)

return SVector(f1, f2)
end

@inline have_constant_speed(::LinearAcousticAdvectionEquation1D) = True()
Expand All @@ -85,5 +86,4 @@ end

# Convert conservative variables to entropy variables
@inline cons2entropy(u, equation::LinearAcousticAdvectionEquation1D) = u

end # @muladd
Loading

0 comments on commit 956b81a

Please sign in to comment.