我用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的更多相关文章

  1. Perl 和 Python 的比较 【转】

    转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&id=4662991&uid=608135 作为万年Perl 党表示最近开 ...

  2. 【脚本语言对比】BASH,PERL以及PYTHON

    据说: BASH能调用linux的应用程序,这是其最大的优点,也是其最大的缺点. PERL那复杂的语法确实看得让人想吐. python很优美,但是据说对正则的支持不够,没有perl强大. 总结一下学习 ...

  3. 常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript

    常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript Javascript现阶段还不适合用来做独立开发,它的天下还是在web应用 ...

  4. Perl,Python,Ruby,Javascript 四种脚本语言比较

    Perl 为了选择一个合适的脚本语言学习,今天查了不少有关Perl,Python,Ruby,Javascript的东西,可是发现各大阵营的人都在吹捧自己喜欢的语言,不过最没有争议的应该是Javascr ...

  5. 关于CGI:Tomcat、PHP、Perl、Python和FastCGI之间的关系

    如前文所述,Web服务器是一个很简单的东西,并不负责动态网页的构建,只能转发静态网页.同时Apache也说,他能支持perl,生成动态网页.这个支持perl,其实是apache越位了,做了一件额外的事 ...

  6. 【原创】控制perl和python脚本执行过程中脚本文件是否关闭的方法

    引子 跟踪perl和python脚本对文件的访问,实际过程中,perl和python解析器在解析完脚本后,直接关闭了 脚本文件,在进程中查询不到是访问文件的脚本文件名称. shell.perl和pyt ...

  7. 正则表达式匹配可以更快更简单 (but is slow in Java, Perl, PHP, Python, Ruby, ...)

    source: https://swtch.com/~rsc/regexp/regexp1.html translated by trav, travmymail@gmail.com 引言 下图是两种 ...

  8. Perl &amp; Python编写CGI

    近期偶然玩了一下CGI,收集点资料写篇在这里留档. 如今想做HTTP Cache回归測试了,为了模拟不同的响应头及数据大小.就须要一个CGI按须要传回指定的响应头和内容.这是从老外的測试页面学习到的经 ...

  9. 分享一个获取代理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 ...

随机推荐

  1. SQL交叉表

    之前做货品横向展示时,有看到评论说用到交叉表. 公司最近需要给订单表做一个数据汇总的功能,同事给到一个参考SQL select * from (select COUNT(1) as 已锁定 from ...

  2. [c#] const 与 readonly

    c# 中 const 与 readonly 关键字看似相同,实则不同.重点在于确定值的时间. const const 很简单,就是一个常量,不可以被 static 修饰,因为被 const 修饰的字段 ...

  3. activiti 工作流

    1. 工作流的概念 工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档.信息或任务的过程自动进行,从而实 ...

  4. .NET Core的“dotnet restore”、“dotnet build”和“dotnet run”命令都是用来干什么的?

    dotnet restore 源代码:https://github.com/dotnet/cli/tree/rel/1.0.0/src/dotnet/commands/dotnet-restore 入 ...

  5. Mysql基本数据操作

    一.mysql中的逻辑对象 mysqld(process_id(threads)+memory+datadir)-->库-->表-->记录(由行与列组成) 什么是关系型数据库:表与表 ...

  6. Webform(分页、组合查询)

    一.分页 1.写查询方法: public List<Student> Select(int PageCount, int PageNumber) {//PageCount为每页显示条数,P ...

  7. RHEL7管道与重定向

    文件描述符 可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以实现文件的读写操作 用户可以自定义文件描述符范围是:3-num,这个最大数字,跟 ...

  8. angularjs的双向数据绑定

    数据绑定有两个方向: 数据 → 界面:我们使用scope对象的$watch()方法监听数据的变化,来更新界面. <html> <head> <title>监听数据& ...

  9. Atitit. Atiposter 发帖机 新特性 poster new feature   v7 q39

    Atitit. Atiposter 发帖机 新特性 poster new feature   v7 q39 V1  初步实现sina csdn cnblogs V2  实现qzone sohu 的发帖 ...

  10. Atitit.json xml 序列化循环引用解决方案json

    Atitit.json xml 序列化循环引用解决方案json 1. 循环引用1 2. 序列化循环引用解决方法1 2.1. 自定义序列化器1 2.2. 排除策略1 2.3. 设置序列化层次,一般3级别 ...