• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

fdtd simulation, plotting with gnuplot, writting in perl

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
# 9月13日 于成都黄龙溪
1
#!/usr/bin/perl 2 3 # Author : Leon Email: [email protected] 4 # fdtd simulation , plotting with gnuplot, writting in perl 5 # perl and gnuplot software packages should be installed before running this program 6 7 #use Time::HiRes qw(sleep); 8 #use autodie qw(:all); 9 print "\@\n"; 10 my $terminal = ""; 11 open GNUPLOT_TERM, "echo \'show terminal;\' | gnuplot 2>&1 |"; 12 while (<GNUPLOT_TERM>) { 13 if (m/terminal type is (\w+)/) { 14 $terminal=$1; 15 } 16 } 17 close GNUPLOT_TERM; 18 19 # unfortunately, the wxt terminal type does not support positioning. 20 # hardcode it... 21 $terminal = "x11"; 22 23 open my $PIPE ,"| gnuplot " || die "Can\'t initialize gnuplot number \n"; 24 25 print $PIPE "set size 0.85, 0.85\n"; 26 print $PIPE "set term png size 600, 400\n"; 27 28 my $title = "fdtd simulation by leon,yangli0534\\\\@"."gmail.com"; 29 print $PIPE "set terminal gif animate\n";# terminal type: png 30 print $PIPE "set output \"fdtd_simulation_v0.1.gif\"\n";#output file name 31 print $PIPE "set title \"{/Times:Italic $title}\"\n";# title name and font 32 #print $PIPE "set title \"fdtd simulation by leon,yangli0534\\\\@ gmail.com\"\n";# title name and font 33 print $PIPE "set title font \",15\" norotate tc rgb \"white\"\n"; 34 print $PIPE "unset key\n"; 35 print $PIPE "set tics textcolor rgb \"white\"\n";# text color 36 print $PIPE "set border lc rgb \"orange\"\n"; 37 print $PIPE "set grid lc rgb\"orange\"\n"; 38 print $PIPE "set object 1 rectangle from screen 0,0 to screen 1,1 fc rgb \"gray10\" behind\n";#background color 39 print $PIPE "set xlabel\" {/Times:Italic distance: wave length}\" tc rgb \"white\" \n";# xlabel 40 print $PIPE "set ylabel\"{/Times:Italic amplitude: v}\" tc rgb \"white\"\n";#ylabel 41 print $PIPE "set autoscale\n"; 42 43 my $size = 400;#physical distance 44 my @ez;#electric field 45 my @hy;#magnetic field 46 47 my $imp0 = 377.0; 48 #initalization 49 for (my $i = 0; $i < $size; $i++){ 50 $ez[$i] = 0; 51 $hy[$i] = 0; 52 53 } 54 my $qTime; 55 my $MaxTime = 1850; 56 my $pi = 3.141592563589793; 57 print $PIPE "set xrange [0:$size-1]\n"; 58 my $mm = 0; 59 60 #do time stepping 61 for($qTime = 0; $qTime < $MaxTime; $qTime+=5){ 62 63 # update magnetic field 64 for( $mm = 0; $mm < $size - 1; $mm++){ 65 $hy[$mm] = $hy[$mm] + ($ez[$mm+1] - $ez[$mm])/$imp0; 66 } 67 68 # update electric field 69 for( $mm = 1; $mm < $size ; $mm++){ 70 $ez[$mm] = $ez[$mm] + ($hy[$mm] - $hy[$mm-1])*$imp0; 71 } 72 73 if($qTime % 10 == 0){ 74 75 print $PIPE "plot \"-\" w l lw 3 lc rgb \"green\"\n"; 76 my $cnt = 0; 77 for my $elem ( @ez) { 78 #print " ".$elem; 79 print $PIPE $cnt." ".$elem."\n"; 80 $cnt += 1; 81 } 82 print $PIPE "e\n"; 83 } 84 #hardwire a source 85 $ez[0] = exp(-($qTime - 30.0)*($qTime - 30.0)/100); 86 } 87 88 #print $PIPE "set terminal x11\n"; 89 90 print $PIPE "set output\n"; 91 92 close($PIPE);


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Can'tlocateData/Dumper.pminperl5的处理发布时间:2022-07-22
下一篇:
Perl:基本语法参考、配置文件、模板、正则表达式发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap