##
Archive for the ‘**VPLAN**’ Category

- In: VPLAN
- Leave a Comment

I have added several helper functions to work with ini-files.

In particular, I wanted to describe piecewise continous control functions by providing a time grid

[0,1,2,3,4,5]

and a list of values of the control function at these points

[4,3,5,3,1,5]

Doing this by hand is quite time consuming, since VPLAN

describes a control function by an offset and a slope.

So if one wants to have a continuous function, one has to calculate the slope such that the pieces fit together.

Being a programmer, I did that only once, then got bored and decided to write a helper function that does this work for me.

import vplan.ini s = vplan.ini.generate_u_description("MyControlFunction", 1, 3, -10, 10, [0,1,2,3,4,5], [4,3,5,3,1,5], [0]*6, [10]*6, [-2]*6, [2]*6) print s

This code generates the code

[Steuerfunktionen] u1=MyControlFunction 3 -10 10 u1tAnzahl=5 u1t0=t0 u1t1q=4 0 10 -1 -2 2 u1t1=1 u1t2q=3 0 10 2 -2 2 u1t2=2 u1t3q=5 0 10 -2 -2 2 u1t3=3 u1t4q=3 0 10 -2 -2 2 u1t4=4 u1t5q=1 0 10 4 -2 2 u1t5=tend

By typing

vplan.ini.generate_u_description?

in an ipython shell, one obtains a full description

s = generate_u_description(name, number, mode, u_lo, u_up, grid,q, q_lo, q_up, s_lo, s_up ) Create ini-file description of a control function of the form Parameters ---------- name: string name of the control function number: int number of the control function (counting from 1) mode: int type of control function 0 piecewise constant 1 piecewise constant (continuous) 2 piecewise linear 3 piecewise linear (continuous) grid: at which points of time does the control function switch? the grid should contain t0 and tend q: array_like control variables describing the values of the control function if mode is 0 or 1: len(q) == len(grid)-1 elif mode is 2 or 3 len(q) == 2*(len(grid)-1) In contrast to the implementation in the ini-file, the two q values are the _value_ of u, _not_ the value and slope u_lo: float lower bound for u u_up: float upper bound for u q_lo: array_like or float lower bounds for q len(q_lo) == len(grid)-1 if a float is provided, q_lo is the bound for all entries of q q_up: array_like or float lower bounds for q len(q_lo) == len(grid)-1 if a float is provided, q_up is the bound for all entries of q s_lo: array_like lower bounds for the slopes s_up: array_like upper bounds for the slopes Returns ------- s: string of the form u1=u 3 20 100 u1tAnzahl=3 u1t0=t0 u1t1q=80 20 100 0 0 0 u1t1=2 u1t2q=70 20 100 0.0 -1e+10 1e+10 u1t2=8 u1t3q=70 20 100 0 0 0 u1t3=tend Description ----------- There three types of constraints for mode 2 and 3 function u on [t0,t1] 1: q_lo and q_up at t0 2: q_lo and q_up at t1 3: s_lo and s_up on [t0,t1] Howerver, VPLAN does not support this. It is only possible to specify 1: q_lo and q_up at t0 3: s_lo and s_up on [t0,t1] the constraint 2: q_lo and q_up at t1 has to be modelled otherwise, e.g. by setting u_lo and u_up