IdealVoltageSource.cpp 1.96 KB
Newer Older
Viviane's avatar
Viviane committed
1
2
3
4
#include "IdealVoltageSource.h"

using namespace DPsim;

5
IdealVoltageSource::IdealVoltageSource(std::string name, int src, int dest, Complex voltage, int num) : BaseComponent(name, src, dest) {
6
	this->number = num;
7
8
	this->mVoltage = voltage;
	attrMap["voltage"] = {AttrComplex, &this->mVoltage};
Viviane's avatar
Viviane committed
9
10
}

11
12
void IdealVoltageSource::applySystemMatrixStamp(SystemModel& system) {
	number = system.getNumIdealVS() - number + 1;
Viviane's avatar
Viviane committed
13
	if (mNode1 >= 0) {
14
15
16
17
		system.setSystemMatrixElement(system.getCompOffset() - number, mNode1, 1);
		system.setSystemMatrixElement(mNode1, system.getCompOffset() - number, 1);
		system.setSystemMatrixElement(2* system.getCompOffset() - number, mNode1 + system.getCompOffset(), 1);
		system.setSystemMatrixElement(mNode1 + system.getCompOffset(), 2 * system.getCompOffset() - number, 1);
Viviane's avatar
Viviane committed
18
19
20
	}

	if (mNode2 >= 0) {
21
22
23
24
		system.setSystemMatrixElement(system.getCompOffset() - number, mNode2, -1);
		system.setSystemMatrixElement(mNode2, system.getCompOffset() - number, -1);
		system.setSystemMatrixElement(2 * system.getCompOffset() - number, mNode2 + system.getCompOffset(), -1);
		system.setSystemMatrixElement(mNode2 + system.getCompOffset(), 2 * system.getCompOffset() - number, -1);
Viviane's avatar
Viviane committed
25
26
27
	}
}

28
void IdealVoltageSource::applyRightSideVectorStamp(SystemModel& system) {
Viviane's avatar
Viviane committed
29
	// Apply matrix stamp for equivalent current source
30
31
	system.addRealToRightSideVector(system.getCompOffset() - number, mVoltage.real());
	system.addRealToRightSideVector(2 * system.getCompOffset() - number, mVoltage.imag());
Viviane's avatar
Viviane committed
32
33
}

34
void IdealVoltageSource::step(SystemModel& system, Real time) {
Viviane's avatar
Viviane committed
35
	// Apply matrix stamp for equivalent current source
36
37
	system.addRealToRightSideVector(system.getCompOffset() - number, mVoltage.real());
	system.addRealToRightSideVector(2 * system.getCompOffset() - number, mVoltage.imag());
38
39
40
41
42
}

Complex IdealVoltageSource::getCurrent(SystemModel& system) {
	return Complex(system.getRealFromLeftSideVector(system.getCompOffset()-number), system.getRealFromLeftSideVector(2*system.getCompOffset()-number));
}