00001 #ifndef _GridWise2_h_
00002 #define _GridWise2_h_
00003 #include "events.h"
00004 #include "Sensor.h"
00005 #include "ElectricalData.h"
00006 #include <list>
00007 #include <map>
00008
00015 class GridFriendly2Load:
00016 public adevs::Atomic<adevs::PortValue<BasicEvent*> >
00017 {
00018 public:
00019 typedef enum { PROP, NONLIP } ControlType;
00021 static const int sensor_input;
00023 static const int base_load;
00028 GridFriendly2Load(unsigned BusID, ElectricalData* init_data);
00030 unsigned getBusID() const { return BusID; }
00034 static void setControlParams(double R, double freq_interval,
00035 double gfl_frac, ControlType control_type, double lip_exponent = 0.5);
00036 void delta_int();
00038 void delta_ext(double e, const adevs::Bag<adevs::PortValue<BasicEvent*> >& xb);
00039 void delta_conf(const adevs::Bag<adevs::PortValue<BasicEvent*> >& xb);
00041 void output_func(adevs::Bag<adevs::PortValue<BasicEvent*> >& yb);
00042 double ta();
00044 void gc_output(adevs::Bag<adevs::PortValue<BasicEvent*> >& gc);
00045
00046 static adevs::rv r;
00047 private:
00048 const unsigned BusID;
00049 Complex ybase;
00050 double load_sig[2];
00051 enum { ADJUST, WAIT } phase;
00052 int freq_pos;
00053 double localDroop, trip_interval;
00054 static double base_interval, droop, gfl_fraction, control_exponent;
00055 static ControlType ctype;
00056
00057 friend class GridFriendly2Sensor;
00058 };
00059
00063 class GridFriendly2Sensor:
00064 public Sensor
00065 {
00066 public:
00072 typedef enum { UP, DOWN } Direction;
00073 GridFriendly2Sensor(GridFriendly2Load* actuator, Direction dir, int* freq_pos);
00075 void trip(ElectricalSensorInterface* evars);
00077 double distFromTrip(ElectricalSensorInterface* evars);
00079 Direction getDirection() const { return dir; }
00081 ~GridFriendly2Sensor();
00083 static void makeSensors(GridFriendly2Load* actuator,
00084 GridFriendly2Sensor** up, GridFriendly2Sensor** down);
00085
00086 private:
00087 GridFriendly2Load* actuator;
00088 const Direction dir;
00089
00090
00091 int* pos;
00092 };
00093
00098 class GridFriendly2Network:
00099 public adevs::Network<adevs::PortValue<BasicEvent*> >
00100 {
00101 public:
00103 static const int sensor_trip;
00105 static const int load_change;
00107 static const int base_load;
00112 GridFriendly2Network(ElectricalData* data);
00117 void getSensors(std::list<Sensor*>& sensors);
00121 void route(const adevs::PortValue<BasicEvent*>& value,
00122 adevs::Devs<adevs::PortValue<BasicEvent*> >* model,
00123 adevs::Bag<adevs::Event<adevs::PortValue<BasicEvent*> > >& r);
00127 void getComponents(adevs::Set<adevs::Devs<adevs::PortValue<BasicEvent*> >* >& c);
00129 ~GridFriendly2Network();
00130 private:
00131 std::map<GridFriendly2Load*,GridFriendly2Load*> loads;
00132 };
00133
00134 #endif