Select Git revision
ReferenceCircuits.cpp
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ReferenceCircuits.cpp 17.04 KiB
#include "ReferenceCircuits.h"
#include "../Simulation.h"
#include "../Utilities.h"
using namespace DPsim;
void DPsim::simulationExample1()
{
// Define Object for saving data on a file
Logger log, leftVectorLog, rightVectorLog;
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, 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));
circElements0.push_back(new LinearResistor("r_2", 3, 0, 2));
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 << "SimulationExample1_" << timeStep;
log.WriteLogToFile("Logs/Log_" + fileName.str() + ".log");
leftVectorLog.WriteLogToFile("Logs/LeftVectorLog_" + fileName.str() + ".csv");
rightVectorLog.WriteLogToFile("Logs/RightVectorLog_" + fileName.str() + ".csv");
}
void DPsim::simulationExample1L2()
{
// Define Object for saving data on a file
Logger log, leftVectorLog, rightVectorLog;
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new VoltSourceRes("v_in", 1, 0, 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));
circElements0.push_back(new LinearResistor("r_2", 3, 0, 2));
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