CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > SU2

Python Script for complete lift polar

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 2 Post By rktchip

Reply
 
LinkBack Thread Tools Display Modes
Old   April 23, 2013, 14:06
Exclamation Python Script for complete lift polar
  #1
Senior Member
 
Join Date: Nov 2010
Posts: 128
Rep Power: 6
taxalian is on a distinguished road
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.
taxalian is offline   Reply With Quote

Old   April 24, 2013, 02:28
Default Inelegant but effective...
  #2
New Member
 
dtucker's Avatar
 
David Tucker
Join Date: Jan 2013
Posts: 16
Rep Power: 4
dtucker is on a distinguished road
Quote:
Originally Posted by taxalian View Post
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.
I'm willing to bet someone has come up with something a little more elegant than this...but I setup a c-shell script to take care of the leg-work. It would be a prime candidate for a loop call, but this does the trick!

...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
Attached Files
File Type: doc SubmitJobsScript.doc (35.0 KB, 24 views)
dtucker is offline   Reply With Quote

Old   May 2, 2013, 13:31
Default Example Code
  #3
Member
 
Trent Lukaczyk
Join Date: Feb 2011
Location: Stanford, CA
Posts: 75
Rep Power: 6
rktchip is on a distinguished road
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)
elvis and dtucker like this.
rktchip is offline   Reply With Quote

Old   December 23, 2013, 10:17
Default How do I Use this code?
  #4
New Member
 
denny lee
Join Date: Feb 2011
Posts: 7
Rep Power: 6
kokoory is on a distinguished road
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.
kokoory is offline   Reply With Quote

Old   January 11, 2014, 23:12
Default
  #5
Super Moderator
 
Francisco Palacios
Join Date: Jan 2013
Location: Stanford, CA
Posts: 301
Rep Power: 5
fpalacios is on a distinguished road
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)
fpalacios is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CentFOAM Python Script Installation: Error socon009 OpenFOAM Installation 2 May 26, 2012 09:36
paraView in shell mode (python script running) Prosiaczek OpenFOAM 2 March 19, 2012 08:54
[ParaView] 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 13:55
Thin foil analsis (sail) - Lift Coeff Problem Kelvin CFX 3 December 22, 2008 17:22


All times are GMT -4. The time now is 16:13.