FDTD笔记--Script

1、简介
2、Scripting Basics

1、Scripting language

Lumerical 的软件包括基于类似 matlab 矩阵风格的强大脚本语言。通过图形界面可以实现的所有的操作,它几乎能够全部实现——比如操纵仿真对象、运行仿真和分析仿真结果。如果需要设置复杂的模拟对象或执行模拟结果的高级分析,使用脚本通常比通过图形用户界面手动执行所有操作更好。使用脚本语言的巨大优势是任务自动化可重现性

2、Scripting Basics

您可以通过在脚本命令终端中输入单个命令或直接调用脚本文件来运行它们。脚本终端也是所有输出和错误消息出现的地方。

在这里插入图片描述

当要写较长的脚本或想要保存一系列命令以供将来使用时最好将命令保存到脚本文件中。使用集成的脚本文件编辑器最容易做到这一点。可以按运行按钮运行脚本文件,或按键盘上的 F9仅运行选定的部分。

在这里插入图片描述

在script prompt中键入不带 .lsf 扩展名的文件名即可运行任何脚本文件。(用script file Editor 写的脚本文件的扩展名为.lsf,如有脚本文件 myscript.lsf ,在script prompt中输入myscript就可运行。)脚本文件也可以从其他脚本文件中调用,只需包含名称即可,脚本作为另一个文件中的命令。
在这里插入图片描述在这里插入图片描述

还有其他地方可以输入脚本。如果查看model,它是所有其他模拟对象的父对象,可以看到有setup script和analysis script的选项卡。您可以在“Variables”选项卡中定义参数,并使用setup script and analysis script选项卡在对象树中设置模拟对象,并在它运行后分析模拟结果。类似地,脚本也在structure and analysis groups中使用,我们将在下面看到。组对象有三种类型:容器、结构和分析。容器组只是为了组织目的而将对象分组在一起;因此,它没有任何脚本选项。另一方面,结构和分析组允许您在其中使用脚本。分析组有setup script 、 analysis script标签,与父对象“model”相似。结构组比较简单,因为它们不用于分析;因此,它们只有一个setup script选项卡。通过以上述各种方式充分利用脚本,可以有效地设置模拟,并对模拟结果进行高级分析。

点击model,然后点击左上角编辑
当您考虑模拟的脚本时,首先检查对象库有没有。它包含许多常用的结构和分析工具,您可以将它们插入到您的对象树中以便立即使用。如果您需要对象库中不包含的更复杂的结构或高级分析,从可用的示例开始并修改它们而不是从头编写脚本。

现在我们来看看在Lumerical的脚本语言中广泛使用的一些与格式相关的关键操作符。

注释:使用#注释,将#所在的一行且在其后面的内容注释
操作:Ctrl+R—注释
Ctrl+T—取消注释
Ctrl+/–注释选中的内容
缩进:为增加可读性,可以使用缩进
操作:1、Ctrl+] – 在当前行或者选中行前添加四个空格
2、Ctrl+[ – 在当前行或者选中行前删除四个空格
3、Ctrl+I – 选中的行进行智能缩进,没选中内容整个文件进行智能缩进
上述功能右键都能看到

格式:(1)每个语句结尾要有分号;Script Prompt中可以省略分号,它会自动添加上。在Script File Editor中必须正确使用分号。
(2)空白行,空格和tab会被忽略
(3)在脚本行前加上‘?’能输出结果

 

### FDTD Method Plane Wave TE Mode Explanation In the context of Finite-Difference Time-Domain (FDTD) simulations, a transverse electric (TE) mode is characterized by having only magnetic field components perpendicular to the direction of propagation while the electric fields lie within planes normal to this direction. For instance, when considering a wave propagating along the z-axis in an FDTD grid, E_x and E_y represent the electric field components whereas H_z represents the magnetic field component[^1]. The Yee cell structure used in FDTD methods allows for accurate representation of these electromagnetic waves through staggered spatial discretization where different field components are located at slightly offset positions on the computational lattice. #### Implementation Details To implement a plane wave with TE polarization in an FDTD simulation: For initializing such conditions programmatically one can use Python as follows: ```python import numpy as np def initialize_te_wave(grid_size, wavelength, amplitude=1): """Initialize TE-mode plane wave.""" # Define initial condition arrays filled with zeros. ex = np.zeros((grid_size)) ey = np.zeros((grid_size)) hz = np.zeros((grid_size)) k0 = 2 * np.pi / wavelength # Set up sinusoidal excitation source terms here... for i in range(len(ex)): phase_shift = k0 * i # Example initialization using sine function ex[i] += amplitude * np.sin(phase_shift) return {'Ex': ex, 'Ey': ey, 'Hz': hz} ``` This code snippet demonstrates how to set up initial values representing a simple harmonic oscillation pattern that could serve as part of setting boundary or internal sources for launching TE polarized waves inside an FDTD domain.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

phyzj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值