2021年5月4日 星期二

如何計算多個beam所合成的EIRP輻射場型

腳本讀取每個beam並記錄其對應的rETotal。完成特定角度最大值運算之後會輸出.tab檔。在HFSS當中匯入.tab檔即可畫出其3D幅射場型及2D contour。

# coding=UTF-8
# User Input--------------------------------------------------------
solution = "Setup1 : LastAdaptive"
freq = "28e9"
code_dir = "D:/demo/code"
output_path = 'd:/demo/EIRP.tab'

# Don't Revise Code Below-------------------------------------------
from math import log10
import os
import time
import json
import itertools
import ScriptEnv

t0 = time.time()

ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oDesktop.ClearMessages("", "", 2)
oModule = oDesign.GetModule("ReportSetup")
try:
oModule.DeleteAllReports()
except:
pass


def getrE():
arr = oModule.GetSolutionDataPerVariation(
"Far Fields",
solution,
[
"Context:=" , "3D"
],
['Freq:=', [freq]],
["rETotal"])

rETotal = [x for x in arr[0].GetRealDataValues("rETotal")]
if len(rETotal) != 65341:
raise Exception("Theta, Phi範圍錯誤!")
return rETotal

def setExcitation(csv_path):
oModule = oDesign.GetModule("BoundarySetup")
ports = [i.replace(':1', '') for i in oModule.GetExcitations()[::2]]
x = {name: ("0W", "0deg") for name in ports}

try:
with open(csv_path) as f:
text = f.readlines()

for i in text[1:]:
try:
source, magnitude, phase = i.split(',')
x[source.replace(':1', '')] = (magnitude, phase)
except:
pass

oModule = oDesign.GetModule("Solutions")
y = []
for name in x:
magnitude, phase = x[name]
y.append([
"Name:=" , name,
"Magnitude:=" , magnitude,
"Phase:=" , phase
])

oModule.EditSources(
[
[
"IncludePortPostProcessing:=", False,
"SpecifySystemPower:=" , False
],
] + y)

for name in x:
magnitude, phase = x[name]
# AddInfoMessage("{}: {}, {}".format(name, magnitude, phase))
AddWarningMessage('Load "{}" successfully!'.format(csv_path))

except:
AddErrorMessage('Load "{}" failed!'.format(csv_path))

data = []
for i in os.listdir(code_dir):
csv_path = os.path.join(code_dir, i)
setExcitation(csv_path)
data.append(getrE())

max_table = list(map(max, zip(*data)))

with open(output_path, 'w') as f:
f.writelines('Phi[deg],Theta[deg],EIRP[dbm/sr]\n')

for Er, (phi, theta) in zip(max_table, itertools.product(range(-180 ,181), range(0 ,181) ,)):
maxU = 10*log10(Er**2/377/2)+30
f.writelines('{}\t{}\t{}\n'.format(phi, theta, maxU))

AddWarningMessage(str(time.time( )-t0))

(圖一) 3D角度設定範圍及解析度


(圖二) EIRP



沒有留言:

張貼留言