2022年3月28日 星期一

如何列出特定目錄底下所有.aedt專案與專案包含的設計名稱

當累積的專案數量很多時,想要查找某個設計是放在哪一個.aedt檔當中相當花時間,用下面pyaedt腳本可以輸出所有專案與專案當中的設計名稱與設計類型(HFSS, Q3D, Circuit...)。不須開啟GUI便可完成輸出。

folder = r"D:\demo\Examples"

import os
import pyaedt
from pyaedt import Desktop

aedts = []
for dirPath, dirNames, fileNames in os.walk(folder):
for f in fileNames:
if f.endswith('.aedt'):
aedts.append(os.path.join(dirPath, f))

info = {}
desktop = Desktop(specified_version='2022.1', non_graphical=True)
for n, i in enumerate(aedts):
if os.path.isfile(i + '.lock'):
os.remove(i + '.lock')
print(f'{n}/{len(aedts)}:{i}')
try:
oproject = desktop.odesktop.OpenProject(i)
designs = oproject.GetChildNames()
types = [oproject.GetChildObject(j).GetDesignType() for j in designs]
info[i] = list(zip(designs, types))
oproject.Close()
except:
pass
desktop.close_desktop()

# %%
design_map = {'HFSS': pyaedt.Hfss,
'HFSS 3D Layout Design': pyaedt.Hfss3dLayout,
'Q3D Extractor': pyaedt.Q3d,
'2D Extractor': pyaedt.Q2d,
'Circuit Design': pyaedt.Circuit,
'Maxwell 2D': pyaedt.Maxwell2d,
'Maxwell 3D': pyaedt.Maxwell3d,
'Icepak': pyaedt.Icepak,
'Twin Builder': pyaedt.TwinBuilder,
'Mechanical': pyaedt.Mechanical,
'EMIT': pyaedt.Emit,
'RMxprt': pyaedt.Rmxprt
}

k = 0
result = {}
for i, design_info in info.items():
result[i] = []
for m, n in design_info:
try:
app = design_map[n](i, m, specified_version='2022.1')
image_path = os.path.abspath(f'{k}.jpg')
app.export_design_preview_to_jpg(image_path)
k += 1
app.close_project()

result[i].append((m, n, image_path))
except:
raise

# %%

css = '''
<style>
* {
box-sizing: border-box;
}

/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 25%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}

/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
'''

with open('summary.html', 'w') as f:
f.write(css)
for aedt_path, data in result.items():
f.write(f'<H2 style="color:blue;">{aedt_path}</H2>\n')
f.write('<div class="row">\n')
for design_name, design_type, image in data:
f.write('<div class="column">\n')
f.write(f'<H3>{design_name} ({design_type})</H3>\n')
f.write(f'<img src="{image}" width="200">\n')
f.write('</div>\n')
f.write('</div>\n')
os.system('summary.html')
print(result)






2022年3月26日 星期六

如何在AEDT比較不同專案設計的S參數

在AEDT比較不同專案設計的S參數

prj_design = [('bp_filter', 'HFSSDesign1', 'S(2,1)'), 
('OptimTee', 'TeeModel', 'S(1,1)') ]


#%%
from pyaedt import Hfss
import matplotlib.pyplot as plt

color = ['r', 'b', 'g', 'y', 'm', 'c']

cases = []
for prj, design, quantity in prj_design:
cases.append((Hfss(projectname=prj, designname=design, specified_version='2022.1',), quantity))

#%%

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
for (i, q), c in zip(cases, color):
result = i.post.get_report_data(f'polar({q})')
ax.plot(result.data_imag(), result.data_real(), color=c)

fig.show()

#%%
fig, ax = plt.subplots()
plt.grid()
for (i, q), c in zip(cases, color):
result = i.post.get_report_data(f'db({q})')
ax.plot(result.sweeps['Freq'], result.data_real(), color=c)

fig.show()

#%%
fig, ax = plt.subplots()
plt.grid()
for (i, q), c in zip(cases, color):
result = i.post.get_report_data(f'ang_deg({q})')
ax.plot(result.sweeps['Freq'], result.data_real(), color=c)

fig.show()


2022年3月12日 星期六

如何輸出HFSS近場資料


import numpy as np
import matplotlib.pyplot as plt
from pyaedt import Hfss
hfss = Hfss(specified_version='2022.1')

data = hfss.post.get_solution_data_per_variation('Near Fields', 'Setup1 : LastAdaptive', "Rectangle1", expression='NearEX')
print(data.units_data)

x_real = data.solutions_data_real['NearEX'].values()
x_imag = data.solutions_data_imag['NearEX'].values()
data.sweeps['_u']
NearEX = [complex(i, j) for i, j in zip(x_real, x_imag)]

NearEX = np.array(NearEX)
x = np.reshape(np.absolute(NearEX), (len(data.sweeps['_u']), len(data.sweeps['_v'])))

u_min, u_max = min(data.sweeps['_u'])*1000, max(data.sweeps['_u'])*1000
v_min, v_max = min(data.sweeps['_v']), max(data.sweeps['_v'])

plt.xlabel('u')
plt.ylabel('v')
plt.imshow(x, cmap='jet', extent = [u_min, u_max, v_min, v_max])
(圖一) Python輸出近場
(圖二) HFSS近場



如何輸出HFSS遠場資料

以下方法可以用在HFSS任何遠場物理量輸出,使用np.ndarray可以加快矩陣運算速度。

import numpy as np
import matplotlib.pyplot as plt
from pyaedt import Hfss
hfss = Hfss(specified_version='2022.1')

data = hfss.post.get_far_field_data(['rETheta', 'rEPhi'],
'Setup1 : LastAdaptive',
'3D')
print(data.units_data)

x_real = data.solutions_data_real['rETheta']
x_imag = data.solutions_data_imag['rETheta']
rETheta = [complex(x_real[i], x_imag[i]) for i in x_real]


x_real = data.solutions_data_real['rEPhi']
x_imag = data.solutions_data_imag['rEPhi']
rEPhi = [complex(x_real[i], x_imag[i]) for i in x_real]

rEPhi = np.array(rEPhi)
x = np.reshape(np.absolute(rEPhi), (361, 181))

plt.xlabel('Phi')
plt.ylabel('Theta')
plt.imshow(x.T, cmap='jet')

(圖一) Python輸出
(圖二)HFSS輸出









EDB建立PinGroup

為U2A5建立GND PinGroup,儲存之後匯入EDB from pyaedt import Edb edb = Edb(edbpath= r"D:\demo\Galileo_G87173_20454.aedb" , edbversion= '20...