Solvers
Solvers
get_cfl_timestep!(buf, u, setup) -> AnyGet proposed maximum time step for convection and diffusion terms.
get_state(
stepper
) -> NamedTuple{(:u, :temp, :t, :n), <:NTuple{4, Any}}Get state (; u, temp, t, n) from stepper.
solve_unsteady(
;
setup,
tlims,
ustart,
tempstart,
method,
psolver,
Δt,
cfl,
n_adapt_Δt,
docopy,
processors,
θ
)Solve unsteady problem using method.
If Δt is a real number, it is rounded such that (t_end - t_start) / Δt is an integer. If Δt = nothing, the time step is chosen every n_adapt_Δt iteration with CFL-number cfl .
The processors are called after every time step.
Note that the state observable passed to the processor.initialize function contains vector living on the device, and you may have to move them back to the host using Array(u) in the processor.
Return (; u, t), outputs, where outputs is a named tuple with the outputs of processors with the same field names.
Processors
Processors can be used to process the solution in solve_unsteady after every time step.
animator(
;
setup,
path,
plot,
nupdate,
framerate,
visible,
screen,
kwargs...
)Animate a plot of the solution every update iteration. The animation is saved to path, which should have one of the following extensions:
".mkv"
".mp4"
".webm"
".gif"
The plot is determined by a plotter processor. Additional kwargs are passed to plot.
energy_history_plot(state; setup)Create energy history plot.
energy_spectrum_plot(state; setup, npoint, a)Create energy spectrum plot. The energy at a scalar wavenumber level
as in San and Staples [13].
fieldplot(state; setup, kwargs...)Plot state field in pressure points. If state is Observable, then the plot is interactive.
Available fieldnames are:
:velocity,:vorticity,:streamfunction,:pressure.
Available plot types for 2D are:
heatmap(default),image,contour,contourf.
Available plot types for 3D are:
contour(default).
The alpha value gets passed to contour in 3D.
fieldsaver(; setup, nupdate)Create processor that stores the solution and time every nupdate time step.
observefield(state; setup, fieldname, logtol, psolver)Observe field fieldname at pressure points.
processor(
initialize
) -> NamedTuple{(:initialize, :finalize), <:Tuple{Any, IncompressibleNavierStokes.var"#311#312"}}
processor(
initialize,
finalize
) -> NamedTuple{(:initialize, :finalize), <:Tuple{Any, Any}}Process results from time stepping. Before time stepping, the initialize function is called on an observable of the time stepper state, returning initialized. The observable is updated every time step.
After timestepping, the finalize function is called on initialized and the final state.
See the following example:
function initialize(state)
s = 0
println("Let's sum up the time steps")
on(state) do (; n, t)
println("The summand is $n, the time is $t")
s = s + n
end
s
end
finalize(i, state) = println("The final sum (at time t=$(state.t)) is $s")
p = processor(initialize, finalize)When solved for 6 time steps from t=0 to t=2 the displayed output is
Let's sum up the time steps
The summand is 0, the time is 0.0
The summand is 1, the time is 0.4
The summand is 2, the time is 0.8
The summand is 3, the time is 1.2
The summand is 4, the time is 1.6
The summand is 5, the time is 2.0
The final sum (at time t=2.0) is 15realtimeplotter(
;
setup,
plot,
nupdate,
displayfig,
screen,
displayupdates,
sleeptime,
kwargs...
)Processor for plotting the solution in real time.
Keyword arguments:
plot: Plot function.nupdate: Show solution everynupdatetime step.displayfig: Display the figure at the start.screen: Ifnothing, use default display. IfGLMakie.screen()multiple plots can be displayed in separate windows like in MATLAB (see alsoGLMakie.closeall()).displayupdates: Display the figure at every update (if using CairoMakie).sleeptime: Thesleeptimeis slept at every update, to give Makie time to update the plot. Set this tonothingto skip sleeping.
Additional kwargs are passed to the plot function.
save_vtk(state; setup, filename, kwargs...)Save fields to vtk file.
The kwargs are passed to snapshotsaver.
snapshotsaver(state; setup, fieldnames, psolver)In the case of a 2D setup, the velocity field is saved as a 3D vector with a z-component of zero, as this seems to be preferred by ParaView.
timelogger(
;
showmax,
showdt,
nupdate
) -> @NamedTuple{initialize::IncompressibleNavierStokes.var"#314#316"{Bool, Bool, Int64}, finalize::IncompressibleNavierStokes.var"#311#312"}Create processor that logs time step information.
vtk_writer(; setup, nupdate, dir, filename, kwargs...)Create processor that writes the solution every nupdate time steps to a VTK file. The resulting Paraview data collection file is stored in "$dir/$filename.pvd". The kwargs are passed to snapshotsaver.