forked from eclipse/openmcx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponent.h
279 lines (199 loc) · 10.5 KB
/
Component.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/********************************************************************************
* Copyright (c) 2020 AVL List GmbH and others
*
* This program and the accompanying materials are made available under the
* terms of the Apache Software License 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#ifndef MCX_CORE_COMPONENT_H
#define MCX_CORE_COMPONENT_H
#include "CentralParts.h"
#include "components/ComponentFactory.h"
#include "core/Component_interface.h"
#include "core/Dependency.h"
#include "objects/StringContainer.h"
#include "reader/model/components/ComponentInput.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef enum ComponentFinishState {
COMP_IS_FINISHED,
COMP_IS_NOT_FINISHED,
COMP_NEVER_FINISHES
} ComponentFinishState;
struct Config;
struct Model;
struct ComponentData;
struct ChannelInfo;
struct Connection;
struct ConnectionInfo;
struct StepTypeParams;
struct ResultsStorage;
struct ComponentStorage;
typedef McxStatus (* fComponentRead)(Component * comp, ComponentInput * input, const struct Config * const config);
typedef McxStatus (* fComponentSetup)(Component * comp);
typedef McxStatus (* fComponentRegisterStorage)(Component * comp, struct ResultsStorage * storage);
typedef McxStatus (* fComponentInitialize)(Component * comp, size_t idx, double startTime);
typedef McxStatus (* fComponentExitInitializationMode)(Component * comp);
typedef McxStatus (* fComponentUpdateInitialOutChannels)(Component * comp);
typedef McxStatus (* fComponentUpdateOutChannels)(Component * comp);
typedef McxStatus (* fComponentUpdateInChannels)(Component * comp);
typedef struct ComponentStorage * (* fComponentGetStorage)(const Component * comp);
typedef McxStatus (* fComponentDoStep)(Component * comp, size_t group, double time,
double deltaTime, double endTime, int isNewStep);
typedef McxStatus (* fComponentFinish)(Component * comp, FinishState * finishState);
typedef size_t (* fComponentGetNumber)(const Component * comp);
typedef size_t (* fComponentGetOutGroup )(const Component * comp, size_t group);
typedef struct Dependencies * (* fComponentGetInOutDependency)(const Component * comp);
typedef McxStatus (* fComponentChannelRead)(Component * comp, struct ChannelInfo * info, PortInput * portInput, size_t idx);
typedef McxStatus (* fComponentChannelSetup)(Component * comp);
typedef McxStatus (* fComponentSetTimeStep)(Component * comp, double timeStep);
typedef void(* fComponentSetTime)(Component * comp, double time);
typedef int (* fComponentHasOwnTime)(const Component * comp);
typedef void(* fComponentSetHasOwnTime)(Component * comp);
typedef void (* fComponentUpdateTime)(Component * comp);
typedef int (* fComponentOneOutputOneGroup)(Component * comp);
typedef ComponentFinishState (* fComponentGetFinishState)(const Component * comp);
typedef void (* fComponentSetIsFinished)(Component * comp);
typedef struct Databus * (* fComponentGetDatabus)(const Component * comp);
typedef const char * (* fComponentGetName)(const Component * comp);
typedef struct Model * (* fComponentGetModel)(const Component * comp);
typedef size_t (* fComponentGetID)(const Component * comp);
typedef int (* fComponentGetSequenceNumber)(const Component * comp);
typedef int (* fComponentGetCPUIdx)(const Component * comp);
typedef ObjectContainer * (*fComponentGetConnections)(Component * fromComp, Component * toComp);
typedef struct PpdLink * (* fGetPPDLink)(struct Component * comp);
typedef ChannelMode (* fGetChannelDefaultMode)(struct Component * comp);
typedef McxStatus (* fComponentPreDoUpdateState)(Component * comp, double time, double deltaTime);
typedef McxStatus (* fComponentPostDoUpdateState)(Component * comp, double time, double deltaTime);
typedef char * (* fComponentGetResultDir)(Component * comp);
typedef void (* fComponentSetModel)(Component * comp, struct Model * model);
typedef McxStatus (* fComponentStore)(Component * comp, ChannelStoreType chType, double time, StoreLevel level);
typedef int (* fComponentPredicate)(Component * comp);
typedef double (* fComponentGetDouble)(const Component * comp);
typedef McxStatus (*fComponentSetDouble)(Component * comp, double offset);
typedef void (*fComponentSetIsPartOfInitCalculation)(Component * comp, int isPartOfInitCalculation);
extern const struct ObjectClass _Component;
struct Component {
Object _;
// Reads general component data from file
fComponentRead Read;
// Builds component according to data read by comp->Read
fComponentSetup Setup;
fComponentSetup SetupRTFactor;
fComponentSetup SetupDatabus;
fComponentInitialize Initialize;
fComponentExitInitializationMode ExitInitializationMode;
/**
* Updates the initial values of the output channels depending on the
* internal parameters and the input channels.
*/
fComponentUpdateInitialOutChannels UpdateInitialOutChannels;
fComponentUpdateOutChannels UpdateOutChannels;
fComponentUpdateInChannels UpdateInChannels;
/**
* Creates a new ComponentStorage, adds all its valid input and output channels,
* and registers the ComponentStorage with the ResultStorage.
*/
fComponentRegisterStorage RegisterStorage;
fComponentGetStorage GetStorage;
fComponentStore Store;
fComponentDoStep DoStep;
fComponentFinish Finish;
// Read and Setup Channels
fComponentChannelRead ChannelInRead;
fComponentChannelSetup ChannelInSetup;
fComponentChannelRead ChannelOutRead;
fComponentChannelSetup ChannelOutSetup;
fGetChannelDefaultMode GetInChannelDefaultMode;
// Data bus functions
fComponentGetNumber GetNumInChannels;
fComponentGetNumber GetNumOutChannels;
fComponentGetNumber GetNumLocalChannels;
fComponentGetNumber GetNumRTFactorChannels;
fComponentGetNumber GetNumWriteInChannels;
fComponentGetNumber GetNumWriteOutChannels;
fComponentGetNumber GetNumWriteLocalChannels;
fComponentGetNumber GetNumWriteRTFactorChannels;
fComponentGetNumber GetNumConnectedOutChannels;
fComponentGetNumber GetNumOutGroups;
fComponentGetNumber GetNumInitialOutGroups;
fComponentGetOutGroup GetOutGroup;
fComponentGetOutGroup GetInitialOutGroup;
fComponentGetInOutDependency GetInOutGroupsDependency;
fComponentGetInOutDependency GetInOutGroupsInitialDependency;
// For multi rate simulation
fComponentGetDouble GetTime;
fComponentSetTime SetTime;
fComponentHasOwnTime HasOwnTime;
fComponentSetHasOwnTime SetHasOwnTime;
fComponentPredicate IsPartOfInitCalculation;
fComponentSetIsPartOfInitCalculation SetIsPartOfInitCalculation;
fComponentGetFinishState GetFinishState;
fComponentSetIsFinished SetIsFinished;
fComponentGetDouble GetTimeStep;
fComponentSetTimeStep SetTimeStep;
fComponentSetTimeStep SetDefaultTimeStep;
fComponentUpdateTime UpdateTime;
fComponentSetModel SetModel;
fComponentGetDatabus GetDatabus;
fComponentGetName GetName;
fComponentGetName GetType;
fComponentGetModel GetModel;
fComponentGetID GetID;
fComponentOneOutputOneGroup OneOutputOneGroup;
fComponentGetSequenceNumber GetSequenceNumber;
fGetPPDLink GetPPDLink;
fComponentGetConnections GetConnections;
fComponentPreDoUpdateState PreDoUpdateState;
fComponentPostDoUpdateState PostDoUpdateState;
fComponentSetup WriteDebugInfoAfterSimulation; // TODO: find a better name for function pointer typedef
fComponentGetResultDir GetResultDir;
fComponentSetDouble SetResultTimeOffset;
struct ComponentData * data;
};
/* these functions have to be called by subclasses */
void ComponentLog(const Component * comp, LogSeverity sev, const char * format, ...);
McxStatus ComponentRead(Component * comp, ComponentInput * input);
McxStatus ComponentSetup(Component * comp);
McxStatus ComponentRegisterStorage(Component* comp, struct ResultsStorage* storage);
McxStatus ComponentInitialize(Component * comp, size_t group, double startTime);
McxStatus ComponentExitInitializationMode(Component * comp);
McxStatus ComponentUpdateOutChannels(Component * comp, TimeInterval * time);
McxStatus ComponentDoStep(Component * comp, size_t group, double time, double deltaTime, double endTime, int isNewStep);
McxStatus ComponentDoCommunicationStep(Component * comp, size_t group, struct StepTypeParams * params);
McxStatus ComponentEnterCommunicationPoint(Component * comp, TimeInterval * time);
McxStatus ComponentEnterCommunicationPointForConnections(Component * comp, ObjectContainer * connections, TimeInterval * time);
struct ConnectionInfo * GetInConnectionInfo(const Component * comp, size_t channelID);
struct Connection * GetInConnection(const Component * comp, size_t channelID);
size_t ComponentGetNumOutGroups(const Component * comp);
size_t ComponentGetNumInitialOutGroups(const Component * comp);
size_t ComponentGetOutGroup(const Component * comp, size_t idx);
size_t ComponentGetInitialOutGroup(const Component * comp, size_t idx);
struct Dependencies * ComponentGetInOutGroupsFullDependency(const Component * comp);
struct Dependencies * ComponentGetInOutGroupsNoDependency(const Component * comp);
McxStatus ComponentOutConnectionsEnterInitMode(Component * comp);
McxStatus ComponentDoOutConnectionsInitialization(Component * comp, int onlyIfDecoupled);
McxStatus ComponentOutConnectionsExitInitMode(Component * comp, double time);
double ComponentGetResultTimeOffset(struct Component * comp);
int ComponentGetHasOwnInputEvaluationTime(const Component * comp);
void ComponentSetHasOwnInputEvaluationTime(Component * comp, int flag);
int ComponentGetUseInputsAtCouplingStepEndTime(const Component * comp);
void ComponentSetUseInputsAtCouplingStepEndTime(Component * comp, int flag);
int ComponentGetStoreInputsAtCouplingStepEndTime(const Component * comp);
void ComponentSetStoreInputsAtCouplingStepEndTime(Component * comp, int flag);
Component * CreateComponentFromComponentInput(ComponentFactory * factory,
ComponentInput * componentInput,
const size_t id,
const struct Config * const config);
Component * ComponentClone(ComponentFactory * factory,
const Component * source,
const char * cloneName,
const size_t id,
const struct Config * const config);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif /* __cplusplus */
#endif /* MCX_CORE_COMPONENT_H */