-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modeling.py
1228 lines (1097 loc) · 40.4 KB
/
Modeling.py
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
encode with UTF-8
PYTHON version 3.11.4 64-bit
CST Studio version 2022
"""
import math
import win32com.client
import os
import re
import matplotlib.pyplot as plt
def quotes_to_list(text):
"""
这是一个将跨行字符串分行转化为数组的函数
一般我在将VBA语句大卸八块的时候会用这个函数作为辅助
"""
lines = text.splitlines()
quoted_lines = ["" + line.lstrip() + "" for line in lines]
return quoted_lines
class StructureMacros:
mws = None
Classname = "StructureMacros"
def __init__(self, handle) -> None:
self.mws = handle
if self.mws == None:
raise ("MWS未进行初始化,请重新进行mws初始化")
else:
print(f"{self.Classname}MWS初始化成功{' '*20}", end="\r")
pass
def AddToHistoryWithList(self, Tag, Command):
"""
添加到历史树
Command只能是队列哦,不能传输裸字符串!
适合在传递一小段一小段语句语句自定义程度较高的时候使用
"""
line_break = "\n" # 这句话表示将每个单句用换行符链接起来
Command = line_break.join(Command) # 这句话表示将每个单句用换行符链接起来
# AddToHistory ( string caption, string contents ) bool
# 隶属于ProjectObject的方法,必须使用mws对象进行调用
self.mws._FlagAsMethod("AddToHistory")
self.mws.AddToHistory(Tag, Command)
def AddToHistoryWithCommand(self, Tag, Command):
"""
添加到历史树
可以传输字符串,适合整段整段懒得改的时候的语句使用
"""
# AddToHistory ( string caption, string contents ) bool
# 隶属于ProjectObject的方法,必须使用mws对象进行调用
self.mws._FlagAsMethod("AddToHistory")
self.mws.AddToHistory(Tag, Command)
class Initial(StructureMacros):
cst = None
mws = None
def __init__(self, lable="New", ProjectName=" ") -> None:
self.cst = self.OpenCST()
if lable == "New":
handle = self.NewProject()
self.BackGroundInitial()
self.UnitInitial()
self.BoundaryInitial()
elif lable == "Open":
handle = self.OpenProject(ProjectName=ProjectName)
def OpenCST(self):
# 调用COM对象,COM对象的名字叫CSTStudio.Application
self.cst = win32com.client.dynamic.Dispatch("CSTStudio.Application")
return self.cst
def NewProject(self):
# 新建一个微波工作室,返回一个操控当前项目的COM组件
self.cst.NewMWS()
self.mws = self.cst.Active3D()
return self.mws
def OpenProject(self, ProjectName):
# 打开一个项目,返回一个操控当前项目的COM组件
self.cst.OpenFile(ProjectName)
self.mws = self.cst.Active3D()
return self.mws
def BackGroundInitial(self):
sCommand = ["With Background", ".ResetBackground", '.Type "PEC"', "End With"]
self.AddToHistoryWithList(Tag="Background Initial", Command=sCommand)
def UnitInitial(self):
sCommand = [
"With Units",
'.Geometry "mm"',
'.Frequency "ghz"',
'.Time "ns"',
"End With",
]
self.AddToHistoryWithList(Tag="Unit Initial", Command=sCommand)
def BoundaryInitial(self):
sCommand = [
"With Boundary",
'.Xmin "electric"',
'.Xmax "electric"',
'.Ymin "electric"',
'.Ymax "electric"',
'.Zmin "electric"',
'.Zmax "electric"',
'.Xsymmetry "none"',
'.Ysymmetry "none"',
'.Zsymmetry "none"',
"End With",
]
self.AddToHistoryWithList(Tag="Boundary Initial", Command=sCommand)
def StoreParameters(self, parameterspath, encodewith="utf-8"):
# 首先将指定路径的文件一行一行的读取出来
# 文件可以是CST直接导出的变量文件
# 创建一个空字典来存储变量信息
variables = {}
# 打开文件并读取每一行
with open(parameterspath, "r", encoding=encodewith) as f:
for line in f:
if line.strip() == "":#如果有空行,那么就跳过这个循环,也就跳过空行了
continue
# 分割每一行并获取变量名和值
parts = line.split("=")
var_name = parts[0].strip()
var_value, var_description = (
parts[1].split('"')[1],
parts[1].split('"')[3],
)
# 将变量名、值和描述存储在字典中
variables[var_name] = {
"value": var_value,
"description": var_description,
}
self.ProcessingDictionary(variables)
return variables
def ProcessingDictionary(self, variables):
sCommand = ""
for key, value in variables.items():
sCommand += """
MakeSureParameterExists("{0}", "{1}")
SetParameterDescription ( "{2}", "{3}" )
""".format(
key, value["value"], key, value["description"]
)
self.AddToHistoryWithCommand("Storeparameters", sCommand)
def UseTemplate(self, Template, FrequencyRange):
if Template == "WaveGuide And Cavity Filter":
sCommand = f"""
'set the units
With Units
.Geometry "mm"
.Frequency "GHz"
.Voltage "V"
.Resistance "Ohm"
.Inductance "NanoH"
.TemperatureUnit "Kelvin"
.Time "ns"
.Current "A"
.Conductance "Siemens"
.Capacitance "PikoF"
End With
'----------------------------------------------------------------------------
'set the frequency range
Solver.FrequencyRange "{FrequencyRange[0]}", "{FrequencyRange[1]}"
'----------------------------------------------------------------------------
' History:
' jei, vso 18-Jan-2012: ver1
' 28-Jan-2020: ver2
' boundaries
With Boundary
.Xmin "electric"
.Xmax "electric"
.Ymin "electric"
.Ymax "electric"
.Zmin "electric"
.Zmax "electric"
End With
With Material
.Reset
.FrqType "all"
.Type "Pec"
.ChangeBackgroundMaterial
End With
With Mesh
.MeshType "PBA"
.SetCreator "High Frequency"
.AutomeshRefineAtPecLines "True", "2"
.UseRatioLimit "True"
.RatioLimit "10"
.LinesPerWavelength "20"
.MinimumStepNumber "10"
.Automesh "True"
End With
With MeshSettings
.SetMeshType "Hex"
.Set "StepsPerWaveNear", "13"
End With
' solver - FD settings
With FDSolver
.Reset
.Method "Tetrahedral Mesh" ' i.e. general purpose
.AccuracyHex "1e-6"
.AccuracyTet "1e-5"
.AccuracySrf "1e-3"
.SetUseFastResonantForSweepTet "False"
.Type "Direct"
.MeshAdaptionHex "False"
.MeshAdaptionTet "True"
.InterpolationSamples "5001"
End With
With MeshAdaption3D
.SetType "HighFrequencyTet"
.SetAdaptionStrategy "Energy"
.MinPasses "3"
.MaxPasses "10"
End With
With FDSolver
.Method "Tetrahedral Mesh (MOR)"
.HexMORSettings "", "5001"
End With
FDSolver.Method "Tetrahedral Mesh" ' i.e. general purpose
'----------------------------------------------------------------------------
With MeshSettings
.SetMeshType "Tet"
.Set "Version", 1%
End With
With Mesh
.MeshType "Tetrahedral"
End With
'set the solver type
ChangeSolverType("HF Frequency Domain")
'----------------------------------------------------------------------------
"""
self.AddToHistoryWithCommand(
"Template:WaveGuide And Cavity Filter", sCommand
)
else:
raise ("NoSuchTemplate")
class Material(StructureMacros):
MaterialName = ""
MaterialEpsilon = 0
MaterialMu = 0
Classname = "Material"
def __init__(self, handle, Name, Epsilon, Mu) -> None:
super().__init__(handle)
self.MaterialName = Name
self.MaterialEpsilon = Epsilon
self.MaterialMu = Mu
self.materialcreate()
def materialcreate(self):
sCommand = f"""With Material
.Reset
.Name "{self.MaterialName}"
.Folder ""
.Rho "0.0"
.ThermalType "Normal"
.ThermalConductivity "0"
.SpecificHeat "0", "J/K/kg"
.DynamicViscosity "0"
.Emissivity "0"
.MetabolicRate "0.0"
.VoxelConvection "0.0"
.BloodFlow "0"
.MechanicsType "Unused"
.IntrinsicCarrierDensity "0"
.FrqType "all"
.Type "Normal"
.MaterialUnit "Frequency", "GHz"
.MaterialUnit "Geometry", "mm"
.MaterialUnit "Time", "ns"
.MaterialUnit "Temperature", "Kelvin"
.Epsilon "{self.MaterialEpsilon}"
.Mu "{self.MaterialMu}"
.Sigma "0"
.TanD "0.0"
.TanDFreq "0.0"
.TanDGiven "False"
.TanDModel "ConstTanD"
.SetConstTanDStrategyEps "AutomaticOrder"
.ConstTanDModelOrderEps "3"
.DjordjevicSarkarUpperFreqEps "0"
.SetElParametricConductivity "False"
.ReferenceCoordSystem "Global"
.CoordSystemType "Cartesian"
.SigmaM "0"
.TanDM "0.0"
.TanDMFreq "0.0"
.TanDMGiven "False"
.TanDMModel "ConstTanD"
.SetConstTanDStrategyMu "AutomaticOrder"
.ConstTanDModelOrderMu "3"
.DjordjevicSarkarUpperFreqMu "0"
.SetMagParametricConductivity "False"
.DispModelEps "None"
.DispModelMu "None"
.DispersiveFittingSchemeEps "Nth Order"
.MaximalOrderNthModelFitEps "10"
.ErrorLimitNthModelFitEps "0.1"
.UseOnlyDataInSimFreqRangeNthModelEps "False"
.DispersiveFittingSchemeMu "Nth Order"
.MaximalOrderNthModelFitMu "10"
.ErrorLimitNthModelFitMu "0.1"
.UseOnlyDataInSimFreqRangeNthModelMu "False"
.UseGeneralDispersionEps "False"
.UseGeneralDispersionMu "False"
.NLAnisotropy "False"
.NLAStackingFactor "1"
.NLADirectionX "1"
.NLADirectionY "0"
.NLADirectionZ "0"
.Colour "0", "1", "0"
.Wireframe "False"
.Reflection "False"
.Allowoutline "True"
.Transparentoutline "False"
.Transparency "0"
.Create
End With"""
self.AddToHistoryWithCommand(
Tag="Add Material " + self.MaterialName, Command=sCommand
)
return self
class GeneralModel(StructureMacros):
Component = ""
Name = ""
Material = ""
Tag = ""
Classname = "GeneralModel"
def __init__(self, handle, Tag, Component, Name, Material) -> None:
super().__init__(handle)
self.Component = Component
self.Name = Name
self.Material = Material
self.Tag = Tag
def create(self):
pass
class Brick(GeneralModel):
Xrange = [0, 1]
Yrange = [0, 1]
Zrange = [0, 1]
Component = "Hallo"
Name = "World"
Material = "PEC"
Classname = "Brick"
def __init__(
self, handle, Tag, Component, Name, Material, Xrange, Yrange, Zrange
) -> None:
super().__init__(handle, Tag, Component, Name, Material)
self.Xrange = Xrange
self.Yrange = Yrange
self.Zrange = Zrange
self.create()
def create(self):
Command = f"""With Brick
.Reset
.Name "{self.Name}"
.Component "{self.Component}"
.Material "{self.Material}"
.Xrange "{self.Xrange[0]}", "{self.Xrange[1]}"
.Yrange "{self.Yrange[0]}", "{self.Yrange[1]}"
.Zrange "{self.Zrange[0]}", "{self.Zrange[1]}"
.Create
End With"""
self.AddToHistoryWithCommand(self.Tag, Command)
return self
class Cylinder(GeneralModel):
Material = "Vacuum"
Innerradius = 0
Outerradius = 0
Xcenter = 0
Ycenter = 0
Zcenter = 0
Xrange = [0, 0]
Yrange = [0, 0]
Zrange = [0, 0]
Range = [0, 0]
Segments = 0
Axis = "z"
Classname = "Cylinder"
def __init__(
self,
handle,
Tag,
Component,
Name,
Material,
Axis,
Innerradius,
Outerradius,
Center,
Range,
Segments=0,
) -> None:
super().__init__(handle, Tag, Component, Name, Material)
self.Innerradius = Innerradius
self.Outerradius = Outerradius
self.Xcenter = Center[0]
self.Ycenter = Center[1]
self.Zcenter = Center[2]
self.Range = Range
self.Segments = Segments
self.Axis = Axis
self.create()
def create(self):
sCommand = f"""With Cylinder
.Reset
.Name ("{self.Name}")
.Component ("{self.Component}")
.Material ("{self.Material}")
.Axis ("{self.Axis}")
.Outerradius ("{self.Outerradius}")
.Innerradius ("{self.Innerradius}")
.Xcenter ("{self.Xcenter}")
.Ycenter ("{self.Ycenter}")
.Zcenter ("{self.Zcenter}")"""
if self.Axis == "z":
sCommand = (
sCommand
+ f"""
.Zrange ("{self.Range[0]}", "{self.Range[1]}")
.Segments ("{self.Segments}")
.Create
End With"""
)
elif self.Axis == "y":
sCommand = (
sCommand
+ f"""
.Yrange ("{self.Range[0]}", "{self.Range[1]}")
.Segments ("{self.Segments}")
.Create
End With"""
)
elif self.Axis == "x":
sCommand = (
sCommand
+ f"""
.Xrange ("{self.Range[0]}", "{self.Range[1]}")
.Segments ("{self.Segments}")
.Create
End With"""
)
self.AddToHistoryWithCommand(Tag=self.Tag, Command=sCommand)
return self
class AnalyticalFace(GeneralModel):
LawX = ""
LawY = ""
LawZ = ""
ParameterRangeU = ""
ParameterRangeV = ""
Classname = "AnalyticalFace"
def __init__(
self,
handle,
Tag,
Component,
Name,
Material,
LawX,
LawY,
LawZ,
ParameterRangeU,
ParameterRangeV,
) -> None:
super().__init__(handle, Tag, Component, Name, Material)
self.LawX = LawX
self.LawY = LawY
self.LawZ = LawZ
self.ParameterRangeU = ParameterRangeU
self.ParameterRangeV = ParameterRangeV
self.create()
def create(self):
sCommand = f"""
With AnalyticalFace
.Reset
.Name "{self.Name}"
.Component "{self.Component}"
.Material "{self.Material}"
.LawX "{self.LawX}"
.LawY "{self.LawY}"
.LawZ "{self.LawZ}"
.ParameterRangeU "{self.ParameterRangeU[0]}", "{self.ParameterRangeU[1]}"
.ParameterRangeV "{self.ParameterRangeV[0]}", "{self.ParameterRangeV[1]}"
.Create
End With"""
self.AddToHistoryWithCommand(self.Tag, sCommand)
return super().create()
class Pick(StructureMacros):
Classname = "Pick"
def __init__(self, handle) -> None:
super().__init__(handle)
def PickCenterpointFromId(self, Tag, Component, Name, Id):
sCommand = f'Pick.PickCenterpointFromId "{Component}:{Name}", "{Id}"'
self.AddToHistoryWithCommand(Tag, sCommand)
def PickFaceFromId(self, Tag, Component, Name, Id):
sCommand = f'Pick.PickFaceFromId "{Component}:{Name}", "{Id}"'
self.AddToHistoryWithCommand(Tag, sCommand)
def PickEdgeFromId(self, Tag, Component, Name, edge_id, vertex_id):
sCommand = (
f'Pick.PickEdgeFromId "{Component}:{Name}", "{edge_id}", "{vertex_id}"'
)
self.AddToHistoryWithCommand(Tag, sCommand)
def PickEdgeFromPoint(self, Tag, Component, Name, PointCoordinate):
sCommand = f'Pick.PickEdgeFromPoint "{Component}:{Name}",{PointCoordinate[0]},{PointCoordinate[1]},{PointCoordinate[2]}'
self.AddToHistoryWithCommand(Tag, sCommand)
def PickFaceFromPoint(self, Tag, Component, Name, PointCoordinate):
sCommand = f'Pick.PickFaceFromPoint "{Component}:{Name}",{PointCoordinate[0]},{PointCoordinate[1]},{PointCoordinate[2]}'
self.AddToHistoryWithCommand(Tag, sCommand)
def PickPointFromCoordinates(self, Tag, PointCoordinate):
sCommand = f"Pick.PickPointFromCoordinates {PointCoordinate[0]},{PointCoordinate[1]},{PointCoordinate[2]}"
self.AddToHistoryWithCommand(Tag, sCommand)
class WCS(StructureMacros):
Classname = "WCS"
def __init__(self, handle) -> None:
super().__init__(handle)
def AlignWCSWithSelectedPoint(self, Tag):
self.AddToHistoryWithCommand(Tag, 'WCS.AlignWCSWithSelected "Point"')
def ActivateWCSGlobal(self):
self.AddToHistoryWithCommand(
"Active the global WCS", 'WCS.ActivateWCS "global"'
)
def AlignWCSWithSelectedFace(self, Tag):
self.AddToHistoryWithCommand(Tag, 'WCS.AlignWCSWithSelected "Face"')
class Transform(StructureMacros):
Classname = "Transform"
def __init__(self, handle) -> None:
super().__init__(handle)
def MirrorTransForm(self, Tag, Component, Name, NormalVector, Copy):
sCommand = f"""With Transform
.Reset
.Name "{Component}:{Name}"
.Origin "Free"
.Center "0", "0", "0"
.PlaneNormal "{NormalVector[0]}", "{NormalVector[1]}", "{NormalVector[2]}"
.MultipleObjects "{Copy}"
.GroupObjects "False"
.Repetitions "1"
.MultipleSelection "False"
.Destination ""
.Material ""
.Transform "Shape", "Mirror"
End With"""
self.AddToHistoryWithCommand(Tag, sCommand)
def TranslateTransform(
self, Tag, Component, Name, TransVector, Copy, RepetitionFactor
):
sCommand = f"""With Transform
.Reset
.Name "{Component}:{Name}"
.Vector "{TransVector[0]}", "{TransVector[1]}", "{TransVector[2]}"
.UsePickedPoints "False"
.InvertPickedPoints "False"
.MultipleObjects "{Copy}"
.GroupObjects "False"
.Repetitions "{RepetitionFactor}"
.MultipleSelection "False"
.Destination ""
.Material ""
.Transform "Shape", "Translate"
End With"""
self.AddToHistoryWithCommand(Tag, sCommand)
class Solid(StructureMacros):
Classname = "Solid"
def __init__(self, handle) -> None:
super().__init__(handle)
def Subtract(self, Tag, component1, name1, component2, name2):
sCommand = f'Solid.Subtract "{component1}:{name1}", "{component2}:{name2}"'
self.AddToHistoryWithCommand(Tag, sCommand)
def Add(self, Tag, component1, name1, component2, name2):
sCommand = f'Solid.Add "{component1}:{name1}", "{component2}:{name2}"'
self.AddToHistoryWithCommand(Tag, sCommand) # 留下来的是后面的那个面,后来居上
def BlendEdge(self, Tag, radius):
sCommand = f'Solid.BlendEdge "{radius}"'
self.AddToHistoryWithCommand(Tag, sCommand)
def Insert(self, Tag, component1, name1, component2, name2):
sCommand = f'Solid.Insert "{component1}:{name1}", "{component2}:{name2}"'
self.AddToHistoryWithCommand(Tag, sCommand)
class Loft(GeneralModel):
Classname = "Loft"
Tangency = "0"
def __init__(self, handle, Tag, Component, Name, Material, Tangency) -> None:
super().__init__(handle, Tag, Component, Name, Material)
self.Tangency = Tangency
self.create()
def create(self):
sCommand = f"""
With Loft
.Reset
.Name "{self.Name}"
.Component "{self.Component}"
.Material "{self.Material}"
.Tangency "{self.Tangency}"
.CreateNew
End With"""
self.AddToHistoryWithCommand(self.Tag, sCommand)
return super().create()
class Extrude(GeneralModel):
Mode = "Picks"
Height = ""
Twist = ""
Taper = ""
UsePicksForHeight = "False"
DeleteBaseFaceSolid = "False"
KeepMaterial = "False"
ClearPickedFace = "True"
def __init__(
self, handle, Tag, Component, Name, Material, Height, Twist, Taper, **kwargs
) -> None:
super().__init__(handle, Tag, Component, Name, Material)
self.Height = Height
self.Twist = Twist
self.Taper = Taper
for key, value in kwargs.items():
match key:
case "Mode":
self.Mode = value
case "UsePicksForHeight":
self.UsePicksForHeight = value
case "DeleteBaseFaceSolid":
self.DeleteBaseFaceSolid = value
case "KeepMaterial":
self.KeepMaterial = value
case "ClearPickedFace":
self.ClearPickedFace = value
case _:
raise ("DameDane")
self.Tag = Tag
self.create()
def create(self):
sCommand = f"""
With Extrude
.Reset
.Name "{self.Name}"
.Component "{self.Component}"
.Material "{self.Material}"
.Mode "{self.Mode}"
.Height "{self.Height}"
.Twist "{self.Twist}"
.Taper "{self.Taper}"
.UsePicksForHeight "{self.UsePicksForHeight}"
.DeleteBaseFaceSolid "{self.DeleteBaseFaceSolid}"
.KeepMaterials "{self.KeepMaterial}"
.ClearPickedFace "{self.ClearPickedFace}"
.Create
End With
"""
self.AddToHistoryWithCommand(self.Tag, sCommand)
return super().create()
class Port(StructureMacros):
PortNumber = 1
NumberOfModes = 1
Coordinates = "Picks"
Orientation = "positive"
PortOnBound = "True"
AdjustPolarization = "False"
Xrange = [0, 0]
XrangeAdd = [0, 0]
Yrange = [0, 0]
YrangeAdd = [0, 0]
Zrange = [0, 0]
ZrangeAdd = [0, 0]
Classname = "Port"
def __init__(self, handle, Tag, Range, PortNumber, **kwargs) -> None:
super().__init__(handle)
self.Xrange = Range[0]
self.Yrange = Range[1]
self.Zrange = Range[2]
self.PortNumber = PortNumber
for key, value in kwargs.items():
match key:
case "NumberOfModes":
self.NumberOfModes = value
case "Coordinates":
self.Coordinates = value
case "Orientation":
self.Orientation = value
case "PortOnBound":
self.PortOnBound = value
case "AdjustPolarization":
self.AdjustPolarization = value
case "AddRange":
self.XrangeAdd = [0]
self.YrangeAdd = [1]
self.ZrangeAdd = [2]
self.create(Tag)
def create(self, Tag):
self.Tag = Tag
sCommand = f"""
With Port
.Reset
.PortNumber "{self.PortNumber}"
.Label ""
.Folder ""
.NumberOfModes "{self.NumberOfModes}"
.AdjustPolarization "{self.AdjustPolarization}"
.PolarizationAngle "0.0"
.ReferencePlaneDistance "0"
.TextSize "50"
.TextMaxLimit "0"
.Coordinates "{self.Coordinates}"
.Orientation "{self.Orientation}"
.PortOnBound "{self.PortOnBound}"
.ClipPickedPortToBound "False"
.Xrange "{self.Xrange[0]}", "{self.Xrange[1]}"
.Xrange "{self.Xrange[0]}", "{self.Xrange[1]}"
.Yrange "{self.Zrange[0]}", "{self.Zrange[1]}"
.XrangeAdd "{self.XrangeAdd[0]}", "{self.XrangeAdd[1]}"
.XrangeAdd "{self.XrangeAdd[0]}", "{self.XrangeAdd[1]}"
.ZrangeAdd "{self.ZrangeAdd[0]}", "{self.ZrangeAdd[1]}"
.SingleEnded "False"
.WaveguideMonitor "False"
.Create
End With"""
self.AddToHistoryWithCommand(
self.Tag + "Add Port" + str(self.PortNumber), sCommand
)
return self
class Mesh(StructureMacros):
StepsPerWaveNear = 17
StepsPerWaveFar = 10
StepsPerBoxNear = 12
StepsPerBoxFar = 10
MeshType = "Tetrahedral"
SetCreator = "High Frequency"
def __init__(self, handle) -> None:
self.mws = handle
def init(
self,
StepsPerWaveNear,
StepsPerWaveFar,
StepsPerBoxNear,
StepsPerBoxFar,
**kwargs,
):
self.StepsPerBoxNear = StepsPerBoxNear
self.StepsPerBoxFar = StepsPerBoxFar
self.StepsPerWaveNear = StepsPerWaveNear
self.StepsPerWaveFar = StepsPerWaveFar
for key, value in kwargs.items():
match key:
case "MeshType":
self.MeshType = value
case "SetCreator":
self.SetCreator = value
return self
def MeshUpdate(self, Tag):
sCommand = f"""
With Mesh
.MeshType "{self.MeshType}"
.SetCreator "{self.SetCreator}"
End With
With MeshSettings
'MAX CELL - WAVELENGTH REFINEMENT
.Set "StepsPerWaveNear", "{self.StepsPerWaveNear}"
.Set "StepsPerWaveFar", "{self.StepsPerWaveFar}"
.Set "PhaseErrorNear", "0.02"
.Set "PhaseErrorFar", "0.02"
.Set "CellsPerWavelengthPolicy", "cellsperwavelength"
'MAX CELL - GEOMETRY REFINEMENT
.Set "StepsPerBoxNear", "{self.StepsPerBoxNear}"
.Set "StepsPerBoxFar", "{self.StepsPerBoxFar}"
.Set "ModelBoxDescrNear", "maxedge"
.Set "ModelBoxDescrFar", "maxedge"
'MIN CELL
.Set "UseRatioLimit", "0"
.Set "RatioLimit", "100"
.Set "MinStep", "0"
'MESHING METHOD
.SetMeshType "Unstr"
.Set "Method", "0"
End With
With MeshSettings
.SetMeshType "Tet"
.Set "CurvatureOrder", "1"
.Set "CurvatureOrderPolicy", "automatic"
.Set "CurvRefinementControl", "NormalTolerance"
.Set "NormalTolerance", "22.5"
.Set "SrfMeshGradation", "1.5"
.Set "SrfMeshOptimization", "1"
End With
With MeshSettings
.SetMeshType "Unstr"
.Set "UseMaterials", "1"
.Set "MoveMesh", "0"
End With
With MeshSettings
.SetMeshType "All"
.Set "AutomaticEdgeRefinement", "0"
End With
With MeshSettings
.SetMeshType "Tet"
.Set "UseAnisoCurveRefinement", "1"
.Set "UseSameSrfAndVolMeshGradation", "1"
.Set "VolMeshGradation", "1.5"
.Set "VolMeshOptimization", "1"
End With
With MeshSettings
.SetMeshType "Unstr"
.Set "SmallFeatureSize", "0"
.Set "CoincidenceTolerance", "1e-06"
.Set "SelfIntersectionCheck", "1"
.Set "OptimizeForPlanarStructures", "0"
End With
With Mesh
.SetParallelMesherMode "Tet", "maximum"
.SetMaxParallelMesherThreads "Tet", "1"
End With
"""
self.AddToHistoryWithCommand(Tag, sCommand)
def MeshUpdateHex(self, Tag):
sCommand = f"""With Mesh
.MeshType "PBA"
.SetCreator "High Frequency"
End With
With MeshSettings
.SetMeshType "Hex"
.Set "Version", 1%
'MAX CELL - WAVELENGTH REFINEMENT
.Set "StepsPerWaveNear", "{self.StepsPerWaveNear}"
.Set "StepsPerWaveFar", "{self.StepsPerWaveFar}"
.Set "WavelengthRefinementSameAsNear", "1"
'MAX CELL - GEOMETRY REFINEMENT
.Set "StepsPerBoxNear", "{self.StepsPerBoxNear}"
.Set "StepsPerBoxFar", "{self.StepsPerBoxFar}"
.Set "MaxStepNear", "0"
.Set "MaxStepFar", "0"
.Set "ModelBoxDescrNear", "maxedge"
.Set "ModelBoxDescrFar", "maxedge"
.Set "UseMaxStepAbsolute", "0"
.Set "GeometryRefinementSameAsNear", "0"
'MIN CELL
.Set "UseRatioLimitGeometry", "1"
.Set "RatioLimitGeometry", "15"
.Set "MinStepGeometryX", "0"
.Set "MinStepGeometryY", "0"
.Set "MinStepGeometryZ", "0"
.Set "UseSameMinStepGeometryXYZ", "1"
End With
With MeshSettings
.Set "PlaneMergeVersion", "2"
End With
With MeshSettings
.SetMeshType "Hex"
.Set "FaceRefinementOn", "0"
.Set "FaceRefinementPolicy", "2"
.Set "FaceRefinementRatio", "2"
.Set "FaceRefinementStep", "0"
.Set "FaceRefinementNSteps", "2"
.Set "EllipseRefinementOn", "0"
.Set "EllipseRefinementPolicy", "2"
.Set "EllipseRefinementRatio", "2"
.Set "EllipseRefinementStep", "0"
.Set "EllipseRefinementNSteps", "2"
.Set "FaceRefinementBufferLines", "3"
.Set "EdgeRefinementOn", "1"
.Set "EdgeRefinementPolicy", "1"
.Set "EdgeRefinementRatio", "2"
.Set "EdgeRefinementStep", "0"
.Set "EdgeRefinementBufferLines", "3"
.Set "RefineEdgeMaterialGlobal", "0"
.Set "RefineAxialEdgeGlobal", "0"
.Set "BufferLinesNear", "3"
.Set "UseDielectrics", "1"
.Set "EquilibrateOn", "0"
.Set "Equilibrate", "1.5"
.Set "IgnoreThinPanelMaterial", "0"
End With
With MeshSettings
.SetMeshType "Hex"
.Set "SnapToAxialEdges", "1"
.Set "SnapToPlanes", "1"
.Set "SnapToSpheres", "1"
.Set "SnapToEllipses", "1"
.Set "SnapToCylinders", "1"
.Set "SnapToCylinderCenters", "1"
.Set "SnapToEllipseCenters", "1"
End With
With Mesh
.ConnectivityCheck "True"
.UsePecEdgeModel "True"
.PointAccEnhancement "0"
.TSTVersion "0"
.PBAVersion "2022060322"
.SetCADProcessingMethod "MultiThread22", "-1"
.SetGPUForMatrixCalculationDisabled "False"
End With
"""
self.AddToHistoryWithCommand(Tag, sCommand)
pass
class Solver(StructureMacros):
def __init__(self, handle) -> None:
self.mws = handle
def FDSolver(self):
sCommand = """
Mesh.SetCreator "High Frequency"
With FDSolver