在HFSS建立3D模型時,可以明顯感覺得出來當模型數量越多時,執行速度會越來越慢。舉例來說,利用雙迴圈的python代碼產生20x20的圓柱陣列(如圖一)花了約74秒的時間。更複雜的結構十多分鐘跑不掉。有沒有方法可以加速3D模型的產生?其實是有的,透過在命令行執行腳本,由於不需要打開AEDT視窗,省去了模型渲染的時間,時間大幅縮短到0.8秒,快了足足有92倍之多。以下是程式碼:
(圖一) 20x20 圓柱陣列 |
run.bat
SET PATH=%PATH%;C:\Program Files\AnsysEM\AnsysEM20.2\Win64
ansysedt.exe -features=beta -ng -RunScriptAndExit .\createCylinder.py
createCylinder.py
import ScriptEnv在2020R1時,這個功能仍是beta版,所以在主程式 ansysedt.exe 後面加上-features=beta。 -ng指的是non-graphic模式,因此不會打開AEDT介面。-RunScriptAndExit會在執行python腳本之後結束工作並釋放license。如果要在Python當中執行,可以參考下列代碼:
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.NewProject()
oProject.InsertDesign("HFSS", "HFSSDesign1", "DrivenModal", "")
oDesign = oProject.SetActiveDesign("HFSSDesign1")
oEditor = oDesign.SetActiveEditor("3D Modeler")
for i in range(20):
for j in range(20):
oEditor.CreateCylinder(
[
"NAME:CylinderParameters",
"XCenter:=" , "{}mm".format(i),
"YCenter:=" , "{}mm".format(j),
"ZCenter:=" , "0mm",
"Radius:=" , "0.2mm",
"Height:=" , "0.8mm",
"WhichAxis:=" , "Z",
"NumSides:=" , "0"
],
[
"NAME:Attributes",
"Name:=" , "Cylinder1",
"Flags:=" , "",
"Color:=" , "(143 175 143)",
"Transparency:=" , 0,
"PartCoordinateSystem:=", "Global",
"UDMId:=" , "",
"MaterialValue:=" , "\"vacuum\"",
"SurfaceMaterialValue:=", "\"\"",
"SolveInside:=" , True,
"ShellElement:=" , False,
"ShellElementThickness:=", "0mm",
"IsMaterialEditable:=" , True,
"UseMaterialAppearance:=", False,
"IsLightweight:=" , False
])
oProject.SaveAs("D:\\demo\\case3.aedt", True)
oDesktop.CloseProject("case3")
import os
import subprocess
os.environ["PATH"] = 'C:/Program Files/AnsysEM/AnsysEM20.1/Win64'
subprocess.check_call(['ansysedt.exe', '-features=beta', '-ng', '-RunScriptAndExit', 'd:/demo2/test.py'])
沒有留言:
張貼留言