Line data Source code
1 : /* 2 : * CellDataWriter.hpp 3 : * 4 : * Created on: 10 Apr 2022 5 : * Author(s): Jorn Reniers, Volkan Kumtepeli 6 : */ 7 : 8 : #pragma once 9 : 10 : #include "cell_data.hpp" 11 : #include "../../settings/enum_definitions.hpp" 12 : #include "../../utility/free_functions.hpp" 13 : 14 : #include <string> 15 : #include <vector> 16 : #include <fstream> 17 : #include <span> 18 : #include <cstdlib> 19 : #include <array> 20 : #include <span> 21 : #include <variant> 22 : 23 : namespace slide { 24 : 25 : inline void writeData(std::ofstream &file, std::span<Histogram<>> histograms) 26 : { 27 : for (auto &hist : histograms) 28 : file << hist << "\n\n"; 29 : } 30 : 31 : 32 10 : inline void writeVarAndStates(std::ofstream &file, auto &cell) 33 : { 34 10 : file << "States:,"; // #TODO we need names for states. 35 330 : for (const auto st_i : cell.viewStates()) // Time and Throughput data is written here if available. 36 320 : file << st_i << ','; 37 10 : file << "\n\n\n"; 38 10 : } 39 : 40 : template <settings::cellDataStorageLevel N> 41 10 : void writeDataImpl(std::ofstream &file, auto &cell, auto &dataStorage) 42 : { 43 : if constexpr (settings::data::writeCumulativeData) 44 10 : writeVarAndStates(file, cell); 45 : 46 : if constexpr (N >= settings::cellDataStorageLevel::storeHistogramData) 47 10 : free::write_data(file, dataStorage.data, 7); 48 : //!< else write nothing. 49 10 : } 50 : 51 : template <settings::cellDataStorageLevel N> 52 : struct CellDataWriter 53 : { 54 : /* 55 : * Writes cell data to a csv file. 56 : * The name of the csv file starts with the value of prefix, 57 : * after which the identification string of this cell is appended 58 : * 59 : * Depending on the value of DATASTORE_CELL, different things are written 60 : * 0 nothing 61 : * 1 general info about the cell and usage statistics in file xxx_cellStats.csv 62 : * 2 cycling data (I, V, T at every time step) in file xxx_cellData.csv 63 : */ 64 : 65 10 : inline static void writeData(auto &cell, const std::string &prefix, auto &storage) 66 : { 67 10 : constexpr auto suffix = "cellData.csv"; 68 20 : auto file = free::openFile(cell, PathVar::results, prefix, suffix); 69 10 : writeDataImpl<N>(file, cell, storage); 70 10 : file.close(); 71 10 : } 72 : }; 73 : 74 : } // namespace slide