SLIDE  3.0.0
A simulator for lithium-ion battery pack degradation
Loading...
Searching...
No Matches
CellDataWriter.hpp
Go to the documentation of this file.
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
23namespace slide {
24
25inline void writeData(std::ofstream &file, std::span<Histogram<>> histograms)
26{
27 for (auto &hist : histograms)
28 file << hist << "\n\n";
29}
30
31
32inline void writeVarAndStates(std::ofstream &file, auto &cell)
33{
34 file << "States:,"; // #TODO we need names for states.
35 for (const auto st_i : cell.viewStates()) // Time and Throughput data is written here if available.
36 file << st_i << ',';
37 file << "\n\n\n";
38}
39
40template <settings::cellDataStorageLevel N>
41void writeDataImpl(std::ofstream &file, auto &cell, auto &dataStorage)
42{
44 writeVarAndStates(file, cell);
45
47 free::write_data(file, dataStorage.data, 7);
49}
50
51template <settings::cellDataStorageLevel N>
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 inline static void writeData(auto &cell, const std::string &prefix, auto &storage)
66 {
67 constexpr auto suffix = "cellData.csv";
68 auto file = free::openFile(cell, PathVar::results, prefix, suffix);
69 writeDataImpl<N>(file, cell, storage);
70 file.close();
71 }
72};
73
74} // namespace slide
Definition: Histogram.hpp:31
void write_data(std::ofstream &file, std::vector< double > &data, size_t N=1)
Definition: free_functions.hpp:49
std::ofstream openFile(auto &SU, const auto &folder, const std::string &prefix, const std::string &suffix)
Definition: free_functions.hpp:245
constexpr bool writeCumulativeData
Definition: derived_settings.hpp:20
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
void writeData(std::ofstream &file, std::span< Histogram<> > histograms)
Definition: CellDataWriter.hpp:25
void writeDataImpl(std::ofstream &file, auto &cell, auto &dataStorage)
Definition: CellDataWriter.hpp:41
void writeVarAndStates(std::ofstream &file, auto &cell)
Definition: CellDataWriter.hpp:32
Definition: CellDataWriter.hpp:53
static void writeData(auto &cell, const std::string &prefix, auto &storage)
Definition: CellDataWriter.hpp:65