VillasTest.cpp 1.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
#include "VillasTest.h"
#include "../Simulation.h"
#include "../VillasInterface.h"
#include "../Utilities.h"

using namespace DPsim;

void DPsim::villasExample()
{
10
	// Very simple test circuit. Just 2 resistors and a current read from VILLASnode.
11
12
13
	Logger log, llog, rlog;
	std::vector<BaseComponent*> comps;

Georg Martin Reinke's avatar
Georg Martin Reinke committed
14
	ExternalVoltageSource *evs = new ExternalVoltageSource("v_s", 1, 0, 1);
15
	comps.push_back(evs);
Georg Martin Reinke's avatar
Georg Martin Reinke committed
16
17
18
19
	comps.push_back(new LinearResistor("r_s", 1, 2, 1));
	comps.push_back(new LinearResistor("r_line", 2, 3, 1));
	comps.push_back(new Inductor("l_line", 3, 4, 1));
	comps.push_back(new LinearResistor("r_load", 4, 0, 1000));
20
	VillasInterface *villas = new VillasInterface("/villas1");
21
22
	villas->registerVoltageSource(evs, 0, 1);
	villas->registerExportedCurrent(evs, 0, 1);
23
24

	// Set up simulation
Georg Martin Reinke's avatar
Georg Martin Reinke committed
25
26
	Real timeStep = 0.001;
	Simulation newSim(comps, 2.0*M_PI*50.0, timeStep, 0.3, log);
27
28
29
30
31
32
33
34
35
36
37
38
39
	newSim.addExternalInterface(villas);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, llog, rlog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;
	log.WriteLogToFile("output.log");
	rlog.WriteLogToFile("rvector.log");
	llog.WriteLogToFile("lvector.log");
40
41
42
43
	for (auto comp : comps) {
		delete comp;
	}
	delete villas;
44
}