Array of airfoils - pre-processing for CFD

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
MM1991
Posts: 13
Joined: Tue Jan 04, 2022 10:20 am

Array of airfoils - pre-processing for CFD

Post by MM1991 »

Dear Community,

Aim:
I am planning to evaluate the heat transfer and pressure drop across an array of airfoils using a CFD program. I explained my problem in another thread where I got help to generate airfoils, see https://forum.freecadweb.org/viewtopic.php?f=3&t=65029

I now instead want to make a script in order to test a large number of different types of airfoils and pitches (vertical and horizontal distance between the air foils in the domain). I have started out by writing a regular Python script using Spyder in order to get the coordinates (X,Y) for the upper and lower lines by using the equations to generate the NACA 4 digits generator http://airfoiltools.com/airfoil/naca4digit.

I have read through the some of the documentation and several tutorials, that is attached in the thread https://forum.freecadweb.org/viewtopic.php?f=22&t=4887. But I have still not managed to find out how to solve the first problem. I will explain what I intend to do in a few steps, and I hope that I can get some good feedback/advice and help as I got when asking my previous question.

Step 1 (Current)
Generate airfoil within FreeCAD using data from the NACA 4 digits generator. Introduce a sizing variable that makes it possible to determine the chord length and scale the airfoil with respect to that.

Step 2
Introduce parameters that makes it possible to decide the height and width of a plate. Place a number (input) of airfoils within the plate boundaries with given space between them (x and y distance between the airfoils given as input).


Step 3
Extrude all airfoils through the plate to generate the domain that is interesting. In order to save computational time and due to symmetry only half of the airfoils are interesting (imagine the bottom half of the first row of airfoils and the upper half of the second row of airfoils).

Step 4
Autogenerate a STL-file saved with a given input name.

First step:
I need to be able to create the shape of the airfoil within FreeCAD. I get the data for the X and Y coordinates from my script;
x_l = [0.0, 0.02564102426422143, 0.051282050056690724, 0.07692307623784783, 0.10256410256514967, 0.12820512821755137, 0.15384615387120512, 0.17948717952566595, 0.2051282051805896, 0.2307692308356979, 0.2564102564907595, 0.28205128214557834, 0.30769230779998596, 0.3333333334538361, 0.3589743591070012, 0.3846153847593688, 0.41025641041083966, 0.4358974360613254, 0.46153846171074714, 0.4871794873590338, 0.5128205130061207, 0.5384615386519489, 0.564102564296463, 0.5897435899396113, 0.615384615581344, 0.6410256412216128, 0.6666666668603692, 0.6923076924975649, 0.7179487181331493, 0.7435897437670701, 0.7692307693992717, 0.7948717950296947, 0.820512820658275, 0.8461538462849428, 0.8717948719096222, 0.8974358975322302, 0.9230769231526761, 0.9487179487708606, 0.9743589743866747, 1.0]

y_l = [[0.0, 0.09257821458441706, 0.12576068965945128, 0.14846630383991022, 0.16539111244144075, 0.17838537656831918, 0.18842133517016554, 0.19609467759384053, 0.2018079879997185, 0.2058526074366821, 0.208450219829809, 0.20977601991688874, 0.20997254861186068, 0.20915841656612066, 0.20743405067346793, 0.2048856184350998, 0.20158779022544743, 0.19760573427457684, 0.19299658981853948, 0.1878105761415747, 0.18209184181119917, 0.17587912483503407, 0.16920627277963085, 0.16210265753294986, 0.15459350967640242, 0.14670019072800114, 0.1384404168091574, 0.12982844392653087, 0.12087522262584686, 0.11158852798742831, 0.1019730696049295, 0.09203058519026719, 0.08175992068917752, 0.07115709920988653, 0.06021538061684715, 0.04892531328971603, 0.037274779270882866, 0.025249033805347716, 0.012830740101440564, -5.828670879282071e-17]
I have tried to use a loop that takes the corresponding X & Y values to generate a polygon;

Code: Select all

for i in range(1,len(x_l)):
	Polygon = Part.makePolygon([(x_l[i-1],y_l[i-1],0),(x_l[i],y_l[i],0)])
	print(i)
Part.show(Polygon)
From what I can see I only manage to create one line, that does not seem to take any of the given positions in X or Y from x_upper nor y_upper. Any advice on how I could handle this?

Kind regards,
MM
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Array of airfoils - pre-processing for CFD

Post by onekk »

Hi,

makePolygon must be supplied with a list of points, with your code you are not creating a list of points.

plus

Code: Select all

y_l = [[
is wrong.

Code: Select all

y_l = [....]

Code: Select all

points = []

for i in range(0, len(x_l)):
    point = (x_l[i], y_l[i], 0)
    points.append(point)

# if you want the profile closed add first point to the list if not comment out the line
points.append(points[0])

Polygon = Part.makePolygon(points)
Part.show(Polygon)


Alternative for loop

Code: Select all

for idx, c_x in enumerate(x_l):
    point = (c_x, y_l[idx], 0)
    points.append(point)
And alternative for a closed profile, reversing the list an negate y coordinate.

Code: Select all

for idx, c_x in enumerate(x_l):
    point = (c_x, y_l[idx], 0)
    points.append(point)

n_points = []

for point in reversed(points):
    n_points.append((point[0], point[1] * -1, 0))

points.extend(n_points)

Polygon = Part.makePolygon(points)
Part.show(Polygon)
Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
MM1991
Posts: 13
Joined: Tue Jan 04, 2022 10:20 am

Re: Array of airfoils - pre-processing for CFD

Post by MM1991 »

onekk wrote: Tue Jan 11, 2022 12:47 pm Hi,

makePolygon must be supplied with a list of points, with your code you are not creating a list of points.

plus

Code: Select all

y_l = [[
is wrong.

That was a copy-paste mistake from my side, sorry for that one.

Code: Select all

y_l = [....]

Code: Select all

points = []

for i in range(0, len(x_l)):
    point = (x_l[i], y_l[i], 0)
    points.append(point)

# if you want the profile closed add first point to the list if not comment out the line
points.append(points[0])

Polygon = Part.makePolygon(points)
Part.show(Polygon)


Alternative for loop

Code: Select all

for idx, c_x in enumerate(x_l):
    point = (c_x, y_l[idx], 0)
    points.append(point)
And alternative for a closed profile, reversing the list an negate y coordinate.

Code: Select all

for idx, c_x in enumerate(x_l):
    point = (c_x, y_l[idx], 0)
    points.append(point)

n_points = []

for point in reversed(points):
    n_points.append((point[0], point[1] * -1, 0))

points.extend(n_points)

Polygon = Part.makePolygon(points)
Part.show(Polygon)
Regards

Carlo D.
I see my mistake regarding the points. Thank you for the help, much appreciated. I finally got it to work. FYI I used the first approach you presented to me since I was thinking for that type of solution.

I will post my code here so you can see it in case (most probably) when I might need more help.

Code: Select all

import FreeCAD
from FreeCAD import Base, Vector
import Part
from math import pi, sin, cos

DOC = FreeCAD.activeDocument()
DOC_NAME = "Pippo"

def clear_doc():
    """
    Clear the active document deleting all the objects
    """
    for obj in DOC.Objects:
        DOC.removeObject(obj.Name)

def setview():
    """Rearrange View"""
    FreeCAD.Gui.SendMsgToActiveView("ViewFit")
    FreeCAD.Gui.activeDocument().activeView().viewAxometric()


if DOC is None:
    FreeCAD.newDocument(DOC_NAME)
    FreeCAD.setActiveDocument(DOC_NAME)
    DOC = FreeCAD.activeDocument()

else:

    clear_doc()

# EPS= tolerance to use to cut the parts
EPS = 0.10
EPS_C = EPS * -0.5

x_l = [0.0, 0.005025126442071894, 0.010050252331580046, 0.01507537811410561, 0.020100503835442318, 0.02512562951427127, 0.030150755160656205, 0.035175880780869924, 0.04020100637919822, 0.04522613195876145, 0.05025125752194019, 0.05527638307061694, 0.06030150860632311, 0.06532663413033356, 0.07035175964372974, 0.07537688514744387, 0.08040201064229034, 0.08542713612898889, 0.09045226160818201, 0.09547738708044819, 0.10050251256261035, 0.10552763818867451, 0.11055276381467101, 0.11557788944060485, 0.12060301506648068, 0.12562814069230285, 0.1306532663180755, 0.13567839194380235, 0.14070351756948704, 0.14572864319513296, 0.15075376882074332, 0.15577889444632118, 0.16080402007186942, 0.16582914569739085, 0.17085427132288805, 0.17587939694836363, 0.18090452257381992, 0.18592964819925928, 0.19095477382468393, 0.19597989945009606, 0.2010050250754976, 0.20603015070089067, 0.2110552763262771, 0.21608040195165878, 0.2211055275770375, 0.22613065320241493, 0.23115577882779276, 0.2361809044531726, 0.24120603007855607, 0.24623115570394463, 0.25125628132933975, 0.2562814069547429, 0.26130653258015535, 0.2663316582055785, 0.2713567838310138, 0.2763819094564623, 0.28140703508192527, 0.28643216070740407, 0.29145728633289963, 0.29648241195841324, 0.301507537583946, 0.3065326632094989, 0.31155778883507307, 0.3165829144606694, 0.321608040086289, 0.32663316571193285, 0.3316582913376018, 0.33668341696329684, 0.3417085425890188, 0.34673366821476864, 0.35175879384054715, 0.35678391946635507, 0.3618090450921934, 0.36683417071806285, 0.3718592963439642, 0.37688442196989813, 0.3819095475958655, 0.3869346732218669, 0.39195979884790316, 0.3969849244739749, 0.4020100501000827, 0.4070351757262274, 0.41206030135240956, 0.4170854269786298, 0.4221105526048888, 0.42713567823118703, 0.43216080385752514, 0.4371859294839038, 0.44221105511032344, 0.4472361807367846, 0.452261306363288, 0.457286431989834, 0.46231155761642323, 0.46733668324305616, 0.4723618088697332, 0.47738693449645503, 0.48241206012322196, 0.4874371857500346, 0.49246231137689334, 0.4974874370037986, 0.502512562630751, 0.5075376882577507, 0.5125628138847985, 0.5175879395118946, 0.5226130651390395, 0.5276381907662334, 0.532663316393477, 0.5376884420207707, 0.5427135676481147, 0.5477386932755096, 0.5527638189029558, 0.5577889445304534, 0.562814070158003, 0.567839195785605, 0.5728643214132598, 0.5778894470409678, 0.582914572668729, 0.5879396982965444, 0.5929648239244139, 0.597989949552338, 0.6030150751803172, 0.6080402008083514, 0.6130653264364416, 0.6180904520645878, 0.6231155776927905, 0.6281407033210499, 0.6331658289493663, 0.6381909545777404, 0.6432160802061724, 0.6482412058346626, 0.6532663314632113, 0.658291457091819, 0.6633165827204861, 0.6683417083492129, 0.6733668339779998, 0.6783919596068472, 0.6834170852357552, 0.6884422108647246, 0.6934673364937555, 0.6984924621228483, 0.7035175877520036, 0.7085427133812214, 0.7135678390105026, 0.7185929646398472, 0.7236180902692557, 0.7286432158987287, 0.7336683415282663, 0.7386934671578691, 0.7437185927875376, 0.7487437184172722, 0.7537688440470731, 0.7587939696769409, 0.7638190953068761, 0.7688442209368791, 0.7738693465669504, 0.7788944721970903, 0.7839195978272996, 0.7889447234575784, 0.7939698490879274, 0.7989949747183471, 0.8040201003488381, 0.8090452259794007, 0.8140703516100354, 0.8190954772407429, 0.8241206028715238, 0.8291457285023784, 0.8341708541333075, 0.8391959797643115, 0.844221105395391, 0.8492462310265466, 0.854271356657779, 0.8592964822890887, 0.8643216079204763, 0.8693467335519425, 0.8743718591834879, 0.8793969848151133, 0.8844221104468191, 0.8894472360786061, 0.894472361710475, 0.8994974873424265, 0.9045226129744615, 0.9095477386065803, 0.9145728642387839, 0.9195979898710731, 0.9246231155034486, 0.9296482411359112, 0.9346733667684616, 0.9396984924011006, 0.9447236180338292, 0.9497487436666482, 0.9547738692995582, 0.9597989949325604, 0.9648241205656554, 0.9698492461988443, 0.9748743718321279, 0.9798994974655072, 0.9849246230989831, 0.9899497487325566, 0.9949748743662284, 1.0]
y_l = [0.0, -0.04284981654890956, -0.05977218671601489, -0.07239852533034395, -0.08278396852776697, -0.0917248260471896, -0.0996297064290181, -0.10674151700621234, -0.11321867402161037, -0.1191713426550491, -0.1246798469808652, -0.1298049263246729, -0.1345938601257772, -0.13908432982435873, -0.14330696281720842, -0.1472870697590824, -0.15104586740721035, -0.15460136179236456, -0.15796900037687908, -0.1611621630233855, -0.1641925379479105, -0.16707041396588215, -0.1698049107505826, -0.17240416244800713, -0.1748754657000664, -0.17722540016558633, -0.17945992753674295, -0.18158447356262794, -0.18360399651390114, -0.18552304473131445, -0.18734580531287678, -0.1890761455523981, -0.1907176484063397, -0.1922736430082731, -0.19374723105079877, -0.19514130969904692, -0.19645859157731638, -0.1977016222732263, -0.19887279572615402, -0.19997436780436256, -0.2010084683247764, -0.20197711172832558, -0.20288220659020875, -0.20372556411681536, -0.20450890575823194, -0.20523387004630822, -0.2059020187524541, -0.2065148424460964, -0.20707376552358786, -0.20758015076795297, -0.20803530349188334, -0.20844047530961277, -0.20879686757751245, -0.2091056345382892, -0.20936788619940852, -0.20958469097269736, -0.20975707809890556, -0.2098860398782581, -0.2099725337256421, -0.21001748406699108, -0.21002178409160954, -0.2099862973735936, -0.20991185937410362, -0.20979927883501978, -0.20964933907342487, -0.20946279918540936, -0.20924039516683982, -0.20898284095798836, -0.2086908294182492, -0.20836503323658007, -0.20800610578277062, -0.20761468190417467, -0.20719137867211507, -0.206736796081793, -0.20625151770919484, -0.20573611132817973, -0.20519112949066182, -0.2046171100725472, -0.20401457678786503, -0.20338403967332885, -0.20272599554538026, -0.20204092843160043, -0.20132930997822712, -0.20059159983537125, -0.19982824602141144, -0.19903968526792104, -0.19822634334638814, -0.1973886353778858, -0.19652696612677087, -0.19564173027940435, -0.1947333127088179, -0.1938020887261818, -0.19284842431987156, -0.1918726763828718, -0.19087519292920427, -0.18985631330002234, -0.18881636835996846, -0.1877556806843498, -0.18667456473765223, -0.1855733270438779, -0.18445226634915898, -0.18331167377707103, -0.18215183297704418, -0.18097302026624104, -0.1797755047652521, -0.17855954852793157, -0.17732540666568333, -0.17607332746648197, -0.17480355250889992, -0.17351631677139331, -0.17221184873708734, -0.17089037049428377, -0.16955209783290204, -0.1681972403370558, -0.16682600147394872, -0.16543857867926975, -0.16403516343925414, -0.16261594136956659, -0.16118109229115835, -0.1597307903032359, -0.1582652038534771, -0.15678449580561865, -0.15528882350453604, -0.15377833883892672, -0.15225318830170576, -0.15071351304821246, -0.1491594489523275, -0.14759112666058766, -0.14600867164438927, -0.14441220425035728, -0.14280183974896235, -0.14117768838145825, -0.1395398554052083, -0.13788844113747092, -0.13622354099770648, -0.1345452455484647, -0.13285364053491355, -0.13114880692305975, -0.1294308209367197, -0.1276997540932836, -0.1259556732383261, -0.12419864057910496, -0.1224287137169932, -0.12064594567888545, -0.11885038494761681, -0.1170420754914334, -0.11522105679254979, -0.11338736387482752, -0.11154102733060785, -0.10968207334672976, -0.10781052372976403, -0.10592639593049079, -0.10402970306764958, -0.10212045395098664, -0.10019865310362591, -0.09826430078378737, -0.09631739300587559, -0.0943579215609611, -0.09238587403667545, -0.09040123383654083, -0.08840398019875363, -0.08639408821443899, -0.08437152884539866, -0.08233626894136373, -0.08028827125677401, -0.07822749446709627, -0.07615389318469871, -0.07406741797429556, -0.07196801536797645, -0.06985562787983313, -0.06773019402019827, -0.0655916483095066, -0.06343992129179303, -0.061274939547837394, -0.059096625707968226, -0.05690489846453519, -0.05469967258406216, -0.05248085891908919, -0.05024836441971434, -0.04800209214484382, -0.04574194127315998, -0.04346780711381527, -0.041179581116860695, -0.03887715088341661, -0.0365604001755944, -0.0342292089261751, -0.03188345324805307, -0.0295230054434523, -0.027147734012919186, -0.024757503664102922, -0.022352175320326042, -0.019931606128950768, -0.017495649469550664, -0.015044154961890389, -0.012576968473718534, -0.010093932128381571, -0.007594884312261131, -0.005079659682041561, -0.0025480891718105917, 5.828670879282071e-17]
x_u = [0.0, 0.005025124814209513, 0.010050250180982769, 0.015075375654738609, 0.02010050118968331, 0.025125626767135766, 0.030150752377032235, 0.035175878013099925, 0.04020100367105304, 0.04522612934777122, 0.05025125504087388, 0.05527638074847854, 0.060301506469053766, 0.06532663220132474, 0.07035175794420996, 0.07537688369677725, 0.08040200945821217, 0.08542713522779502, 0.09045226100488332, 0.09547738678889854, 0.1005025125630178, 0.10552763819323503, 0.11055276382351996, 0.11557788945386752, 0.12060301508427308, 0.1256281407147323, 0.1306532663452411, 0.13567839197579565, 0.14070351760639235, 0.14572864323702783, 0.15075376886769892, 0.15577889449840246, 0.1608040201291356, 0.16582914575989557, 0.17085427139067977, 0.17587939702148564, 0.18090452265231075, 0.18592964828315278, 0.19095477391400953, 0.19597989954487885, 0.2010050251757587, 0.20603015080664702, 0.211055276437542, 0.2160804020684417, 0.22110552769934444, 0.2261306533302484, 0.23115577896115197, 0.23618090459205351, 0.24120603022295145, 0.24623115585384434, 0.25125628148473056, 0.2562814071156089, 0.26130653274647786, 0.266331658377336, 0.2713567840081822, 0.27638190963901516, 0.2814070352698335, 0.28643216090063617, 0.29145728653142194, 0.2964824121621898, 0.3015075377929385, 0.3065326634236669, 0.3115577890543742, 0.3165829146850592, 0.32160804031572104, 0.32663316594635866, 0.3316582915769711, 0.33668341720755746, 0.34170854283811686, 0.34673366846864845, 0.3517587940991514, 0.3567839197296248, 0.3618090453600679, 0.3668341709904798, 0.3718592966208599, 0.37688442225120744, 0.3819095478815214, 0.38693467351180144, 0.39195979914204665, 0.3969849247722563, 0.4020100504024299, 0.40703517603256656, 0.41206030166266583, 0.417085427292727, 0.4221105529227494, 0.4271356785527326, 0.43216080418267583, 0.43718592981257864, 0.44221105544244044, 0.4472361810722606, 0.4522613067020387, 0.457286432331774, 0.4623115579614662, 0.46733668359111474, 0.472361809220719, 0.47738693485027867, 0.48241206047979307, 0.4874371861092619, 0.4924623117386846, 0.49748743736806067, 0.5025125629973897, 0.5075376886266714, 0.512562814255905, 0.5175879398850903, 0.5226130655142269, 0.5276381911433142, 0.5326633167723521, 0.5376884424013398, 0.5427135680302773, 0.5477386936591638, 0.5527638192879991, 0.5577889449167828, 0.5628140705455146, 0.567839196174194, 0.5728643218028207, 0.5778894474313941, 0.5829145730599141, 0.5879396986883803, 0.5929648243167922, 0.5979899499451495, 0.6030150755734518, 0.6080402012016988, 0.61306532682989, 0.6180904524580253, 0.6231155780861041, 0.6281407037141261, 0.6331658293420909, 0.6381909549699982, 0.6432160805978477, 0.648241206225639, 0.6532663318533717, 0.6582914574810452, 0.6633165831086596, 0.6683417087362142, 0.6733668343637088, 0.6783919599911429, 0.6834170856185161, 0.6884422112458282, 0.6934673368730787, 0.6984924625002673, 0.7035175881273935, 0.7085427137544569, 0.7135678393814572, 0.718592965008394, 0.7236180906352669, 0.7286432162620754, 0.733668341888819, 0.7386934675154977, 0.7437185931421106, 0.7487437187686575, 0.753768844395138, 0.7587939700215517, 0.7638190956478977, 0.7688442212741762, 0.7738693469003863, 0.7788944725265279, 0.7839195981526, 0.7889447237786025, 0.7939698494045349, 0.7989949750303966, 0.8040201006561871, 0.809045226281906, 0.8140703519075525, 0.8190954775331264, 0.824120603158627, 0.8291457287840538, 0.8341708544094062, 0.8391959800346834, 0.8442211056598854, 0.8492462312850112, 0.8542713569100603, 0.859296482535032, 0.8643216081599256, 0.8693467337847409, 0.8743718594094769, 0.879396985034133, 0.8844221106587087, 0.8894472362832029, 0.8944723619076155, 0.8994974875319454, 0.9045226131561919, 0.9095477387803544, 0.9145728644044321, 0.9195979900284244, 0.9246231156523304, 0.9296482412761492, 0.9346733668998802, 0.9396984925235224, 0.9447236181470753, 0.9497487437705378, 0.9547738693939092, 0.9597989950171885, 0.9648241206403747, 0.9698492462634672, 0.9748743718864651, 0.9798994975093672, 0.9849246231321728, 0.9899497487548807, 0.9949748743774901, 1.0]
y_u = [0.0, 0.042849816744864204, 0.059772187097823434, 0.07239852588790564, 0.08278396925098104, 0.0917248269259553, 0.09962970745323467, 0.10674151816577901, 0.1132186753064264, 0.11917134405501374, 0.12467984848587771, 0.1298049279246325, 0.13459386181058317, 0.13908433158391023, 0.14330696464140477, 0.14728707163782284, 0.15104586933039413, 0.15460136374989086, 0.15796900235864722, 0.16116216501929473, 0.1641925399479099, 0.1670704159658067, 0.16980491275030765, 0.17240416444740794, 0.1748754676990183, 0.17722540216396457, 0.1794599295344229, 0.18158447555948484, 0.18360399850981035, 0.18552304672615125, 0.18734580730651643, 0.1890761475447159, 0.190717650397211, 0.19227364499757316, 0.1937472330384029, 0.1951413116848304, 0.19645859356115453, 0.19770162425499443, 0.1988727977057274, 0.19997436978161653, 0.2010084702995862, 0.20197711370056656, 0.20288220855975622, 0.20372556608354458, 0.20450890772201824, 0.20523387200702686, 0.2059020207099804, 0.2065148444003057, 0.2070737674743554, 0.2075801527151541, 0.2080353054353933, 0.2084404772493069, 0.20879686951326606, 0.20910563646997757, 0.2093678881269069, 0.20958469289588114, 0.20975708001765, 0.20988604179243847, 0.2099725356351337, 0.21001748597166928, 0.21002178599134957, 0.20998629926827078, 0.20991186126359324, 0.20979928071919715, 0.2096493409521653, 0.20946280105858814, 0.20924039703433225, 0.20898284281966972, 0.20869083127399482, 0.20836503508626525, 0.20800610762627064, 0.20761468374136485, 0.20719138050287067, 0.20673679790598934, 0.20625151952670726, 0.2057361131388835, 0.20519113129443223, 0.20461711186925954, 0.2040145785773946, 0.20338404145555095, 0.2027259973201702, 0.2020409301988335, 0.20132931173777863, 0.2005916015871165, 0.19982824776522576, 0.1990396870036797, 0.1982263450739664, 0.19738863709715904, 0.19652696783761434, 0.19564173198169332, 0.19473331440242772, 0.19380209041098775, 0.19284842599574895, 0.19187267804969593, 0.1908751945868504, 0.1898563149483658, 0.18881636999888457, 0.18775568231371384, 0.18667456635733945, 0.1855733286537637, 0.1844522679491186, 0.18331167536697973, 0.1821518345567773, 0.1809730218356739, 0.17977550632425995, 0.17855955007638977, 0.17732540820346718, 0.17607332899346673, 0.17480355402496092, 0.17351631827640582, 0.17221185023092667, 0.1708903719768252, 0.16955209930402088, 0.16819724179662737, 0.1668260029218483, 0.16543858011537266, 0.16403516486343564, 0.162615942781702, 0.161181093691123, 0.15973079169090504, 0.15826520522872606, 0.1567844971683227, 0.15528882485457052, 0.15377834017616693, 0.15225318962602696, 0.15071351435949, 0.14915945025043661, 0.1475911279454037, 0.14600867291578754, 0.14441220550821304, 0.14280184099315094, 0.14117768961185492, 0.13953985662168839, 0.13788844233990968, 0.13622354218597924, 0.13454524672244678, 0.13285364169448022, 0.13114880806808632, 0.1294308220670815, 0.1276997552088559, 0.12595567433898416, 0.12419864166472414, 0.12242871478744878, 0.12064594673405271, 0.11885038598737106, 0.11704207651564998, 0.11522105780110395, 0.11338736486759456, 0.11154102830746308, 0.10968207430754849, 0.10781052467442155, 0.10592639685886242, 0.10402970397961059, 0.10212045484641234, 0.10019865398239161, 0.09826430164576835, 0.09631739385094716, 0.09435792238899854, 0.09238587484755409, 0.09040123463013597, 0.08840398097494055, 0.08639408897309299, 0.08437152958639503, 0.0823362696645778, 0.08028827196208105, 0.07822749515437159, 0.07615389385381761, 0.07406741862513333, 0.07196801600040842, 0.06985562849373458, 0.06773019461544448, 0.0655916488859729, 0.06343992184935472, 0.06127494008636975, 0.05909662622734656, 0.05690489896463479, 0.054699673064758335, 0.05248085938025724, 0.05024836486122957, 0.04800209256658152, 0.04574194167499545, 0.04346780749562381, 0.04117958147851761, 0.038877151224797186, 0.03656040049657395, 0.034229209226628914, 0.03188345352785646, 0.02952300570248055, 0.027147734251047606, 0.024757503881206806, 0.02235217551628069, 0.019931606303631482, 0.01749564962283274, 0.015044155093649128, 0.012576968583829232, 0.010093932216719533, 0.007594884378701652, 0.005079659726459943, 0.002548089194082133, -5.828670879282071e-17]
points_l = []
points_u = []
for i in range(0,len(x_l)):
	point_l = (x_l[i],y_l[i],0)
	point_u = (x_u[i],y_u[i],0)
	points_l.append(point_l)
	points_u.append(point_u)

Polygon_u = Part.makePolygon(points_u)
Polygon_l = Part.makePolygon(points_l)
Part.show(Polygon_u)
Part.show(Polygon_l)

User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Array of airfoils - pre-processing for CFD

Post by onekk »

whatever approach you will use important thing is final results.

There could be some speed considerations, as some enumeration are more demanding than others.

check if all points are used range is excluding last item, now I have no way to check python documents as I'm on mobile.

I prefer enumerate as it is more compact and return one elements so a list extraction is avoided.

and there is no index concerns as it start from 0 as list is expecting.

Feel free to ask.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
MM1991
Posts: 13
Joined: Tue Jan 04, 2022 10:20 am

Re: Array of airfoils - pre-processing for CFD

Post by MM1991 »

I have now managed to create the airfoils and the rectangle that will represent the flow domain. I am struggling with how to actually extrude the airfoils through the box that I have created.

I want to extrude the two airfoils through the box;
Airfoils
Airfoils
AirFoils_Rectangle.PNG (10.06 KiB) Viewed 2325 times
Any advice on how I could continue, how should I handle the fact that they are not a sketch on the box? Do I have to use Shapebinders somehow?

I attach the code here

Code: Select all

import FreeCAD
from FreeCAD import Base, Vector
import Part
from math import pi, sin, cos
import numpy as np

DOC = FreeCAD.activeDocument()
DOC_NAME = "Pippo"

def clear_doc():
    """
    Clear the active document deleting all the objects
    """
    for obj in DOC.Objects:
        DOC.removeObject(obj.Name)

def setview():
    """Rearrange View"""
    FreeCAD.Gui.SendMsgToActiveView("ViewFit")
    FreeCAD.Gui.activeDocument().activeView().viewAxometric()


if DOC is None:
    FreeCAD.newDocument(DOC_NAME)
    FreeCAD.setActiveDocument(DOC_NAME)
    DOC = FreeCAD.activeDocument()

else:

    clear_doc()

# EPS= tolerance to use to cut the parts
EPS = 0.10
EPS_C = EPS * -0.5
Scale_factor = 14
x_l = [0.0, 0.005025126442071894, 0.010050252331580046, 0.01507537811410561, 0.020100503835442318, 0.02512562951427127, 0.030150755160656205, 0.035175880780869924, 0.04020100637919822, 0.04522613195876145, 0.05025125752194019, 0.05527638307061694, 0.06030150860632311, 0.06532663413033356, 0.07035175964372974, 0.07537688514744387, 0.08040201064229034, 0.08542713612898889, 0.09045226160818201, 0.09547738708044819, 0.10050251256261035, 0.10552763818867451, 0.11055276381467101, 0.11557788944060485, 0.12060301506648068, 0.12562814069230285, 0.1306532663180755, 0.13567839194380235, 0.14070351756948704, 0.14572864319513296, 0.15075376882074332, 0.15577889444632118, 0.16080402007186942, 0.16582914569739085, 0.17085427132288805, 0.17587939694836363, 0.18090452257381992, 0.18592964819925928, 0.19095477382468393, 0.19597989945009606, 0.2010050250754976, 0.20603015070089067, 0.2110552763262771, 0.21608040195165878, 0.2211055275770375, 0.22613065320241493, 0.23115577882779276, 0.2361809044531726, 0.24120603007855607, 0.24623115570394463, 0.25125628132933975, 0.2562814069547429, 0.26130653258015535, 0.2663316582055785, 0.2713567838310138, 0.2763819094564623, 0.28140703508192527, 0.28643216070740407, 0.29145728633289963, 0.29648241195841324, 0.301507537583946, 0.3065326632094989, 0.31155778883507307, 0.3165829144606694, 0.321608040086289, 0.32663316571193285, 0.3316582913376018, 0.33668341696329684, 0.3417085425890188, 0.34673366821476864, 0.35175879384054715, 0.35678391946635507, 0.3618090450921934, 0.36683417071806285, 0.3718592963439642, 0.37688442196989813, 0.3819095475958655, 0.3869346732218669, 0.39195979884790316, 0.3969849244739749, 0.4020100501000827, 0.4070351757262274, 0.41206030135240956, 0.4170854269786298, 0.4221105526048888, 0.42713567823118703, 0.43216080385752514, 0.4371859294839038, 0.44221105511032344, 0.4472361807367846, 0.452261306363288, 0.457286431989834, 0.46231155761642323, 0.46733668324305616, 0.4723618088697332, 0.47738693449645503, 0.48241206012322196, 0.4874371857500346, 0.49246231137689334, 0.4974874370037986, 0.502512562630751, 0.5075376882577507, 0.5125628138847985, 0.5175879395118946, 0.5226130651390395, 0.5276381907662334, 0.532663316393477, 0.5376884420207707, 0.5427135676481147, 0.5477386932755096, 0.5527638189029558, 0.5577889445304534, 0.562814070158003, 0.567839195785605, 0.5728643214132598, 0.5778894470409678, 0.582914572668729, 0.5879396982965444, 0.5929648239244139, 0.597989949552338, 0.6030150751803172, 0.6080402008083514, 0.6130653264364416, 0.6180904520645878, 0.6231155776927905, 0.6281407033210499, 0.6331658289493663, 0.6381909545777404, 0.6432160802061724, 0.6482412058346626, 0.6532663314632113, 0.658291457091819, 0.6633165827204861, 0.6683417083492129, 0.6733668339779998, 0.6783919596068472, 0.6834170852357552, 0.6884422108647246, 0.6934673364937555, 0.6984924621228483, 0.7035175877520036, 0.7085427133812214, 0.7135678390105026, 0.7185929646398472, 0.7236180902692557, 0.7286432158987287, 0.7336683415282663, 0.7386934671578691, 0.7437185927875376, 0.7487437184172722, 0.7537688440470731, 0.7587939696769409, 0.7638190953068761, 0.7688442209368791, 0.7738693465669504, 0.7788944721970903, 0.7839195978272996, 0.7889447234575784, 0.7939698490879274, 0.7989949747183471, 0.8040201003488381, 0.8090452259794007, 0.8140703516100354, 0.8190954772407429, 0.8241206028715238, 0.8291457285023784, 0.8341708541333075, 0.8391959797643115, 0.844221105395391, 0.8492462310265466, 0.854271356657779, 0.8592964822890887, 0.8643216079204763, 0.8693467335519425, 0.8743718591834879, 0.8793969848151133, 0.8844221104468191, 0.8894472360786061, 0.894472361710475, 0.8994974873424265, 0.9045226129744615, 0.9095477386065803, 0.9145728642387839, 0.9195979898710731, 0.9246231155034486, 0.9296482411359112, 0.9346733667684616, 0.9396984924011006, 0.9447236180338292, 0.9497487436666482, 0.9547738692995582, 0.9597989949325604, 0.9648241205656554, 0.9698492461988443, 0.9748743718321279, 0.9798994974655072, 0.9849246230989831, 0.9899497487325566, 0.9949748743662284, 1.0]
y_l = [0.0, -0.04284981654890956, -0.05977218671601489, -0.07239852533034395, -0.08278396852776697, -0.0917248260471896, -0.0996297064290181, -0.10674151700621234, -0.11321867402161037, -0.1191713426550491, -0.1246798469808652, -0.1298049263246729, -0.1345938601257772, -0.13908432982435873, -0.14330696281720842, -0.1472870697590824, -0.15104586740721035, -0.15460136179236456, -0.15796900037687908, -0.1611621630233855, -0.1641925379479105, -0.16707041396588215, -0.1698049107505826, -0.17240416244800713, -0.1748754657000664, -0.17722540016558633, -0.17945992753674295, -0.18158447356262794, -0.18360399651390114, -0.18552304473131445, -0.18734580531287678, -0.1890761455523981, -0.1907176484063397, -0.1922736430082731, -0.19374723105079877, -0.19514130969904692, -0.19645859157731638, -0.1977016222732263, -0.19887279572615402, -0.19997436780436256, -0.2010084683247764, -0.20197711172832558, -0.20288220659020875, -0.20372556411681536, -0.20450890575823194, -0.20523387004630822, -0.2059020187524541, -0.2065148424460964, -0.20707376552358786, -0.20758015076795297, -0.20803530349188334, -0.20844047530961277, -0.20879686757751245, -0.2091056345382892, -0.20936788619940852, -0.20958469097269736, -0.20975707809890556, -0.2098860398782581, -0.2099725337256421, -0.21001748406699108, -0.21002178409160954, -0.2099862973735936, -0.20991185937410362, -0.20979927883501978, -0.20964933907342487, -0.20946279918540936, -0.20924039516683982, -0.20898284095798836, -0.2086908294182492, -0.20836503323658007, -0.20800610578277062, -0.20761468190417467, -0.20719137867211507, -0.206736796081793, -0.20625151770919484, -0.20573611132817973, -0.20519112949066182, -0.2046171100725472, -0.20401457678786503, -0.20338403967332885, -0.20272599554538026, -0.20204092843160043, -0.20132930997822712, -0.20059159983537125, -0.19982824602141144, -0.19903968526792104, -0.19822634334638814, -0.1973886353778858, -0.19652696612677087, -0.19564173027940435, -0.1947333127088179, -0.1938020887261818, -0.19284842431987156, -0.1918726763828718, -0.19087519292920427, -0.18985631330002234, -0.18881636835996846, -0.1877556806843498, -0.18667456473765223, -0.1855733270438779, -0.18445226634915898, -0.18331167377707103, -0.18215183297704418, -0.18097302026624104, -0.1797755047652521, -0.17855954852793157, -0.17732540666568333, -0.17607332746648197, -0.17480355250889992, -0.17351631677139331, -0.17221184873708734, -0.17089037049428377, -0.16955209783290204, -0.1681972403370558, -0.16682600147394872, -0.16543857867926975, -0.16403516343925414, -0.16261594136956659, -0.16118109229115835, -0.1597307903032359, -0.1582652038534771, -0.15678449580561865, -0.15528882350453604, -0.15377833883892672, -0.15225318830170576, -0.15071351304821246, -0.1491594489523275, -0.14759112666058766, -0.14600867164438927, -0.14441220425035728, -0.14280183974896235, -0.14117768838145825, -0.1395398554052083, -0.13788844113747092, -0.13622354099770648, -0.1345452455484647, -0.13285364053491355, -0.13114880692305975, -0.1294308209367197, -0.1276997540932836, -0.1259556732383261, -0.12419864057910496, -0.1224287137169932, -0.12064594567888545, -0.11885038494761681, -0.1170420754914334, -0.11522105679254979, -0.11338736387482752, -0.11154102733060785, -0.10968207334672976, -0.10781052372976403, -0.10592639593049079, -0.10402970306764958, -0.10212045395098664, -0.10019865310362591, -0.09826430078378737, -0.09631739300587559, -0.0943579215609611, -0.09238587403667545, -0.09040123383654083, -0.08840398019875363, -0.08639408821443899, -0.08437152884539866, -0.08233626894136373, -0.08028827125677401, -0.07822749446709627, -0.07615389318469871, -0.07406741797429556, -0.07196801536797645, -0.06985562787983313, -0.06773019402019827, -0.0655916483095066, -0.06343992129179303, -0.061274939547837394, -0.059096625707968226, -0.05690489846453519, -0.05469967258406216, -0.05248085891908919, -0.05024836441971434, -0.04800209214484382, -0.04574194127315998, -0.04346780711381527, -0.041179581116860695, -0.03887715088341661, -0.0365604001755944, -0.0342292089261751, -0.03188345324805307, -0.0295230054434523, -0.027147734012919186, -0.024757503664102922, -0.022352175320326042, -0.019931606128950768, -0.017495649469550664, -0.015044154961890389, -0.012576968473718534, -0.010093932128381571, -0.007594884312261131, -0.005079659682041561, -0.0025480891718105917, 5.828670879282071e-17]
x_u = [0.0, 0.005025124814209513, 0.010050250180982769, 0.015075375654738609, 0.02010050118968331, 0.025125626767135766, 0.030150752377032235, 0.035175878013099925, 0.04020100367105304, 0.04522612934777122, 0.05025125504087388, 0.05527638074847854, 0.060301506469053766, 0.06532663220132474, 0.07035175794420996, 0.07537688369677725, 0.08040200945821217, 0.08542713522779502, 0.09045226100488332, 0.09547738678889854, 0.1005025125630178, 0.10552763819323503, 0.11055276382351996, 0.11557788945386752, 0.12060301508427308, 0.1256281407147323, 0.1306532663452411, 0.13567839197579565, 0.14070351760639235, 0.14572864323702783, 0.15075376886769892, 0.15577889449840246, 0.1608040201291356, 0.16582914575989557, 0.17085427139067977, 0.17587939702148564, 0.18090452265231075, 0.18592964828315278, 0.19095477391400953, 0.19597989954487885, 0.2010050251757587, 0.20603015080664702, 0.211055276437542, 0.2160804020684417, 0.22110552769934444, 0.2261306533302484, 0.23115577896115197, 0.23618090459205351, 0.24120603022295145, 0.24623115585384434, 0.25125628148473056, 0.2562814071156089, 0.26130653274647786, 0.266331658377336, 0.2713567840081822, 0.27638190963901516, 0.2814070352698335, 0.28643216090063617, 0.29145728653142194, 0.2964824121621898, 0.3015075377929385, 0.3065326634236669, 0.3115577890543742, 0.3165829146850592, 0.32160804031572104, 0.32663316594635866, 0.3316582915769711, 0.33668341720755746, 0.34170854283811686, 0.34673366846864845, 0.3517587940991514, 0.3567839197296248, 0.3618090453600679, 0.3668341709904798, 0.3718592966208599, 0.37688442225120744, 0.3819095478815214, 0.38693467351180144, 0.39195979914204665, 0.3969849247722563, 0.4020100504024299, 0.40703517603256656, 0.41206030166266583, 0.417085427292727, 0.4221105529227494, 0.4271356785527326, 0.43216080418267583, 0.43718592981257864, 0.44221105544244044, 0.4472361810722606, 0.4522613067020387, 0.457286432331774, 0.4623115579614662, 0.46733668359111474, 0.472361809220719, 0.47738693485027867, 0.48241206047979307, 0.4874371861092619, 0.4924623117386846, 0.49748743736806067, 0.5025125629973897, 0.5075376886266714, 0.512562814255905, 0.5175879398850903, 0.5226130655142269, 0.5276381911433142, 0.5326633167723521, 0.5376884424013398, 0.5427135680302773, 0.5477386936591638, 0.5527638192879991, 0.5577889449167828, 0.5628140705455146, 0.567839196174194, 0.5728643218028207, 0.5778894474313941, 0.5829145730599141, 0.5879396986883803, 0.5929648243167922, 0.5979899499451495, 0.6030150755734518, 0.6080402012016988, 0.61306532682989, 0.6180904524580253, 0.6231155780861041, 0.6281407037141261, 0.6331658293420909, 0.6381909549699982, 0.6432160805978477, 0.648241206225639, 0.6532663318533717, 0.6582914574810452, 0.6633165831086596, 0.6683417087362142, 0.6733668343637088, 0.6783919599911429, 0.6834170856185161, 0.6884422112458282, 0.6934673368730787, 0.6984924625002673, 0.7035175881273935, 0.7085427137544569, 0.7135678393814572, 0.718592965008394, 0.7236180906352669, 0.7286432162620754, 0.733668341888819, 0.7386934675154977, 0.7437185931421106, 0.7487437187686575, 0.753768844395138, 0.7587939700215517, 0.7638190956478977, 0.7688442212741762, 0.7738693469003863, 0.7788944725265279, 0.7839195981526, 0.7889447237786025, 0.7939698494045349, 0.7989949750303966, 0.8040201006561871, 0.809045226281906, 0.8140703519075525, 0.8190954775331264, 0.824120603158627, 0.8291457287840538, 0.8341708544094062, 0.8391959800346834, 0.8442211056598854, 0.8492462312850112, 0.8542713569100603, 0.859296482535032, 0.8643216081599256, 0.8693467337847409, 0.8743718594094769, 0.879396985034133, 0.8844221106587087, 0.8894472362832029, 0.8944723619076155, 0.8994974875319454, 0.9045226131561919, 0.9095477387803544, 0.9145728644044321, 0.9195979900284244, 0.9246231156523304, 0.9296482412761492, 0.9346733668998802, 0.9396984925235224, 0.9447236181470753, 0.9497487437705378, 0.9547738693939092, 0.9597989950171885, 0.9648241206403747, 0.9698492462634672, 0.9748743718864651, 0.9798994975093672, 0.9849246231321728, 0.9899497487548807, 0.9949748743774901, 1.0]
y_u = [0.0, 0.042849816744864204, 0.059772187097823434, 0.07239852588790564, 0.08278396925098104, 0.0917248269259553, 0.09962970745323467, 0.10674151816577901, 0.1132186753064264, 0.11917134405501374, 0.12467984848587771, 0.1298049279246325, 0.13459386181058317, 0.13908433158391023, 0.14330696464140477, 0.14728707163782284, 0.15104586933039413, 0.15460136374989086, 0.15796900235864722, 0.16116216501929473, 0.1641925399479099, 0.1670704159658067, 0.16980491275030765, 0.17240416444740794, 0.1748754676990183, 0.17722540216396457, 0.1794599295344229, 0.18158447555948484, 0.18360399850981035, 0.18552304672615125, 0.18734580730651643, 0.1890761475447159, 0.190717650397211, 0.19227364499757316, 0.1937472330384029, 0.1951413116848304, 0.19645859356115453, 0.19770162425499443, 0.1988727977057274, 0.19997436978161653, 0.2010084702995862, 0.20197711370056656, 0.20288220855975622, 0.20372556608354458, 0.20450890772201824, 0.20523387200702686, 0.2059020207099804, 0.2065148444003057, 0.2070737674743554, 0.2075801527151541, 0.2080353054353933, 0.2084404772493069, 0.20879686951326606, 0.20910563646997757, 0.2093678881269069, 0.20958469289588114, 0.20975708001765, 0.20988604179243847, 0.2099725356351337, 0.21001748597166928, 0.21002178599134957, 0.20998629926827078, 0.20991186126359324, 0.20979928071919715, 0.2096493409521653, 0.20946280105858814, 0.20924039703433225, 0.20898284281966972, 0.20869083127399482, 0.20836503508626525, 0.20800610762627064, 0.20761468374136485, 0.20719138050287067, 0.20673679790598934, 0.20625151952670726, 0.2057361131388835, 0.20519113129443223, 0.20461711186925954, 0.2040145785773946, 0.20338404145555095, 0.2027259973201702, 0.2020409301988335, 0.20132931173777863, 0.2005916015871165, 0.19982824776522576, 0.1990396870036797, 0.1982263450739664, 0.19738863709715904, 0.19652696783761434, 0.19564173198169332, 0.19473331440242772, 0.19380209041098775, 0.19284842599574895, 0.19187267804969593, 0.1908751945868504, 0.1898563149483658, 0.18881636999888457, 0.18775568231371384, 0.18667456635733945, 0.1855733286537637, 0.1844522679491186, 0.18331167536697973, 0.1821518345567773, 0.1809730218356739, 0.17977550632425995, 0.17855955007638977, 0.17732540820346718, 0.17607332899346673, 0.17480355402496092, 0.17351631827640582, 0.17221185023092667, 0.1708903719768252, 0.16955209930402088, 0.16819724179662737, 0.1668260029218483, 0.16543858011537266, 0.16403516486343564, 0.162615942781702, 0.161181093691123, 0.15973079169090504, 0.15826520522872606, 0.1567844971683227, 0.15528882485457052, 0.15377834017616693, 0.15225318962602696, 0.15071351435949, 0.14915945025043661, 0.1475911279454037, 0.14600867291578754, 0.14441220550821304, 0.14280184099315094, 0.14117768961185492, 0.13953985662168839, 0.13788844233990968, 0.13622354218597924, 0.13454524672244678, 0.13285364169448022, 0.13114880806808632, 0.1294308220670815, 0.1276997552088559, 0.12595567433898416, 0.12419864166472414, 0.12242871478744878, 0.12064594673405271, 0.11885038598737106, 0.11704207651564998, 0.11522105780110395, 0.11338736486759456, 0.11154102830746308, 0.10968207430754849, 0.10781052467442155, 0.10592639685886242, 0.10402970397961059, 0.10212045484641234, 0.10019865398239161, 0.09826430164576835, 0.09631739385094716, 0.09435792238899854, 0.09238587484755409, 0.09040123463013597, 0.08840398097494055, 0.08639408897309299, 0.08437152958639503, 0.0823362696645778, 0.08028827196208105, 0.07822749515437159, 0.07615389385381761, 0.07406741862513333, 0.07196801600040842, 0.06985562849373458, 0.06773019461544448, 0.0655916488859729, 0.06343992184935472, 0.06127494008636975, 0.05909662622734656, 0.05690489896463479, 0.054699673064758335, 0.05248085938025724, 0.05024836486122957, 0.04800209256658152, 0.04574194167499545, 0.04346780749562381, 0.04117958147851761, 0.038877151224797186, 0.03656040049657395, 0.034229209226628914, 0.03188345352785646, 0.02952300570248055, 0.027147734251047606, 0.024757503881206806, 0.02235217551628069, 0.019931606303631482, 0.01749564962283274, 0.015044155093649128, 0.012576968583829232, 0.010093932216719533, 0.007594884378701652, 0.005079659726459943, 0.002548089194082133, -5.828670879282071e-17]

x_l = Scale_factor*np.array(x_l)
y_l = Scale_factor*np.array(y_l)
x_u = Scale_factor*np.array(x_u)
y_u = Scale_factor*np.array(y_u)
thickness = max(y_u)*2

points_l = []
points_u = []
for i in range(0,len(x_l)):
	point_l = (x_l[i],y_l[i],0)
	point_u = (x_u[i],y_u[i],0)
	points_l.append(point_l)
	points_u.append(point_u)
points_l.append(points_l[0])
points_u.append(points_u[0])

Polygon_u = Part.makePolygon(points_u) 
Polygon_l = Part.makePolygon(points_l)

## Translate polygon
dX = 4  #mm spacing between the Airfoils in horizontal direction
dY = 8 #mm spacing between the Airfoils in vertical direction 
chord = Scale_factor
P_L = (chord + dX)/2
P_T = dY + thickness
Polygon_l.translate((P_L,P_T,0))
Part.show(Polygon_u)
Part.show(Polygon_l)


## Deciding the number of airfoils and the length of the fluid domain
X_L = 40  ## mm inlet, empty
X_T = 60 ##mm outlet, empty
nr_airfoils = 10 ## The number of air foils in the first row
depth_airfoils = nr_airfoils * 2 * P_L - dX  ## The length from the first point of the first airfoil to the last point of the last airfoil
total_depth = X_L + depth_airfoils + X_T  ## Total domain length for CFD
fluid_domain = Part.makeBox(total_depth,P_T,1)
fluid_domain.translate((-X_L,0,0))
Part.show(fluid_domain)


print(thickness)

Best Regards,
MM
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Array of airfoils - pre-processing for CFD

Post by onekk »

MM1991 wrote: Wed Jan 12, 2022 9:26 am I want to extrude the two airfoils through the box;
You have to make a solid, so you have wires, obtained by makePolygon, you have to:
  1. Create a Face
  2. extrude the Face
  3. visualize the Face
here the steps, in code:

  1. Code: Select all

    face1 = Part.Face(Part.Wire(Polygon_u)) 
  2. Code: Select all

    solid1 = face1.extrude(Vector(0,0,10))
  3. Code: Select all

    Part.show(solid1)
Place the code below after

Code: Select all

Polygon_l.translate((P_L,P_T,0))
Here the code:

Code: Select all


face1 = Part.Face(Part.Wire(Polygon_u)) 
face2 = Part.Face(Part.Wire(Polygon_l))

solid1 = face1.extrude(Vector(0,0,10))
solid2 = face2.extrude(Vector(0,0,10))

Part.show(solid1)
Part.show(solid2)


Some considerations:
Hope it helps

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
MM1991
Posts: 13
Joined: Tue Jan 04, 2022 10:20 am

Re: Array of airfoils - pre-processing for CFD

Post by MM1991 »

onekk wrote: Wed Jan 12, 2022 10:22 am
MM1991 wrote: Wed Jan 12, 2022 9:26 am I want to extrude the two airfoils through the box;
You have to make a solid, so you have wires, obtained by makePolygon, you have to:
  1. Create a Face
  2. extrude the Face
  3. visualize the Face
here the steps, in code:

  1. Code: Select all

    face1 = Part.Face(Part.Wire(Polygon_u)) 
  2. Code: Select all

    solid1 = face1.extrude(Vector(0,0,10))
  3. Code: Select all

    Part.show(solid1)
Place the code below after

Code: Select all

Polygon_l.translate((P_L,P_T,0))
Here the code:

Code: Select all


face1 = Part.Face(Part.Wire(Polygon_u)) 
face2 = Part.Face(Part.Wire(Polygon_l))

solid1 = face1.extrude(Vector(0,0,10))
solid2 = face2.extrude(Vector(0,0,10))

Part.show(solid1)
Part.show(solid2)


Some considerations:
Hope it helps

Regards

Carlo D.
Thank you for the help. I have been working with the script and have got stuck on how to apply to linear pattern. I have not managed to find some good examples on how to implement it in a code. I tried to do it manually and to see how the code actually looks and then implement it myself;

Code: Select all

face_1_pattern = DOC.addObject('PartDesign::LinearPattern','LinearPattern')
face_1_pattern.Originals = [DOC.getObject('face1')]
face_1_pattern.Direction = (DOC.getObject('face1'),['H_Axis'])
face_1_pattern.Length = 100
face_1_pattern.Occurrences = 2
I get the following error
<Exception> type of first element in tuple must be 'DocumentObject', not NoneType
. What I am doing wrong?
MM1991
Posts: 13
Joined: Tue Jan 04, 2022 10:20 am

Re: Array of airfoils - pre-processing for CFD

Post by MM1991 »

I finally managed to solve the problem, maybe by using the worst coding ever;

Code: Select all

solids_upper = []
solids_lower = []
for i in range(0,nr_airfoils):
	face_upper = Part.Face(Part.Wire(Polygon_u))
	face_lower = Part.Face(Part.Wire(Polygon_l))
	face_upp_new = face_upper.translate((i*2*P_L,0,0))
	face_lower_new = face_lower.translate((i*2*P_L,0,0))
	solids_upper.append(face_upp_new.extrude(Vector(0,0,10)))
	solids_lower.append(face_lower_new.extrude(Vector(0,0,10)))
solids =solids_upper+solids_lower
trimmed_shape= fluid_domain.cut((solids))
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Array of airfoils - pre-processing for CFD

Post by onekk »

MM1991 wrote: Fri Jan 14, 2022 10:27 am I finally managed to solve the problem, maybe by using the worst coding ever;

Code: Select all

face_upper = Part.Face(Part.Wire(Polygon_u)).extrude(Vector(0,0,10))
face_lower = Part.Face(Part.Wire(Polygon_l)).extrude(Vector(0,0,10))

solids_upper = []
solids_lower = []

for idx in range(0, nr_airfoils):
    face_upper_new = face_upper.copy()
    face_upper_new.Placement = Placement(Vector(idx * 2 * P_L, 0, 0), Rotation(0,0,0))

    face_lower_new = face_lower.copy()
    face_lower_new.Placement = Placement(Vector(idx *  2 * P_L, 0, 0), Rotation(0,0,0))

    solids_upper.append(face_upper_new)
    solids_lower.append(face_lower_new)

solids = solids_upper + solids_lower
trimmed_shape = fluid_domain.cut((solids))

Part.show(trimmed_shape, "trimmed_shape")

Not very different, only:
  1. more readable some newlines and spaces around operators,
  2. creation of solids outside the loop, simply copying them is enough.
  3. I have used Placement property, it is more useable, and permit complex transformation, in one line,
  4. I have avoided the i as the index, it is easy to not see it, and on some fonts it is very small.
Many of them are simply cosmetics, to correctly use them you must have:

Code: Select all

from FreeCAD import Placement, Rotation, Vector
in the import statements, to shorten writings, (it avoid to prepend FreeCAD.) to all Vector, Rotation and Placement elements.

If you intend to code, readability is important, so spacing things, and also make "block of code" visible, using blank lines when appropriate.

Another little things, set your editor to use 4 spaces instead of "Tabs", it will be more in line with recommendations of PEP8 (if you search for "Python PEP8" you will find some interesting things.)

Serious editors, could even do some "syntax checking" using PEP8 rules. I suppose Atom will do and maybe even others, but I've abandoned java based editors to use "old school" Emacs as it is more "stable and reliable", but as usual this is a "matter of taste".

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
MM1991
Posts: 13
Joined: Tue Jan 04, 2022 10:20 am

Re: Array of airfoils - pre-processing for CFD

Post by MM1991 »

onekk wrote: Fri Jan 14, 2022 11:22 am
MM1991 wrote: Fri Jan 14, 2022 10:27 am I finally managed to solve the problem, maybe by using the worst coding ever;

Code: Select all

face_upper = Part.Face(Part.Wire(Polygon_u)).extrude(Vector(0,0,10))
face_lower = Part.Face(Part.Wire(Polygon_l)).extrude(Vector(0,0,10))

solids_upper = []
solids_lower = []

for idx in range(0, nr_airfoils):
    face_upper_new = face_upper.copy()
    face_upper_new.Placement = Placement(Vector(idx * 2 * P_L, 0, 0), Rotation(0,0,0))

    face_lower_new = face_lower.copy()
    face_lower_new.Placement = Placement(Vector(idx *  2 * P_L, 0, 0), Rotation(0,0,0))

    solids_upper.append(face_upper_new)
    solids_lower.append(face_lower_new)

solids = solids_upper + solids_lower
trimmed_shape = fluid_domain.cut((solids))

Part.show(trimmed_shape, "trimmed_shape")

Not very different, only:
  1. more readable some newlines and spaces around operators,
  2. creation of solids outside the loop, simply copying them is enough.
  3. I have used Placement property, it is more useable, and permit complex transformation, in one line,
  4. I have avoided the i as the index, it is easy to not see it, and on some fonts it is very small.
Many of them are simply cosmetics, to correctly use them you must have:

Code: Select all

from FreeCAD import Placement, Rotation, Vector
in the import statements, to shorten writings, (it avoid to prepend FreeCAD.) to all Vector, Rotation and Placement elements.

If you intend to code, readability is important, so spacing things, and also make "block of code" visible, using blank lines when appropriate.

Another little things, set your editor to use 4 spaces instead of "Tabs", it will be more in line with recommendations of PEP8 (if you search for "Python PEP8" you will find some interesting things.)

Serious editors, could even do some "syntax checking" using PEP8 rules. I suppose Atom will do and maybe even others, but I've abandoned java based editors to use "old school" Emacs as it is more "stable and reliable", but as usual this is a "matter of taste".

Regards

Carlo D.
Thank you for the advice, I will for sure make my code more readable. I am new to programming, but I understand that it might be necessary if the code is intended to be read and understood by others. Also, a big thank you for all the help!

Now I will try to generate the points that gives the airfoil within FreeCAD using numpy.
Post Reply