-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOET-v0-3.mo
629 lines (541 loc) · 38.1 KB
/
OET-v0-3.mo
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/* Modelica Ocean Engineering Toolbox v0.3
Copyright (C) 2024 Ajay Menon, Ali Haider, Kush Bubbar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Your copy of the GNU General Public License can be viewed
here <https://www.gnu.org/licenses/>.
*/
/* Library structure:
Ocean Engineering Toolbox (LIBRARY)
|
|-> Wave Profile (PACKAGE)
| |-> Regular Wave (PACKAGE)
| | |-> LinearWave (MODEL) [!- Monochromatic regular wave]
| |
| |-> Irregular Wave (PACKAGE)
| | |-> Pierson Moskowitz Spectrum (MODEL) [!- Fully-developed sea state]
| | |-> Bretschneider Spectrum (MODEL) [!- Modified PM spectrum for developing sea state]
| | |-> JONSWAP Spectrum (MODEL) [!- Developing sea state with limited fetch]
| |
|-> Structures (PACKAGE)
| |-> RigidBody (MODEL) [!- Solves motion using the Cummins equation]
|
|-> Internal (PACKAGE)
| |-> Functions (PACKAGE)
| | |-> waveNumber (FUNCTION) [!- Wave number iterations from frequency and depth]
| | |-> randomNumberGen (FUNCTION) [!- Random numbers through XOR shift generator]
| | |-> frequencySelector (FUNCTION) [!- Select wave frequencies from a range]
| | |-> spectrumGenerator_PM (FUNCTION) [!- Generate Pierson Moskowitz spectrum for frequency components]
| | |-> spectrumGenerator_BRT (FUNCTION) [!- Generate Bretschneider spectrum for frequency components]
| | |-> spectrumGenerator_JONSWAP (FUNCTION) [!- Generate JONSWAP spectrum for frequency components]
| |
| |-> Connectors (PACKAGE)
| | |-> WaveOutConn (CONNECTOR) [!- Output transfer wave elevation and excitation force]
| | |-> WaveInConn (CONNECTOR) [!- Input transfer wave elevation and excitation force]
| | |-> DataCollector (CONNECTOR) [!- Transfer 'Rigid Body' dynamics and forces]
| |
| |-> TestDevelopment (MODEL) [!- Developer component to test all models, functions, connectors]
|
|-> Tutorial (PACKAGE)
| |-> Sample1 (MODEL) [!- Example model to simulate a rigid body in regular waves]
| |-> Sample2 (MODEL) [!- Example model to simulate a rigid body in irregular waves]
|
|-> Simulations (PACKAGE)
|-> * Directory for users to build custom simulation models *
*/
package OceanEngineeringToolbox
extends Modelica.Icons.Package;
package WaveProfile
package RegularWave
/* Package for regular wave elevation profile and excitation force calculations */
model LinearWave
/* Implementation of linear Airy wave model.
Excitation force transferred through 'wconn'.
Elevation profile is local and not transferred.
*/
extends Modelica.Blocks.Icons.Block;
import Modelica.Math.Vectors;
OceanEngineeringToolbox.Internal.Connectors.WaveOutConn wconn;
/* Environmental constants */
constant Real pi = Modelica.Constants.pi "Mathematical constant pi";
constant Real g = Modelica.Constants.g_n "Acceleration due to gravity";
/* 'wDims' is 2-element vector of size of hydroCoeff frequency vector [1, size].
Convert to scalar 'parameter Integer wSize' to pass as argument to readRealMatrix().
The first matrix dimension is size=1 since w, F_excRe, and F_excIm are vectors.
Size of w (frequency vector) is passed as argument for F_excRe and F_excIm also.
*/
parameter String fileName "Address of hydroCoeff.mat file";
parameter Integer wDims[:] = Modelica.Utilities.Streams.readMatrixSize(fileName, "hydroCoeff.w");
parameter Integer wSize = wDims[2];
parameter Real F_excRe[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.FexcRe", 1, wSize));
parameter Real F_excIm[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.FexcIm", 1, wSize));
parameter Real w[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.w", 1, wSize));
/* Variable declarations */
parameter Modelica.Units.SI.Length d = 100 "Water depth";
parameter Modelica.Units.SI.Density rho = 1025 "Density of seawater";
parameter Modelica.Units.SI.Length Hs = 2.5 "Significant Wave Height";
parameter Modelica.Units.SI.AngularFrequency omega = 0.9423 "Wave frequency";
parameter Real Trmp = 100 "Interval for ramping up of waves during start phase";
parameter Modelica.Units.SI.Length zeta = Hs/2 "Wave amplitude";
parameter Real Tp = 2*pi/omega "Wave period";
parameter Real k = 2*pi/(1.56*(Tp^2)) "Wave number";
Real ExcCoeffRe "Real component of excitation coefficient";
Real ExcCoeffIm "Imaginary component of excitation coefficient";
Modelica.Units.SI.Length SSE "Sea surface elevation";
equation
/* Interpolate excitation coefficients (Re & Im) for wave frequency */
ExcCoeffRe = Modelica.Math.Vectors.interpolate(w, F_excRe, omega);
ExcCoeffIm = Modelica.Math.Vectors.interpolate(w, F_excIm, omega);
/* Define wave elevation profile (SSE) and excitation force */
SSE = zeta*cos(omega*time);
/* Ramp the excitation force for any time < ramp time (Trmp) */
if time < Trmp then
wconn.F_exc = 0.5*(1 + cos(pi + (pi*time/Trmp)))*((ExcCoeffRe*zeta*cos(omega*time))-(ExcCoeffIm*zeta*sin(omega*time)))*rho*g;
else
wconn.F_exc = ((ExcCoeffRe*zeta*cos(omega*time))-(ExcCoeffIm*zeta*sin(omega*time)))*rho*g;
end if;
annotation(
Icon(graphics = {Line(origin = {-50.91, 48.08}, points = {{-33.2809, -22.5599}, {-21.2809, -20.5599}, {-13.2809, 27.4401}, {6.71907, -20.5599}, {24.7191, -24.5599}, {42.7191, -24.5599}, {44.7191, -24.5599}}, color = {255, 0, 0}, smooth = Smooth.Bezier), Line(origin = {-37, 51}, points = {{-51, 29}, {-51, -29}, {37, -29}}), Text(origin = {6, 55}, extent = {{-40, 17}, {40, -17}}, textString = "Hs"), Line(origin = {22, 4}, points = {{0, 22}, {0, -22}}, thickness = 1, arrow = {Arrow.None, Arrow.Filled}), Line(origin = {-7.57, -61.12}, points = {{-82.4341, -12.8774}, {-76.4341, -2.87735}, {-72.4341, -6.87735}, {-62.4341, 13.1226}, {-50.4341, -26.8774}, {-46.4341, -20.8774}, {-38.4341, -26.8774}, {-34.4341, -18.8774}, {-34.4341, 3.12265}, {-26.4341, 1.12265}, {-20.4341, 7.12265}, {-12.4341, 9.12265}, {-8.43408, 19.1226}, {1.56592, -4.87735}, {7.56592, -24.8774}, {19.5659, -6.87735}, {21.5659, 9.12265}, {31.5659, 13.1226}, {39.5659, -0.87735}, {43.5659, 11.1226}, {55.5659, 15.1226}, {63.5659, 27.1226}, {79.5659, -22.8774}}, color = {0, 0, 255}, smooth = Smooth.Bezier), Rectangle(origin = {100, 0}, fillColor = {85, 255, 127}, fillPattern = FillPattern.Solid, extent = {{-20, 20}, {20, -20}})}, coordinateSystem(initialScale = 0.1)),
experiment(StartTime = 0, StopTime = 400, Tolerance = 1e-06, Interval = 0.05));
end LinearWave;
end RegularWave;
package IrregularWave
/* Package for irregular wave elevation profile and excitation force calculations */
model PiersonMoskowitzWave
/* Implements Pierson Moskowitz (PM) energy spectrum.
Excitation force transferred through 'wconn'.
Elevation profile is local and not transferred.
*/
extends Modelica.Blocks.Icons.Block;
import Modelica.Math.Vectors;
OceanEngineeringToolbox.Internal.Connectors.WaveOutConn wconn;
/* Environmental constants */
constant Real pi = Modelica.Constants.pi "Mathematical constant pi";
constant Real g = Modelica.Constants.g_n "Acceleration due to gravity";
/* 'wDims' is 2-element vector of size of hydroCoeff frequency vector [1, size].
Convert to scalar 'parameter Integer wSize' to pass as argument to readRealMatrix().
The first matrix dimension is size=1 since w, F_excRe, and F_excIm are vectors.
Size of w (frequency vector) is passed as argument for F_excRe and F_excIm also.
*/
parameter String fileName "Address of hydroCoeff.mat file";
parameter Integer wDims[:] = Modelica.Utilities.Streams.readMatrixSize(fileName, "hydroCoeff.w");
parameter Integer wSize = wDims[2];
parameter Real F_excRe[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.FexcRe", 1, wSize));
parameter Real F_excIm[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.FexcIm", 1, wSize));
parameter Real w[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.w", 1, wSize));
/* Variable declarations */
parameter Modelica.Units.SI.Length d = 100 "Water depth";
parameter Modelica.Units.SI.Density rho = 1025 "Density of seawater";
parameter Modelica.Units.SI.Length Hs = 2.5 "Significant Wave Height";
parameter Modelica.Units.SI.AngularFrequency omega_min = 0.03141 "Lowest frequency component/frequency interval";
parameter Modelica.Units.SI.AngularFrequency omega_max = 3.141 "Highest frequency component";
parameter Modelica.Units.SI.AngularFrequency omega_peak = 0.9423 "Peak spectral frequency";
parameter Real spectralWidth_min = 0.07 "Lower spectral bound for JONSWAP";
parameter Real spectralWidth_max = 0.09 "Upper spectral bound for JONSWAP";
parameter Integer n_omega = 100 "Number of frequency components";
parameter Integer localSeed = 614657 "Local random seed";
parameter Integer globalSeed = 30020 "Global random seed";
parameter Real rnd_shft[n_omega] = OceanEngineeringToolbox.Internal.Functions.randomNumberGen(localSeed, globalSeed, n_omega);
parameter Integer localSeed1 = 614757 "Local rand seed";
parameter Integer globalSeed1 = 40020 "Global rand seed";
parameter Real epsilon[n_omega] = OceanEngineeringToolbox.Internal.Functions.randomNumberGen(localSeed1, globalSeed1, n_omega) "Wave components phase shift";
parameter Real Trmp = 100 "Interval for ramping up of waves during start phase";
parameter Real omega[n_omega] = OceanEngineeringToolbox.Internal.Functions.frequencySelector(omega_min, omega_max, rnd_shft);
parameter Real S[n_omega] = OceanEngineeringToolbox.Internal.Functions.spectrumGenerator_PM(Hs, omega) "Spectral values for frequency components";
parameter Modelica.Units.SI.Length zeta[n_omega] = sqrt(2*S*omega_min) "Wave amplitude component";
parameter Real Tp[n_omega] = 2*pi./omega "Wave period components";
parameter Real k[n_omega] = OceanEngineeringToolbox.Internal.Functions.waveNumber(d, omega) "Wave number component";
Real ExcCoeffRe[n_omega] "Real component of excitation coefficient for frequency components";
Real ExcCoeffIm[n_omega] "Imaginary component of excitation coefficient for frequency components";
Modelica.Units.SI.Length SSE "Sea surface elevation";
equation
/* Interpolate excitation coefficients (Re & Im) for each frequency component */
for i in 1:n_omega loop
ExcCoeffRe[i] = Modelica.Math.Vectors.interpolate(w, F_excRe, omega[i])*rho*g;
ExcCoeffIm[i] = Modelica.Math.Vectors.interpolate(w, F_excIm, omega[i])*rho*g;
end for;
/* Define wave elevation profile (SSE) and excitation force */
SSE = sum(zeta.*cos(omega*time - 2*pi*epsilon));
/* Ramp the excitation force for any time < ramp time (Trmp) */
if time < Trmp then
wconn.F_exc = 0.5*(1 + cos(pi + (pi*time/Trmp)))*sum((ExcCoeffRe.*zeta.*cos(omega*time - 2*pi*epsilon)) - (ExcCoeffIm.*zeta.*sin(omega*time - 2*pi*epsilon)));
else
wconn.F_exc = sum((ExcCoeffRe.*zeta.*cos(omega*time - 2*pi*epsilon)) - (ExcCoeffIm.*zeta.*sin(omega*time - 2*pi*epsilon)));
end if;
annotation(
Icon(graphics = {Line(origin = {-50.91, 48.08}, points = {{-33.2809, -22.5599}, {-21.2809, -20.5599}, {-13.2809, 27.4401}, {6.71907, -20.5599}, {24.7191, -24.5599}, {42.7191, -24.5599}, {44.7191, -24.5599}}, color = {255, 0, 0}, smooth = Smooth.Bezier), Line(origin = {-37, 51}, points = {{-51, 29}, {-51, -29}, {37, -29}}), Text(origin = {6, 55}, extent = {{-40, 17}, {40, -17}}, textString = "Hs"), Line(origin = {22, 4}, points = {{0, 22}, {0, -22}}, thickness = 1, arrow = {Arrow.None, Arrow.Filled}), Line(origin = {-7.57, -61.12}, points = {{-82.4341, -12.8774}, {-76.4341, -2.87735}, {-72.4341, -6.87735}, {-62.4341, 13.1226}, {-50.4341, -26.8774}, {-46.4341, -20.8774}, {-38.4341, -26.8774}, {-34.4341, -18.8774}, {-34.4341, 3.12265}, {-26.4341, 1.12265}, {-20.4341, 7.12265}, {-12.4341, 9.12265}, {-8.43408, 19.1226}, {1.56592, -4.87735}, {7.56592, -24.8774}, {19.5659, -6.87735}, {21.5659, 9.12265}, {31.5659, 13.1226}, {39.5659, -0.87735}, {43.5659, 11.1226}, {55.5659, 15.1226}, {63.5659, 27.1226}, {79.5659, -22.8774}}, color = {0, 0, 255}, smooth = Smooth.Bezier), Rectangle(origin = {100, 0}, fillColor = {85, 255, 127}, fillPattern = FillPattern.Solid, extent = {{-20, 20}, {20, -20}})}, coordinateSystem(initialScale = 0.1)));
end PiersonMoskowitzWave;
model BretschneiderWave
/* Implements Bretschneider energy spectrum.
Excitation force transferred through 'wconn'.
Elevation profile is local and not transferred.
*/
extends Modelica.Blocks.Icons.Block;
import Modelica.Math.Vectors;
OceanEngineeringToolbox.Internal.Connectors.WaveOutConn wconn;
/* Environmental constants */
constant Real pi = Modelica.Constants.pi "Mathematical constant pi";
constant Real g = Modelica.Constants.g_n "Acceleration due to gravity";
/* 'wDims' is 2-element vector of size of hydroCoeff frequency vector [1, size].
Convert to scalar 'parameter Integer wSize' to pass as argument to readRealMatrix().
The first matrix dimension is size=1 since w, F_excRe, and F_excIm are vectors.
Size of w (frequency vector) is passed as argument for F_excRe and F_excIm also.
*/
parameter String fileName "Address of hydroCoeff.mat file";
parameter Integer wDims[:] = Modelica.Utilities.Streams.readMatrixSize(fileName, "hydroCoeff.w");
parameter Integer wSize = wDims[2];
parameter Real F_excRe[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.FexcRe", 1, wSize));
parameter Real F_excIm[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.FexcIm", 1, wSize));
parameter Real w[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.w", 1, wSize));
/* Variable declarations */
parameter Modelica.Units.SI.Length d = 100 "Water depth";
parameter Modelica.Units.SI.Density rho = 1025 "Density of seawater";
parameter Modelica.Units.SI.Length Hs = 2.5 "Significant Wave Height";
parameter Modelica.Units.SI.AngularFrequency omega_min = 0.03141 "Lowest frequency component/frequency interval";
parameter Modelica.Units.SI.AngularFrequency omega_max = 3.141 "Highest frequency component";
parameter Modelica.Units.SI.AngularFrequency omega_peak = 0.9423 "Peak spectral frequency";
parameter Integer n_omega = 100 "Number of frequency components";
parameter Integer localSeed = 614657 "Local random seed";
parameter Integer globalSeed = 30020 "Global random seed";
parameter Real rnd_shft[n_omega] = OceanEngineeringToolbox.Internal.Functions.randomNumberGen(localSeed, globalSeed, n_omega);
parameter Integer localSeed1 = 614757 "Local rand seed";
parameter Integer globalSeed1 = 40020 "Global rand seed";
parameter Real epsilon[n_omega] = OceanEngineeringToolbox.Internal.Functions.randomNumberGen(localSeed1, globalSeed1, n_omega) "Wave components phase shift";
parameter Real Trmp = 200 "Interval for ramping up of waves during start phase";
parameter Real omega[n_omega] = OceanEngineeringToolbox.Internal.Functions.frequencySelector(omega_min, omega_max, rnd_shft);
parameter Real S[n_omega] = OceanEngineeringToolbox.Internal.Functions.spectrumGenerator_BRT(Hs, omega, omega_peak) "Spectral values for frequency components";
parameter Modelica.Units.SI.Length zeta[n_omega] = sqrt(2*S*omega_min) "Wave amplitude component";
parameter Real Tp[n_omega] = 2*pi./omega "Wave period components";
parameter Real k[n_omega] = OceanEngineeringToolbox.Internal.Functions.waveNumber(d, omega) "Wave number component";
Real ExcCoeffRe[n_omega] "Real component of excitation coefficient for frequency components";
Real ExcCoeffIm[n_omega] "Imaginary component of excitation coefficient for frequency components";
Modelica.Units.SI.Length SSE "Sea surface elevation";
equation
/* Interpolate excitation coefficients (Re & Im) for each frequency component */
for i in 1:n_omega loop
ExcCoeffRe[i] = Modelica.Math.Vectors.interpolate(w, F_excRe, omega[i])*rho*g;
ExcCoeffIm[i] = Modelica.Math.Vectors.interpolate(w, F_excIm, omega[i])*rho*g;
end for;
/* Define wave elevation profile (SSE) and excitation force */
SSE = sum(zeta.*cos(omega*time - 2*pi*epsilon));
/* Ramp the excitation force for any time < ramp time (Trmp) */
if time < Trmp then
wconn.F_exc = 0.5*(1 + cos(pi + (pi*time/Trmp)))*sum((ExcCoeffRe.*zeta.*cos(omega*time - 2*pi*epsilon)) - (ExcCoeffIm.*zeta.*sin(omega*time - 2*pi*epsilon)));
else
wconn.F_exc = sum((ExcCoeffRe.*zeta.*cos(omega*time - 2*pi*epsilon)) - (ExcCoeffIm.*zeta.*sin(omega*time - 2*pi*epsilon)));
end if;
annotation(
Icon(graphics = {Line(origin = {-50.91, 48.08}, points = {{-33.2809, -22.5599}, {-21.2809, -20.5599}, {-13.2809, 27.4401}, {6.71907, -20.5599}, {24.7191, -24.5599}, {42.7191, -24.5599}, {44.7191, -24.5599}}, color = {255, 0, 0}, smooth = Smooth.Bezier), Line(origin = {-37, 51}, points = {{-51, 29}, {-51, -29}, {37, -29}}), Text(origin = {6, 55}, extent = {{-40, 17}, {40, -17}}, textString = "Hs"), Line(origin = {22, 4}, points = {{0, 22}, {0, -22}}, thickness = 1, arrow = {Arrow.None, Arrow.Filled}), Line(origin = {-7.57, -61.12}, points = {{-82.4341, -12.8774}, {-76.4341, -2.87735}, {-72.4341, -6.87735}, {-62.4341, 13.1226}, {-50.4341, -26.8774}, {-46.4341, -20.8774}, {-38.4341, -26.8774}, {-34.4341, -18.8774}, {-34.4341, 3.12265}, {-26.4341, 1.12265}, {-20.4341, 7.12265}, {-12.4341, 9.12265}, {-8.43408, 19.1226}, {1.56592, -4.87735}, {7.56592, -24.8774}, {19.5659, -6.87735}, {21.5659, 9.12265}, {31.5659, 13.1226}, {39.5659, -0.87735}, {43.5659, 11.1226}, {55.5659, 15.1226}, {63.5659, 27.1226}, {79.5659, -22.8774}}, color = {0, 0, 255}, smooth = Smooth.Bezier), Rectangle(origin = {100, 0}, fillColor = {85, 255, 127}, fillPattern = FillPattern.Solid, extent = {{-20, 20}, {20, -20}})}, coordinateSystem(initialScale = 0.1)),
experiment(StartTime = 0, StopTime = 400, Tolerance = 1e-06, Interval = 0.05));
end BretschneiderWave;
model JonswapWave
/* Implements JONSWAP energy spectrum.
Excitation force transferred through 'wconn'.
Elevation profile is local and not transferred.
*/
extends Modelica.Blocks.Icons.Block;
import Modelica.Math.Vectors;
OceanEngineeringToolbox.Internal.Connectors.WaveOutConn wconn;
/* Environmental constants */
constant Real pi = Modelica.Constants.pi "Mathematical constant pi";
constant Real g = Modelica.Constants.g_n "Acceleration due to gravity";
/* 'wDims' is 2-element vector of size of hydroCoeff frequency vector [1, size].
Convert to scalar 'parameter Integer wSize' to pass as argument to readRealMatrix().
The first matrix dimension is size=1 since w, F_excRe, and F_excIm are vectors.
Size of w (frequency vector) is passed as argument for F_excRe and F_excIm also.
*/
parameter String fileName "Address of hydroCoeff.mat file";
parameter Integer wDims[:] = Modelica.Utilities.Streams.readMatrixSize(fileName, "hydroCoeff.w");
parameter Integer wSize = wDims[2];
parameter Real F_excRe[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.FexcRe", 1, wSize));
parameter Real F_excIm[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.FexcIm", 1, wSize));
parameter Real w[:] = vector(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.w", 1, wSize));
/* Variable declarations */
parameter Modelica.Units.SI.Length d = 100 "Water depth";
parameter Modelica.Units.SI.Density rho = 1025 "Density of seawater";
parameter Modelica.Units.SI.Length Hs = 2.5 "Significant Wave Height";
parameter Modelica.Units.SI.AngularFrequency omega_min = 0.03141 "Lowest frequency component/frequency interval";
parameter Modelica.Units.SI.AngularFrequency omega_max = 3.141 "Highest frequency component";
parameter Modelica.Units.SI.AngularFrequency omega_peak = 0.9423 "Peak spectral frequency";
parameter Real spectralWidth_min = 0.07 "Lower spectral bound for JONSWAP";
parameter Real spectralWidth_max = 0.09 "Upper spectral bound for JONSWAP";
parameter Integer n_omega = 100 "Number of frequency components";
parameter Integer localSeed = 614657 "Local random seed";
parameter Integer globalSeed = 30020 "Global random seed";
parameter Real rnd_shft[n_omega] = OceanEngineeringToolbox.Internal.Functions.randomNumberGen(localSeed, globalSeed, n_omega);
parameter Integer localSeed1 = 614757 "Local rand seed";
parameter Integer globalSeed1 = 40020 "Global rand seed";
parameter Real epsilon[n_omega] = OceanEngineeringToolbox.Internal.Functions.randomNumberGen(localSeed1, globalSeed1, n_omega) "Wave components phase shift";
parameter Real Trmp = 200 "Interval for ramping up of waves during start phase";
parameter Real omega[n_omega] = OceanEngineeringToolbox.Internal.Functions.frequencySelector(omega_min, omega_max, rnd_shft);
parameter Real S[n_omega] = OceanEngineeringToolbox.Internal.Functions.spectrumGenerator_JONSWAP(Hs, omega, omega_peak, spectralWidth_min, spectralWidth_max) "Spectral values for frequency components";
parameter Modelica.Units.SI.Length zeta[n_omega] = sqrt(2*S*omega_min) "Wave amplitude component";
parameter Real Tp[n_omega] = 2*pi./omega "Wave period components";
parameter Real k[n_omega] = OceanEngineeringToolbox.Internal.Functions.waveNumber(d, omega) "Wave number component";
Real ExcCoeffRe[n_omega] "Real component of excitation coefficient for frequency components";
Real ExcCoeffIm[n_omega] "Imaginary component of excitation coefficient for frequency components";
Modelica.Units.SI.Length SSE "Sea surface elevation";
equation
/* Interpolate excitation coefficients (Re & Im) for each frequency component */
for i in 1:n_omega loop
ExcCoeffRe[i] = Modelica.Math.Vectors.interpolate(w, F_excRe, omega[i])*rho*g;
ExcCoeffIm[i] = Modelica.Math.Vectors.interpolate(w, F_excIm, omega[i])*rho*g;
end for;
/* Define wave elevation profile (SSE) and excitation force */
SSE = sum(zeta.*cos(omega*time - 2*pi*epsilon));
/* Ramp the excitation force for any time < ramp time (Trmp) */
if time < Trmp then
wconn.F_exc = 0.5*(1 + cos(pi + (pi*time/Trmp)))*sum((ExcCoeffRe.*zeta.*cos(omega*time - 2*pi*epsilon)) - (ExcCoeffIm.*zeta.*sin(omega*time - 2*pi*epsilon)));
else
wconn.F_exc = sum((ExcCoeffRe.*zeta.*cos(omega*time - 2*pi*epsilon)) - (ExcCoeffIm.*zeta.*sin(omega*time - 2*pi*epsilon)));
end if;
annotation(
Icon(graphics = {Line(origin = {-50.91, 48.08}, points = {{-33.2809, -22.5599}, {-21.2809, -20.5599}, {-13.2809, 27.4401}, {6.71907, -20.5599}, {24.7191, -24.5599}, {42.7191, -24.5599}, {44.7191, -24.5599}}, color = {255, 0, 0}, smooth = Smooth.Bezier), Line(origin = {-37, 51}, points = {{-51, 29}, {-51, -29}, {37, -29}}), Text(origin = {6, 55}, extent = {{-40, 17}, {40, -17}}, textString = "Hs"), Line(origin = {22, 4}, points = {{0, 22}, {0, -22}}, thickness = 1, arrow = {Arrow.None, Arrow.Filled}), Line(origin = {-7.57, -61.12}, points = {{-82.4341, -12.8774}, {-76.4341, -2.87735}, {-72.4341, -6.87735}, {-62.4341, 13.1226}, {-50.4341, -26.8774}, {-46.4341, -20.8774}, {-38.4341, -26.8774}, {-34.4341, -18.8774}, {-34.4341, 3.12265}, {-26.4341, 1.12265}, {-20.4341, 7.12265}, {-12.4341, 9.12265}, {-8.43408, 19.1226}, {1.56592, -4.87735}, {7.56592, -24.8774}, {19.5659, -6.87735}, {21.5659, 9.12265}, {31.5659, 13.1226}, {39.5659, -0.87735}, {43.5659, 11.1226}, {55.5659, 15.1226}, {63.5659, 27.1226}, {79.5659, -22.8774}}, color = {0, 0, 255}, smooth = Smooth.Bezier), Rectangle(origin = {100, 0}, fillColor = {85, 255, 127}, fillPattern = FillPattern.Solid, extent = {{-20, 20}, {20, -20}})}, coordinateSystem(initialScale = 0.1)),
experiment(StartTime = 0, StopTime = 400, Tolerance = 1e-06, Interval = 0.05));
end JonswapWave;
end IrregularWave;
end WaveProfile;
package Structures
/* 'RigidBody' component models a rigid body in waves.
Implements a symbolic formulation of the Cummins equation.
Radiation force calculated using the state-space model.
*/
model RigidBody
/* Solves 1DOF Cummins' equation for single body.
Heave excitation force transferred in using 'wconn'.
Heave velocity and radiation force transferred out using 'conn'.
*/
extends Modelica.Blocks.Icons.Block;
OceanEngineeringToolbox.Internal.Connectors.WaveInConn wconn "Connector for wave elevation and excitation force" annotation(
Placement(transformation(extent = {{-90, -10}, {-110, 10}})));
OceanEngineeringToolbox.Internal.Connectors.DataCollector conn "Connector for velocity and radiation force" annotation(
Placement(transformation(extent = {{-10, 90}, {10, 110}})));
/* Parameters & variables */
parameter String fileName;
parameter Modelica.Units.SI.Mass M = scalar(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.m33", 1, 1)) "Total mass of the body (including ballast)";
parameter Modelica.Units.SI.Mass Ainf = scalar(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.Ainf33", 1, 1)) "Added mass at maximum (cut-off) frequency";
parameter Modelica.Units.SI.TranslationalSpringConstant Khs = scalar(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.Khs33", 1, 1)) "Hydrostatic stiffness";
parameter Real A1[2, 2] = Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.ss_rad33.A", 2, 2) "State matrix";
parameter Real B1[2, 1] = Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.ss_rad33.B", 2, 1) "Input matrix";
parameter Real C1[1, 2] = Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.ss_rad33.C", 1, 2) "Output matrix";
parameter Real D1 = scalar(Modelica.Utilities.Streams.readRealMatrix(fileName, "hydroCoeff.ss_rad33.D", 1, 1)) "Feed matrix";
Real x[2,1] "State-space intermediate variables";
Modelica.Units.SI.Length z "Heave displacement";
Modelica.Units.SI.Velocity v_z "Heave velocity";
Modelica.Units.SI.Acceleration a_z "Heave acceleration";
Modelica.Units.SI.Force F_rad "Radiation Force";
initial equation
/* Define body at rest at time=0 */
z = 0;
v_z = 0;
equation
v_z = der(z);
a_z = der(v_z);
/* Radiation force state-space model */
der(x) = (A1*x) + (B1*v_z);
F_rad = scalar(C1*x) + (D1*v_z);
/* Assemble Cummins' equation */
((M + Ainf)*a_z) + F_rad + (Khs*z) = wconn.F_exc;
/* Connector declarations */
conn.F_rad = F_rad;
conn.v_z = v_z;
end RigidBody;
end Structures;
package Internal
/* Internal library of core functions and connectors */
package Functions
/* Package defining explicit library functions */
function waveNumber
/* Function to iteratively compute the wave number from the frequency components */
input Real d "Water depth";
input Real omega[:] "Wave frequency components";
output Real k[size(omega, 1)] "Wave number components";
protected
constant Real g = Modelica.Constants.g_n;
constant Real pi = Modelica.Constants.pi;
parameter Integer n = size(omega, 1);
Real T[size(omega, 1)] "Wave period components";
Real L0[size(omega, 1)] "Deepwater wave length";
Real L1(start = 0, fixed = true) "Temporary variable";
Real L1c(start = 0, fixed = true) "Temporary variable";
Real L[size(omega, 1)] "Iterated wave length";
algorithm
T := 2*pi./omega;
L0 := g*T.^2/(2*pi);
for i in 1:size(omega, 1) loop
L1 := L0[i];
L1c := 0;
while abs(L1c - L1) > 0.001 loop
L1c := L1;
L[i] := g*T[i]^2/(2*pi)*tanh(2*pi/L1*d);
L1 := L[i];
end while;
end for;
k := 2*pi./L;
end waveNumber;
function randomNumberGen
/* Function to generate random numbers from local and global seeds using XOR shift */
input Integer ls = 614657 "Local seed";
input Integer gs = 30020 "Global seed";
input Integer n = 100 "Number of frequency components";
output Real r64[n] "Random number vector";
protected
Integer state64[2](each start = 0, each fixed = true);
algorithm
state64[1] := 0;
state64[2] := 0;
for i in 1:n loop
if i == 1 then
state64 := Modelica.Math.Random.Generators.Xorshift64star.initialState(ls, gs);
r64[i] := 0;
else
(r64[i], state64) := Modelica.Math.Random.Generators.Xorshift64star.random((state64));
end if;
end for;
end randomNumberGen;
function frequencySelector
/* Function to randomly select frequency components */
input Real omega_min "Frequency minima";
input Real omega_max "Frequency maxima";
input Real epsilon[:] "Random phase vector";
output Real omega[size(epsilon, 1)] "Output vector of frequency components";
protected
parameter Real ref_omega[size(epsilon, 1)] = omega_min:(omega_max - omega_min)/(size(epsilon, 1) - 1):omega_max;
algorithm
omega[1] := omega_min;
for i in 2:size(epsilon, 1) - 1 loop
omega[i] := ref_omega[i] + epsilon[i]*omega_min;
end for;
omega[size(epsilon, 1)] := omega_max;
end frequencySelector;
function spectrumGenerator_PM
/* Function to generate Pierson Moskowitz spectrum */
input Real Hs = 1 "Significant wave height";
input Real omega[:] "Frequency components";
output Real spec[size(omega, 1)] "Spectral values for input frequencies";
protected
constant Real pi = Modelica.Constants.pi;
constant Real g = Modelica.Constants.g_n;
algorithm
for i in 1:size(omega, 1) loop
spec[i] := 0.0081*g^2/omega[i]^5*exp(-0.0358*(g/(Hs*omega[i]^2))^2);
end for;
end spectrumGenerator_PM;
function spectrumGenerator_BRT
/* Function to generate Bretschneider spectrum */
input Real Hs = 1 "Significant wave height";
input Real omega[:] "Frequency components";
input Real omega_peak = 0.9423 "Peak spectral frequency";
output Real spec[size(omega, 1)] "Spectral values for input frequencies";
protected
constant Real pi = Modelica.Constants.pi;
constant Real g = Modelica.Constants.g_n;
algorithm
for i in 1:size(omega, 1) loop
spec[i] := 1.9635*Hs^2*omega_peak^4/omega[i]^5*exp(-1.25*((omega_peak/omega[i])^4));
end for;
end spectrumGenerator_BRT;
function spectrumGenerator_JONSWAP
/* Function to generate JONSWAP spectrum */
input Real Hs = 1 "Significant wave height";
input Real omega[:] "Frequency components";
input Real omega_peak = 0.9423 "Peak spectral frequency";
input Real spectralWidth_min "Spectral width lower bound";
input Real spectralWidth_max "Spectral width upper bound";
output Real spec[size(omega, 1)] "Spectral values for input frequencies";
protected
constant Real pi = Modelica.Constants.pi;
constant Real g = Modelica.Constants.g_n;
constant Real gamma = 3.3;
Real sigma;
Real b;
algorithm
for i in 1:size(omega, 1) loop
if omega[i] > omega_peak then
sigma := spectralWidth_max;
else
sigma := spectralWidth_min;
end if;
b := exp(-0.5*(((omega[i] - omega_peak)/(sigma*omega_peak))^2));
spec[i] := 0.0081*g^2/omega[i]^5*exp(-1.25*((omega_peak/omega[i])^4))*gamma^b;
end for;
end spectrumGenerator_JONSWAP;
end Functions;
package Connectors
/* Package defining library connectors */
connector WaveOutConn
/* Output datastream - wave elevation & excitation force */
Modelica.Blocks.Interfaces.RealOutput F_exc;
end WaveOutConn;
connector WaveInConn
/* Input datastream - wave elevation & excitation force */
Modelica.Blocks.Interfaces.RealInput F_exc;
end WaveInConn;
connector DataCollector
/* Output datastream - velocity and radiation force */
Modelica.Blocks.Interfaces.RealOutput F_rad;
Modelica.Blocks.Interfaces.RealOutput v_z;
end DataCollector;
end Connectors;
model TestDevelopment
/* Model to test all wave components and WEC rigid body */
parameter String filePath = "F:/.../hydroCoeff.mat";
OceanEngineeringToolbox.WaveProfile.RegularWave.LinearWave Reg1(fileName = filePath, Hs = 2.5, Trmp = 50);
OceanEngineeringToolbox.WaveProfile.IrregularWave.PiersonMoskowitzWave Irr1(fileName = filePath, Hs = 2.5, n_omega = 100, Trmp = 50);
OceanEngineeringToolbox.WaveProfile.IrregularWave.BretschneiderWave Irr2(fileName = filePath, Hs = 2.5, n_omega = 100, Trmp = 50);
OceanEngineeringToolbox.WaveProfile.IrregularWave.JonswapWave Irr3(fileName = filePath, Hs = 2.5, n_omega = 100, Trmp = 50);
OceanEngineeringToolbox.Structures.RigidBody Body1(fileName = filePath);
OceanEngineeringToolbox.Structures.RigidBody Body2(fileName = filePath);
OceanEngineeringToolbox.Structures.RigidBody Body3(fileName = filePath);
OceanEngineeringToolbox.Structures.RigidBody Body4(fileName = filePath);
equation
connect(Reg1.wconn.F_exc, Body1.wconn.F_exc);
connect(Irr1.wconn.F_exc, Body2.wconn.F_exc);
connect(Irr2.wconn.F_exc, Body3.wconn.F_exc);
connect(Irr3.wconn.F_exc, Body4.wconn.F_exc);
annotation(
experiment(StartTime = 0, StopTime = 200, Tolerance = 1e-06, Interval = 0.1));
end TestDevelopment;
end Internal;
package Tutorial
/* Sample simulation models */
model sample1
/* Single body, regular waves */
parameter String filePath = "F:/.../hydroCoeff.mat";
OceanEngineeringToolbox.WaveProfile.RegularWave.LinearWave Reg1(fileName = filePath, Hs = 2.5, Trmp = 50);
OceanEngineeringToolbox.Structures.RigidBody Body1(fileName = filePath);
equation
connect(Reg1.wconn.F_exc, Body1.wconn.F_exc);
annotation(
Line(points = {{-40, 30}, {-20, 30}, {-20, 0}, {40, 0}, {40, 0}}),
experiment(StartTime = 0, StopTime = 500, Tolerance = 1e-06, Interval = 0.1));
end sample1;
model sample2
/* Single body, irregular waves with PM spectrum */
parameter String filePath = "F:/.../hydroCoeff.mat";
OceanEngineeringToolbox.WaveProfile.IrregularWave.PiersonMoskowitzWave PM1(fileName = filePath, Hs = 2.5, n_omega = 100, Trmp = 100);
OceanEngineeringToolbox.Structures.RigidBody Body1(fileName = filePath);
equation
connect(PM1.wconn.F_exc, Body1.wconn.F_exc);
annotation(
Line(points = {{-40, 30}, {-20, 30}, {-20, 0}, {40, 0}, {40, 0}}),
experiment(StartTime = 0, StopTime = 1000, Tolerance = 1e-06, Interval = 0.1));
end sample2;
end Tutorial;
package Simulations
/* Directory for user-defined simulation models */
end Simulations;
end OceanEngineeringToolbox;
/* Modelica Ocean Engineering Toolbox (OET) v0.3
Developed at:
Sys-MoDEL,
University of New Brunswick, Fredericton
New Brunswick, E3B 5A3, Canada
Copyright under the terms of the GNU General Public License
*/