SOS: gnuplot fdtd的一个问题求助 perl vs python
我用perl和python写了相同功能的一段程序,计算一维fdtd,用gnuplot动态显示,可是python的数据没有显示出来,看横纵坐标的变化数据是正确收到了的,如最后的图片,求大神指点,谢谢。
#!/usr/bin/perl # Author : Leon Email: yangli0534@gmail.com
# fdtd simulation , plotting with gnuplot, writting in perl
# perl and gnuplot software packages should be installed before running this program
# 1d fdtd with absorbing boundary and TFSF boundary between [49] and [50]
# lossy dielectric material localted at > ez[150]
#use Time::HiRes qw(sleep);
#use autodie qw(:all);
use strict;
use warnings; #print "\@\n";
#my $terminal = "";
# open GNUPLOT_TERM, "echo 'show terminal;' | gnuplot 2>&1 |";
# while (<GNUPLOT_TERM>) {
# if (m/terminal type is (\w+)/) {
# $terminal=$1;
# }
# }
# close GNUPLOT_TERM; # unfortunately, the wxt terminal type does not support positioning.
# hardcode it...
# $terminal = "x11"; open my $PIPE ,"| gnuplot " || die "Can't initialize gnuplot number \n"; print $PIPE "set size 0.85, 0.85\n";
print $PIPE "set term png size 600, 400\n"; my $title = "fdtd simulation by leon,yangli0534\\\\@"."gmail.com";
print $PIPE "set terminal gif animate\n";# terminal type: png
print $PIPE "set output \"fdtd_simulation_abc_tfsf_match_diel.gif\"\n";#output file name
print $PIPE "set title \"{/Times:Italic $title}\"\n";# title name and font
#print $PIPE "set title \"fdtd simulation by leon,yangli0534\\\\@ gmail.com\"\n";# title name and font
print $PIPE "set title font \",10\" norotate tc rgb \"white\"\n";
print $PIPE "unset key\n";
print $PIPE "set tics textcolor rgb \"white\"\n";# text color
print $PIPE "set border lc rgb \"orange\"\n";
print $PIPE "set grid lc rgb\"orange\"\n";
print $PIPE "set object 1 rectangle from screen 0,0 to screen 1,1 fc rgb \"gray10\" behind\n";#background color
print $PIPE "set xlabel\" {/Times:Italic distance: wave length}\" tc rgb \"white\" \n";# xlabel
print $PIPE "set ylabel\"{/Times:Italic amplitude: v}\" tc rgb \"white\"\n";#ylabel
print $PIPE "set autoscale\n"; my $size = ;#physical distance
my @ez;#electric field
my @hy;#magnetic field
my @ceze;#
my @cezh;#
my @chye;#
my @chyh;#
my $LOSS_LAYER = ; #my @epsR;
my $LOSS = 0.01;
my $imp0 = 377.0;
#initalization
for (my $i = ; $i < $size; $i++){
$ez[$i] = 0.0;
$hy[$i] = 0.0;
if ($i < ) {
#$epsR[$i] = 1.0;
$ceze[$i] = 1.0;
$cezh[$i] = $imp0;
}
elsif($i < $LOSS_LAYER){
#$epsR[$i] = 1.0;
$ceze[$i] = 1.0;
$cezh[$i] = $imp0/9.0;
}
else {
#$epsR[$i] = 9.0;
$ceze[$i] = (1.0-$LOSS)/(1.0+$LOSS);
$cezh[$i] = $imp0 / /(1.0+$LOSS);
}
} for ( my $i = ; $i < $size; $i++){ if($i < $LOSS_LAYER){
#$epsR[$i] = 1.0;
$chye[$i] = 1.0/$imp0;
$chyh[$i] = 1.0;
}
else {
#$epsR[$i] = 9.0;
$chye[$i] = 1.0/ $imp0 /(1.0+$LOSS);
$chyh[$i] = (1.0-$LOSS)/(1.0+$LOSS);
}
}
my $qTime;
my $MaxTime = ;
my $pi = 3.141592563589793;
print $PIPE "set xrange [0:$size-1]\n";
my $mm = ; #do time stepping
for($qTime = ; $qTime < $MaxTime; $qTime+=){ # update magnetic field
#$hy[$size - 1] = $hy[$size - 2 ];#abc
for( $mm = ; $mm < $size - ; $mm++){
$hy[$mm] = $hy[$mm]*$chyh[$mm] + ($ez[$mm+] - $ez[$mm])*$chye[$mm];
}
$hy[] -=exp(-($qTime - 30.0)*($qTime - 30.0)/100.0)/$imp0;
# update electric field
$ez[] = $ez[];#abc
#$ez[$size-1] = $ez[$size-2];
for( $mm = ; $mm < $size- ; $mm++){
$ez[$mm] = $ez[$mm]*$ceze[$mm] + ($hy[$mm] - $hy[$mm-])*$cezh[$mm];
} if($qTime % == ){ print $PIPE "plot \"-\" w l lw 1.5 lc rgb \"green\"\n";
my $cnt = ;
for my $elem ( @ez) {
#print " ".$elem;
print $PIPE $cnt." ".$elem."\n";
$cnt += ;
}
print $PIPE "e\n";
}
#hardwire a source
$ez[] += exp(-($qTime +0.5-(-0.5)- 30.0)*($qTime +0.5-(-0.5)- 30.0)/100.0);
} #print $PIPE "set terminal x11\n"; print $PIPE "set output\n"; close($PIPE);
正常结果

python的程序
#!/usr/bin/env python import sys
import math
import os
# Author : Leon Email: yangli0534@gmail.com
# fdtd simulation , plotting with gnuplot, writting in python
# perl and gnuplot software packages should be installed before running this program
# 1d fdtd with absorbing boundary and TFSF boundary between [49] and [50]
# lossy dielectric material localted at > ez[150]
gp = os.popen('gnuplot','w')
#gp .write('plot sin(x)\n');
#gp .flush();
#p .close();
gp.write('set size 0.85, 0.85\n')
gp.write('set term png size 600, 400\n')
title = 'fdtd simulation by leon,yangli0534\\\\@gmail.com'
gp.write('set terminal gif animate\n')
gp.write('set output "fdtd_simulation_abc_tfsf_match_diel_py.gif"\n')
gp.write(''.join(['set title "{/Times:Italic ',title, '}"\n']))
gp.write('set title font ",10" norotate tc rgb "white"\n')
gp.write('unset key\n')
gp.write('set tics textcolor rgb "white"\n')
gp.write('set border lc rgb "orange"\n')
gp.write('set grid lc rgb"orange"\n')
gp.write('set object 1 rectangle from screen 0,0 to screen 1,1 fc rgb "gray10" behind\n')
gp.write('set xlabel" {/Times:Italic distance: wave length}" tc rgb "white" \n')
gp.write('set ylabel"{/Times:Italic amplitude: v}" tc rgb "white"\n')
gp.write('set autoscale\n'); size = 400#physical distance
ez=size * [0.00]#electric field
hy=size * [0.00]#magnetic field
ceze=size * [0.00]#
cezh=size * [0.00]#
chye=size * [0.00]#
chyh=size * [0.00]#
imp0 = 377.00
LOSS = 0.01
LOSS_LAYER = 250
MaxTime = 18000
cnt = 0
elem = 0.00000
gp.write(''.join(['set xrange [0:',str(size),'-1]\n']));
for i in range(0,size):
ez[i] = 0.0
hy[i] = 0.0
if (i < 100):
#$epsR[$i] = 1.0;
ceze[i] = 1.0
cezh[i] = imp0
elif(i < LOSS_LAYER):
#$epsR[$i] = 1.0;
ceze[i] = 1.0
cezh[i] = imp0/9.0
else :
#$epsR[$i] = 9.0;
ceze[i] = (1.0-LOSS)/(1.0+LOSS)
cezh[i] = imp0 / 9 /(1.0+LOSS)
if( i < LOSS_LAYER):
chye[i] = 1.0/imp0
chyh[i] = 1.0
else:
chye[i] = 1.0/imp0/(1.0+LOSS)
chyh[i] = (1.0-LOSS)/(1.0+LOSS)
for qTime in range(0, MaxTime):
# update magnetic field
for mm in range(0, size-1):
hy[mm] = hy[mm]*chyh[mm] + (ez[mm+1]-ez[mm])*chye[mm]
hy[49] = hy[49]-math.exp(-(qTime - 30.0)*(qTime - 30.0)/100.0)/imp0
# update electric field
ez[0] = ez[1]#abc
#$ez[$size-1] = $ez[$size-2];
for mm in range(1, size-1):
ez[mm] = ez[mm]*ceze[mm] + (hy[mm] - hy[mm-1])*cezh[mm]
if(qTime % 20 == 0):
gp.write('plot "-" w l lw 1.5 lc rgb "white"\n')
cnt = 0
for elem in ez:
#gp.write([cnt,' ',elem,'\n'])
gp.write(''.join([str(cnt),' ',str(elem),'\n']))
#gp.write(' ')
#gp.write(str(elem))
#gp.write('\n')
cnt += 1
gp.write('e\n')
ez[50] = ez[50]+math.exp(-(qTime +0.5-(-0.5)- 30.0)*(qTime +0.5-(-0.5)- 30.0)/100.0);
gp.write('set output\n')
gp.close()
结果就是
SOS: gnuplot fdtd的一个问题求助 perl vs python的更多相关文章
- Perl 和 Python 的比较 【转】
转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&id=4662991&uid=608135 作为万年Perl 党表示最近开 ...
- 【脚本语言对比】BASH,PERL以及PYTHON
据说: BASH能调用linux的应用程序,这是其最大的优点,也是其最大的缺点. PERL那复杂的语法确实看得让人想吐. python很优美,但是据说对正则的支持不够,没有perl强大. 总结一下学习 ...
- 常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript
常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript Javascript现阶段还不适合用来做独立开发,它的天下还是在web应用 ...
- Perl,Python,Ruby,Javascript 四种脚本语言比较
Perl 为了选择一个合适的脚本语言学习,今天查了不少有关Perl,Python,Ruby,Javascript的东西,可是发现各大阵营的人都在吹捧自己喜欢的语言,不过最没有争议的应该是Javascr ...
- 关于CGI:Tomcat、PHP、Perl、Python和FastCGI之间的关系
如前文所述,Web服务器是一个很简单的东西,并不负责动态网页的构建,只能转发静态网页.同时Apache也说,他能支持perl,生成动态网页.这个支持perl,其实是apache越位了,做了一件额外的事 ...
- 【原创】控制perl和python脚本执行过程中脚本文件是否关闭的方法
引子 跟踪perl和python脚本对文件的访问,实际过程中,perl和python解析器在解析完脚本后,直接关闭了 脚本文件,在进程中查询不到是访问文件的脚本文件名称. shell.perl和pyt ...
- 正则表达式匹配可以更快更简单 (but is slow in Java, Perl, PHP, Python, Ruby, ...)
source: https://swtch.com/~rsc/regexp/regexp1.html translated by trav, travmymail@gmail.com 引言 下图是两种 ...
- Perl & Python编写CGI
近期偶然玩了一下CGI,收集点资料写篇在这里留档. 如今想做HTTP Cache回归測试了,为了模拟不同的响应头及数据大小.就须要一个CGI按须要传回指定的响应头和内容.这是从老外的測试页面学习到的经 ...
- 分享一个获取代理ip的python函数
分享一个获取代理ip的python函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #coding:utf-8 from bs4 import Beaut ...
随机推荐
- ASP.NET中Session简单原理图
刚学习Session,对session的理解相当肤浅,按照我的想法画了原理图,麻烦各位大神指正,谢了!
- API的非向后兼容性无论如何通常代表着一种比较差的设计
不管一个类库或者工具方法实现多么的好,如果无法做到向后兼容性,通常会给用户带来很大的升级成本,很多对此的依赖如果希望在后续的升级和维护期间使用该类库的其他新增特性或者好处,将不得不推迟升级亦或是被迫接 ...
- javascript中||和&&代替if
首先,我们来看一段代码: ; ){ add_level = ; } ){ add_level = ; } ){ add_level = ; } ){ add_level = ; } else { ad ...
- 身份证校验(c++实现)
描述: 我国国标[GB 11643-1999]中规定:公民身份号码是18位特征组合码,由十七位数字本体码和一位数字校验码组成.排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码 ...
- SharePoint 2013 隐藏部分Ribbon菜单
SharePoint的使用中,因为用户经常不愿意看到那些不经常使用的操作,我们经常需要定制Ribbon菜单, 更多时候不是隐藏所有,而是隐藏掉我们不需要的那些:下面,我们一列表为例,简单介绍下如何部分 ...
- iOS多线程-05-多图下载
效果图 常见问题及解决方法 图片重复下载 将内存保存在内存或沙盒中. 若下载的图片量较大,则会出现UI界面不流畅的现象 在子线程中执行下载操作,然后回到主线程成中进行UI界面的刷新. 由于cell的循 ...
- 开源项目go2o - golang版的o2o项目
发一个github上唯一用golang实现的o2o项目 What's Go2o Golang combine simple o2o DDD domain-driven design realizati ...
- Android分辨率适配心得
关于Android分辨率适配,这个是Android开发很头疼的一个问题,也需要花费相当一部分开发时间处理的一个问题,往往一个界面怎么适配就得想半天,特别是新手,也经常有人问我是怎么适配分辨率的,我也不 ...
- Android Design Support Library——TextInputLayout
前沿 上一篇介绍了NavigationView的主要使用方式,本章主要介绍TextInputLayout的使用方式. TextInputLayout——EditText悬浮标签 TextInputLa ...
- (ios实战)ios调试总结(转载)
在程序中,无论是你想弄清楚为什么数组中有3个对象而不是5个,或者为什么一个新的玩家开始之后,游戏在倒退——调试在这些处理过程中是比较重要的一部分.通过本文的学习,我们将知道在程序中,可以使用的大多数重 ...