00001 #include "BusVoltageListener.h" 00002 using namespace std; 00003 using namespace adevs; 00004 00005 BusVoltageListener::BusVoltageListener(ElectricalModel* model, double cint, string model_name): 00006 EventListener<PortValue<BasicEvent*> >(), 00007 cint(cint), 00008 fout(string(model_name+"_all_volts.dat").c_str()), 00009 t_last_record(0.0), 00010 src(model) 00011 { 00012 } 00013 00014 void BusVoltageListener::stateChange(Atomic<PortValue<BasicEvent*> >* model, double t) 00015 { 00016 if (t - t_last_record >= cint) 00017 { 00018 t_last_record = t; 00019 fout << t << " "; 00020 for (unsigned i = 0; i < src->getElectricalData()->getNodeCount(); i++) 00021 { 00022 fout << abs(src->getVoltage(i)) << " "; 00023 } 00024 fout << endl; 00025 } 00026 } 00027 00028 BusVoltageListener::~BusVoltageListener() 00029 { 00030 fout.close(); 00031 } 00032