OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
timeleft.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 VTT Technical Research Centre of Finland Ltd
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
31#ifndef PFC_UTILS_TIMELEFT_HPP
32#define PFC_UTILS_TIMELEFT_HPP
33
34#include <iostream>
35
36namespace pfc {
37namespace utils {
38
39class TimeLeft {
40private:
41 int m_seconds = 0, m_minutes = 0, m_hours = 0, m_days = 0;
42
43public:
44 explicit TimeLeft(double t) : m_seconds(t) {
45 if (m_seconds > 60) {
46 m_minutes = m_seconds / 60;
47 m_seconds -= m_minutes * 60;
48 }
49 if (m_minutes > 60) {
50 m_hours = m_minutes / 60;
51 m_minutes -= m_hours * 60;
52 }
53 if (m_hours > 24) {
54 m_days = m_hours / 24;
55 m_hours -= m_days * 24;
56 }
57 }
58
59 friend std::ostream &operator<<(std::ostream &os, const TimeLeft &e) {
60 if (e.m_days > 0) {
61 os << e.m_days << "d ";
62 }
63 if (e.m_hours > 0) {
64 os << e.m_hours << "h ";
65 }
66 if (e.m_minutes > 0) {
67 os << e.m_minutes << "m ";
68 }
69 os << e.m_seconds << "s";
70 return os;
71 }
72};
73} // namespace utils
74} // namespace pfc
75
76#endif // PFC_UTILS_TIMELEFT_HPP
Definition timeleft.hpp:39
Represents the global simulation domain (the "world").
Definition world.hpp:91