00001 #include "BusPowerListener.h" 00002 using namespace std; 00003 using namespace adevs; 00004 00005 BusPowerListener::BusPowerListener(ElectricalModel* model, double cint, string model_name): 00006 EventListener<PortValue<BasicEvent*> >(), 00007 cint(cint), 00008 pout(string(model_name+"_all_P.dat").c_str()), 00009 qout(string(model_name+"_all_Q.dat").c_str()), 00010 t_last_record(0.0), 00011 src(model) 00012 { 00013 } 00014 00015 void BusPowerListener::stateChange(Atomic<PortValue<BasicEvent*> >* model, double t) 00016 { 00017 if (t - t_last_record >= cint) 00018 { 00019 t_last_record = t; 00020 pout << t << " "; 00021 qout << t << " "; 00022 for (unsigned i = 0; i < src->getElectricalData()->getNodeCount(); i++) 00023 { 00024 Complex S = src->getLoadPower(i); 00025 pout << real(S) << " "; 00026 qout << imag(S) << " "; 00027 } 00028 pout << endl; 00029 qout << endl; 00030 } 00031 } 00032 00033 BusPowerListener::~BusPowerListener() 00034 { 00035 pout.close(); 00036 qout.close(); 00037 } 00038