00001 #ifndef _electrical_model_eqns_h_
00002 #define _electrical_model_eqns_h_
00003 #include <map>
00004 #include <list>
00005 #include <vector>
00006 #include "ElectricalData.h"
00007 #include "ElectricalSensorInterface.h"
00008 #include "adevs.h"
00009 #include "events.h"
00010 #include "Sensor.h"
00011
00016 class ElectricalModelEqns:
00017 public adevs::dae_se1_system<adevs::PortValue<BasicEvent*> >
00018 {
00019 public:
00023 static const int LoadAdj;
00027 static const int SetLoad;
00033 static const int GenrTrip;
00039 static const int SensorOutput;
00044 static const int ACE;
00048 static const int LineAction;
00053 ElectricalModelEqns(ElectricalData* data, std::list<Sensor*>& sensors, bool no_events = false);
00054 ElectricalModelEqns(ElectricalData* data, bool no_events = false);
00056 ~ElectricalModelEqns();
00058 void init(double* q, double* a);
00059 void alg_func(const double* q, const double* a, double* af);
00060 void der_func(const double* q, const double* a, double* dq);
00061 void state_event_func(const double* q, const double* a, double *z);
00062 double time_event_func(const double* q, const double* a);
00063 void internal_event(double* q, double* a, const bool* state_event);
00064 void external_event(double* q, double* a, double e,
00065 const adevs::Bag<adevs::PortValue<BasicEvent*> >& xb);
00066 void confluent_event(double* q, double* a, const bool* state_event,
00067 const adevs::Bag<adevs::PortValue<BasicEvent*> >& xb);
00068 void output_func(const double* q, const double* a, const bool* state_event,
00069 adevs::Bag<adevs::PortValue<BasicEvent*> >& yb);
00070 void postStep(double* q, double* a);
00071 void gc_output(adevs::Bag<adevs::PortValue<BasicEvent*> >& gb);
00073 Complex getVoltage(unsigned bus);
00075 double getGenrFreq(unsigned genr_number, const double *q);
00077 double getRealGenrPower(unsigned genr_number, const double *q);
00079 bool genrOffLine(unsigned genr_number);
00081 double getBusFreq(unsigned bus);
00087 double getVoltageWaveform(const double* q, unsigned bus);
00089 Complex getLoadPower(unsigned bus);
00091 ElectricalData* getElectricalData() { return data; }
00092 private:
00093
00094 class SensorInterface:
00095 public ElectricalSensorInterface
00096 {
00097 public:
00098 SensorInterface(ElectricalModelEqns* model):model(model){}
00099 Complex getVoltage(unsigned bus) { return model->getVoltage(bus); }
00100 double getBusAngle(unsigned bus) { return arg(getVoltage(bus)); }
00101 double getRealGenrPower(unsigned genr_number)
00102 {
00103 return model->getRealGenrPower(genr_number,q);
00104 }
00105 double getGenrFreq(unsigned genr_number)
00106 {
00107 return model->getGenrFreq(genr_number,q);
00108 }
00109 double getBusFreq(unsigned bus) { return model->getBusFreq(bus); }
00110 bool genrOffLine(unsigned genr_number) { return model->genrOffLine(genr_number); }
00111 Complex getLoadPower(unsigned bus) { return model->getLoadPower(bus); }
00112 void setStateVars(const double* q) { this->q = q; }
00113 private:
00115 const double* q;
00116 ElectricalModelEqns* model;
00117 };
00118 SensorInterface* evar_iface;
00119
00120 ElectricalData* data;
00121
00122
00123 const unsigned int num_nodes;
00124
00125 Complex* load_Yt;
00126 Complex* genr_Yt;
00127
00128 Complex *voltage, *current, *dV, *dI, *v0;
00129
00130 Complex *Ef;
00131
00132 double* load_freq;
00133
00134 bool* breaker_closed;
00135
00136 typedef enum { SAT, NOT_SAT, FALLING } ExcitationState;
00137 ExcitationState* excite_status;
00138
00139 std::vector<Sensor*> sensors, sensors_primed;
00140
00141 std::map<unsigned,unsigned> genr_bus_lookup;
00142
00143 bool no_events;
00144
00145 Complex load_adj;
00146
00147 AdmittanceNetwork Y;
00148
00149 double* Pref;
00150
00151 void init_model(ElectricalData* data, std::list<Sensor*>& sensors, bool no_events);
00152
00153 void solve_for_voltages(const double* q, const double* a);
00154
00155
00156 void solve_for_freq(const double* q);
00157 };
00158
00159 #endif