-
Notifications
You must be signed in to change notification settings - Fork 23
/
DynamicalMovementMooringWaveParametric.js
826 lines (745 loc) · 28.8 KB
/
DynamicalMovementMooringWaveParametric.js
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
//@ferrari212
/*This code is based on work developed by Thiago G. Monteiro, Jiafeng Xu and Henrique M. Gaspar.*/
/*source: http://www.shiplab.hials.org/app/6dof/.*/
/*The code will require the main ship dimensions*/
function DynamicalMovement(ship, states, userParameters, Ini, seaDepth) {
this.ship = ship;
this.states = states;
var calculatedParameters = this.ship.designState.calculationParameters;
var options = {
valueNames: ['id', 'name', 'x_position', 'y_position', 'z_position', 'mass', 'l_mass', 'h_mass', 'w_mass']
};
length = floatingStates.LWL;
breadth = floatingStates.BWL;
depth = designDimension.Depth;
draft = floatingStates.T;
Cb = calculatedParameters.Cb_design;
KG = 0.5 * depth;
// Init list
var rho = 1025; // Water Density (kg/m3)
g = 9.81; // Gravitational Acceleration (m/s2)
var m = floatingStates.w.mass; // Vessel Mass (kg)
var a_33 = rho * g * breadth * draft;
var A_WP = floatingStates.Awp; // Still Water Plane Area (m2)
// Remenber to use recalculate the draft when the code allow add mass like bellow
// var draft_system = (LL[0][0]+rho*length*breadth*draft*Cb)/(rho*length*breadth*Cb); // draft vessel + body (m)
// var center_reference = -draft;
this.states.continuous.motion = {};
var motion = this.states.continuous.motion;
[motion.surge, motion.sway, motion.heave, motion.roll, motion.pitch, motion.yaw, motion.VSurge, motion.VSway,
motion.VHeave, motion.VRoll, motion.VPitch, motion.VYaw, motion.EX, motion.EY, motion.EZ
] = Ini;
this.moveShip = function(tprev, dt) {
if (ocean.waves["0"].A) {
waveForce = this.WaveForce(rho, tprev, a_33);
} else {
B_33 = rho * A_WP * userParameters.C_D;
B_44 = userParameters.B_44;
B_55 = userParameters.B_55;
B_66 = userParameters.B_66;
waveForce = [0, 0, 0, 0, 0, 0]
}
mooringForce = this.InsertMooring(this.ship, this.states, motion, seaDepth, mooring.anchorPoint);
// Inertia
var I_46 = 0; //Small coupled term, was neglected.
var I_44 = Math.pow((0.4 * breadth), 2) * m; // Rolling Moment of Inertia (kgm2) //(1/12)*m*(Math.pow(B,2)+Math.pow(D,2));
var I_55 = Math.pow((0.28 * length), 2) * m; // Pitching Moment of Inertia (kgm2) //(1/12)*m*(Math.pow(L,2)+Math.pow(D,2));
var I_66 = Math.pow((0.28 * length), 2) * m; // Yawing Moment of Inertia (kgm2) //(1/12)*m*(Math.pow(B,2)+Math.pow(L,2));
MM = [
[m, 0, 0, 0, m * (KG - (depth / 2)), 0],
[0, m, 0, -m * (KG - (depth / 2)), 0, 0],
[0, 0, m, 0, 0, 0],
[0, -m * (KG - (depth / 2)), 0, I_44, 0, 0],
[m * (KG - (depth / 2)), 0, 0, 0, I_55, 0],
[0, 0, 0, 0, 0, I_66]
]; // Vessel's inertia tensor
RG_system = [MM[5][1] / m, MM[3][2] / m, MM[4][0] / m]; // System's centre of gravity
// Initial Stability
var Delta = m * g; // Vessel Displacement (N)
var KB = draft / 2; // Centre of Buoyancy Height (m)
var C_33 = rho * g * A_WP; // Heave Restoring Coeff. (N/m)
// var C_44a = Delta*(KB-KG); // First Part of Roll Restoring Coeff. (Nm)
var C_44a = Delta * (KB - (RG_system[2] + draft / 2)); // First Part of Roll Restoring Coeff. (Nm) //KG calcluated after calculating masses @ferrari212
var C_44b = (1 / 12) * rho * g * Math.pow(breadth, 3) * length; // Second Part of Roll Restoring Coeff. (Nm)
var C_44 = C_44a + C_44b; // Total Roll Restoring Coeff. (Nm)
// var C_55a = Delta*(KB-KG); // First Part of Pitch Restoring Coeff. (Nm)
var C_55a = Delta * (KB - (RG_system[2] + draft / 2)); // First Part of Pitch Restoring Coeff. (Nm) //KG calcluated after calculating masses @ferrari212
var C_55b = (1 / 12) * rho * g * Math.pow(length, 3) * breadth; // Second Part of Pitch Restoring Coeff. (Nm)
var C_55 = C_55a + C_55b; // Total Pitch Restoring Coeff. (Nm)
var C_35 = 0; // Heave-Pitch Coupled Restoring Coeff. (N) // aproximmation to zero is valid if the water plane is symmetrical in relation to the mid section
var C_53 = 0; // Pitch-Heave Coupled Restoring Coeff. (N) // aproximmation to zero is valid if the water plane is symmetrical in relation to the mid section
// Damping
var B_11 = rho * breadth * draft * userParameters.C_D; // Linear Sway Dampig Coeff. (kg/s)
var B_22 = rho * length * draft * userParameters.C_D; // Linear Sway Dampig Coeff. (kg/s)
// var B_33 = rho*A_WP*userParameters.C_D; // Linear Heave Dampig Coeff. (kg/s)
var ADD_33 = a_33 * length;
var ADD_44 = 0.15 * I_44; // Equation 6.61a
var ADD_55 = a_33 * Math.pow(length, 3) / 12;
ADD_mass = [
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, ADD_33, 0, 0, 0],
[0, 0, 0, ADD_44, 0, 0],
[0, 0, 0, 0, ADD_55, 0],
[0, 0, 0, 0, 0, 0]
]; // Vessel's added mass
AA = numeric.add(MM, ADD_mass); // System's total inertia tensor
// Inserting the critical damping in roll (6.66) considering sigma = 10
// B_44 += 10*2*Math.sqrt(C_44*(I_44+ADD_44));
//Dynamic Equations
BB = [
[B_11, 0, 0, 0, 0, 0],
[0, B_22, 0, 0, 0, 0],
[0, 0, B_33, 0, 0, 0],
[0, 0, 0, B_44, 0, 0],
[0, 0, 0, 0, B_55, 0],
[0, 0, 0, 0, 0, B_66]
]; // Damping Matrix
CC = [
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, C_33, 0, -C_35, 0],
[0, 0, 0, C_44, 0, 0],
[0, 0, C_53, 0, C_55, 0],
[0, 0, 0, 0, 0, 0]
]; // Restoring Matrix
// console.log("Natural Period Vibration: Heave %.2f; Roll %.2f; Pitch %.2f;", (2*Math.PI)*Math.pow(AA[2][2]/C_33,0.5), (2*Math.PI)*Math.pow(AA[3][3]/C_44,0.5), (2*Math.PI)*Math.pow(AA[4][4]/C_55,0.5));
// Rugen Kutta
// dy(1:6) = World fixed velocity
// dy(7:12) = Body fixed acceleration
// dy(13:15)= Euler angle rate
// y(1:6) = World fixed motion
// y(7:12) = Body fixed velocity
// y(13:15) = Euler angle
// J1 = Body 2 world Jacobian
// J2 = Body 2 Euler angle rate Jacobian
var y = [motion.surge, motion.sway, motion.heave - this.states.discrete.FloatingCondition.state.T,
motion.roll, motion.pitch, motion.yaw, motion.VSurge, motion.VSway, motion.VHeave, motion.VRoll,
motion.VPitch, motion.VYaw, motion.EX, motion.EY, motion.EZ
];
var sol = numeric.dopri(tprev, tprev + dt, y, this.RungeKuttaSolver, 1e-8, 10000).at(tprev + dt);
// Equalizing the solution
[motion.surge, motion.sway, motion.heave, motion.roll, motion.pitch, motion.yaw, motion.VSurge,
motion.VSway, motion.VHeave, motion.VRoll, motion.VPitch, motion.VYaw, motion.EX, motion.EY, motion.EZ
] = sol;
motion.heave += this.states.discrete.FloatingCondition.state.T;
};
// This formulation is based on the book Wave-Induced Loads and Ship Motions, LArs Bergdahl
// chapter 6 - motion for smal body approximation
//@ferrari212
this.WaveForce = function(rho, t, a_33) {
var a = ocean.waves["0"].A; //Amplitude of Movement
var costh = ocean.waves["0"].costh; //Cos of Wave Directions
var sinth = ocean.waves["0"].sinth; //Sen of Wave Directions
// projection of trajectory for calculation of phase difference
var projMag = ship3D.position.x * costh + ship3D.position.y * sinth; // magnitude of projection
var omega = wavCre.waveDef.waveFreq; // wave frequencie
var k = 2 * Math.PI / ocean.waves["0"].L; // wave number
var phase = omega * t - ocean.waves["0"].phi - k * projMag;
// WARNING:
//if (breadth > ocean.waves["0"].L / 4) {
// console.warn("Small body approximation denied Breadth > Lambda / 4.");
//}
//if (length / breadth < 5) {
// console.warn("Slender ship condition denied Length/Breadth < 5.");
//}
// Heave Forces Calculations
var A = 2 * Math.sin(Math.pow(omega, 2) * breadth / (2 * g)) * Math.exp(-Math.pow(omega, 2) * draft / g);
var alpha = 1; // Speed equals to zero therefore fr is zero
var b_33 = rho * Math.pow(g * A, 2) / (Math.pow(omega * alpha, 3));
B_33 = b_33 * length;
B_55 = b_33 * Math.pow(length, 3) / 12;
var complex1, complex2, integral;
complex1 = new numeric.T(rho * g * breadth - Math.pow(omega, 2) * a_33, -omega * b_33);
complex2 = new numeric.T(Math.cos(omega * t), -Math.sin(omega * t));
integral = (Math.abs(costh) > 0.01) ? 2 * Math.sin(k * (costh) * length / 2) / (k * costh) : length;
// Equation (6.39)
var FW_33 = complex1.mul(complex2).dot(a * Math.exp(-k * draft) * integral).x;
// Roll Forces Calculations
var ra, rb, rd, r;
r = breadth / draft;
ra = -3.94 * r + 13.69;
rb = -2.12 * r - 1.89;
rd = 1.16 * r - 7.97;
//if (r < 1 || r > 3) {
// console.warn('This B/T ratio is not supported by the method: %f', r);
//}
// Equation (6.62)
var b_44 = rho * draft * Math.pow(breadth, 3) * Math.pow(2 * g / breadth, 0.5) * ra * Math.exp(rb * Math.pow(omega, -1.3)) * Math.pow(omega, rd);
B_44 = b_44 * length;
// Equation (6.68)
if (Math.abs(costh) > 0.01) {
var FW_44 = complex2.dot(a * Math.pow(rho * g * g * b_44 / omega, 0.5) * 2 * sinth * Math.sin(k * costh * length / 2) / (k * costh)).x;
} else {
var FW_44 = complex2.dot(a * Math.pow(rho * g * g * b_44 / omega, 0.5) * length * sinth).x;
}
// Equation (6.52)
complex1 = new numeric.T(0, 2 * (Math.sin(k * costh * length / 2) - k * costh * length / 2 * Math.cos(k * costh * length / 2)) / Math.pow(k * costh, 2));
var complex3 = new numeric.T(-a * Math.exp(-k * draft) * (rho * g * breadth - omega * omega * a_33, -a * Math.exp(-k * draft) * (-omega * b_33)));
var FW_55 = complex1.mul(complex2).mul(complex3).x;
var FW = [0, 0, FW_33, FW_44, FW_55, 0];
return FW;
}
this.RungeKuttaSolver = function(t, y) {
var J1 = Euler2J1(y.slice(3, 6));
var J2 = Euler2J2(y.slice(3, 6));
var J11 = numeric.rep([6, 6], 0);
for (i = 0; i < 3; i++) {
for (f = 0; f < 3; f++) {
J11[i][f] = J1[i][f];
J11[3 + i][3 + f] = J2[i][f];
}
}
var g_components = numeric.dot(Smtrx(numeric.dot(J1, RG_system)), [0, 0, g]);
var gforce = [0, 0, m * g, m * g_components[0], m * g_components[1], m * g_components[2]];
var dy = numeric.rep([15], 0); // 6 Positions & 6 Velocities & 3 Euler Angles
var b_velocities = y.slice(6, 12);
var w_velocities = numeric.dot(J11, b_velocities);
for (f = 0; f < 6; f++) {
dy[f] = w_velocities[f];
}
// console.log(mooringForce);
var linear_Solve = numeric.solve(AA, numeric.add(numeric.dot(numeric.transpose(J11), numeric.add(waveForce, mooringForce)), numeric.neg(numeric.dot(Coriolis(MM, ADD_mass, y.slice(6, 12)), y.slice(6, 12))), numeric.neg(numeric.dot(BB, y.slice(6, 12))), numeric.neg(numeric.dot(numeric.dot(numeric.transpose(J11), CC), y.slice(0, 6))), numeric.neg(numeric.dot(numeric.transpose(J11), gforce))));
for (f = 6; f < 12; f++) {
dy[f] = linear_Solve[f - 6];
}
var b_angular_velocities = y.slice(9, 12);
var euler_angle_rate = numeric.dot(J2, b_angular_velocities);
for (f = 12; f < 15; f++) {
dy[f] = euler_angle_rate[f - 12];
}
return dy;
}
var Coriolis = function(M, AM, vel) {
var c = numeric.dot(M, vel);
var C = numeric.rep([6, 6], 0);
var CA = numeric.rep([6, 6], 0);
// Creanting Inercia Matrix
var I0 = numeric.diag([M[3][3], M[4][4], M[5][5]]);
// Calculating Coriolis by Thor Eq. (8)
var S1 = Smtrx([-m * vel[0], -m * vel[1], -m * vel[2]]);
var S2 = numeric.dot(Smtrx([m * vel[3], m * vel[4], m * vel[5]]), Smtrx(RG_system));
var SI = numeric.neg(Smtrx(numeric.dot(I0, [vel[3], vel[4], vel[5]])));
// Coriolis Added Mass by Thor Eq. (40)
var SA = numeric.dot(AM, vel);
var CAQuad2 = Smtrx(SA.slice(0, 3));
var CAQuad1 = numeric.rep([3, 3], 0);
var CAQuad3 = CAQuad2;
var CAQuad4 = Smtrx(SA.slice(3, 6));
for (i = 0; i < 3; i++) {
for (f = 0; f < 3; f++) {
C[i][3 + f] = S1[i][f] - S2[i][f];
C[3 + i][f] = S1[i][f] + S2[i][f];
C[3 + i][3 + f] = S1[i][f];
CA[i][f] = CAQuad1[i][f];
CA[i][3 + f] = CAQuad2[i][f];
CA[3 + i][f] = CAQuad3[i][f];
CA[3 + i][3 + f] = CAQuad4[i][f];
}
}
return numeric.add(C, CA);
}
var Euler2J1 = function(Eang) {
Eang[0] = -Eang[0];
Eang[2] = -Eang[2];
rx = [
[1, 0, 0],
[0, Math.cos(Eang[0]), -Math.sin(Eang[0])],
[0, Math.sin(Eang[0]), Math.cos(Eang[0])]
];
ry = [
[Math.cos(Eang[1]), 0, Math.sin(Eang[1])],
[0, 1, 0],
[-Math.sin(Eang[1]), 0, Math.cos(Eang[1])]
];
rz = [
[Math.cos(Eang[2]), -Math.sin(Eang[2]), 0],
[Math.sin(Eang[2]), Math.cos(Eang[2]), 0],
[0, 0, 1]
];
J1 = numeric.dot(numeric.dot(rz, ry), rx);
return J1;
}
var Euler2J2 = function(Eang) {
Eang[0] = -Eang[0];
Eang[2] = -Eang[2];
J2 = [
[1, Math.sin(Eang[0]) * Math.tan(Eang[1]), Math.cos(Eang[0]) * Math.tan(Eang[1])],
[0, Math.cos(Eang[0]), -Math.sin(Eang[0])],
[0, Math.sin(Eang[0]) / Math.cos(Eang[1]), Math.cos(Eang[0]) / Math.cos(Eang[1])]
];
return J2
}
// Returns the skew-symetrical of the matrix
var Smtrx = function(vec3) {
var m = [
[0, -vec3[2], vec3[1]],
[vec3[2], 0, -vec3[0]],
[-vec3[1], vec3[0], 0]
];
return m;
}
this.InsertMooring = function(ship, states, motion, anchorPoint) {
var J = Euler2J1([motion.roll, motion.pitch, motion.yaw]);
// Add the first four corner mooring lines plus n pairs of extra lines
var pos = [];
for (var i = 0; i < (4 + mooring.numberOfMooringPerpendicular * 2 + mooring.numberOfMooringLongitudinal*2); i++) {
pos[i] = numeric.dot(J, mooring.mooringPointOnShip[i])
}
// Variables Inserting
var xs; // Mooring suspended line (m)
var aPosible = []; // Guesses necessary for solving Eq. (m)
var a = []; // Guesses necessary for solving Eq. (m)
var horizontalForce = []; // Horizontal Force on the ship (kgf)
var verticalForce = []; // Vertical Force on the ship (kgf)
var FM = numeric.rep([6], 0); // Horizontal forces and Moments (m)
// Anchoring point in seabed
var anchorAngle = []; // Cos and sin of horzontal angle (-)
var anchorPointOnShip = []; // Line geometry (global) (m, m, m)
var anchorDist = []; // Max. horizontal distance of line (m)
var mooringLengthSuspended; // Suspende line length (m)
var anchorPoint = [];
var resultingForce = [];
for (var i = 0; i < pos.length; i++) {
baseangle = 0;
lwl = floatingStates.LWL/2 + floatingStates.trim;
bwl = floatingStates.BWL/2
// First, add the mooring lines on each of the four corners
// Mooring lines at the stern
if (i==3 || i==2) {
baseangle = Math.PI;
lwl = -floatingStates.LWL/2 + floatingStates.trim;
};
// If mooring lines at portside (negative)
if (i==1 || i==2) {
bwl = -floatingStates.BWL/2
};
// Mooring line on seabed [m, m, m]
anchorPoint[i] = [
userParameters.radialDistance * Math.cos((baseangle) + Math.pow((-1), i) * (mooring.mooringAngle * Math.PI) / 180) + lwl,
-userParameters.seaDepth,
userParameters.radialDistance * Math.sin((baseangle) + Math.pow((-1), i) * (mooring.mooringAngle * Math.PI) / 180) + bwl,
];
// Second, add the mooring line board side
if (mooring.numberOfMooringPerpendicular > 0) {
if (i == 4 || i == 5) {
anchorPoint[i][0] = floatingStates.LWL * mooring.percentageLwlB1 / 200 + userParameters.radialDistanceB * Math.sin(mooring.mooringAngle2 * Math.PI / 180)
anchorPoint[i][2] = userParameters.radialDistanceB * Math.pow((-1), i+1) + bwl
};
if (mooring.numberOfMooringPerpendicular == 2 || mooring.numberOfMooringPerpendicular == 3) {
if (i == 6 || i == 7) {
anchorPoint[i][0] = floatingStates.LWL * mooring.percentageLwlB2 / 200 + userParameters.radialDistanceB * Math.sin(mooring.mooringAngle3 * Math.PI / 180)
anchorPoint[i][2] = userParameters.radialDistanceB * Math.pow((-1), i+1) + bwl
};
};
if (mooring.numberOfMooringPerpendicular == 3) {
if (i == 8 || i == 9) {
anchorPoint[i][0] = floatingStates.LWL * mooring.percentageLwlB3 / 200 + userParameters.radialDistanceB * Math.sin(mooring.mooringAngle4 * Math.PI / 180)
anchorPoint[i][2] = userParameters.radialDistanceB * Math.pow((-1), i+1) + bwl
};
};
};
// Last, mooring line stern and bow
var start = 4 + mooring.numberOfMooringPerpendicular*2;
if (mooring.numberOfMooringLongitudinal > 0) {
if ( i == start || i == start+1) {
anchorPoint[i][0] = (floatingStates.LWL/2 + userParameters.radialDistanceC) * Math.pow((-1), i)
anchorPoint[i][2] = floatingStates.BWL * mooring.percentageBwlB1 / 200 * userParameters.radialDistanceB * Math.sin(mooring.mooringAngle2C * Math.PI / 180)
};
if (mooring.numberOfMooringLongitudinal == 2) {
if ( i == start+2 || i == start+3) {
anchorPoint[i][0] = (floatingStates.LWL/2 + userParameters.radialDistanceC) * Math.pow((-1), i)
anchorPoint[i][2] = floatingStates.BWL * mooring.percentageBwlB2 / 200 * userParameters.radialDistanceC * Math.sin(-mooring.mooringAngle2C * Math.PI / 180)
};
};
};
// Find solutions for each mooring line
hangedMooring[i] = []
anchorPointOnShip[i] = [pos[i][0] + motion.surge, pos[i][2] + motion.heave, pos[i][1] - motion.sway];
anchorDist[i] = Math.pow(Math.pow(anchorPoint[i][0] - anchorPointOnShip[i][0], 2) + Math.pow(anchorPoint[i][1] - anchorPointOnShip[i][1], 2) + Math.pow(anchorPoint[i][2] - anchorPointOnShip[i][2], 2), 0.5);
anchorAngle[i] = [(anchorPoint[i][0] - anchorPointOnShip[i][0]) / anchorDist[i], (anchorPoint[i][2] - anchorPointOnShip[i][2]) / anchorDist[i]];
if (i < 4) {
var as = numeric.linspace(0.01, mooring.anchorLength, 100);
for (var n = 0; n < as.length; n++) {
aPosible[n] = mooring.anchorLength - anchorDist[i] - as[n] * Math.sinh(Math.acosh(((anchorPointOnShip[i][1] + userParameters.seaDepth) / as[n]) + 1)) + as[n] * (Math.acosh(((anchorPointOnShip[i][1] + userParameters.seaDepth) / as[n]) + 1));
}
} else if (i > 3 && i < start +1) {
var as = numeric.linspace(0.01, mooring.anchorLengthB, 100);
for (var n = 0; n < as.length; n++) {
aPosible[n] = mooring.anchorLengthB - anchorDist[i] - as[n] * Math.sinh(Math.acosh(((anchorPointOnShip[i][1] + userParameters.seaDepth) / as[n]) + 1)) + as[n] * (Math.acosh(((anchorPointOnShip[i][1] + userParameters.seaDepth) / as[n]) + 1));
}
} else if (i > start) {
var as = numeric.linspace(0.01, mooring.anchorLengthC, 100);
for (var n = 0; n < as.length; n++) {
aPosible[n] = mooring.anchorLengthC - anchorDist[i] - as[n] * Math.sinh(Math.acosh(((anchorPointOnShip[i][1] + userParameters.seaDepth) / as[n]) + 1)) + as[n] * (Math.acosh(((anchorPointOnShip[i][1] + userParameters.seaDepth) / as[n]) + 1));
}
};
a[i] = numeric.spline(as, aPosible).roots();
horizontalForce[i] = a[i] * userParameters.density;
mooringLengthSuspended = Math.pow((anchorPointOnShip[i][1] + userParameters.seaDepth) * ((anchorPointOnShip[i][1] + userParameters.seaDepth) + 2 * a[i]), 0.5);
xs = a[i] * Math.asinh(mooringLengthSuspended / a[i]); // Horizontal distance of the ship (m)
verticalForce[i] = userParameters.density * mooringLengthSuspended;
const dx = xs / 50; // Distance variated (m)
var m = 0;
for (var d = xs; d >= 0; d -= dx) {
hangedMooring[i][m] = [anchorPointOnShip[i][0] + (xs - d) * (anchorAngle[i][0]),
a[i] * (Math.cosh(d / a[i]) - 1) - userParameters.seaDepth,
anchorPointOnShip[i][2] + (xs - d) * (anchorAngle[i][1])
];
m++;
};
// Force component at this specific moment
Fx = g * horizontalForce[i] * (anchorAngle[i][0]);
Fy = g * horizontalForce[i] * (anchorAngle[i][1]);
Fz = g * verticalForce[i];
resultingForce[i] = Math.pow(Math.pow(Fx, 2) + Math.pow(Fy, 2) + Math.pow(Fz, 2), 0.5)/1000; // Resulting Force in kN
// Removes the mooring line in case it breaks geometrically
if (hangedMooring[i].length == 0) {
scene.remove(mooring.anchorLineGeometry[i])
resultingForce[i] = 0
};
// Approximation small angles of yaw
FM[0] += Fx;
FM[1] -= Fy;
FM[2] -= Fz;
FM[3] += (g * horizontalForce[i] * (anchorAngle[i][1])) * (pos[i][2] + depth - draft / 2) + (g * verticalForce[i]) * pos[i][1];
FM[4] += g * horizontalForce[i] * (anchorAngle[i][0]) * (pos[i][2] + depth - draft / 2) + g * verticalForce[i] * pos[i][0];
FM[5] += (-g * horizontalForce[i] * (anchorAngle[i][1])) * (pos[i][0]) + g * horizontalForce[i] * (anchorAngle[i][0]) * (pos[i][1]);
// Turn mooring names to red color when they fail
if (i==0) {
if (resultingForce[0] > mooring.breakingLoad) {
mooring.mooringStatus.mooringNE = 'Fail';
var change = document.getElementsByTagName("LI").item(37);
change.style.color = '#FF0000';
var change2 = change.querySelector(".c");
var change3 = change2.querySelector("input");
change3.style.color = '#FF0000';
}
}
if (i==1) {
if (resultingForce[1] > mooring.breakingLoad) {
mooring.mooringStatus.mooringNW = 'Fail';
var change = document.getElementsByTagName("LI").item(38);
change.style.color = '#FF0000';
var change2 = change.querySelector(".c");
var change3 = change2.querySelector("input");
change3.style.color = '#FF0000';
}
}
if (i==2) {
if (resultingForce[2] > mooring.breakingLoad) {
mooring.mooringStatus.mooringSW = 'Fail';
var change = document.getElementsByTagName("LI").item(40);
change.style.color = '#FF0000';
var change2 = change.querySelector(".c");
var change3 = change2.querySelector("input");
change3.style.color = '#FF0000';
}
}
if (i==3) {
if (resultingForce[3] > mooring.breakingLoad) {
mooring.mooringStatus.mooringSE = 'Fail';
var change = document.getElementsByTagName("LI").item(39);
change.style.color = '#FF0000';
var change2 = change.querySelector(".c");
var change3 = change2.querySelector("input");
change3.style.color = '#FF0000';
}
}
};
mooring.conditionMooring = [mooring.mooringStatus.mooringNE, mooring.mooringStatus.mooringNW, mooring.mooringStatus.mooringSW, mooring.mooringStatus.mooringSE];
window.feedTension = function(callback) {
var tick = {};
if (mooring.conditionMooring[0] != "Fail") {
tick.plot0 = resultingForce[0];
} else {
tick.plot0 = 0
}
if (mooring.conditionMooring[1] != "Fail") {
tick.plot1 = resultingForce[1];
} else {
tick.plot1 = 0
}
if (mooring.conditionMooring[2] != "Fail") {
tick.plot3 = resultingForce[2];
} else {
tick.plot3 = 0
}
if (mooring.conditionMooring[3] != "Fail") {
tick.plot2 = resultingForce[3];
} else {
tick.plot2 = 0
};
tick.plot4 = resultingForce[4];
tick.plot5 = resultingForce[6];
tick.plot6 = resultingForce[8];
callback(JSON.stringify(tick));
};
window.feedMotion = function(callback) {
var tick = {};
tick.plot0 = motion.heave;
tick.plot1 = motion.sway;
tick.plot2 = motion.surge;
callback(JSON.stringify(tick));
};
window.feedMotionRoll = function(callback) {
var tick = {};
tick.plot0 = motion.roll * 180 / Math.PI;
tick.plot1 = motion.pitch * 180 / Math.PI;
tick.plot2 = motion.yaw * 180 / Math.PI;
callback(JSON.stringify(tick));
};
var myDashboardMooring = {
"graphset":[
{//---------- mooring line tension plot-----------//
"type":"line",
"plotarea":{
"adjust-layout":true
},
"height":"100%",
"width":"33%",
"x":"0%",
"y":"0%",
"plot":{
"aspect":"spline",
"marker":{"visible":true},
},
"series":[{
"values":[0],
"lineColor": "#808080",
"text": "Mooring NE",
"marker" :{
"background-color":"#808080",
},
}, {
"values":[0],
"lineColor": "0xff0000",
"text": "Mooring NW",
"marker" :{
"background-color":"0xff0000",
},
}, {
"values":[0],
"lineColor": "0x0066ff",
"text": "Mooring SE",
"marker" :{
"background-color":"0x0066ff",
},
}, {
"values":[0],
"lineColor": "0x33cc33",
"text": "Mooring SW",
"marker" :{
"background-color":"0x33cc33",
},
}, {
"values":[0],
"lineColor": "0x762a83",
"text": "Side",
"marker" :{
"background-color":"0x762a83",
},
}, {
"values":[0],
"lineColor": "0xfdb863",
"text": "Side",
"marker" :{
"background-color":"0xfdb863",
},
}, {
"values":[0],
"lineColor": "0x80cdc1",
"text": "Side",
"marker" :{
"background-color":"0x80cdc1",
},
},
],
"refresh":{
"type":"feed",
"transport":"js",
"url":"feedTension()",
"method":"pull",
"interval":500,
"adjust-scale":true
},
scaleY: {
label: {
text: 'Tension',
fontStyle: 'normal',
fontWeight: 'normal',
},
},
title:{
text:"Mooring Line Tension",
marginBottom: "0",
fontFamily:"Helvetica",
fontWeight:"none",
fontSize: 12
},
plotarea: {
"margin": "20% 10% 15% 10%",
},
legend: {
"layout": "float",
"background-color": "none",
"border-width": 0,
"shadow": 0,
"text-align":"middle",
"offsetY": 25,
"align": "center",
"item": {
"font-color": "#black",
"font-size": "10px"
}
},
},
{//---------- ship motion heave -----------//
"type":"line",
"height":"100%",
"width":"33%",
"x":"33%",
"y":"0%",
"plot":{
"aspect":"spline",
"marker":{"visible":true},
},
"series":[{
"values":[0],
"text": "Heave [meters]"
}, {
"values":[0],
"text": "Sway [meters]"
}, {
"values":[0],
"text": "Surge [meters]"
}],
"refresh":{
"type":"feed",
"transport":"js",
"url":"feedMotion()",
"method":"pull",
"interval":500,
"adjust-scale":true
},
title:{
text:"Ship Motion",
marginBottom: "0",
fontFamily:"Helvetica",
fontWeight:"none",
fontSize: 12
},
plotarea: {
"margin": "20% 10% 15% 10%",
},
legend: {
"layout": "float",
"background-color": "none",
"border-width": 0,
"shadow": 0,
"text-align":"middle",
"offsetY": 25,
"align": "center",
"item": {
"font-color": "#black",
"font-size": "10px"
}
},
},
{//---------- ship motion pitch roll -----------//
"type":"line",
"height":"100%",
"width":"33%",
"x":"66%",
"y":"0%",
"plot":{
"aspect":"spline",
"marker":{"visible":true},
},
"series":[{
"values":[0],
"text": "Roll [deg]"
}, {
"values":[0],
"text": "Pitch [deg]"
}, {
"values":[0],
"text": "Yaw [deg]"
}],
"refresh":{
"type":"feed",
"transport":"js",
"url":"feedMotionRoll()",
"method":"pull",
"interval":500,
"adjust-scale":true
},
title:{
text:"Ship Motion",
marginBottom: "0",
fontFamily:"Helvetica",
fontWeight:"none",
fontSize: 12
},
plotarea: {
"margin": "20% 10% 15% 10%",
},
legend: {
"layout": "float",
"background-color": "none",
"border-width": 0,
"shadow": 0,
"text-align":"middle",
"offsetY": 25,
"align": "center",
"item": {
"font-color": "#black",
"font-size": "10px"
}
},
},
]
};
window.onload=function(){
zingchart.render({
id:'plotMooringTension',
height:"100%",
width:"100%",
data: myDashboardMooring,
});
};
for (var i = 0; i < pos.length; i++) {
if (mooring.conditionMooring[i] == "Fail") {
scene.remove(mooring.anchorLineGeometry[i])
}
if (mooring.anchorLineGeometry[i].geometry.vertices[0] == undefined) {
mooring.anchorLineGeometry[i].geometry.vertices[0] = [];
mooring.anchorLineGeometry[i].geometry.vertices[0].push(new THREE.Vector3(anchorPointOnShip[i][0], anchorPointOnShip[i][1], anchorPointOnShip[i][2]));
} else {
mooring.anchorLineGeometry[i].geometry.vertices[0].x = anchorPointOnShip[i][0];
mooring.anchorLineGeometry[i].geometry.vertices[0].y = anchorPointOnShip[i][1];
mooring.anchorLineGeometry[i].geometry.vertices[0].z = anchorPointOnShip[i][2];
}
for (var m = 0; m < hangedMooring[i].length; m++) {
if (mooring.anchorLineGeometry[i].geometry.vertices[m + 1] == undefined) {
mooring.anchorLineGeometry[i].geometry.vertices[m + 1] = [];
mooring.anchorLineGeometry[i].geometry.vertices[m + 1].push(new THREE.Vector3(hangedMooring[i][m][0], hangedMooring[i][m][1], hangedMooring[i][m][2]));
} else {
mooring.anchorLineGeometry[i].geometry.vertices[m + 1].x = hangedMooring[i][m][0];
mooring.anchorLineGeometry[i].geometry.vertices[m + 1].y = hangedMooring[i][m][1];
mooring.anchorLineGeometry[i].geometry.vertices[m + 1].z = hangedMooring[i][m][2];
}
}
if (mooring.anchorLineGeometry[i].geometry.vertices[m] == undefined) {
mooring.anchorLineGeometry[i].geometry.vertices[m] = [];
mooring.anchorLineGeometry[i].geometry.vertices[m].push(new THREE.Vector3(anchorPoint[i][0], anchorPoint[i][1], anchorPoint[i][2]));
} else {
mooring.anchorLineGeometry[i].geometry.vertices[m].x = anchorPoint[i][0];
mooring.anchorLineGeometry[i].geometry.vertices[m].y = anchorPoint[i][1];
mooring.anchorLineGeometry[i].geometry.vertices[m].z = anchorPoint[i][2];
}
mooring.anchorLineGeometry[i].geometry.verticesNeedUpdate = true;
}
return FM;
}
};