可执行文件地址:

下载后,后缀修改去掉.ra即可执行

源代码

  1. #!/usr/bin/env python
  2.  
  3. from math import exp
  4. from gnuplot_leon import *
  5. imp0 = 377.0
  6.  
  7. class fdtd_leon:
  8. # Author : Leon Email: yangli0534@gmail.com
  9. # fdtd simulation
  10.  
  11. #initialization
  12. def __init__(self,size=400,time=0,MaxTime=1000,delay = 30, width = 10, cdtds =1.0):
  13. self.ez = size * [0.00]
  14. self.hy = size * [0.00]
  15. self.ceze = size * [0.00]
  16. self.chye = size * [0.00]
  17. self.cezh = size * [0.00]
  18. self.chyh = size * [0.00]
  19. self.size = size
  20. self.time = 0
  21. self.MaxTime = MaxTime
  22. self.delay = delay
  23. self.width = width
  24. self.cdtds = cdtds
  25.  
  26. # grid initialization
  27. def grid_init(self,loss = 0.02, loss_layer = 180, epsr = 9.0):
  28. for mm in range(0, self.size):
  29. if (mm < 100):
  30. self.ceze[mm] = 1.0
  31. self.cezh[mm] = imp0
  32. elif (mm < loss_layer):
  33. self.ceze[mm] = 1.0
  34. self.cezh[mm] = imp0/epsr
  35. else:
  36. self.ceze[mm] = (1.0-loss)/(1.0+loss)
  37. self.cezh[mm] = imp0/epsr//(1.0+loss)
  38. if(mm < loss_layer):
  39. self.chyh[mm] = 1.0
  40. self.chye[mm] = 1.0/imp0
  41. else:
  42. self.chyh[mm] = (1.0-loss)/(1.0+loss)
  43. self.chye[mm] = 1.0/imp0/(1.0+loss)
  44.  
  45. # update electric field
  46. def update_e(self):
  47. mm =0;
  48. for mm in range(1,self.size-1):
  49. self.ez[mm] = self.ez[mm]*self.ceze[mm] + (self.hy[mm]-self.hy[mm-1])*self.cezh[mm]
  50.  
  51. # update magnetic field
  52. def update_h(self):
  53. mm =0;
  54. for mm in range(0,self.size-1):
  55. self.hy[mm] = self.hy[mm]*self.chyh[mm] + (self.ez[mm+1]-self.ez[mm])*self.chye[mm]
  56.  
  57. def ez_inc_init(self):
  58. #self.delay = int(raw_input('Enter delay:'))
  59. #self.width = int(raw_input('Enter width:'))
  60. #self.cdtds = int(raw_input('Enter cdtds:'))
  61. #print self.delay
  62. #print self.width
  63. #print self.cdtds
  64. return
  65.  
  66. def ez_inc(self,time,location):
  67. #print ''.join(['ez_inc time: ',str(time),'location: ',str(location)] )
  68. #print exp(-((time-self.delay-location/self.cdtds)/self.width)**2)
  69. return exp(-((time-self.delay-location/self.cdtds)/self.width)**2)
  70.  
  71. def abc_init(self):
  72. return
  73.  
  74. def abc(self):
  75. self.ez[0] = self.ez[1]
  76.  
  77. def tfsf_init(self):
  78. tfsf_boundary = raw_input('Enter location of tfsf boundary:')
  79. self.ez_inc_init()
  80. return int(tfsf_boundary)
  81.  
  82. def tfsf_update(self,tfsf_boundary):
  83. #print self.time
  84. #print tfsf_boundary
  85. tfsf_boundary = int(tfsf_boundary)
  86. if (tfsf_boundary <= 0):
  87. print 'tfsf boundary error \n'
  88. return
  89. else:
  90. self.hy[tfsf_boundary] -= self.ez_inc(self.time,0.0)*self.chye[tfsf_boundary]
  91. self.ez[tfsf_boundary+1] += self.ez_inc(self.time+0.5,-0.5)

例子

  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import math
  5. import os
  6. from gnuplot_leon import *
  7. from fdtd_leon import *
  8. import threading
  9. # Author : Leon Email: yangli0534@gmail.com
  10. # fdtd simulation , plotting with gnuplot, writting in python
  11. # python and gnuplot software packages should be installed before running this program
  12. # 1d fdtd with absorbing boundary and TFSF boundary
  13. # lossy dielectric material
  14.  
  15. def snashot(gp, fdtd,interval):
  16. """Record a frame data into the gif file
  17.  
  18. Parameters
  19. ----------
  20. gp : class gnuplot_leon
  21. fdtd : class fdtd_leon
  22. interval : int record one every [interval] frames
  23. """
  24. if(fdtd.time % interval == 0):
  25. gp.set_frame_start('l', 1, 'green')
  26. cnt = 0
  27. for elem in fdtd.ez:
  28. gp.update_point(cnt,elem)
  29. cnt += 1
  30. gp.set_frame_end()
  31.  
  32. def report():
  33. """report the rate of progress
  34.  
  35. Parameters
  36. ----------
  37. none
  38. """
  39. global MaxTime
  40. global qTime
  41. print ''.join([str(int(1000.00*int(qTime+1)/int(MaxTime))/10.0),'% has been finished!'])
  42. if(qTime>=MaxTime-1):
  43. return
  44. global timer
  45. timer = threading.Timer(2.0,report)
  46. timer.start()
  47.  
  48. gp = gnuplot_leon()
  49. gp.set_plot_size(0.85,0.85)
  50. gp.set_canvas_size(600,400)
  51. #gp.set_title('fdtd simulation by leon : gnuplot class test')
  52. title = 'fdtd simulation by leon,yangli0534\\\\@gmail.com'
  53.  
  54. gp.set_title(title)
  55. gp.set_gif()
  56. #gp.set_png()
  57. gp.set_file_name('demo3.gif')
  58. gp.set_tics_color('white')
  59. gp.set_border_color('orange')
  60. gp.set_grid_color('orange')
  61. gp.set_bkgr_color('gray10')
  62. gp.set_xlabel('length','white')
  63. gp.set_ylabel('amplitude','white')
  64. gp.auto_scale_enable()
  65. gp.set_key('off','sin(x)','white')
  66.  
  67. size = 400#physical distance
  68. #ez=size * [0.00]#electric field
  69. #hy=size * [0.00]#magnetic field
  70. #ceze=size * [0.00]#
  71. #cezh=size * [0.00]#
  72. #chye=size * [0.00]#
  73. #chyh=size * [0.00]#
  74. #sinwave=size * [0.00]#
  75. imp0 = 377.00
  76. LOSS = 0.01
  77. LOSS_LAYER = 250
  78. qTime = 0
  79. MaxTime = 18000
  80. delay = 30
  81. width = 10
  82. cdtds =1.0
  83. epsR = 9.0
  84. tfsf_boundary = 0
  85. interval = 30
  86. #cnt = 0
  87. #elem = 0.00000
  88. gp.set_x_range(0,size-1)
  89.  
  90. fdtd = fdtd_leon(size,0,MaxTime,delay,width,cdtds)
  91. fdtd.grid_init(LOSS, LOSS_LAYER, epsR)
  92. fdtd.abc_init()
  93. tfsf_boundary = fdtd.tfsf_init()
  94. timer = threading.Timer(1,report)
  95. timer.start()
  96. # do time stepping
  97. for fdtd.time in range(0, MaxTime):
  98. qTime = fdtd.time
  99. fdtd.update_h()
  100. fdtd.tfsf_update(tfsf_boundary)
  101. fdtd.abc()
  102. fdtd.update_e()
  103. snashot(gp,fdtd,interval)
  104.  
  105. gp.set_output_valid()
  106. gp.close()

FDTD Python API的更多相关文章

  1. Appium python API 总结

    Appium python api 根据testerhome的文章,再补充一些文章里面没有提及的API [TOC] [1]find element driver 的方法 注意:这几个方法只能通过sel ...

  2. The novaclient Python API

    The novaclient Python API Usage First create a client instance with your credentials: >>> f ...

  3. Openstack python api 学习文档 api创建虚拟机

    Openstack python api 学习文档 转载请注明http://www.cnblogs.com/juandx/p/4953191.html 因为需要学习使用api接口调用openstack ...

  4. BotVS开发基础—Python API

    代码 import json def main(): # python API列表 https://www.botvs.com/bbs-topic/443 #状态信息 LogStatus(" ...

  5. 《Spark Python API 官方文档中文版》 之 pyspark.sql (一)

    摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...

  6. 《Spark Python API 官方文档中文版》 之 pyspark.sql (二)

    摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...

  7. HBase Python API

    HBase Python API HBase通过thrift机制可以实现多语言编程,信息通过端口传递,因此Python是个不错的选择 吐槽 博主在Mac上配置HBase,奈何Zoomkeeper一直报 ...

  8. 二、Blender/Python API总览

    原文:https://docs.blender.org/api/blender_python_api_current/info_overview.html Python in Blender  Ble ...

  9. Appium+python自动化8-Appium Python API

    Appium+python自动化8-AppiumPython API   前言: Appium Python API全集,不知道哪个大神整理的,这里贴出来分享给大家. 1.contexts conte ...

随机推荐

  1. 重新想象 Windows 8 Store Apps (41) - 打印

    [源码下载] 重新想象 Windows 8 Store Apps (41) - 打印 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 打印 示例1.需要打印的文档Pr ...

  2. Uxf框架引入Rest控制器特性

    引入Rest风格接口的特性,主要是为了适应平台化和移动化开发的需要. 移植自ThinkPHP项目的RestAction. REST(Representational State Transfer表述性 ...

  3. 内核移植和文件系统制作(2):linux内核最小系统和initramfs文件系统

    linux内核最小系统,使用内核版本:https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.8.1.tar.bz2 1,FL2440板子的基本硬件: ...

  4. nginx模块开发(31)—定时器模型

    http://cjhust.blog.163.com/blog/static/175827157201348112639361/   Hello world 模块功能:注册一个定时事件,每过一秒钟打印 ...

  5. 结合源代码详解android消息模型

    Handler是整个消息系统的核心,是Handler向MessageQueue发送的Message,最后Looper也是把消息通知给Handler,所以就从Handler讲起. 一.Handler H ...

  6. 搭建Android 5.0开发环境

    1.Android SDK的安装 下载地址:http://developer.android.com/index.html 访问网站的话请自备梯子 选择:adt-bundle-windows-x86_ ...

  7. JSP Model模式

    用JSP开发的Web应用模型可以分为Model1和Model2 对于小型的Web应用,通常可以使用模型1来完成. 模型1可以分为两种方式: 一种是完全使用JSP页面来开发Web应用: 另一种是使用JS ...

  8. Android中进程与线程

    常说的主线程(UI线程)是什么? 当一个Android程序刚启动的时候,我们的android系统就会启动一个带有一个单一线程的linux进程.默认情况下,所有的组件比如Activity都运行在同样的一 ...

  9. select_tag 选择后自动提交,并且保持选择的项

    使用select来选择,,,选择就响应真是花了好大的功夫....你妹...在controller设置变量来储存选择后的值...js中如果select选择为空那么传入的值是””而不是null selec ...

  10. JavaScript Patterns 4.5 Immediate Functions

    The immediate function pattern is a syntax that enables you to execute a function as soon as it is d ...