ClimaCore.jl icon indicating copy to clipboard operation
ClimaCore.jl copied to clipboard

Most operators don't like tuples

Open ekdejong opened this issue 1 year ago • 0 comments

Describe the bug

Everything except for interpolation and 10% of the upwinding code is not implemented with RecursiveApply. Sad face. This means that they cannot automatically be applied to Fields of Tuples.

To Reproduce

See branch ej/add_cloudy of KinematicDriver.jl. In the file src/K1DModel/tendency.jl we compute advection tendencies as a Field{NTuple} using the "hacky" dolla-dolla-i :($$i). To see why we are doing it this way, try replacing the function advection_tendency!(::CO.CloudyPrecip, dY, Y, aux, t) (last function of the file) with:

@inline function advection_tendency!(::CO.CloudyPrecip, dY, Y, aux, t)
    FT = eltype(Y.ρq_vap)
    Nmom = Int(sum(aux.cloudy_params.NProgMoms))
    
    If = CC.Operators.InterpolateC2F()
    ∂ = CC.Operators.DivergenceF2C(
        bottom = CC.Operators.Extrapolate(),
        top = CC.Operators.SetValue(ntuple(_ -> CC.Geometry.WVector(FT(0)), 6)),
    )
    fcc = CC.Operators.FluxCorrectionC2C(bottom = CC.Operators.Extrapolate(), top = CC.Operators.Extrapolate())
    
    @. dY.moments = -∂(
                (
                    aux.prescribed_velocity.ρw / If(aux.moisture_variables.ρ) +
                    map(CC.Geometry.WVector, If(aux.cloudy_velocity.weighted_vt) * FT(-1))
                ) * If(Y.moments),
            )
    @. dY.moments += fcc(
        (
            aux.prescribed_velocity.ρw / If(aux.moisture_variables.ρ) +
            map(CC.Geometry.WVector, If(aux.cloudy_velocity.weighted_vt) * FT(-1))
        ),
        Y.moments
    )

    return dY
end

and then run the example from the REPL via

julia --project=test
julia > include("test/experiments/KiD_driver/KiD_driver.jl")

You will see that the recursion is not used in many places where it should be.

Any relevant system information:

  • Julia version - 1.10
  • operating system - macOS

Talk to @dennisYatunin for more information/knowledge on necessary steps.

ekdejong avatar May 06 '24 22:05 ekdejong