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

Define get_expensive_vars or something? #157

Open
charleskawczynski opened this issue Sep 1, 2023 · 1 comment
Open

Define get_expensive_vars or something? #157

charleskawczynski opened this issue Sep 1, 2023 · 1 comment

Comments

@charleskawczynski
Copy link
Member

There are some ClimaAtmos functions that call several functions, resulting in several expensive calls. We could either cache the expensive variables in the thermo state, or we could define a getter that efficiently computes all of the variables and returns a struct where it's cached. One advantage of this is that it's use is optional.

For example:

    @. ᶜlinear_buoygrad = buoyancy_gradients(
        params,
        moisture_model,
        EnvBuoyGrad(
            BuoyGradMean(),
            TD.air_temperature(thermo_params, ᶜts⁰),                           # t_sat
            TD.vapor_specific_humidity(thermo_params, ᶜts⁰),                   # qv_sat
            ᶜspecific⁰.q_tot,                                                  # qt_sat
            TD.dry_pottemp(thermo_params, ᶜts⁰),                               # θ_sat
            TD.liquid_ice_pottemp(thermo_params, ᶜts⁰),                        # θ_liq_ice_sat
            projected_vector_data(
                C3,
                ᶜgradᵥ(ᶠinterp(TD.virtual_pottemp(thermo_params, ᶜts⁰))),
                ᶜlg,
            ),                                                                 # ∂θv∂z_unsat
            projected_vector_data(C3, ᶜgradᵥ(ᶠinterp(ᶜspecific⁰.q_tot)), ᶜlg), # ∂qt∂z_sat
            projected_vector_data(
                C3,
                ᶜgradᵥ(ᶠinterp(TD.liquid_ice_pottemp(thermo_params, ᶜts⁰))),
                ᶜlg,
            ),                                                                 # ∂θl∂z_sat
            ᶜp,                                                                # p
            ifelse(TD.has_condensate(thermo_params, ᶜts⁰), 1, 0),              # en_cld_frac
            ᶜρ⁰,                                                               # ρ
        ),
    )

is a massive kernel:

Screen Shot 2023-09-01 at 4 09 26 PM

Hyperdiffusion (on the left) is shown for scale. It's called 3 times and each one is 10% of root.

@charleskawczynski
Copy link
Member Author

Local notes:

    @. ᶜlinear_buoygrad = buoyancy_gradients(
        BuoyGradMean(),
        thermo_params,
        moisture_model,
        EnvBuoyGradVars(
            ᶜts,
            pd(ᶜgradᵥ(ᶠts), ᶜlg,),    # ∂θv∂z_unsat
            pd(ᶜgradᵥ(TD.total_specific_humidity(thermo_params, ᶠts)), ᶜlg),                                      # ∂qt∂z_sat
            pd(ᶜgradᵥ(TD.liquid_ice_pottemp(thermo_params, ᶠts)), ᶜlg,), # ∂θl∂z_sat
        ),
    )

    if atmos.moisture_model isa DryModel
		@. ᶠts = TD.PhaseDry_ρe(
		    ᶠinterp(TD.air_temperature(thermo_params, ᶜts)),
		    ᶠinterp(TD.internal_energy(thermo_params, ᶜts)),
	    )
	elseif atmos.moisture_model isa EquilMoistModel
		@. ᶠts = TD.PhaseEquil_ρeq(
		    ᶠinterp(TD.air_temperature(thermo_params, ᶜts)),
		    ᶠinterp(TD.internal_energy(thermo_params, ᶜts)),
		    ᶠinterp(TD.total_specific_humidity(thermo_params, ᶜts)),
		    3,
            eltype(thermo_params)(0.003),
	    )
	else
		@assert atmos.moisture_model isa NonEquilMoistModel
		@. ᶠts = TD.PhaseNonEquil_ρeq(
		    ᶠinterp(TD.air_temperature(thermo_params, ᶜts)),
		    ᶠinterp(TD.internal_energy(thermo_params, ᶜts)),
		    ᶠinterp(TD.PhasePartition(thermo_params, ᶜts)),
	    )
	end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant