forked from noahbagz/ShipD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHullParameterization.py
More file actions
2236 lines (1498 loc) · 87.1 KB
/
Copy pathHullParameterization.py
File metadata and controls
2236 lines (1498 loc) · 87.1 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
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
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 29 11:50:30 2022
@author: shannon
Code Written by Noah Bagazinski
=============================================================================================
The Target of this Script is to Define the functions and parameters to define a ship hull.
This Code is a continuation of Noah Bagazinski's work in ship hull genneration using a
parametric design scheme.
=============================================================================================
The hull parameterization is defined in five chunks:
1) General Hull Form.
This includes metrics such as the beam at the deck, the
hull taper, and the stern taper.
2) The parallel mid body cross section.
This includes parameters for the flare, chine radius, deadrise, and keel radius
3) The Bow Form.
This includes functions that define the bow rise (rake), the profile drift angle with respect to depth,
the profile of rocker at the front of the ship, and the profile of the location where the full breadth
is achieved for a given depth.
4) The Stern Form
This includes functions that define the stern profile, the convergence angle (slope of the ship at the transom), the transom cross section, the profile
of the rocker at the stern of the ship, the profile where the full beadth of the ship is achieved, and the curvature of the hull along the stern.
5) Bulb Forms
Bulb forms slightly modified from the parameterization defined by:
Chrismianto, D. and Kim, D.J., 2014. 'Parametric bulbous bow design using the cubic
Bezier curve and curve-plane intersection method for the minimization of ship resistance
in CFD'. Journal of Marine Science and Technology, 19(4), pp.479-492.
functions include generation of NURBS curves to generate the meshes of the bulbous bow and stern
"""
#import all the goodies:
import numpy as np
# scipy.optimize import fsolve
from matplotlib import pyplot as plt
from stl import mesh
class Hull_Parameterization:
#Define parameters of targethull
def __init__(self, inputs):
'''
inputs is a numpy vector that represents the parameterization of a hull.
the instantiation function generates all of the constants and factors used
in defining the parameterization of the hull.
Most of the inputs are scaled to LOA in some form
'''
self.LOA = inputs[0]
self.Lb = inputs[1] *self.LOA
self.Ls = inputs[2] *self.LOA
self.Bd = inputs[3]/2.0 *self.LOA#half breadth
self.Dd = inputs[4] *self.LOA
self.Bs = inputs[5] *self.Bd #half breadth, fraction of Bd
self.WL = inputs[6] *self.Dd
self.Bc = inputs[7]/2.0 *self.LOA #half breadth
self.Beta = inputs[8]
self.Rc = inputs[9]*self.Bc
self.Rk = inputs[10]*self.Dd
self.BOW = np.zeros((3,))
self.BOW[0] = inputs[11]*0.5*self.Lb/self.Dd**2.0
self.BOW[1] = inputs[12]*0.5*self.Lb/self.Dd
self.BK = np.zeros((2,))
self.BK[1] = inputs[13] *self.Dd #BK_z is an input - BK_x is solved for
self.Kappa_BOW = inputs[14]
self.DELTA_BOW = np.zeros((3,))
self.DELTA_BOW[0] = inputs[15]*0.5*self.Lb/self.Dd**2.0
self.DELTA_BOW[1] = inputs[16]*0.5*self.Lb/self.Dd
self.DRIFT = np.zeros((3,))
self.DRIFT[0] = inputs[17]*60.0/self.Dd**2.0
self.DRIFT[1] = inputs[18]*60.0/self.Dd
self.DRIFT[2] = inputs[19]
self.bit_EP_S = inputs[20]
self.bit_EP_T = inputs[21]
self.TRANS = np.zeros((2,))
self.TRANS[0] = inputs[22]
self.SK = np.zeros((2,))
self.SK[1] = inputs[23]
self.Kappa_STERN = inputs[24]
self.DELTA_STERN = np.zeros((3,))
self.DELTA_STERN[0] = inputs[25]*0.5*self.Ls/self.Dd**2.0
self.DELTA_STERN[1] = inputs[26]*0.5*self.Ls/self.Dd
#self.RY_STERN = np.array(inputs[25:27])
#self.RX_STERN = np.array(inputs[27:29])
self.Beta_trans = inputs[27]
self.Bc_trans = inputs[28]/2.0 *self.LOA # half breadth
self.Rc_trans = inputs[29]*self.Bc_trans
self.Rk_trans = inputs[30]*self.Dd*(1-self.SK[1])
#self.CONVERGE = np.array(inputs[33:36])
self.bit_BB = inputs[31]
self.bit_SB = inputs[32]
self.Lbb = inputs[33]
self.Hbb = inputs[34]
self.Bbb = inputs[35]
self.Lbbm = inputs[36]
self.Rbb = inputs[37]
self.Kappa_SB = inputs[38]
self.Lsb = inputs[39]
self.HSBOA = inputs[40]
self.Hsb = inputs[41]
self.Bsb = inputs[42]
self.Lsbm = inputs[43]
self.Rsb = inputs[44]
#Generate and Check the Forms of the Overall Hull
self.GenGeneralHullform()
#C1 = print(self.GenralHullformConstraints())
self.GenCrossSection()
# C2 = print(self.CrossSectionConstraints())
self.GenBowForm()
#C3 = print(self.BowformConstraints())
self.GenSternForm()
#C4 = print(self.SternFormConstraints())
self.GenBulbForms()
#C5 = print(self.BulbFormConstraints())
'''
=======================================================================
Section 1: General Hull Form
=======================================================================
The General hull form is characterized by 5 characteristics:
0) LOA -> length overall of the vessel in [m] or = 1
1) Lb -> length of the bow taper in [m] or fraction of LOA
2) Ls -> length of the stern taper in [m] or fraction of LOA
3) Bd -> Beam at the top deck of the vessel in [m] or fraction of LOA
4) Dd -> Depth of the vessel at the deck in [m] or fraction of LOA
5) Bs -> Beam at the stern in [m] or fraction of LOA
6) WL -> Waterline depts in [m] or fraction of LOA
Constraints / NOTES to ensure realistic sizing/ shape of a hull:
0) The length of the parallel mid body is equal to LOA-Lb-Ls = Lm
1) Lb + Ls <= LOA
2) Bd is not necessarily the maximum beam of the vessel. It is only the breadth of the
main deck. BOA is calculated in the Section 2: Cross Section
3) 0 <= Bs <= BOA
4) Lb is used to define the limits of the bow taper from the forwardmost point on the
bow rake to the point where the parallel mid-body starts. The profile of the ship
at different waterlines is dependent of the other parameters defined later in the
parameterization.
5) Ls is used to define the limits of the stern taper from the aftmost point on the
stern rake to the point where the parallel mid-body ends. The profile of the ship
at different waterlines is dependent of the other parameters defined later in the
parameterization.
6) WL < Dd
7) All variables are positive or 0
'''
def GenGeneralHullform(self):
'''
This funciton computes the other form factors of the general hullform
that can be calculate from the inputs
'''
self.Lm = self.LOA - self.Ls - self.Lb
def GenralHullformConstraints(self):
'''
This function checks that constraints are satisfied for the hullfrom.
If no constraint violations are found,
'''
C = np.array([-self.LOA + self.Ls+self.Lb,
self.WL - self.Dd])
return C
'''
=======================================================================
Section 2: Cross Section
=======================================================================
The Cross Section is defined by the following inputs:
0) Bd -> The Beam at the Deck in [m] or fraction of LOA
1) Dd -> The Depth of the Deck in [m] or fraction of LOA
2) Bc -> The Beam at the Chine (intersection) in [m] or fraction of LOA
3) Dc -> The Depth of the Chine (intersection) in [m] or fraction of LOA
4) Beta -> The deadrise angle in degrees
5) Rc -> The Chine Radius in [m] or fraction of LOA
6) Rk -> The keel Radius in [m] or fraction of LOA
Constraints/ NOTES to ensure realistic sizing/ shape of a hull:
0) 0 <= Dc < Dd
1) Rc and Rk are agebraically limited to ensure that the radius can exist with the
given Bd,Dd,BcdC, and Beta values.
'''
def GenCrossSection(self):
'''
This function calculates the constants and other form factors that will allow future
analysis of the cross section.
'''
#(y,z) pair for center of keel radius
self.Rk_Center = np.array([-self.Rk*(0.5 - 0.5*np.sign(self.Rk)),
self.Rk*(0.5 + 0.5*np.sign(self.Rk))])
#(y,z) pair for intersection of keel radius and LG line at the transom
self.Rk_LG_int = np.array([self.Rk_Center[0] + self.Rk*np.sin(np.pi*self.Beta/180.0),
self.Rk_Center[1] - self.Rk*np.cos(np.pi*self.Beta/180.0)])
#solve for the lower gunwhale line: A*z + B*y + C = 0
A = np.array([[1.0, 1.0, 1.0],
[self.Rk_LG_int[1], self.Rk_LG_int[0], 1.0],
[-(self.Rk_LG_int[0]-self.Rk_Center[0]), (self.Rk_LG_int[1]-self.Rk_Center[1]), 0.0]])
b = np.array([1.0, 0.0, 0.0])
self.LG = np.linalg.solve(A,b)
del A, b
self.Dc = -(self.LG[1]*self.Bc + self.LG[2])/self.LG[0]
# Upper Gunwhale Line: A*z + B*y + C = 0, where UG = [A,B,C]
A = np.array([[self.Dc, self.Bc, 1.0],
[self.Dd, self.Bd, 1.0],
[1.0, 1.0, 1.0]])
b = np.array([0.0,0.0,1.0])
self.UG = np.linalg.solve(A,b)
del A, b
# Calculate terms for the half beam of the cross section of the transom:
self.Rc_Center = np.zeros((2,)) #(y,z) pair for center of chine radius at the transom
self.Rc_UG_int = np.zeros((2,)) #(y,z) pair for intersection of chine radius and UG line at the transom
self.Rc_LG_int = np.zeros((2,)) #(y,z) pair for intersection of chine radius and LG line at the transom
#make math more readable to solve the chine
A1 = self.UG[0]
B1 = self.UG[1]
theta = np.arctan2(-B1,A1)
if theta < 0.0:
theta = theta + np.pi
beta = self.Beta*np.pi/180.0
A2 = self.LG[0]
B2 = self.LG[1]
A = np.array([[B1, A1, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, B2, A2, 0.0, 0.0],
[1.0, 0.0, 0.0, 0.0, -1.0, 0.0],
[0.0, -1.0, 0.0, 0.0, 0.0, 1.0],
[0.0, 0.0, 1.0, 0.0, -1.0, 0.0],
[0.0, 0.0, 0.0, -1.0, 0.0, 1.0]])
b = np.array([-self.UG[2],
-self.LG[2],
self.Rc*np.sin(theta),
self.Rc*np.cos(theta),
self.Rc*np.sin(beta),
self.Rc*np.cos(beta)])
C = np.linalg.solve(A,b)
self.Rc_UG_int = C[0:2]
self.Rc_LG_int = C[2:4]
self.Rc_Center = C[4:6]
def CrossSectionConstraints(self):
C = [-self.Rc_UG_int[1] + self.Dc,
-self.Rc,
-self.Bc,
-self.Dc,
self.Rc_LG_int[0] - self.Bc,
self.Rk_LG_int[0] - self.Rc_LG_int[0],
0.00000001 -np.abs(self.Rk)]
return C
def halfBeam_MidBody(self, z):
# This funtion calculates the half beam of the cross section at a given height, z
# If 0 > z or Dd < z, then the function returns -1 as an error
if z < 0.0 or z > self.Dd:
return -1
elif z >= 0.0 and z < self.Rk_LG_int[1]:
return np.sign(self.Rk)*np.sqrt((self.Rk**2) - (z-self.Rk_Center[1])**2) + self.Rk_Center[0]
elif z >= self.Rk_LG_int[1] and z < self.Rc_LG_int[1]:
return -(self.LG[0] * z + self.LG[2])/self.LG[1]
elif z >= self.Rc_LG_int[1] and z < self.Rc_UG_int[1]:
return np.sqrt((self.Rc**2) - (z-self.Rc_Center[1])**2) + self.Rc_Center[0]
else:
return -(self.UG[0] * z + self.UG[2])/self.UG[1]
def plot_MidBody_CrossSection(self):
# Plot intersection points in blue
# Plot chine pt in green
# Plot Center of Rc and Rk in red
# half Beam(z) in black
z = np.linspace(0.0, self.Dd, num = 200)
y = np.zeros((200,))
for i in range(0,len(z)):
y[i] = self.halfBeam_MidBody(z[i])
fig2, ax2 = plt.subplots()
ax2.axis('equal')
#plt.axis([0,10,0,10])
ax2.plot([self.Bd, self.Rc_UG_int[0], self.Rc_LG_int[0], self.Rk_LG_int[0], 0.0],
[self.Dd, self.Rc_UG_int[1], self.Rc_LG_int[1], self.Rk_LG_int[1], 0.0], 'o', color = 'blue')
ax2.plot([self.Rc_Center[0], self.Rk_Center[0]], [self.Rc_Center[1], self.Rk_Center[1]],'o' ,color = 'red')
ax2.plot([self.Bc], [self.Dc],'o' ,color = 'green')
ax2.plot(y,z,'-', color = 'black', linewidth = 0.75)
'''
=======================================================================
Section 3: Bow Form
=======================================================================
The Bow Form is defined by the following inputs:
0) Dd -> The Depth of the Deck in [m] or fraction of LOA
1) Lb -> The length of the bow taper in [m] or fraction of LOA
2) Abow -> The z^2 term for Bow(z) that defines the profile of the bowrise
3) Bbow -> The z term for Bow(z) that defines the profile of the bowrise
4) BK_z -> The Z Point of the intersection of the Bow rise and keel rise as percentage of Dd
5) Kappa_bow-> The X position where the Keel rise begins. percentage of Lb
6) Adel -> z^2 term for delta(z), the x position where the max Beam is achieved for a given height
7) Bdel -> z term for delta(z), the x position where the max Beam is achieved for a given height
8) Adrft-> z^2 term for drift(z), the drift angle along the bowrise and keel rise
9) Bdrft-> z term for drift(z), the drift angle along the bowrise and keel rise
10) Cdrft-> const term for drift(z), the drift angle along the bowrise and keel rise
These Parameters solve for 4 functions:
0) Bow(z) -> gives the X position of the bow rise in the form Az^2 + Bz + C
1) Keel_BOW(x) -> gives the z height of the keel rise with respect to X in the form A*(X-Kappa_BOW*Lb)^2
2) Delta_BOW(z) -> gives the x position between 0 and Lb where the full breadth is achieved for a given z: A(z/Dd)^2 + B(z/Dd) + C = x/Lb
3) Drift(z) -> gives the drift angle of the bow for a given z: Az^2 + Bz + C
These four functions define the following curve for each z:
halfBeam_Bow(x) = Y(x) = A*x^3 + Bx^2 + Cx + D for all z between 0 and Dd
Since we know two points and the derivatives of those two points
Constraints/ NOTES to ensure realistic sizing/ shape of a hull:
0) Kappa_BOW*Lb < delta(z=0)
1) 0 < drift(z) < 90 for 0 <= z <= Dd (only need to check at z = 0, Dd, and -B/(2*A) if within range of z )
2) 0 <= BK_x < Kappa_BOW*Lb
3) 0 <= BK_z < Dd
4) delta(z) > Bow(z) and Keel(z) for 0 <= z <= Dd -> check z = 0,Dd,BK, Vert (Bow) and Vert (Delta)
'''
def GenBowForm(self):
'''
This funciton computes the other form factors of the Bowform
that can be calculated from the inputs
'''
if self.BOW[0] == 0:
Zv = -1.0
else:
Zv = -self.BOW[1]/(2*self.BOW[0]) #Find Z of vertex of bowrise(z)
C = np.array([self.BOW[0]*self.Dd**2.0 + self.BOW[1]*self.Dd, #Bow rise protrusion at Deck
self.BOW[0]*self.BK[1]**2.0 + self.BOW[1]*self.BK[1], #Bow rise protrusion at Bow-keel intersection
self.BOW[0]*Zv**2.0 + self.BOW[1]*Zv]) #Bowrise protrusio at vertex of bow rise eqn
if (Zv >= self.BK[1]*self.Dd and Zv <= self.Dd):
self.BOW[2] = -np.amin(C) # If the vertex is between the BK intersect and the Deck, then it is included in the min search
else:
self.BOW[2] = -np.amin(C[0:2])
# X Position of BK intersect
self.BK[0] = self.bowrise(self.BK[1])
# Calculate the Keelrise equation: it is of the form X = sqrt(Z/A) + Kappa_Bow*Lb or Z = A(X-K*Lb)**2, where self.Keel = A
self.KEEL_BOW = self.BK[1]/((self.BK[0]-self.Kappa_BOW*self.Lb)**2.0)
#Calculate the C for the Delta equation, where C is the constant such that max(Delta(z)) = 0 between 0 and Dd
if self.DELTA_BOW[0] == 0:
Zv = -1.0
else:
Zv = -self.DELTA_BOW[1]/(2*self.DELTA_BOW[0]) #Find Z of vertex of Delta(z)
C = np.array([self.DELTA_BOW[0]*self.Dd**2.0 + self.DELTA_BOW[1]*self.Dd, #BDelta at Deck
0.0, #As is, Delta(0) = 0
self.DELTA_BOW[0]*Zv**2.0 + self.DELTA_BOW[1]*Zv]) #Bowrise protrusion at vertex of bow rise eqn
if (Zv >= 0.0 and Zv <= self.Dd):
self.DELTA_BOW[2] = -np.amax(C) # If the vertex is between z = 0 and the Deck, then it is included in the search
else:
self.DELTA_BOW[2] = -np.amax(C[0:2])
#The following funcitons return the
def bowrise(self, z):
#returns the x position of the bowrise for a given z for BK_z <= z <= Dd
return self.BOW[0]*z**2.0 + self.BOW[1]*z + self.BOW[2]
def keelrise_bow(self, z):
#returns the x position of the keelrise at the bow for a given z for 0 <= z <= Bk_z
return -np.sqrt(z/self.KEEL_BOW) + self.Kappa_BOW*self.Lb
def delta_bow(self, z):
#returns the x position where the full cross section width is achieved for a given z for 0 <= z <= Dd
return self.Lb + self.DELTA_BOW[0]*z**2.0 + self.DELTA_BOW[1]*z + self.DELTA_BOW[2]
def drift(self, z):
#returns the drift angle in radians
return np.pi*(self.DRIFT[0]*z**2.0 + self.DRIFT[1]*z + self.DRIFT[2])/180.0
def solve_waterline_bow(self,z):
#this function solves for a cubic function: y(half beam) = Ax^3 + Bx^2 + CX + D for the half beam of the profile between the bow/keel rise and delta for a given z for 0 <= z <= Dd
X1 = self.bow_profile(z)
X2 = self.delta_bow(z)
Y2 = self.halfBeam_MidBody(z)
A = np.array([[X1**3.0, X1**2.0, X1, 1.0],
[3.0*X1**2.0, 2*X1, 1.0, 0.0],
[X2**3.0, X2**2.0, X2, 1.0],
[3.0*X2**2.0, 2.0*X2, 1.0, 0.0]])
b = np.array([0.0,
np.tan(self.drift(z)),
Y2,
0.0])
return np.linalg.solve(A,b)
def bow_profile(self, z):
# This assumes that z >= 0 and z <= Dd
if z <= self.BK[1]:
X1 = self.keelrise_bow(z)
else:
X1 = self.bowrise(z)
return X1
def halfBeam_Bow(self, x, PROF):
#returns the halfbeam along the bow taper between the bow/keel rise and delta(z), PROF is the output of solve)waterline_bow(z)
#x is a vector
y = np.zeros((len(x),))
for i in range(0,len(x)):
y[i] = PROF[0]*x[i]**3.0 + PROF[1]*x[i]**2.0 + PROF[2]*x[i] + PROF[3]
return y
def bow_dydx(self, x, PROF):
#returns slope dydx of the bow taper at a height z that is defined by PROF
#x is a vecotr and function returns the vector of dydx
dydx = np.zeros((len(x),))
for i in range(0,len(x)):
dydx[i] = 3.0*PROF[0]*x[i]**2.0 + 2.0*PROF[1]*x[i] + PROF[2]
return dydx
def gen_waterline_bow(self, z, NUM_POINTS = 100, X = [0,1], bit_spaceOrGrid = 1):
'''
This fuction generates a set of points [[X1,Y1] .... [X2,Y2]] that detail the curvature of the bow taper for a given z, for 0 <= z <= Dd
it can either be created as with a number of set of points, or an even spacing based on the global x spacing (better for station plotting)
BOOL_PTS_OR_SPACE controls whether a set number of points will produce the waterline (1) or the spacing vector will(0)
'''
x1 = self.bow_profile(z)
x2 = self.delta_bow(z)
prof = self.solve_waterline_bow(z)
#Set x based on spacing or grid
if bit_spaceOrGrid:
x = np.linspace(x1,x2,NUM_POINTS)
XY = np.zeros((len(x),2))
else:
x = [i for i in X if (i > x1 and i <= x2)]
x = np.concatenate(([x1],x))
XY = np.zeros((len(x),2))
XY[0,:] = [x1, 0.0]
y = self.halfBeam_Bow(x[1:], prof)
XY[1:] = np.transpose([x[1:],y])
return XY
def BowformConstraints(self):
#This fuction returns booleans if the bow constraints are satisfied as detailed above:
#Check that the vertex (Zv) of the drift angle equation satisfies the constraint of the drift angle if
# if it lies within the bounds of 0 and Dd. If drift(z) is a line, or the vertex is outside the bounds,
# Then True is returned
if self.DRIFT[0] == 0.0:
Zv = -1.0
else:
Zv = -self.DRIFT[1]/(2.0*self.DRIFT[0])
if Zv >= 0.0 and Zv <= self.Dd:
vert_drift = [self.drift(Zv) - np.pi/2.0,
-self.drift(Zv)]
else:
vert_drift = [-1,-1]
#Check that Delta_Bow(z) is always greater than the leading edge of the ship (keelrise(z) and bow(z))
#Check at z = 0, vertex of delta(z), vertex of bow(z), BKz, Dd
if self.DELTA_BOW[0] == 0.0:
Zv = -1.0
else:
Zv = -self.DELTA_BOW[1]/ (2.0*self.DELTA_BOW[0])
if Zv >=0.0 and Zv <= self.Dd:
vert_delta_bow = (-self.delta_bow(Zv) + self.bow_profile(Zv))
else:
vert_delta_bow = -1
if self.BOW[0] == 0.0:
Zv = -1.0
else:
Zv = -self.BOW[1]/ (2.0*self.BOW[0])
if Zv >=0.0 and Zv <= self.Dd:
vert_bow = (-self.delta_bow(Zv) + self.bow_profile(Zv))
else:
vert_bow = -1
C = [self.Kappa_BOW*self.Lb - self.delta_bow(0.0),
self.drift(0.0) - np.pi/2.0,
-self.drift(0.0) ,
self.drift(self.Dd) - np.pi/2.0,
-self.drift(self.Dd),
vert_drift[0],
vert_drift[1],
-self.BK[0],
self.BK[0] - self.Kappa_BOW*self.Lb,
-self.BK[1],
self.BK[1] - self.Dd,
-self.delta_bow(self.Dd) + self.bow_profile(self.Dd),
-self.delta_bow(self.BK[1]) + self.BK[0],
vert_delta_bow,
vert_bow]
return C
'''
=======================================================================
Section 4: Stern Form
=======================================================================
The Stern Form is defined by the following inputs:
0) bit_EP_S -> defines whether the stern will be elliptical (1) or parabolic (0) below the SK intersect
1) bit_EP_T -. Defines whether the stern will be elliptical (1) or parabolic (0) abover the SK intersect
2) Bs -> The width of the stern at the deck of the ship in [m] or fraction of LOA
3) Ls -> The length of the stern taper in [m] or fraction of LOA
4) A_trans -> The A term that defines the transom slope X = Az + B
5) SKz -> The Z Point of the intersection of the Stern rise and transom as percentage of Dd
6) Kappa_STERN -> The X position where the Stern rise begins aft of the end of the parallel midbody as a fraction of Ls
7) Adel -> z^2 term for delta_stern(z), the x position where the max Beam is achieved for a given height,
8) Bdel -> z term for delta_stern(z), the x position where the max Beam is achieved for a given height
9) Bc_trans -> The beam of the chine point at the transom in [m] or fraction of LOA
10) Dc_trans -> The depth of the chine point at the transom in [m] or fraction of LOA
11) Rc_trans -> The Chine radius of the chine at the transom in [m] or fraction of LOA
12) Rk_trans -> the keel radius of the chine at the transom in [m] or fraction of LOA
REMOVE THESE FOR NOW
7) A_Ry-> z term for Ry(z), the y-raduis of the ellipse at the stern of the ship
8) B_Ry-> const for Ry(z), the y-raduis of the ellipse at the stern of the ship
9) A_Rx-> z term for Rx(z), the x-raduis of the ellipse at the stern of the ship
10) B_Rx-> const for Rx(z), the x-raduis of the ellipse at the stern of the ship
15) AconvT -> the z^2 term for Converge Angle(z) the tangent angle of the gunwhale at the transom
16) BconvT -> the z term for Converge Angle(z) the tangent angle of the gunwhale at the transom
17) CconvT -> the const term for Converge Angle(z) the tangent angle of the gunwhale at the transom
These Parameters solve for 7 functions:
0) Transom(z) -> gives the X position of the transom in the form Az + B
1) Sternrise(x) -> gives the z height of the stern rise with respect to X in the form A*(X-Kappa*Ls)^2
2) Delta_Stern(z) -> gives the x position between LOA-Ls and LOA where the full breadth is achieved for a given z: A(z)^2 + B(z) + C = X
3) halfBeam_transom(z) -> gives the halfbeam of the transom for z between SKz and Dd
REMOVE THESE FOR BIW
3) Converge(z) -> gives the convergence tangent angle of the gunwhale at the transom for a given z: Az^2 + Bz + C
4) Ry(z) -> gives the y radius of the stern ellipse in the form Ry = Az + B
5) Rx(z) -> gives the x radius of the stern ellipse in the form Rx = Az + B
These four functions define the following curve for each z:
halfBeam_Stern(x) = Y(x) = Parabola + Ellipse for all z between 0 and Dd
Constraints/ NOTES to ensure realistic sizing/ shape of a hull:
0) Lb+Lm + Kappa_Stern*Ls > delta_Stern(z=0)
1) 0 < converge(z) < 90 for 0 <= z <= Dd (only need to check at z = 0, Dd, and -B/(2*A) if within range of z )
2) 0 <= SK_x > Lb+Lm+ Kappa*Ls
3) 0 <= SK_z < Dd
4) delta(z) < Transom(z) and Sternrise(z) for 0 <= z <= Dd
'''
def GenSternForm(self):
# Recalculate SK to be a value instead of a percentage
self.SK[1] = self.SK[1]*self.Dd
# Solve for the B value such that max(Transom(z)) = LOA
if self.TRANS[0] >= 0.0:
self.TRANS[1] = self.LOA - self.TRANS[0]*self.Dd
else:
self.TRANS[1] = self.LOA - self.TRANS[0]*self.SK[1]
#calculate the x value for the SK intersect
self.SK[0] = self.transom(self.SK[1])
# find the constant term in the sternrise equation: z = A(x-Lb+Lm+Ls*Kappa_stern)^2
self.STERNRISE = self.SK[1]/(self.SK[0] - (self.Lb + self.Lm + self.Ls*self.Kappa_STERN))**2.0
#Calculate the C for the Delta_stern equation, where C is the constant such that min(Delta_stern(z)) = 0 for z between 0 and Dd
if self.DELTA_STERN[0] == 0:
Zv = -1.0
else:
Zv = -self.DELTA_STERN[1]/(2*self.DELTA_STERN[0]) #Find Z of vertex of Delta(z)
C = np.array([self.DELTA_STERN[0]*self.Dd**2.0 + self.DELTA_STERN[1]*self.Dd, #Stern Delta at Deck
0.0, #As is, Delta_Stern(0) = 0
self.DELTA_STERN[0]*Zv**2.0 + self.DELTA_STERN[1]*Zv]) #vertex of Delta_STERN equation
if (Zv >= 0.0 and Zv <= self.Dd):
self.DELTA_STERN[2] = -np.amin(C) # If the vertex is between z = 0 and the Deck, then it is included in the search
else:
self.DELTA_STERN[2] = -np.amin(C[0:2])
#(y,z) pair for center of keel radius
self.Rk_Center_trans = np.array([-self.Rk_trans*(0.5 - 0.5*np.sign(self.Rk_trans)),
self.SK[1] + self.Rk_trans*(0.5 + 0.5*np.sign(self.Rk_trans))])
#(y,z) pair for intersection of keel radius and LG line at the transom
self.Rk_LG_int_trans = np.array([self.Rk_Center_trans[0] + self.Rk_trans*np.sin(np.pi*self.Beta_trans/180.0),
self.Rk_Center_trans[1] - self.Rk_trans*np.cos(np.pi*self.Beta_trans/180.0)])
#solve for the lower gunwhale line: A*z + B*y + C = 0
A = np.array([[1.0, 1.0, 1.0],
[self.Rk_LG_int_trans[1], self.Rk_LG_int_trans[0], 1.0],
[-(self.Rk_LG_int_trans[0]-self.Rk_Center_trans[0]), (self.Rk_LG_int_trans[1]-self.Rk_Center_trans[1]), 0.0]])
b = np.array([1.0, 0.0, 0.0])
self.LG_trans = np.linalg.solve(A,b)
del A, b
self.Dc_trans = -(self.LG_trans[1]*self.Bc_trans + self.LG_trans[2])/self.LG_trans[0]
# Upper Gunwhale Line: A*z + B*y + C = 0, where UG = [A,B,C]
A = np.array([[self.Dc_trans, self.Bc_trans , 1.0],
[self.Dd, self.Bs, 1.0],
[1.0, 1.0, 1.0]])
b = np.array([0.0,0.0,1.0])
self.UG_trans = np.linalg.solve(A,b)
del A, b
# Calculate terms for the half beam of the cross section of the transom:
self.Rc_Center_trans = np.zeros((2,)) #(y,z) pair for center of chine radius at the transom
self.Rc_UG_int_trans = np.zeros((2,)) #(y,z) pair for intersection of chine radius and UG line at the transom
self.Rc_LG_int_trans = np.zeros((2,)) #(y,z) pair for intersection of chine radius and LG line at the transom
#make math more readable to solve the chine
A1 = self.UG_trans[0]
B1 = self.UG_trans[1]
theta = np.arctan2(-B1,A1)
if theta < 0.0:
theta = theta + np.pi
beta = self.Beta_trans*np.pi/180.0
A2 = self.LG_trans[0]
B2 = self.LG_trans[1]
A = np.array([[B1, A1, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, B2, A2, 0.0, 0.0],
[1.0, 0.0, 0.0, 0.0, -1.0, 0.0],
[0.0, -1.0, 0.0, 0.0, 0.0, 1.0],
[0.0, 0.0, 1.0, 0.0, -1.0, 0.0],
[0.0, 0.0, 0.0, -1.0, 0.0, 1.0]])
b = np.array([-self.UG_trans[2],
-self.LG_trans[2],
self.Rc_trans*np.sin(theta),
self.Rc_trans*np.cos(theta),
self.Rc_trans*np.sin(beta),
self.Rc_trans*np.cos(beta)])
C = np.linalg.solve(A,b)
self.Rc_UG_int_trans = C[0:2]
self.Rc_LG_int_trans = C[2:4]
self.Rc_Center_trans = C[4:6]
def transom(self, z):
#returns the x position of the transom for a given z fr SK_z <= z <= Dd
return self.TRANS[0]*z + self.TRANS[1]
def sternrise(self, z):
#returns the x position of the sternrise for a given z for 0 <= z <= SK_z
return np.sqrt(z/self.STERNRISE) + self.Lb + self.Lm + self.Ls*self.Kappa_STERN
def stern_profile(self, z):
# shows the profile of the stern without the bulbous stern:
if self.bit_SB and z <= self.WL*self.HSBOA:
return self.SB_Prof[0] # If there is a bulbous stern, we want to form the profile to lead into the SB.
else:
if z <= self.SK[1]:
return self.sternrise(z)
else:
return self.transom(z)
def delta_stern(self, z):
#returns the starting position of the stern taper at a given heigt
return self.Lb + self.Lm + self.DELTA_STERN[0]* z**2.0 + self.DELTA_STERN[1]*z + self.DELTA_STERN[2]
def halfBeam_Transom(self, z):
#Returns the x,y pair of the transom at a height z. This assumes that SK_z <= z <= Dd. otherwise y returns -1
x = self.stern_profile(z)
if z <= self.SK[1] and z > 0.0:
y = 0.0
elif z < 0.0 or z > self.Dd:
y = -1.0
elif z > self.SK[1] and z < self.Rk_LG_int_trans[1]:
y = np.sign(self.Rk_trans)*np.sqrt((self.Rk_trans**2) - (z-self.Rk_Center_trans[1])**2) + self.Rk_Center_trans[0]
elif z >= self.Rk_LG_int_trans[1] and z < self.Rc_LG_int_trans[1]:
y = -(self.LG_trans[0] * z + self.LG_trans[2])/self.LG_trans[1]
elif z >= self.Rc_LG_int_trans[1] and z < self.Rc_UG_int_trans[1]:
y = np.sqrt((self.Rc_trans**2) - (z-self.Rc_Center_trans[1])**2) + self.Rc_Center_trans[0]
else:
y = -(self.UG_trans[0] * z + self.UG_trans[2])/self.UG_trans[1]
return [x,y]
def plot_Transom_CrossSection(self):
# Plot intersection points in blue
# Plot chine pt in green
# Plot Center of Rc and Rk in red
# half Beam(z) in black
z = np.linspace(self.SK[1], self.Dd, num = 200)
y = np.zeros((200,2))
for i in range(0,len(z)):
y[i] = self.halfBeam_Transom(z[i])
fig1,ax1 = plt.subplots()
ax1.axis('equal')
#plt.axis([0,10,0,10])
ax1.plot([self.Bs, self.Rc_UG_int_trans[0], self.Rc_LG_int_trans[0], self.Rk_LG_int_trans[0], 0.0],
[self.Dd, self.Rc_UG_int_trans[1], self.Rc_LG_int_trans[1], self.Rk_LG_int_trans[1], self.SK[1]], 'o', color = 'blue')
ax1.plot([self.Rc_Center_trans[0], self.Rk_Center_trans[0]], [self.Rc_Center_trans[1], self.Rk_Center_trans[1]],'o' ,color = 'red')
ax1.plot([self.Bc_trans], [self.Dc_trans],'o' ,color = 'green')
ax1.plot(y[:,1],z,'-', color = 'black', linewidth = 0.75)
def halfBeam_Stern(self, x, PROF):
#returns the halfbeam along the stern taper between delta(z) and stern_profile(z), PROF is the output of solve_waterline_stern(z)
# x is a vector
y = np.zeros((len(x),))
if PROF[0]:
for i in range(0,len(x)):
y[i] = np.sqrt( np.abs(PROF[5]**2.0 * (1.0 - ((x[i] - PROF[6])/PROF[4])**2.0))) + PROF[7] #ellipse
else:
for i in range(0,len(x)):
y[i] = PROF[1]*x[i]**2.0 + PROF[2]*x[i] + PROF[3] #parabola
return y
def stern_dydx(self, x, PROF):
#returns slope dydx of the stern taper at a height z that is defined by PROF
#x is a vecotr and function returns the vector of dydx
dydx = np.zeros((len(x),))
if PROF[0]:
for i in range(0,len(x)):
dydx[i] = -PROF[5]*(x[i]-PROF[6])/(PROF[4]**2.0) * 1/np.sqrt(np.abs(1.0 - ((x[i] - PROF[6])/PROF[4])**2.0))
else:
for i in range(0,len(x)):
dydx[i] = 2.0*PROF[1]*x[i] + PROF[2]
return dydx
def solve_waterline_stern(self, z):
#returns PROF, a parabola [A,B,C], an ellipse [Rx, Ry, Cx, Cy] of the two curves such that they are tangent at the intersection
# Compares bit_EP_S and bit_EP_T -> if the curve is a parabola, the ellipse values in PROF are 0 and vice versa
# PROF = [A,B,C, Rx, Ry, Cx, Cy]
x1 = self.delta_stern(z)
y1 = self.halfBeam_MidBody(z)
[x2,y2] = self.halfBeam_Transom(z)
PROF = np.zeros((8,))
if z >= self.SK[1]:
if self.bit_EP_T:
#If the curve is at the transom and the curve is an ellipse
Rx = x2-x1
Ry = y1-y2
Cx = x1
Cy = y2
PROF[0] = 1
PROF[4:8] = np.array([Rx,Ry,Cx,Cy])
else:
#If the curve is at the transom and the curve is a parabola:
A = np.array([[x1**2.0, x1, 1.0],
[x2**2.0, x2, 1.0],
[2.0*x1, 1.0, 0.0]])
b = np.array([y1, y2, 0.0])
C = np.linalg.solve(A,b)
PROF[1:4] = C
else:
if self.bit_EP_S:
#If the curve is below the transom and the curve is an ellipse
Rx = x2-x1
Ry = y1-y2
Cx = x1
Cy = y2
PROF[0] = 1
PROF[4:8] = np.array([Rx,Ry,Cx,Cy])
else:
#If the curve is below the transom and the curve is a parabola:
A = np.array([[x1**2.0, x1, 1.0],
[x2**2.0, x2, 1.0],
[2.0*x1, 1.0, 0.0]])
b = np.array([y1, y2, 0.0])
C = np.linalg.solve(A,b)
PROF[1:4] = C
return PROF
def gen_waterline_stern(self, z, NUM_POINTS = 100, X = [0,1], bit_spaceOrGrid = 1):
'''
This fuction generates a set of points [[X1,Y1] .... [X2,Y2]] that detail the curvature of the bow taper for a given z, for 0 <= z <= Dd
it can either be created as with a number of set of points, or an even spacing based on the global x spacing (better for station plotting)
BOOL_PTS_OR_SPACE controls whether a set number of points will produce the waterline (1) or the spacing vector will(0)
'''
x1 = self.delta_stern(z)
x2 = self.stern_profile(z)
prof = self.solve_waterline_stern(z)
if bit_spaceOrGrid:
x = np.linspace(x1,x2,NUM_POINTS)
XY = np.zeros((len(x),2))
else:
x = [i for i in X if (i >= x1 and i < x2)]
x = np.concatenate((x,[x2]))
XY = np.zeros((len(x),2))
y = self.halfBeam_Stern(x[0:-1], prof)
XY[0:-1] = np.transpose([x[0:-1],y])
#set the last element in the array to be the transom point
XY[-1] = self.halfBeam_Transom(z)
return XY
def SternformConstraints(self):
# this is an incomplete list of geometric constrains for the hull form
#Check that Delta_Bow(z) is always greater than the leading edge of the ship (keelrise(z) and bow(z))
#Check at z = 0, vertex of delta(z), vertex of bow(z), BKz, Dd
if self.DELTA_STERN[0] == 0.0:
Zv = -1.0
else:
Zv = -self.DELTA_STERN[1]/ (2.0*self.DELTA_STERN[0])
if Zv >=0.0 and Zv <= self.Dd:
vert_delta_stern = (self.delta_stern(Zv) - self.stern_profile(Zv))
else:
vert_delta_stern = -1
C = [self.delta_stern(0.0) - (self.Lb + self.Lm + self.Ls*self.Kappa_STERN),
self.delta_stern(self.SK[1]) - self.SK[0],
vert_delta_stern,
self.delta_stern(self.Dd) - self.stern_profile(self.Dd),
(self.Lb + self.Lm + self.Ls*self.Kappa_STERN) - self.SK[0],
self.Bc_trans - self.halfBeam_MidBody(self.Dc_trans),
-self.Rc_UG_int_trans[1] + self.Dc_trans,
-self.Rc_trans,
-self.Bc_trans,
-self.Dc_trans,
self.Rc_LG_int_trans[0] - self.Bc_trans,
self.Rk_LG_int_trans[0] - self.Rc_LG_int_trans[0]]
return C
'''
=======================================================================
Section 5: Bulb Forms
=======================================================================
The Bulb Forms are defined by the following inputs:
0) bit_BB -> Bit that defines whether there is a bublous bow (1) or not (0)
1) bit_SB -> Bit that defines whether there is a bublous stern (1) or not (0)
2) Lbb -> Length of the bulbous bow (BB) fwd the foward perpendicular as a fraction of LOA