@@ -46,10 +46,12 @@ def objective(trial: optuna.Trial, config: OptimizationParameters) -> tuple:
4646 if geometry .fin_distance_s <= 0.1e-3 :
4747 return float ('nan' ), float ('nan' )
4848
49- if length_l * width_b < config .area_min :
50- return float ('nan' ), float ('nan' )
51-
5249 try :
50+ area = width_b * length_l
51+
52+ if config .number_directions == 2 and area < config .area_min :
53+ return float ('nan' ), float ('nan' )
54+
5355 volume_flow_v_dot , pressure = calc_volume_flow (fan_name , geometry , plot = False )
5456
5557 if np .isnan (volume_flow_v_dot ):
@@ -59,15 +61,19 @@ def objective(trial: optuna.Trial, config: OptimizationParameters) -> tuple:
5961 # weight = calc_weight_heat_sink(geometry, constants)
6062 total_volume = calc_total_volume (geometry , fan_name )
6163
62- return total_volume , r_th_sa
64+ if config .number_directions == 2 :
65+ return total_volume , r_th_sa
66+ elif config .number_directions == 3 :
67+ return total_volume , r_th_sa , area
6368 except :
64- return float ('nan' ), float ('nan' )
69+ if config .number_directions == 2 :
70+ return float ('nan' ), float ('nan' )
71+ elif config .number_directions == 3 :
72+ return float ('nan' ), float ('nan' ), float ('nan' )
6573
6674 @staticmethod
67- def start_proceed_study (config : OptimizationParameters , number_trials : int ,
68- storage : str = 'sqlite' ,
69- sampler = optuna .samplers .NSGAIIISampler (),
70- ) -> None :
75+ def start_proceed_study (config : OptimizationParameters , number_trials : int , storage : str = 'sqlite' ,
76+ sampler = optuna .samplers .NSGAIIISampler ()) -> None :
7177 """Proceed a study which is stored as sqlite database.
7278
7379 :param number_trials: Number of trials adding to the existing study
@@ -81,6 +87,8 @@ def start_proceed_study(config: OptimizationParameters, number_trials: int,
8187 """
8288 if os .path .exists (f"{ config .heat_sink_optimization_directory } /{ config .heat_sink_study_name } .sqlite3" ):
8389 print ("Existing study found. Proceeding." )
90+ else :
91+ os .makedirs (config .heat_sink_optimization_directory , exist_ok = True )
8492
8593 # introduce study in storage, e.g. sqlite or mysql
8694 if storage == 'sqlite' :
@@ -111,7 +119,12 @@ def start_proceed_study(config: OptimizationParameters, number_trials: int,
111119 print ("abort..." )
112120 return None
113121
114- directions = ['minimize' , 'minimize' ]
122+ if config .number_directions == 2 :
123+ directions = ['minimize' , 'minimize' ]
124+ elif config .number_directions == 3 :
125+ directions = ['minimize' , 'minimize' , 'minimize' ]
126+ else :
127+ logging .error (f"number_directions to optimize must be 2 or 3, but it is { config .number_directions } ." )
115128
116129 func = lambda trial : Optimization .objective (trial , config )
117130 optuna .logging .set_verbosity (optuna .logging .ERROR )
0 commit comments