-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExampleOfMicrowaveWindow.py
More file actions
195 lines (174 loc) · 4.73 KB
/
ExampleOfMicrowaveWindow.py
File metadata and controls
195 lines (174 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
from Modeling import *
def DoubleRidgeWaveGuide(
mws, DRWname, Component, Name, length, a, b, d, s, Matetial="Vacuum"
):
# 进行脊波导的建模
DRW = Brick(
mws,
f"Create Double Ridge Waveguide :{DRWname}",
Component,
Name,
Matetial,
[f"-{a}/2", f"{a}/2"],
[f"-{b}/2", f"{b}/2"],
[length[0], length[1]],
)
L = 10
cutoff = Brick(
mws,
f"Create the cut-off part of {DRWname}",
Component,
DRWname + "cutoff",
Matetial,
[f"-{s}/2", f"{s}/2"],
[f"{d}/2", f"{b}/2"],
[length[0], length[1]],
)
transform = Transform(mws)
transform.MirrorTransForm(
f"Mirror transform the cut-off part of {DRWname}",
cutoff.Component,
cutoff.Name,
[0, -1, 0],
True,
)
# 切除波导冗余部位
solid = Solid(mws)
solid.Subtract(
f"Cut the cutoff part 1",
DRW.Component,
DRW.Name,
cutoff.Component,
cutoff.Name,
)
solid.Subtract(
f"Cut the cutoff part 2",
DRW.Component,
DRW.Name,
cutoff.Component,
cutoff.Name + "_1",
)
return DRW
path = os.path.dirname(
os.path.abspath(__file__)
) # 获取当前py文件所在文件夹路径,方便保存
filename = "Test.cst" # 保存的文件的名称,要加后缀cst
projectName = os.path.join(path, filename)
# init = Initial(lable='Open', ProjectName=projectName)
init = Initial()
mws = init.mws
cst = init.cst
CstSaveAsProject(mws, projectName) # 在新建时候保存用
SimulateFrequency = [8, 9]
# 使用模板来对项目进行初始化
history = StructureMacros(mws)
init.UseTemplate(
Template="WaveGuide And Cavity Filter", FrequencyRange=SimulateFrequency
)
# 加载变量名
parametersfilename = "ParameterList.txt"
parameterspath = os.path.join(path, parametersfilename)
# 将处理好的变量存储到应用中
init.StoreParameters(parameterspath)
# 创建材料Sapphire蓝宝石
sapphire = Material(mws, "Sapphire", 6.5, 1)
# 创建圆柱形窗片
cylinderwindow = Cylinder(
mws,
"Creat the sappire disc",
"Window",
"SapphireWindow",
sapphire.MaterialName,
"z",
0,
"wr",
[0, 0, 0],
["-wt/2", "wt/2"],
)
# 选取圆柱形窗片中点,将坐标系进行位移
pick = Pick(mws)
pick.PickCenterpointFromId(
"选取圆柱窗片中心点", cylinderwindow.Component, cylinderwindow.Name, 3
)
wcs = WCS(mws)
wcs.AlignWCSWithSelectedPoint("将中心点移到圆柱窗片中心")
solid = Solid(mws)
waveguide = DoubleRidgeWaveGuide(
mws, "DoubleRidgeWaveGuide", "WaveGuide", "DRW1", [0, 10], "a", "b", "d", "s"
)
# 补偿波导建模,顺便一提论文的这个部分有问题,具体的宽度我只能脑测了
transportwaveguide = Brick(
mws,
"Add transport waveguide",
waveguide.Component,
"TW",
waveguide.Material,
["-ta/2", "ta/2"],
["-tb/2", "tb/2"],
[0, "trh"],
)
solid.Add(
"Add the DRW with the transport waveguide",
waveguide.Component,
waveguide.Name,
waveguide.Component,
"TW",
)
trans = Transform(mws)
# 创建全局坐标系,进行变换
wcs.ActivateWCSGlobal()
trans.MirrorTransForm(
"Mirror Transformation of DRW",
waveguide.Component,
waveguide.Name,
[0, 0, -1],
True,
)
# 选取面,并且设置端口
pick.PickFaceFromId("Pick face 1", waveguide.Component, waveguide.Name, 27)
Port(
mws,
"Add port 1",
[["-a/2", "a/2"], ["-b/2", "b/2"], ["wt/2+10", "wt/2+10"]],
PortNumber=1,
)
pick.PickFaceFromId("Pick face 2", waveguide.Component, waveguide.Name + "_1", 27)
Port(
mws,
"Add port 2",
[["-a/2", "a/2"], ["-b/2", "b/2"], ["-(wt/2+10)", "-(wt/2+10)"]],
PortNumber=2,
)
# 更新网格并且求解(我不会写网格更新(悲))
mesh = Mesh(mws)
mesh.init(10, 5, 6, 5)
mesh.MeshUpdate("Update the mesh")
# 进行求解(我也不会写求解器(悲))
solver = Solver(mws)
solver.FDSolver()
# 求解S参数后处理
postprocess = PostProcessingItems(mws)
(
resultdatas,
Frequencyseries,
SREALseries,
SIMAGEseries,
) = postprocess.GetSparametersinRunID(ResultTag="S12")
Sdbs = []
for runid, Sreal in enumerate(SREALseries):
Sdb = []
for index, Sparameter in enumerate(Sreal):
Sparameterdb = 20 * math.log10(
abs(complex(Sreal[index], SIMAGEseries[runid][index]))
)
Sdb.append(Sparameterdb)
# plt.figure(runid) # 注释了的话那就在同一张图上
plt.plot(Frequencyseries[runid], Sdb)
plt.xlabel(resultdatas[runid].GetXlabel)
plt.ylabel("Magnitude in dB")
plt.title("S11, Current RunId:" + str(runid))
# plt.show()
Sdbs.append(Sdb)
plt.show()
pathofselected = postprocess.GetSelectedTreeItem()
pass