|
[Sponsors] |
April 23, 2013, 15:06 |
Python Script for complete lift polar
|
#1 |
Senior Member
|
Hi SU2 users,
Is there already python script exists that automatically takes the converged solution of the current angle of attack as restart solution to compute the next angle of attack and so on ... to complete the lift polar. Instead of always doing this process manually to do the polars. Thanks and regards. |
|
April 24, 2013, 03:28 |
Inelegant but effective...
|
#2 | |
New Member
David Tucker
Join Date: Jan 2013
Posts: 16
Rep Power: 13 |
Quote:
...I'm also not worried about space, so I just copy/paste a run directory to the next run (each AoA is a sub-directory of that) and run the script. Since I'm running on a KRAKEN Cray 5 system, I also need a submit script. As I say...not terribly sophisticated, and I am currently "tail"ing each output file one by one and transferring the CL and CD values. If you get anything more slick I'd be interested in taking a look! Good Luck! Dave |
||
May 2, 2013, 14:31 |
Example Code
|
#3 |
Member
Trent Lukaczyk
Join Date: Feb 2011
Location: Stanford, CA
Posts: 75
Rep Power: 15 |
This is a good example to try with the new SU2 python package! Here's an example python script -
Code:
#!/usr/bin/env python # imports import SU2 import numpy as np import pylab as plt from copy import deepcopy # load config, start state config = SU2.io.Config('inv_NACA0012.cfg') state = SU2.io.State() # prepare config config.NUMBER_PART = 2 config.EXT_ITER = 99999 config.RESTART_SOL = 'YES' # find solution files if they exist state.find_files(config) # angles to run angles = np.linspace(-10.,10.,7) # start results data results = SU2.util.bunch() results.AoA = angles results.DRAG = [] results.LIFT = [] # iterate angles for angle in angles: # local config and state konfig = deepcopy(config) ztate = deepcopy(state) # set angle of attack konfig.AoA = angle print 'AoA = ' , konfig.AoA # run su2 drag = SU2.eval.func('DRAG',konfig,ztate) lift = SU2.eval.func('LIFT',konfig,ztate) # append results results.DRAG.append(drag) results.LIFT.append(lift) #: for each angle # plotting plt.figure() plt.plot( results.AoA , results.DRAG ) plt.show() # save data SU2.io.save_data('results.pkl',results) |
|
December 23, 2013, 10:17 |
How do I Use this code?
|
#4 |
New Member
denny lee
Join Date: Feb 2011
Posts: 7
Rep Power: 15 |
Hi rktchip
I try to draw drag polar range from -9 to 9. Sure, I could draw the polar manually trying to 19 times to complete. but I want to calculate automatically. Could u explain the code How could I do that using ur code? I dont know well python... and english.. thanks. |
|
January 11, 2014, 23:12 |
|
#5 |
Super Moderator
Francisco Palacios
Join Date: Jan 2013
Location: Long Beach, CA
Posts: 404
Rep Power: 15 |
In the script below, you can specify the angle of attack and mach number changing the value of
# angles to run angles = np.linspace(-15.0,15.0,11) # mach numbers to run mach = np.linspace(0.15,0.90,5) Best Regards, Francisco #!/usr/bin/env python ## \file shape_optimization.py # \brief Python script for performing the shape optimization. # \author Francisco Palacios, Trent Lukaczyk, Aerospace Design Laboratory (Stanford University) <http://su2.stanford.edu>. # \version 2.0.8 # # Stanford University Unstructured (SU2). # Copyright (C) 2012-2013 Aerospace Design Laboratory (ADL). # # SU2 is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # SU2 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with SU2. If not, see <http://www.gnu.org/licenses/>. # imports import numpy as np from optparse import OptionParser import os, sys, shutil, copy sys.path.append(os.environ['SU2_RUN']) import SU2 # Command Line Options parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="read config from FILE", metavar="FILE") parser.add_option("-p", "--partitions", dest="partitions", default=2, help="number of PARTITIONS", metavar="PARTITIONS") parser.add_option("-i", "--iterations", dest="iterations", default=99999, help="number of ITERATIONS", metavar="ITERATIONS") (options, args)=parser.parse_args() options.partitions = int( options.partitions ) options.iterations = int( options.iterations ) # load config, start state config = SU2.io.Config(options.filename) state = SU2.io.State() # prepare config config.NUMBER_PART = options.partitions config.EXT_ITER = options.iterations # find solution files if they exist state.find_files(config) # angles to run angles = np.linspace(-15.0,15.0,11) # mach numbers to run mach = np.linspace(0.15,0.90,5) # start results data results = SU2.util.bunch() results.AoA = angles results.MACH = mach results.DRAG = [] results.LIFT = [] results.MOMENT_Z = [] # iterate mach for MachNumber in mach: f = open('Polar_M' + str(MachNumber) + '.dat', 'w') f.write('VARIABLES = "AoA", "C<sub>L</sub>", "C<sub>D</sub>", "C<sub>Mz</sub>" \n') # iterate angles for AngleAttack in angles: # local config and state konfig = copy.deepcopy(config) ztate = copy.deepcopy(state) # set angle of attack konfig.AoA = AngleAttack konfig.MACH_NUMBER = MachNumber print 'Mach = ' , konfig.MACH_NUMBER , 'AoA = ' , konfig.AoA # run su2 drag = SU2.eval.func('DRAG',konfig,ztate) lift = SU2.eval.func('LIFT',konfig,ztate) moment = SU2.eval.func('MOMENT_Z',konfig,ztate) # append results results.DRAG.append(drag) results.LIFT.append(lift) results.MOMENT_Z.append(moment) output = str(AngleAttack) + ", " + str(lift) + ", " + str(drag) + ", " + str(moment) + "\n" f.write(output) f.close() # Close open file #: for each angle # plotting # plt.figure() # plt.plot( results.MACH_NUMBER, results.AoA , results.LIFT , results.DRAG ) # plt.show() # save data SU2.io.save_data('results.pkl',results) |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
CentFOAM Python Script Installation: Error | socon009 | OpenFOAM Installation | 2 | May 26, 2012 10:36 |
paraView in shell mode (python script running) | Prosiaczek | OpenFOAM | 2 | March 19, 2012 08:54 |
[General] SurfaceFlow filter in python script | yohey | ParaView | 2 | March 18, 2012 08:43 |
Script for an airfoil polar plots computation | maddalena | OpenFOAM | 5 | June 9, 2010 14:55 |
Thin foil analsis (sail) - Lift Coeff Problem | Kelvin | CFX | 3 | December 22, 2008 17:22 |