Skip to content

Commit

Permalink
Format source code based on ˋSciMLˋ style (4 spaces) (#1513)
Browse files Browse the repository at this point in the history
* Format source code based on ˋSciMLˋ style (4 spaces)

* Make JuliaFormatter consume the two-layer SWE files again

* Remove files from ignore list

* Format two-layer SWE files

* Fix recursive_length formatting

* Find accceptable formatting for SemiHypMeshBCSolver

* Slightly improve semi_hyp_par formatting

* Variant on TrixiODESolution type formatting

* add FormatCheck CI job

* Allow alignment in struct definitions

* Fix formatting abomination

* Remove useless spam

* Sanitize type alias

* Fix using statement

* Update src/auxiliary/mpi.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Update src/callbacks_stage/positivity_zhang_shu.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Update src/callbacks_step/amr_dg2d.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Update src/callbacks_step/analysis.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Format the formatter

* substituted non-ascii lambda (#1521)

* rename format-check job name

* fix bad formatting

* improve some bad formatting

* align some struct fields

* align some struct fields

* align some struct fields

* begin end blocks for some at-trixi_timeit

* Update src/visualization/utilities.jl

* Update src/solvers/fdsbp_tree/fdsbp.jl

* Update src/meshes/p4est_mesh.jl

* Update src/meshes/p4est_mesh.jl

* comments on pssing nothing as mortar

* comment on passing nothing as mortar

* formatting on/off blocks

* Copy JuliaFormatter.toml from TrixiParticles.jl

* Add info on automated source code formatting

* Format `ext/`

* Format `benchmark/`

* Format `utils/`

---------

Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Joshua Lampert <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Jesse Chan <[email protected]>
  • Loading branch information
5 people authored Jun 16, 2023
1 parent 4357fe9 commit 2bc1cc6
Show file tree
Hide file tree
Showing 207 changed files with 46,607 additions and 43,236 deletions.
8 changes: 8 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Use SciML style: https://github.com/SciML/SciMLStyle
style = "sciml"

# Python style alignment. See https://github.com/domluna/JuliaFormatter.jl/pull/732.
yas_style_nesting = true

# Align struct fields for better readability of large struct definitions
align_struct_field = true
44 changes: 44 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: format-check

on:
push:
branches:
- 'main'
tags: '*'
pull_request:

jobs:
check-format:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v3
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version = "0.13.0"))'
#
# TODO: Change the call below to
# format(".")
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(["benchmark", "ext", "src", "utils"])'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
68 changes: 34 additions & 34 deletions benchmark/benchmark_ec.jl
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
using Printf, BenchmarkTools, Trixi

function run_benchmarks(benchmark_run; levels=0:5, polydeg=3)
runtimes = zeros(length(levels))
for (idx,initial_refinement_level) in enumerate(levels)
result = benchmark_run(; initial_refinement_level, polydeg)
display(result)
runtimes[idx] = result |> median |> time # in nanoseconds
end
return (; levels, runtimes, polydeg)
function run_benchmarks(benchmark_run; levels = 0:5, polydeg = 3)
runtimes = zeros(length(levels))
for (idx, initial_refinement_level) in enumerate(levels)
result = benchmark_run(; initial_refinement_level, polydeg)
display(result)
runtimes[idx] = result |> median |> time # in nanoseconds
end
return (; levels, runtimes, polydeg)
end

function tabulate_benchmarks(args...; kwargs...)
result = run_benchmarks(args...; kwargs...)
println("#Elements | Runtime in seconds")
for (level,runtime) in zip(result.levels, result.runtimes)
@printf("%9d | %.2e\n", 4^level, 1.0e-9 * runtime)
end
for (level,runtime) in zip(result.levels, result.runtimes)
@printf("%.16e\n", 1.0e-9 * runtime)
end
result = run_benchmarks(args...; kwargs...)
println("#Elements | Runtime in seconds")
for (level, runtime) in zip(result.levels, result.runtimes)
@printf("%9d | %.2e\n", 4^level, 1.0e-9*runtime)
end
for (level, runtime) in zip(result.levels, result.runtimes)
@printf("%.16e\n", 1.0e-9*runtime)
end
end

function benchmark_euler(; initial_refinement_level=1, polydeg=3)
function benchmark_euler(; initial_refinement_level = 1, polydeg = 3)
γ = 1.4
equations = CompressibleEulerEquations2D(γ)

γ = 1.4
equations = CompressibleEulerEquations2D(γ)
surface_flux = flux_ranocha
volume_flux = flux_ranocha
solver = DGSEM(polydeg, surface_flux, VolumeIntegralFluxDifferencing(volume_flux))

surface_flux = flux_ranocha
volume_flux = flux_ranocha
solver = DGSEM(polydeg, surface_flux, VolumeIntegralFluxDifferencing(volume_flux))
coordinates_min = (-2.0, -2.0)
coordinates_max = (2.0, 2.0)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = initial_refinement_level,
n_cells_max = 100_000)

coordinates_min = (-2.0, -2.0)
coordinates_max = ( 2.0, 2.0)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level=initial_refinement_level,
n_cells_max=100_000)
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_weak_blast_wave,
solver)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_weak_blast_wave, solver)
t0 = 0.0
u0 = compute_coefficients(t0, semi)
du = similar(u0)

t0 = 0.0
u0 = compute_coefficients(t0, semi)
du = similar(u0)

@benchmark Trixi.rhs!($du, $u0, $semi, $t0)
@benchmark Trixi.rhs!($du, $u0, $semi, $t0)
end

# versioninfo(verbose=true)
@show Threads.nthreads()
tabulate_benchmarks(benchmark_euler, levels=0:8)
tabulate_benchmarks(benchmark_euler, levels = 0:8)
3 changes: 3 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Disable formatting this file since it contains highly unusual formatting for better
# readability
#! format: off

using BenchmarkTools
using Trixi
Expand Down
80 changes: 40 additions & 40 deletions benchmark/elixir_2d_euler_vortex_p4est.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,42 @@ The classical isentropic vortex test case of
[NASA/CR-97-206253](https://ntrs.nasa.gov/citations/19980007543)
"""
function initial_condition_isentropic_vortex(x, t, equations::CompressibleEulerEquations2D)
# needs appropriate mesh size, e.g. [-10,-10]x[10,10]
# make sure that the inicenter does not exit the domain, e.g. T=10.0
# initial center of the vortex
inicenter = SVector(0.0, 0.0)
# size and strength of the vortex
iniamplitude = 0.2
# base flow
rho = 1.0
v1 = 1.0
v2 = 1.0
vel = SVector(v1, v2)
p = 10.0
rt = p / rho # ideal gas equation
cent = inicenter + vel*t # advection of center
cent = x - cent # distance to centerpoint
#cent=cross(iniaxis,cent) # distance to axis, tangent vector, length r
# cross product with iniaxis = [0,0,1]
cent = SVector(-cent[2], cent[1])
r2 = cent[1]^2 + cent[2]^2
du = iniamplitude/(2*π)*exp(0.5*(1-r2)) # vel. perturbation
dtemp = -(equations.gamma-1)/(2*equations.gamma*rt)*du^2 # isentrop
rho = rho * (1+dtemp)^(1\(equations.gamma-1))
vel = vel + du*cent
v1, v2 = vel
p = p * (1+dtemp)^(equations.gamma/(equations.gamma-1))
prim = SVector(rho, v1, v2, p)
return prim2cons(prim, equations)
# needs appropriate mesh size, e.g. [-10,-10]x[10,10]
# make sure that the inicenter does not exit the domain, e.g. T=10.0
# initial center of the vortex
inicenter = SVector(0.0, 0.0)
# size and strength of the vortex
iniamplitude = 0.2
# base flow
rho = 1.0
v1 = 1.0
v2 = 1.0
vel = SVector(v1, v2)
p = 10.0
rt = p / rho # ideal gas equation
cent = inicenter + vel * t # advection of center
cent = x - cent # distance to centerpoint
#cent=cross(iniaxis,cent) # distance to axis, tangent vector, length r
# cross product with iniaxis = [0,0,1]
cent = SVector(-cent[2], cent[1])
r2 = cent[1]^2 + cent[2]^2
du = iniamplitude / (2 * π) * exp(0.5 * (1 - r2)) # vel. perturbation
dtemp = -(equations.gamma - 1) / (2 * equations.gamma * rt) * du^2 # isentrop
rho = rho * (1 + dtemp)^(1 \ (equations.gamma - 1))
vel = vel + du * cent
v1, v2 = vel
p = p * (1 + dtemp)^(equations.gamma / (equations.gamma - 1))
prim = SVector(rho, v1, v2, p)
return prim2cons(prim, equations)
end
initial_condition = initial_condition_isentropic_vortex
solver = DGSEM(polydeg=3, surface_flux=flux_lax_friedrichs)
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = (-10.0, -10.0)
coordinates_max = ( 10.0, 10.0)
mesh = P4estMesh((1, 1), polydeg=Trixi.polydeg(solver),
coordinates_min=coordinates_min, coordinates_max=coordinates_max,
initial_refinement_level=4)

coordinates_max = (10.0, 10.0)
mesh = P4estMesh((1, 1), polydeg = Trixi.polydeg(solver),
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
initial_refinement_level = 4)

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

Expand All @@ -66,19 +65,20 @@ ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval=analysis_interval, save_analysis=true,
extra_analysis_errors=(:conservation_error,),
extra_analysis_integrals=(entropy, energy_total,
energy_kinetic, energy_internal))
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
save_analysis = true,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (entropy, energy_total,
energy_kinetic,
energy_internal))

alive_callback = AliveCallback(analysis_interval=analysis_interval)
alive_callback = AliveCallback(analysis_interval = analysis_interval)

callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback)


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

sol = solve(ode, BS3(),
save_everystep=false, callback=callbacks);
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary
74 changes: 37 additions & 37 deletions benchmark/elixir_2d_euler_vortex_structured.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,42 @@ The classical isentropic vortex test case of
[NASA/CR-97-206253](https://ntrs.nasa.gov/citations/19980007543)
"""
function initial_condition_isentropic_vortex(x, t, equations::CompressibleEulerEquations2D)
# needs appropriate mesh size, e.g. [-10,-10]x[10,10]
# make sure that the inicenter does not exit the domain, e.g. T=10.0
# initial center of the vortex
inicenter = SVector(0.0, 0.0)
# size and strength of the vortex
iniamplitude = 0.2
# base flow
rho = 1.0
v1 = 1.0
v2 = 1.0
vel = SVector(v1, v2)
p = 10.0
rt = p / rho # ideal gas equation
cent = inicenter + vel*t # advection of center
cent = x - cent # distance to centerpoint
#cent=cross(iniaxis,cent) # distance to axis, tangent vector, length r
# cross product with iniaxis = [0,0,1]
cent = SVector(-cent[2], cent[1])
r2 = cent[1]^2 + cent[2]^2
du = iniamplitude/(2*π)*exp(0.5*(1-r2)) # vel. perturbation
dtemp = -(equations.gamma-1)/(2*equations.gamma*rt)*du^2 # isentrop
rho = rho * (1+dtemp)^(1\(equations.gamma-1))
vel = vel + du*cent
v1, v2 = vel
p = p * (1+dtemp)^(equations.gamma/(equations.gamma-1))
prim = SVector(rho, v1, v2, p)
return prim2cons(prim, equations)
# needs appropriate mesh size, e.g. [-10,-10]x[10,10]
# make sure that the inicenter does not exit the domain, e.g. T=10.0
# initial center of the vortex
inicenter = SVector(0.0, 0.0)
# size and strength of the vortex
iniamplitude = 0.2
# base flow
rho = 1.0
v1 = 1.0
v2 = 1.0
vel = SVector(v1, v2)
p = 10.0
rt = p / rho # ideal gas equation
cent = inicenter + vel * t # advection of center
cent = x - cent # distance to centerpoint
#cent=cross(iniaxis,cent) # distance to axis, tangent vector, length r
# cross product with iniaxis = [0,0,1]
cent = SVector(-cent[2], cent[1])
r2 = cent[1]^2 + cent[2]^2
du = iniamplitude / (2 * π) * exp(0.5 * (1 - r2)) # vel. perturbation
dtemp = -(equations.gamma - 1) / (2 * equations.gamma * rt) * du^2 # isentrop
rho = rho * (1 + dtemp)^(1 \ (equations.gamma - 1))
vel = vel + du * cent
v1, v2 = vel
p = p * (1 + dtemp)^(equations.gamma / (equations.gamma - 1))
prim = SVector(rho, v1, v2, p)
return prim2cons(prim, equations)
end
initial_condition = initial_condition_isentropic_vortex
solver = DGSEM(polydeg=3, surface_flux=flux_lax_friedrichs)
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = (-10.0, -10.0)
coordinates_max = ( 10.0, 10.0)
coordinates_max = (10.0, 10.0)
cells_per_dimension = (16, 16)
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)


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

###############################################################################
Expand All @@ -65,19 +64,20 @@ ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval=analysis_interval, save_analysis=true,
extra_analysis_errors=(:conservation_error,),
extra_analysis_integrals=(entropy, energy_total,
energy_kinetic, energy_internal))
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
save_analysis = true,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (entropy, energy_total,
energy_kinetic,
energy_internal))

alive_callback = AliveCallback(analysis_interval=analysis_interval)
alive_callback = AliveCallback(analysis_interval = analysis_interval)

callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback)


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

sol = solve(ode, BS3(),
save_everystep=false, callback=callbacks);
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary
Loading

0 comments on commit 2bc1cc6

Please sign in to comment.