OMSimulatorLib The OMSimulator project is a FMI-based co-simulation environment.

Loading...
Searching...
No Matches
ResultWriter.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36#ifndef _OMS_RESULTWRITER_H_
37#define _OMS_RESULTWRITER_H_
38
39#include "ComRef.h"
40#include <string>
41#include <vector>
42
43 namespace oms
44{
45 enum SignalType_t
46 {
47 SignalType_REAL,
48 SignalType_INT,
49 SignalType_BOOL
50 };
51
52 union SignalValue_t
53 {
54 double realValue;
55 int intValue;
56 bool boolValue;
57 };
58
59 struct Signal
60 {
61 ComRef name;
62 std::string description;
63 SignalType_t type;
64 };
65
66 struct Parameter
67 {
68 Signal signal;
69 SignalValue_t value;
70 };
71
72 class ResultWriter
73 {
74 public:
75 ResultWriter(unsigned int bufferSize);
76 virtual ~ResultWriter();
77
78 unsigned int addSignal(const ComRef& name, const std::string& description, SignalType_t type, bool exportNameUsed = false);
79 void addParameter(const ComRef& name, const std::string& description, SignalType_t type, SignalValue_t value, bool exportNameUsed = false);
80
81 bool create(const std::string& filename, double startTime, double stopTime);
82 void close();
83
84 void updateSignal(unsigned int id, SignalValue_t value);
85 void emit(double time);
86
87 private:
88 // Stop the compiler generating methods for copying the object
89 ResultWriter(ResultWriter const& copy); // Not Implemented
90 ResultWriter& operator=(ResultWriter const& copy); // Not Implemented
91
92 protected:
93 virtual bool createFile(const std::string& filename, double startTime, double stopTime) = 0;
94 virtual void closeFile() = 0;
95 virtual void writeFile() = 0;
96
97 std::vector<Signal> signals;
98 std::vector<Parameter> parameters;
99
100 double* data_2;
101 unsigned int bufferSize;
102 unsigned int nEmits;
103 };
104
105 class VoidWriter :
106 public ResultWriter
107 {
108 public:
109 VoidWriter(unsigned int bufferSize) :ResultWriter(bufferSize) {}
110 ~VoidWriter() {}
111
112 protected:
113 bool createFile(const std::string& filename, double startTime, double stopTime) {return true;}
114 void closeFile() {}
115 void writeFile() {}
116 };
117}
118
119#endif
ComRef.h
oms::ComRef
ComRef - component reference.
Definition ComRef.h:51
oms::ResultWriter
Definition ResultWriter.h:73
oms::ResultWriter::addSignal
unsigned int addSignal(const ComRef &name, const std::string &description, SignalType_t type, bool exportNameUsed=false)
Definition ResultWriter.cpp:54
oms::ResultWriter::writeFile
virtual void writeFile()=0
oms::ResultWriter::emit
void emit(double time)
Definition ResultWriter.cpp:161
oms::ResultWriter::closeFile
virtual void closeFile()=0
oms::ResultWriter::updateSignal
void updateSignal(unsigned int id, SignalValue_t value)
Definition ResultWriter.cpp:142
oms::ResultWriter::data_2
double * data_2
Definition ResultWriter.h:100
oms::ResultWriter::~ResultWriter
virtual ~ResultWriter()
Definition ResultWriter.cpp:48
oms::ResultWriter::parameters
std::vector< Parameter > parameters
Definition ResultWriter.h:98
oms::ResultWriter::ResultWriter
ResultWriter(ResultWriter const &copy)
oms::ResultWriter::close
void close()
Definition ResultWriter.cpp:128
oms::ResultWriter::operator=
ResultWriter & operator=(ResultWriter const &copy)
oms::ResultWriter::create
bool create(const std::string &filename, double startTime, double stopTime)
Definition ResultWriter.cpp:118
oms::ResultWriter::nEmits
unsigned int nEmits
Definition ResultWriter.h:102
oms::ResultWriter::createFile
virtual bool createFile(const std::string &filename, double startTime, double stopTime)=0
oms::ResultWriter::signals
std::vector< Signal > signals
Definition ResultWriter.h:97
oms::ResultWriter::bufferSize
unsigned int bufferSize
Definition ResultWriter.h:101
oms::ResultWriter::addParameter
void addParameter(const ComRef &name, const std::string &description, SignalType_t type, SignalValue_t value, bool exportNameUsed=false)
Definition ResultWriter.cpp:88
oms::VoidWriter
Definition ResultWriter.h:107
oms::VoidWriter::createFile
bool createFile(const std::string &filename, double startTime, double stopTime)
Definition ResultWriter.h:113
oms::VoidWriter::VoidWriter
VoidWriter(unsigned int bufferSize)
Definition ResultWriter.h:109
oms::VoidWriter::writeFile
void writeFile()
Definition ResultWriter.h:115
oms::VoidWriter::~VoidWriter
~VoidWriter()
Definition ResultWriter.h:110
oms::VoidWriter::closeFile
void closeFile()
Definition ResultWriter.h:114
oms
Definition AlgLoop.h:52
oms::SignalType_t
SignalType_t
Definition ResultWriter.h:46
oms::SignalType_REAL
@ SignalType_REAL
Definition ResultWriter.h:47
oms::SignalType_BOOL
@ SignalType_BOOL
Definition ResultWriter.h:49
oms::SignalType_INT
@ SignalType_INT
Definition ResultWriter.h:48
oms::Parameter
Definition ResultWriter.h:67
oms::Parameter::signal
Signal signal
Definition ResultWriter.h:68
oms::Parameter::value
SignalValue_t value
Definition ResultWriter.h:69
oms::Signal
Definition ResultWriter.h:60
oms::Signal::description
std::string description
Definition ResultWriter.h:62
oms::Signal::name
ComRef name
Definition ResultWriter.h:61
oms::Signal::type
SignalType_t type
Definition ResultWriter.h:63
oms::SignalValue_t
Definition ResultWriter.h:53
oms::SignalValue_t::boolValue
bool boolValue
Definition ResultWriter.h:56
oms::SignalValue_t::realValue
double realValue
Definition ResultWriter.h:54
oms::SignalValue_t::intValue
int intValue
Definition ResultWriter.h:55