SLIDE  3.0.0
A simulator for lithium-ion battery pack degradation
Loading...
Searching...
No Matches
timing.hpp
Go to the documentation of this file.
1/*
2 * timing.hpp
3 *
4 * Some utility functions for timing.
5
6 * Created on: 16 Oct 2022
7 * Author(s): Jorn Reniers, Volkan Kumtepeli
8 */
9
10
11#pragma once
12
13#include <ctime>
14#include <iostream>
15#include <cmath>
16#include <chrono>
17
18
19namespace slide {
20struct Clock
21{
22 std::chrono::time_point<std::chrono::steady_clock> tstart{ std::chrono::steady_clock::now() };
23 Clock() = default;
24 auto now() const { return std::chrono::steady_clock::now(); }
25 auto start() const { return tstart; }
26 double duration() const
27 {
28 std::chrono::duration<double> elapsed_seconds = now() - start();
29 return elapsed_seconds.count();
30 }
31};
32
33inline std::ostream &operator<<(std::ostream &ofs, const Clock &clk)
34{
35 const auto duration = clk.duration();
36 ofs << std::floor(duration / 60) << ":"
37 << duration - std::floor(duration / 60) * 60
38 << " min:sec";
39
40 return ofs;
41}
42} // namespace slide
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
std::ostream & operator<<(std::ostream &os, const DynamicMatrix< Tdata > &M)
Definition: DynamicMatrix.hpp:72
Definition: timing.hpp:21
auto start() const
Definition: timing.hpp:25
double duration() const
Definition: timing.hpp:26
auto now() const
Definition: timing.hpp:24
std::chrono::time_point< std::chrono::steady_clock > tstart
Definition: timing.hpp:22
Clock()=default