CREATE CST IN VISUAL BASIC

COILS TRAPEZOIDAL SPIRAL

AR for Postprocessing  Combine Results

EXTRUDE MULTIPLE PICKED FACES

AXIAL CORRUGATED HORN

Add/Delete Parameter

Define Ports

Add/Delete Monitors-Menu

200708270752AM_Nmodes_2

 Calculatepoint Example AXIAL RATIO CALCULATION
ADD_MONITORS WITH MENU SET JJLEE_B_PARAMETERS CST TLib Create Line/Polyline
HANDLING PARAMETERS CREATE SYMMETRY Save project list of parameter SWARM IN SAX
Matthias

F7

Matthias CST TIME/DATE FUNCTIONS
Z_TO_GAMMA BUILD Polyline RebuildForParametricChange NOTES
GetProjectPath BUILD 3DPolyline T_Add_3DPolygon_Line_by_Line  
 
AXIAL RATIO CALCULATION AXIAL CORRUGATED HORN COILS TRAPEZOIDAL SPIRAL
Sub Main()
Dim iPoint As Integer
Dim ipVert As Double, ipHoriz As Double, PhaseDelta As Double
Dim iaVert As Double, iaHoriz As Double
Dim F1,F2,F3,F4 As String
Dim freq As Double
Dim OA As Double, OB As Double
Dim AR As Double
Dim PI As Double

Dim aVert As Object, aHoriz As Object
Dim pVert As Object, pHoriz As Object
Dim nPoints As Integer

F1 = "AR.txt" ' output file name for Axial Ratio
F2="AMP_DIFF.TXT" '
F3="PHASE_DIFF.TXT"
F4="AMP.TXT"

PI=4*Atn(1.)
DEG=180/PI
Open F1 For Output As #1
Open F2 For Output As #2
Open F3 For Output As #3
Open F4 For Output As #4

Set aVert = Result1D("a2(3)1(1)")
Set pVert = Result1D("p2(3)1(1)")
Set aHoriz = Result1D("a2(2)1(1)")
Set pHoriz = Result1D("p2(2)1(1)")

nPoints = aVert.GetN

For iPoint=1 To nPoints-1
ipVert=pVert.GetY(iPoint)
ipHoriz=pHoriz.GetY(iPoint)
PhaseDelta=ipVert-ipHoriz
'PhaseDelta=PhaseDelta+7
iaVert=aVert.GetY(iPoint)
iaHoriz=aHoriz.GetY(iPoint)
'Print #1,CStr(iaVert) & " " & CStr(iaHoriz)
OA=iaHoriz^2+iaVert^2+(iaHoriz^4+iaVert^4+2*iaHoriz^2*iaVert^2*CosD(2*PhaseDelta))^0.5
OB=iaHoriz^2+iaVert^2-(iaHoriz^4+iaVert^4+2*iaHoriz^2*iaVert^2*CosD(2*PhaseDelta))^0.5
'Print #1,CStr(OA) & " " & CStr(OB)
AR=10*Log(OA/OB)/Log(10)   'corrected
iaVert_dB=20*Log(iaVert)/Log(10)
iaHoriz_dB=20*Log(iaHoriz)/Log(10)
amp_diff_db=iaVert_dB-iaHoriz_dB
freq = pVert.GetX(iPoint) ' * Units.GetTimeUnitToSI
Print #1,CStr(freq) & " " & CStr(AR)
Print #2,CStr(freq) & " " & CStr(amp_diff_db)
Print #3,CStr(freq) & " " & CStr(PhaseDelta)
Print #4,CStr(freq) & " " & CStr(iaVert)& " " & CStr(iaHoriz)
Next iPoint

Close #1

With ResultTree
.Reset
.Name "1D Results\AR\AR"
.Type "XYSignal"
.Subtype "Linear"
.Title "AR in dB"
.Xlabel "Frequency / " + Units.GetFrequencyUnit
.Ylabel "dB"
.File F1
.Add
End With
With ResultTree
.Reset
.Name "1D Results\AMP_DIFF\AMP_DIFF"
.Type "XYSignal"
.Subtype "Linear"
.Title "Amplitude_Difference in dB"
.Xlabel "Frequency / " + Units.GetFrequencyUnit
.Ylabel "dB"
.File F2
.Add
End With
With ResultTree
.Reset
.Name "1D Results\PHASE_DIFF\PHASE_DIFF"
.Type "XYSignal"
.Subtype "Linear"
.Title "Phase_Difference in Deg"
.Xlabel "Frequency / " + Units.GetFrequencyUnit
.Ylabel "DEG"
.File F3
.Add
End With
With ResultTree
.Reset
.Name "1D Results\AMPS\AMPS"
.Type "XYSignal"
.Subtype "Linear"
.Title "Amplitudes"
.Xlabel "Frequency / " + Units.GetFrequencyUnit
.Ylabel "???"
.File F4
.Add
End With
End Sub
 
'Sub Main ()
Dim LENGTHS(1000) As Double
Dim CR1(1000)As Double
Dim CR2(1000)As Double
Dim CCL(1000) As Double
Dim RWGIN As Double
Dim IFLN, OFLN As String
Dim LB_R,LB_S,HB_R,HB_S As Double
Dim CY_Rout_PN(1000),
Dim CY_Rin_PN(1000),CY_L_PN(1000) As String
Dim FREKO As String
'@ use template: Antenna (in Free Space, waveguide)

' Template for Antenna in Free Space
' ==================================
' (CSTxMWSxONLY)
' DO NOT draw the bounding box
Plot.DrawBox False
' DO NOT draw grid
Plot.DrawWorkplane "false"
' set units to cm, ghz
With Units
.Geometry "cm"
.Frequency "ghz"
.Time "ns"
End With
' set background material to vacuum
With Background
.Type "Normal"
.Epsilon "1.0"
.Mue "1.0"
.XminSpace "0.0"
.XmaxSpace "0.0"
.YminSpace "0.0"
.YmaxSpace "0.0"
.ZminSpace "0.0"
.ZmaxSpace "0.0"
End With
' set boundary conditions to open
With Boundary
.Xmin "expanded open"
.Xmax "expanded open"
.Ymin "expanded open"
.Ymax "expanded open"
.Zmin "expanded open"
.Zmax "expanded open"
.Xsymmetry "none"
.Ysymmetry "none"
.Zsymmetry "none"
End With
' switch on FD-TET setting for accurate farfields
FDSolver.ExtrudeOpenBC "True"
Mesh.FPBAAvoidNonRegUnite "True"
IFLN="LENGTHS.TXT"
OFLN="LENGTHS2.TXT"
I=0
Open IFLN For Input As 1
Open OFLN For Output As 2

Dim AKO As Integer
LB_R=.0254 '=10 mil .0384 '[cm] = 15 mil'
LB_S=.0504 '=20 mil .0489 '[cm] = 19 mil'
HB_R=LB_R
HB_S=LB_S
RWGIN=0.675
I=0
While EOF(1)=False
I=I+1
Input#1, LENGTHS(I)
AKO=I Mod 4
Select Case AKO
Case 1
DELTA=LB_R
Case 2
DELTA=LB_S
Case 3
DELTA=HB_R
Case 0
DELTA=HB_S
End Select
If I=1 Then
CR1(I)=RWGIN
Else
CR1(I)=CR2(I-1)
End If
CR2(I)=CR1(I)+DELTA
CCL(I)=LENGTHS(I)
'Print#2,Str$(LENGTHS(I))
Wend

NMAX=I

For I=1 To NMAX
CY_Rout_PN(I)="CYout_" & LTrim(RTrim(Str$(I)))
CY_Rin_PN(I)="CYin_" & LTrim(RTrim(Str$(I)))
CY_L_PN(I)="CYLen_" & LTrim(RTrim(Str$(I)))
A$=CY_Rout_PN(I)
StoreDoubleParameter (CY_Rout_PN(I), CR2(I))
StoreDoubleParameter (CY_Rin_PN(I),CR1(I))
StoreDoubleParameter (CY_L_PN(I), LENGTHS(I))


With Cylinder
.Reset
.Name "R" & LTrim(RTrim(Str$(I)))
.Component "AXIAL_CORRUGATED_HORN"
.Material "PEC"
.OuterRadius CY_Rout_PN(I)
.InnerRadius CY_Rin_PN(I)
.Axis "z"
.Zrange "0", CY_L_PN(I)
.Xcenter "0"
.Ycenter "0"
.Segments "0"
.Create
End With
Next I

With Cylinder
.Reset
.Name "Circular_waveguide"
.Component "AXIAL_CORRUGATED_HORN"
.Material "PEC"
.OuterRadius CY_Rout_PN(1)
.InnerRadius CY_Rin_PN(1)
.Axis "z"
.Zrange "-1", "0"
.Xcenter "0"
.Ycenter "0"
.Segments "0"
.Create
End With

With Cylinder
.Reset
.Name "Circular_Port"
.Component "AXIAL_CORRUGATED_HORN"
.Material "Vacuum"
.OuterRadius Str$(CY_Rin_PN(1))
.InnerRadius "0"
.Axis "z"
.Zrange "-1", "0"
.Xcenter "0"
.Ycenter "0"
.Segments "0"
.Create
End With
Close 1
Close 2
Pick.PickFaceFromId "AXIAL_CORRUGATED_HORN:Circular_Port", "1"
With Port
.Reset
.PortNumber "1"
.NumberOfModes "17"
.AdjustPolarization True
.PolarizationAngle "90"
.ReferencePlaneDistance "0"
.TextSize "50"
.Coordinates "Picks"
.Orientation "positive"
.PortOnBound "True"
.ClipPickedPortToBound "False"
.Xrange "-0.675", "0.675"
.Yrange "-0.675", "0.675"
.Zrange "-1", "-1"
.XrangeAdd "0.0", "0.0"
.YrangeAdd "0.0", "0.0"
.ZrangeAdd "0.0", "0.0"
.SingleEnded "False"
.Create
End With
FMIN=15.
FSTEP=0.5
NF=50
FREKO=Str$(FREQ)
For IFREQ=1 To NF
FREQ=FMIN+(IFREQ-1)*FSTEP
FREKO=LTrim(RTrim(Str$(FREQ)))
With Monitor
.Reset
.Name "farfield (f=" & FREKO & ")"
.Domain "Frequency"
.FieldType "Farfield"
.Frequency FREKO
.Create
End With

With Monitor
.Reset
.Name "h-field (f=" & FREKO & ")"
.Dimension "Volume"
.Domain "Frequency"
.FieldType "Hfield"
.Frequency FREKO
.Create
End With

With Monitor
.Reset
.Name "e-field f=" & FREKO & ")"
.Dimension "Volume"
.Domain "Frequency"
.FieldType "Efield"
.Frequency FREKO
.Create
End With
Next IFREQ
End Sub 
 
' Construct / Coils / Trapezoidal-Spiral
' !!! Do not change the line above !!!
' macro.521
'--------------------------------------------------------------------------------------------
' 21-Oct-2005 imu: Included into Online Help
' 18-oct-2005 fhi: trapezoidal spiral coil: initial version

Option Explicit
Public macropath As String
Public filename As String

Sub Main ()

Dim a As Double, c As Double, h As Double, s As Double, alpha As Double
Dim dx As Double, dxs As Double, p1x As Double, p1y As Double, p2x As Double, p2y As Double
Dim p3x As Double, p3y As Double, p4x As Double, p4y As Double
Dim p5x As Double, p5y As Double, p6x As Double, p6y As Double, nr_of_turns As Integer, i As Integer
Dim blend_radius As Double, index As Integer, cst_result As Integer
Dim cst_a As String, cst_h As String, cst_c As String, cst_s As String
Dim cst_blendradius As String, cst_met_w As String, cst_met_thick As String, cst_nr_of_turns As String
Dim met_width As Double, met_thick As Double, cst_blend As Integer, blend_yes_no As Integer

BeginHide

macropath = getmacropath
filename = macropath+"\macro_522_pict.bmp"

Begin Dialog UserDialog 660,308,"Trapezoidal Spiral Coil" ',.DialogFunc ' %GRID:10,7,1,1
Text 10,7,100,21,"Height",.Text1
TextBox 120,7,80,21,.h
Text 10,35,100,21,"Broadside ",.Text2
TextBox 120,35,80,21,.a
Text 10,63,70,21,"Shortside",.Text3
TextBox 120,63,80,21,.c
Text 10,91,60,21,"Spacing ",.Text4
TextBox 120,91,80,21,.s
Text 10,119,50,21,"Turns",.Text5
TextBox 120,119,80,21,.nr_of_turns
Picture 220,7,430,259,filename,0,.Picture1
GroupBox 0,203,210,63,"Metallization",.GroupBox1
Text 10,224,70,14,"Width",.Text9
Text 10,245,80,14,"Thickness",.Text10
TextBox 120,238,80,21,.met_thickness
TextBox 120,217,80,21,.met_width
GroupBox 0,147,210,49,"Blending",.GroupBox2
CheckBox 10,168,100,21,"On Radius",.blend
TextBox 120,168,80,21,.blend_radius
OKButton 20,280,110,21
CancelButton 150,280,100,21
PushButton 270,280,90,21,"Help",.Help
End Dialog
Dim dlg As UserDialog

'Default values
dlg.a="30"
dlg.h="30"
dlg.c="20"
dlg.s="2."
dlg.blend_radius="1."
dlg.met_width="1"
dlg.met_thickness=".03"
dlg.nr_of_turns = "4"
dlg.blend = 1

cst_result = Dialog(dlg)
assign "cst_result" ' writes e.g. "cst_result = -1/0/1" into history list
If (cst_result = 0) Then Exit All

cst_a= dlg.a
cst_h= dlg.h
cst_c =dlg.c
cst_s= dlg.s
cst_blendradius= dlg.blend_radius
cst_met_w= dlg.met_width
cst_met_thick = dlg.met_thickness
cst_nr_of_turns = dlg.nr_of_turns
cst_blend =dlg.blend

assign "cst_a"
assign "cst_h"
assign "cst_s"
assign "cst_c"
assign "cst_blendradius"
assign "cst_met_w"
assign "cst_met_thick"
assign "cst_nr_of_turns"
assign "cst_blend"

EndHide

If (cst_result =0) Then Exit All ' if cancel/help is clicked, exit all

a = Evaluate(cst_a)
c = Evaluate(cst_c)
h = Evaluate(cst_h)
s = Evaluate(cst_s)
blend_radius = Evaluate(cst_blendradius)
met_width = Evaluate(cst_met_w)
met_thick = Evaluate(cst_met_thick)
nr_of_turns = CInt(cst_nr_of_turns)
blend_yes_no = CInt(cst_blend)

'start modeling the coil

alpha = Atn((a-c)/(2*h)) 'angle of side-traces
dx = s/Cos (alpha)
dxs = s*((a-c)/(2*h))

'MsgBox CStr(alpha*180/pi)

Curve.NewCurve "curve1"

p1x= 0 'starting points
p1y=0
p2x = -c/2
p2y = 0
p3x = -a/2
p3y = h
p4x = a/2
p4y = h
p5x = c/2+dxs
p5y = s
p6x = 0
p6y = s


'@ define curve polygon: curve1: 1st Port-Line

With Polygon
.Reset
.Name "Line1"
.Curve "curve1"
.Point 0 , -c/2
.lineto p1x,p1y
.create
End With

i=1
For index = 1 To nr_of_turns

'create_polygon "curve1", "Line"+CStr(i+1), p1x,p1y,p2x,p2y
With Polygon
.Reset
.Curve "curve1"
.Name "Line"+CStr(i+1)
.Point p1x, p1y
.lineto p2x,p2y
.create
End With

If blend_yes_no = 1 Then
If i=1 Then
'create_blending "curve1","blend"+CStr(i),"Line"+CStr(i),"Line"+CStr(i+1), 1.0
With BlendCurve
.Reset
.Name "blend"+CStr(i)
.Radius blend_radius
.Curve "curve1"
.CurveItem1 "Line"+CStr(i)
.CurveItem2 "Line"+CStr(i+1)
.EdgeId1 "1"
.EdgeId2 "1"
.VertexId1 "2"
.VertexId2 "1"
.Create
End With
End If
End If
'create_polygon "curve1", "Line"+CStr(i+2), p2x,p2y,p3x,p3y
With Polygon
.Reset
.Curve "curve1"
.name "Line"+CStr(i+2)
.Point p2x, p2y
.lineto p3x,p3y
.create
End With
If blend_yes_no = 1 Then
'create_blending "curve1","blend"+CStr(i+1),"Line"+CStr(i+1),"Line"+CStr(i+2), 1.0
With BlendCurve
.Reset
.Name "blend"+CStr(i+1)
.Radius blend_radius
.Curve "curve1"
.CurveItem1 "Line"+CStr(i+1)
.CurveItem2 "Line"+CStr(i+2)
.EdgeId1 "1"
.EdgeId2 "1"
.VertexId1 "2"
.VertexId2 "1"
.Create
End With
End If
'create_polygon "curve1", "Line"+CStr(i+3), p3x,p3y,p4x,p4y
With Polygon
.Reset
.curve "curve1"
.name "Line"+CStr(i+3)
.Point p3x, p3y
.lineto p4x,p4y
.create
End With
If blend_yes_no = 1 Then
'create_blending "curve1","blend"+CStr(i+2),"Line"+CStr(i+2),"Line"+CStr(i+3), 1.0
With BlendCurve
.Reset
.Name "blend"+CStr(i+2)
.Radius blend_radius
.Curve "curve1"
.CurveItem1 "Line"+CStr(i+2)
.CurveItem2 "Line"+CStr(i+3)
.EdgeId1 "1"
.EdgeId2 "1"
.VertexId1 "2"
.VertexId2 "1"
.Create
End With
End If
'create_polygon "curve1", "Line"+CStr(i+4), p4x,p4y,p5x,p5y
With Polygon
.Reset
.curve "curve1"
.name "Line"+CStr(i+4)
.Point p4x, p4y
.lineto p5x,p5y
.create
End With
If blend_yes_no = 1 Then
'create_blending "curve1","blend"+CStr(i+3),"Line"+CStr(i+3),"Line"+CStr(i+4), 1.0
With BlendCurve
.Reset
.Name "blend"+CStr(i+3)
.Radius blend_radius
.Curve "curve1"
.CurveItem1 "Line"+CStr(i+3)
.CurveItem2 "Line"+CStr(i+4)
.EdgeId1 "1"
.EdgeId2 "1"
.VertexId1 "2"
.VertexId2 "1"
.Create
End With
End If
'create_polygon "curve1", "Line"+CStr(i+5), p5x,p5y,p6x,p6y
With Polygon
.Reset
.curve "curve1"
.name "Line"+CStr(i+5)
.Point p5x, p5y
.lineto p6x,p6y
.create
End With
If blend_yes_no = 1 Then
'create_blending "curve1","blend"+CStr(i+4),"Line"+CStr(i+4),"Line"+CStr(i+5), 1.0
With BlendCurve
.Reset
.Name "blend"+CStr(i+4)
.Radius blend_radius
.Curve "curve1"
.CurveItem1 "Line"+CStr(i+4)
.CurveItem2 "Line"+CStr(i+5)
.EdgeId1 "1"
.EdgeId2 "1"
.VertexId1 "2"
.VertexId2 "1"
.Create
End With
End If
'create point-offsets for next loop
p1y =p1y+s
p2x = p2x +dx-dxs
p2y = p2y +s
p3x = p3x +dx+dxs
p3y = p3y -s
p4x = p4x -dx-dxs
p4y = p4y -s
p5x = p5x -dx+dxs
p5y = p5y +s
p6y = p6y+s

i=i+5

Next
'create Solid
With TraceFromCurve
.Reset
.Name Solid.GetNextFreeName
.Component "Trapezoidal_Spiral"
.Material "PEC"
.Curve "curve1:Line1"
.Thickness met_thick
.Width met_width
.RoundStart "False"
.RoundEnd "False"
.GapType "2"
.Create
End With

End Sub

Function DialogFunc%(Item As String, Action As Integer, Value As Integer)
Select Case Action
Case 1 ' Dialog box initialization
Case 2 ' Value changing or button pressed
Select Case Item
Case "Help"
StartHelp "common_preloadedmacro_Construct_Coils"
DialogFunc = True
End Select
Case 3 ' ComboBox or TextBox Value changed
Case 4 ' Focus changed
Case 5 ' Idle
End Select
End Function
 
ADD/DELETE PARAMTER
Sub Main ()
StoreDoubleParameter("Goal_Function",Str$(12.2))
DeleteParameter("Goal_Function")

StoreParameter("GoalFunction",Str$(12.2))

SetParameterDescription (name, description )

End Sub
 

Define Ports
Dim PNUM,XMIN1,XMAX1,YMIN1,YMAX1 As String
Dim XMIN2,XMAX2,YMIN2,YMAX2 As String
Dim TMP As String

A$=Chr$(34)

For I=1 To 1
PNUM=LTrim(RTrim(Str$(I)))
XMIN1=LTrim(RTrim(Str$(-0.5481)))
XMAX1=LTrim(RTrim(Str$(-0.1481)))
YMIN1=LTrim(RTrim(Str$(13.6159)))
YMAX1=LTrim(RTrim(Str$(14.2721)))

TMP="With Port"+vbCrLf
TMP=TMP+" .Reset"+vbCrLf
TMP=TMP+" .PortNumber "+A$+PNUM+A$+vbCrLf
TMP=TMP+" .NumberOfModes "+A$+"1"+A$+vbCrLf
TMP=TMP+" .AdjustPolarization False"+vbCrLf
TMP=TMP+" .PolarizationAngle "+A$+"0.0"+A$+vbCrLf
TMP=TMP+" .ReferencePlaneDistance" +A$+"0"+A$+vbCrLf
TMP=TMP+" .TextSize "+A$+"50"+A$+vbCrLf
TMP=TMP+" .Coordinates "+A$+"Free"+A$+vbCrLf
TMP=TMP+" .Orientation "+A$+"positive"+A$+vbCrLf
TMP=TMP+" .PortOnBound "+A$+"False"+A$+vbCrLf
TMP=TMP+" .ClipPickedPortToBound "+A$+"False"+A$+vbCrLf
TMP=TMP+" .Xrange "+A$+XMIN1+A$+" , "+ A$+XMAX1+A$+vbCrLf
TMP=TMP+" .Yrange "+A$+YMIN1+A$+" , "+ A$+YMAX1+A$+vbCrLf
TMP=TMP+" .Zrange "+A$+"-2"+A$+" , "+A$+ "-2"+A$+vbCrLf
TMP=TMP+" .XrangeAdd "+A$+"0.0"+A$+" , "+A$+ "0.0"+A$+vbCrLf
TMP=TMP+" .YrangeAdd "+A$+"0.0"+A$+" , "+A$+ "0.0"+A$+vbCrLf
TMP=TMP+" .ZrangeAdd "+A$+"0.0"+A$+" , "+A$+ "0.0"+A$+vbCrLf
TMP=TMP+" .SingleEnded "+A$+"False"+A$+vbCrLf
TMP=TMP+" .Create"+vbCrLf
TMP=TMP+"End With"
AddtoHistory("AddPort"+" "+PNUM,TMP)
Next I

EXTRUDE MULTIPLE PICKED FACES AR for Postprocessing F7= RebuildForParametricChange
' Extrude multiple picked faces
' User can enter shapenames and component
' Material will be cloned from the original shape
'-----------------------------------------------------------------------------------------------------------------------------
' History Of Changes
'-----------------------------------------------------------------------------------------------------------------------------
' 22-Sep-2005 msc: First version

Sub Main
Begin Dialog UserDialog 330,154,"Extrude Multiple Shapes" ' %GRID:10,7,1,1
GroupBox 10,7,310,105,"Properties",.GroupBox1
TextBox 150,28,70,21,.sExtr
Text 20,35,120,14,"Extrusion Height",.Text1
Text 20,63,120,14,"Component",.Text2
Text 20,91,120,14,"Shape",.Text3
OKButton 190,126,90,21
CancelButton 60,126,90,21
TextBox 150,56,150,21,.sComp
TextBox 150,84,150,21,.sShape
End Dialog
Dim dlg As UserDialog

dlg.sExtr = "0"
dlg.sComp = "Extrusion"
dlg.sShape = "Extr"

If (Dialog(dlg) = 0) Then Exit All

Dim dExtrHeight As Double
dExtrHeight = CDbl(dlg.sExtr)

Dim n_faces As Integer
n_faces = Pick.GetNumberOfPickedFaces

If (n_faces = 0) Then
MsgBox "No Faces picked."
Exit All
End If

Dim i_fids()
ReDim i_fids(n_faces)

Dim s_names()
ReDim s_names(n_faces)

Dim s_sname As String
Dim i_fid As Long

For i=1 To n_faces
s_name = Pick.GetPickedFaceFromIndex(i,i_fid)
s_names(i) = s_name
i_fids(i) = i_fid
Next i


Dim sCommand As String
Dim sTmp1 As String
Dim sTmp2 As String
Dim sTmp3 As String

sCommand = ""
sTmp1 = ""
sTmp2 = ""
sTmp3 = ""
sCommand = sCommand + "Pick.ClearAllPicks" + vbLf

For i=1 To n_faces

sTmp1 = s_names(i)
sTmp2 = i_fids(i)
sTmp3 = Solid.GetMaterialNameForShape(s_names(i))

sCommand = sCommand + "Pick.PickFaceFromId(""
sCommand = sCommand + sTmp1 +"""
sCommand = sCommand + "," + """
sCommand = sCommand + sTmp2 + """
sCommand = sCommand + ")" + vbLf
sCommand = sCommand + "With Extrude" + vbLf
sCommand = sCommand + ".Reset" + vbLf
sCommand = sCommand + ".Component(""
sCommand = sCommand + dlg.sComp + """
sCommand = sCommand + ")" + vbLf
sCommand = sCommand + ".Name(""
sCommand = sCommand + dlg.sShape
sCommand = sCommand + CStr(i) +"""
sCommand = sCommand + ")" + vbLf
sCommand = sCommand + ".Material(""
sCommand = sCommand + sTmp3 + """
sCommand = sCommand + ")" + vbLf ' !Same material as original shape
sCommand = sCommand + ".Mode (""
sCommand = sCommand + "Picks" + """
sCommand = sCommand + ")" + vbLf
sCommand = sCommand + ".Height(""
sCommand = sCommand + dlg.sExtr + """
sCommand = sCommand + ")" + vbLf
sCommand = sCommand + ".UsePicksForHeight (False)" + vbLf
sCommand = sCommand + ".DeleteBaseFaceSolid (False)" + vbLf
sCommand = sCommand + ".ClearPickedFace (True)" + vbLf
sCommand = sCommand + ".Create" + vbLf
sCommand = sCommand + "End With" + vbLf
Next i

AddToHistory "Multiple Extrude Picked Faces", sCommand

End Sub
PhaseDelta=PV-PH
OA=AH^2+AV^2+(AH^4+AV^4+2*AH^2*AV^2*Cos(2*PhaseDelta))^0.5 OB=AH^2+AV^2-(AH^4+AV^4+2*AH^2*AV^2*Cos(2*PhaseDelta))^0.5 AR=10*Log(OA/OB)/Log(10)

C=A-B
OA=B^2+A^2+(B^4+A^4+2*B^2*A^2*Cos(2*C))^0.5
OB=B^2+A^2-(B^4+A^4+2*B^2*A^2*Cos(2*C))^0.5
AR=10*Log(A/B)/Log(10) 'corrected
vbCrLf = Carriage return

temp = "Mesh.MinimumCurvatureRefinement ""150"" "+ vbCrLf + _
" Solver.FrequencyRange ""17.5"", ""21.5"" "+ vbCrLf + _
"Component.New ""component1"" "+ vbCrLf + _
"With Cylinder" + vbCrLf + _
" .Reset" + vbCrLf + _
" .Name ""CYLINDER"" "+ vbCrLf + _
" .Component ""component1"" "+ vbCrLf + _
" .Material ""Vacuum"" "+ vbCrLf + _
" .OuterRadius 6" + vbCrLf + _
" .InnerRadius 1" + vbCrLf + _
" .Axis ""z"" "+ vbCrLf + _
" .Zrange -40, 40" + vbCrLf + _
" .Xcenter ""0"" "+ vbCrLf + _
" .Ycenter ""0"" "+ vbCrLf + _
" .Segments ""0"" "+ vbCrLf + _
" .Create" + vbCrLf + _
"End With"
AddtoHistory("Cylinder", temp)
Combine Results Matthias
a$=Chr$(34)
I=1
TEMP="With CombineResults"+vbCrLf
TEMP=TEMP+" .Reset"+vbCrLf
TEMP=TEMP+" .SetMonitorType ("+A$+"frequency"+A$+")"+vbCrLf
TEMP=TEMP+" .EnableAutomaticLabeling (False)"+vbCrLf
TEMP=TEMP+" .SetLabel ("+A$+"Combined_Patterns"+a$+")"+vbCrLf
TEMP=TEMP+" .SetNone"+vbCrLf
For I=1 To 10
TEMP=TEMP+" .SetPortModeValues ("+Str$(I)+", 1, 1, 0.0)"+vbCrLf
Next I
TEMP=TEMP+" .Run"+vbCrLf
TEMP=TEMP+"End With"+vbCrLf
Debug.Print TEMP
AddtoHistory("Combine_Patterns",TEMP)
Sub Main ()
' UPDATED 20071210_0819AM
Dim CST_FILE,CST_Parameters,CST_Goal_Function,CST_Constants,temp As String
Dim H0,DH01,DH02,DH03,DH04,DH05,DH06,DH07,DH08,H1,H2,H3,H4,H5,H6,H7,H8,SW,TW,PW,RCYL_IN,RCYL_OUT,ZP As Double
Dim SH0,SH1,SH2,SH3,SH4,SH5,HS6,SH7,SH8,SSW,STW,SPW,SRCYL_IN,SRCYL_OUT,SHS,SZP,SNZP,SNRCYL_OUT,SNMODES As String
Dim bComp1 As Boolean
Dim DFLN,PFLN,OFLN,RES1,RES2,RES3,RES4,MON,CST_FLN,WAIT_FLN,XFLN As String
Dim NP,NITERATION,WAIT_INDEX As Integer
Dim FREQ(),AV(),AH(),PV(),PH(),Delta_phase_deg,Delta_phase_rad,Delta_amp_dB,Retloss(),OA,OB,AR_dB As Double

Rebuild
Debug.Clear
Open "C:\TDATA\AFRL\ST-AFRL\[04] SIMULATION ANNEALING FOR CST\20071118_1014AM_ANNEAL\RUN\PVF_ANNEAL\PVF_ANNEAL\MY_FILES.TXT" For Input As 101
Line Input#101,CST_FILE
Line Input#101,CST_Parameters
Line Input#101,CST_Constants
Line Input#101,CST_Goal_Function
Line Input#101,RES1
Line Input#101,RES2
Line Input#101,RES3
Line Input#101,RES4
Line Input#101,MON
Debug.Print "CST_FILE : ";CST_FILE
Debug.Print "CST_Parameters: ";CST_Parameters
Debug.Print "CST_Constants : ";CST_Constants
Debug.Print "RES1 : ";RES1
Debug.Print "RES2 : ";RES2
Debug.Print "RES3 : ";RES3
Debug.Print "RES4 : ";RES4
Debug.Print "MON : ";MON

Close 101

Call Set_units(temp)
Dim xtype As String
xtype="Normal"
Call Define_Background(xtype)

' set background material to pec
temp = "With Background" + vbCrLf + _
" .Type ""pec"" "+ vbCrLf + _
" .XminSpace ""0.0"" "+ vbCrLf + _
" .XmaxSpace ""0.0"" "+ vbCrLf + _
" .YminSpace ""0.0"" "+ vbCrLf + _
" .YmaxSpace ""0.0"" "+ vbCrLf + _
" .ZminSpace ""0.0"" "+ vbCrLf + _
" .ZmaxSpace ""0.0"" "+ vbCrLf + _
"End With"
AddtoHistory("Define Background", temp)

' set boundary conditions to electric
temp = "With Boundary" + vbCrLf + _
" .Xmin ""electric"" "+ vbCrLf + _
" .Xmax ""electric"" "+ vbCrLf + _
" .Ymin ""electric"" "+ vbCrLf + _
" .Ymax ""electric"" "+ vbCrLf + _
" .Zmin ""electric"" "+ vbCrLf + _
" .Zmax ""electric"" "+ vbCrLf + _
" .Xsymmetry ""none"" "+ vbCrLf + _
" .Ysymmetry ""none"" "+ vbCrLf + _
" .Zsymmetry ""none"" "+ vbCrLf + _
"End With"
AddtoHistory("Define Boundary", temp)

Mesh.MinimumCurvatureRefinement "150"

'Dim NMODES As Integer
'DFLN="C:\TDATA\AFRL\ST-AFRL\20071118_1014AM_ANNEAL\RUN\CST_simulation_file\"
'OFLN="Matthias2"
'PFLN=DFLN+OFLN+".MOD"
'RES1=DFLN+OFLN+"^a2(2)1(2).sig"
'RES2=DFLN+OFLN+"^a2(3)1(2).sig"
'RES3=DFLN+OFLN+"^p2(2)1(2).sig"
'RES4=DFLN+OFLN+"^p2(3)1(2).sig"
'MON=DFLN+OFLN+".OUT"
'CST_FLN=DFLN+OFLN+".MOD"

NP=1001

ReDim FREQ(NP),AV(NP),AH(NP),PV(NP),PH(NP)
Dim GOAL_FUNCTION As Double
Open CST_Parameters For Input As 1

Input#1, H0
Input#1,DH01
Input#1,DH02
Input#1,DH03
Input#1,DH04
Input#1,DH05
Input#1,DH06
Input#1,DH07
Input#1,DH08
Input#1,SW
Close 1
Open CST_Constants For Input As 11
Input#11,TW
Input#11,RCYL_IN
Input#11,RCYL_OUT
Input#11,LCYL
Input#11,NMODES
Close 11
STOREDOUBLEPARAMETER("H0",Str$(H0))
STOREDOUBLEPARAMETER("DH01",Str$(DH01))
STOREDOUBLEPARAMETER("DH02",Str$(DH02))
STOREDOUBLEPARAMETER("DH03",Str$(DH03))
STOREDOUBLEPARAMETER("DH04",Str$(DH04))
STOREDOUBLEPARAMETER("DH05",Str$(DH05))
STOREDOUBLEPARAMETER("DH06",Str$(DH06))
STOREDOUBLEPARAMETER("DH07",Str$(DH07))
STOREDOUBLEPARAMETER("DH08",Str$(DH08))
STOREDOUBLEPARAMETER("SW",Str$(SW))

STOREDOUBLEPARAMETER("TW",Str$(TW))
STOREDOUBLEPARAMETER("RCYL_IN",Str$(RCYL_IN))
STOREDOUBLEPARAMETER("RCYL_OUT",Str$(RCYL_OUT))
STOREDOUBLEPARAMETER("LCYL",Str$(LCYL))
STOREDOUBLEPARAMETER("NMODES",Str$(NMODES))

SNMODES=NMODES

H1=-(H0+DH01)
H2=-(H0+DH02)
H3=-(H0+DH03)
H4=-(H0+DH04)
H5=-(H0+DH05)
H6=-(H0+DH06)
H7=-(H0+DH07)
H8=-(H0+DH08)
PW=TW+SW
ZP=LCYL/2
SRCYL_IN=RCYL_IN
SLCYL=LCYL
SH1=H1
SH2=H2
SH3=H3
SH4=H4
SH5=H5
SH6=H6
SH7=H7
SH8=H8
SSW=SW
SHW=SW/2
STW=TW
SRCYL_OUT=RCYL_OUT
SPW=PW
SNRCYL_OUT=-RCYL_OUT
SZP=LCYL/2
SNZP=-LCYL/2
Solver.FrequencyRange "17.5", "21.5"
' new component: component1

Component.New "component1"

' define cylinder: component1:CYLINDER

With Cylinder
.Reset
.Name "CYLINDER"
.Component "component1"
.Material "Vacuum"
.OuterRadius SRCYL_OUT
.InnerRadius SRCYL_IN
.Axis "z"
.Zrange SLCYL, "0"
.Xcenter "0"
.Ycenter "0"
.Segments "0"
.Create
End With

' switch working plane

Plot.DrawWorkplane "false"

' pick circle center point

Pick.PickCirclecenterFromId "component1:CYLINDER", "3"

' align wcs with point

WCS.AlignWCSWithSelectedPoint

' move wcs

WCS.MoveWCS "local", "0.0", SRCYL_OUT, "0.0"
'================ here 1
' rotate wcs

WCS.RotateWCS "v", "180"

' move wcs

WCS.MoveWCS "local", "0.0", "0.0", SHW
'============================================= here2
'@ define brick: component1:BRICK1 <= DO BRICK1 ============================================================

With Brick
.Reset
.Name "BRICK1"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH1, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW '<================pw


'@ define brick: component1:BRICK2 <= DO BRICK2 ============================================================

With Brick
.Reset
.Name "BRICK2"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH2, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", SPW

'@ define brick: component1:BRICK3 <= DO BRICK3 ============================================================

With Brick
.Reset
.Name "BRICK3"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH3, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW

'@ define brick: component1:BRICK4 <= DO BRICK4 ============================================================

With Brick
.Reset
.Name "BRICK4"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH4, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW

'@ define brick: component1:BRICK5 <= DO BRICK5

With Brick
.Reset
.Name "BRICK5"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH5, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", SPW

'@ define brick: component1:BRICK6 <= DO BRICK6

With Brick
.Reset
.Name "BRICK6"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH6, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW

'@ define brick: component1:BRICK7 <= DO BRICK7

With Brick
.Reset
.Name "BRICK7"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH7, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW

'@ define brick: component1:BRICK8 <= DO BRICK8

With Brick
.Reset
.Name "BRICK8"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH8, "0"
.Zrange "0", STW
.Create
End With

'@ boolean add shapes: component1:BRICK1, component1:BRICK2
'@ boolean add shapes: component1:BRICK1, component1:BRICK2
Solid.Add "component1:BRICK1", "component1:BRICK2"
'@ boolean add shapes: component1:BRICK1, component1:BRICK3
Solid.Add "component1:BRICK1", "component1:BRICK3"
'@ boolean add shapes: component1:BRICK1, component1:BRICK4
Solid.Add "component1:BRICK1", "component1:BRICK4"
'@ boolean add shapes: component1:BRICK1, component1:BRICK5
Solid.Add "component1:BRICK1", "component1:BRICK5"
'@ boolean add shapes: component1:BRICK1, component1:BRICK6
Solid.Add "component1:BRICK1", "component1:BRICK6"
'@ boolean add shapes: component1:BRICK1, component1:BRICK7
Solid.Add "component1:BRICK1", "component1:BRICK7"
'@ boolean add shapes: component1:BRICK1, component1:BRICK8
Solid.Add "component1:BRICK1", "component1:BRICK8"
WCS.ActivateWCS "global"
With Transform
.Reset
.Name "component1:BRICK1"
.Origin "Free"
.Center "0", "0", "0"
.PlaneNormal "0", "-1", "0"
.MultipleObjects "True"
.GroupObjects "False"
.Repetitions "1"
.MultipleSelection "False"
.Component ""
.Material ""
.MirrorAdvanced
End With

Pick.PickCirclecenterFromId "component1:CYLINDER", "3"
Pick.PickCirclecenterFromId "component1:CYLINDER", "1"

With Transform
.Reset
.Name "component1"
.Vector "0", "0", "-30"
.UsePickedPoints "True"
.InvertPickedPoints "False"
.MultipleObjects "False"
.GroupObjects "False"
.Repetitions "1"
.MultipleSelection "False"
.TranslateAdvanced
End With
'@ boolean add shapes: component1:BRICK1, component1:BRICK1_1

Solid.Add "component1:BRICK1", "component1:BRICK1_1"
'@ boolean insert shapes: component1:CYLINDER, component1:BRICK1
Solid.Insert "component1:CYLINDER", "component1:BRICK1"
'@ delete shape: component1:BRICK1
Solid.Delete "component1:BRICK1"
With Transform
.Reset
.Name "component1:CYLINDER"
.Origin "Free"
.Center "0", "0", "0"
.PlaneNormal "0", "0", "1"
.MultipleObjects "True"
.GroupObjects "False"
.Repetitions "1"
.MultipleSelection "False"
.Component ""
.Material ""
.MirrorAdvanced
End With

'@ boolean add shapes: component1:CYLINDER, component1:CYLINDER_1
Solid.Add "component1:CYLINDER", "component1:CYLINDER_1"

'@ pick face
Pick.PickFaceFromId "component1:CYLINDER", "97"
'@ define port: 1

With Port
.Reset
.PortNumber "1"
.NumberOfModes SNMODES
.AdjustPolarization True
.PolarizationAngle "45"
.ReferencePlaneDistance "0"
.TextSize "50"
.Coordinates "Free"
.Orientation "zmax"
.PortOnBound "True"
.ClipPickedPortToBound "False"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SNRCYL_OUT, SRCYL_OUT
.Zrange SNZP, SNZP
.XrangeAdd "0.0", "0.0"
.YrangeAdd "0.0", "0.0"
.ZrangeAdd "0.0", "0.0"
.Create
End With

'@ pick face

Pick.PickFaceFromId "component1:CYLINDER", "214"

' FRED STOP HERE AND GO STEP BY STEP - IT WILL WORK TO THE END. IF YOU RUN WITHOUT STOPING WILL HAVE A PROBLEM WITH PORT 2 !!!
'@ define port: 2

With Port
.Reset
.PortNumber "2"
.NumberOfModes SNMODES
.AdjustPolarization True
.PolarizationAngle "45"
.ReferencePlaneDistance "0"
.TextSize "50"
.Coordinates "Picks"
.Orientation "zmin"
.PortOnBound "True"
.ClipPickedPortToBound "False"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SNRCYL_OUT, SRCYL_OUT
.Zrange SZP, SZP
.XrangeAdd "0.0", "0.0"
.YrangeAdd "0.0", "0.0"
.ZrangeAdd "0.0", "0.0"
.Create
End With
'====================== DEFINE EXCITATION MODES
With Solver
.ResetExcitationModes
.SimultaneousExcitation "False"
.SetSimultaneousExcitAutoLabel "True"
.SetSimultaneousExcitationLabel "1(2)[1.0,0.0]"
.SetSimultaneousExcitationOffset "Timedelay"
.PhaseRefFrequency "19.5"
.ExcitationPortMode "1", "1", "1.0", "0.0", "default", "False"
.ExcitationPortMode "1", "2", "1.0", "0.0", "default", "True"
.ExcitationPortMode "1", "3", "1.0", "0.0", "default", "False"
.ExcitationPortMode "2", "1", "1.0", "0.0", "default", "False"
.ExcitationPortMode "2", "2", "1.0", "0.0", "default", "False"
.ExcitationPortMode "2", "3", "1.0", "0.0", "default", "False"
End With
'====================== SOLVER PARAMETERS
'@ use template: Waveguide Coupler

' Template for Waveguide Coupler
' ==============================

' (CSTxMWSxONLY)

'====================== SAVE FILE AS
SaveAs (CST_FILE,True)
'====================================
With Mesh
.UseRatioLimit "True"
.RatioLimit "40"
.LinesPerWavelength "15"
.MinimumStepNumber "15"
.Automesh "True"
.MeshType "PBA"
End With

With Solver
.CalculationType "TD-S"
.StimulationPort "Selected"
.StimulationMode "All"
.SteadyStateLimit "-30"
.MeshAdaption "False"
.AutoNormImpedance "False"
.NormingImpedance "50"
.CalculateModesOnly "False"
.SParaSymmetry "False"
.StoreTDResultsInCache "False"
.FullDeembedding "False"
.start
End With
'===============================================================
Debug.Print "RES1 : ";RES1

Open RES1 For Input As 1
Call Read_Results(1,FREQ,AV,NP)
Close 1
Open RES2 For Input As 2
Call Read_Results(2,FREQ,AH,NP)
Close 2
Open RES3 For Input As 3
Call Read_Results(3,FREQ,PV,NP)
Close 3
Open RES4 For Input As 4
Call Read_Results(4,FREQ,PH,NP)
Close 4
GOAL_FUNCTION=-10^33
For J=1 To NP
Delta_phase_deg=Abs(PV(J)-PH(J))
Delta_phase_rad=Delta_phase_deg*3.1416/180
AAHH=AH(J)
AAVV=AV(J)
OA=AAHH^2+AAVV^2+(AAHH^4+AAVV^4+2*AAHH^2*AAVV^2*Cos(2*Delta_phase_rad))^0.5
OB=AAHH^2+AAVV^2-(AAHH^4+AAVV^4+2*AAHH^2*AAVV^2*Cos(2*Delta_phase_rad))^0.5
AR_dB=10*Log(OA/OB)/Log(10)
If GOAL_FUNCTION<AR_dB Then
GOAL_FUNCTION=AR_dB
End If
Next J

Open CST_Goal_Function For Output As 11
Print#11,Str(GOAL_FUNCTION)
Close 11
StoreParameter("Goal_Function",Str$(GOAL_FUNCTION))
'===============================================================
End Sub
Public Sub Read_Results(I,FREQUENCY,GANIE,NP)
Dim XXX,YYY As Double
Line Input#I,t$
Line Input#I,t$
Line Input#I,t$
Line Input#I,t$
For K=1 To NP
Input#I,t$
NL=Len(t$)
FREQUENCY(K)=Val(Mid(t$,1,Int(NL/2)))
GANIE(K)=Val(Mid(t$,Int(NL/2)+1,NL))
Next K
End Sub
Public Sub Set_units(temp)
' set units
temp = "With Units" + vbCrLf + _
" .Geometry ""mm"" "+ vbCrLf + _
" .Frequency ""ghz"" "+ vbCrLf + _
" .Time ""ns"" "+ vbCrLf + _
"End With"
AddtoHistory("Define Units", temp)
End Sub
Public Sub Define_Background(xtype)
' set background material to pec
'Dim xtype As String
A$=Chr$(34)

temp = "With Background" + vbCrLf + _
" .Type "+" "+A$+xtype+A$+" "+ vbCrLf + _
" .XminSpace ""0.0"" "+ vbCrLf + _
" .XmaxSpace ""0.0"" "+ vbCrLf + _
" .YminSpace ""0.0"" "+ vbCrLf + _
" .YmaxSpace ""0.0"" "+ vbCrLf + _
" .ZminSpace ""0.0"" "+ vbCrLf + _
" .ZmaxSpace ""0.0"" "+ vbCrLf + _
"End With"
Debug.Print temp
AddtoHistory("Define Background", temp)
End Sub
CREATE LINE
temp="With Line" + vbCrLf
temp=temp+" .Reset" + vbCrLf
temp=temp+" .Name "+Z$+"Line"+LTrim(Str$(i))+Z$+vbCrLf
'temp=temp+" .Component ""component1"" "+ vbCrLf
temp=temp+" .Curve "+Z$+"curve1"+Z$+ vbCrLf
temp=temp+" .X1 "+Z$+LTrim(Str$(xp(I)))+ Z$ + vbCrLf
temp=temp+" .Y1 "+Z$+LTrim(Str$(yp(I)))+ Z$ + vbCrLf
temp=temp+" .X2 "+Z$+LTrim(Str$(xp(I+1)))+ Z$ + vbCrLf
temp=temp+" .Y2 "+Z$+LTrim(Str$(xp(I+1)))+ Z$ + vbCrLf
temp=temp+" .Create" + vbCrLf
temp=temp+"End With"
Debug.Print temp
Print#2,Str$(I)+" "+Str$(xp(I))+" "+Str$(yp(I))+" "+Str$(xp(I+1))+" "+Str$(yp(I+1))
AddtoHistory("Add Line", temp)

Public Sub T_Create_Polyline(pname,cname,xp,yp,n)
Q$=Chr$(34)
temp="Component.New "+Q$+ "component1"+Q$+vbCrLf
temp=temp+"Curve.NewCurve "+Q$+"curve1"+Q$+vbCrLf
Debug.Print temp
temp=temp+"With Polygon" + vbCrLf
temp=temp+" .Reset" + vbCrLf
temp=temp+" .Name "+Q$+pname+Q$+vbCrLf
temp=temp+" .Curve "+Q$+cname+Q$+ vbCrLf
For i=1 To n
temp=temp+".LineTo "+Q$+LTrim(Str$(xp(I)))+ Q$+" ,"+Q$+LTrim(Str$(yp(I)))+Q$+ vbCrLf
Next i
temp=temp+" .Create" + vbCrLf
temp=temp+"End With"
Debug.Print temp
AddtoHistory("Add_Line", temp)
End Sub
 
   

 

TOP ADD_MONITORS WITH MENU
  Sub Main ()

Dim V_Fmin As Double, V_Fmax As Double, V_Fstep As Double, scst_torrus_h As Double
Dim scst_torrus_N As Integer, cst_result As Integer, sCurveName As String
Dim cst_torrus_N As Integer, cst_torrus_phi As Double, cst_torrus_h As Double, cst_torrus_r As Double

BeginHide
Begin Dialog UserDialog 630,126,"Add/Delete Monitors" ' %GRID:10,7,1,1

Text 10,14,110,14,"Fmin [GHz]",.Text1
TextBox 130,14,80,21,.Fmin
Text 10,35,90,14,"Fmax [GHz]",.Text3
TextBox 130,35,80,21,.Fmax
OKButton 10,98,100,21
CancelButton 120,98,90,21
Text 10,56,110,14,"Fstep [GHz]",.Text4
TextBox 130,56,80,21,.Fstep
OptionGroup .Group1
OptionButton 230,14,130,14,"Add Monitors",.OptionButton1
OptionButton 230,35,130,14,"Delete Monitors",.OptionButton2
CheckBox 390,14,140,14,"E-Fields",.CheckBox1
CheckBox 390,35,140,14,"H-Fields",.CheckBox2
CheckBox 390,56,140,14,"Farfields",.CheckBox3


End Dialog
Dim dlg As UserDialog
Dim I,J1,J2,J3
' set defaults for dialog
dlg.Fmin = "1."
dlg.Fmax ="5."
dlg.Fstep = "1"

Dialog dlg ' show dialog (wait for ok)

I=dlg.Group1 ' IF I=0 THEN <<ADD>>. IF I=1 THEN << DELETE>>

J1=dlg.checkbox1 'If J1=1 "E-FIELDS". If J1=0 << NO E-FIELDS>>
J2=dlg.checkbox2 'If J1=1 "H-FIELDS". If J1=0 << NO H-FIELDS>>
J3=dlg.checkbox3 'If J1=1 "Surface Currents". If J1=0 << NO Surface Currents>>

V_Fmin = evaluate(dlg.Fmin)
V_Fmax=evaluate(dlg.Fmax)
V_Fstep= evaluate(dlg.Fstep)

StoreDoubleParameter "Fmin", V_Fmin
SetParameterDescription ("Fmin", "Lowest Frequency" )
StoreDoubleParameter "Fmax", V_Fmax
SetParameterDescription ("Fmax", "Highest Frequency" )
StoreDoubleParameter "Fstep", V_Fstep
SetParameterDescription ("Fstep", "Frequency Step" )

EndHide


If I=0 Then
Call Add_monitors(V_Fmin,V_Fmax,V_Fstep,J1,J2,J3,J4)
End If
If I=1 Then
Call Delete_monitors(V_Fmin,V_Fmax,V_Fstep,J1,J2,J3)
End If
End Sub
Sub Add_monitors(fmin,fmax,df,J1,J2,J3,J4)
a$=Chr$(32)
freq=fmin-df
While freq<fmax
freq=freq+df
If J1=1 Then
With Monitor
.Reset
.Name "e-field (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
.Dimension "Volume"
.Domain "Frequency"
.FieldType "Efield"
.Frequency a$+Str$(freq)+a$
.Create
End With
End If

If J2=1 Then
With Monitor
.Reset
.Name "h-field (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
.Dimension "Volume"
.Domain "Frequency"
.FieldType "Hfield"
.Frequency a$+Str$(freq)+a$
.Create
End With
End If


If J3=1 Then
With Monitor
.Reset
.Name "farfield (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
.Domain "Frequency"
.FieldType "Farfield"
.Frequency a$+Str$(freq)+a$
.Create
End With
End If
Wend
End Sub
Sub Delete_monitors(fmin,fmax,df,J1,J2,J3)
a$=Chr$(32)
freq=fmin-df
While freq<fmax
freq=freq+df
Monitor.Delete "e-field (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
Monitor.Delete "h-field (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
Monitor.Delete "farfield (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
Wend

End Sub
 
  200708270752AM_Nmodes_2
  Sub Main ()
' UPDATED 20071210_0819AM
Dim CST_FILE,CST_Parameters,CST_Goal_Function,CST_Constants,temp As String
Dim H0,DH01,DH02,DH03,DH04,DH05,DH06,DH07,DH08,H1,H2,H3,H4,H5,H6,H7,H8,SW,TW,PW,RCYL_IN,RCYL_OUT,ZP As Double
Dim SH0,SH1,SH2,SH3,SH4,SH5,HS6,SH7,SH8,SSW,STW,SPW,SRCYL_IN,SRCYL_OUT,SHS,SZP,SNZP,SNRCYL_OUT,SNMODES As String
Dim bComp1 As Boolean
Dim DFLN,PFLN,OFLN,RES1,RES2,RES3,RES4,MON,CST_FLN,WAIT_FLN,XFLN As String
Dim NP,NITERATION,WAIT_INDEX As Integer
Dim FREQ(),AV(),AH(),PV(),PH(),Delta_phase_deg,Delta_phase_rad,Delta_amp_dB,Retloss(),OA,OB,AR_dB As Double

rebuild
Debug.Clear
Open "C:\TDATA\AFRL\ST-AFRL\[04] SIMULATION ANNEALING FOR CST\20071118_1014AM_ANNEAL\RUN\PVF_ANNEAL\PVF_ANNEAL\MY_FILES.TXT" For Input As 101
Line Input#101,CST_FILE
Line Input#101,CST_Parameters
Line Input#101,CST_Constants
Line Input#101,CST_Goal_Function
Line Input#101,RES1
Line Input#101,RES2
Line Input#101,RES3
Line Input#101,RES4
Line Input#101,MON
Debug.Print "CST_FILE : ";CST_FILE
Debug.Print "CST_Parameters: ";CST_Parameters
Debug.Print "CST_Constants : ";CST_Constants
Debug.Print "RES1 : ";RES1
Debug.Print "RES2 : ";RES2
Debug.Print "RES3 : ";RES3
Debug.Print "RES4 : ";RES4
Debug.Print "MON : ";MON


Close 101


' set units
temp = "With Units" + vbCrLf + _
" .Geometry ""mm"" "+ vbCrLf + _
" .Frequency ""ghz"" "+ vbCrLf + _
" .Time ""ns"" "+ vbCrLf + _
"End With"
AddtoHistory("Define Units", temp)

' set background material to pec
temp = "With Background" + vbCrLf + _
" .Type ""pec"" "+ vbCrLf + _
" .XminSpace ""0.0"" "+ vbCrLf + _
" .XmaxSpace ""0.0"" "+ vbCrLf + _
" .YminSpace ""0.0"" "+ vbCrLf + _
" .YmaxSpace ""0.0"" "+ vbCrLf + _
" .ZminSpace ""0.0"" "+ vbCrLf + _
" .ZmaxSpace ""0.0"" "+ vbCrLf + _
"End With"
AddtoHistory("Define Background", temp)

' set boundary conditions to electric
temp = "With Boundary" + vbCrLf + _
" .Xmin ""electric"" "+ vbCrLf + _
" .Xmax ""electric"" "+ vbCrLf + _
" .Ymin ""electric"" "+ vbCrLf + _
" .Ymax ""electric"" "+ vbCrLf + _
" .Zmin ""electric"" "+ vbCrLf + _
" .Zmax ""electric"" "+ vbCrLf + _
" .Xsymmetry ""none"" "+ vbCrLf + _
" .Ysymmetry ""none"" "+ vbCrLf + _
" .Zsymmetry ""none"" "+ vbCrLf + _
"End With"
AddtoHistory("Define Boundary", temp)

Mesh.MinimumCurvatureRefinement "150"

'Dim NMODES As Integer
'DFLN="C:\TDATA\AFRL\ST-AFRL\20071118_1014AM_ANNEAL\RUN\CST_simulation_file\"
'OFLN="Matthias2"
'PFLN=DFLN+OFLN+".MOD"
'RES1=DFLN+OFLN+"^a2(2)1(2).sig"
'RES2=DFLN+OFLN+"^a2(3)1(2).sig"
'RES3=DFLN+OFLN+"^p2(2)1(2).sig"
'RES4=DFLN+OFLN+"^p2(3)1(2).sig"
'MON=DFLN+OFLN+".OUT"
'CST_FLN=DFLN+OFLN+".MOD"

NP=1001

ReDim FREQ(NP),AV(NP),AH(NP),PV(NP),PH(NP)
Dim GOAL_FUNCTION As Double
Open CST_Parameters For Input As 1

Input#1, H0
Input#1,DH01
Input#1,DH02
Input#1,DH03
Input#1,DH04
Input#1,DH05
Input#1,DH06
Input#1,DH07
Input#1,DH08
Input#1,SW
Close 1
Open CST_Constants For Input As 11
Input#11,TW
Input#11,RCYL_IN
Input#11,RCYL_OUT
Input#11,LCYL
Input#11,NMODES
Close 11
STOREDOUBLEPARAMETER("H0",Str$(H0))
STOREDOUBLEPARAMETER("DH01",Str$(DH01))
STOREDOUBLEPARAMETER("DH02",Str$(DH02))
STOREDOUBLEPARAMETER("DH03",Str$(DH03))
STOREDOUBLEPARAMETER("DH04",Str$(DH04))
STOREDOUBLEPARAMETER("DH05",Str$(DH05))
STOREDOUBLEPARAMETER("DH06",Str$(DH06))
STOREDOUBLEPARAMETER("DH07",Str$(DH07))
STOREDOUBLEPARAMETER("DH08",Str$(DH08))
STOREDOUBLEPARAMETER("SW",Str$(SW))

STOREDOUBLEPARAMETER("TW",Str$(TW))
STOREDOUBLEPARAMETER("RCYL_IN",Str$(RCYL_IN))
STOREDOUBLEPARAMETER("RCYL_OUT",Str$(RCYL_OUT))
STOREDOUBLEPARAMETER("LCYL",Str$(LCYL))
STOREDOUBLEPARAMETER("NMODES",Str$(NMODES))

SNMODES=NMODES

H1=-(H0+DH01)
H2=-(H0+DH02)
H3=-(H0+DH03)
H4=-(H0+DH04)
H5=-(H0+DH05)
H6=-(H0+DH06)
H7=-(H0+DH07)
H8=-(H0+DH08)
PW=TW+SW
ZP=LCYL/2
SRCYL_IN=RCYL_IN
SLCYL=LCYL
SH1=H1
SH2=H2
SH3=H3
SH4=H4
SH5=H5
SH6=H6
SH7=H7
SH8=H8
SSW=SW
SHW=SW/2
STW=TW
SRCYL_OUT=RCYL_OUT
SPW=PW
SNRCYL_OUT=-RCYL_OUT
SZP=LCYL/2
SNZP=-LCYL/2
Solver.FrequencyRange "17.5", "21.5"
' new component: component1

Component.New "component1"

' define cylinder: component1:CYLINDER

With Cylinder
.Reset
.Name "CYLINDER"
.Component "component1"
.Material "Vacuum"
.OuterRadius SRCYL_OUT
.InnerRadius SRCYL_IN
.Axis "z"
.Zrange SLCYL, "0"
.Xcenter "0"
.Ycenter "0"
.Segments "0"
.Create
End With

' switch working plane

Plot.DrawWorkplane "false"

' pick circle center point

Pick.PickCirclecenterFromId "component1:CYLINDER", "3"

' align wcs with point

WCS.AlignWCSWithSelectedPoint

' move wcs

WCS.MoveWCS "local", "0.0", SRCYL_OUT, "0.0"
'================ here 1
' rotate wcs

WCS.RotateWCS "v", "180"

' move wcs

WCS.MoveWCS "local", "0.0", "0.0", SHW
'============================================= here2
'@ define brick: component1:BRICK1 <= DO BRICK1 ============================================================

With Brick
.Reset
.Name "BRICK1"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH1, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW '<================pw


'@ define brick: component1:BRICK2 <= DO BRICK2 ============================================================

With Brick
.Reset
.Name "BRICK2"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH2, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", SPW

'@ define brick: component1:BRICK3 <= DO BRICK3 ============================================================

With Brick
.Reset
.Name "BRICK3"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH3, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW

'@ define brick: component1:BRICK4 <= DO BRICK4 ============================================================

With Brick
.Reset
.Name "BRICK4"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH4, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW

'@ define brick: component1:BRICK5 <= DO BRICK5

With Brick
.Reset
.Name "BRICK5"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH5, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", SPW

'@ define brick: component1:BRICK6 <= DO BRICK6

With Brick
.Reset
.Name "BRICK6"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH6, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW

'@ define brick: component1:BRICK7 <= DO BRICK7

With Brick
.Reset
.Name "BRICK7"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH7, "0"
.Zrange "0", STW
.Create
End With

'@ move wcs

WCS.MoveWCS "local", "0.0", "0.0", PW

'@ define brick: component1:BRICK8 <= DO BRICK8

With Brick
.Reset
.Name "BRICK8"
.Component "component1"
.Material "Vacuum"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SH8, "0"
.Zrange "0", STW
.Create
End With

'@ boolean add shapes: component1:BRICK1, component1:BRICK2
'@ boolean add shapes: component1:BRICK1, component1:BRICK2
Solid.Add "component1:BRICK1", "component1:BRICK2"
'@ boolean add shapes: component1:BRICK1, component1:BRICK3
Solid.Add "component1:BRICK1", "component1:BRICK3"
'@ boolean add shapes: component1:BRICK1, component1:BRICK4
Solid.Add "component1:BRICK1", "component1:BRICK4"
'@ boolean add shapes: component1:BRICK1, component1:BRICK5
Solid.Add "component1:BRICK1", "component1:BRICK5"
'@ boolean add shapes: component1:BRICK1, component1:BRICK6
Solid.Add "component1:BRICK1", "component1:BRICK6"
'@ boolean add shapes: component1:BRICK1, component1:BRICK7
Solid.Add "component1:BRICK1", "component1:BRICK7"
'@ boolean add shapes: component1:BRICK1, component1:BRICK8
Solid.Add "component1:BRICK1", "component1:BRICK8"
WCS.ActivateWCS "global"
With Transform
.Reset
.Name "component1:BRICK1"
.Origin "Free"
.Center "0", "0", "0"
.PlaneNormal "0", "-1", "0"
.MultipleObjects "True"
.GroupObjects "False"
.Repetitions "1"
.MultipleSelection "False"
.Component ""
.Material ""
.MirrorAdvanced
End With

Pick.PickCirclecenterFromId "component1:CYLINDER", "3"
Pick.PickCirclecenterFromId "component1:CYLINDER", "1"

With Transform
.Reset
.Name "component1"
.Vector "0", "0", "-30"
.UsePickedPoints "True"
.InvertPickedPoints "False"
.MultipleObjects "False"
.GroupObjects "False"
.Repetitions "1"
.MultipleSelection "False"
.TranslateAdvanced
End With
'@ boolean add shapes: component1:BRICK1, component1:BRICK1_1

Solid.Add "component1:BRICK1", "component1:BRICK1_1"
'@ boolean insert shapes: component1:CYLINDER, component1:BRICK1
Solid.Insert "component1:CYLINDER", "component1:BRICK1"
'@ delete shape: component1:BRICK1
Solid.Delete "component1:BRICK1"
With Transform
.Reset
.Name "component1:CYLINDER"
.Origin "Free"
.Center "0", "0", "0"
.PlaneNormal "0", "0", "1"
.MultipleObjects "True"
.GroupObjects "False"
.Repetitions "1"
.MultipleSelection "False"
.Component ""
.Material ""
.MirrorAdvanced
End With

'@ boolean add shapes: component1:CYLINDER, component1:CYLINDER_1
Solid.Add "component1:CYLINDER", "component1:CYLINDER_1"

'@ pick face
Pick.PickFaceFromId "component1:CYLINDER", "97"
'@ define port: 1

With Port
.Reset
.PortNumber "1"
.NumberOfModes SNMODES
.AdjustPolarization True
.PolarizationAngle "45"
.ReferencePlaneDistance "0"
.TextSize "50"
.Coordinates "Free"
.Orientation "zmax"
.PortOnBound "True"
.ClipPickedPortToBound "False"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SNRCYL_OUT, SRCYL_OUT
.Zrange SNZP, SNZP
.XrangeAdd "0.0", "0.0"
.YrangeAdd "0.0", "0.0"
.ZrangeAdd "0.0", "0.0"
.Create
End With



'@ pick face


Pick.PickFaceFromId "component1:CYLINDER", "214"

'================================================== FRED STOP HERE AND GO STEP BY STEP - IT WILL WORK TO THE END. IF YOU RUN WITHOUT STOPING WILL HAVE A PROBLEM WITH PORT 2 !!!
'@ define port: 2

With Port
.Reset
.PortNumber "2"
.NumberOfModes SNMODES
.AdjustPolarization True
.PolarizationAngle "45"
.ReferencePlaneDistance "0"
.TextSize "50"
.Coordinates "Picks"
.Orientation "zmin"
.PortOnBound "True"
.ClipPickedPortToBound "False"
.Xrange SNRCYL_OUT, SRCYL_OUT
.Yrange SNRCYL_OUT, SRCYL_OUT
.Zrange SZP, SZP
.XrangeAdd "0.0", "0.0"
.YrangeAdd "0.0", "0.0"
.ZrangeAdd "0.0", "0.0"
.Create
End With


'====================== DEFINE EXCITATION MODES
With Solver
.ResetExcitationModes
.SimultaneousExcitation "False"
.SetSimultaneousExcitAutoLabel "True"
.SetSimultaneousExcitationLabel "1(2)[1.0,0.0]"
.SetSimultaneousExcitationOffset "Timedelay"
.PhaseRefFrequency "19.5"
.ExcitationPortMode "1", "1", "1.0", "0.0", "default", "False"
.ExcitationPortMode "1", "2", "1.0", "0.0", "default", "True"
.ExcitationPortMode "1", "3", "1.0", "0.0", "default", "False"
.ExcitationPortMode "2", "1", "1.0", "0.0", "default", "False"
.ExcitationPortMode "2", "2", "1.0", "0.0", "default", "False"
.ExcitationPortMode "2", "3", "1.0", "0.0", "default", "False"
End With
'====================== SOLVER PARAMETERS
'@ use template: Waveguide Coupler

' Template for Waveguide Coupler
' ==============================

' (CSTxMWSxONLY)

'====================== SAVE FILE AS
SaveAs (CST_FILE,True)
'====================================
With Mesh
.UseRatioLimit "True"
.RatioLimit "40"
.LinesPerWavelength "15"
.MinimumStepNumber "15"
.Automesh "True"
.MeshType "PBA"
End With

With Solver
.CalculationType "TD-S"
.StimulationPort "Selected"
.StimulationMode "All"
.SteadyStateLimit "-30"
.MeshAdaption "False"
.AutoNormImpedance "False"
.NormingImpedance "50"
.CalculateModesOnly "False"
.SParaSymmetry "False"
.StoreTDResultsInCache "False"
.FullDeembedding "False"
.start
End With
'===============================================================
Debug.Print "RES1 : ";RES1

Open RES1 For Input As 1
Call Read_Results(1,FREQ,AV,NP)
Close 1
Open RES2 For Input As 2
Call Read_Results(2,FREQ,AH,NP)
Close 2
Open RES3 For Input As 3
Call Read_Results(3,FREQ,PV,NP)
Close 3
Open RES4 For Input As 4
Call Read_Results(4,FREQ,PH,NP)
Close 4
GOAL_FUNCTION=-10^33
For J=1 To NP
Delta_phase_deg=Abs(PV(J)-PH(J))
Delta_phase_rad=Delta_phase_deg*3.1416/180
AAHH=AH(J)
AAVV=AV(J)
OA=AAHH^2+AAVV^2+(AAHH^4+AAVV^4+2*AAHH^2*AAVV^2*Cos(2*Delta_phase_rad))^0.5
OB=AAHH^2+AAVV^2-(AAHH^4+AAVV^4+2*AAHH^2*AAVV^2*Cos(2*Delta_phase_rad))^0.5
AR_dB=10*Log(OA/OB)/Log(10)
If GOAL_FUNCTION<AR_dB Then
GOAL_FUNCTION=AR_dB
End If
Next J

Open CST_Goal_Function For Output As 11
Print#11,Str(GOAL_FUNCTION)
Close 11
StoreParameter("Goal_Function",Str$(GOAL_FUNCTION))
'===============================================================
End Sub
Public Sub Read_Results(I,FREQUENCY,GANIE,NP)
Dim XXX,YYY As Double
Line Input#I,T$
Line Input#I,T$
Line Input#I,T$
Line Input#I,T$
For K=1 To NP
Input#I,T$
NL=Len(T$)
FREQUENCY(K)=Val(Mid(T$,1,Int(NL/2)))
GANIE(K)=Val(Mid(T$,Int(NL/2)+1,NL))
Next K
End Sub
TOP CREATE CST IN VISUAL BASIC
  Sub Main()
Dim studio As Object
Set studio = CreateObject("CSTStudio.Application")
Dim mws As Object
Set mws = studio.NewMWS
Dim brick As Object
Set brick = mws.brick
brick.Name "brick"
brick.Xrange 0, 1
brick.Yrange 0, 1
brick.Zrange 0, 1
brick.Create
mws.SaveAs "C:\temp\test.mod", False
mws.Quit
Set studio = Nothing
End Sub
Please refer to the online documentation for more information on the particular methods
available for the COM objects provided by CST STUDIO SUITE™.
Access to the object’s methods can be simplified by using a With – End With block as
shown in the example below:
Sub Main()
Dim studio As Object
Set studio = CreateObject("CSTStudio.Application")
With studio.NewMWS
With .Brick
.Name "brick"
.Xrange 0, 1
.Yrange 0, 1
.Zrange 0, 1
.Create
End With
.SaveAs "C:\temp\test.mod", False
.Quit
End With
   
   
   
   
   

 

TOP ADD_MONITORS WITH MENU_Final_FF
  ' add_monitors

Sub Main ()

Dim V_Fmin As Double, V_Fmax As Double, V_Fstep As Double, scst_torrus_h As Double
Dim scst_torrus_N As Integer, cst_result As Integer, sCurveName As String
Dim cst_torrus_N As Integer, cst_torrus_phi As Double, cst_torrus_h As Double, cst_torrus_r As Double

BeginHide
Begin Dialog UserDialog 630,126,"Add/Delete Monitors" ' %GRID:10,7,1,1
Text 10,14,110,14,"Fmin [GHz]",.Text1
TextBox 130,14,80,21,.Fmin
Text 10,35,90,14,"Fmax [GHz]",.Text3
TextBox 130,35,80,21,.Fmax
OKButton 10,98,100,21
CancelButton 120,98,90,21
Text 10,56,110,14,"Fstep [GHz]",.Text4
TextBox 130,56,80,21,.Fstep
OptionGroup .Group1
OptionButton 230,14,130,14,"Add Monitors",.OptionButton1
OptionButton 230,35,130,14,"Delete Monitors",.OptionButton2
CheckBox 390,14,140,14,"E-Fields",.CheckBox1
CheckBox 390,35,140,14,"H-Fields",.CheckBox2
CheckBox 390,56,140,14,"Surface Currents",.CheckBox3
CheckBox 390,77,140,14,"Farfields",.CheckBox4
End Dialog
Dim dlg As UserDialog
Dim I,J1,J2,J3
' set defaults for dialog
dlg.Fmin = "1."
dlg.Fmax ="5."
dlg.Fstep = "1"

Dialog dlg ' show dialog (wait for ok)

I=dlg.Group1 ' IF I=0 THEN <<ADD>>. IF I=1 THEN << DELETE>>

J1=dlg.checkbox1 'If J1=1 "E-FIELDS". If J1=0 << NO E-FIELDS>>
J2=dlg.checkbox2 'If J1=1 "H-FIELDS". If J1=0 << NO H-FIELDS>>
J3=dlg.checkbox3 'If J1=1 "Surface Currents". If J1=0 << NO Surface Currents>>
J4=dlg.checkbox4 'If J1=1 "Farfields". If J1=0 << NO Surface Currents>>
V_Fmin = evaluate(dlg.Fmin)
V_Fmax=evaluate(dlg.Fmax)
V_Fstep= evaluate(dlg.Fstep)

'StoreDoubleParameter "Fmin", V_Fmin
'SetParameterDescription ("Fmin", "Lowest Frequency" )
'StoreDoubleParameter "Fmax", V_Fmax
'SetParameterDescription ("Fmax", "Highest Frequency" )
'StoreDoubleParameter "Fstep", V_Fstep
'SetParameterDescription ("Fstep", "Frequency Step" )

EndHide


If I=0 Then
Call Add_monitors(V_Fmin,V_Fmax,V_Fstep,J1,J2,J3,J4)
End If
If I=1 Then
Call Delete_monitors(V_Fmin,V_Fmax,V_Fstep,J1,J2,J3,J4)
End If
End Sub
Sub Add_monitors(fmin,fmax,df,J1,J2,J3,J4)
a$=Chr$(32)
freq=fmin-df
While freq<fmax
freq=freq+df
If J1=1 Then
With Monitor
.Reset
.Name "e-field (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
.Dimension "Volume"
.Domain "Frequency"
.FieldType "Efield"
.Frequency a$+Str$(freq)+a$
.Create
End With
End If

If J2=1 Then
With Monitor
.Reset
.Name "h-field (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
.Dimension "Volume"
.Domain "Frequency"
.FieldType "Hfield"
.Frequency a$+Str$(freq)+a$
.Create
End With
End If

If J3=1 Then
With Monitor
.Reset
.Name "Surface Current (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
.Domain "Frequency"
.FieldType "Farfield"
.Frequency a$+Str$(freq)+a$
.Create
End With
End If

If J4=1 Then
With Monitor
.Reset
.Name "Farfield (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
.Domain "Frequency"
.FieldType "Farfield"
.Frequency a$+Str$(freq)+a$
.Create
End With
End If

Wend
End Sub
Sub Delete_monitors(fmin,fmax,df,J1,J2,J3,J4)
a$=Chr$(32)
freq=fmin-df
While freq<fmax
freq=freq+df
Monitor.Delete "e-field (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
Monitor.Delete "h-field (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
Monitor.Delete "farfield (f="+a$+LTrim(RTrim(Str$(freq)))+a$+")"
Wend

End Sub
 

 

TOP SET JJLEE_B_PARAMETERS
  Sub Main
Dim P_Name(),P_Value(),P_Description()

Np=getnumberofparameters
For i=1 To np
a$=getparametername(i)
Debug.Print a$
deleteparameter(a$)
Next i

N_Par=24

ReDim P_Name(N_Par),P_Value(N_Par),P_Description(N_Par)

fc=0.6
wl=30/fc

P_Name(15)="GND_XDim_wl" : P_Value(15)=0.5 :P_Description(1)=" "
P_Name(16)="GND_YDim_wl" : P_Value(16)=0.5 :P_Description(2)=" "
P_Name(17)="GND_to_Dipoles_wl" : P_Value(17)=0.43 :P_Description(3)=" "
P_Name(18)="GND_to_Panel_wl" : P_Value(18)=0.46 :P_Description(4)=" "
P_Name(19)="Dipole_XDim_wl" : P_Value(19)=0.02 :P_Description(5)=" "
P_Name(20)="Dipole_YDim_wl" : P_Value(20)=P_Value(16) :P_Description(6)=" "
P_Name(22)="Panel_YDim_wl" : P_Value(22)=0.249 :P_Description(8)=" "
P_Name(23)="Voltage_Gap_wl" : P_Value(23)=0.02 :P_Description(9)=" "
P_Name(24)="mt_wl" : P_Value(24)=0.0001 :P_Description(10)=" "
P_Name(21)="Slot_YDim_wl" : P_Value(21)=(P_Value(16)-P_Value(23))/2 : P_Description(7)=" "

P_Name(1)="GND_XDim" : P_Value(1)=wl*P_Value(15) :P_Description(1)=" "
P_Name(2)="GND_YDim" : P_Value(2)=wl*P_Value(16) :P_Description(2)=" "
P_Name(3)="GND_to_Dipoles" : P_Value(3)=wl*P_Value(17) :P_Description(3)=" "
P_Name(4)="GND_to_Panel" : P_Value(4)=wl*P_Value(18) :P_Description(4)=" "
P_Name(5)="Dipole_XDim" : P_Value(5)=wl*P_Value(19) :P_Description(5)=" "
P_Name(6)="Dipole_YDim" : P_Value(6)=wl*P_Value(20) :P_Description(6)=" "
P_Name(7)="Slot_YDim" : P_Value(7)=wl*P_Value(21) :P_Description(7)=" "
P_Name(8)="Panel_YDim" : P_Value(8)=wl*P_Value(22) :P_Description(8)=" "
P_Name(9)="Voltage_Gap" : P_Value(9)=wl*P_Value(23) :P_Description(9)=" "
P_Name(10)="mt" : P_Value(10)=0.05 :P_Description(10)=" "
P_Name(11)="Z0" : P_Value(11)=337 :P_Description(11)=" "
P_Name(12)="Project_Name" : P_Value(12)=0
P_Name(13)="Fhigh" : P_Value(13)=fc :P_Description(13)="High end of the Band "
P_Name(14)="Wlg" : P_Value(14)=wl :P_Description(14)="Wavelength at the High end of the Band "

For i=1 To N_Par
Debug.Print P_Name(i);P_Value(i)
storedoubleparameter(P_Name(i),P_Value(i))
setparameterdescription(P_Name(i),P_Description(i))
Next i
End Sub

 

TOP CST TLib
  Public TEMP As String
Public CCOMPONENT,CNAME,ORIG As String
Public XC, YC, ZC As Double
Public PNX,PNY,PNZ As Integer
Public Q$
Sub Main ()
' UPDATED 20071220_0839AM
Dim CST_FILE,CST_Parameters,CST_Goal_Function,CST_Constants,TEMP As String
Dim DFLN,PFLN,OFLN,RES1,RES2,RES3,RES4,MON,CST_FLN,WAIT_FLN,XFLN As String

Dim FREQ(),AV(),AH(),PV(),PH(),Delta_phase_deg,Delta_phase_rad,Delta_amp_dB,Retloss(),OA,OB,AR_dB As Double
Dim H0,DH01,DH02,DH03,DH04,DH05,DH06,DH07,DH08,H1,H2,H3,H4,H5,H6,H7,H8,SW,TW,PW,RCYL_IN,RCYL_OUT,LCYL As Double
Dim AMP(),PHASE() As Double

Dim NP,NITERATION,WAIT_INDEX,NMODES As Integer

Dim YES_NO() As Boolean
Dim FMIN,FMAX,FMID
Dim bComp1 As Boolean
Dim YN As Boolean

Rebuild

Debug.Clear
Open "C:\TDATA\AFRL\ST-AFRL\[04] SIMULATION ANNEALING FOR CST\20071118_1014AM_ANNEAL\RUN\PVF_ANNEAL\PVF_ANNEAL\MY_FILES.TXT" For Input As 101
Line Input#101,CST_FILE
Line Input#101,CST_Parameters
Line Input#101,CST_Constants
Line Input#101,CST_Goal_Function
Line Input#101,RES1
Line Input#101,RES2
Line Input#101,RES3
Line Input#101,RES4
Line Input#101,MON
Debug.Print "CST_FILE : ";CST_FILE
Debug.Print "CST_Parameters: ";CST_Parameters
Debug.Print "CST_Constants : ";CST_Constants
Debug.Print "RES1 : ";RES1
Debug.Print "RES2 : ";RES2
Debug.Print "RES3 : ";RES3
Debug.Print "RES4 : ";RES4
Debug.Print "MON : ";MON

Close 101

Q$=Chr$(34)
NPORTS=0

' set units
Call T_Units("mm","GHz","ns")
' set background material to pec
Call T_Background_PEC
' set boundary conditions to electric
Call T_Boundary_Electric
Call T_MeshMinimumCurvatureRefinement(150)

NP=1001

ReDim FREQ(NP),AV(NP),AH(NP),PV(NP),PH(NP)
Dim GOAL_FUNCTION As Double

Open CST_Parameters For Input As 1
Input#1, H0
Input#1,DH01
Input#1,DH02
Input#1,DH03
Input#1,DH04
Input#1,DH05
Input#1,DH06
Input#1,DH07
Input#1,DH08
Input#1,SW
Close 1

Open CST_Constants For Input As 11
Input#11,TW
Input#11,RCYL_IN
Input#11,RCYL_OUT
Input#11,LCYL
Input#11,NMODES
Input#11,FMIN
Input#11,FMAX
Input#11,RatioLimit
Input#11,LinesPerWavelength
Input#11,MinimumStepNumber
Input#11,SteadyStateLimit
Input#11,ZPORT
Close 11

FMID=(FMIN+FMAX)/2

H1=-(H0+DH01)
H2=-(H0+DH02)
H3=-(H0+DH03)
H4=-(H0+DH04)
H5=-(H0+DH05)
H6=-(H0+DH06)
H7=-(H0+DH07)
H8=-(H0+DH08)
PW=TW+SW

STOREDOUBLEPARAMETER("H0",Str$(H0))
STOREDOUBLEPARAMETER("H1",Str$(H1))
STOREDOUBLEPARAMETER("H2",Str$(H2))
STOREDOUBLEPARAMETER("H3",Str$(H3))
STOREDOUBLEPARAMETER("H4",Str$(H4))
STOREDOUBLEPARAMETER("H5",Str$(H5))
STOREDOUBLEPARAMETER("H6",Str$(H6))
STOREDOUBLEPARAMETER("H7",Str$(H7))
STOREDOUBLEPARAMETER("H8",Str$(H8))
STOREDOUBLEPARAMETER("SW",Str$(SW))

STOREDOUBLEPARAMETER("TW",Str$(TW))
STOREDOUBLEPARAMETER("RCYL_IN",Str$(RCYL_IN))
STOREDOUBLEPARAMETER("RCYL_OUT",Str$(RCYL_OUT))
STOREDOUBLEPARAMETER("LCYL",Str$(LCYL))
STOREDOUBLEPARAMETER("NMODES",Str$(NMODES))


Call T_Define_Frequency_Range(FMIN,FMAX)

Call T_Add_Cylinder("Component1","Cylinder",RCYL_OUT,RCYL_IN,0.0,LCYL/2)

Call T_Switch_Working_Plane("false")

Call T_Pick_PickCircleCenterFromID("Component1","Cylinder",1)

Call T_Align_WCS_with_Point

Call T_Activate_Local

Call T_Move_WCS("local",0.0,RCYL_OUT,0.0)

Call T_Move_WCS("local",0.0,0.0,SW/2)

Call T_Brick("BRICK1","Component1","Vacuum",-RCYL_OUT, RCYL_OUT,H1,0.,0., TW)

Call T_Move_WCS("local",0.0,0,PW)

Call T_Brick("BRICK2","Component1","Vacuum",-RCYL_OUT, RCYL_OUT,H2,0.,0., TW)

Call T_Move_WCS("local",0.0,0,PW)

Call T_Brick("BRICK3","Component1","Vacuum",-RCYL_OUT, RCYL_OUT,H3,0.,0., TW)

Call T_Move_WCS("local",0.0,0,PW)

Call T_Brick("BRICK4","Component1","Vacuum",-RCYL_OUT, RCYL_OUT,H4,0.,0., TW)

Call T_Move_WCS("local",0.0,0,PW)

Call T_Brick("BRICK5","Component1","Vacuum",-RCYL_OUT, RCYL_OUT,H5,0.,0., TW)

Call T_Move_WCS("local",0.0,0,PW)

Call T_Brick("BRICK6","Component1","Vacuum",-RCYL_OUT, RCYL_OUT,H6,0.,0., TW)

Call T_Move_WCS("local",0.0,0,PW)

Call T_Brick("BRICK7","Component1","Vacuum",-RCYL_OUT, RCYL_OUT,H7,0.,0., TW)

Call T_Move_WCS("local",0.0,0,PW)

Call T_Brick("BRICK8","Component1","Vacuum",-RCYL_OUT, RCYL_OUT,H8,0.,0., TW)

Call T_Boolean_Add("BRICK1","BRICK2","Component1")
Call T_Boolean_Add("BRICK1","BRICK3","Component1")
Call T_Boolean_Add("BRICK1","BRICK4","Component1")
Call T_Boolean_Add("BRICK1","BRICK5","Component1")
Call T_Boolean_Add("BRICK1","BRICK6","Component1")
Call T_Boolean_Add("BRICK1","BRICK7","Component1")
Call T_Boolean_Add("BRICK1","BRICK8","Component1")

Call T_Activate_Global

Call T_Transform("Component1","BRICK1","Free",0.0, 0.0, 0.0,0,-1,0 ,"True","False",1,"false","","","MirrorAdvanced")
Call T_Boolean_Add("BRICK1","BRICK1_1","Component1")
Call T_Insert("Cylinder","BRICK1","Component1")
Call T_Delete("BRICK1","Component1")


Call T_Transform_Whole_Component("Component1","Cylinder","Free",0.0, 0.0, 0.0,0,0,-1 ,"True","False",1,"False","","","MirrorAdvanced")

Call T_Boolean_Add("Cylinder","Cylinder_1","Component1")

Call T_PORT(1,5,45,0,50,"Free","zmax","True","False",-RCYL_OUT,RCYL_OUT,-RCYL_OUT,RCYL_OUT,-LCYL/2,-LCYL/2,0.0,0.0,0.0,0.0,0.0,0.0)
NPORTS=NPORTS+1
Call T_PORT(2,5,45,0,50,"Free","zmin","True","False",-RCYL_OUT,RCYL_OUT,-RCYL_OUT,RCYL_OUT,LCYL/2,LCYL/2,0.0,0.0,0.0,0.0,0.0,0.0)
NPORTS=NPORTS+1

ReDim AMP(NPORTS,NMODES),PHASE(NPORTS,NMODES),YES_NO(NPORTS,NMODES)
For I=1 To NPORTS
For J=1 To NMODES
AMP(I,J)=1
PHASE(I,J)=0
YES_NO(I,J)=False
Next J
Next I
YES_NO(1,2)=True

Call T_Solver("False","True" ,"1(2)[1.0,0.0]" ,FMID ,2 ,5 ,AMP,PHASE,YES_NO)

'====================== SAVE FILE AS =========================
SaveAs (CST_FILE,True)
'=============================================================
Call T_Mesh("True",RatioLimit,LinesPerWavelength,MinimumStepNumber,"True","PBA")

Call T_Solver_Run("TD-S","Selected","All", SteadyStateLimit,"False","False",ZPORT,"False","False","False","False")

'===============================================================
Debug.Print "RES1 : ";RES1

Open RES1 For Input As 1
Call Read_Results(1,FREQ,AV,NP)
Close 1
Open RES2 For Input As 2
Call Read_Results(2,FREQ,AH,NP)
Close 2
Open RES3 For Input As 3
Call Read_Results(3,FREQ,PV,NP)
Close 3
Open RES4 For Input As 4
Call Read_Results(4,FREQ,PH,NP)
Close 4
GOAL_FUNCTION=-10^33
For J=1 To NP
Delta_phase_deg=Abs(PV(J)-PH(J))
Delta_phase_rad=Delta_phase_deg*3.1416/180
AAHH=AH(J)
AAVV=AV(J)
OA=AAHH^2+AAVV^2+(AAHH^4+AAVV^4+2*AAHH^2*AAVV^2*Cos(2*Delta_phase_rad))^0.5
OB=AAHH^2+AAVV^2-(AAHH^4+AAVV^4+2*AAHH^2*AAVV^2*Cos(2*Delta_phase_rad))^0.5
AR_dB=10*Log(OA/OB)/Log(10)
If GOAL_FUNCTION<AR_dB Then
GOAL_FUNCTION=AR_dB
End If
Next J

Open CST_Goal_Function For Output As 11
Print#11,Str(GOAL_FUNCTION)
Close 11
StoreParameter("Goal_Function",Str$(GOAL_FUNCTION))
'===============================================================
End Sub
Public Sub Read_Results(I,FREQUENCY,GANIE,NP)
Dim XXX,YYY As Double
Line Input#I,T$
Line Input#I,T$
Line Input#I,T$
Line Input#I,T$
For K=1 To NP
Input#I,T$
NL=Len(T$)
FREQUENCY(K)=Val(Mid(T$,1,Int(NL/2)))
GANIE(K)=Val(Mid(T$,Int(NL/2)+1,NL))
Next K
End Sub
Public Sub T_Units(A$,B$,C$)
TEMP=""
TEMP = "With Units" + vbCrLf + _
" .Geometry "+Q$+A$+Q$+ vbCrLf + _
" .Frequency "+Q$+B$+Q$+ vbCrLf + _
" .Time "+Q$+C$+Q$+ vbCrLf + _
"End With"
Debug.Print TEMP
AddtoHistory("Define Units", TEMP)
End Sub

Public Sub T_Background_PEC
TEMP=""
TEMP = "With Background" + vbCrLf + _
" .Type ""pec"" "+ vbCrLf + _
" .XminSpace ""0.0"" "+ vbCrLf + _
" .XmaxSpace ""0.0"" "+ vbCrLf + _
" .YminSpace ""0.0"" "+ vbCrLf + _
" .YmaxSpace ""0.0"" "+ vbCrLf + _
" .ZminSpace ""0.0"" "+ vbCrLf + _
" .ZmaxSpace ""0.0"" "+ vbCrLf + _
"End With"
Debug.Print TEMP
AddtoHistory("Define Background PEC", TEMP)
End Sub
Public Sub T_Boundary_Electric
TEMP=""
TEMP = "With Boundary" + vbCrLf + _
" .Xmin ""electric"" "+ vbCrLf + _
" .Xmax ""electric"" "+ vbCrLf + _
" .Ymin ""electric"" "+ vbCrLf + _
" .Ymax ""electric"" "+ vbCrLf + _
" .Zmin ""electric"" "+ vbCrLf + _
" .Zmax ""electric"" "+ vbCrLf + _
" .Xsymmetry ""none"" "+ vbCrLf + _
" .Ysymmetry ""none"" "+ vbCrLf + _
" .Zsymmetry ""none"" "+ vbCrLf + _
"End With"
Debug.Print TEMP
AddtoHistory("Define Boundary Electric", TEMP)
End Sub
Public Sub T_MeshMinimumCurvatureRefinement(N)
TEMP=""
TEMP = "Mesh.MinimumCurvatureRefinement "+Q$+Str$(N)+Q$
Debug.Print TEMP
AddtoHistory("MeshMinimumCurvatureRefinement", TEMP)
End Sub
Public Sub T_FrequencyRange
TEMP="Solver.FrequencyRange "+C$+"17.5"+C$+","+C$+C$+ "21.5"+C$
Debug.Print TEMP
AddtoHistory("FrequencyRange", TEMP)
End Sub
Public Sub NewComponent
TEMP="Component.New ""component1"" "
Debug.Print TEMP
AddtoHistory("NewComponent", TEMP)
End Sub
Public Sub T_Add_Cylinder(CCOMPONENT,CNAME,ROUT,RIN,Z1,Z2)
TEMP=""
TEMP=TEMP+"With Cylinder" + vbCrLf
TEMP=TEMP+ " .Reset" + vbCrLf
TEMP=TEMP+" .Name "+Q$+CNAME+Q$+" "+ vbCrLf
TEMP=TEMP+" .Component "+Q$+CCOMPONENT+Q$+" "+ vbCrLf
TEMP=TEMP+" .Material ""Vacuum"" "+ vbCrLf
TEMP=TEMP+" .OuterRadius "+Q$+Str$(RCYL_OUT)+Q$ + vbCrLf
TEMP=TEMP+" .InnerRadius "+Q$+Str$(RCYL_IN)+Q$ + vbCrLf
TEMP=TEMP+" .Axis ""z"" "+ vbCrLf
TEMP=TEMP+" .Zrange "+Q$+Str$(Z1)+Q$+","+Q$+Str$(Z2)+Q$ + vbCrLf
TEMP=TEMP+" .Xcenter "+Q$+Str$(0.0)+Q$+ vbCrLf
TEMP=TEMP+" .Ycenter "+Q$+Str$(0.0)+Q$ + vbCrLf
TEMP=TEMP+" .Segments "+Str$(0.0) + vbCrLf
TEMP=TEMP+" .Create" + vbCrLf
TEMP=TEMP+"End With"
Debug.Print TEMP
AddtoHistory("Add_Cylinder", TEMP)
End Sub
Public Sub T_PlotDrawingplane
TEMP="Plot.DrawWorkplane "+Q$+ "false"+Q$
Debug.Print TEMP
AddtoHistory("Plot_DrawWorkplane", TEMP)
End Sub
Public Sub T_PickPickCirclecenterFromId(CCOMPONENT,CNAME,NFACE)
TEMP=" Pick.PickCirclecenterFromId "+Q$+Str$(CCOMPONENT)+":"+CNAME+Q$+", "+Q$+Str$(NFACE)+Q$
Debug.Print TEMP
AddtoHistory("Pick_PickCirclecenterFromId", TEMP)
End Sub
Public Sub T_WCS_AlignwithSDelectedPoint
TEMP="WCS.AlignWCSWithSelectedPoint"
Debug.Print TEMP
AddtoHistory("WCS_AlignwithSDelectedPoint", TEMP)
End Sub
Public Sub T_MoveWCS(A$,B$,C$)
TEMP=" WCS.MoveWCS "+Q$+"LOCAL"+Q$+" , "+Q$+A$+Q$+","+Q$+B$+Q$+","+Q$+C$+Q$
Debug.Print TEMP
AddtoHistory("WCS_Move", TEMP)
End Sub
Public Sub T_RotateWCS(A$,B$)
TEMP="WCS.RotateWCS "+Q$+ A$+Q$+" , "+Q$+B$+Q$
Debug.Print TEMP
AddtoHistory("WCS_Rotate", TEMP)
End Sub
Public Sub T_Brick(A$,B$,C$,D$, EE,FF,GG,HH,II)
E$=Str$(EE):F$=Str$(FF):G$=Str$(GG):H$=Str$(HH):I$=Str$(II)
TEMP="With Brick "+ vbCrLf + _
" .Reset "+ vbCrLf + _
" .Name "+Q$+A$+Q$+ vbCrLf + _
" .Component "+Q$+B$+Q$+ vbCrLf + _
" .Material "+Q$+C$+Q$+ vbCrLf+ _
" .Xrange "+Q$+D$+Q$+" , "+Q$+E$+Q$+vbCrLf+ _
" .Yrange "+Q$+F$+Q$+" , "+Q$+G$+Q$+vbCrLf+ _
" .Zrange "+Q$+H$+Q$+" , "+Q$+I$+Q$+vbCrLf+ _
" .Create "+ vbCrLf+ _
"End With"
Debug.Print TEMP
AddtoHistory("Add_"+A$, TEMP)
End Sub
Public Sub T_BooleanAdd(A$,B$,C$)
TEMP="Solid.Add "+Q$+C$+":"+A$+Q$+", "+Q$+C$+":"+B$+Q$
Debug.Print TEMP
AddtoHistory("BooleanAdd", TEMP)
End Sub
Public Sub T_ActivateLocal
TEMP="WCS.ActivateWCS"+Q$+ "local"+Q$
Debug.Print TEMP
AddtoHistory("ActivateLocal", TEMP)
End Sub
Public Sub T_ActivateGlobal
TEMP="WCS.ActivateWCS"+Q$+ "Global"+Q$
Debug.Print TEMP
AddtoHistory("ActivateLocal", TEMP)
End Sub
Public Sub T_Transform(CCOMPONENT,CNAME,ORIG,XC, YC, ZC,PNX,PNY,PNZ ,MOBJECTS,GOBJECTS,NREP,MREP,XCOMP,XMAT,TTYPE)
TEMP="With Transform"+vbCrLf
TEMP=TEMP+" .Reset"+vbCrLf
TEMP=TEMP+" .Name "+Q$+CCOMPONENT+":"+CNAME+Q$+vbCrLf
TEMP=TEMP+" .Origin "+Q$+ORIG+Q$+vbCrLf
TEMP=TEMP+" .Center "+Q$+XC+Q$+","+Q$+YC+Q$+","+Q$+ZC+Q$+vbCrLf
TEMP=TEMP+" .PlaneNormal "+Q$+PNX+Q$+","+Q$+PNY+Q$+","+Q$+PNZ+Q$+vbCrLf
TEMP=TEMP+" .MultipleObjects "+Q$+MOBJECTS+Q$+vbCrLf
TEMP=TEMP+" .GroupObjects "+Q$+GOBJECTS+Q$+vbCrLf
TEMP=TEMP+" .Repetitions "+Q$+NREP+Q$+vbCrLf
TEMP=TEMP+" .MultipleSelection "+Q$+MREP+Q$+vbCrLf
TEMP=TEMP+" .Component "+Q$+XCOMP+Q$+vbCrLf
TEMP=TEMP+" .Material "+Q$+XMAT+Q$+vbCrLf
TEMP=TEMP+" ."+TTYPE+vbCrLf
TEMP=TEMP+"End With"+vbCrLf
Debug.Print TEMP
AddtoHistory("Transform", TEMP)
End Sub
Public Sub T_Transform_Whole_Component(CCOMPONENT,COBJ,ORIG,XC, YC, ZC,PNX,PNY,PNZ ,MOBJECTS,GOBJECTS,NREP,MREP,XCOMP,XMAT,TTYPE)
TEMP= "With Transform"+vbCrLf
TEMP=TEMP+" .Reset"+vbCrLf
TEMP=TEMP+" .Name "+Q$+CCOMPONENT+":"+COBJ+Q$+vbCrLf
TEMP=TEMP+" .Origin "+Q$+ORIG+Q$+vbCrLf
TEMP=TEMP+" .Center "+Q$+XC+Q$+","+Q$+YC+Q$+","+Q$+ZC+Q$+vbCrLf
TEMP=TEMP+" .PlaneNormal "+Q$+PNX+Q$+","+Q$+PNY+Q$+","+Q$+PNZ+Q$+vbCrLf
TEMP=TEMP+" .MultipleObjects "+Q$+MOBJECTS+Q$+vbCrLf
TEMP=TEMP+" .GroupObjects "+Q$+GOBJECTS+Q$+vbCrLf
TEMP=TEMP+" .Repetitions "+Q$+NREP+Q$+vbCrLf
TEMP=TEMP+" .MultipleSelection "+Q$+MREP+Q$+vbCrLf
TEMP=TEMP+" .Component "+Q$+XCOMP+Q$+vbCrLf
TEMP=TEMP+" .Material "+Q$+XMAT+Q$+vbCrLf
TEMP=TEMP+" ."+TTYPE+vbCrLf
TEMP=TEMP+"End With"+vbCrLf
Debug.Print TEMP
AddtoHistory("Transform Whole Component", TEMP)
End Sub
Public Sub T_Define_Frequency_Range(F1,F2)
TEMP=""
TEMP="Solver.FrequencyRange "+Q$+Str$(F1)+Q$+" , "+Q$+Str$(F2)+Q$
AddtoHistory("Define Frequency Range", TEMP)
End Sub
Public Sub T_NewComponent(S$)
TEMP=""
TEMP="Component.New "+Q$+S$+Q$
AddtoHistory("New Component", TEMP)
Debug.Print TEMP
End Sub
Public Sub T_Switch_Working_Plane(YN)
TEMP=""
TEMP="Plot.DrawWorkplane "+Q$+YN+Q$
Debug.Print TEMP
AddtoHistory("Switch Working Plane", TEMP)
End Sub
Public Sub T_Pick_PickCircleCenterFromID(A$,B$,X)
TEMP="Pick.PickCirclecenterFromId "+Q$+A$+":"+B$+Q$+", "+Q$+Str$(X)+Q$
Debug.Print TEMP
AddtoHistory("Pick.PickCirclecenterFromId", TEMP)
End Sub
Public Sub T_Pick_PickFaceFromId(A$,B$,X)
TEMP="Pick.PickFaceFromId "+Q$+A$+":"+B$+Q$+", "+Q$+Str$(X)+Q$
Debug.Print TEMP
AddtoHistory("Pick.PickCirclecenterFromId", TEMP)
End Sub
Public Sub T_Align_WCS_with_Point
TEMP="WCS.AlignWCSWithSelectedPoint"
Debug.Print TEMP
AddtoHistory("WCS.AlignWCSWithSelectedPoint", TEMP)
End Sub
Public Sub T_Move_WCS(A$,DX,DY,DZ)
TEMP="WCS.MoveWCS "+Q$+A$+Q$+", "+Q$+Str$(DX)+Q$+", "+Q$+Str$(DY)+Q$+", "+Q$+Str$(DZ)+Q$
Debug.Print TEMP
AddtoHistory("WCS.MoveWCS", TEMP)
End Sub
Public Sub T_Rotate_WCS(A$,ANGLE)
TEMP="WCS.RotateWCS "+Q$+A$+Q$+", "+Q$+Str$(ANGLE)+Q$
Debug.Print TEMP
AddtoHistory("WCS.RotateWCS", TEMP)
End Sub
Public Sub T_Activate_Local
TEMP="WCS.ActivateWCS"+Q$+ "local"+Q$
Debug.Print TEMP
AddtoHistory("ActivateLocal", TEMP)
End Sub
Public Sub T_Boolean_Add(A$,B$,C$)
v$=Q$+C$+":"+A$+Q$+", "+Q$+C$+":"+B$+Q$
TEMP="Solid.Add "+Q$+C$+":"+A$+Q$+", "+Q$+C$+":"+B$+Q$
Debug.Print TEMP
AddtoHistory("Boolean_Add", TEMP)
End Sub
Public Sub T_Activate_Global
TEMP="WCS.ActivateWCS"+Q$+ "Global"+Q$
Debug.Print TEMP
AddtoHistory("Activate_Global", TEMP)
End Sub
Public Sub T_Insert(A$,B$,C$)
TEMP="Solid.Insert "+Q$+C$+":"+A$+Q$+" , "+Q$+C$+":"+B$+Q$
Debug.Print TEMP
AddtoHistory("Insert Component", TEMP)
End Sub
Public Sub T_Delete(A$,C$)
TEMP="Solid.Delete "+Q$+C$+":"+A$+Q$
Debug.Print TEMP
AddtoHistory("Delete Component", TEMP)
End Sub
Public Sub T_PORT(PN,NMODES,POL_ANGLE,REFPLANEDIST,TEXTSIZE,COORDINATES,ORIENTATION,PORTONBOUND,CLIPPICKED,XMIN,XMAX,YMIN,YMAX,ZMIN,ZMAX,XRADDMIN,XRADDMAX,YRADDMIN,YRADDMAX,ZRADDMIN,ZRADDMAX)
TEMP=""
TEMP=TEMP+"With Port"+vbCrLf
TEMP=TEMP+" .Reset"+vbCrLf
TEMP=TEMP+" .PortNumber "+Q$+Str$(PN)+Q$+vbCrLf
TEMP=TEMP+" .NumberOfModes "+Q$+Str$(NMODES)+Q$+vbCrLf
TEMP=TEMP+" .AdjustPolarization True"+vbCrLf
TEMP=TEMP+" .PolarizationAngle "+Q$+Str$(POL_ANGLE)+Q$+vbCrLf
TEMP=TEMP+" .ReferencePlaneDistance "+Q$+Str$(REFPLANEDIST)+Q$+vbCrLf
TEMP=TEMP+" .TextSize "+Q$+Str$(TEXTSIZE)+Q$+vbCrLf
TEMP=TEMP+" .Coordinates "+Q$+COORDINATES+Q$+vbCrLf
TEMP=TEMP+" .Orientation "+Q$+ORIENTATION+Q$+vbCrLf
TEMP=TEMP+" .PortOnBound "+Q$+PORTONBOUND+Q$+vbCrLf
TEMP=TEMP+" .ClipPickedPortToBound "+Q$+CLIPPICKED+Q$+vbCrLf
TEMP=TEMP+" .Xrange "+Q$+Str$(XMIN)+Q$+" , "+Q$+Str$(XMAX)+Q$+vbCrLf
TEMP=TEMP+" .Yrange "+Q$+Str$(YMIN)+Q$+" , "+Q$+Str$(YMAX)+Q$+vbCrLf
TEMP=TEMP+" .Zrange "+Q$+Str$(ZMIN)+Q$+" , "+Q$+Str$(ZMAX)+Q$+vbCrLf
TEMP=TEMP+" .XrangeAdd "+Q$+XRADDMIN+Q$+" , "+Q$+Str$(XRADDMAX)+Q$+vbCrLf
TEMP=TEMP+" .YrangeAdd "+Q$+YRADDMIN+Q$+" , "+Q$+Str$(YRADDMAX)+Q$+vbCrLf
TEMP=TEMP+" .ZrangeAdd "+Q$+ZRADDMIN+Q$+" , "+Q$+Str$(ZRADDMAX)+Q$+vbCrLf
TEMP=TEMP+" .Create"+vbCrLf
TEMP=TEMP+"End With"
Debug.Print TEMP
AddtoHistory("Add_Port_"+Str$(PN), TEMP)
End Sub
Public Sub T_Solver(SIM_EX,AUTOLEBEL,EXCITATION_LABEL,PHASEREF_FREQ,XNPORTS,NMODES,AMP,PHASE,YES_NO)
TEMP=""
TEMP=TEMP+"With Solver"+vbCrLf
TEMP=TEMP+" .ResetExcitationModes "+vbCrLf
TEMP=TEMP+" .SimultaneousExcitation "+Q$+SIM_EX+Q$+vbCrLf
TEMP=TEMP+" .SetSimultaneousExcitAutoLabel "+Q$+AUTOLEBEL+Q$+vbCrLf
TEMP=TEMP+" .SetSimultaneousExcitationLabel "+Q$+EXCITATION_LABEL+Q$+vbCrLf
TEMP=TEMP+" .SetSimultaneousExcitationOffset "+Q$+"Timedelay"+Q$+vbCrLf
TEMP=TEMP+" .PhaseRefFrequency "+Q$+LTrim(Str$(PHASEREF_FREQ))+Q$+vbCrLf
For I=1 To XNPORTS
For J=1 To NMODES
TEMP=TEMP+" .ExcitationPortMode "+Q$+LTrim(Str$(I))+Q$+" , "+Q$+LTrim(Str$(J))+Q$+" , "+Q$+Format$(Str$(AMP(I,J)),"0.0")+Q$+" , "+Q$+Format$(Str$(PHASE(I,J)),"0.0")+Q$+" ,"+Q$+"default"+Q$+", "+Q$+LTrim(Str$(YES_NO(I,J)))+Q$+vbCrLf
Next J
Next I
TEMP=TEMP+"End With"
Debug.Print TEMP
AddtoHistory("Solver", TEMP)
End Sub
Public Sub T_Mesh(UseRatioLimit,RatioLimit,LinesPerWavelength,MinimumStepNumber,Automesh,MeshType)
TEMP=""
TEMP=TEMP+"With Mesh"+vbCrLf
TEMP=TEMP+" .UseRatioLimit "+Q$+UseRatioLimit+Q$+vbCrLf
TEMP=TEMP+" .RatioLimit "+Q$+LTrim(Str$(RatioLimit))+Q$+vbCrLf
TEMP=TEMP+" .LinesPerWavelength "+Q$+LTrim(Str$(LinesPerWavelength))+Q$+vbCrLf
TEMP=TEMP+" .MinimumStepNumber "+Q$+LTrim(Str$(MinimumStepNumber))+Q$+vbCrLf
TEMP=TEMP+" .Automesh "+Q$+Automesh+Q$+vbCrLf
TEMP=TEMP+" .MeshType "+Q$+MeshType+Q$+vbCrLf
TEMP=TEMP+"End With"
Debug.Print TEMP
AddtoHistory("Mesh", TEMP)
End Sub
Public Sub T_Solver_Run(CalculationType,StimulationPort,StimulationMode, SteadyStateLimit,MeshAdaption,AutoNormImpedance,NormingImpedance,CalculateModesOnly,SParaSymmetry,StoreTDResultsInCache,FullDeembedding)
TEMP=""
TEMP=TEMP+"With Solver"+vbCrLf
TEMP=TEMP+" .CalculationType "+Q$+CalculationType+Q$+vbCrLf
TEMP=TEMP+" .StimulationPort "+Q$+StimulationPort+Q$+vbCrLf
TEMP=TEMP+" .StimulationMode "+Q$+StimulationMode+Q$+vbCrLf
TEMP=TEMP+" .SteadyStateLimit "+Q$+LTrim(Str$(SteadyStateLimit))+Q$+vbCrLf
TEMP=TEMP+" .MeshAdaption "+Q$+MeshAdaption+Q$+vbCrLf
TEMP=TEMP+" .AutoNormImpedance "+Q$+AutoNormImpedance+Q$+vbCrLf
TEMP=TEMP+" .NormingImpedance "+Q$+LTrim(Str$(NormingImpedance))+Q$+vbCrLf
TEMP=TEMP+" .CalculateModesOnly "+Q$+CalculateModesOnly+Q$+vbCrLf
TEMP=TEMP+" .SParaSymmetry "+Q$+SParaSymmetry+Q$+vbCrLf
TEMP=TEMP+" .StoreTDResultsInCachee "+Q$+StoreTDResultsInCache+Q$+vbCrLf
TEMP=TEMP+" .FullDeembedding "+Q$+FullDeembedding+Q$+vbCrLf
TEMP=TEMP+" .start "+vbCrLf
TEMP=TEMP+"End With"
Debug.Print TEMP
AddtoHistory("Solver_Run", TEMP)
End Sub
 
Top Handeling Parameters
  Sub Main
Dim Vax As Double
Dim n As Long
'c$=GetFilePath$("george.txt")
c$="C:\TDATA\AFRL\ST-AFRL\[14] OPTIMIZATION - VB\20080122_0724AM_SWARM\CST_FRAG\george1.txt"
Open c$ For Output As 1
n=getNumberOfParameters
Debug.Print n
For i=1 To n
a$=GetParameterName(i)
Vax=GetParameterNValue(i)
s$=GetParameterSValue(i)
x$=Format$(i,"##00")+" " + a$+" " + LTrim(RTrim(Str$(Vax)))+ " " +s$
Print#1,x$
Debug.Print x$
Next i
Close 1
End Sub

Parameter Handling

DeleteParameter ( string name ) - Deletes an existing parameter with the specified name.

GetNumberOfParameters long - Returns the number of parameters defined so far.

GetParameterName ( long index ) string  - Returns the name of the parameter referenced by the given index. The first parameter is reference by the index 0.

GetParameterNValue ( long index ) double - Returns the value of the double parameter referenced by the given index. The first parameter is referenced by the index 0.

GetParameterSValue ( long index ) string - Returns the numerical expression for the parameter referenced by the given index. The first parameter is referenced by the index 0.

RestoreParameter ( string name ) string  - Gets the value of the specified string parameter.

RestoreDoubleParameter ( string name ) double  - Gets the value of a specified double parameter.

RestoreParameterExpression ( string name ) string  - Gets the numerical expression for the specified string parameter.

StoreParameter ( string name, string value ) - Creates a new string parameter or changes an existing one, with the specified string value.

StoreDoubleParameter ( string name, double value ) - Creates a new double parameter or changes an existing one, with the specified double value.

SetParameterDescription ("Fmin", "Lowest Frequency" )

Example: StoreDoubleParameter ( "test", 100.22 )

TOP CREATE SYMMETRY BUILD POLYLINE
  Sub symmetry()
'
' symmetry Macro
' Macro recorded 2/2/2008 by AFRL User
'
'
n = 10 'half number in a row
k = 0
For i = 1 To n
For j = i To n
k = k + 1
'A$ = "(" + Str$(i) + " ," + Str$(j) + ")"
a$ = Str$(k)
Cells(i, j).Value = a$ 'top left
Cells(n + n - i + 1, j).Value = a$ 'bottom left
Cells(n + n - i + 1, n + n - j + 1).Value = a$ 'bottom right
Cells(i, n + n - j + 1).Value = a$ 'top right

Cells(j, i).Value = Cells(i, j).Value ' top left
Cells(j, n + n - i + 1).Value = Cells(n + n - i + 1, j).Value
Cells(n + n - j + 1, n + n - i + 1).Value = Cells(n + n - i + 1, n + n - j + 1).Value
Cells(n + n - j + 1, i).Value = Cells(i, n + n - j + 1).Value
Next j
Next i

End Sub
Public Sub T_Create_Polyline(pname, cname, xp, yp, n)
Q$ = Chr$(34)
temp = "Component.New " + Q$ + "component1" + Q$ + vbCrLf
temp = temp + "Curve.NewCurve " + Q$ + "curve1" + Q$ + vbCrLf
Debug.Print temp
temp = temp + "With Polygon" + vbCrLf
temp = temp + " .Reset" + vbCrLf
temp = temp + " .Name " + Q$ + pname + Q$ + vbCrLf
temp = temp + " .Curve " + Q$ + cname + Q$ + vbCrLf
For i = 1 To n
temp = temp + ".LineTo " + Q$ + LTrim(Str$(xp(i))) + Q$ + " ," + Q$ + LTrim(Str$(yp(i))) + Q$ + vbCrLf
Next i
temp = temp + " .Create" + vbCrLf
temp = temp + "End With"
Debug.Print temp
AddtoHistory("Add_Line", temp)
End Sub
 
TOP Save project list of parameter CST TIME/DATE FUNCTIONS
  Sub Main
Dim Vax As Double
Dim n As Long
Dim cst_filename
'c$=GetFilePath$("george.txt")
cst_filename = GetProjectPath("Root")
c$=cst_filename+"_george4.txt"
Debug.Print c$
Open c$ For Output As 1
n=getNumberOfParameters
Debug.Print n
For i=1 To n
A$=GetParameterName(i)
z$=RTrim(LTrim(A$))
Debug.Print z$
Vax=GetParameterNValue(i)
s$=GetParameterSValue(i)
x$=I_(i,3)+" " + RTrim(LTrim(A$))+" " + F_(Vax,10,3)+ " " +RTrim(LTrim(s$))
Print#1,x$
Debug.Print x$
Next i
Close 1
End Sub
a=Timer
Debug.Print a
For i=1 To 100001
'Debug.Print i
Next i
b=Timer
Debug.Print b
Debug.Print b-a
c=now
debug.print c
Z_TO_GAMMA
DENO=Z0^2+2*Real_Z*Z0+Imag_Z^2+Real_Z^2
GAMMA_R=-(Z0^2-Imag_Z^2-Real_Z^2)/(Z0^2+2*Real_Z*Z0+Imag_Z^2+Real_Z^2)/DENO
GAMMA_I=2*Imag_Z*Z0/(Z0^2+2*Real_Z*Z0+Imag_Z^2+Real_Z^2)/DENO
Rebuild
Recreates the structure by processing the History List . All results will be deleted.

RebuildForParametricChange

Updates the structure after parametric changes have been made by processing the History List.
Results which should survive parametric changes will be kept, all other results will be deleted.
 
Public Sub T_Add_3DPolygon(Curve_name,Polygon_name,XX,YY,ZZ,Nmax)
Q$=Chr$(34)
XX(0)=XX(Nmax)
ZZ(0)=ZZ(Nmax)
temp=""
temp=temp+"With Polygon3D"+ vbCrLf
temp=temp+" .Reset"+ vbCrLf
temp=temp+" .Name "+Q$+Polygon_name+Q$+ vbCrLf
temp=temp+" .Curve "+Q$+Curve_name+Q$+ vbCrLf
temp=temp+" .Point "+Q$+LTrim(RTrim(Str$(XX(1))))+Q$+","+Q$+LTrim(RTrim(Str$(YY(1))))+Q$+","+Q$+LTrim(RTrim(Str$(ZZ(1))))+Q$+ vbCrLf
For I=2 To Nmax
temp=temp+" .Point "+Q$+LTrim(RTrim(Str$(XX(I))))+Q$+","+Q$+LTrim(RTrim(Str$(YY(I))))+Q$+","+Q$+LTrim(RTrim(Str$(ZZ(i1))))+Q$+ vbCrLf
Next I
temp=temp+" .Create "+ vbCrLf
temp=temp+"End With"
Debug.Print temp
AddtoHistory("Add Polygon:"+Q$+Polygon_name+Q$, temp)
Debug.Print temp
End Sub
Public Sub T_Add_3DPolygon_Line_by_Line(Curve_name,XX,YY,ZZ,Nmax)
Q$=Chr$(34)
XX(0)=XX(Nmax)
ZZ(0)=ZZ(Nmax)
for i=1 to Nmax-1
Polygon_name="L"+ltrim(trim(str$(i)))
temp=""
temp=temp+"With Polygon3D"+ vbCrLf
temp=temp+" .Reset"+ vbCrLf
temp=temp+" .Name "+Q$+Polygon_name+Q$+ vbCrLf
temp=temp+" .Curve "+Q$+Curve_name+Q$+ vbCrLf
temp=temp+" .Point "+Q$+LTrim(RTrim(Str$(XX(i))))+Q$+","+Q$+LTrim(RTrim(Str$(YY(i))))+Q$+","+Q$+LTrim(RTrim(Str$(ZZ(i))))+Q$+ vbCrLf
temp=temp+" .Point "+Q$+LTrim(RTrim(Str$(XX(I+1))))+Q$+","+Q$+LTrim(RTrim(Str$(YY(i+1))))+Q$+","+Q$+LTrim(RTrim(Str$(ZZ(i+1))))+Q$+ vbCrLf
temp=temp+" .Create "+ vbCrLf
temp=temp+"End With"
Debug.Print temp
AddtoHistory("Add Polygon:"+Q$+Polygon_name+Q$, temp)
Debug.Print temp
next i
End Sub
TOP  
Sub Main
    a$=GetProjectPath("Root")
    Debug.Print a$
    a$=GetProjectPath("Project")
    Debug.Print a$
    a$=GetProjectPath("Model3D")
    Debug.Print a$
    a$=GetProjectPath("ModelCache")
    Debug.Print a$
    a$=GetProjectPath("Result")
    Debug.Print a$
    a$=GetProjectPath("Temp")
    Debug.Print a$
End Sub
 

 

 

NOTES

1) the macros path.
You can add the path first, and then create the sub folder by the name
"macros" under this path. Finally, you move all user macros to macros
folder. It will work.

2) parameters for the macro model

you can use parameters in the macro without "dim". When you run the
macro, the dialog box will popup for the value of this un defined
parameter. You can put the initial value then. It should be ok for
optimization. By the way, you need uncheck "Edit/fast model update" to
allow update the parameters during the optimization/parameter study.