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 ...
随机推荐
- SignalR+Asp.net高频率实时消息传递应用
1.概述: 使用 ASP.NET 和SignalR 2高频率的实时消息功能.高频率消息在这种情况下就意味着更新发送以固定的速率; 本教程中创建的应用程序显示一个用户可以拖动的形状.在所有其他连接浏览器 ...
- [moka收藏]php正则表达式验证
手机号验证规则[['mobile'], 'match','pattern' =>"/^1[34578]\\d{9}$/"], [['sendmail_limit'],'mat ...
- Incorrect string value: '\xF0\x90\x8D\x83...' for column 通用解决方案
mysql插入非ascii字符时报这个错的根本原因在于: 对应表的字符集无法存储要插入的字符,比如汉字插入latin1编码,某些特殊字符插入gbk或者utf8等. 检查一下实际插入的字符以及对应表或者 ...
- Ansible用于网络设备管理 part 1 Jinja2 YAML初窥
这一次的实验内容依然来自Kirk Byers的博客,源地址在https://pynet.twb-tech.com/blog/python/paramiko-ssh-part1.html 但是,这次实验 ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q127-Q130)
Question 127You create a custom list named Products.You need to perform a Representational State Tra ...
- Universal-Image-Loader完全解析(上)
Universal-Image-Loader完全解析(上) 基本介绍及使用 大家平时做项目的时候,或多或少都会接触到异步加载图片,或者大量加载图片的问题,而加载图片时候经常会遇到各种问题,如oom,图 ...
- Android文件操作
将数据写入Internal Storage: String fileName = "myfile.txt"; String str="保存数据到内部存储"; t ...
- iOS开发之保存照片到系统相册(Photo Album)
iOS开发之保存照片到系统相册(Photo Album) 保存照片到系统相册这个功能很多社交类的APP都有的,今天我们简单讲解一下,如何将图片保存到系统相册(Photo Album). 创建UIIma ...
- 快速与MySQL交互,使用XMAPP打开MySQL数据库,并用shell进行与MySQL交互<Window 10>
1.如果想要通过XAMPP shell登录MySQL,还需要下载安装好XAMPP. 2.双击打开xampp-control.exe,会出现以下界面,点击开启Apache和MySQL,这样我们就开启服务 ...
- vs2012远程调试功能的改进
不知道大家有没有遇到过这种情况,刚开发完的程序,明明在本机能够好好的运行,可是部署到服务器过分发给用户时,总是出现莫名其妙的错误. 一时半会又看不出问题来,怎么办呢?难道只能在服务器或是客户电脑上装一 ...