tomchor / Oceanostics.jl

Diagnostics for Oceananigans
https://tomchor.github.io/Oceanostics.jl/
MIT License
24 stars 8 forks source link

Revamps progress messengers #144

Closed tomchor closed 10 months ago

tomchor commented 1 year ago

Closes https://github.com/tomchor/Oceanostics.jl/issues/129 Closes https://github.com/tomchor/Oceanostics.jl/issues/69

This creates an AbstractProgressMessenger (APM) which is modular. Each APM can be called on a Simulation, as per usual, but it can also be added to other APMs to make functions that can also be called on a Simulation and their outputs are strung together.

Here an example that's working right now:

julia> using Revise

julia> using Oceananigans

julia> using Oceanostics.ProgressMessengers

julia> grid = RectilinearGrid(size=(4, 5, 6), extent=(1, 1, 1));

julia> model = NonhydrostaticModel(; grid);

julia> simulation = Simulation(model, Δt=1, stop_time=10);

julia> max_u = MaxUVelocity();

julia> max_v = MaxVVelocity();

julia> max_w = MaxWVelocity();

julia> max_u(simulation)
"|u|ₘₐₓ = 0.00e+00 m/s"

julia> max_v(simulation)
"|v|ₘₐₓ = 0.00e+00 m/s"

julia> max_w(simulation)
"|w|ₘₐₓ = 0.00e+00 m/s"

These can then be combined to make more complex messages:

julia> max_vels = max_u + max_v + max_w
#5 (generic function with 1 method)

julia> max_vels(simulation)
"0.00e+00,    0.00e+00,    0.00e+00"

julia> max_vels = "|u⃗|ₘₐₓ = " + max_u + max_v + max_w
#5 (generic function with 1 method)

julia> max_vels(simulation)
"|u⃗|ₘₐₓ = ,    0.00e+00,    0.00e+00,    0.00e+00"

julia> max_vels = "|u⃗|ₘₐₓ = " * FunctionMessenger(max_u + max_v + max_w)
#41 (generic function with 1 method)

julia> max_vels(simulation)
"|u⃗|ₘₐₓ =  0.00e+00,    0.00e+00,    0.00e+00"