VM2D 1.14
Vortex methods for 2D flows simulation
Loading...
Searching...
No Matches
TimesGen.cpp
Go to the documentation of this file.
1/*--------------------------------*- VM2D -*-----------------*---------------*\
2| ## ## ## ## #### ##### | | Version 1.14 |
3| ## ## ### ### ## ## ## ## | VM2D: Vortex Method | 2026/03/06 |
4| ## ## ## # ## ## ## ## | for 2D Flow Simulation *----------------*
5| #### ## ## ## ## ## | Open Source Code |
6| ## ## ## ###### ##### | https://www.github.com/vortexmethods/VM2D |
7| |
8| Copyright (C) 2017-2026 I. Marchevsky, K. Sokol, E. Ryatina, A. Kolganova |
9*-----------------------------------------------------------------------------*
10| File name: TimesGen.cpp |
11| Info: Source code of VM2D |
12| |
13| This file is part of VM2D. |
14| VM2D is free software: you can redistribute it and/or modify it |
15| under the terms of the GNU General Public License as published by |
16| the Free Software Foundation, either version 3 of the License, or |
17| (at your option) any later version. |
18| |
19| VM2D is distributed in the hope that it will be useful, but WITHOUT |
20| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21| FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
22| for more details. |
23| |
24| You should have received a copy of the GNU General Public License |
25| along with VM2D. If not, see <http://www.gnu.org/licenses/>. |
26\*---------------------------------------------------------------------------*/
27
39#include "TimesGen.h"
40
41#include "PassportGen.h"
42
43#include "WorldGen.h"
44
45using namespace VMlib;
46
47TimersGen::TimersGen(const WorldGen& W_, std::vector<std::string> labels)
48 : W(W_)
49{
50 timerLabelList = labels;
51 for (const auto& s : labels)
52 timer.insert({ s, std::make_unique<vmTimer>(s) });
53}//TimersGen(...)
54
55void TimersGen::start(const std::string& timerLabel)
56{
57 try
58 {
59 timer.at(timerLabel)->start();
60 }
61 catch (...)
62 {
63 std::cout << "No timer \"" << timerLabel << "\" pre-determined!" << std::endl;
64 exit(-16);
65 }
66}//start(...)
67
68void TimersGen::stop(const std::string& timerLabel)
69{
70 try
71 {
72 timer.at(timerLabel)->stop();
73 }
74 catch (...)
75 {
76 std::cout << "No timer \"" << timerLabel << "\" pre-determined!" << std::endl;
77 exit(-16);
78 }
79}//stop(...)
80
82{
83 for (auto& tmr_ : timer)
84 tmr_.second->reset();
85}//resetAll(...)
86
88{
89 std::stringstream ss;
90 ss << std::setw(6) << "Step" << "" \
91 << std::setw(9) << "Time" << "" \
92 << std::setw(9) << "N" << "";
93
94 for (const auto& k : timerLabelList)
95 ss << std::setw(9) << k << "";
96
97 ss << std::setw(9) << "Other" << "";
98
99 std::stringstream timeStatFileName;
100 timeStatFileName << W.getPassportGen().dir << "timestat";
101
102 std::ofstream timeStatFile(timeStatFileName.str());
103 VMlib::PrintLogoToTextFile(timeStatFile, timeStatFileName.str(), "Time statistics (in milliseconds)");
104
105 VMlib::PrintHeaderToTextFile(timeStatFile, ss.str());
106
107 timeStatFile.close();
108 timeStatFile.clear();
109}//GenerateStatHeader()
110
111void TimersGen::GenerateStatString(size_t stepNo, double curTime, size_t N)
112{
113 std::ofstream timestatFile(W.getPassportGen().dir + "timestat", std::ios::app);
114
115 std::stringstream ss;
116 ss << std::setw(9) << stepNo << "" \
117 << std::setw(9) << curTime << "" \
118 //<< std::setw(9) << N << "";
119 << std::setw(9) << W.nVtxBeforeMerging << "";
120 double tOther = 0.0;
121
122 ss.precision(2);
123 ss << std::fixed;
124
125 for (const auto& k : timerLabelList)
126 {
127 double duration = timer[k]->duration<vmTimer::ms>();
128 ss << std::setw(9) << duration << "";
129 tOther += (k == "Step" ? duration : -duration);
130 }
131 ss << std::setw(9) << tOther;
132
133 timestatFile << std::endl << ss.str();
134}//GenerateStatString()
Заголовочный файл с описанием класса PasportGen.
Заголовочный файл с описанием класса TimesGen.
Заголовочный файл с описанием класса WorldGen.
std::string dir
Рабочий каталог задачи
std::vector< std::string > timerLabelList
Список имен счетчиков
Definition TimesGen.h:164
void GenerateStatString(size_t stepNo, double curTime, size_t N)
Формирование очередной строки файла временной статистики
Definition TimesGen.cpp:111
void GenerateStatHeader()
Формирование заголовка файла временной статистики
Definition TimesGen.cpp:87
void stop(const std::string &timerLabel)
Останов счетчика
Definition TimesGen.cpp:68
void start(const std::string &timerLabel)
Запуск счетчика
Definition TimesGen.cpp:55
void resetAll()
Сброс всех счетчиков
Definition TimesGen.cpp:81
const WorldGen & W
Константная ссылка на решаемую задачу
Definition TimesGen.h:160
TimersGen(const WorldGen &W_, std::vector< std::string > labels)
Конструктор
Definition TimesGen.cpp:47
std::map< std::string, std::unique_ptr< vmTimer > > timer
Ассоциативный массив { имя, счетчик }.
Definition TimesGen.h:167
Класс, опеделяющий текущую решаемую задачу
Definition WorldGen.h:57
const PassportGen & getPassportGen() const
Definition WorldGen.h:102
size_t nVtxBeforeMerging
Definition WorldGen.h:76
std::chrono::duration< float, std::chrono::milliseconds::period > ms
Основная единица измерения времени — миллисекунды
Definition TimesGen.h:88
void PrintHeaderToTextFile(std::ofstream &str, const std::string &header)
Формирование подзаголовка в текстовом файле вывода программы VM2D/VM3D.
Definition defs.cpp:175
void PrintLogoToTextFile(std::ofstream &str, const std::string &fileName, const std::string &descr)
Формирование заголовка файла программы VM2D/VM3D.
Definition defs.cpp:139