Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set! initial conditions #557

Open
milankl opened this issue Jun 26, 2024 · 4 comments
Open

set! initial conditions #557

milankl opened this issue Jun 26, 2024 · 4 comments
Assignees
Labels
initial conditions 🚥 Initial conditions of model simulations user interface 🎹 How users use our user interface

Comments

@milankl
Copy link
Member

milankl commented Jun 26, 2024

With the new variable structure in #525 we also need to redesign a convenient way of setting the initial conditions of the prognostic variables. I think we want

  • set!(simulation, vor=f) with a function like f(x,y,z) = ... where x,y,z would be coordinates lon, lat, height (probably lond 0-360˚, latd -90˚ to 90˚, sigma 0 to 1)
  • set! with a scalar, e.g. set!(simulation, humid=0)
  • other ideas?

I've drafted that a bit and just throw this in here to collect this

set!(S::AbstractSimulation; kwargs...) = set!(S.prognostic_variables, S.model.geometry; kwargs...)

function set!(
    progn::PrognosticVariables,
    geometry::Geometry;
    u = nothing,
    v = nothing,
    vor = nothing,
    div = nothing,
    temp = nothing,
    humid = nothing,
    pres = nothing,
    lf::Integer = 1,
    add::Bool = false,
)
    isnothing(vor)   || set!(progn.vor[lf],     vor, geometry; add)
    isnothing(div)   || set!(progn.div[lf],     div, geometry; add)
    isnothing(temp)  || set!(progn.temp[lf],   temp, geometry; add)
    isnothing(humid) || set!(progn.humid[lf], humid, geometry; add)
    isnothing(pres)  || set!(progn.pres[lf],   pres, geometry; add)

    isnothing(u) | isnothing(v) || set_vordiv!(progn.vor[lf], progn.div[lf], vor, div; add)
end

function set!(var::LowerTriangularArray, f::Function, geometry::Geometry, S::SpectralTransform; add)
    grid =
    set!(grid, f, geometry; add)
    transform!(var, grid, S)
end

function set!(var::AbstractGridArray, f::Function, geometry::Geometry; add)
    (; londs, latds, σ_levels_full) = geometry
    kernel(a, b) = add ? a+b : b
    for k in eachgrid(var)
        for ij in eachgridpoint(var)
            var[ij, k] = kernel(var[ij, k], f(londs[ij], latds[ij], σ_levels_full[k]))
        end
    end
end

function set!(var::LowerTriangularArray, f::Real, geometry::Geometry; add)
end
@milankl milankl added user interface 🎹 How users use our user interface initial conditions 🚥 Initial conditions of model simulations labels Jun 26, 2024
@maximilian-gelbrecht
Copy link
Member

I like the idea and the general design.

I'd probably just add a method to set! with an instance of AbstractGrid.

Oh, and I think explicitly denoting Function is not ideal because not all callable objects are subtypes of Function (e.g. overloaded structs are not).

@maximilian-gelbrecht maximilian-gelbrecht self-assigned this Jul 6, 2024
@milankl
Copy link
Member Author

milankl commented Jul 8, 2024

@maximilian-gelbrecht
Copy link
Member

Implemented in #525 , but with one broken test remaining, so this issue stays open.

@milankl
Copy link
Member Author

milankl commented Dec 17, 2024

More set! functionality in #579 for tracers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
initial conditions 🚥 Initial conditions of model simulations user interface 🎹 How users use our user interface
Projects
None yet
Development

No branches or pull requests

2 participants