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

AbstractSurfacePerturbation #631

Merged
merged 11 commits into from
Dec 6, 2024
Merged

AbstractSurfacePerturbation #631

merged 11 commits into from
Dec 6, 2024

Conversation

milankl
Copy link
Member

@milankl milankl commented Dec 5, 2024

@minqi6 I wanted to write a general interface for any surface perturbation that'll go into the convection scheme. If everything here works you'd be able to define your own surface perturbation as follows

using SpeedyWeather

@kwdef struct MySurfacePerturbation <: SpeedyWeather.AbstractSurfacePerturbation
    # put here any parameters you need, e.g.
    noise_scale_temp::Float32 = 1            # standard deviation of perturbation, in Kelvin
end

# implement the actual perturbation as a functor 
function (SP::MySurfacePerturbation)(
    column::ColumnVariables,    # don't change this function signature
    model::PrimitiveEquation,   # in case you need anything from model, you can use it (read only)
)
    (; temp, humid, nlayers) = column
    T, q = temp[nlayers], humid[nlayers]    # unperturbed lowermost layer variables

    # perturb them somehow, write your code here
    r = column.random_value                 # needs a `random_process` passed to the model, otherwise 0!
    T += SP.noise_scale_temp*r

    # expected to return T, q
    return T, q
end

and that's all you need to define, you can do this in your notebook, no need to branch the model (but you can!). Construct then as (possibly pass on non-default parameters)

spectral_grid = SpectralGrid()
my_surface_perturbation = MySurfacePerturbation()

# construct convection with that perturbation
convection = SimplifiedBettsMiller(spectral_grid, surface_temp_humid=my_surface_perturbation)

# don't forget the random process otherwise your `column.random_value` is always 0!
random_process = SpectralAR1Process(spectral_grid)

# construct model
model = PrimitiveWetModel(spectral_grid; random_process, convection)

and everything else as normal!

@milankl milankl added parameterizations 🌧️ Parameterizations of unresolved physical processes surface ⛰️ Affecting the interaction with the planetary boundary layer stochastic 🎲 Random or stochastic components in a simulation labels Dec 5, 2024
@milankl milankl merged commit aa279a0 into main Dec 6, 2024
5 checks passed
@milankl milankl deleted the mk/convection_perturbation branch December 8, 2024 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parameterizations 🌧️ Parameterizations of unresolved physical processes stochastic 🎲 Random or stochastic components in a simulation surface ⛰️ Affecting the interaction with the planetary boundary layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant