Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Chemistry
Biology and Medical
Earth Sciences
Computer Science
Computing and Technology
DIY Projects
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Chemistry
Biology and Medical
Earth Sciences
Computer Science
Computing and Technology
DIY Projects
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Other Sciences
Programming and Computer Science
Why is my Hydrodynamics Simulation Code Producing a Noisy Signal?
Reply to thread
Message
[QUOTE="Silviu, post: 5447120, member: 588158"] Hi! I have this code which should simulate a sod shock tube like this: [URL]https://en.wikipedia.org/wiki/Sod_shock_tube[/URL] But when i plot density versus distance I just get something like a noisy signal. Any idea where I am doing something wrong? from matplotlib import pyplot as plt import numpy as np import copy import random import mathL=1.0 gamma = 1.4 N=1000 h=L/(N-1) CFL=0.1v=[[0 for x in range(3)] for x in range(N)] F=[[0 for x in range(3)] for x in range(N)] # give the values to each cell def initialise(): for i in range(N): if i<N/2: rho=1 p=1 u=0 else: rho=0.125 p=0.1 u=0 e=p/((gamma-1)*rho) v[i][0]=rho #create a matrix with first column for density, second for density times speed v[i][1]=u*rho #and third for e, and a vector for the volume of each grid v[i][2]=e # calculate the maximum speed in the program def cMax(): uMax=0 for i in range(N): pressure = (gamma-1)*v[i][0]*v[i][2] speed=v[i][1]/v[i][0] c=np.sqrt(gamma*abs(pressure)/abs(v[i][0])) if uMax< (c+abs(speed)): uMax=c+abs(speed) return uMax def fluxCalculator(): for i in range(1,N-1): #density flux if v[i][0]< v[i-1][0]: rho=v[i-1][0] if v[i][0]> v[i-1][0]: rho=v[i][0] if v[i][0]==v[i-1][0]: rho=0 F[i][0]=rho*v[i][1]/v[i][0] #energy flux if v[i][2]<v[i-1][2]: e=v[i-1][2] if v[i][2]>v[i-1][2]: e=v[i][2] if v[i][2]==v[i-1][2]: e=0 F[i][2]=F[i][0]*e #momentum flux if v[i][1]/v[i][0]<v[i-1][1]/v[i-1][0]: u=v[i-1][1]/v[i-1][0] if v[i][1]/v[i][0]>v[i-1][1]/v[i-1][0]: u=v[i][1]/v[i][0] if v[i][1]/v[i][0]==v[i-1][1]/v[i-1][0]: u=0 F[i][1]=0.5*u*(F[i+1][0]+F[i][0])initialise() def update(): tau=CFL*h/cMax() fluxCalculator() for i in range(1,N-1): rho=v[i][0] m=v[i][1] e=v[i][2] pressure=(gamma-1)*rho*e e=e-tau/h*pressure*(v[i+1][1]/v[i+1][0]-m/rho) m=m-tau/h*(pressure-(gamma-1)*v[i-1][0]*v[i-1][2]) rho=rho-tau/h*(F[i+1][0]-F[i][0]) e=e-tau/h*(F[i+1][2]-F[i][2]) m=m-tau/h*(F[i+1][1]-F[i][1]) v[i][0]=rho v[i][1]=m v[i][2]=e density=[] position=np.arange(0,1+h/2,h) for i in range(1000): update() for i in range(N): density=density+[v[i][0]] plt.plot(position,density) plt.show()[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i] [/QUOTE]
Insert quotes…
Post reply
Forums
Other Sciences
Programming and Computer Science
Why is my Hydrodynamics Simulation Code Producing a Noisy Signal?
Back
Top