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

[Scripting]: How to get the coordinates of a 2D airfoil @ different angles of attack?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By Flowkersma

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 25, 2017, 00:37
Default [Scripting]: How to get the coordinates of a 2D airfoil @ different angles of attack?
  #1
New Member
 
Join Date: Oct 2017
Posts: 15
Rep Power: 8
CfdIntro is on a distinguished road
I have this piece of code which calculates the coordinates of a point(qx,qy) after it is rotated around an origin(ox, oy) by an angle(angle):
Code:
import math  

def rotate(origin, point, angle): 
  
ox, oy = origin 
px, py = point  

qx = ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy) 
qy = oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy) 

return qx, qy  

print(rotate((ox, oy), (px, py), math.radians(angle)))
I want to get the coordinates of an airfoil at different angle of attacks. For this, I want the final script to be able to read the x,y coordinates of the airfoil at 0 degrees angle of attack from a .txt file, do the calculation for all the coordinates for a new angle of attack and then export the results to a new .geo file.

I have this code that lets the script to open the .txt file with the coordinates at 0 angle of attack:

Code:
coordsAt0 = [] 
with open('coordinatesAt0.txt') as fin: 

fin.readline() 

for l in fin:     

coords = map(float,l.split())     

coordsAt0.append(coords[:2])
After the calculation of the coordinates for the new angle of attack, I have this code which exports the new coordinates to a new .geo file.

Quote:
with open('newcoordinates.geo','w') as fout:

for i, c in enumerate(coordsAt0):

fout.write('Point (%i) = {%f, %f, 0, 1};\n'%(i+1,c[0],c[1]))
My problem is how should I implement the code that calculates the new coordinates of the airfoil at a new angle of attack?

Any hint or a simpler piece of code on how to do it would be greatly appreciated!

Regards,
CfdIntro
CfdIntro is offline   Reply With Quote

Old   November 26, 2017, 14:43
Default
  #2
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
Hi,

Looks like a familiar piece of code :-)

After line
Code:
coords = map(float,l.split())
You can just add the rotate function call
Code:
angle = 10 # degrees
origin = (0,0)
coords0 = rotate(coords[:2], origin, math.radians(angle))
coordsAt0.append(coords0)
Regards, Mikko
lcarasik and CfdIntro like this.
Flowkersma is offline   Reply With Quote

Old   December 12, 2017, 10:23
Default
  #3
New Member
 
Join Date: Oct 2017
Posts: 15
Rep Power: 8
CfdIntro is on a distinguished road
Quote:
Originally Posted by Flowkersma View Post
Hi,

Looks like a familiar piece of code :-)

After line
Code:
coords = map(float,l.split())
You can just add the rotate function call
Code:
angle = 10 # degrees
origin = (0,0)
coords0 = rotate(coords[:2], origin, math.radians(angle))
coordsAt0.append(coords0)
Regards, Mikko
Hi,

I was trying to have the script open the .txt file with the coordinates at 0 AoA, rotate the coordinates by the desired AoA, print the results into a new .txt file, then read the coordinates at the new AoA and finally export the results into a .geo format file. That being said, your suggestion saved me about 30 lines of code!

Thanks again for the tip

Regards,
CfdIntro
CfdIntro is offline   Reply With Quote

Reply

Tags
airfoil 2d, angle of attack, coordinates from .txt, python script


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ffd_control_point_2d feiyi SU2 4 September 30, 2019 12:42
High drag for airfoil compared to XFOIL and wind tunnel data Ry10 SU2 15 October 30, 2016 17:27
2D FFD Optimization RLangtry SU2 2 August 5, 2014 09:48
Automatic Simulation of 2D Airfoil Section at Different Angles of Attack Hybrid ANSYS 3 May 10, 2012 22:26
Airfoil simulation in High Angles of Attack Yasser Nabavi FLUENT 0 April 21, 2006 17:28


All times are GMT -4. The time now is 04:20.