diff --git a/ShipGen/Generate.py b/ShipGen/Generate.py index 845b26c..4ae7e74 100644 --- a/ShipGen/Generate.py +++ b/ShipGen/Generate.py @@ -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") @@ -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/" @@ -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]) \ No newline at end of file + print('Error at hull {}'.format(valid_idx[idxs[i]])) \ No newline at end of file diff --git a/ShipGen/tools/HullParameterization.py b/ShipGen/tools/HullParameterization.py index b382674..034c4c4 100644 --- a/ShipGen/tools/HullParameterization.py +++ b/ShipGen/tools/HullParameterization.py @@ -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