Commit c43efaae authored by Markus Mirz's avatar Markus Mirz
Browse files

loglevel filter

parent e60a2efa
......@@ -197,4 +197,38 @@ void DPsim::runDpEmtVarFreqStudy() {
timeStep = 0.04;
VarFreqRXLineResLoadEMT(timeStep, finalTime, freqStep, loadStep, rampTime);
VarFreqRXLineResLoad(timeStep, finalTime, freqStep, loadStep, rampTime);
}
void DPsim::RXLineResLoadStatic() {
// Define Object for saving data on a file
Logger log(LogLevel::NONE), leftVectorLog(LogLevel::NONE), rightVectorLog(LogLevel::NONE);
// Declare circuit components
std::vector<BaseComponent*> circElements0;
circElements0.push_back(new VoltSourceRes("v_s", 1, 0, 10000, 0, 1));
circElements0.push_back(new LinearResistor("r_line", 1, 2, 1));
circElements0.push_back(new Inductor("l_line", 2, 3, 1));
circElements0.push_back(new LinearResistor("r_load", 3, 0, 1000));
// 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 << "RXLineResLoad_" << 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
......@@ -10,6 +10,7 @@ namespace DPsim {
void RXLineResLoadEMT();
void VarFreqRXLineResLoadEMT(Real timeStep, Real finalTime, Real freqStep, Real loadStep, Real rampTime);
void runDpEmtVarFreqStudy();
void RXLineResLoadStatic();
}
#endif
#include "Logger.h"
Logger::Logger() {
mLogLevel = LogLevel::INFO;
}
Logger::Logger(LogLevel level) {
mLogLevel = level;
}
Logger::~Logger() {
......@@ -22,17 +26,25 @@ std::ostringstream& Logger::Log() {
return mLogStream;
}
std::ostringstream& Logger::Log(Logtype type) {
switch (type) {
case Logtype::INFO:
std::ostringstream& Logger::Log(LogLevel level) {
if (level > mLogLevel) {
return mNullStream;
}
switch (level) {
case LogLevel::INFO:
mLogStream << "INFO: ";
break;
case Logtype::WARN:
case LogLevel::WARN:
mLogStream << "WARN: ";
break;
case Logtype::ERROR:
case LogLevel::ERROR:
mLogStream << "ERROR: ";
break;
case LogLevel::NONE:
mNullStream.str("");
return mNullStream;
break;
}
return mLogStream;
}
......
......@@ -6,21 +6,24 @@
#include "MathLibrary.h"
enum class Logtype { INFO, WARN, ERROR };
enum class LogLevel { NONE, ERROR, WARN, INFO };
class Logger {
private:
std::string mLogFileName;
std::ofstream mLogFile;
std::ostringstream mLogStream;
std::ostringstream mNullStream;
LogLevel mLogLevel;
public:
Logger();
Logger(LogLevel level);
~Logger();
int AddDataLine(double time, DPSMatrix data);
std::ostringstream& Log();
std::ostringstream& Log(Logtype type);
std::ostringstream& Log(LogLevel level);
void WriteLogToFile(std::string fileName);
static std::ostringstream VectorToDataLine(double time, DPSMatrix vector);
};
......
......@@ -22,13 +22,13 @@ Simulation::Simulation(std::vector<BaseComponent*> elements, Real om, Real dt, R
: Simulation(elements, om, dt, tf) {
for (std::vector<BaseComponent*>::iterator it = elements.begin(); it != elements.end(); ++it) {
logger.Log(Logtype::INFO) << "Added " << (*it)->getName() << " of type " << typeid(*(*it)).name() << " to simulation." << std::endl;
logger.Log(LogLevel::INFO) << "Added " << (*it)->getName() << " of type " << typeid(*(*it)).name() << " to simulation." << std::endl;
}
logger.Log(Logtype::INFO) << "System matrix A:" << std::endl;
logger.Log(LogLevel::INFO) << "System matrix A:" << std::endl;
logger.Log() << mSystemModel.getCurrentSystemMatrix() << std::endl;
logger.Log(Logtype::INFO) << "LU decomposition:" << std::endl;
logger.Log(LogLevel::INFO) << "LU decomposition:" << std::endl;
logger.Log() << mSystemModel.getLUdecomp() << std::endl;
logger.Log(Logtype::INFO) << "Known variables matrix j:" << std::endl;
logger.Log(LogLevel::INFO) << "Known variables matrix j:" << std::endl;
logger.Log() << mSystemModel.getRightSideVector() << std::endl;
}
......@@ -122,7 +122,7 @@ int Simulation::step(Logger& logger)
if (mTime >= mSwitchEventVector[mCurrentSwitchTimeIndex].switchTime) {
switchSystemMatrix(mSwitchEventVector[mCurrentSwitchTimeIndex].systemIndex);
mCurrentSwitchTimeIndex++;
logger.Log(Logtype::INFO) << "Switched to system " << mCurrentSwitchTimeIndex << " at " << mTime << std::endl;
logger.Log(LogLevel::INFO) << "Switched to system " << mCurrentSwitchTimeIndex << " at " << mTime << std::endl;
}
}
......@@ -176,7 +176,7 @@ int Simulation::stepGeneratorTest(Logger& logger, Logger& leftSideVectorLog, Log
switchSystemMatrix(mSwitchEventVector[mCurrentSwitchTimeIndex].systemIndex);
mCurrentSwitchTimeIndex++;
logger.Log(Logtype::INFO) << "Switched to system " << mCurrentSwitchTimeIndex << " at " << mTime << std::endl;
logger.Log(LogLevel::INFO) << "Switched to system " << mCurrentSwitchTimeIndex << " at " << mTime << std::endl;
}
}
......
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