Skip to content

Commit

Permalink
Improved typing
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeBell committed Mar 5, 2025
1 parent 19cf09b commit c640f6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
34 changes: 9 additions & 25 deletions ShipGen/Generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

import numpy as np
from tqdm import tqdm
import math
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
import torch.nn.functional as F
from .tools import Guided_Cond_DDPM_Tools as GC_DDPM
from .tools.HullParameterization import Hull_Parameterization as HP
from .__init__ import data_path, trained_models_path

from sklearn.decomposition import PCA # type: ignore

import matplotlib.pyplot as plt

from .tools.HullParameterization import Hull_Parameterization as HP

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

Expand Down Expand Up @@ -217,34 +210,27 @@ def generate_hulls(final_count:int,
if characteristics is None:
Ship = np.array([333, 42.624, 11.28, 29.064, 97561,16])
else: Ship = characteristics.as_array()
if reject_count is None: num_samples = final_count * (reject_ratio + 1)
if reject_count is None: num_samples = int(final_count * (reject_ratio + 1))
else: num_samples = final_count + reject_count

LOA = Ship[0] #in meters
BoL = Ship[1]/LOA #beam to length ratio
ToD = Ship[2]/Ship[3] #Draft to depth ratio
DoL = Ship[3]/LOA #Depth to length ratio
Vol = np.log10(Ship[4]/LOA**3) # to normalize Volume by LOA**3
LOA:float = Ship[0] #in meters
BoL:float = Ship[1]/LOA #beam to length ratio
ToD:float = Ship[2]/Ship[3] #Draft to depth ratio
DoL:float = Ship[3]/LOA #Depth to length ratio
Vol:float = np.log10(Ship[4]/LOA**3) # to normalize Volume by LOA**3

U = Ship[5] # 12.86 #m/s = 25 knots
U:float = Ship[5] # 12.86 #m/s = 25 knots

dim_d = np.array([[ToD, U, LOA]]) #Drag_conditioning is [ToD, U(m/s), LOA (m)]

drag_cond = np.repeat(dim_d, num_samples, axis=0) #reapeat
#print(cond.shape)
dim_g = np.array([[ToD, BoL, DoL, Vol]])

geom_cond = np.repeat(dim_g, num_samples, axis=0) #reapeat
#print(cond.shape)

x_samples, unnorm = T.gen_vol_drag_guided_samples(geom_cond, drag_cond)


Rt_guidance = T.Predict_Drag(unnorm, drag_cond)
Drag_Guidance = np.mean(Rt_guidance)




path = "./Hulls/"

Expand All @@ -265,6 +251,4 @@ def generate_hulls(final_count:int,
try:
mesh = Hull.gen_stl(NUM_WL=47, PointsPerWL=151, bit_AddTransom = 1, bit_AddDeckLid = 1, bit_RefineBowAndStern = 1,namepath = strpath)
except:
print('Error at hull {}'.format(valid_idx[idxs[i]]))

idx_min_pred_drag = np.argmin(Rt_guidance[valid_idx])
print('Error at hull {}'.format(valid_idx[idxs[i]]))
2 changes: 1 addition & 1 deletion ShipGen/tools/HullParameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ def gen_WLPoints(self, z, PointsPerWL = 300):
return np.array(WL)


def gen_stl(self, NUM_WL = 50, PointsPerWL = 300, bit_AddTransom = 1, bit_AddDeckLid = 0, bit_RefineBowAndStern = 0, namepath = 'Hull_Mesh'):
def gen_stl(self, NUM_WL = 50, PointsPerWL = 300, bit_AddTransom = 1, bit_AddDeckLid = 0, bit_RefineBowAndStern = 0, namepath = 'Hull_Mesh') -> mesh.Mesh:
# This function generates a surface of the mesh by iterating through the points on the waterlines

#compute number of triangles in the mesh
Expand Down

0 comments on commit c640f6c

Please sign in to comment.