📄 virturalshocktube.txt
字号:
else label4.setText("Pressure ratio = 0.0"+scrollbar3.getValue()); } public void scrollScrollbar4(Event ev) { if(scrollbar4.getValue()>9) label7.setText("Temperature ratio = 0."+scrollbar4.getValue()); else label7.setText("Temperature ratio = 0.0"+scrollbar4.getValue()); } public void clickedButton1() { double p1,t1,p2,p3,p4,t4,g1,g4,r1,r4,a1,a4,p4p1,p2p1,p2p1new,a4a1; double[] pe=new double[21]; if(animator!=null) {stop();return;} /*Clear screen*/ offg.setColor(Color.white); offg.fillRect(0,0,size().width,size().height); drawTube(); drawAxes(); paint(gs); /*Get tube parameters */ p4=(double)scrollbar1.getValue()*1000.0; t4=(double)scrollbar2.getValue(); p1=(double)scrollbar3.getValue()/100.0*p4; t1=(double)scrollbar4.getValue()/100.0*t4; g4=1.4;r4=287.0; if(choice1.getSelectedIndex()==1) {g4=1.29;r4=188.9;} // CO2 value if(choice1.getSelectedIndex()==2) {g4=1.66;r4=2077;} //He value g1=1.4;r1=287.0; if(choice2.getSelectedIndex()==1) {g1=1.29;r1=188.9;} //CO2 value if(choice2.getSelectedIndex()==2) {g1=1.66;r1=2077;} //He value a4=Math.sqrt(g4*r4*t4); a1=Math.sqrt(g1*r1*t1); /*Determine shock and expansion strengths*/ p4p1=p4/p1;a4a1=a4/a1;p2p1=p4p1;p2p1new=p4p1/2.; while(Math.abs((p2p1new-p2p1)/p4p1)>.0001) { p2p1=p2p1new; p2p1new=p2p1-func(p2p1,p4p1,g1,g4,a4a1)*p2p1*.01/(func(p2p1*1.01,p4p1,g1,g4,a4a1)-func(p2p1,p4p1,g1,g4,a4a1)); } p2=p2p1*p1;p3=p2; lsstrength.setText("Shock strength = "+p2p1); lestrength.setText("Exp. strength = "+p4/p3); /*Determine shock speed W, mass motion velocity Up */ up=a1/g1*(p2p1-1.)*Math.sqrt(2.*g1/(g1+1.)/(p2p1+(g1-1.)/(g1+1.))); w=a1*Math.sqrt((g1+1.)/2./g1*(p2p1-1.)+1.); /*Determine speed of expansion at 11 locations in exp. wave */ for(int i=0;i<11;i++) { pe[i]=p4-(p4-p3)/10.*(double)i; ue[i]=2.*a4/(g4-1.)-(g4+1)/(g4-1.)*a4*Math.pow(pe[i]/p4,(g4-1.)/g4/2.); upe[i]=(2./(g4-1.)*(1-Math.pow(pe[i]/p4,(g4-1.)/g4/2.)))*a4; } lshock.setText("Shock speed "+w+"m/s"); lcontact.setText("Mass motion "+up+"m/s"); lexte.setText("Expansion t.e. "+ue[10]+"m/s"); lexple.setText("Expansion l.e. "+ue[0]+"m/s"); start(); } double func(double p2p1,double p4p1,double g1,double g4,double a4a1) { return(p2p1*Math.pow(1.-((g4 - 1.)/a4a1*(p2p1-1.))/Math.sqrt(2.*g1*(2.*g1+(g1+1.)*(p2p1-1.))),-2.*g4/(g4-1.))-p4p1); } void drawArrow(int shaftLength, int headLength, int headWidth, int xPos, int yPos, double angle, Graphics ga) { int xa,ya,xb,yb,xc,yc,xd,yd; xa=xPos-(int)Math.round(shaftLength/2.0*Math.cos(angle)); ya=yPos+(int)Math.round(shaftLength/2.0*Math.sin(angle)); xb=xa+(int)Math.round(shaftLength*Math.cos(angle)); yb=ya-(int)Math.round(shaftLength*Math.sin(angle)); xc=xa+(int)Math.round((shaftLength-headLength)*Math.cos(angle)-headWidth/2.0*Math.sin(angle)); yc=ya-(int)Math.round((shaftLength-headLength)*Math.sin(angle)+headWidth/2.0*Math.cos(angle)); xd=xa+(int)Math.round((shaftLength-headLength)*Math.cos(angle)+headWidth/2.0*Math.sin(angle)); yd=ya-(int)Math.round((shaftLength-headLength)*Math.sin(angle)-headWidth/2.0*Math.cos(angle)); ga.drawLine(xa,ya,xb,yb); ga.drawLine(xb,yb,xc,yc); ga.drawLine(xb,yb,xd,yd); } void drawAxes() { Font f=new Font("TimesRoman",Font.PLAIN,12); //font offg.setColor(Color.gray); drawArrow(ltube,xdiap/30,xdiap/30,xtube+ltube/2,ytube+yaxis+htube+50,0.0,offg); drawArrow(yaxis,xdiap/30,xdiap/30,xtube+xdiap,ytube+yaxis/2+htube+50,3.14159/2.,offg); offg.setColor(Color.black); offg.drawString("t",xtube+xdiap+3,ytube+htube+50); offg.drawString("x",xtube+ltube+3,ytube+yaxis+htube+50); } void drawTube() { Font f=new Font("TimesRoman",Font.BOLD,10); //font offg.setFont(f); offg.setColor(Color.black); offg.drawLine(xtube-50,0,xtube-50,size().height); drawArrow(ltube/2,xdiap/30,xdiap/40,xtube+ltube*3/4,ytube+htube+20,0.0,offg); drawArrow(ltube/2,xdiap/30,xdiap/40,xtube+ltube*1/4,ytube+htube+20,3.14159,offg); offg.drawString("4 m",xtube+xdiap-5,ytube+htube+28); offg.fillRect(xtube,ytube,ltube,htube/20); offg.fillRect(xtube,ytube+htube,ltube,htube/20); offg.fillRect(xtube,ytube-htube/20,htube/20,htube/20); offg.fillRect(xtube,ytube+htube+htube/20,htube/20,htube/20); offg.fillRect(xtube+xdiap,ytube-htube/20,htube/20,htube/20); offg.fillRect(xtube+xdiap,ytube+htube+htube/20,htube/20,htube/20); offg.fillRect(xtube+ltube-htube/20,ytube-htube/20,htube/20,htube/20); offg.fillRect(xtube+ltube-htube/20,ytube+htube+htube/20,htube/20,htube/20); offg.setColor(Color.gray); offg.fillRect(xtube+xdiap+htube/40,ytube+htube/20,htube/40,htube-htube/20); } public void paint(Graphics g) { g.drawImage(offi,0,0,this); } public void start() { animator=new Thread(this); animator.start(); button1.setLabel(">>>> STOP <<<<"); } public void stop() { if(animator!=null) animator.stop(); animator=null; button1.setLabel(">>>> FIRE <<<<"); } public void update(Graphics g) { g.clipRect(xtube,ytube+htube/20,ltube,htube-htube/20); paint(g); } public void run () { int xContact,xShock,xExp,xp,j,y0; double rContact,rShock,tmax,tstep,tmaxp,t; double[] rp=new double[101]; double[] rExp=new double[21]; y0=ytube+yaxis+htube+50; tmax=.5/up;tstep=tmax/250.; tmaxp=1/w; for(int i=0;i<41;i++) rp[i]=-xdiap*tubeLength/ltube+tubeLength*(double)i/40.; for(t=0.;;t+=tstep) { offg.setColor(getBackground()); offg.fillRect(xtube,ytube+htube/20,ltube,htube-htube/20); ltime.setText("Elapsed time = "+t+"s"); /*Draw contact surface*/ rContact=up*t; xContact=(int)(rContact*(double)ltube/tubeLength); offg.setColor(Color.pink); gs.setColor(Color.pink); offg.drawLine(xtube+xdiap+xContact,ytube+htube/20,xtube+xdiap+xContact,ytube+htube); if(t<tmaxp) { offg.drawLine(xtube+xdiap,y0,xContact+xtube+xdiap,y0-(int)(yaxis*t/tmaxp)); gs.drawLine(xtube+xdiap,y0,xContact+xtube+xdiap,y0-(int)(yaxis*t/tmaxp)); } /*Draw shock*/ rShock=w*t; xShock=(int)(rShock*(double)ltube/tubeLength); if(xShock<ltube-xdiap) { offg.setColor(Color.red); offg.drawLine(xtube+xdiap+xShock,ytube+htube/20,xtube+xdiap+xShock,ytube+htube); gs.setColor(Color.red); if(t<tmaxp) { offg.drawLine(xtube+xdiap,y0,xShock+xtube+xdiap,y0-(int)(yaxis*t/tmaxp)); gs.drawLine(xtube+xdiap,y0,xShock+xtube+xdiap,y0-(int)(yaxis*t/tmaxp)); } } /*Draw Expansion Wave*/ for(int i=0;i<11;i++) { rExp[i]=ue[i]*t; xExp=(int)(rExp[i]*(double)ltube/tubeLength); if(xExp>-xdiap) { offg.setColor(Color.blue); offg.drawLine(xtube+xdiap+xExp,ytube+htube/20,xtube+xdiap+xExp,ytube+htube); if(t<tmaxp) { offg.setColor(Color.blue); gs.setColor(Color.blue); offg.drawLine(xtube+xdiap,y0,xExp+xtube+xdiap,y0-(int)(yaxis*t/tmaxp)); gs.drawLine(xtube+xdiap,y0,xExp+xtube+xdiap,y0-(int)(yaxis*t/tmaxp)); } } } /*Draw Particles*/ offg.setColor(Color.gray); for(int i=0;i<41;i++) { j=0; while (rp[i]>rExp[j] && j<11) j++; if (j==11 && rp[i]<rShock) rp[i]+=up*tstep; else if(j>0 && j<11) rp[i]+=(upe[j-1]+upe[j])/2.*tstep; xp=(int)(rp[i]*(double)ltube/tubeLength); if(xp<ltube && xp>-xdiap) { offg.drawLine(xp+xtube+xdiap,ytube+htube/4,xp+xtube+xdiap,ytube+htube/4); offg.drawLine(xp+xtube+xdiap,ytube+htube/2,xp+xtube+xdiap,ytube+htube/2); offg.drawLine(xp+xtube+xdiap,ytube+htube*3/4,xp+xtube+xdiap,ytube+htube*3/4); } } repaint(); try {Thread.sleep(10);} catch (InterruptedException e) {} } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -