Skip to content

Instantly share code, notes, and snippets.

View ufechner7's full-sized avatar

Uwe Fechner ufechner7

  • aenarete - Smart Wind
  • The Hague, The Netherlands
View GitHub Profile
@ufechner7
ufechner7 / sim_core_cpp.py
Created April 18, 2014 14:31
Example for using Numba classes
# -*- coding: utf-8 -*-
"""
Test and wrapper script for simulator core functions.
To recompile the C++ library type ! ./make.sh from the ipython console and restart
the ipython kernel.
"""
import os
import sys
path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(path + '/..')
@ufechner7
ufechner7 / julia.lang
Last active January 12, 2024 06:03
julia specification files for gedit / gnome
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of GtkSourceView
Authors: Waldir Pimenta
Copyright (C) 2013 Waldir Pimenta <waldir@email.com>
GtkSourceView is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ufechner7
ufechner7 / linalg_3.py
Created April 1, 2015 11:07
Fast linear algebra for 3D vectors using numba 0.17 or newer
# -*- coding: utf-8 -*-
"""
* This file is part of FreeKiteSim.
*
* FreeKiteSim -- A kite-power system power simulation software.
* Copyright (C) 2013 by Uwe Fechner, Delft University
* of Technology, The Netherlands. All rights reserved.
*
* FreeKiteSim is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ufechner7
ufechner7 / FastKPS_01.py
Created April 1, 2015 12:10
Implementation of a fast simulation core for kite power systems using numba and 2d arrays
# constants for accessing the array of scalars
ParamCD = 0
ParamCL = 1
Length = 2 # length of one tether segment at zero force
C_spring = 3 # spring constant of one tether segment
Damping = 4 # damping constant of one tether segment
Depower = 5
Steering = 6
Alpha_depower = 7
Alpha_zero = 8
@ufechner7
ufechner7 / bench_rec_array.py
Created April 1, 2015 12:37
Comparing the speed of accessing record arrays and two dimensional arrays using numba
# -*- coding: utf-8 -*-
""" Accessing record arrays with numba 0.17 is 10 times slower than using two dimensional arrays. """
from numba import jit
import numpy as np
import time
V_WIND = 8.0
V_wind = 0 # (westwind, downwind direction to the east)
V_wind_gnd = 1
@ufechner7
ufechner7 / KPS3_v3.py
Last active August 29, 2015 14:18
Demo code to show the speed problem with record arrays in numba 0.18.
# -*- coding: utf-8 -*-
"""
Demo code, showing the problem with using record arrays with Numba 0.18.
I replaced just three of the elements of vec3 with a record array with three elements. The execution time
increases from 22us to 45 us.
Model of a kite-power system in implicit form: residual = f(y, yd, sw)
This model implements a 3D mass-spring system with reel-out. It uses five tether segments (the number can be
configured in the file Settings.py). The kite is modelled as additional mass at the end of the tether.
@ufechner7
ufechner7 / RealTime.jl
Created August 23, 2015 17:47
Test script for the realtime performance of Julia
using Winston
const SIMUL_DUR = 10.0 # simulation time in seconds
const PeriodTime = 20e-3 # period time for the simulation in seconds
const workload = 20000 # workload in vector additions/ multiplications per simulation step
const vec_size = 3
const cpu_usage = zeros(round(Int, SIMUL_DUR / PeriodTime)) # data array to log the cpu usage
const vec = zeros(vec_size, workload) # preallocate data array of 3D vectors
function check_sleep(amount)
start = time()
sleep(amount)
final = time()
delta = final - start
return delta
end
sum = 0.0
abs(check_sleep(0.020)-0.020) # precompile check_sleep
from datetime import datetime
import time
def check_sleep(amount):
start = datetime.now()
time.sleep(amount)
end = datetime.now()
delta = end-start
return delta.seconds + delta.microseconds/1000000.
@ufechner7
ufechner7 / CustomType.jl
Created March 13, 2016 12:53
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