DPsim
Loading...
Searching...
No Matches
CSVReader.h
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <fstream>
12#include <iostream>
13#include <iterator>
14#include <sstream>
15#include <string>
16#include <vector>
17
18#include <dpsim-models/DP/DP_Ph1_AvVoltageSourceInverterDQ.h>
19#include <dpsim-models/DP/DP_Ph1_PQLoadCS.h>
20#include <dpsim-models/Filesystem.h>
21#include <dpsim-models/Logger.h>
22#include <dpsim-models/SP/SP_Ph1_AvVoltageSourceInverterDQ.h>
23#include <dpsim-models/SP/SP_Ph1_Load.h>
24#include <dpsim-models/SystemTopology.h>
25
26namespace CPS {
28class CSVReader {
29private:
31 Logger::Log mSLog;
33 String mPath;
35 std::list<fs::path> mFileList;
37 std::map<String, String> mAssignPattern;
39 Bool mSkipFirstRow = true;
40
41public:
44 enum class Mode { AUTO, MANUAL };
45
46 /* Time Stamp Format.
47 *
48 * HHMMSS: Hours : Minutes : Seconds, it be casted to the corresponding SECONDS.
49 * SECONDS: profiles recorded with total seconds.
50 * PVGEN: format comply with https://www.fein-aachen.org/projects/PVgenerator/
51 */
52 enum class DataFormat { HHMMSS, SECONDS, HOURS, MINUTES };
53
55 CSVReader(String name, std::list<fs::path> path, Logger::Level logLevel);
57 CSVReader(String name, String path, Logger::Level logLevel);
59 CSVReader(String name, std::list<fs::path> path,
60 std::map<String, String> &assignList, Logger::Level logLevel);
62 CSVReader(String name, String path, std::map<String, String> &assignList,
63 Logger::Level logLevel);
64
67 Real time_format_convert(const String &time);
69 void doSkipFirstRow(Bool value = true) { mSkipFirstRow = value; }
71 MatrixRow csv2Eigen(const String &path);
72
73 std::vector<PQData> readLoadProfileDP(
74 fs::path file, Real start_time = -1, Real time_step = 1,
75 Real end_time = -1, Real scale_factor = 1,
76 CSVReader::DataFormat format = CSVReader::DataFormat::SECONDS);
77
78 void assignLoadProfileDP(
79 std::vector<std::shared_ptr<CPS::DP::Ph1::AvVoltageSourceInverterDQ>>
80 &loads,
81 Real start_time = -1, Real time_step = 1, Real end_time = -1,
82 Real scale_factor = 1, CSVReader::Mode mode = CSVReader::Mode::AUTO,
83 CSVReader::DataFormat format = CSVReader::DataFormat::SECONDS);
84
88 fs::path file, Real start_time = -1, Real time_step = 1,
89 Real end_time = -1,
90 CSVReader::DataFormat format = CSVReader::DataFormat::SECONDS);
92 std::vector<Real>
93 readPQData(fs::path file, Real start_time = -1, Real time_step = 1,
94 Real end_time = -1,
95 CSVReader::DataFormat format = CSVReader::DataFormat::SECONDS);
98 SystemTopology &sys, Real start_time = -1, Real time_step = 1,
99 Real end_time = -1, CSVReader::Mode mode = CSVReader::Mode::AUTO,
100 CSVReader::DataFormat format = CSVReader::DataFormat::SECONDS);
102 void assignPVGeneration(SystemTopology &sys, Real start_time = -1,
103 Real time_step = 1, Real end_time = -1,
104 CSVReader::Mode mode = CSVReader::Mode::AUTO);
105
107 PQData interpol_linear(std::map<Real, PQData> &data_PQ, Real x);
108
110 Real interpol_linear(std::map<Real, Real> &data_wf, Real x);
111};
112
113// #### csv reader section
114class CSVRow {
115public:
117 String const &get(std::size_t index) const { return m_data[index]; }
119 Int size() const;
121 void readNextRow(std::istream &str);
122
123private:
125 std::vector<String> m_data;
126};
127
128class CSVReaderIterator {
129public:
130 CSVReaderIterator(std::istream &str);
131 CSVReaderIterator();
132
133 CSVReaderIterator &next();
134 CSVReaderIterator next(Int);
135 CSVReaderIterator &step(Int time_step);
136 CSVRow const &operator*() const { return m_row; };
137 Bool operator==(CSVReaderIterator const &rhs) {
138 return ((this == &rhs) || ((this->m_str == NULL) && (rhs.m_str == NULL)));
139 }
140 Bool operator!=(CSVReaderIterator const &rhs) { return !((*this) == rhs); }
141
142private:
143 std::istream *m_str;
144 CSVRow m_row;
145};
146} // namespace CPS
PowerProfile readLoadProfile(fs::path file, Real start_time=-1, Real time_step=1, Real end_time=-1, CSVReader::DataFormat format=CSVReader::DataFormat::SECONDS)
PQData interpol_linear(std::map< Real, PQData > &data_PQ, Real x)
interpolation for PQ data points
void doSkipFirstRow(Bool value=true)
Skip first row if it has no digits at beginning.
Definition CSVReader.h:69
void assignLoadProfile(SystemTopology &sys, Real start_time=-1, Real time_step=1, Real end_time=-1, CSVReader::Mode mode=CSVReader::Mode::AUTO, CSVReader::DataFormat format=CSVReader::DataFormat::SECONDS)
assign load profile to corresponding load object
Real interpol_linear(std::map< Real, Real > &data_wf, Real x)
interpolation for weighting factor data points
Real time_format_convert(const String &time)