add a timer to the propagator to record propagation time in runUntilTerminate()

This commit is contained in:
Travis Hunter 2023-04-10 20:02:55 -06:00
parent 0734d6a013
commit 48d1a933ab
3 changed files with 16 additions and 21 deletions

View File

@ -3,10 +3,12 @@
#include "sim/RK4Solver.h"
#include "model/Rocket.h"
#include "utils/Logger.h"
#include "QtRocket.h"
#include <utility>
#include <QTextStream>
#include <chrono>
#include <sstream>
namespace sim {
@ -45,8 +47,9 @@ Propagator::~Propagator()
void Propagator::runUntilTerminate()
{
std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point endTime;
QTextStream out(stdout);
std::size_t j = 0;
while(true && j < 100000)
{
@ -66,19 +69,19 @@ void Propagator::runUntilTerminate()
{
states.push_back(currentState);
}
out << currentTime << ": ("
<< currentState[0] << ", "
<< currentState[1] << ", "
<< currentState[2] << ", "
<< currentState[3] << ", "
<< currentState[4] << ", "
<< currentState[5] << ")\n";
if(currentState[2] < 0.0)
break;
j++;
currentTime += timeStep;
}
endTime = std::chrono::steady_clock::now();
std::stringstream duration;
duration << "runUntilTerminate time (microseconds): ";
duration << std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime).count();
utils::Logger::getInstance()->debug(duration.str());
}
double Propagator::getMass()

View File

@ -18,12 +18,6 @@ Logger* Logger::getInstance()
Logger::Logger()
{
outFile.open("log.txt");
/*
error = [this](std::string_view msg) { log(msg, ERROR); };
warn = [this](std::string_view msg) { log(msg, WARN); };
info = [this](std::string_view msg) { log(msg, INFO); };
debug = [this](std::string_view msg) { log(msg, DEBUG); };
*/
}
Logger::~Logger()
@ -42,21 +36,21 @@ void Logger::log(std::string_view msg, const LogLevel& lvl)
if(lvl == DEBUG)
{
outFile << "[DEBUG] " << msg << std::endl;
std::cout << "[DEBUG] " << msg << std::endl;
std::cout << "[DEBUG] " << msg << "\n";
}
[[fallthrough]];
case INFO:
if(lvl == INFO)
{
outFile << "[INFO] " << msg << std::endl;
std::cout << "[INFO] " << msg << std::endl;
std::cout << "[INFO] " << msg << "\n";
}
[[fallthrough]];
case WARN:
if(lvl == WARN)
{
outFile << "[WARN] " << msg << std::endl;
std::cout << "[WARN] " << msg << std::endl;
std::cout << "[WARN] " << msg << "\n";
}
[[fallthrough]];
// Regardless of what level is set, ERROR is always logged, so
@ -65,8 +59,7 @@ void Logger::log(std::string_view msg, const LogLevel& lvl)
if(lvl == ERROR)
{
outFile << "[ERROR] " << msg << std::endl;
std::cout << "[ERROR] " << msg << std::endl;
std::cerr << "[ERROR] " << msg << std::endl;
std::cout << "[ERROR] " << msg << "\n";
}
}
}

View File

@ -4,7 +4,6 @@
#include <fstream>
#include <mutex>
#include <string_view>
//#include <functional>
/**
* @todo write docs