DPsim
Loading...
Searching...
No Matches
DataLogger.h
1/* Copyright 2017-2024 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 <map>
14
15#include <dpsim-models/Attribute.h>
16#include <dpsim-models/Filesystem.h>
17#include <dpsim-models/PtrFactory.h>
18#include <dpsim-models/SimNode.h>
19#include <dpsim-models/Task.h>
20#include <dpsim/DataLoggerInterface.h>
21#include <dpsim/Definitions.h>
22#include <dpsim/Scheduler.h>
23
24namespace DPsim {
25
26class DataLogger : public DataLoggerInterface,
27 public SharedFactory<DataLogger> {
28
29protected:
30 std::ofstream mLogFile;
31 String mName;
32 Bool mEnabled;
33 UInt mDownsampling;
34 fs::path mFilename;
35
36 virtual void logDataLine(Real time, Real data);
37 virtual void logDataLine(Real time, const Matrix &data);
38 virtual void logDataLine(Real time, const MatrixComp &data);
39
40public:
41 typedef std::shared_ptr<DataLogger> Ptr;
42
43 DataLogger(Bool enabled = true);
44 DataLogger(String name, Bool enabled = true, UInt downsampling = 1);
45 virtual ~DataLogger(){};
46
47 virtual void start() override;
48 virtual void stop() override;
49
50 virtual void setColumnNames(std::vector<String> names);
51 void logPhasorNodeValues(Real time, const Matrix &data, Int freqNum = 1);
52 void logEMTNodeValues(Real time, const Matrix &data);
53
54 virtual void log(Real time, Int timeStepCount) override;
55
56 virtual CPS::Task::Ptr getTask() override;
57
58 class Step : public CPS::Task {
59 public:
60 Step(DataLogger &logger) : Task(logger.mName + ".Write"), mLogger(logger) {
61 for (auto attr : logger.mAttributes) {
62 mAttributeDependencies.push_back(attr.second);
63 }
64 mModifiedAttributes.push_back(Scheduler::external);
65 }
66
67 void execute(Real time, Int timeStepCount);
68
69 private:
70 DataLogger &mLogger;
71 };
72};
73} // namespace DPsim
Tasks to be defined by every component.
Definition Task.h:25