Hydrostatics Module
The Hydrostatics module provides tools for calculating hydrostatic properties of hull geometries, including displacement, buoyancy centers, waterplane properties, and metacentric heights.
Main Classes
HydrostaticsCalculator
Bases:
objectCalculates hydrostatic properties for hull geometries.
The Hull object to analyze.
Density of water in kg/m³.
Shell thickness in meters (adds to submerged volume).
Initialize the hydrostatics calculator.
- Parameters:
hull – The Hull object.
water_density – Density of water in kg/m³ (default: 1025 for seawater).
shell_thickness – Shell thickness in meters (default: 0 for no shell). Adds volume to account for water displaced by shell thickness.
Calculates hydrostatics for a fixed draft, trim, and heel.
- Parameters:
draft – Draft at the reference point in meters.
trim – Trim angle in degrees (positive = bow down).
heel – Heel angle in degrees (positive = starboard down).
vcg – Vertical Center of Gravity (KG) in meters.
- Returns:
HydrostaticState object with all calculated properties.
Finds the equilibrium position for a given displacement and CoG.
- Parameters:
displacement_mass – Target displacement mass in kg.
center_of_gravity – (LCG, TCG, VCG) in meters.
initial_draft – Initial guess for draft. If None, estimated from bounds.
- Returns:
HydrostaticState at equilibrium.
HydrostaticState
Bases:
objectStores all hydrostatic properties for a specific loading condition.
Draft at the reference point (typically amidships) in meters.
- Type:
Trim angle in degrees (positive = bow down).
- Type:
Heel angle in degrees (positive = starboard down).
- Type:
Displaced volume in m³.
- Type:
Displaced mass in kg.
- Type:
Longitudinal Center of Buoyancy in meters.
- Type:
Transverse Center of Buoyancy in meters.
- Type:
Vertical Center of Buoyancy (KB) in meters.
- Type:
Longitudinal Center of Gravity in meters.
- Type:
Transverse Center of Gravity in meters.
- Type:
Vertical Center of Gravity (KG) in meters.
- Type:
Waterplane area in m².
- Type:
Longitudinal Center of Flotation in meters.
- Type:
Transverse Metacentric Height (KM transverse) in meters.
- Type:
Longitudinal Metacentric Height (KM longitudinal) in meters.
- Type:
Transverse Metacentric Radius (BM transverse) in meters.
- Type:
Longitudinal Metacentric Radius (BM longitudinal) in meters.
- Type:
Length on Waterline in meters.
- Type:
Beam on Waterline in meters.
- Type:
Wetted surface area in m².
- Type:
Midship section area in m².
- Type:
Midship section coefficient.
- Type:
6x6 restoring force/moment matrix.
- Type:
numpy.ndarray | None
Initialize stiffness matrix if not provided.
HullVisualizer
Bases:
objectProvides visualization capabilities for hull geometries.
The Hull object to visualize.
Initialize the visualizer.
- Parameters:
hull – The Hull object to visualize.
Saves a screenshot of the hull from a specified viewpoint.
- Parameters:
filename – Output filename (should end with .png, .jpg, etc.).
view_type – View type - ‘iso’, ‘side’, ‘front’, ‘rear’, ‘top’.
show_waterline – Whether to show the waterplane.
draft – Draft level for waterplane visualization.
trim – Trim angle in degrees.
heel – Heel angle in degrees.
Opens an interactive VTK window to view and manipulate the hull.
The window allows rotation, zooming, and panning with mouse controls.
Utility Functions
The tools submodule provides low-level utility functions:
This module provides utility functions for hydrostatic calculations, including volume and surface area computations.
Calculate submerged volume, center of buoyancy, and wetted surface area.
This is a generic function that can handle different types of free surfaces: - Planar surface (calm water) - Sinusoidal surface (waves) - Custom surface defined by a function
- Parameters:
polydata – The hull geometry as vtkPolyData.
surface_function – Function f(x, y) -> z defining the free surface. For planar: lambda x, y: draft. For sinusoidal: lambda x, y: draft + A*sin(k*x + phi).
surface_type – Type of surface (‘planar’, ‘sinusoidal’, ‘custom’).
draft – Reference draft level (used for planar surfaces).
**kwargs – Additional parameters (e.g., wave amplitude, wavelength).
- Returns:
volume: Submerged volume in m³. center_of_buoyancy: numpy array [x, y, z] in meters. wetted_surface_area: Wetted surface area in m². bounds: (xmin, xmax, ymin, ymax, zmin, zmax) of submerged part.
- Return type:
Tuple of (volume, center_of_buoyancy, wetted_surface_area, bounds) where
Calculate the volume of the shell based on wetted surface area and thickness.
This is an approximation assuming the shell follows the outer surface. For thin shells, Volume ≈ Area × Thickness
- Parameters:
wetted_area – Wetted surface area in m².
thickness – Shell thickness in meters.
- Returns:
Shell volume in m³.
Calculate geometric properties of the waterplane (Area, Centroid, I_t, I_l).
Uses Green’s theorem for polygon properties. Assumes the waterplane is in the XY plane (or parallel to it).
- Parameters:
waterline_polydata – vtkPolyData containing the waterline contour(s).
- Returns:
Tuple (Area, Centroid, I_t, I_l, lwl, bwl) - Area: Waterplane area in m² - Centroid: Cylinder center [x, y, z] (z is from input data) - I_t: Transverse moment of inertia (about longitudinal axis through centroid) in m^4 - I_l: Longitudinal moment of inertia (about transverse axis through centroid) in m^4 - lwl: Length on waterline in m - bwl: Beam on waterline in m
Calculate the submerged area of a transverse section at x_location.
- Parameters:
hull_polydata – Hull geometry.
x_location – Longitudinal position of the section.
draft – Waterline Z-coordinate (area is calculated below this).
- Returns:
Area in m².
Example Usage
Calculating Hydrostatics at a Draft
from pynavaltoolbox import Hull
from pynavaltoolbox.hydrostatics import HydrostaticsCalculator
hull = Hull("hull.stl")
calc = HydrostaticsCalculator(hull, water_density=1025.0)
# Calculate at specific draft
state = calc.calculate_at_draft(draft=5.0, trim=0, heel=0)
print(f"Displacement: {state.displacement_mass:.0f} kg")
print(f"Volume: {state.displacement_volume:.2f} m³")
print(f"LCB: {state.lcb:.2f} m")
print(f"KB: {state.vcb:.2f} m")
print(f"KMt: {state.kmt:.2f} m")
print(f"BMt: {state.bmt:.2f} m")
Finding Equilibrium
# Find equilibrium for given displacement and CoG
equilibrium = calc.find_equilibrium(
displacement_mass=5000000.0,
center_of_gravity=(70.0, 0.0, 10.0),
initial_draft=5.0 # Optional starting guess
)
print(f"Draft: {equilibrium.draft:.2f} m")
print(f"Trim: {equilibrium.trim:.2f}°")
Visualizing the Hull
from pynavaltoolbox.hydrostatics import HullVisualizer
visualizer = HullVisualizer(hull)
# Save images from different views
visualizer.save_view("hull_side.png", view_type="side", draft=5.0)
visualizer.save_view("hull_iso.png", view_type="iso", draft=5.0)
# Interactive visualization
visualizer.show()