Skip to content

Instantly share code, notes, and snippets.

@ufechner7
Created March 13, 2016 12:53
Show Gist options
  • Save ufechner7/8545f18ad6d65b80b334 to your computer and use it in GitHub Desktop.
Save ufechner7/8545f18ad6d65b80b334 to your computer and use it in GitHub Desktop.
Custom type for scalars and vectors in julia
# Custom type, that can store scalars of vectors in Julia
NumberOrVector = Union{Number, Vector}
# input data
type Project
p_el_nom::NumberOrVector # electrical generator power in kW
rel_drum_diameter::NumberOrVector # ratio of the drum diameter and the tether diameter
rpm_generator::NumberOrVector # nominal speed of the electrical machine
z_ref::NumberOrVector # reference height for wind profile law
alpha::NumberOrVector # exponent of the wind profile law; default: for Cabauw
rho0::NumberOrVector # air density at the ground
elevation:: NumberOrVector # elevation angle in degrees
v_wind_nom:: NumberOrVector # nominal ground wind speed
v_ro_rel:: NumberOrVector # relative nominal reel-out speed (to windspeed at kite)
cl_wing::NumberOrVector
cd_wing::NumberOrVector
cd_tether::NumberOrVector
strength::NumberOrVector # nominal force of a tether with 4 mm diameter
rel_delta_l::NumberOrVector # relative difference between max. and min. tether length
end
Project(f::Vector) = Project(similar(f),similar(f),similar(f),similar(f),similar(f),similar(f),similar(f),
similar(f),similar(f),similar(f),similar(f),similar(f),similar(f),similar(f))
Project() = Project(1.5, 30.0, 1500.0, 10.0, 0.23375, 1.225, 25.0, 6.0, 0.20686, 1.3, 0.1413, 1.0, 4000.0, 30.0)
Base.copy(p::Project) = Project(copy(p.p_el_nom), copy(p.rel_drum_diameter), copy(p.rpm_generator), copy(p.z_ref),
copy(p.alpha), copy(p.rho0), copy(p.elevation), copy(p.v_wind_nom),
copy(p.v_ro_rel), copy(p.cl_wing), copy(p.cd_wing), copy(p.cd_tether),
copy(p.strength), copy(p.rel_delta_l))
function Base.show(io::IO, pro::Project)
println(io, "p_el_nom: $(pro.p_el_nom) kW")
println(io, "rel_drum_diameter: $(pro.rel_drum_diameter) [-]")
println(io, "rpm_generator: $(pro.rpm_generator) rpm")
println(io, "z_ref: $(pro.z_ref) m")
println(io, "alpha: $(pro.alpha)")
println(io, "rho0: $(pro.rho0) kg / m³")
println(io, "elevation: $(pro.elevation)°")
println(io, "v_wind_nom: $(pro.v_wind_nom) m/s")
println(io, "v_ro_rel: $(pro.v_ro_rel)")
println(io, "cl_wing: $(pro.cl_wing)")
println(io, "cd_wing: $(round(pro.cd_wing, 2))")
println(io, "cd_tether: $(pro.cd_tether)")
println(io, "strength: $(pro.strength) N")
println(io, "rel_delta_l: $(pro.rel_delta_l) %")
end
function push_project!(projects, pro::Project)
push!(projects.p_el_nom, pro.p_el_nom)
push!(projects.rel_drum_diameter, pro.rel_drum_diameter)
push!(projects.rpm_generator, pro.rpm_generator)
push!(projects.z_ref, pro.z_ref)
push!(projects.alpha, pro.alpha)
push!(projects.rho0, pro.rho0)
push!(projects.elevation, pro.elevation)
push!(projects.v_wind_nom, pro.v_wind_nom)
push!(projects.v_ro_rel, pro.v_ro_rel)
push!(projects.cl_wing, pro.cl_wing)
push!(projects.cd_wing, pro.cd_wing)
push!(projects.cd_tether, pro.cd_tether)
push!(projects.strength, pro.strength)
push!(projects.rel_delta_l, pro.rel_delta_l)
return projects
end
# create a scalar project
pro = Project()
# create a project, that keeps vectors of numbers
projects = Project(Number[])
# push the scalar project to the projects structure
push_project!(projects, pro)
# create a copy of the project template
pro2 = copy(pro)
# modify the copy
pro2.p_el_nom = 2.0
# push the copy to the projects structure
push_project!(projects, pro2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment