In [1]:
import numpy as np
import scipy.interpolate as interpolate
import scipy.optimize as optimize

%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

import time

Load Mesh


In [11]:
# Import the test geoemtry, which is a full size version of the ship KCS
shipMesh = mesh.importObj('KCS.obj')

# The keel is located at z=0 in the geometry file. Translate it downwards to right depth
T = 10.8
shipMesh.translate(0, 0, -T)

Extract submerged Body


In [12]:
startTime = time.time()
wetMesh = hydrostatic.extractWetSurface(shipMesh)
stopTime = time.time()

print(stopTime - startTime)
wetMesh.exportObj('wetMesh.obj')


0.5628688335418701

Calculate hydrostatistic values


In [16]:
rho = 1025

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')


Volume: 51990.134 m^3
Surface: 9535.126 m^2
Volume centroid: 117.8406 0.0 -4.8902
Dimensions: [ 239.44714354   32.20119      10.8       ]
Mass: 53289.8869651 tonnes