Sophie

Sophie

distrib > Fedora > 18 > x86_64 > media > updates > by-pkgid > 45a94e45036b4f2592a7e2c3922f90c7 > files > 214

adevs-doc-2.6-4.fc18.noarch.rpm

#include "BusVoltsListener.h"
using namespace std;
using namespace adevs;

BusVoltsListener::BusVoltsListener(ElectricalModel* model, double cint, string model_name):
	EventListener<PortValue<BasicEvent*> >(),
	cint(cint),
	fout(string(model_name+"_volt.dat").c_str()),
	t_last_record(0.0),
	src(model)
{
	fout << 0.0;
	for (unsigned i = 0; i < src->getElectricalData()->getNodeCount(); i++)
	{
		fout << " " << abs(src->getVoltage(i));
	}
	fout << endl;
}

void BusVoltsListener::stateChange(Atomic<PortValue<BasicEvent*> >* model, double t)
{
	if (t - t_last_record >= cint)
	{
		t_last_record = t;
		fout << t;
		for (unsigned i = 0; i < src->getElectricalData()->getNodeCount(); i++)
		{
			fout << " " << abs(src->getVoltage(i));
		}
		fout << endl;
	}
}

BusVoltsListener::~BusVoltsListener()
{
	fout.close();
}