Skip to content
Snippets Groups Projects
Select Git revision
  • e7db8b4a57b318cd0285c04e999db3527e84c6a9
  • master default protected
  • fgh-updated-cw
  • cuda-solver-fix
  • fix-rocky-dockerfile
  • fgh-ba-mielchen
  • fgh-updated-base
  • i-nergy-ASM
  • emt-syngen-trstab
  • mnasolver-plugins
  • vs-signal-gen-follow-up-rebase6
  • fgh_cw_csv_sourcereader
  • sg-controllers
  • slew-scenarios-all-updated-villas
  • 4OrderSG-iter
  • SynGenModels
  • syngen-vbr-nicslu
  • slew-scenarios-all
  • slew-scenario-2
  • gh-actions
  • villas-interface
  • v1.0.0
  • v0.1.6
  • v0.1.5
  • v0.1.3
  • v0.1.1
  • v0.1.0
27 results

ReferenceCircuits.cpp

Blame
  • 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