Ejemplo n.º 1
0
def my_func(M,P,T,aoa,span,tip_chord):
        chord[1] = tip_chord
	mesh_utils.write_wing_file(M,P,T,chord,span,n_sections,n_naca_pts)
	NACA.create_wing('current_wing','output')
	run_apame(aoa)
	fid = open('output_polar.dat','r')
	nb_lines=0
	while fid.readline():
		nb_lines+=1
	if nb_lines==0:
		raise TypeError("Empty file")
	fid.close()
	fid = open('output_polar.dat','r')
	# revenir au debut
	alpha=numpy.zeros(nb_lines)
	cx=numpy.zeros(nb_lines)
	cz=numpy.zeros(nb_lines)
	for i in xrange(nb_lines):
		tmp=fid.readline()
		tmp=tmp.split()
		alpha[i]=float(tmp[0])
		cx[i]=float(tmp[2])
		cz[i]=float(tmp[1])
	fid.close()
	ind = cx.argmin()
	Cf = 0.0583/Re**0.2
	Sw = (chord[0]+chord[1])*span/2.
        Cd_friction = Sw/Sref*Cf
	return min(cx)+Cd_friction,cz[ind]
Ejemplo n.º 2
0
def my_func(M, P, T, span, tip_chord):
    chord[1] = tip_chord
    mesh_utils.write_wing_file(M, P, T, chord, span, n_sections, n_naca_pts)
    NACA.create_wing("current_wing", "output")
    run_apame()
    fid = open("output_polar.dat", "r")
    nb_lines = 0
    while fid.readline():
        nb_lines += 1
    if nb_lines == 0:
        raise TypeError("Empty file")
    fid.close()
    fid = open("output_polar.dat", "r")
    # revenir au debut
    alpha = numpy.zeros(nb_lines)
    cx = numpy.zeros(nb_lines)
    cz = numpy.zeros(nb_lines)
    finesse = numpy.zeros(nb_lines)
    Cf = 0.0583 / Re ** 0.2
    Sw = (chord[0] + chord[1]) * span / 2.0
    Cd_friction = Sw / Sref * Cf
    for i in xrange(nb_lines):
        tmp = fid.readline()
        tmp = tmp.split()
        alpha[i] = float(tmp[0])
        cx[i] = float(tmp[2]) + Cd_friction
        cz[i] = float(tmp[1])
        finesse[i] = cz[i] / cx[i]
    fid.close()
    return max(finesse)
Ejemplo n.º 3
0
def my_func(X):
	chord=[1.,1.]
	M=X[0:2]
	P=X[2:4]
	T=X[4:6]
	alpha=X[6]
	span=X[7]
	chord[1]=X[8]
	n_sections=31
	n_naca_pts=50
	Sref=10.
	Re=5.e5
	mesh_utils.write_wing_file(M,P,T,chord,span,n_sections,n_naca_pts)
	NACA.create_wing('current_wing','output')
	run_apame(alpha)
	fid = open('output_polar.dat','r')
	nb_lines=0
	while fid.readline():
		nb_lines+=1
	if nb_lines==0:
		raise TypeError("Empty file")
	fid.close()
	fid = open('output_polar.dat','r')
	# revenir au debut
	alpha=numpy.zeros(nb_lines)
	cx=numpy.zeros(nb_lines)
	cz=numpy.zeros(nb_lines)
	for i in xrange(nb_lines):
		tmp=fid.readline()
		tmp=tmp.split()
		alpha[i]=float(tmp[0])
		cx[i]=float(tmp[2])
		cz[i]=float(tmp[1])
	fid.close()
	#f = interpolate.interp1d(numpy.array(cz), numpy.array(cx), kind='cubic')
	#print 'DRAG >>> ', min(cx)
	#cx=f(0.5)
	
	ind = cx.argmin()
	Cf = 0.0583/Re**0.2
	Sw = (chord[0]+chord[1])*span/2.
	Cd_friction = Sw/Sref*Cf
	print 'DRAG >>> ', cx+Cd_friction
	cx_tab[k]=cx+Cd_friction
	contrainte_tab[k]=0.5-cz
	k=k+1
	return cx+Cd_friction#,cz[ind]
		 beta=beta_list,
		 v=airspeed,
		 rho=rho,
		 P=Patm,
		 Mach=0.,
		 origin=[0.,0.,0.],
		 wingspan=10.,
		 ref_chord=1.,
		 Sref=Sref,
		 method=0,
		 farfield_dist=50.,
		 velorder=1)

if nb==8415:
	nb_angles=11
	M=[0.08,0.08]
	P=[0.4,0.4]
	T=[0.15,0.15]
	
elif nb==12:
	nb_angles=21
	M=[0.0,0.0]
	P=[0.4,0.4]
	T=[0.12,0.12]

mesh_utils.write_wing_file(M,P,T,chord,span,n_sections,n_naca_pts)
NACA.create_wing('current_wing','initial'+str(nb))
run_apame(nb_angles)


Ejemplo n.º 5
0
def create_mesh_linear_interp(filename,root,tip,span,n_sections,n_naca_points=150):
    if n_sections%2 == 0:
	raise ValueError("Merci de donner un nombre de sections impair")
    if type(root) is not list:
	raise TypeError("Le deuxieme argument doit etre une liste contenant M,P,T et Chord pour la section root.")
    if type(tip) is not list:
	raise TypeError("Le troisieme argument doit etre une liste contenant M,P,T et Chord pour la section tip.")
    if type(filename) is not str:
	raise TypeError("Le premier argument doit etre un string (nom du fichier de sortie).")
    if len(root)!=4:
	raise ValueError("Le deuxieme argument doit etre une liste contenant 4 valeurs (M,P,T,Chord).")
    if len(tip)!=4:
	raise ValueError("Le troisieme argument doit etre une liste contenant 4 valeurs (M,P,T,Chord).")

    ind_root=(n_sections-1)//2
    semi_span = span/2.
    theta = numpy.linspace(0.,numpy.pi,n_sections)
    y_list = -semi_span*numpy.cos(theta)
    y_list[ind_root]=0. # souvent 10^-16
    m_root,p_root,t_root,chord_root=root
    m_tip,p_tip,t_tip,chord_tip=tip

    Xu_tip,Xl_tip,Yu_tip,Yl_tip = NACA.create(m_tip,p_tip,t_tip,chord_tip,n_naca_points)
    upper_tip = numpy.array([Xu_tip,Yu_tip]).T
    lower_tip = numpy.array([Xl_tip,Yl_tip]).T
    tip_section = numpy.concatenate((lower_tip[::-1],upper_tip[1:]))

    Xu_root,Xl_root,Yu_root,Yl_root = NACA.create(m_root,p_root,t_root,chord_root,n_naca_points)
    upper_root = numpy.array([Xu_root,Yu_root]).T
    lower_root = numpy.array([Xl_root,Yl_root]).T
    root_section = numpy.concatenate((lower_root[::-1],upper_root[1:]))


    # build mesh
    vtk_model = vtk.vtkStructuredGrid()
    vtk_model.SetDimensions(2*n_naca_points-1,n_sections,1)
    # build points
    vtk_points = vtk.vtkPoints()

    for i in xrange(n_sections):
	r = numpy.abs(y_list[i])/semi_span
	current_section = (1.-r)*root_section + r*tip_section
        for j in xrange(2*n_naca_points-1):
                vtk_points.InsertNextPoint(current_section[j,0],y_list[i],current_section[j,1])
    # set points
    vtk_model.SetPoints(vtk_points)
    # convert to poly data    
    pdata_filter = vtk.vtkGeometryFilter()
    if vtk.VTK_MAJOR_VERSION <= 5:
        pdata_filter.SetInput(vtk_model)
    else:
        pdata_filter.SetInputData(vtk_model)
    pdata_filter.Update()
    poly_data = pdata_filter.GetOutput()
    
    # compute normals
    norms = vtk.vtkPolyDataNormals()
    if vtk.VTK_MAJOR_VERSION <= 5:
        norms.SetInput(poly_data)
    else:
        norms.SetInputData(poly_data)
    norms.ComputePointNormalsOff()
    norms.ComputeCellNormalsOn()
    norms.ConsistencyOn()
    norms.Update()
    
    # clean poly data
    clean_poly = vtk.vtkCleanPolyData()
    clean_poly.ToleranceIsAbsoluteOn()
    clean_poly.SetAbsoluteTolerance(1.e-6)
    if vtk.VTK_MAJOR_VERSION <= 5:
        clean_poly.SetInput(norms.GetOutput())
    else:
        clean_poly.SetInputData(norms.GetOutput())
    clean_poly.Update()
    
    # write output mesh
    writer = vtk.vtkXMLPolyDataWriter()
    if vtk.VTK_MAJOR_VERSION <= 5:
        writer.SetInput(clean_poly.GetOutput())
    else:
        writer.SetInputData(clean_poly.GetOutput())
    writer.SetFileName(filename+'.vtp')
    writer.Write()