I have the following code:
using StaticArrays
# Type definitions
const MyFloat = Float32
const Vec3 = MVector{3, MyFloat}
mutable struct State
v_wind::Vec3 # wind vector at the height of the kite
v_wind_gnd::Vec3 # wind vector at reference height
v_wind_tether::Vec3
v_apparent::Vec3
drag_force::Vec3
lift_force::Vec3
steering_force::Vec3
last_force::Vec3
spring_force::Vec3
kite_y::Vec3
segment::Vec3
seg_area::MyFloat # area of one tether segment
c_spring::MyFloat
length::MyFloat
damping::MyFloat
area::MyFloat
param_cl::MyFloat
param_cd::MyFloat
v_app_norm::MyFloat
cor_steering::MyFloat
psi::MyFloat
beta::MyFloat
end
function init()
state = State(zeros(3), zeros(3), zeros(3), zeros(3), zeros(3), zeros(3), zeros(3), zeros(3), zeros(3), zeros(3), zeros(3), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
state.v_wind[1] = 8 # westwind, downwind direction to the east
state.v_wind_gnd[1] = 8 # westwind, downwind direction to the east
state.v_wind_tether[1] = 8 # wind at half of the height of the kite
state.v_apparent = [1.0, 2.0, 3.0]
state.param_cl = 0.2
state.param_cd = 1.0
state
end
const state = init()
How can this be written in a more Julian way?
Is there a way to initialize the struct with zeros without having to write all fields by hand?
Is there a better way to write a constructor?