-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
225 lines (120 loc) · 4 KB
/
Copy pathSource.cpp
File metadata and controls
225 lines (120 loc) · 4 KB
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
#include "Source.h"
#define time q[2]
#define d_time dq[2]
Source::Source()
{
rk_45<IO_Type>* solver = new adevs::rk_45<IO_Type>(sub, simulation_solverTolerance, simulation_step);
linear_event_locator<IO_Type>* event_finder = new adevs::linear_event_locator<IO_Type>(sub, simulation_locatorTolerance);
Hybrid<IO_Type>* shell = new Hybrid<IO_Type>(sub, solver, event_finder);
add(shell);
couple(this, this->in1->Id, shell, sub->in1->Id);
couple(shell, sub->out1->Id, this, this->out1->Id);
}
_Source::_Source():dae_se1_system<IO_Type>(3,2,0) {
}
void _Source::init(double* q, double* a) {
for (int i = 0; i < numVars(); ++i) {
q[i] = 0;
}
for (int i = 0; i < numAlgVars(); ++i) {
a[i] = 0;
}
_t_out=DBL_MAX;
state=_initial;
materialGenerationTotal = 0;
createNum = 0;
generatingMethod = 0;
tableN = 0;
generateNextNum = 0;
t_next = 0;
}
void _Source::der_func(const double* q, const double* a,double* dq) {
d_time = 1;
dq[_initial] = 1;
dq[_Generating] = 1;
}
void _Source::alg_func(const double* q, const double* a,double* af) {
}
double _Source::time_event_func(const double * q, const double* a) {
return _t_out;
}
void _Source::state_event_func(const double* q, const double* a, double* z) {
if(state == _initial && q[_initial]>dwellTime){
if (true)
z[0] = 1;
}
else
z[0] = -1;
if(state == _Generating && q[_Generating]>dwellTime && time>t_next){
if (true)
z[1] = 1;
}
else
z[1] = -1;
}
void _Source::internal_event(double* q, double* a, const bool* state_event) {
if (state_event[0]){
xfe(_Generating,q);
if(generatingMethod == 0){
t_next = time + cf->processTime(generateTime);
generateNextNum = cf->processTime(generateNum);
}
if(generatingMethod == 1){
map<string,double> res = cf->getTime(generateTable,tableN);
if (res["hava"] = 1){
t_next = res["time"];
generateNextNum = res["num"];
tableN++;
}
}
}
if (state_event[1]){
xfe(_Generating,q);
for (int i = 0; i < generateNextNum && createNum < materialGenerationTotal; i++){
createMat signal;
signal.sourceID = sourceId;
signal.ID = sourceId + "-" + to_string(createNum);
signal.priority = priority;
signal.materialNum = materialNum;
out1->send(signal);
createNum++;
}
if(generatingMethod == 0 && createNum < materialGenerationTotal){
t_next = time + cf->processTime(generateTime);
generateNextNum = cf->processTime(generateNum);
}
if(generatingMethod == 0 && createNum >= materialGenerationTotal){
t_next = 1000000;
}
if(generatingMethod == 1){
map<string,double> res = cf->getTime(generateTable, tableN);
if (res["hava"] = 1){
t_next = res["time"];
generateNextNum = res["num"];
tableN++;
}
}
}
}
void _Source::external_event(double* q, double* a, double e, const Bag<IO_Type>& xb) {
Bag < IO_Type >:: const_iterator i = xb.begin();
for (; i != xb.end(); i++) {
}
}
void _Source::confluent_event(double* q, double* a, const bool* state_event, const Bag<IO_Type>& xb) {
external_event(q, a, 0.0, xb);
}
void _Source::output_func(const double * q, const double* a,const bool * state_event, Bag < IO_Type > & yb) {
while (!out1->outEvents.empty()) {
yb.insert(out1->outEvents.front());
out1->outEvents.pop_front();
}
_t_out=DBL_MAX;
}
void _Source::postStep(double* q, double* a){
}
void _Source::gc_output(Bag<IO_Type>& yb) {
for (const auto& item : yb) {
delete item.value;
}
}