Skip to content

Add other versions of adder component #560

@corakingdon

Description

@corakingdon

We may want to add versions of adder that allow for missing values, or that allow first and last bounds.

examples (need better names):

@defcomp adder2 begin
    add    = Parameter(index=[time])
    input  = Parameter(index=[time])
    output = Variable(index=[time])

    function run_timestep(p, v, d, t)
        v.output[t] = Mimi.@allow_missing(p.input[t]) + p.add[t]
    end
end

or

@defcomp adder3 begin
    add    = Parameter(index=[time])
    input  = Parameter(index=[time])
    output = Variable(index=[time])

    first::Int = Parameter(default=0)
    last::Int  = Parameter(default=typemax(Int))

    function run_timestep(p, v, d, t)
        if first < getindex(t) < last
            v.output[t] = p.input[t] + p.add[t]
        end
    end
end

Note that in this version of adder3, we would need to decide if first and last are index values, in which case we need to add a getindex(t) function, or if they refer to actual year values, in which case we would need to use gettime(t) and this would only work for time indexes that are Ints.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions