Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielDoehring committed Feb 7, 2024
1 parent 3fef537 commit 1597340
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 177 deletions.
42 changes: 19 additions & 23 deletions examples/structured_1d_dgsem/elixir_traffic_flow_lwr_greenlight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,52 @@ using Trixi
equations = TrafficFlowLWREquations1D()

basis = LobattoLegendreBasis(3)

surface_flux = flux_hll

solver = DGSEM(basis, surface_flux)

coordinates_min = (-1.0,) # minimum coordinate
coordinates_max = (1.0,) # maximum coordinate
cells_per_dimension = (64,)

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

# Example inspired from http://www.clawpack.org/riemann_book/html/Traffic_flow.html#Example:-green-light
# Green light that at x = 0 which switches at t = 0 from red to green.
# To the left there are cars bumper to bumper, to the right there are no cars.
function initial_condition_greenlight(x, t, equation::TrafficFlowLWREquations1D)
scalar = x[1] < 0.0 ? 1.0 : 0.0
scalar = x[1] < 0.0 ? 1.0 : 0.0

return SVector(scalar)
return SVector(scalar)
end

###############################################################################
# Specify non-periodic boundary conditions

# Assume that there are always cars waiting at the left
function inflow(x, t, equations::TrafficFlowLWREquations1D)
return initial_condition_greenlight(coordinate_min, t, equations)
return initial_condition_greenlight(coordinate_min, t, equations)
end
boundary_condition_inflow = BoundaryConditionDirichlet(inflow)

# Cars may leave the modeled domain
function boundary_condition_outflow(u_inner, orientation, normal_direction, x, t,
surface_flux_function, equations::TrafficFlowLWREquations1D)
# Calculate the boundary flux entirely from the internal solution state
flux = Trixi.flux(u_inner, orientation, equations)
surface_flux_function,
equations::TrafficFlowLWREquations1D)
# Calculate the boundary flux entirely from the internal solution state
flux = Trixi.flux(u_inner, orientation, equations)

return flux
return flux
end

boundary_conditions = (x_neg = boundary_condition_outflow,
x_pos = boundary_condition_outflow)

boundary_conditions = (x_neg=boundary_condition_outflow,
x_pos=boundary_condition_outflow)

initial_condition = initial_condition_greenlight

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
boundary_conditions=boundary_conditions)

boundary_conditions = boundary_conditions)

###############################################################################
# ODE solvers, callbacks etc.
Expand All @@ -65,12 +63,11 @@ ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval=analysis_interval)
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval=analysis_interval)

stepsize_callback = StepsizeCallback(cfl=1.2)
alive_callback = AliveCallback(analysis_interval = analysis_interval)

stepsize_callback = StepsizeCallback(cfl = 1.2)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
Expand All @@ -79,9 +76,8 @@ callbacks = CallbackSet(summary_callback,
###############################################################################
# run the simulation


sol = solve(ode, CarpenterKennedy2N54(williamson_condition=false),
dt=42, # 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 = 42, # 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
19 changes: 8 additions & 11 deletions examples/tree_1d_dgsem/elixir_traffic_flow_lwr_convergence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Trixi
###############################################################################

equations = TrafficFlowLWREquations1D()

# Use first order finite volume to prevent oscillations at the shock
solver = DGSEM(polydeg = 3, surface_flux = flux_hll)

Expand All @@ -24,7 +24,6 @@ initial_condition = initial_condition_convergence_test
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
source_terms = source_terms_convergence_test)


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

Expand All @@ -34,24 +33,22 @@ ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval=analysis_interval)
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval=analysis_interval)

stepsize_callback = StepsizeCallback(cfl=1.6)
alive_callback = AliveCallback(analysis_interval = analysis_interval)

stepsize_callback = StepsizeCallback(cfl = 1.6)

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

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


sol = solve(ode, CarpenterKennedy2N54(williamson_condition=false),
dt=42, # 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 = 42, # 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
40 changes: 19 additions & 21 deletions examples/tree_1d_dgsem/elixir_traffic_flow_lwr_trafficjam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Trixi
###############################################################################

equations = TrafficFlowLWREquations1D()

# Use first order finite volume to prevent oscillations at the shock
solver = DGSEM(polydeg = 0, surface_flux = flux_lax_friedrichs)

Expand All @@ -22,35 +22,35 @@ mesh = TreeMesh(coordinates_min, coordinates_max,
# Discontinuous initial condition (Riemann Problem) leading to a shock that moves to the left.
# The shock corresponds to the traffic congestion.
function initial_condition_traffic_jam(x, t, equation::TrafficFlowLWREquations1D)
scalar = x[1] < 0.0 ? 0.5 : 1.0
scalar = x[1] < 0.0 ? 0.5 : 1.0

return SVector(scalar)
return SVector(scalar)
end

###############################################################################
# Specify non-periodic boundary conditions

function outflow(x, t, equations::TrafficFlowLWREquations1D)
return initial_condition_traffic_jam(coordinates_min, t, equations)
return initial_condition_traffic_jam(coordinates_min, t, equations)
end
boundary_condition_outflow = BoundaryConditionDirichlet(outflow)

function boundary_condition_inflow(u_inner, orientation, normal_direction, x, t,
surface_flux_function, equations::TrafficFlowLWREquations1D)
# Calculate the boundary flux entirely from the internal solution state
flux = Trixi.flux(u_inner, orientation, equations)
surface_flux_function,
equations::TrafficFlowLWREquations1D)
# Calculate the boundary flux entirely from the internal solution state
flux = Trixi.flux(u_inner, orientation, equations)

return flux
return flux
end

boundary_conditions = (x_neg=boundary_condition_outflow,
x_pos=boundary_condition_inflow)
boundary_conditions = (x_neg = boundary_condition_outflow,
x_pos = boundary_condition_inflow)

initial_condition = initial_condition_traffic_jam

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
boundary_conditions=boundary_conditions)

boundary_conditions = boundary_conditions)

###############################################################################
# ODE solvers, callbacks etc.
Expand All @@ -61,12 +61,11 @@ ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval=analysis_interval)
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval=analysis_interval)

stepsize_callback = StepsizeCallback(cfl=2.0)
alive_callback = AliveCallback(analysis_interval = analysis_interval)

stepsize_callback = StepsizeCallback(cfl = 2.0)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
Expand All @@ -75,9 +74,8 @@ callbacks = CallbackSet(summary_callback,
###############################################################################
# run the simulation


sol = solve(ode, CarpenterKennedy2N54(williamson_condition=false),
dt=42, # 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 = 42, # 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
4 changes: 2 additions & 2 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ abstract type AbstractEquationsParabolic{NDIMS, NVARS, GradientVariables} <:
AbstractEquations{NDIMS, NVARS} end

# Lighthill-Witham-Richards (LWR) traffic flow model
abstract type AbstractTrafficFlowLWREquations{NDIMS, NVARS} <:
abstract type AbstractTrafficFlowLWREquations{NDIMS, NVARS} <:
AbstractEquations{NDIMS, NVARS} end
include("traffic_flow_lwr_1d.jl")
include("traffic_flow_lwr_1d.jl")
end # @muladd
Loading

0 comments on commit 1597340

Please sign in to comment.