Commit ad4b3f2d authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

implement complex Python attributes; use Complex more consequently

parent 5e3d3b8a
......@@ -104,7 +104,7 @@ BaseComponent* CIMReader::mapExternalNetworkInjection(ExternalNetworkInjection*
}
std::cerr << "IdealVoltageSource " << inj->name << " rid=" << inj->mRID << " node1=" << node << " node2=0 ";
std::cerr << " V=" << volt->v.value << "<" << volt->angle.value << std::endl;
return new IdealVoltageSource(inj->name, node, 0, volt->v.value, volt->angle.value*PI/180, ++mNumVoltageSources);
return new IdealVoltageSource(inj->name, node, 0, Complex(volt->v.value, volt->angle.value*PI/180), ++mNumVoltageSources);
}
BaseComponent* CIMReader::mapPowerTransformer(PowerTransformer* trans) {
......@@ -145,7 +145,7 @@ BaseComponent* CIMReader::mapSynchronousMachine(SynchronousMachine* machine) {
std::cerr << "VoltSourceRes " << machine->name << " rid=" << machine->mRID << " node1=" << node << " node2=0 ";
std::cerr << " V=" << volt->v.value << "<" << volt->angle.value << " R=" << machine->r.value << std::endl;
// TODO is it appropiate to use this resistance here
return new VoltSourceRes(machine->name, node, 0, volt->v.value, volt->angle.value*PI/180, machine->r.value);
return new VoltSourceRes(machine->name, node, 0, Complex(volt->v.value, volt->angle.value*PI/180), machine->r.value);
}
BaseComponent* CIMReader::mapComponent(BaseClass* obj) {
......
......@@ -14,6 +14,7 @@ namespace DPsim {
AttrReal,
AttrInt,
AttrString, // value should be *std::string, not *char!
AttrComplex
};
struct CompAttr {
......
......@@ -2,17 +2,17 @@
using namespace DPsim;
CurrentSource::CurrentSource(std::string name, int src, int dest, double current, double phase) : BaseComponent(name, src, dest) {
this->currentr = current*cos(phase);
this->currenti = current*sin(phase);
CurrentSource::CurrentSource(std::string name, int src, int dest, Complex current) : BaseComponent(name, src, dest) {
this->mCurrent = current;
attrMap["current"] = {AttrComplex, &this->mCurrent};
};
void CurrentSource::applyRightSideVectorStamp(SystemModel& system) {
if (mNode1 >= 0) {
system.addCompToRightSideVector(mNode1, currentr, currenti);
system.addCompToRightSideVector(mNode1, mCurrent.real(), mCurrent.imag());
}
if (mNode2 >= 0) {
system.addCompToRightSideVector(mNode2, -currentr, -currenti);
system.addCompToRightSideVector(mNode2, -mCurrent.real(), mCurrent.imag());
}
}
......@@ -21,5 +21,5 @@ void CurrentSource::step(SystemModel& system, Real time) {
}
Complex CurrentSource::getCurrent(SystemModel &system) {
return Complex(currentr, currenti);
return mCurrent;
}
......@@ -7,12 +7,11 @@ namespace DPsim {
class CurrentSource : public BaseComponent {
protected:
double currentr;
double currenti;
Complex mCurrent;
public:
CurrentSource() { ; };
CurrentSource(std::string name, int src, int dest, double current, double phase);
CurrentSource(std::string name, int src, int dest, Complex current);
void init(Real om, Real dt) { }
void applySystemMatrixStamp(SystemModel& system) { }
......
......@@ -2,11 +2,10 @@
using namespace DPsim;
ExternalCurrentSource::ExternalCurrentSource(std::string name, int src, int dest, Real initCurrent, Real initPhase) :
CurrentSource(name, src, dest, initCurrent, initPhase) {
ExternalCurrentSource::ExternalCurrentSource(std::string name, int src, int dest, Complex initCurrent) :
CurrentSource(name, src, dest, initCurrent) {
}
void ExternalCurrentSource::setCurrent(Real real, Real imag) {
this->currentr = real;
this->currenti = imag;
this->mCurrent = Complex(real, imag);
}
......@@ -9,7 +9,7 @@ namespace DPsim {
public:
ExternalCurrentSource() {};
ExternalCurrentSource(std::string name, int src, int dest, Real initCurrent, Real initPhase);
ExternalCurrentSource(std::string name, int src, int dest, Complex current);
void setCurrent(Real real, Real imag);
};
......
......@@ -2,11 +2,10 @@
using namespace DPsim;
ExternalVoltageSource::ExternalVoltageSource(std::string name, int src, int dest, Real initVoltage, Real initPhase, int num) :
IdealVoltageSource(name, src, dest, initVoltage, initPhase, num) {
ExternalVoltageSource::ExternalVoltageSource(std::string name, int src, int dest, Complex voltage, int num) :
IdealVoltageSource(name, src, dest, voltage, num) {
}
void ExternalVoltageSource::setVoltage(Real real, Real imag) {
this->mVoltageDiffr = real;
this->mVoltageDiffi = imag;
this->mVoltage = Complex(real, imag);
}
......@@ -9,7 +9,7 @@ namespace DPsim {
public:
ExternalVoltageSource() {};
ExternalVoltageSource(std::string name, int src, int dest, Real initVoltage, Real initPhase, int num);
ExternalVoltageSource(std::string name, int src, int dest, Complex voltage, int num);
void setVoltage(Real real, Real imag);
};
......
......@@ -2,10 +2,10 @@
using namespace DPsim;
IdealVoltageSource::IdealVoltageSource(std::string name, int src, int dest, Real voltage, Real phase, int num) : BaseComponent(name, src, dest) {
IdealVoltageSource::IdealVoltageSource(std::string name, int src, int dest, Complex voltage, int num) : BaseComponent(name, src, dest) {
this->number = num;
this->mVoltageDiffr = voltage*cos(phase);
this->mVoltageDiffi = voltage*sin(phase);
this->mVoltage = voltage;
attrMap["voltage"] = {AttrComplex, &this->mVoltage};
}
void IdealVoltageSource::applySystemMatrixStamp(SystemModel& system) {
......@@ -27,14 +27,14 @@ void IdealVoltageSource::applySystemMatrixStamp(SystemModel& system) {
void IdealVoltageSource::applyRightSideVectorStamp(SystemModel& system) {
// Apply matrix stamp for equivalent current source
system.addRealToRightSideVector(system.getCompOffset() - number, mVoltageDiffr);
system.addRealToRightSideVector(2 * system.getCompOffset() - number, mVoltageDiffi);
system.addRealToRightSideVector(system.getCompOffset() - number, mVoltage.real());
system.addRealToRightSideVector(2 * system.getCompOffset() - number, mVoltage.imag());
}
void IdealVoltageSource::step(SystemModel& system, Real time) {
// Apply matrix stamp for equivalent current source
system.addRealToRightSideVector(system.getCompOffset() - number, mVoltageDiffr);
system.addRealToRightSideVector(2 * system.getCompOffset() - number, mVoltageDiffi);
system.addRealToRightSideVector(system.getCompOffset() - number, mVoltage.real());
system.addRealToRightSideVector(2 * system.getCompOffset() - number, mVoltage.imag());
}
Complex IdealVoltageSource::getCurrent(SystemModel& system) {
......
......@@ -15,9 +15,8 @@ namespace DPsim {
protected:
// ### Ideal Voltage source parameters ###
/// Real and imaginary part of the voltage [V]
Real mVoltageDiffr;
Real mVoltageDiffi;
/// Complex voltage [V]
Complex mVoltage;
Real mVoltageAtSourcer;
Real mVoltageAtSourcei;
......@@ -33,7 +32,7 @@ namespace DPsim {
IdealVoltageSource() { ; };
/// define paramenters of the voltage source
IdealVoltageSource(std::string name, int src, int dest, Real voltage, Real phase, int num);
IdealVoltageSource(std::string name, int src, int dest, Complex voltage, int num);
void init(Real om, Real dt) { }
......
......@@ -2,16 +2,17 @@
using namespace DPsim;
VoltSourceRes::VoltSourceRes(std::string name, int src, int dest, Real voltage, Real phase, Real resistance) : BaseComponent(name, src, dest) {
this->mVoltageDiffr = voltage*cos(phase);
this->mVoltageDiffi = voltage*sin(phase);
VoltSourceRes::VoltSourceRes(std::string name, int src, int dest, Complex voltage, Real resistance) : BaseComponent(name, src, dest) {
this->mVoltage = voltage;
this->mResistance = resistance;
this->mConductance = 1. / resistance;
this->mCurrentr = mVoltageDiffr / resistance;
this->mCurrenti = mVoltageDiffi / resistance;
attrMap["voltage"] = {AttrComplex, &this->mVoltage};
attrMap["resistance"] = {AttrReal, &this->mResistance};
}
void VoltSourceRes::applySystemMatrixStamp(SystemModel& system) {
mConductance = 1. / mResistance;
mCurrentr = mVoltage.real() / mResistance;
mCurrenti = mVoltage.imag() / mResistance;
// Apply matrix stamp for equivalent resistance
if (mNode1 >= 0) {
system.addCompToSystemMatrix(mNode1, mNode1, mConductance, 0);
......
......@@ -14,10 +14,8 @@ namespace DPsim {
protected:
// ### Real Voltage source parameters ###
/// Real part of the voltage [V]
Real mVoltageDiffr;
/// Imaginary part of the voltage [V]
Real mVoltageDiffi;
/// Complex voltage [V]
Complex mVoltage;
/// Resistance [ohm]
Real mResistance;
......@@ -34,7 +32,7 @@ namespace DPsim {
VoltSourceRes() { ; };
/// define voltage source paramenters
VoltSourceRes(std::string name, int src, int dest, Real voltage, Real phase, Real resistance);
VoltSourceRes(std::string name, int src, int dest, Complex voltage, Real resistance);
void init(Real om, Real dt) { }
......
......@@ -2,16 +2,13 @@
using namespace DPsim;
VoltSourceResEMT::VoltSourceResEMT(std::string name, int src, int dest, Real voltage, Real phase, Real resistance) : BaseComponent(name, src, dest) {
mVoltageAmp = voltage;
mVoltagePhase = phase;
VoltSourceResEMT::VoltSourceResEMT(std::string name, int src, int dest, Complex voltage, Real resistance) : BaseComponent(name, src, dest) {
mVoltage = voltage;
mResistance = resistance;
mVoltageDiff = mVoltageAmp*cos(mVoltagePhase);
mConductance = 1. / mResistance;
mCurrent = mVoltageDiff / mResistance;
}
void VoltSourceResEMT::applySystemMatrixStamp(SystemModel& system) {
mConductance = 1. / mResistance;
// Apply matrix stamp for equivalent resistance
if (mNode1 >= 0) {
system.addRealToSystemMatrix(mNode1, mNode1, mConductance);
......@@ -26,6 +23,7 @@ void VoltSourceResEMT::applySystemMatrixStamp(SystemModel& system) {
}
void VoltSourceResEMT::applyRightSideVectorStamp(SystemModel& system) {
mCurrent = mVoltage.real() / mResistance;
// Apply matrix stamp for equivalent current source
if (mNode1 >= 0) {
system.addRealToRightSideVector(mNode1, mCurrent);
......@@ -37,7 +35,7 @@ void VoltSourceResEMT::applyRightSideVectorStamp(SystemModel& system) {
void VoltSourceResEMT::step(SystemModel& system, Real time) {
mVoltageDiff = mVoltageAmp * cos(mVoltagePhase + system.getOmega() * time);
mVoltageDiff = std::abs(mVoltage) * cos(std::arg(mVoltage) + system.getOmega() * time);
mCurrent = mVoltageDiff / mResistance;
if (mNode1 >= 0) {
......
......@@ -7,6 +7,7 @@ namespace DPsim {
class VoltSourceResEMT : public BaseComponent {
protected:
Complex mVoltage;
Real mVoltageAmp;
Real mVoltagePhase;
Real mVoltageDiff;
......@@ -16,7 +17,7 @@ namespace DPsim {
public:
VoltSourceResEMT() { ; };
VoltSourceResEMT(std::string name, int src, int dest, Real voltage, Real phase, Real resistance);
VoltSourceResEMT(std::string name, int src, int dest, Complex voltage, Real resistance);
void init(Real om, Real dt) { }
void applySystemMatrixStamp(SystemModel& system);
......
......@@ -18,7 +18,7 @@ void DPsim::simulationExample1()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, 10, 0, 1));
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new Inductor("l_1", 1, 2, 0.02));
circElements0.push_back(new Inductor("l_2", 2, 0, 0.1));
circElements0.push_back(new Inductor("l_3", 2, 3, 0.05));
......@@ -58,7 +58,7 @@ void DPsim::simulationExample1L2()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, 10, 0, 1));
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new Inductor("l_1", 1, 2, 0.02));
circElements0.push_back(new Inductor("l_2", 2, 0, 0.1));
circElements0.push_back(new Inductor("l_3", 2, 3, 0.05));
......@@ -98,7 +98,7 @@ void DPsim::simulationExample2()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, 10, 0, 1));
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new Inductor("l_1", 1, 2, 0.02));
circElements0.push_back(new Inductor("l_2", 2, 0, 0.1));
......@@ -136,7 +136,7 @@ void DPsim::simulationExample3()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, 10, 0, 1));
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new Capacitor("c_1", 1, 2, 0.001));
circElements0.push_back(new Inductor("l_1", 2, 0, 0.001));
circElements0.push_back(new LinearResistor("r_2", 2, 0, 1));
......@@ -175,7 +175,7 @@ void DPsim::simulationExampleIdealVS()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_in", 1, 2, 10, 0, 1));
circElements0.push_back(new IdealVoltageSource("v_in", 1, 2, Complex(10, 0), 1));
circElements0.push_back(new LinearResistor("r_1", 1, 0, 1));
circElements0.push_back(new LinearResistor("r_2", 2, 0, 1));
circElements0.push_back(new LinearResistor("r_3", 2, 0, 1));
......@@ -214,7 +214,7 @@ void DPsim::simulationExampleIdealVS2()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_in", 1, 0, 10, 0, 1));
circElements0.push_back(new IdealVoltageSource("v_in", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new LinearResistor("r_1", 1, 2, 1));
circElements0.push_back(new Capacitor("c_1", 2, 3, 0.001));
circElements0.push_back(new Inductor("l_1", 3, 0, 0.001));
......@@ -255,13 +255,13 @@ void DPsim::simulationExampleIdealVS3()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, 10, 0, 1));
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new LinearResistor("r_1", 1, 2, 1));
circElements0.push_back(new LinearResistor("r_2", 2, 0, 1));
circElements0.push_back(new LinearResistor("r_3", 2, 3, 1));
circElements0.push_back(new LinearResistor("r_4", 3, 0, 1));
circElements0.push_back(new LinearResistor("r_5", 3, 4, 1));
circElements0.push_back(new IdealVoltageSource("v_2", 4, 0, 20, 0, 2));
circElements0.push_back(new IdealVoltageSource("v_2", 4, 0, Complex(20, 0), 2));
......@@ -300,7 +300,7 @@ void DPsim::simulationExampleRXLine()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, 10, 0, 1));
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new RxLine("Line_1", 1, 2, 3, 0.1, 0.001));
circElements0.push_back(new LinearResistor("r_1", 2, 0, 20));
......@@ -339,7 +339,7 @@ void DPsim::simulationExampleRXLine2()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, 10, 0, 1));
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new Inductor("l_L", 2, 3, 0.001));
circElements0.push_back(new LinearResistor("r_L", 1, 2, 0.1));
......@@ -380,7 +380,7 @@ void DPsim::simulationExampleRXLine3()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, 10, 0, 1));
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(10, 0), 1));
circElements0.push_back(new RxLine("Line_1", 1, 2, 0.1, 0.001));
circElements0.push_back(new LinearResistor("r_1", 2, 0, 20));
......@@ -419,7 +419,7 @@ void DPsim::simulationExamplePiLine()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, 345, 0, 1));
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(345, 0), 1));
circElements0.push_back(new LinearResistor("r1", 1, 2, 5));
circElements0.push_back(new PiLine("PiLine1", 2, 3, 4, 6.4, 0.186, 0.004));
circElements0.push_back(new LinearResistor("r_load", 3, 0, 150));
......@@ -460,7 +460,7 @@ void DPsim::simulationExamplePiLine2()
rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, 345, 0, 1));
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(345, 0), 1));
circElements0.push_back(new LinearResistor("r1", 1, 2, 5));
circElements0.push_back(new Capacitor("c_1", 2, 0, 0.002));
circElements0.push_back(new LinearResistor("r_load", 2, 4, 6.4));
......
......@@ -14,7 +14,7 @@ void DPsim::shmemExample()
Logger log("output.log"), llog("lvector.log"), rlog("rvector.log");
std::vector<BaseComponent*> comps;
ExternalVoltageSource *evs = new ExternalVoltageSource("v_s", 1, 0, 0, 0, 1);
ExternalVoltageSource *evs = new ExternalVoltageSource("v_s", 1, 0, Complex(0, 0), 1);
comps.push_back(evs);
comps.push_back(new LinearResistor("r_s", 1, 2, 1));
comps.push_back(new LinearResistor("r_line", 2, 3, 1));
......@@ -53,7 +53,7 @@ void DPsim::shmemRTExample()
conf.polling = false;
Logger log;
ExternalVoltageSource *evs = new ExternalVoltageSource("v_s", 1, 0, 0, 0, 1);
ExternalVoltageSource *evs = new ExternalVoltageSource("v_s", 1, 0, Complex(0, 0), 1);
comps.push_back(evs);
comps.push_back(new LinearResistor("r_s", 1, 2, 1));
comps.push_back(new LinearResistor("r_line", 2, 3, 1));
......@@ -101,15 +101,15 @@ void DPsim::shmemDistributedDirect(int argc, char *argv[])
}
if (!strcmp(argv[1], "0")) {
comps.push_back(new VoltSourceRes("v_s", 1, 0, 10000, 0, 1));
comps.push_back(new VoltSourceRes("v_s", 1, 0, Complex(10000, 0), 1));
comps.push_back(new Inductor("l_1", 1, 2, 1e-3));
ExternalVoltageSource *evs = new ExternalVoltageSource("v_t", 2, 0, 0, 0, 1);
ExternalVoltageSource *evs = new ExternalVoltageSource("v_t", 2, 0, Complex(0, 0), 1);
comps.push_back(evs);
shmem = new ShmemInterface("/dpsim01", "/dpsim10", &conf);
shmem->registerVoltageSource(evs, 0, 1);
shmem->registerExportedCurrent(evs, 0, 1);
} else if (!strcmp(argv[1], "1")) {
ExternalCurrentSource *ecs = new ExternalCurrentSource("v_s", 1, 0, 0, 0);
ExternalCurrentSource *ecs = new ExternalCurrentSource("v_s", 1, 0, Complex(0, 0));
comps.push_back(ecs);
comps.push_back(new LinearResistor("r_2", 1, 0, 1));
shmem = new ShmemInterface("/dpsim10", "/dpsim01", &conf);
......@@ -154,17 +154,17 @@ void DPsim::shmemDistributed(int argc, char *argv[])
if (!strcmp(argv[1], "0")) {
logname = "lvector0.log";
comps.push_back(new VoltSourceRes("v_s", 1, 0, 10000, 0, 1));
comps.push_back(new VoltSourceRes("v_s", 1, 0, Complex(10000, 0), 1));
comps.push_back(new Inductor("l_1", 1, 2, 0.1));
comps.push_back(new LinearResistor("r_1", 2, 3, 1));
ExternalVoltageSource *evs = new ExternalVoltageSource("v_t", 3, 0, 0, 0, 1);
ExternalVoltageSource *evs = new ExternalVoltageSource("v_t", 3, 0, Complex(0, 0), 1);
comps.push_back(evs);
shmem = new ShmemInterface("/villas1-in", "/villas1-out", &conf);
shmem->registerVoltageSource(evs, 0, 1);
shmem->registerExportedCurrent(evs, 0, 1);
} else if (!strcmp(argv[1], "1")) {
logname = "lvector1.log";
ExternalCurrentSource *ecs = new ExternalCurrentSource("v_s", 1, 0, 0, 0);
ExternalCurrentSource *ecs = new ExternalCurrentSource("v_s", 1, 0, Complex(0, 0));
comps.push_back(ecs);
comps.push_back(new LinearResistor("r_2", 1, 0, 10));
shmem = new ShmemInterface("/villas2-in", "/villas2-out", &conf);
......@@ -207,7 +207,7 @@ void DPsim::shmemDistributedRef()
Logger log("output.log"), llog("lvector.log"), rlog("rvector.log");
std::vector<BaseComponent*> comps, comps2;
comps.push_back(new VoltSourceRes("v_s", 1, 0, 10000, 0, 1));
comps.push_back(new VoltSourceRes("v_s", 1, 0, Complex(10000, 0), 1));
comps.push_back(new Inductor("l_1", 1, 2, 0.1));
comps.push_back(new LinearResistor("r_1", 2, 3, 1));
comps2 = comps;
......
......@@ -18,7 +18,7 @@ void DPsim::RXLineResLoad() {
// Declare circuit components
std::vector<BaseComponent*> circElements0, circElements1, circElements2;
circElements0.push_back(new VoltSourceRes("v_s", 1, 0, 10000, 0, 1));
circElements0.push_back(new VoltSourceRes("v_s", 1, 0, Complex(10000, 0), 1));
circElements0.push_back(new LinearResistor("r_line", 1, 2, 1));
circElements0.push_back(new Inductor("l_line", 2, 3, 1));
circElements1 = circElements0;
......@@ -96,7 +96,7 @@ void DPsim::RXLineResLoadEMT() {
// Declare circuit components
std::vector<BaseComponent*> circElements0, circElements1, circElements2;
circElements0.push_back(new VoltSourceResEMT("v_s", 1, 0, 10000, 0, 1));
circElements0.push_back(new VoltSourceResEMT("v_s", 1, 0, Complex(10000, 0), 1));
circElements0.push_back(new LinearResistorEMT("r_line", 1, 2, 1));
circElements0.push_back(new InductorEMT("l_line", 2, 3, 1));
circElements1 = circElements0;
......@@ -215,7 +215,7 @@ void DPsim::RTExample() {
std::vector<BaseComponent*> comps;
Logger log;
comps.push_back(new VoltSourceRes("v_s", 1, 0, 10000, 0, 1));
comps.push_back(new VoltSourceRes("v_s", 1, 0, Complex(10000, 0), 1));
comps.push_back(new LinearResistor("r_line", 1, 2, 1));
comps.push_back(new Inductor("l_line", 2, 3, 1));
comps.push_back(new LinearResistor("r_load", 3, 0, 1000));
......
......@@ -82,6 +82,11 @@ PyObject* PyComponent::getattr(PyComponent* self, char* name) {
return PyFloat_FromDouble(*((Real*) attr.value));
case AttrInt:
return PyLong_FromLong(*((Integer*) attr.value));
case AttrString:
return PyUnicode_FromString(((std::string*) attr.value)->c_str());
case AttrComplex:
Complex c = *((Complex*) attr.value);
return PyComplex_FromDoubles(c.real(), c.imag());
}
PyErr_Format(PyExc_SystemError, "invalid type in internal attribute map");
return nullptr;
......@@ -115,6 +120,16 @@ int PyComponent::setattr(PyComponent* self, char* name, PyObject *v) {
return -1;
*((Integer*) attr.value) = i;
break;
case AttrString:
if (!PyUnicode_Check(v))
return -1;
*((std::string*) attr.value) = std::string(PyUnicode_AsUTF8(v));
break;
case AttrComplex:
if (!PyComplex_Check(v))
return -1;
*((Complex*) attr.value) = Complex(PyComplex_RealAsDouble(v), PyComplex_ImagAsDouble(v));
break;
default:
PyErr_Format(PyExc_SystemError, "invalid type in internal attribute map");
return -1;
......
......@@ -37,6 +37,10 @@ void SystemModel::addCompToSystemMatrix(Int row, Int column, Real reValue, Real
mSystemMatrix(row + mCompOffset, column) = mSystemMatrix(row + mCompOffset, column) + imValue;
}
void SystemModel::addCompToSystemMatrix(Int row, Int column, Complex value) {
addCompToSystemMatrix(row, column, value.real(), value.imag());
}
void SystemModel::addCompToRightSideVector(Int row, Real reValue, Real imValue) {
mRightSideVector(row, 0) = mRightSideVector(row, 0) + reValue;
mRightSideVector(row + mCompOffset, 0) = mRightSideVector(row + mCompOffset, 0) + imValue;
......
......@@ -77,6 +77,7 @@ namespace DPsim {
void switchSystemMatrix(Int systemMatrixIndex);
void addRealToSystemMatrix(Int row, Int column, Real value);
void addCompToSystemMatrix(Int row, Int column, Real reValue, Real imValue);
void addCompToSystemMatrix(Int row, Int column, Complex value);
void addCompToRightSideVector(Int row, Real reValue, Real imValue);
void addRealToRightSideVector(Int row, Real value);
void setRightSideVectorToZero();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment