Skip to content

Commit

Permalink
Clean up broken comment examples
Browse files Browse the repository at this point in the history
  • Loading branch information
agdestein committed Jul 16, 2024
1 parent 32f445f commit d1297bf
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 141 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.jl.cov
*.jl.mem
*package-lock.json
*package.json
*Manifest.toml
/docs/build/
/docs/src/generated/
Expand All @@ -16,3 +17,4 @@

# Mac OS
*.DS_Store
docs/make.jl
5 changes: 3 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ examples = [

# Convert scripts to executable markdown files
output = "generated"
outputdir = joinpath(@__DIR__, "src", output)
rm(outputdir; recursive = true)
for e examples
inputfile = joinpath(@__DIR__, "..", "examples", e.name * ".jl")
outputdir = joinpath(@__DIR__, "src", output)
if e.run
# With code execution blocks
Literate.markdown(inputfile, outputdir)
Expand All @@ -60,7 +61,7 @@ for e ∈ examples
inputfile,
outputdir;
preprocess = content ->
"# *Note: Output is not generated for this example to save resources on GitHub.*\n\n" *
"# *Note: Output is not generated for this example (to save resources on GitHub).*\n\n" *
content,
postprocess = content -> replace(content, r"@example.*" => "julia"),
)
Expand Down
20 changes: 10 additions & 10 deletions examples/Actuator2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ using GLMakie #!md
using IncompressibleNavierStokes

# Output directory
output = "output/Actuator2D"
outdir = joinpath(@__DIR__, "output", "Actuator2D")

# A 2D grid is a Cartesian product of two vectors
n = 40
x = LinRange(0.0, 10.0, 5n + 1)
y = LinRange(-2.0, 2.0, 2n + 1)
plotgrid(x, y)
plotgrid(x, y; figure = (; size = (600, 300)))

# Boundary conditions
boundary_conditions = (
Expand Down Expand Up @@ -65,13 +65,13 @@ state, outputs = solve_unsteady(;
method = RKMethods.RK44P2(),
Δt = 0.05,
processors = (
rtp = realtimeplotter(; setup, plot = fieldplot, nupdate = 1),
rtp = realtimeplotter(; setup, size = (600, 300), nupdate = 1),
## ehist = realtimeplotter(; setup, plot = energy_history_plot, nupdate = 1),
## espec = realtimeplotter(; setup, plot = energy_spectrum_plot, nupdate = 1),
## anim = animator(; setup, path = "$output/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = "$output", filename = "solution"),
## anim = animator(; setup, path = "$outdir/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = "$outdir", filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 1),
log = timelogger(; nupdate = 24),
),
);

Expand All @@ -80,7 +80,7 @@ state, outputs = solve_unsteady(;
# We may visualize or export the computed fields `(u, p)`.

# Export to VTK
save_vtk(setup, state.u, state.t, "$output/solution")
save_vtk(setup, state.u, state.t, "$outdir/solution")

# We create a box to visualize the actuator.
box = (
Expand All @@ -89,16 +89,16 @@ box = (
)

# Plot pressure
fig = fieldplot(state; setup, fieldname = :pressure)
fig = fieldplot(state; setup, size = (600, 300), fieldname = :pressure)
lines!(box...; color = :red)
fig

# Plot velocity
fig = fieldplot(state; setup, fieldname = :velocitynorm)
fig = fieldplot(state; setup, size = (600, 300), fieldname = :velocitynorm)
lines!(box...; color = :red)
fig

# Plot vorticity
fig = fieldplot(state; setup, fieldname = :vorticity)
fig = fieldplot(state; setup, size = (600, 300), fieldname = :vorticity)
lines!(box...; color = :red)
fig
8 changes: 4 additions & 4 deletions examples/Actuator3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using GLMakie #!md
using IncompressibleNavierStokes

# Output directory
output = "output/Actuator3D"
outdir = joinpath(@__DIR__, "output", "Actuator3D")

# Floating point type
T = Float64
Expand Down Expand Up @@ -89,8 +89,8 @@ ustart = create_initial_conditions(setup, (dim, x, y, z) -> dim() == 1 ? one(x)
## plot = energy_spectrum_plot,
nupdate = 1,
),
## anim = animator(; setup, path = "$output/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = "$output", filename = "solution"),
## anim = animator(; setup, path = "$outdir/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = "$outdir", filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 1),
),
Expand All @@ -104,4 +104,4 @@ ustart = create_initial_conditions(setup, (dim, x, y, z) -> dim() == 1 ? one(x)
outputs.rtp

# Export to VTK
save_vtk(setup, u, t, "$output/solution")
save_vtk(setup, u, t, "$outdir/solution")
20 changes: 11 additions & 9 deletions examples/BackwardFacingStep2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using GLMakie #!md
using IncompressibleNavierStokes

# Output directory
output = "output/BackwardFacingStep2D"
outdir = joinpath(@__DIR__, "output", "BackwardFacingStep2D")

# Floating point type
T = Float64
Expand Down Expand Up @@ -47,7 +47,7 @@ boundary_conditions = (
# the walls.
x = LinRange(T(0), T(10), 301)
y = cosine_grid(-T(0.5), T(0.5), 51)
plotgrid(x, y)
plotgrid(x, y; figure = (; size = (600, 150)))

# Build setup and assemble operators
setup = Setup(x, y; Re, boundary_conditions, ArrayType);
Expand All @@ -71,12 +71,14 @@ state, outputs = solve_unsteady(;
plot = fieldplot,
## plot = energy_history_plot,
## plot = energy_spectrum_plot,
docolorbar = false,
size = (600, 150),
nupdate = 1,
),
## anim = animator(; setup, path = "$output/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = output, filename = "solution"),
## anim = animator(; setup, path = "$outdir/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = outdir, filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 1),
log = timelogger(; nupdate = 500),
),
);

Expand All @@ -85,13 +87,13 @@ state, outputs = solve_unsteady(;
# We may visualize or export the computed fields

# Export to VTK
save_vtk(setup, state.u, state.t, "$output/solution")
save_vtk(setup, state.u, state.t, "$outdir/solution")

# Plot pressure
fieldplot(state; setup, fieldname = :pressure)
fieldplot(state; setup, size = (600, 150), fieldname = :pressure)

# Plot velocity
fieldplot(state; setup, fieldname = :velocitynorm)
fieldplot(state; setup, size = (600, 150), fieldname = :velocitynorm)

# Plot vorticity
fieldplot(state; setup, fieldname = :vorticity)
fieldplot(state; setup, size = (600, 150), fieldname = :vorticity)
14 changes: 7 additions & 7 deletions examples/BackwardFacingStep3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ using GLMakie #!md
using IncompressibleNavierStokes

# Output directory
output = "output/BackwardFacingStep3D"
outdir = joinpath(@__DIR__, "output", "BackwardFacingStep3D")

# Floating point type
T = Float64
T = Float32

# Array type
ArrayType = Array
Expand All @@ -29,7 +29,7 @@ ArrayType = Array
## using Metal; ArrayType = MtlArray

# Reynolds number
Re = T(3000)
Re = T(1000)

# A 3D grid is a Cartesian product of three vectors
x = LinRange(T(0), T(10), 129)
Expand Down Expand Up @@ -75,10 +75,10 @@ state, outputs = solve_unsteady(;
## plot = energy_spectrum_plot,
nupdate = 1,
),
## anim = animator(; setup, path = "$output/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = output, filename = "solution"),
## anim = animator(; setup, path = "$outdir/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = outdir, filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 1),
log = timelogger(; nupdate = 100),
),
)

Expand All @@ -87,7 +87,7 @@ state, outputs = solve_unsteady(;
# We may visualize or export the computed fields

# Export to VTK
save_vtk(setup, state.u, state.t, "$output/solution")
save_vtk(setup, state.u, state.t, "$outdir/solution")

# Plot pressure
fieldplot(state; setup, fieldname = :pressure)
Expand Down
8 changes: 4 additions & 4 deletions examples/DecayingTurbulence2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using GLMakie #!md
using IncompressibleNavierStokes

# Output directory
output = "output/DecayingTurbulence2D"
outdir = joinpath(@__DIR__, "output", "DecayingTurbulence2D")

# Floating point precision
T = Float64
Expand Down Expand Up @@ -52,8 +52,8 @@ state, outputs = solve_unsteady(;
displayfig = false,
),
espec = realtimeplotter(; setup, plot = energy_spectrum_plot, nupdate = 10),
## anim = animator(; setup, path = "$output/solution.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = output, filename = "solution"),
## anim = animator(; setup, path = "$outdir/solution.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = outdir, filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 100),
),
Expand All @@ -70,7 +70,7 @@ outputs.ehist
outputs.espec

# Export to VTK
save_vtk(setup, state.u, state.t, "$output/solution")
save_vtk(setup, state.u, state.t, "$outdir/solution")

# Plot field
fieldplot(state; setup)
8 changes: 4 additions & 4 deletions examples/DecayingTurbulence3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using GLMakie #!md
using IncompressibleNavierStokes

# Output directory
output = "output/DecayingTurbulence3D"
outdir = joinpath(@__DIR__, "output", "DecayingTurbulence3D")

# Floating point precision
T = Float64
Expand Down Expand Up @@ -59,8 +59,8 @@ ustart = random_field(setup; psolver);
displayfig = false,
),
espec = realtimeplotter(; setup, plot = energy_spectrum_plot, nupdate = 10),
## anim = animator(; setup, path = "$output/solution.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = output, filename = "solution"),
## anim = animator(; setup, path = "$outdir/solution.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = outdir, filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 100),
),
Expand All @@ -77,4 +77,4 @@ outputs.ehist
outputs.espec

# Export to VTK
save_vtk(setup, u, t, "$output/solution")
save_vtk(setup, u, t, "$outdir/solution")
12 changes: 6 additions & 6 deletions examples/LidDrivenCavity2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using GLMakie #!md
using IncompressibleNavierStokes

# Case name for saving results
output = "output/LidDrivenCavity2D"
outdir = joinpath(@__DIR__, "output", "LidDrivenCavity2D")

# The code allows for using different floating point number types, including single
# precision (`Float32`) and double precision (`Float64`). On the CPU, the speed
Expand Down Expand Up @@ -90,8 +90,8 @@ processors = (
## rtp = realtimeplotter(; setup, plot = fieldplot, nupdate = 50),
## ehist = realtimeplotter(; setup, plot = energy_history_plot, nupdate = 10),
## espec = realtimeplotter(; setup, plot = energy_spectrum_plot, nupdate = 10),
## anim = animator(; setup, path = "$output/solution.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 100, dir = output, filename = "solution"),
## anim = animator(; setup, path = "$outdir/solution.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 100, dir = outdir, filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 1000),
);
Expand All @@ -105,10 +105,10 @@ state, outputs = solve_unsteady(; setup, ustart, tlims, Δt = T(1e-3), processor
#
# We may visualize or export the computed fields

# Export fields to VTK. The file `output/solution.vti` may be opened for
# Export fields to VTK. The file `outdir/solution.vti` may be opened for
# visualization in [ParaView](https://www.paraview.org/). This is particularly
# useful for inspecting results from 3D simulations.
save_vtk(setup, state.u, state.t, "$output/solution")
save_vtk(setup, state.u, state.t, "$outdir/solution")

# Plot pressure
fieldplot(state; setup, fieldname = :pressure)
Expand All @@ -127,7 +127,7 @@ fieldplot(state; setup, fieldname = :vorticity)
## outputs.rtp
## outputs.ehist
## outputs.espec
## outputs.anim
## outputs.anim
## outputs.vtk
## outputs.field
outputs.log
10 changes: 5 additions & 5 deletions examples/LidDrivenCavity3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using GLMakie #!md
using IncompressibleNavierStokes

# Case name for saving results
output = "output/LidDrivenCavity3D"
outdir = joinpath(@__DIR__, "output", "LidDrivenCavity3D")

# Floating point type
T = Float64
Expand Down Expand Up @@ -61,19 +61,19 @@ ustart = create_initial_conditions(setup, (dim, x, y, z) -> zero(x))
## rtp = realtimeplotter(; setup, plot = fieldplot, nupdate = 50),
ehist = realtimeplotter(; setup, plot = energy_history_plot, nupdate = 10),
## espec = realtimeplotter(; setup, plot = energy_spectrum_plot, nupdate = 10),
## anim = animator(; setup, path = "$output/solution.mkv", nupdate = 20),
# vtk = vtk_writer(; setup, nupdate = 100, dir = output, filename = "solution"),
## anim = animator(; setup, path = "$outdir/solution.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 100, dir = outdir, filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 20),
),
);

# ## Post-process
#
# We may visualize or export the computed fields `(V, p)`
# We may visualize or export the computed fields

# Export to VTK
save_vtk(setup, u, t, "$output/solution")
save_vtk(setup, u, t, "$outdir/solution")

# Energy history
outputs.ehist
Loading

0 comments on commit d1297bf

Please sign in to comment.