00001 // $Id: frequency_gen.h 2009-11-10 17:00:00Z d3x593 $ 00002 // Copyright (C) 2009 Battelle Memorial Institute 00003 00004 #ifndef _FREQUENCYGEN_H 00005 #define _FREQUENCYGEN_H 00006 00007 #include "powerflow.h" 00008 00009 typedef enum { 00010 MATCHED=0, 00011 GOV_DELAY=1, 00012 GEN_RAMP=2 00013 } FREQSTATE; 00014 00015 typedef enum { 00016 EMPTY=0, //No contribution 00017 CONSTANT=1, //Constant term 00018 SCALAR=2, //Scalar term ax 00019 EXPONENT=3, //Exponential a*exp(bx) 00020 STEPEXP=4, //Step exponent of a*(1-exp(b*x)) 00021 RAMPEXP=5, //Ramp exponent of a*[(x-1/b*(exp(b*x)-1))+(c-t-1/b+1/b*exp((t-c)*b))*u(t-c)] 00022 PERSCONST=6, //Persistent constant - always there 00023 CSTEPEXP=7, //Step exponent with consant - c+a*(1-exp(b*x)) 00024 } CONTRIBTYPE; 00025 00026 typedef enum { 00027 OFF=0, //"Dumb" frequency generation - played in presumably 00028 AUTO=1 //"Active" frequency generation - performed by this object 00029 } FREQMODE; 00030 00031 typedef struct s_algcomponents { 00032 double coeffa; //First coefficient (constant, scalar) 00033 double coeffb; //Second coefficient - exponential scalar 00034 double delay_time; //Time delay for delayed contributions (RAMPEXP) 00035 CONTRIBTYPE contype; //Contribution type 00036 TIMESTAMP starttime; //Starting time of this contributor 00037 TIMESTAMP endtime; //Ending time of this contributor 00038 TIMESTAMP enteredtime; //Time entry was included - used for updates 00039 } ALGCOMPONENTS; //Algorithm components definition 00040 00041 class frequency_gen : public powerflow_object 00042 { 00043 public: 00044 static CLASS *oclass; 00045 static CLASS *pclass; 00046 public: 00047 double FrequencyValue; 00048 double FrequencyChange; 00049 double Mac_Inert, D_Load, PMech, tgov_delay; 00050 double LoadPower; 00051 double system_base; 00052 double ramp_rate; 00053 double Freq_Low, Freq_High, Freq_Histr; 00054 double calc_tol_perc; 00055 FREQMODE FreqObjectMode; 00056 int Num_Resp_Eqs; 00057 int iter_passes; //Number of passes that have been made over the object - used to figure out if things need removing or not 00058 double day_average, day_std, week_average, week_std; //Variables for 24- and 168-hour statistics (mean and std dev) 00059 00060 frequency_gen(MODULE *mod); 00061 inline frequency_gen(CLASS *cl=oclass):powerflow_object(cl){}; 00062 int create(void); 00063 int init(OBJECT *parent=NULL); 00064 int isa(char *classname); 00065 00066 TIMESTAMP presync(TIMESTAMP t0); 00067 TIMESTAMP postsync(TIMESTAMP t0); 00068 00069 private: 00070 FREQSTATE CurrGenCondition, NextGenCondition; //State machine variables 00071 double NominalFreq; 00072 double stored_freq[168]; //Storage array for statistic estimations 00073 int curr_store_loc; //Pointer to current storage location 00074 TIMESTAMP track_time; //Time to track when an hour has passed to store "new" value 00075 int eight_tau_value; //8 times the time constant of the system - theoretically used to remove equation contributions 00076 int three_tau_value; //3 times the time constant of the system - used for comparisons 00077 TIMESTAMP prev_time; //Previous timestep a run has been accomplished 00078 TIMESTAMP next_time; //Next timestep a change is expected 00079 TIMESTAMP curr_dt; //Current dt value observed 00080 TIMESTAMP trans_time; //Time to next FOI transition (estimated) 00081 TIMESTAMP Gov_Delay; //Time governor delay will be up and ramp rate will begin (for delay calculations) 00082 00083 double PrevLoadPower; //Load power calculated at last timestep 00084 double PrevGenPower; //Generator power calculated at last timestep (used during ramp) 00085 00086 bool Gov_Delay_Active; //Boolean to indicate if in the delay period (is Gov_Resp valid) 00087 bool Gen_Ramp_Direction; //Boolean to indicate ramping direction - false is down, true is up 00088 bool Change_Lockout; //Flag to prevent multiple changes during a timestep. Mainly used during ramps to prevent multiple time extensions 00089 double DB_Low, DB_High; //Frequency dead-band limits for governor operation 00090 double K_val, T_val, invT_val, AK_val; //Working variables for simplified power/frequency model 00091 double F_Low_PU, F_High_PU; //Low and High FOI - in p.u. 00092 double P_delta; //DeltaP associated with the frequency hysteresis 00093 double calc_tol; //power calculation threshold (since it wiggles a lot) 00094 00095 TIMESTAMP pres_updatetime(TIMESTAMP t0, TIMESTAMP dt_val); //Function to compute frequency changes based on current influencing contributions (writes updates) 00096 TIMESTAMP updatetime(TIMESTAMP t0, TIMESTAMP dt_val, double &FreqVal, double &DeltaFreq); //Function to compute frequency changes based on current influencing contributions (does not write anything) 00097 void RemoveScheduled(TIMESTAMP t0); //Function to remove all items added for the specified timestamp. Used to aid in the correction of jitter and changing powerflow conditions that may force something to be schedule early. 00098 00099 void DumpScheduler(void); //Temporary - remove me 00100 00101 ALGCOMPONENTS *CurrEquations; //Equation "buffer" 00102 }; 00103 00104 #endif // _FREQUENCYGEN_H