-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource_dyn.java
More file actions
211 lines (197 loc) · 6.32 KB
/
Copy pathSource_dyn.java
File metadata and controls
211 lines (197 loc) · 6.32 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
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
// Class name: Source_dyn
//
// Description: input disturbance signal used for process
// different options can be chosen by setting
// the variable type_ ... "true"
// Input variables (poles):
// in - in (normally time signal)
// Output variables (poles):
// out - output
// Variables:
// in - time
//
// Constant:
// mean - the constant value at time = 0
// Step:
// mean - the constant value at time = 0
// step - the height of the step
// tmin - for t < tmin, ramp function applies
// ste - output value
// Oscillation:
// omega - frequency
// fi - phase lag (in degree)
// ampl - amplitude
// maxampl - limiting amplitude (to cut off)
// osc - output value
// Jum:
// height - the height of the step
// for t < tmin and
// (tmin+dtjum)<t<(2*tmin+dtjum)
// ramp function applies
// dtjum - duration of jump
// jum - output value
// Ramp:
// slope - slope of the ramp function
// ram - output value
//
// out - disturbation as a function of in
// type - user chosen type
//
// Created: 01.12.2007
// Last modified: 31.03.2011
//-------------------------------------------------------
import java.text.*;
class Source_dyn {
/*@ specification Source_dyn {
double in, out;
boolean type_con, type_ste, type_jum;
boolean type_osc, type_ram;
double mean;
double step;
double tmin;
double dtjum, height;
double omega,fi,ampl,maxampl;
double slope;
// double Pi;
// State variables
double initstate_c, oldstate_c, state_c;
double nextstate_c, finalstate_c;
alias (double) initstate = (initstate_c);
alias (double) oldstate = (oldstate_c);
alias (double) state = (state_c);
alias (double) nextstate = (nextstate_c);
alias (double) finalstate = (finalstate_c);
// Collecting outputs
alias (double) result = (out, nextstate_c);
// Evaluating initstate components
initstate_c = 0;
//**************************************************
// Method specifications
//Constant:
mean,type_con,state_c -> result {con_calc};
//Step:
// mean - the constant value at time = 0
// step - the height of the step
// tmin - for t < tmin, ramp function applies
in,mean,step,tmin,type_ste,state_c
-> result {ste_calc};
// Oscillation:
// omega - frequency
// fi - phase lag (in degree)
// ampl - amplitude
// maxampl - limiting amplitude (to cut off)
in,mean,omega,fi,ampl,maxampl,type_osc,state_c
-> result {osc_calc};
// Jump:
// height - the height of the step
// for t < tmin and
// (tmin+dtjum)<t<(2*tmin+dtjum)
// ramp function applies
// dtjum - duration of jump
in,mean,height,tmin,dtjum,type_jum,state_c
-> result {jum_calc};
// Ramp:
// slope - slope of the ramp function
// ram - output value
// out - disturbation as a function of in
in, mean, slope, type_ram, state_c
-> result {ram_calc};
}@*/
//=======================================================
// mean,type -> con {con_calc}
//=======================================================
public double[] con_calc ( double mean, boolean type,
double state_c) {
double[] result = new double[2];
result[0] = mean;
result[1] = state_c + 1;
//print_ar("ste_calc: result ",result);
return result;
}
//=======================================================
// in,mean,step,tmin,type,state_c -> result {ste_calc};
//=======================================================
public double[] ste_calc ( double in, double mean,
double step, double tmin,
boolean type, double state_c){
double[] result = new double[2];
double ste;
if ( in < tmin) ste = mean + in * step / tmin;
else ste = mean + step;
result[0] = ste;
result[1] = state_c + 1;
//print_ar("ste_calc: result ",result);
return result;
}
//=======================================================
// in,mean,height,tmin,dtjum, type,state_c
// -> result {jum_calc};
//=======================================================
public double[] jum_calc ( double in, double mean,
double height, double tmin,
double dtjum,
boolean type, double state_c){
double[] result = new double[2];
double jum = 0;
// if ( in <= tmin) {
if ( in < tmin) {
jum = mean + in * height / tmin;
}
else if (in < (tmin + dtjum)) {
jum = mean + height;
}
else if (in < (2*tmin + dtjum)) {
jum = mean +(2*tmin + dtjum -in)*
height/tmin;
}
else if (in >= (2*tmin + dtjum)) {
jum = mean;
}
result[0] = jum;
result[1] = state_c + 1;
//print_ar("jum_calc: result ",result);
return result;
}
//=======================================================
// in,mean,omega,fi,Pi,ampl,maxampl, type,state_c
// -> result {osc_calc};
//=======================================================
public double[] osc_calc ( double in, double mean,
double omega, double fi,
double ampl, double maxampl,
boolean type, double state_c){
double[] result = new double[2];
double osc;
osc = ampl*Math.sin(2*Math.PI*omega*in + fi*Math.PI/180.)+mean;
result[0] = osc;
result[1] = state_c + 1;
//print_ar("osc_calc: result ",result);
return result;
}
//=======================================================
// in,mean,slope, type,state_c -> result {ram_calc};
//=======================================================
public double[] ram_calc ( double in, double mean,
double slope,
boolean type,
double state_c){
double[] result = new double[2];
double ram;
ram = mean + slope*in;
result[0] = ram;
result[1] = state_c + 1;
//print_ar("ram_calc: result ",result);
return result;
}
//=======================================================
// void print_ar (String ar_name, double[] ar)
//=======================================================
public void print_ar (String ar_name, double[] ar) {
DecimalFormat dF = new DecimalFormat("0.###E0");
System.out.print(ar_name + ":");
for (int i = 0; i < ar.length; i++ ) {
System.out.print(" " + dF.format(ar[i]));
}
System.out.println();
}
}