From acc070be965d28f8358ce4ccf1a57cfc7fe3b635 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Fri, 9 Dec 2022 15:05:12 +0100 Subject: [PATCH 01/11] Rename Print_external_file --- SU2_PY/OptimalPropeller.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index 709096b1253..70021d228c6 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -48,15 +48,14 @@ ### Functions ### ########################## def a_distribution (w0, Chi): - """Function used to compute the value of the axial interference factor using the inviscid theory of the optimal propeller.""" a = (w0*pow(Chi,2))/(pow(Chi,2)+pow((1+(w0)),2)) return a -def Print_external_file(CTrs, CPrs): - +def write_external_file(CTrs, CPrs): """Function used to write the actuator disk input data file""" + file = open('ActuatorDisk.dat', 'w') file.write('# Automatic generated actuator disk input data file using the Optimal Propeller code.\n') file.write('# Data file needed for the actuator disk VARIABLE_LOAD type.\n') @@ -359,7 +358,7 @@ def Print_external_file(CTrs, CPrs): # Write the actuator disk data file. # This is the actuator disk input data file. -Print_external_file(dCt_optimal, dCp) +write_external_file(dCt_optimal, dCp) ########################## ### Plots ### From f8ed853ef8b9884fbfb0140f1e492036fa056be9 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Fri, 9 Dec 2022 15:07:44 +0100 Subject: [PATCH 02/11] Rename corr variable --- SU2_PY/OptimalPropeller.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index 70021d228c6..a5f29e4ba99 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -157,10 +157,10 @@ def write_external_file(CTrs, CPrs): N = int(input('N (number of propeller blades): ')) print('') - corr = True + prandtl_correction = True else: - corr = False + prandtl_correction = False # Computation of the non-dimensional hub radius. rs_hub = rhub/R @@ -179,7 +179,7 @@ def write_external_file(CTrs, CPrs): Omega = n*2*math.pi # Computation of the tip loss Prandtl correction function F. -if corr == True: +if prandtl_correction: for i in range(0, Stations): F[i] = (2/math.pi)*math.acos(math.exp(-0.5*N*(1-r[i])*math.sqrt(1+pow(Omega*R/Vinf,2)))) @@ -383,7 +383,7 @@ def write_external_file(CTrs, CPrs): pl.ylabel('') pl.title("Interference Factors") -if corr == True: +if prandtl_correction: f1 = pl.figure(3) pl.plot(r, F, 'k', markersize=4) pl.grid(True) From c9b5974408bbaff537d37c59bb9a2c6f8a4de7c1 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Fri, 9 Dec 2022 15:16:01 +0100 Subject: [PATCH 03/11] create a write_su2_config_file function --- SU2_PY/OptimalPropeller.py | 47 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index a5f29e4ba99..0b3c54d3a68 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -53,6 +53,27 @@ def a_distribution (w0, Chi): a = (w0*pow(Chi,2))/(pow(Chi,2)+pow((1+(w0)),2)) return a +def write_su2_config_file(): + """ + Write the actuator disk configuration file + """ + + with open('ActuatorDisk.cfg', 'w') as f: + f.write('% Automatic generated actuator disk configuration file.\n') + f.write('%\n') + f.write('% The first two elements of MARKER_ACTDISK must be filled.\n') + f.write('% An example of this file can be found in the TestCases directory.\n') + f.write('%\n') + f.write('% Author: Ettore Saetta, Lorenzo Russo, Renato Tognaccini.\n') + f.write('% Theoretical and Applied Aerodynamic Research Group (TAARG),\n') + f.write('% University of Naples Federico II\n') + f.write('\n') + f.write('ACTDISK_TYPE = VARIABLE_LOAD\n') + f.write('ACTDISK_FILENAME = ActuatorDisk.dat\n') + f.write('MARKER_ACTDISK = ( , , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)\n') + + print('SU2 file generated!') + def write_external_file(CTrs, CPrs): """Function used to write the actuator disk input data file""" @@ -337,27 +358,11 @@ def write_external_file(CTrs, CPrs): ########################## ### File Writing ### ########################## -# Write the actuator disk configuration file -file = open('ActuatorDisk.cfg', 'w') - -file.write('% Automatic generated actuator disk configuration file.\n') -file.write('%\n') -file.write('% The first two elements of MARKER_ACTDISK must be filled.\n') -file.write('% An example of this file can be found in the TestCases directory.\n') -file.write('%\n') -file.write('% Author: Ettore Saetta, Lorenzo Russo, Renato Tognaccini.\n') -file.write('% Theoretical and Applied Aerodynamic Research Group (TAARG),\n') -file.write('% University of Naples Federico II\n') -file.write('\n') -file.write('ACTDISK_TYPE = VARIABLE_LOAD\n') -file.write('ACTDISK_FILENAME = ActuatorDisk.dat\n') -file.write('MARKER_ACTDISK = ( , , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)\n') -file.close() - -print('SU2 file generated!') - -# Write the actuator disk data file. -# This is the actuator disk input data file. + +# Write the corresponding SU2 configuration file +write_su2_config_file() + +# Write the actuator disk data file. This is the actuator disk input data file. write_external_file(dCt_optimal, dCp) ########################## From eaf3d8c1ceb6764299ee581ada417e8ae8f9e894 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Fri, 9 Dec 2022 15:19:40 +0100 Subject: [PATCH 04/11] rename stations with lower letter --- SU2_PY/OptimalPropeller.py | 94 +++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index 0b3c54d3a68..e8f3b68638a 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -54,9 +54,7 @@ def a_distribution (w0, Chi): return a def write_su2_config_file(): - """ - Write the actuator disk configuration file - """ + """Write the actuator disk configuration file""" with open('ActuatorDisk.cfg', 'w') as f: f.write('% Automatic generated actuator disk configuration file.\n') @@ -96,10 +94,10 @@ def write_external_file(CTrs, CPrs): file.write('AXIS= \n') file.write('RADIUS= '+str(R)+'\n') file.write('ADV_RATIO= '+str(J)+'\n') - file.write('NROW= '+str(Stations)+'\n') + file.write('NROW= '+str(stations)+'\n') file.write('# rs=r/R dCT/drs dCP/drs dCR/drs\n') - for i in range(0, Stations): + for i in range(0, stations): file.write(f' {r[i]:.7f} {CTrs[i]:.7f} {CPrs[i]:.7f} 0.0\n') file.close() @@ -126,28 +124,28 @@ def write_external_file(CTrs, CPrs): print('') # Number of radial stations in input. -Stations = int(input('Number of radial stations: ')) +stations = int(input('Number of radial stations: ')) print('') -dStations = float(Stations) +dStations = float(stations) # Resize the vectors using the number of radial stations. -r = np.empty(Stations) -chi = np.empty(Stations) -dCp = np.empty(Stations) -w = np.empty(Stations) -a_new = np.empty(Stations) -a_old = np.empty(Stations) -a_0 = np.empty(Stations) -ap_old = np.empty(Stations) -dCt_new = np.empty(Stations) -dCt_old = np.empty(Stations) -dCt_0 = np.empty(Stations) -DeltaP = np.empty(Stations) -F = np.empty(Stations) -a_optimal = np.empty(Stations) -ap_optimal = np.empty(Stations) -dCt_optimal = np.empty(Stations) +r = np.empty(stations) +chi = np.empty(stations) +dCp = np.empty(stations) +w = np.empty(stations) +a_new = np.empty(stations) +a_old = np.empty(stations) +a_0 = np.empty(stations) +ap_old = np.empty(stations) +dCt_new = np.empty(stations) +dCt_old = np.empty(stations) +dCt_0 = np.empty(stations) +DeltaP = np.empty(stations) +F = np.empty(stations) +a_optimal = np.empty(stations) +ap_optimal = np.empty(stations) +dCt_optimal = np.empty(stations) # Thrust coefficient in input. Ct = float(input('CT (Renard definition): ')) @@ -187,8 +185,8 @@ def write_external_file(CTrs, CPrs): rs_hub = rhub/R # Computation of the non-dimensional radial stations. -for i in range(1,Stations+1): - r[i-1]=i/dStations +for i in range(1,stations+1): + r[i-1]=i/float(stations) if r[i-1] <= rs_hub: i_hub = i-1 @@ -201,43 +199,43 @@ def write_external_file(CTrs, CPrs): # Computation of the tip loss Prandtl correction function F. if prandtl_correction: - for i in range(0, Stations): + for i in range(0, stations): F[i] = (2/math.pi)*math.acos(math.exp(-0.5*N*(1-r[i])*math.sqrt(1+pow(Omega*R/Vinf,2)))) else: - for i in range(0, Stations): + for i in range(0, stations): F[i] = 1.0 # Computation of the non-dimensional radius chi=Omega*r/Vinf. -for i in range(0, Stations): +for i in range(0, stations): chi[i] = Omega*r[i]*R/Vinf eps = 5E-20 # Computation of the propeller radial stations spacing. -h = (1.0/Stations) +h = (1.0/stations) # Computation of the first try induced velocity distribution. -for i in range(0, Stations): +for i in range(0, stations): w[i] = (2/math.pow(Vinf,2))*((-1/Vinf)+math.sqrt(1+((math.pow(D,4)*(Ct)*math.pow(n,2))/(math.pow(Vinf,2)*math.pi*r[i])))) # Computation of the first try Lagrange moltiplicator. w_0 = 0.0 -for i in range(0, Stations): +for i in range(0, stations): w_0 += w[i] -w_0 = w_0/(Vinf*Stations) +w_0 = w_0/(Vinf*stations) # Computation of the first try axial interference factor distribution. -for i in range(0, Stations): +for i in range(0, stations): a_0[i] = a_distribution(w_0*F[i],chi[i]) # Computation of the thrust coefficient distribution -for i in range(0, Stations): +for i in range(0, stations): dCt_0[i]= math.pi*J*J*r[i]*(1+a_0[i])*a_0[i] # Computation of the total thrust coefficient. Ct_0 = 0.0 -for i in range(i_hub, Stations): +for i in range(i_hub, stations): Ct_0 += h*dCt_0[i] # Compute the error with respect to the thrust coefficient given in input. @@ -249,16 +247,16 @@ def write_external_file(CTrs, CPrs): w_old = w_0 + 0.1 # Computation of the second try axial interference factor distribution. -for i in range(0, Stations): +for i in range(0, stations): a_old[i] = a_distribution(w_old*F[i],chi[i]) # Computation of the thrust coefficient distribution -for i in range(0, Stations): +for i in range(0, stations): dCt_old[i]= math.pi*J*J*r[i]*(1+a_old[i])*a_old[i] # Computation of the total thrust coefficient. Ct_old = 0.0 -for i in range(i_hub, Stations): +for i in range(i_hub, stations): Ct_old += h*dCt_old[i] # Compute the error with respect to the thrust coefficient given in input. @@ -280,16 +278,16 @@ def write_external_file(CTrs, CPrs): w_new = (w_old*err_0 - w_0*err_old)/(err_0 - err_old) # Computation of the new axial interference factor distribution. - for i in range(0, Stations): + for i in range(0, stations): a_new[i] = a_distribution(w_new*F[i],chi[i]) # Computation of the new thrust coefficient distribution. - for i in range(0, Stations): + for i in range(0, stations): dCt_new[i]= math.pi*J*J*r[i]*(1+a_new[i])*a_new[i] # Computation of the new total thrust coefficient. Ct_new = 0.0 - for i in range(i_hub, Stations): + for i in range(i_hub, stations): Ct_new += h*dCt_new[i] # Computation of the total thrust coefficient error with respect to the input value. @@ -305,16 +303,16 @@ def write_external_file(CTrs, CPrs): w_old = w_new # Computation of the correct axial and rotational interference factors (a and ap). -for i in range(0, Stations): +for i in range(0, stations): a_optimal[i] = a_distribution(w_new*F[i],chi[i]) ap_optimal[i] = (w_new*F[i])*((1+w_new*F[i])/(chi[i]*chi[i]+math.pow(1+w_new*F[i],2))) # Computation of the correct thrust coefficient distribution. -for i in range(0, Stations): +for i in range(0, stations): dCt_optimal[i] = math.pi*J*J*r[i]*(1+a_optimal[i])*a_optimal[i] # Computation of the correct power coefficient distribution. -for i in range(0, Stations): +for i in range(0, stations): dCp[i] = (R*4*math.pi/(math.pow(n,3)*math.pow(D,5)))*(math.pow(Vinf,3)*math.pow(1+a_optimal[i],2)*a_optimal[i]*r[i]*R+math.pow(Omega,2)*Vinf*(1+a_optimal[i])*math.pow(ap_optimal[i],2)*math.pow(r[i]*R,3)) ########################## @@ -322,21 +320,21 @@ def write_external_file(CTrs, CPrs): ########################## # Computation of the total power coefficient. Cp = 0.0 -for i in range(i_hub, Stations): +for i in range(i_hub, stations): Cp += h*dCp[i] # Computation of the total thrust coefficient. Ct_optimal = 0.0 -for i in range(i_hub, Stations): +for i in range(i_hub, stations): Ct_optimal += h*dCt_optimal[i] # Computation of the static pressure jump distribution. -for i in range(0, Stations): +for i in range(0, stations): DeltaP[i] = (dCt_optimal[i])*(2*Vinf*Vinf)/(J*J*math.pi*r[i]) # Computation of the thrust over density (T) using the static pressure jump distribution. T = 0.0 -for i in range(i_hub, Stations): +for i in range(i_hub, stations): T += 2*math.pi*r[i]*math.pow(R,2)*h*DeltaP[i] # Computation of the thrust coefficient using T. From 0a8a903a90b4e8b90c98147dd3731d5bf0e9acc3 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Fri, 9 Dec 2022 15:23:24 +0100 Subject: [PATCH 05/11] rename Prandtl variable and simplify "yes" values --- SU2_PY/OptimalPropeller.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index e8f3b68638a..f84727a625e 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -73,7 +73,7 @@ def write_su2_config_file(): print('SU2 file generated!') def write_external_file(CTrs, CPrs): - """Function used to write the actuator disk input data file""" + """Function to write the actuator disk input data file""" file = open('ActuatorDisk.dat', 'w') file.write('# Automatic generated actuator disk input data file using the Optimal Propeller code.\n') @@ -127,8 +127,6 @@ def write_external_file(CTrs, CPrs): stations = int(input('Number of radial stations: ')) print('') -dStations = float(stations) - # Resize the vectors using the number of radial stations. r = np.empty(stations) chi = np.empty(stations) @@ -168,16 +166,14 @@ def write_external_file(CTrs, CPrs): print('') # Asking if the tip loss Prandtl correction function needs to be used. -Prandtl = input('Using tip loss Prandtl correction? (/n): ') +prandtl_input = input('Using tip loss Prandtl correction? (/n): ') print('') -if Prandtl == 'y' or Prandtl == 'Y' or Prandtl == '': +if prandtl_input.lower() in ['yes', 'y', '']: # Number of propeller blades in input. N = int(input('N (number of propeller blades): ')) print('') - prandtl_correction = True - else: prandtl_correction = False From 2693f2fbb35836fc2324be9f466ae97fe0823672 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Fri, 9 Dec 2022 16:18:54 +0100 Subject: [PATCH 06/11] Use numpy in all simple case --- SU2_PY/OptimalPropeller.py | 72 ++++++++++---------------------------- 1 file changed, 19 insertions(+), 53 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index f84727a625e..96c227b2b62 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -129,21 +129,12 @@ def write_external_file(CTrs, CPrs): # Resize the vectors using the number of radial stations. r = np.empty(stations) -chi = np.empty(stations) dCp = np.empty(stations) -w = np.empty(stations) a_new = np.empty(stations) a_old = np.empty(stations) a_0 = np.empty(stations) -ap_old = np.empty(stations) -dCt_new = np.empty(stations) -dCt_old = np.empty(stations) -dCt_0 = np.empty(stations) -DeltaP = np.empty(stations) -F = np.empty(stations) a_optimal = np.empty(stations) ap_optimal = np.empty(stations) -dCt_optimal = np.empty(stations) # Thrust coefficient in input. Ct = float(input('CT (Renard definition): ')) @@ -195,48 +186,37 @@ def write_external_file(CTrs, CPrs): # Computation of the tip loss Prandtl correction function F. if prandtl_correction: - for i in range(0, stations): - F[i] = (2/math.pi)*math.acos(math.exp(-0.5*N*(1-r[i])*math.sqrt(1+pow(Omega*R/Vinf,2)))) - + F = (2/math.pi)*np.arccos(np.exp(-0.5*N*(1-r)*np.sqrt(1+pow(Omega*R/Vinf,2)))) else: - for i in range(0, stations): - F[i] = 1.0 + F = np.ones((stations)) # Computation of the non-dimensional radius chi=Omega*r/Vinf. -for i in range(0, stations): - chi[i] = Omega*r[i]*R/Vinf +chi = Omega*r*R/Vinf + eps = 5E-20 # Computation of the propeller radial stations spacing. h = (1.0/stations) # Computation of the first try induced velocity distribution. -for i in range(0, stations): - w[i] = (2/math.pow(Vinf,2))*((-1/Vinf)+math.sqrt(1+((math.pow(D,4)*(Ct)*math.pow(n,2))/(math.pow(Vinf,2)*math.pi*r[i])))) +w = (2/np.power(Vinf,2))*((-1/Vinf)+np.sqrt(1+((np.power(D,4)*(Ct)*np.power(n,2))/(np.power(Vinf,2)*np.pi*r)))) # Computation of the first try Lagrange moltiplicator. -w_0 = 0.0 -for i in range(0, stations): - w_0 += w[i] - -w_0 = w_0/(Vinf*stations) +w_0 = sum(w)/(Vinf*stations) # Computation of the first try axial interference factor distribution. for i in range(0, stations): a_0[i] = a_distribution(w_0*F[i],chi[i]) # Computation of the thrust coefficient distribution -for i in range(0, stations): - dCt_0[i]= math.pi*J*J*r[i]*(1+a_0[i])*a_0[i] +dCt_0 = math.pi*J**2*r*(1+a_0)*a_0 # Computation of the total thrust coefficient. -Ct_0 = 0.0 -for i in range(i_hub, stations): - Ct_0 += h*dCt_0[i] +Ct_0 = sum(h*dCt_0) # Compute the error with respect to the thrust coefficient given in input. err_0 = Ct_0 - Ct -print('CONVERGENCE HISTORY:') +print("\nCONVERGENCE HISTORY:") print(err_0) # Computation of the second try Lagrange moltiplicator. @@ -247,13 +227,10 @@ def write_external_file(CTrs, CPrs): a_old[i] = a_distribution(w_old*F[i],chi[i]) # Computation of the thrust coefficient distribution -for i in range(0, stations): - dCt_old[i]= math.pi*J*J*r[i]*(1+a_old[i])*a_old[i] +dCt_old = math.pi*J**2*r*(1+a_old)*a_old # Computation of the total thrust coefficient. -Ct_old = 0.0 -for i in range(i_hub, stations): - Ct_old += h*dCt_old[i] +Ct_old = sum(h*dCt_old) # Compute the error with respect to the thrust coefficient given in input. err_old = Ct_old - Ct @@ -278,13 +255,10 @@ def write_external_file(CTrs, CPrs): a_new[i] = a_distribution(w_new*F[i],chi[i]) # Computation of the new thrust coefficient distribution. - for i in range(0, stations): - dCt_new[i]= math.pi*J*J*r[i]*(1+a_new[i])*a_new[i] + dCt_new = math.pi*J**2*r*(1+a_new)*a_new # Computation of the new total thrust coefficient. - Ct_new = 0.0 - for i in range(i_hub, stations): - Ct_new += h*dCt_new[i] + Ct_new = sum(h*dCt_new) # Computation of the total thrust coefficient error with respect to the input value. err_new = Ct_new - Ct @@ -304,8 +278,7 @@ def write_external_file(CTrs, CPrs): ap_optimal[i] = (w_new*F[i])*((1+w_new*F[i])/(chi[i]*chi[i]+math.pow(1+w_new*F[i],2))) # Computation of the correct thrust coefficient distribution. -for i in range(0, stations): - dCt_optimal[i] = math.pi*J*J*r[i]*(1+a_optimal[i])*a_optimal[i] +dCt_optimal = math.pi*J**2*r*(1+a_optimal)*a_optimal # Computation of the correct power coefficient distribution. for i in range(0, stations): @@ -315,26 +288,19 @@ def write_external_file(CTrs, CPrs): ### Check Results ### ########################## # Computation of the total power coefficient. -Cp = 0.0 -for i in range(i_hub, stations): - Cp += h*dCp[i] +Cp = sum(h*dCp) # Computation of the total thrust coefficient. -Ct_optimal = 0.0 -for i in range(i_hub, stations): - Ct_optimal += h*dCt_optimal[i] +Ct_optimal = sum(h*dCt_optimal) # Computation of the static pressure jump distribution. -for i in range(0, stations): - DeltaP[i] = (dCt_optimal[i])*(2*Vinf*Vinf)/(J*J*math.pi*r[i]) +DeltaP = dCt_optimal*(2*Vinf**2)/(J**2*math.pi*r) # Computation of the thrust over density (T) using the static pressure jump distribution. -T = 0.0 -for i in range(i_hub, stations): - T += 2*math.pi*r[i]*math.pow(R,2)*h*DeltaP[i] +T = sum(2*math.pi*r*math.pow(R,2)*h*DeltaP) # Computation of the thrust coefficient using T. -Ct_Renard = (T)/(math.pow(n,2)*math.pow(D,4)) +Ct_Renard = T/(math.pow(n,2)*math.pow(D,4)) # Computation of the efficiency. eta = J*(Ct_optimal/Cp) From e4210b3d59ea0edae6c3f07b8f1ade023667419e Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Mon, 19 Dec 2022 11:22:54 +0100 Subject: [PATCH 07/11] Use contex manager to write file --- SU2_PY/OptimalPropeller.py | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index 96c227b2b62..1b92dbb0476 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -47,6 +47,7 @@ ########################## ### Functions ### ########################## + def a_distribution (w0, Chi): """Function used to compute the value of the axial interference factor using the inviscid theory of the optimal propeller.""" @@ -75,32 +76,31 @@ def write_su2_config_file(): def write_external_file(CTrs, CPrs): """Function to write the actuator disk input data file""" - file = open('ActuatorDisk.dat', 'w') - file.write('# Automatic generated actuator disk input data file using the Optimal Propeller code.\n') - file.write('# Data file needed for the actuator disk VARIABLE_LOAD type.\n') - file.write('# The load distribution is obtained using the inviscid theory of the optimal propeller\n') - file.write('# using global data.\n') - file.write('#\n') - file.write('# The first three lines must be filled.\n') - file.write('# An example of this file can be found in the TestCases directory.\n') - file.write('#\n') - file.write('# Author: Ettore Saetta, Lorenzo Russo, Renato Tognaccini.\n') - file.write('# Theoretical and Applied Aerodynamic Research Group (TAARG),\n') - file.write('# University of Naples Federico II\n') - file.write('# -------------------------------------------------------------------------------------\n') - file.write('#\n') - file.write('MARKER_ACTDISK= \n') - file.write('CENTER= \n') - file.write('AXIS= \n') - file.write('RADIUS= '+str(R)+'\n') - file.write('ADV_RATIO= '+str(J)+'\n') - file.write('NROW= '+str(stations)+'\n') - file.write('# rs=r/R dCT/drs dCP/drs dCR/drs\n') - - for i in range(0, stations): - file.write(f' {r[i]:.7f} {CTrs[i]:.7f} {CPrs[i]:.7f} 0.0\n') + with open('ActuatorDisk.dat', 'w') as f: + f.write('# Automatic generated actuator disk input data file using the Optimal Propeller code.\n') + f.write('# Data file needed for the actuator disk VARIABLE_LOAD type.\n') + f.write('# The load distribution is obtained using the inviscid theory of the optimal propeller\n') + f.write('# using global data.\n') + f.write('#\n') + f.write('# The first three lines must be filled.\n') + f.write('# An example of this file can be found in the TestCases directory.\n') + f.write('#\n') + f.write('# Author: Ettore Saetta, Lorenzo Russo, Renato Tognaccini.\n') + f.write('# Theoretical and Applied Aerodynamic Research Group (TAARG),\n') + f.write('# University of Naples Federico II\n') + f.write('# -------------------------------------------------------------------------------------\n') + f.write('#\n') + f.write('MARKER_ACTDISK= \n') + f.write('CENTER= \n') + f.write('AXIS= \n') + f.write('RADIUS= '+str(R)+'\n') + f.write('ADV_RATIO= '+str(J)+'\n') + f.write('NROW= '+str(stations)+'\n') + f.write('# rs=r/R dCT/drs dCP/drs dCR/drs\n') + + for i in range(0, stations): + f.write(f' {r[i]:.7f} {CTrs[i]:.7f} {CPrs[i]:.7f} 0.0\n') - file.close() ########################## ### Main ### From 041d55eccaa7d6835e798b743e21824dd10fbf48 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Mon, 19 Dec 2022 11:25:15 +0100 Subject: [PATCH 08/11] Use new lines directly in print --- SU2_PY/OptimalPropeller.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index 1b92dbb0476..c137e9fbd57 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -105,7 +105,7 @@ def write_external_file(CTrs, CPrs): ########################## ### Main ### ########################## -# Screen output + print('------------------ Optimal Propeller vsn 7.0.6 ------------------') print('| Computation of the optimal dCT/dr and dCP/dr distributions. |') print('| Based on the inviscid theory of the optimal propeller. |') @@ -118,14 +118,12 @@ def write_external_file(CTrs, CPrs): print('| Theoretical and Applied Aerodynamic Research Group (TAARG), |') print('| University of Naples Federico II. |') print('-----------------------------------------------------------------') - print('') print('Warning: present version requires input in SI units.') print('') # Number of radial stations in input. stations = int(input('Number of radial stations: ')) -print('') # Resize the vectors using the number of radial stations. r = np.empty(stations) @@ -137,33 +135,26 @@ def write_external_file(CTrs, CPrs): ap_optimal = np.empty(stations) # Thrust coefficient in input. -Ct = float(input('CT (Renard definition): ')) -print('') +Ct = float(input('\nCT (Renard definition): ')) # Propeller radius in input. -R = float(input('R (propeller radius [m]): ')) -print('') +R = float(input('\nR (propeller radius [m]): ')) # Hub radius in input. -rhub = float(input('r_hub (hub radius [m]): ')) -print('') +rhub = float(input('\nr_hub (hub radius [m]): ')) # Advance ratio in input. -J = float(input('J (advance ratio): ')) -print('') +J = float(input('\nJ (advance ratio): ')) # Freestream velocity in input. -Vinf = float(input('Vinf (m/s): ')) -print('') +Vinf = float(input('\nVinf (m/s): ')) # Asking if the tip loss Prandtl correction function needs to be used. -prandtl_input = input('Using tip loss Prandtl correction? (/n): ') -print('') +prandtl_input = input('\nUsing tip loss Prandtl correction? (/n): ') if prandtl_input.lower() in ['yes', 'y', '']: # Number of propeller blades in input. - N = int(input('N (number of propeller blades): ')) - print('') + N = int(input('\nN (number of propeller blades): ')) prandtl_correction = True else: prandtl_correction = False @@ -216,7 +207,7 @@ def write_external_file(CTrs, CPrs): # Compute the error with respect to the thrust coefficient given in input. err_0 = Ct_0 - Ct -print("\nCONVERGENCE HISTORY:") +print("\n\nCONVERGENCE HISTORY:") print(err_0) # Computation of the second try Lagrange moltiplicator. From 1847e54117e833b3d7eb8875303bf8f9bf8e5a59 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Mon, 19 Dec 2022 11:46:18 +0100 Subject: [PATCH 09/11] simplification and linting --- SU2_PY/OptimalPropeller.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index c137e9fbd57..cdccbf5023d 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -51,8 +51,8 @@ def a_distribution (w0, Chi): """Function used to compute the value of the axial interference factor using the inviscid theory of the optimal propeller.""" - a = (w0*pow(Chi,2))/(pow(Chi,2)+pow((1+(w0)),2)) - return a + return (w0*pow(Chi,2))/(pow(Chi,2)+pow((1+(w0)),2)) + def write_su2_config_file(): """Write the actuator disk configuration file""" @@ -73,6 +73,7 @@ def write_su2_config_file(): print('SU2 file generated!') + def write_external_file(CTrs, CPrs): """Function to write the actuator disk input data file""" @@ -160,20 +161,20 @@ def write_external_file(CTrs, CPrs): prandtl_correction = False # Computation of the non-dimensional hub radius. -rs_hub = rhub/R +rs_hub = rhub / R # Computation of the non-dimensional radial stations. -for i in range(1,stations+1): - r[i-1]=i/float(stations) +for i in range(1, stations+1): + r[i-1] = i / float(stations) if r[i-1] <= rs_hub: - i_hub = i-1 + i_hub = i - 1 # Computation of the propeller diameter. -D = 2*R +D = 2 * R # Computation of the propeller angular velocity (Rounds/s). -n = Vinf/(D*J) +n = Vinf / (D*J) # Computation of the propeller angular velocity (Rad/s). -Omega = n*2*math.pi +Omega = n * 2 * math.pi # Computation of the tip loss Prandtl correction function F. if prandtl_correction: @@ -235,7 +236,6 @@ def write_external_file(CTrs, CPrs): iteration = 2 err_new = err_old while math.fabs(err_new) >= eps and err_0 != err_old: - iteration += 1 # Computation of the new Lagrange moltiplicator value based on the false position method. @@ -253,7 +253,6 @@ def write_external_file(CTrs, CPrs): # Computation of the total thrust coefficient error with respect to the input value. err_new = Ct_new - Ct - print(err_new) # Updating the stored values for the next iteration. @@ -291,10 +290,10 @@ def write_external_file(CTrs, CPrs): T = sum(2*math.pi*r*math.pow(R,2)*h*DeltaP) # Computation of the thrust coefficient using T. -Ct_Renard = T/(math.pow(n,2)*math.pow(D,4)) +Ct_Renard = T / (math.pow(n,2)*math.pow(D,4)) # Computation of the efficiency. -eta = J*(Ct_optimal/Cp) +eta = J * (Ct_optimal/Cp) # Screen output used to check that everything worked correcty. print('%%%%%%%%%%%%%%%%%%%%%%%%% CHECK OUTPUT VALUES %%%%%%%%%%%%%%%%%%%%%%%%%') @@ -321,7 +320,7 @@ def write_external_file(CTrs, CPrs): ########################## # Automatically plot the computed propeller performance. -f1 = pl.figure(1) +pl.figure(1) pl.plot(r, dCt_optimal, 'r', markersize=4, label='$\\frac{dCT}{d\overline{r}}$') pl.plot(r, dCp, 'k', markersize=4, label='$\\frac{dCP}{d\overline{r}}$') pl.grid(True) @@ -330,7 +329,7 @@ def write_external_file(CTrs, CPrs): pl.ylabel('') pl.title("Load Distribution") -f1 = pl.figure(2) +pl.figure(2) pl.plot(chi, a_optimal, 'r', markersize=4, label='$a$') pl.plot(chi, ap_optimal, 'k', markersize=4, label='$a^1$') pl.grid(True) @@ -340,7 +339,7 @@ def write_external_file(CTrs, CPrs): pl.title("Interference Factors") if prandtl_correction: - f1 = pl.figure(3) + pl.figure(3) pl.plot(r, F, 'k', markersize=4) pl.grid(True) pl.xlabel('$\overline{r}$') From a95cf4a326684b502683c646c10f6ed5d43bfd81 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Tue, 20 Dec 2022 11:55:04 +0100 Subject: [PATCH 10/11] fix sum from i_hub --- SU2_PY/OptimalPropeller.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SU2_PY/OptimalPropeller.py b/SU2_PY/OptimalPropeller.py index cdccbf5023d..d4a32c150f2 100644 --- a/SU2_PY/OptimalPropeller.py +++ b/SU2_PY/OptimalPropeller.py @@ -204,7 +204,7 @@ def write_external_file(CTrs, CPrs): dCt_0 = math.pi*J**2*r*(1+a_0)*a_0 # Computation of the total thrust coefficient. -Ct_0 = sum(h*dCt_0) +Ct_0 = sum(h*dCt_0[i_hub:]) # Compute the error with respect to the thrust coefficient given in input. err_0 = Ct_0 - Ct @@ -222,7 +222,7 @@ def write_external_file(CTrs, CPrs): dCt_old = math.pi*J**2*r*(1+a_old)*a_old # Computation of the total thrust coefficient. -Ct_old = sum(h*dCt_old) +Ct_old = sum(h*dCt_old[i_hub:]) # Compute the error with respect to the thrust coefficient given in input. err_old = Ct_old - Ct @@ -249,7 +249,7 @@ def write_external_file(CTrs, CPrs): dCt_new = math.pi*J**2*r*(1+a_new)*a_new # Computation of the new total thrust coefficient. - Ct_new = sum(h*dCt_new) + Ct_new = sum(h*dCt_new[i_hub:]) # Computation of the total thrust coefficient error with respect to the input value. err_new = Ct_new - Ct @@ -278,16 +278,16 @@ def write_external_file(CTrs, CPrs): ### Check Results ### ########################## # Computation of the total power coefficient. -Cp = sum(h*dCp) +Cp = sum(h*dCp[i_hub:]) # Computation of the total thrust coefficient. -Ct_optimal = sum(h*dCt_optimal) +Ct_optimal = sum(h*dCt_optimal[i_hub:]) # Computation of the static pressure jump distribution. DeltaP = dCt_optimal*(2*Vinf**2)/(J**2*math.pi*r) # Computation of the thrust over density (T) using the static pressure jump distribution. -T = sum(2*math.pi*r*math.pow(R,2)*h*DeltaP) +T = sum(2*math.pi*r[i_hub:]*math.pow(R,2)*h*DeltaP[i_hub:]) # Computation of the thrust coefficient using T. Ct_Renard = T / (math.pow(n,2)*math.pow(D,4)) From 6f83468f2ff9ce0ef0320ce5e09b0ea7ee186cd0 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Tue, 3 Jan 2023 08:15:33 +0100 Subject: [PATCH 11/11] Add my name in AUTHORS.md --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 53a02f26eb3..cd87c268ba1 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -43,6 +43,7 @@ in collaboration with the following main contributors and research teams: Copyright holders might be the individual person or their respective employer. If no real name is available, the Github user name is listed. ``` +Aidan Jungo Akshay.K.R Alejandro Alessandro Gastaldi