Commit e7db8b4a authored by Viviane's avatar Viviane
Browse files

finished PiLine model

parent 4b8822e5
......@@ -82,6 +82,11 @@ void PiLine::init(Real om, Real dt) {
mDeltaVre = 0;
mDeltaVim = 0;
mVoltageAtNode1Re = 0;
mVoltageAtNode1Im = 0;
mVoltageAtNode2Re = 0;
mVoltageAtNode2Im = 0;
}
void PiLine::step(SystemModel& system, Real time) {
......@@ -98,6 +103,7 @@ void PiLine::step(SystemModel& system, Real time) {
}
// Initialize internal state capacitance 1
mCurEqCapRe1 = mCurrCapRe1 + mGcr * mVoltageAtNode1Re + mGci * mVoltageAtNode1Im;
mCurEqCapIm1 = mCurrCapIm1 + mGcr * mVoltageAtNode1Im - mGci * mVoltageAtNode1Re;
......@@ -122,20 +128,13 @@ void PiLine::postStep(SystemModel& system) {
vposr = system.getRealFromLeftSideVector(mNode3);
vposi = system.getImagFromLeftSideVector(mNode3);
}
else {
vposr = 0;
vposi = 0;
}
if (mNode2 >= 0) {
system.getRealFromLeftSideVector(mNode2);
vnegr = system.getRealFromLeftSideVector(mNode2);
vnegi = system.getImagFromLeftSideVector(mNode2);
}
else {
vnegr = 0;
vnegi = 0;
}
mDeltaVre = vposr - vnegr;
mDeltaVim = vposi - vnegi;
mCurrIndRe = mGlr * mDeltaVre - mGli * mDeltaVim + mCurEqIndRe;
......
......@@ -12,15 +12,18 @@ int main(int argc, char* argv[]) {
simulationExample1();
simulationExample2();
simulationExample3();
simulationExampleIdealVS();
simulationExampleIdealVS2();
simulationExampleIdealVS3();
simulationExampleRXLine3();
simulationExampleRXLine();
simulationExampleRXLine2();
//simulationExample1();
//simulationExample2();
//simulationExample3();
//simulationExampleIdealVS();
//simulationExampleIdealVS2();
//simulationExampleIdealVS3();
//simulationExampleRXLine3();
//simulationExampleRXLine();
//simulationExampleRXLine2();
simulationExamplePiLine();
simulationExamplePiLine2();
//NetlistSim(argc, argv);
......
......@@ -395,4 +395,87 @@ void DPsim::simulationExampleRXLine3()
log.WriteLogToFile("Logs/Log_" + fileName.str() + ".log");
leftVectorLog.WriteLogToFile("Logs/LeftVectorLog_" + fileName.str() + ".csv");
rightVectorLog.WriteLogToFile("Logs/RightVectorLog_" + fileName.str() + ".csv");
}
void DPsim::simulationExamplePiLine()
{
// Define Object for saving data on a file
Logger log, leftVectorLog, rightVectorLog;
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, 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));
std::cout << "The contents of circElements0 are:";
for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
std::cout << "Added " << (*it)->getName() << std::endl;
}
std::cout << '\n';
// Set up simulation
Real timeStep = 0.001;
Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);
// Main Simulation Loop
std::cout << "Start simulation." << std::endl;
while (newSim.step(log, leftVectorLog, rightVectorLog))
{
newSim.increaseByTimeStep();
updateProgressBar(newSim.getTime(), newSim.getFinalTime());
}
std::cout << "Simulation finished." << std::endl;
// Write simulation data to file
std::ostringstream fileName;
fileName << "SimulationExamplePiLine_" << timeStep;
log.WriteLogToFile("Logs/Log_" + fileName.str() + ".log");
leftVectorLog.WriteLogToFile("Logs/LeftVectorLog_" + fileName.str() + ".csv");
rightVectorLog.WriteLogToFile("Logs/RightVectorLog_" + fileName.str() + ".csv");
}
void DPsim::simulationExamplePiLine2()
{
// Define Object for saving data on a file
Logger log, leftVectorLog, rightVectorLog;
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, 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));
circElements0.push_back(new Inductor("l_1", 4, 3, 0.186));
circElements0.push_back(new Capacitor("c_2", 3, 0, 0.002));
circElements0.push_back(new LinearResistor("r_load", 3, 0, 150));
std::cout << "The contents of circElements0 are:";
for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
std::cout << "Added " << (*it)->getName() << std::endl;
}
std::cout << '\n';
// Set up simulation
Real timeStep = 0.001;
Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);
// Main Simulation Loop
std::cout << "Start simulation." << std::endl;
while (newSim.step(log, leftVectorLog, rightVectorLog))
{
newSim.increaseByTimeStep();
updateProgressBar(newSim.getTime(), newSim.getFinalTime());
}
std::cout << "Simulation finished." << std::endl;
// Write simulation data to file
std::ostringstream fileName;
fileName << "SimulationExamplePiLine2_" << timeStep;
log.WriteLogToFile("Logs/Log_" + fileName.str() + ".log");
leftVectorLog.WriteLogToFile("Logs/LeftVectorLog_" + fileName.str() + ".csv");
rightVectorLog.WriteLogToFile("Logs/RightVectorLog_" + fileName.str() + ".csv");
}
\ No newline at end of file
......@@ -15,5 +15,7 @@ namespace DPsim {
void simulationExampleRXLine();
void simulationExampleRXLine2();
void simulationExampleRXLine3();
void simulationExamplePiLine();
void simulationExamplePiLine2();
}
#endif
......@@ -47,7 +47,7 @@ Simulation::~Simulation() {
void Simulation::initialize(std::vector<BaseComponent*> newElements) {
int maxNode = 0;
Int numIdealVS = 0;
int numRxLines = 0;
int numLines = 0;
mElementsVector.push_back(newElements);
mElements = mElementsVector[0];
......@@ -65,15 +65,15 @@ void Simulation::initialize(std::vector<BaseComponent*> newElements) {
if (type == "class DPsim::IdealVoltageSource") {
numIdealVS = numIdealVS + 1;
}
if (type == "class DPsim::RxLine") {
if (type == "class DPsim::RxLine" || type == "class DPsim::PiLine") {
if ((*it)->getNode3() != -1) {
numRxLines = numRxLines + 1;
numLines = numLines + 1;
}
}
}
Int numNodes = maxNode + 1 + numIdealVS + numRxLines;
Int numNodes = maxNode + 1 + numIdealVS + numLines;
mSystemModel.initialize(numNodes,numIdealVS);
addSystemTopology(mElements);
......
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