Julian way of writing a constructor

Maybe something like this:

using Parameters

@with_kw mutable struct State{S, T}
    v_wind::T = zero(T)       # wind vector at the height of the kite
    v_wind_gnd::T = zero(T)    # wind vector at reference height
    v_wind_tether::T = zero(T)
    v_apparent::T = zero(T)
    drag_force::T = zero(T)
    lift_force::T = zero(T)
    steering_force::T = zero(T)
    last_force::T = zero(T)
    spring_force::T = zero(T)
    kite_y::T = zero(T)
    segment::T = zero(T)
    seg_area::S = zero(S)   # area of one tether segment
    c_spring::S = zero(S)
    length::S = zero(S)
    damping::S = zero(S)
    area::S = zero(S)
    param_cl::S = zero(S)
    param_cd::S = zero(S)
    v_app_norm::S = zero(S)
    cor_steering::S = zero(S)
    psi::S = zero(S)
    beta::S = zero(S)
end

s = State{Float32, MVector{3,Float32}}()

I would parameterize the struct instead of forcing a specific precision and vector type.

5 Likes