Skip to content

Commit c6f9d6c

Browse files
committed
change optimization
1 parent 44a5ca1 commit c6f9d6c

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

design/Inc_Turbulent_Bend_Wallfunctions/optimization.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
import os
88
import subprocess
9+
910
# get the path to su2 executable
1011
su2_run= os.environ["SU2_RUN"] + "/"
1112
print("SU2 executable obtained from ", su2_run)
@@ -15,12 +16,17 @@
1516
# nr of cores for mpi
1617
ncores="2"
1718

19+
# Set to true if you want to use the restart files of previous design iterations
20+
# this set RESTART= NO to RESTART=YES after the first design iteration
21+
update_restart_file = False
22+
1823
# total number of design iterations.
1924
number_of_design_iterations = 1
2025

2126
configMaster="sudo.cfg"
2227
meshName="sudo_coarse_FFD.su2"
23-
# inlet BC file
28+
29+
# inlet BC file, needs to be copied
2430
inletName="inlet.dat"
2531
restartAdjName="solution_adj_dp.csv"
2632

@@ -135,19 +141,21 @@
135141
# Evaluations ---------------------------------------------------------- #
136142

137143
def_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_DEF " + configCopy
138-
cfd_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_CFD " + configCopy
139-
cfd_ad_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_CFD_AD " + configCopy
140-
cfd_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_CFD " + configCopy + " && cp restart.csv ../../solution.csv"
141-
cfd_ad_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_CFD_AD " + configCopy + " && cp restart_adj_" + objstring + ".csv ../../solution_adj_"+objstring+".csv"
142-
dot_ad_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_DOT_AD " + configCopy
143144

144-
# global iteration
145-
global_iter = 0
145+
if update_restart_file = True:
146+
cfd_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_CFD " + configCopy + " && cp restart.csv ../../solution.csv"
147+
cfd_ad_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_CFD_AD " + configCopy + " && cp restart_adj_" + objstring + ".csv ../../solution_adj_"+objstring+".csv"
148+
else :
149+
cfd_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_CFD " + configCopy
150+
cfd_ad_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_CFD_AD " + configCopy
146151

152+
dot_ad_command = "mpirun --allow-run-as-root -n " + ncores + " " + su2_run + "SU2_DOT_AD " + configCopy
147153

148154
max_tries = 1
149155

156+
#####################################################################
150157
# mesh deformation, running in subdirectory DEFORM
158+
#####################################################################
151159
deform = ExternalRun("DEFORM",def_command,True) # True means sym links are used for addData
152160
deform.setMaxTries(max_tries)
153161
deform.addConfig(configCopy)
@@ -159,7 +167,9 @@
159167
deform.addParameter(enable_def)
160168
deform.addParameter(enable_obj)
161169

170+
#####################################################################
162171
# direct run, running in subdirectory DIRECT
172+
#####################################################################
163173
direct = ExternalRun("DIRECT",cfd_command,True)
164174
direct.setMaxTries(max_tries)
165175
direct.addConfig(configCopy)
@@ -173,7 +183,9 @@
173183
direct.addParameter(enable_not_def)
174184
direct.addParameter(enable_obj)
175185

186+
#####################################################################
176187
# adjoint run, running in subdorectory ADJOINT
188+
#####################################################################
177189
adjoint = ExternalRun("ADJOINT",cfd_ad_command,True)
178190
adjoint.setMaxTries(max_tries)
179191
adjoint.addConfig(configCopy)
@@ -200,7 +212,9 @@
200212
adjoint.addParameter(enable_not_def)
201213
adjoint.addParameter(enable_obj)
202214

215+
#####################################################################
203216
# gradient projection, running in subdirectory DOT
217+
#####################################################################
204218
dot = ExternalRun("DOT",dot_ad_command,True)
205219
dot.setMaxTries(max_tries)
206220
dot.addConfig(configCopy)
@@ -225,7 +239,9 @@
225239
dot.addParameter(enable_def)
226240
dot.addParameter(enable_obj) # necessary for correct file extension
227241

242+
#####################################################################
228243
# update restart file
244+
#####################################################################
229245
update_restart = ExternalRun("UPDATE_RESTART",restart_yes,False) # True means sym links are used for addData
230246
update_restart.addData(configCopy)
231247

@@ -246,7 +262,8 @@
246262
func_surfdp.addValueEvalStep(deform)
247263
func_surfdp.addValueEvalStep(direct)
248264
func_surfdp.addGradientEvalStep(adjoint)
249-
func_surfdp.addGradientEvalStep(update_restart)
265+
if update_restart_file == True:
266+
func_surfdp.addGradientEvalStep(update_restart)
250267
func_surfdp.addGradientEvalStep(dot)
251268
func_surfdp.setDefaultValue(0.0)
252269

0 commit comments

Comments
 (0)