/
HFSS-loadbest.py
61 lines (51 loc) · 1.73 KB
/
HFSS-loadbest.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
# ----------------------------------------------
# Script Written by Jason W. Sidabras (jason.sidabras@cec.mpg.de)
# requires jsidabras/hycohanz as of 20-04-2017
# Loads a file with a list of 1s and 0s and implements it to HFSS as Silv/Vac
# used to load the best results per generation or final
# ----------------------------------------------
from random import *
import argparse
import hycohanz as hfss
[oAnsoftApp, oDesktop] = hfss.setup_interface()
oProject = oDesktop.SetActiveProject("GA_PlanarResonator")
oDesign = hfss.set_active_design(oProject, 'HFSSDesign1')
oEditor = hfss.set_active_editor(oDesign)
oFieldsReporter = hfss.get_module(oDesign, 'FieldsReporter')
parser = argparse.ArgumentParser(description='Load GA best file and run solution in HFSS.')
parser.add_argument('file', type=str, help='the filename to load')
args = parser.parse_args()
f = open(args.file, 'r')
loadthing = f.readline()
f.close()
dump = loadthing.strip("[")
dump = dump.rstrip()
dump = dump.strip(r"']").split(", ")
thing = []
for i in dump:
thing.append(int(i))
print(len(dump))
index = 0
Vac = []
Silv = []
for i in thing:
if i == 1:
Silv.append("Elm_"+str(index))
index += 1
else:
Vac.append("Elm_"+str(index))
index += 1
oDesktop.ClearMessages("", "", 3)
# Check if list is empty
if Vac:
hfss.assign_White(oEditor, Vac)
hfss.assign_material(oEditor, Vac, MaterialName="vacuum", SolveInside=True)
if Silv:
hfss.assign_Orange(oEditor, Silv)
hfss.assign_material(oEditor, Silv, MaterialName="pec", SolveInside=False)
oDesktop.ClearMessages("", "", 3)
# try:
#oDesign.Analyze("Setup1")
# except:
# print("Simulation Error")
#oProject.Save()