In [1]:
import numpy as np
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['figure.figsize'] = (16, 9)
import sys
import imp
import os
import polymesh.mesh as mesh
import polymesh.hydrostatic as hydrostatic
In [2]:
# Import the test geoemtry, which is a full size version of the ship KCS
shipMesh = mesh.importObj('BrAa_40m_hull_side_offset.obj')
scale_to_small_vessel = True
L_small = 27
B_small = 8.5
L_orig = 40
B_orig = 10
if scale_to_small_vessel:
L_scale_ratio = L_small/L_orig
B_scale_ratio = B_small/B_orig
shipMesh.scale(L_scale_ratio, B_scale_ratio, B_scale_ratio)
# The keel is located at z=0 in the geometry file. Translate it downwards to right depth
T = 1.65
if scale_to_small_vessel:
T = 1.11
shipMesh.translate(0, 0, -T)
In [3]:
rho = 1025
wetMesh = hydrostatic.extractWetSurface(shipMesh)
wetMesh.exportObj('wetMesh.obj')
wetMesh.calculateEdgeConnectivity()
Volume = hydrostatic.calculateVolume(wetMesh)
Surface = hydrostatic.calculateSurface(wetMesh)
volumeCentroid = hydrostatic.calculateVolumeCentroid(wetMesh)
Dimensions = hydrostatic.calculateDimensions(wetMesh)
Mass = Volume*rho
print('Volume:', np.round(Volume, decimals=3), 'm^3')
print('Surface:', np.round(Surface, decimals=3), 'm^2')
print('Volume centroid:', np.round(volumeCentroid[0], decimals=4), np.round(volumeCentroid[1], decimals=4), np.round(volumeCentroid[2], decimals=4))
print('Dimensions:', Dimensions)
print('Mass:', Mass/1e3, 'tonnes')
In [4]:
plt.scatter(wetMesh.verts[wetMesh.face_verts][:,0], wetMesh.verts[wetMesh.face_verts][:,2])
plt.axis('equal')
plt.figure()
plt.scatter(wetMesh.verts[wetMesh.face_verts][:,1], wetMesh.verts[wetMesh.face_verts][:,2])
plt.axis('equal')
Out[4]:
In [4]:
shipMesh.translate(0, 0, T)
wetMesh.translate(0, 0, T)
In [5]:
extrude_vert = True
extrude_vert_len = 5.0
add_center_point = True
n_planes = 101
norm_axis = 0
sort_axis = 1
mesh_ = wetMesh
plt.scatter(mesh_.verts[mesh_.face_verts][:,0], mesh_.verts[mesh_.face_verts][:,1])
plt.axis('equal')
ax_min = np.amin(mesh_.verts[mesh_.face_verts][:,0])
ax_max = np.amax(mesh_.verts[mesh_.face_verts][:,0])
ax_len = ax_max-ax_min
d_long = (ax_len)/(n_planes-1)
pos_long = np.zeros(n_planes)
plane_points= []
for i in range(n_planes):
pos_long[i] = ax_min + i*d_long
plane = hydrostatic.extractPlane(wetMesh, norm_axis, pos_long[i])
points = plane[0]
points = points[points[:,sort_axis].argsort()]
if extrude_vert:
inner_point = points[0,:]
outer_point = points[-1,:]
new_inner_point = inner_point + extrude_vert_len*np.array((0,0,1.0))
new_outer_point = outer_point + extrude_vert_len*np.array((0,0,1.0))
points = np.vstack((new_inner_point, points))
points = np.vstack((points, new_outer_point))
if add_center_point:
inner_point_z = points[0,2]+.01
new_inner_point = np.array((pos_long[i], 0, inner_point_z))
points = np.vstack((new_inner_point, points))
plane_points.append(points)
In [6]:
plt.scatter(mesh_.verts[mesh_.face_verts][:,0], mesh_.verts[mesh_.face_verts][:,2])
plt.axis('equal')
plt.figure()
plt.scatter(mesh_.verts[mesh_.face_verts][:,1], mesh_.verts[mesh_.face_verts][:,2])
plt.axis('equal')
Out[6]:
In [7]:
plane_no = 67
plt.figure()
plt.plot(plane_points[plane_no][:,1],plane_points[plane_no][:,2])
plt.tight_layout()
print(np.min(plane_points[plane_no][:,2]))
In [10]:
save_location = '/home/johnmartingodo/Dropbox/Flying Foil/Prosjekter/Utviklingskontrakt Trøndelag/Gjennomføring/Hovedprosjekt/Regularitet og komfort/Skroggeometri/Original_40m/'
vessel_name = 'BrAa_40m_hull'
if scale_to_small_vessel:
save_location = '/home/johnmartingodo/Dropbox/Flying Foil/Prosjekter/Utviklingskontrakt Trøndelag/Gjennomføring/Hovedprosjekt/Regularitet og komfort/Skroggeometri/Scaled_30m/'
vessel_name = 'BrAa_30m_hull_scaled_from40'
f = open(save_location+vessel_name+'.mgf', 'w')
f.write(vessel_name+'\n')
for i in range(3):
f.write('\n')
f.write(str(ax_len)+'\n')
for i in range(n_planes-1):
plane_index = n_planes-2-i
shpx_index = plane_index+1
f.write(str(shpx_index)+'\n')
f.write(str(pos_long[plane_index]-.5*ax_len)+'\n')
n_points_plane = len(plane_points[plane_index])
f.write(str(n_points_plane)+'\n')
for j in range(n_points_plane):
point_index = n_points_plane-1-j
f.write('{:.8f} {:.8f}\n'.format(plane_points[plane_index][point_index,1], plane_points[plane_index][point_index,2]))
f.close()
In [ ]: