Full 2-port simulation (Python) #64
-
Hi all, is there any example how to do full 2-port simulation with excitation at port 1 and 2 (one after another) using the Python interface? What I tried: set port 1 excitation first and run FDTD, then swap port1.excite and port2.excite values using the same (!) CSX and re-run FDTD, but that seems to be the wrong approach. All help/hint/example is much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 16 replies
-
That's also how I do it: excite the port of interest and set the others to excite=0.0. |
Beta Was this translation helpful? Give feedback.
-
Ok, maybe I understand the concept better now: it seems that we need a separate, new CSX for each separate port excitation. My solution was to place the entire code that populates the CSX into a function, and call that function two times with varying settings for port excitation. Each excitation data is placed in a separate directory, so we can finally get the full [S] matrix including reverse path. Just in case another beginner has the same question, I tried to post some code snippets from my Python model, but the code embedding feature messed up formatting of my code. Marking thread as solved. Best regards Function to create CSX, port excitation (forward/reverse path of 2-port) set by parameter: def createSimulation (exciteport):
# Define function for model creation because we need to create and run separate CSX
# for each excitation. For S11,S21 we only need to excite port 1, but for S22,S12
# we need to excite port 2. This requires separate CSX with different port settings.
############ Geometry setup ############
CSX = ContinuousStructure()
FDTD.SetCSX(CSX)
mesh = CSX.GetGrid()
mesh.SetDeltaUnit(unit)
(...)
if exciteport==1:
port1 = FDTD.AddLumpedPort(1, 50, [-22.2, 0, TopMetal1_zmin], [-10, 10, TopMetal1_zmax], 'x', excite=1.0, priority=150)
port2 = FDTD.AddLumpedPort(2, 50, [ 22.2, 0, TopMetal1_zmin], [ 10, 10, TopMetal1_zmax], 'x', excite=0, priority=150)
else:
port1 = FDTD.AddLumpedPort(1, 50, [-22.2, 0, TopMetal1_zmin], [-10, 10, TopMetal1_zmax], 'x', excite=0, priority=150)
port2 = FDTD.AddLumpedPort(2, 50, [ 22.2, 0, TopMetal1_zmin], [ 10, 10, TopMetal1_zmax], 'x', excite=1.0, priority=150)
(...)
# create subdirectory to hold data for this excitation
excitation_path = os.path.join(sim_path, 'sub-' + str(exciteport))
if not os.path.exists(excitation_path):
os.makedirs(excitation_path)
# write CSX file
CSX_file = os.path.join(excitation_path, model_basename + '.xml')
CSX.Write2XML(CSX_file)
if not postprocess_only: # preview model, but only for first port excitation
if (exciteport==1):
from CSXCAD import AppCSXCAD_BIN
os.system(AppCSXCAD_BIN + ' "{}"'.format(CSX_file))
if not preview_only: # start simulation
if not postprocess_only:
print("Running FDTD simulation, excitation port " + str(exciteport))
FDTD.Run(excitation_path, verbose=1)
# return ports, so that we can postprocess them
return port1, port2, excitation_path
######### end of function createSimulation (exciteport) ########## This createSimulation () function is called in main program, to create two CSX in separate directories and run each of them: ########### create model, run and post-process ###########
f = np.linspace(fstart,fstop,numfreq)
# call createSimulation function defined above
sub1_port1, sub1_port2, sub1_excitation_path = createSimulation (1) # excite port 1
sub2_port1, sub2_port2, sub2_excitation_path = createSimulation (2) # excite port 2
if not preview_only:
# evaluate port 1 excitation
sub1_port1.CalcPort( sub1_excitation_path, f, ref_impedance = 50)
sub1_port2.CalcPort( sub1_excitation_path, f, ref_impedance = 50)
s11 = sub1_port1.uf_ref / sub1_port1.uf_inc
s21 = sub1_port2.uf_ref / sub1_port1.uf_inc
# evaluate port 2 excitation
sub2_port1.CalcPort( sub2_excitation_path, f, ref_impedance = 50)
sub2_port2.CalcPort( sub2_excitation_path, f, ref_impedance = 50)
s22 = sub2_port2.uf_ref / sub2_port2.uf_inc
s12 = sub2_port1.uf_ref / sub2_port2.uf_inc |
Beta Was this translation helpful? Give feedback.
-
Changing the port excitation doesn't work as CSX.AddExcitation() is only called in |
Beta Was this translation helpful? Give feedback.
-
The latest version (build from source) now has many new options for this. Ports can now be enabled/disabled (SetEnabled), but the correct "excite" must be set for the ports on setup.
But it is now also possible to reset everything. Either the FDTD class or only the geometry using "Reset()". |
Beta Was this translation helpful? Give feedback.
Ok, maybe I understand the concept better now: it seems that we need a separate, new CSX for each separate port excitation. My solution was to place the entire code that populates the CSX into a function, and call that function two times with varying settings for port excitation. Each excitation data is placed in a separate directory, so we can finally get the full [S] matrix including reverse path.
Just in case another beginner has the same question, I tried to post some code snippets from my Python model, but the code embedding feature messed up formatting of my code.
Marking thread as solved.
Best regards
Volker
Function to create CSX, port excitation (forward/reverse path of 2-port) s…