VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
LogFileWriterImp.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
32//=======================================================================================
33#include "LogFileWriterImp.h"
34
41
42#include <helper_functions.h>
43#include <iomanip>
44#include <ctime>
45#include <filesystem>
46
47LogFileWriterImp::LogFileWriterImp(std::shared_ptr<LogFileHead> logFileHead, std::shared_ptr<BasicSimulationInfo> basicSimInfo, std::shared_ptr<BasicTestLogFileInformation> basicTestInfo, std::vector<std::shared_ptr<TestLogFileInformation> > testLogFiles, std::shared_ptr<LogFileTimeInformation> logFileTimeInfo, std::shared_ptr<SimulationLogFileInformation> simLogInfo, std::string kernel, double viscosity) : viscosity(viscosity)
48{
49 kernelName = kernel;
50
51 logFileInfo.push_back(logFileHead);
52 logFileInfo.push_back(basicSimInfo);
53 this->simLogInfo = simLogInfo;
54 logFileInfo.push_back(simLogInfo);
55 logFileInfo.push_back(logFileTimeInfo);
56 logFileInfo.push_back(basicTestInfo);
57 for (int i = 0; i < testLogFiles.size(); i++)
58 logFileInfo.push_back(testLogFiles.at(i));
59}
60
61std::shared_ptr<LogFileWriterImp> LogFileWriterImp::getNewInstance(std::shared_ptr<LogFileHead> logFileHead, std::shared_ptr<BasicSimulationInfo> basicSimInfo, std::shared_ptr<BasicTestLogFileInformation> basicTestInfo, std::vector<std::shared_ptr<TestLogFileInformation> > testLogFiles, std::shared_ptr<LogFileTimeInformation> logFileTimeInfo, std::shared_ptr<SimulationLogFileInformation> simLogInfo, std::string kernel, double viscosity)
62{
63 return std::shared_ptr<LogFileWriterImp>(new LogFileWriterImp(logFileHead, basicSimInfo, basicTestInfo, testLogFiles, logFileTimeInfo, simLogInfo, kernel, viscosity));
64}
65
67{
68 logFilePath = buildFilePath(basicFilePath);
69 logFile.open(logFilePath, std::ios::out);
70
71 for (int i = 0; i < logFileInfo.size(); i++)
72 logFile << logFileInfo.at(i)->getOutput();
73
74 logFile.close();
75}
76
77
78std::string LogFileWriterImp::calcDateAndTime()
79{
80 std::ostringstream oss;
81 now = time(NULL);
82 nowLocal = *localtime(&now);
83 oss << std::setfill('0') << nowLocal.tm_year + 1900 << std::setw(2) << nowLocal.tm_mon + 1 << std::setw(2) << nowLocal.tm_mday << "_" << std::setw(2) << nowLocal.tm_hour << std::setw(2) << nowLocal.tm_min << std::setw(2) << nowLocal.tm_sec;
84 return oss.str();
85}
86
87std::string LogFileWriterImp::buildFilePath(std::string basicFilePath)
88{
89 std::ostringstream filePath;
90 filePath << basicFilePath << simLogInfo->getFilePathExtension().at(0) << "/viscosity_" << viscosity << "/" << simLogInfo->getFilePathExtension().at(1) << "/" << kernelName;
91
92 std::filesystem::path dir(filePath.str());
93 if (!(std::filesystem::exists(dir)))
94 std::filesystem::create_directories(dir);
95
96 filePath << "/logfile_" << calcDateAndTime() << "_" << kernelName << "_vis_" << viscosity << ".txt";
97 return filePath.str();
98}
99
void writeLogFile(std::string basicFilePath)
static std::shared_ptr< LogFileWriterImp > getNewInstance(std::shared_ptr< LogFileHead > logFileHead, std::shared_ptr< BasicSimulationInfo > basicSimInfo, std::shared_ptr< BasicTestLogFileInformation > basicTestInfo, std::vector< std::shared_ptr< TestLogFileInformation > > testLogFiles, std::shared_ptr< LogFileTimeInformation > logFileTimeInfo, std::shared_ptr< SimulationLogFileInformation > simLogInfo, std::string kernel, double viscosity)
std::shared_ptr< T > SPtr