-
Notifications
You must be signed in to change notification settings - Fork 49
/
Model.h
189 lines (154 loc) · 7.11 KB
/
Model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
#ifndef _OMS_MODEL_H_
#define _OMS_MODEL_H_
#include "Clock.h"
#include "ComRef.h"
#include "Element.h"
#include "ResultWriter.h"
#include "Types.h"
#include "Snapshot.h"
#include "Values.h"
#include <assert.h>
#include <pugixml.hpp>
#if (BOOST_VERSION >= 105300)
#include <ctpl.h>
#else // use the standard queue
#include <ctpl_stl.h>
#endif
namespace oms
{
class Component;
class System;
class Model
{
public: // methods
~Model();
/**
* NewModel() is used instead of a constructor to make sure that only
* instances with valid names can be created.
*/
static Model* NewModel(const ComRef& cref);
const ComRef& getCref() const {return cref;}
System* getSystem(const ComRef& cref);
oms_status_enu_t delete_(const ComRef& cref);
Component* getComponent(const ComRef& cref);
System* getTopLevelSystem() const {return system;}
std::string getTempDirectory() const {return tempDir;}
oms_status_enu_t rename(const ComRef& cref);
oms_status_enu_t rename(const ComRef& cref, const ComRef& newCref);
oms_status_enu_t list(const ComRef& cref, char** contents);
oms_status_enu_t addSystem(const ComRef& cref, oms_system_enu_t type);
oms_status_enu_t newResources(const ComRef& cref);
oms_status_enu_t addResources(const ComRef& cref, const std::string& path);
oms_status_enu_t deleteReferencesInSSD(const ComRef& cref);
oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
oms_status_enu_t duplicateVariant(const ComRef& crefA, const ComRef& crefB);
oms_status_enu_t referenceResources(const ComRef& cref, const std::string& ssmFile);
oms_status_enu_t reduceSSV(const std::string& ssvfile, const std::string& ssmfile, const std::string& filepath);
oms_status_enu_t exportToSSD(Snapshot& snapshot) const;
oms_status_enu_t exportSnapshot(const ComRef& cref, char** contents);
oms_status_enu_t exportSSVTemplate(const ComRef& cref, const std::string& filename);
oms_status_enu_t exportSSMTemplate(const ComRef& cref, const std::string& filename);
void exportSignalFilter(Snapshot& snapshot) const;
void exportUnitDefinitionsToSSD(pugi::xml_node& node) const;
oms_status_enu_t importFromSnapshot(const Snapshot& snapshot);
oms_status_enu_t importSnapshot(const char* snapshot, char** newCref);
oms_status_enu_t importSignalFilter(const std::string& filename, const Snapshot& snapshot);
oms_status_enu_t exportToFile(const std::string& filename) const;
oms_system_enu_t getSystemType(const pugi::xml_node& node, const std::string& sspVersion);
oms_system_enu_t getSystemTypeHelper(const pugi::xml_node& node, const std::string& sspVersion);
oms_status_enu_t updateParameterBindingsToSSD(pugi::xml_node& node, bool isTopSystemOrModel) const;
void copyResources(bool copy_resources) {this->copy_resources = copy_resources;}
bool copyResources() {return copy_resources;}
oms::Element** getElements() {return &elements[0];}
void writeAllResourcesToFilesystem(std::vector<std::string>& resources, Snapshot& snapshot) const;
oms_status_enu_t instantiate();
oms_status_enu_t initialize();
oms_status_enu_t simulate();
oms_status_enu_t doStep();
oms_status_enu_t stepUntil(double stopTime);
oms_status_enu_t terminate();
oms_status_enu_t reset();
oms_modelState_enu_t getModelState() const {return modelState;}
oms_status_enu_t setStartTime(double value);
double getStartTime() const {return startTime;}
oms_status_enu_t setStopTime(double value);
double getStopTime() const {return stopTime;}
double getTime() const;
oms_status_enu_t setLoggingInterval(double loggingInterval);
double getLoggingInterval() const {return loggingInterval;}
oms_status_enu_t setResultFile(const std::string& filename, int bufferSize);
oms_status_enu_t getResultFile(char** filename, int* bufferSize);
oms_status_enu_t emit(double time, bool force=false, bool* emitted=NULL);
oms_status_enu_t addSignalsToResults(const char* regex);
oms_status_enu_t removeSignalsFromResults(const char* regex);
bool validState(int validStates) const {return (modelState & validStates);}
bool isIsolatedFMUModel() const {return isolatedFMU;}
void setIsolatedFMUModel() {isolatedFMU = true;}
bool useThreadPool() {return (pool != nullptr);}
ctpl::thread_pool& getThreadPool() {assert(pool); return *pool;}
oms_status_enu_t loadSnapshot(const pugi::xml_node& node);
std::vector<std::string> importedResources; ///< list of imported resources from ssp
std::vector<char*> listVariants; ///< list of all variants copied when user create a new variant using oms_duplicateVariant()
std::string getVariantName() {return variantName;}
private: // methods
Model(const ComRef& cref, const std::string& tempDir);
// stop the compiler generating methods copying the object
Model(Model const& copy); ///< not implemented
Model& operator=(Model const& copy); ///< not implemented
oms_status_enu_t registerSignalsForResultFile();
private: // attributes
ComRef cref;
System* system = NULL;
std::string tempDir;
std::vector<oms::Element*> elements;
bool copy_resources = true;
oms_modelState_enu_t modelState = oms_modelState_virgin;
// ssd:DefaultExperiment
double startTime = 0.0;
double stopTime = 1.0;
ResultWriter* resultFile = NULL;
double lastEmit;
double loggingInterval = 0.0;
int bufferSize = 10;
Clock clock;
Values values;
std::string resultFilename; ///< default <name>_res.mat
std::string signalFilterFilename = "resources/signalFilter.xml";
std::string variantName = "SystemStructure.ssd"; ///< default name
std::vector<std::string> externalResources; ///< list of external ssv or ssm resources from filesystem
bool isolatedFMU = false;
ctpl::thread_pool* pool = nullptr;
ComRef new_root_cref;
};
}
#endif