ich schreibe grade eine Abschlussarbeit in der ich ein Programm schreiben muss. Titel der Arbeit: "Effiziente Berechnung der Schallausbreitung.."
Das Programm besteht bis jetzt nur für konkrete Werte und soll noch parametrisiert werden. Außerdem muss es noch für 3d Probleme erweitert werden, bis jetzt nur 2d. Die Ausgabe beim plotten könnte ebenfalls noch verbessert werden. Außerdem muss ich noch das ganze Programm in eine Schleife packen mit passender Abbruchbedingung.
Wäre über jede hilfe wirklich sehr dankbar.
Ich habe noch nie vorher mit Python gearbeitet das meiste aus dem Programm hat mir mein Prof. geschrieben, aber muss jetzt auch mal selbst was hinkriegen.
Falls jemand das Programm in irgend einer Weise verbessern kann würde dass schon helfen.
Danke im vorraus.
Programmtext:
Code: Alles auswählen
from numpy import * #importiert alle Dateien von numerischem Python
import matplotlib.pyplot as plt #importiert Dateien zum ploten
from scipy.integrate import odeint
from scipy.optimize import * #importiert Funktionen von Scipy zur
from mayavi import mlab #zur 3D-Darstellung
from time import time #zur Ermittlung der Programmlaufzeit
c=343 #globale Konstante c
n = 15 # Exponent Geschwindigkeitsfunktion;globale Konstante Dimensionslos
v0 = 50. # Geschwindigkeit Stroemung in m/s
def v(xx): # definition des Geschwindigkeitsprofils
x,y,z = xx #
v = array((v0*(1-tanh(y**n)), 0., 0.)) #Geschwindigkeitsprofil
dv = array( ((0,0,0),(-n*v0*y**(n-1)*(1-tanh(y**n)**2),0,0),(0,0,0)) ) #Ableitung des Geschwindigkeitsprofils
return v,dv #
def f(y,t):
x=y[0:3]
s=y[3:6]
vv,dv = v(x)
sa = sqrt((s*s).sum()) # Betrag von s-Vektor
f0 = c*s/sa + vv
f1 = dot(s,dv)
return hstack((f0,f1))
t = linspace(0, 0.008, 2000)
x0 = array((0,0,0.))
n0 = array((1, 0.1, 0.1))/sqrt(2)
s0 = n0 / (c+dot(v(x0)[0],n0))
y0 = hstack((x0,s0))
#ti = time()
soln = odeint(f, y0, t)
ort = soln[:,0:3]
def abstd(n):
n0 = n/sqrt((n*n).sum())
s0 = n0 / (c+dot(v(x0)[0],n0))
y0 = hstack((x0,s0))
soln = odeint(f, y0, t)
ort = soln[:,0:3]
abstand = sqrt((abs(ziel-ort)**2).sum(1))
indmin = abstand.argmin()
tmin = t[indmin]
a = ort[indmin]
u = ort[indmin+1] - a
d = cross(ziel-a,u)
d = sqrt((d*d).sum())/sqrt((u*u).sum())
return abstand[indmin],tmin#,d
def abstd2(n):
return abstd(n)[0]
#ziel = array(1,1,0)
ziel = array((1,1,0.01))
ti = time()
res = fmin(abstd2, n0,maxfun=300,full_output=0)
print time()-ti
print res
print abstd(res)
print sqrt(((x0-ziel)**2).sum())/c
plt.plot(t,ort[:,0],label='x')
plt.plot(t,ort[:,1],label='y')
plt.plot(t,ort[:,2],label='z')
plt.legend()
plt.show()
pl=mlab.plot3d(ort[:,0],ort[:,1],ort[:,2],color=(1,0,0))
mlab.axes(pl)
mlab.show()
for y in arange(-1,1,0.1):
print v( array((0,y,0)) )
y = arange(-2,2,0.01)
vx = 1-tanh(y**10)
vxs = -10*y**9*(1-tanh(y**10)**2)
plt.plot (y,vxs)
plt.plot (y,vx)
plt.show()
for y in arange(-1,1,0.1):
print v( array((0,y,0)) )
y = arange(-2,2,0.01)
vx = 1-tanh((y**10)
vxs = -10*y**9*(1-tanh(y**10)**2)
plt.plot (y,vxs)
plt.show()