123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- #ifndef delay_h
- #define delay_h
- /*
- * Copyright (C) 1995-2006 Dynasim AB.
- * All rights reserved.
- *
- */
- /* first implementation:
- Dieter Moormann (DLR), till Nov 14, 1995 */
- /* modfied for use with derivatives also:
- Dieter Moormann (DLR), till May 24, 1996 */
- /* improvements made for Dymola Version 3.1:
- Dieter Moormann (DLR), April 2, 1998 */
- /* improvements made for Dymola Version 3.1b:
- Dag Bruck, Dynasim AB, October 5, 1998 */
- /* These functions are to be used together with the Dymola model
- classes <FixDelay>, <VarDelay>, and <Derivative>.
- The time <Time> and the input <u> are written into a circular buffer.
-
- Delay:
- At start time the <Time> is set to the negative value of the
- delaytime, which is specified by the parameter <DelayTime>, <u> is
- given its initial value.
- After the start of the integration, only pairs of <Time> and <u>
- are stored in the buffer, when the time has increased from the
- last value. If the integrator has move backwards, the old (now
- invalid) values will be overwritten by the new ones. This guarantees,
- that the time is allways increasing ( = that the history of the
- buffer is always correct).
- If the end of the buffer is reached, the new pair of <Time> and <u>
- is stored at the first postion of the buffer (circular buffer).
- The output <y> is interpolated from the buffer at the <Time> reduced
- by the <DelayTime> by linear interpolation.
- DelayedTime = Time - DelayTime
-
- At that time <DelayedTime>, the interpolation is performed:
- ( u(t_up) - ul(t_low) )
- y = u(t_low) + (DelayedTime - t_low) * ------------------------
- ( t_up - t_low )
- with: t_low < DelayedTime <= t_up
- If the <DelayedTime> is smaller than the lowest time in the buffer,
- the value is extrapolated from the two lowest values of the buffer.
- If the <DelayedTime> is bigger than the highest time in the buffer,
- the value is extrapolated from the two highest values of the buffer.
- This can happen, when the delaytime is negative ("extrapolation into
- future")
- The buffersize is fixed to the value specified by the parameter
- <Buffersize> in the Dymola model class <Delay>.
- In the current version the Delay Block is realized as SISO system.
- Derivative:
- ( u(t_up) - ul(t_low) )
- y = ------------------------
- ( t_up - t_low )
- In the current version the Derivative block is realized as SISO system.
- */
- #include "libdssetup.h"
- #ifndef DELAYSTRUCT_H
- #define DELAYSTRUCT_H
- typedef struct { /* struct for storing the delay/derivative information */
- double *x; /* column of time values */
- double *y; /* column of values, which belong to time values of
- same row */
- double timedelay; /* value of timedelay (used for delays only) */
- int nx; /* buffersize of the system = number of columns */
- int first; /* column of first value in the buffer */
- int old; /* column of last interpolation step */
- int add; /* column of last value added to the buffer */
- } delayStruct;
- #endif
- DYMOLA_STATIC LIBDS_API_AFTER double delayIni(double delaytime, double buffer, double startTime, double u);
- /* Function is called from the Dymola generated code for each <Delay>
- during initialisation. It allocates the storage for each delay of the model
- and sets its inital conditions and returns the identifyer.
- inputs: <delaytime> (Delaytime) ;double
- <buffer> (Buffersize) ;double
- <startTime> (StartTime) ;double
- <u> (Input) ;double
- outputs: RETURN (Identifyer) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER double delayFunction(double idd, double delaytime, double maxDelayTime, double t, double u,const char*str);
- /* Function is called from the Dymola generated code for each <Delay>.
- It puts the current value of Time <t> and Input <u> in the buffer
- of the Delay with the identifyer <idd>. It returns the interpolated
- value of the delayed time.
- inputs: <idd> (Identity) ;double
- <delaytime> (Delaytime) ;double
- <t> (Time) ;double
- <u> (Input) ;double
- outputs: RETURN (Derivative) ;double
- This function calls first: <delayWrite>
- and then: <delayRead>
- */
- DYMOLA_STATIC LIBDS_API_AFTER double delayWrite (double *idd, double *t, double *u);
- /* Function is called from <delayfunc>.
- It puts the current value of Time <t> and Input <u> in the buffer
- of the Delay with the identifyer <idd>. The function returns the
- unchanged input <u>.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- <u> (Input) ;double
- outputs: RETURN (Input) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER double delayRead(double *idd, double *delaytime, double *t);
- /* Function is called from <delayfunc>.
- It returns the interpolated value of the Delay with the
- identifyer <idd> of the delayed time.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- outputs: RETURN (Interpolated Output) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER double derivativeIni(double startTime, double u);
- /* Function is called from the Dymola generated code for each <Derivative>
- during initialisation. It allocates the storage for each derivative of the model
- and sets its inital conditions and returns the identifyer.
- inputs: <startTime> (StartTime) ;double
- <u> (Input) ;double
- outputs: RETURN (Identifyer) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER double derivativeFunction(double idd, double t, double u);
- /* Function is called from the Dymola generated code for each <Derivative>.
- It puts the current value of Time <t> and Input <u> in the buffer
- of the Derivative with the identifyer <idd>. It returns the derivative.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- <u> (Input) ;double
- outputs: RETURN (Derivative) ;double
- This function calls first: <derivWrite>
- and then: <derivPut>
- */
- DYMOLA_STATIC LIBDS_API_AFTER double derivWrite(double *idd, double *t, double *u);
- /* Function is called from <derivativeFunction>.
- It puts the current value of Time <t> and Input <u> in the buffer
- of the Derivative with the identifyer <idd>. The function returns the
- unchanged input <u>.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- <u> (Input) ;double
- outputs: RETURN (Input) ;double
- */
-
- DYMOLA_STATIC LIBDS_API_AFTER double derivRead(double *idd, double *t);
- /* Function is called from <derivativeFunction>.
- It returns the derivative value of the Derivative with the
- identifyer <idd>.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- outputs: RETURN (Derivative) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER void delayDerivativeClose(void);
- /* Function is called at the end of the simulation to free allocated
- storage of delays and derivatives and to reset the counters.
- no inputs, no outputs */
- /****************************************************************************************
- the following definitions are required for the Block library of
- Dymola version 3.0 or older, but not for Dymola 3.1
- ****************************************************************************************/
- DYMOLA_STATIC LIBDS_API_AFTER double delayinit(double delaytime, double buffer, double u);
- /* Function is called from the Dymola generated code for each <Delay>.
- Called from <dsblockS> (during initialisation) it allocates the
- storage for each delay of the model and sets its inital conditions
- and returns the identifyer.
- Called during simulation it just returns the identifyer.
- inputs: <delaytime> (Delaytime) ;double
- <buffer> (Buffersize) ;double
- <u> (Input) ;double
- outputs: RETURN (Identifyer) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER void delayiniclos(void);
- /* Function is called to end the initialization procedure.
- no inputs, no outputs */
- DYMOLA_STATIC LIBDS_API_AFTER void delayclose(void);
- /* Function is called at the end of the simulation to free allocated
- storage.
- no inputs, no outputs */
- DYMOLA_STATIC LIBDS_API_AFTER double delayfunc(double delaytime, double t, double u, double buffersize);
- /* Function is called from the Dymola generated code for each <Delay>.
- It puts the current value of Time <t> and Input <u> in the buffer
- of the Delay. It returns the interpolated value of the delayed time.
- inputs: <delaytime> (Delytime) ;double
- <t> (Time) ;double
- <u> (Input) ;double
- <buffersize> (Buffersize) ;double
- outputs: RETURN (Interpolated Output) ;double
- This function calls first: <delayput>
- and then: <delayget>
- */
- DYMOLA_STATIC LIBDS_API_AFTER double delayput(double *idd, double *t, double *u);
- /* Function is called from <delayfunc>.
- It puts the current value of Time <t> and Input <u> in the buffer
- of the Delay with the identifyer <idd>. The function returns the
- unchanged input <u>.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- <u> (Input) ;double
- outputs: RETURN (Input) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER double delayget(double *idd, double *t);
- /* Function is called from <delayfunc>.
- It returns the interpolated value of the Delay with the
- identifyer <idd> of the delayed time.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- outputs: RETURN (Interpolated Output) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER double derivfunc(double t, double u);
- /* Function is called from the Dymola generated code for each <Delay>.
- It puts the current value of Time <t> and Input <u> in the buffer
- of the Delay with the identifyer <idd>. It returns the interpolated
- value of the delayed time.
- inputs: <t> (Time) ;double
- <u> (Input) ;double
- outputs: RETURN (Derivative) ;double
- This function calls first: <delayput>
- and then: <derivget>
- */
- DYMOLA_STATIC LIBDS_API_AFTER double derivput(double *idd, double *t, double *u);
- /* Function is called from <delayfunc>.
- It puts the current value of Time <t> and Input <u> in the buffer
- of the Derivative with the identifyer <idd>. The function returns the
- unchanged input <u>.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- <u> (Input) ;double
- outputs: RETURN (Input) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER double derivget(double *idd, double *t);
- /* Function is called from <delayfunc>.
- It returns the derivative value of the Derivative with the
- identifyer <idd>.
- inputs: <idd> (Identifyer) ;double
- <t> (Time) ;double
- outputs: RETURN (Derivative) ;double
- */
- DYMOLA_STATIC LIBDS_API_AFTER double delayDDFunction(double expr,double dt,double*idd,int BufferSize,double Time,int Event,int*timed);
- DYMOLA_STATIC LIBDS_API_AFTER double delayDCFunction(double expr,double dt,double*idd,int BufferSize,double Time,int Event,
- double*rel,double*qp,double*qn,int*qen,double*qz2,int*AnyEvent);
- DYMOLA_STATIC LIBDS_API_AFTER int transportIni(double buffer, double startX, double u);
- DYMOLA_STATIC LIBDS_API_AFTER void transportGet(double T1,double T2,double x,int vs,int id,double*Tf1,double*Tf2);
- DYMOLA_STATIC LIBDS_API_AFTER void transportPut(double T1,double T2,double x,int vs,int id);
- DYMOLA_STATIC LIBDS_API_AFTER void transportFunction(double T1,double T2,double x,int vs,int id,double*Tf1,double*Tf2);
- #endif
|