Option Explicit '#include "vba_globals.lib" ' (CSTxMWSxONLY) ' ================================================================================================ ' Post Processing Template: 3D Eigenvalue result ' ' (C) 2004-2011 CST GmbH ' ================================================================================================ ' History of Changes ' ------------------ ' 10-May-2011 ube: voltage computation now also working for TET-Eigenmode Solver ' 10-May-2011 ube: switched from GetFieldvector To List-Evaluation (much quicker for IFX) ' 20-Oct-2010 fmo/ube: AutoConvert of old Eigenmodefreq goals did not work because of sLogFilename_CST = "" ' 14-Sep-2010 fsr/ube: multiple mode handling and default naming improved ' 08-Sep-2010 fsr: Adapted to new template structure ' 30-Jul-2010 ube: StoreTemplateSetting included ' 26-Mar-2010 fsr: transferred to 1D template from 0D template for multiple port modes ' 12-Sep-2008 rsj: included value Loaded Frequency according to loaded Q-value ' 27-Apr-2007 ube: adapted to 2008 ' 17-Feb-2007 ube: renamed "Total Loss (Perturbation)" into "Total Loss (Pert., Aver.)" ' 05-Feb-2007 ube: power loss is now stored as time averaged value = 0.5 * peak value ' shunt impedance was factor 2 too small , R/Q as well ' 26-Nov-2005 fde: loaded Q included ' 24-Nov-2005 ube: external Q included ' 24-Oct-2005 ube: Included into Online Help ' 27-May-2004 ube: Q-lossy Eigenmode included ' 25-May-2004 ube: bugfix R/Q was too big by factor 2, (frq-unit corrected) ' 08-Apr-2004 ube: first version ' ================================================================================================ ' ' *** global variables Dim a0DValue() As String Dim acoordinates() As String Dim uvwlabel(3,2) As String Dim iuvw As Integer Dim sLogFilename_CST As String, bLogFileFirstEval As Boolean 'Dim lib_rundef As Double = -1.2345e27 Public Const sAction =Array("Frequency","Q-Factor (Perturbation)", "Total Loss (Pert., Aver.)", "Total Energy", _ "R over Q", "Shunt Impedance", "Voltage", "Q-Factor (lossy Eigenmode)", "Q-Factor (external)", _ "Q-Factor (loaded)", "Loaded Frequency") Public Const CLight = 299792448 Private Function bVoltageNeeded(s1 As String) As Boolean bVoltageNeeded = True Select Case s1 Case "R over Q" Case "Shunt Impedance" Case "Voltage" Case Else bVoltageNeeded = False End Select End Function Private Function bPowerNeeded(s1 As String) As Boolean bPowerNeeded = True Select Case s1 Case "Q-Factor (Perturbation)" Case "Total Loss (Pert., Aver.)" Case "Shunt Impedance" Case Else bPowerNeeded = False End Select End Function Private Function DialogFunction(DlgItem$, Action%, SuppValue&) As Boolean ' ------------------------------------------------------------------------------------------------- ' DialogFunction: This function defines the dialog box behaviour. It is automatically called ' whenever the user changes some settings in the dialog box, presses any button ' or when the dialog box is initialized. ' ------------------------------------------------------------------------------------------------- If (Action% = 1 Or Action% = 2) Then If (DlgItem = "Help") Then StartHelp "common_preloadedmacro_0D_3D_Eigenmode_Result" DialogFunction = True End If Dim bPw As Boolean bPw = bPowerNeeded(a0DValue(DlgValue("a0DValue"))) DlgEnable "QInfo", IIf(bPw, 1, 0) Dim bVV As Boolean bVV = bVoltageNeeded(a0DValue(DlgValue("a0DValue"))) DlgEnable "GroupBox1", IIf(bVV, 1, 0) DlgEnable "Text3", IIf(bVV, 1, 0) DlgEnable "coordinates", IIf(bVV, 1, 0) DlgEnable "Sampling", IIf(bVV, 1, 0) DlgEnable "stepsize", IIf(bVV, 1, 0) DlgEnable "maxrange", IIf(bVV, 1, 0) DlgEnable "u1text", IIf(bVV, 1, 0) DlgEnable "v1text", IIf(bVV, 1, 0) DlgEnable "w1text", IIf(bVV, 1, 0) DlgEnable "u2text", IIf(bVV, 1, 0) DlgEnable "v2text", IIf(bVV, 1, 0) DlgEnable "w2text", IIf(bVV, 1, 0) DlgEnable "u1", IIf(bVV, 1, 0) DlgEnable "v1", IIf(bVV, 1, 0) DlgEnable "w1", IIf(bVV, 1, 0) DlgEnable "u2", IIf(bVV, 1, 0) DlgEnable "v2", IIf(bVV, 1, 0) DlgEnable "w2", IIf(bVV, 1, 0) DlgEnable "ttf", IIf(bVV, 1, 0) DlgEnable "tbeta", IIf(bVV, 1, 0) DlgEnable "beta", IIf(bVV, 1, 0) DlgEnable "Check_ttf", IIf(bVV, 1, 0) DlgEnable "DrawPoints", IIf(bVV, 1, 0) If bVV Then SetLabels DlgValue("coordinates") Dim iccc As Integer iccc = DlgValue("coordinates") DlgListBoxArray "coordinates", acoordinates DlgValue "coordinates", iccc DlgText "u1text", uvwlabel(1,1) DlgText "v1text", uvwlabel(2,1) DlgText "w1text", uvwlabel(3,1) DlgText "u2text", uvwlabel(1,2) DlgText "v2text", uvwlabel(2,2) DlgText "w2text", uvwlabel(3,2) DlgEnable "a0DValue", 1 DlgEnable "coordinates", 1 DlgEnable "Sampling", 1 DlgEnable "maxrange", 1 DlgEnable "u1", 1 DlgEnable "v1", 1 DlgEnable "w1", 1 DlgEnable "u2", 0 DlgEnable "v2", 0 DlgEnable "w2", 0 If DlgValue("maxrange") = 0 Then If DlgValue("coordinates") = 0 Then DlgEnable "u2", 1 If DlgValue("coordinates") = 1 Then DlgEnable "v2", 1 If DlgValue("coordinates") = 2 Then DlgEnable "w2", 1 Else If DlgValue("coordinates") = 0 Then DlgEnable "u1", 0 If DlgValue("coordinates") = 1 Then DlgEnable "v1", 0 If DlgValue("coordinates") = 2 Then DlgEnable "w1", 0 End If If DlgValue("Check_ttf") = 0 Then DlgText "beta", "not used" DlgEnable "beta", 0 DlgEnable "tbeta", 0 Else If DlgText("beta") = "not used" Then DlgText "beta", "1" DlgEnable "beta", 1 DlgEnable "tbeta", 1 End If End If Dim sTmpFile As String If (DlgItem = "PushLogfile") Then DialogFunction = True ' Don't close the dialog box. If (sLogFilename_CST <> "") Then sTmpFile = GetProjectPath("Result") + sLogFilename_CST + ".log" If Dir$(sTmpFile) <> "" Then Shell("notepad.exe " + sTmpFile, 1) Else MsgBox "Option is only available after evaluation.",vbInformation End If Else MsgBox "Option is only available after evaluation.",vbInformation End If End If If (DlgItem = "DrawPoints") Then DialogFunction = True ' Don't close the dialog box. If (sLogFilename_CST <> "") Then sTmpFile = GetProjectPath("Result") + sLogFilename_CST + ".xyz" If Dir$(sTmpFile) <> "" Then DrawXYZPickPoints sTmpFile, 1000 Else MsgBox "Option is only available after evaluation.",vbInformation End If Else MsgBox "Option is only available after evaluation.",vbInformation End If End If If (DlgItem = "OK") Then ' The user pressed the Ok button. Check the settings and display an error message if some required ' fields have been left blank. Dim beta As Double If (DlgValue("Check_ttf") = 1) Then beta = Evaluate(DlgText("beta")) If (beta <= 0 Or beta >1) Then MsgBox "invalid value for beta (=velocity/clight)"+vbCrLf + vbCrLf + "possible range: 0 < beta <= 1",vbExclamation DialogFunction = True End If Else ' for safety, although not used beta = 0 End If If (False) Then MsgBox "Please check and complete your settings.", vbCritical DialogFunction = True ' There is an error in the settings -> Don't close the dialog box. End If End If End If End Function Sub SetLabels (idir As Integer) FillArray acoordinates() , Array("X", "Y", "Z") FillArray a0DValue() , sAction For iuvw=1 To 3 If iuvw = idir+1 Then uvwlabel(iuvw,1) = acoordinates(iuvw-1) + "min:" uvwlabel(iuvw,2) = acoordinates(iuvw-1) + "max:" Else uvwlabel(iuvw,1) = acoordinates(iuvw-1) + ":" uvwlabel(iuvw,2) = "" End If Next iuvw End Sub Function Define(sName As String, bCreate As Boolean, bNameChanged As Boolean) As Boolean Define = True ' Initialize the global arrays first SetLabels 0 Begin Dialog UserDialog 420,301,"3D Eigenmode Result",.DialogFunction ' %GRID:10,7,1,1 Text 20,7,90,14,"Result value:",.Text2 DropListBox 20,21,220,203,a0DValue(),.a0DValue Text 270,7,140,14,"Modes: eg 1,3,5-10",.Text1 TextBox 270,21,90,21,.modesTT Text 20,49,380,14,"(Conductivity taken from Results->Loss and Q-Calculation...)",.QInfo GroupBox 10,70,400,196,"Voltage Integration Range",.GroupBox1 Text 20,84,90,14,"Direction:",.Text3 DropListBox 20,98,110,77,acoordinates(),.coordinates Text 20,126,120,14,"Stepsize (0=auto):",.Sampling TextBox 20,140,110,21,.stepsize CheckBox 30,182,100,14,"max. range",.maxrange Text 160,84,90,14,uvwlabel(1,1),.u1text Text 160,126,100,14,uvwlabel(2,1),.v1text Text 160,168,100,14,uvwlabel(3,1),.w1text Text 290,84,90,14,uvwlabel(1,2),.u2text Text 290,126,100,14,uvwlabel(2,2),.v2text Text 290,168,110,14,uvwlabel(3,2),.w2text TextBox 160,98,100,21,.u1 TextBox 290,98,100,21,.u2 TextBox 160,140,100,21,.v1 TextBox 290,140,100,21,.v2 TextBox 160,182,100,21,.w1 TextBox 290,182,100,21,.w2 GroupBox 20,210,380,49,"Transit Time Factor",.ttf CheckBox 40,233,160,14,"consider part.velocity",.Check_ttf Text 230,233,50,14,"beta =",.tbeta TextBox 280,231,100,21,.beta OKButton 10,273,70,21 CancelButton 90,273,70,21 PushButton 250,273,80,21,"DrawPoints",.DrawPoints PushButton 340,273,70,21,"Logfile...",.PushLogfile PushButton 170,273,70,21,"Help",.Help End Dialog Dim dlg As UserDialog dlg.modesTT = GetScriptSetting("ModeNumbers", "1") ' default=1 dlg.a0DValue = FindListIndex(a0DValue(), GetScriptSetting("Action","Frequency")) dlg.coordinates = CInt(GetScriptSetting("coordinates","0")) dlg.stepsize = GetScriptSetting("stepsize","0.0") dlg.maxrange = CInt(GetScriptSetting("maxrange","1")) dlg.u1 = GetScriptSetting("u1","0.0") dlg.v1 = GetScriptSetting("v1","0.0") dlg.w1 = GetScriptSetting("w1","0.0") dlg.u2 = GetScriptSetting("u2","0.0") dlg.v2 = GetScriptSetting("v2","0.0") dlg.w2 = GetScriptSetting("w2","0.0") dlg.Check_ttf = CInt(GetScriptSetting("Check_ttf","0")) dlg.beta = GetScriptSetting("beta","not used") SetLabels dlg.coordinates dlg.a0DValue=FindListIndex(a0DValue(), GetScriptSetting("a0DValue",a0DValue(0))) sLogFilename_CST = GetScriptSetting("sLogFilename_CST","") ' Show the dialog box If (Not Dialog(dlg)) Then ' The user left the dialog box without pressing Ok. Assigning False to the function ' will cause the framework to cancel the creation or modification without storing ' anything. Define = False Else ' The user properly left the dialog box by pressing Ok. Assigning True to the function ' will cause the framework to complete the creation or modification and store the corresponding ' settings. Define = True ' Convert the dialog data into strings in order to store them in the script settings database. ' Determine a proper name for the result item. Changing the name will cause the framework to use ' the modified name for the result item. If (Not bNameChanged) Then sName = sAction(dlg.a0DValue) If (dlg.Check_ttf = 1) And (bVoltageNeeded(sAction(dlg.a0DValue))) Then sName = sName + " beta=" + dlg.beta sName = NoForbiddenFilenameCharacters(sName) sName = Replace(sName,"lossy Eigenmode","lossy E") End If StoreScriptSetting("ModeNumbers", dlg.modesTT) StoreScriptSetting("Action",a0DValue(dlg.a0DValue)) StoreScriptSetting("coordinates",CStr(dlg.coordinates)) StoreScriptSetting("stepsize",CStr(dlg.stepsize)) StoreScriptSetting("maxrange",CStr(dlg.maxrange)) StoreScriptSetting("u1",CStr(dlg.u1)) StoreScriptSetting("v1",CStr(dlg.v1)) StoreScriptSetting("w1",CStr(dlg.w1)) StoreScriptSetting("u2",CStr(dlg.u2)) StoreScriptSetting("v2",CStr(dlg.v2)) StoreScriptSetting("w2",CStr(dlg.w2)) StoreScriptSetting("a0DValue",a0DValue(dlg.a0DValue)) StoreScriptSetting("coord1",acoordinates(0)) StoreScriptSetting("coord2",acoordinates(1)) StoreScriptSetting("coord3",acoordinates(2)) StoreScriptSetting("Check_ttf",CStr(dlg.Check_ttf)) StoreScriptSetting("beta",dlg.beta) If ((UBound(Split(dlg.modesTT,","))>0) Or (UBound(Split(dlg.modesTT,"-"))>0))Then StoreTemplateSetting("TemplateType","1D") sName = sName + " (Multiple Modes)" Else StoreTemplateSetting("TemplateType","0D") sName = sName + " (Mode " + dlg.modesTT + ")" End If End If End Function Function Evaluate0D() As Double bLogFileFirstEval = True Evaluate0D = CalculateEigenModeResult(Evaluate(GetScriptSetting("ModeNumbers","1"))) End Function Function Evaluate1D() As Object bLogFileFirstEval = True Dim i As Integer, j As Integer Dim sModeNumbers As String Dim iModeNumbers() As Integer Dim sModeNumbersSplit() As String Dim sModeNumbersSubSplit() As String Dim calculatedResult As Double Set Evaluate1D = Result1D("") calculatedResult = 0 sModeNumbers = GetScriptSetting("ModeNumbers", "1") ' default=1 ' parse string, split by commas first, then dashes sModeNumbersSplit() = Split(sModeNumbers,",") ReDim iModeNumbers(0) For i=0 To UBound(sModeNumbersSplit) sModeNumbersSubSplit = Split(sModeNumbersSplit(i),"-") For j=Evaluate(sModeNumbersSubSplit(LBound(sModeNumbersSubSplit))) To Evaluate(sModeNumbersSubSplit(UBound(sModeNumbersSubSplit))) ReDim Preserve iModeNumbers(UBound(iModeNumbers)+1) iModeNumbers(UBound(iModeNumbers)) = j Next Next For i=1 To UBound(iModeNumbers) calculatedResult = CalculateEigenModeResult(iModeNumbers(i)) If(calculatedResult <> lib_rundef) Then Evaluate1D.AppendXY(iModeNumbers(i), calculatedResult) bLogFileFirstEval = False Else ' Evaluate1D.AppendXY(iModeNumbers(i), -1) End If Next i End Function Function CalculateEigenModeResult(iModeNumber As Integer) As Double Mesh.ViewMeshMode False Dim s0DValue As String s0DValue = GetScriptSetting("a0DValue","Frequency") Dim q_cst As Double, pw_cst As Double, eng_cst As Double, frq_cst As Double, volt_cst As Double If (Not SelectTreeItem("2D/3D Results\Modes\Mode " + CStr(iModeNumber) + "\e")) Then ReportWarningToWindow("Error in 3D Eigenmode result template execution: Cannot find result for mode #"+CStr(iModeNumber)+".") CalculateEigenModeResult = lib_rundef Exit Function End If Plot.Update ScreenUpdating True Wait 0.3 frq_cst = GetFieldFrequency() If bLogFileFirstEval Then ' always write new log-file name for every evaluate (otherwise overwriting result files by duplicated templates) Dim ntoday As Long, ntime As Long ntoday = CLng(Day(Date)) + 100 * CLng(Month(Date)) + 10000 * CLng(Year(Date)) ntime = CLng(Second(Time)) + 100 * CLng(Minute(Time)) + 10000 * CLng(Hour(Time)) StoreScriptSetting("sLogFilename_CST",NoForbiddenFilenameCharacters(CStr(ntoday) + CStr (ntime) + Cstr(Cint(100*Rnd())))) sLogFilename_CST = GetScriptSetting("sLogFilename_CST","") sLogFilename_CST = GetScriptSetting("sLogFilename_CST","") If (sLogFilename_CST = "") Then CalculateEigenModeResult = lib_rundef Exit Function End If Dim sLogFile_CST As String sLogFile_CST = GetProjectPath("Result") + sLogFilename_CST + ".log" Open sLogFile_CST For Output As #1 Print #1, vbCrLf + _ "Mode " + Trim(Str(iModeNumber)) + vbCrLf + vbCrLf + _ PP15L("Frequency") + " = " + PP15(frq_cst) + " " + Units.GetFrequencyUnit + vbCrLf Close #1 End If If (s0DValue <> "Frequency") And (s0DValue <> "Q-Factor (lossy Eigenmode)") And (s0DValue <> "Q-Factor (external)") Then With QFactor .Reset .SetHField "Mode " + Trim(Str(iModeNumber)) .Calculate q_cst = .GetTotalQ pw_cst = .GetTotalLoss/2 eng_cst = .GetTotalEnergy End With If bLogFileFirstEval Then Open sLogFile_CST For Append As #1 Print #1, PP15L("Total Q") + " = " + PP15(q_cst) Print #1, PP15L("Total Loss_av") + " = " + PP15(pw_cst) Print #1, PP15L("Total Energy") + " = " + PP15(eng_cst) Print #1, vbCrLf + _ "QFI-File (settings of Loss and Q-calculation):" + vbCrLf + _ "==============================================" + vbCrLf Close #1 CST_AppendFile sLogFile_CST, GetProjectPath("Model3D")+"Model.qfi" Open sLogFile_CST For Append As #1 Print #1, vbCrLf + vbCrLf Close #1 End If ' bLogFileFirstEval End If If bVoltageNeeded(s0DValue) Then ' . get min and max meshstep Dim dMeshMin As Double, dMeshMax As Double, dStepNow As Double Dim dmline1 As Double, dmline2 As Double, nMeshTmp As Long Dim dAbsMeshMax As Double Dim x1box As Double, x2box As Double Dim y1box As Double, y2box As Double Dim z1box As Double, z2box As Double Boundary.GetCalculationBox x1box, x2box, y1box, y2box, z1box, z2box dAbsMeshMax = 0 With Mesh On Error GoTo NoMeshExists dMeshMin = .GetMinimumEdgeLength dMeshMax = .GetMaximumEdgeLength On Error GoTo 0 GoTo MeshExists NoMeshExists: CalculateEigenModeResult = lib_rundef ReportError "No Mesh Exists." Exit Function MeshExists: If Abs(x1box) > dAbsMeshMax Then dAbsMeshMax = Abs(x1box) If Abs(y1box) > dAbsMeshMax Then dAbsMeshMax = Abs(y1box) If Abs(z1box) > dAbsMeshMax Then dAbsMeshMax = Abs(z1box) If Abs(x2box) > dAbsMeshMax Then dAbsMeshMax = Abs(x2box) If Abs(y2box) > dAbsMeshMax Then dAbsMeshMax = Abs(y2box) If Abs(z2box) > dAbsMeshMax Then dAbsMeshMax = Abs(z2box) ' search all X-Meshlines End With ' now dMeshMin, dMeshMax contain the smallest and biggest meshstep ' dAbsMeshMax is the biggest absolute dimension from origin (useful for maxrange guess) '---------------------------------------------------------------------------------- Dim iDir_CST As Integer, dstepsize_CST As Double, bmaxrange_CST As Boolean iDir_CST = 1+CInt(GetScriptSetting("coordinates","0")) dstepsize_CST = Evaluate(GetScriptSetting("stepsize","0.0")) bmaxrange_CST = 1=CInt(GetScriptSetting("maxrange","1")) Dim dUVWvalue(3,3) As Double ' first index=u,v,w second index=low,high,step dUVWvalue(1,1) = Evaluate (GetScriptSetting("u1","0.0")) dUVWvalue(2,1) = Evaluate (GetScriptSetting("v1","0.0")) dUVWvalue(3,1) = Evaluate (GetScriptSetting("w1","0.0")) dUVWvalue(1,2) = Evaluate (GetScriptSetting("u2","0.0")) dUVWvalue(2,2) = Evaluate (GetScriptSetting("v2","0.0")) dUVWvalue(3,2) = Evaluate (GetScriptSetting("w2","0.0")) ' set stepsize ddStep (equidistant) dep on mesh-type Dim ddStep As Double, nIndex As Long If dstepsize_CST = 0.0 Then ' automatic choice Select Case Mesh.GetMeshType Case "Surface", "Tetrahedral" If 50.0*dMeshMin > dMeshMax Then ddStep = 0.5 * dMeshMin Else ddStep = 0.1 * dMeshMax End If Case Else ' hex ddStep = 0.5 * dMeshMin ' for 1D half of min meshstep is used End Select Else ddStep = dstepsize_CST End If Dim xyzbox(3,2) As Double xyzbox(1,1) = x1box xyzbox(1,2) = x2box xyzbox(2,1) = y1box xyzbox(2,2) = y2box xyzbox(3,1) = z1box xyzbox(3,2) = z2box ' if max-range, then set minmax values dep. on dim and coord.system If (bmaxrange_CST) Then dUVWvalue(iDir_CST,1) = xyzbox(iDir_CST,1) dUVWvalue(iDir_CST,2) = xyzbox(iDir_CST,2) End If ' now maxrange is set, all dUVWvalues() are set now '---------------------------------------------------------------------------------- ' adjust final min, max values and afterwards adjust the stepsize, fitting to it ' also, recalculate angle-stepwidth from from ddStep Dim dstptmp As Double, nstpstmp As Long, dminmaxtmp As Double ' max=min, step = 1 for all directions unequal idir direction For nIndex = 1 To 3 If nIndex <> iDir_CST Then dUVWvalue(nIndex,2) = dUVWvalue(nIndex,1) dUVWvalue(nIndex,3) = 1 End If Next dstptmp = ddStep dminmaxtmp = dUVWvalue(iDir_CST,2)-dUVWvalue(iDir_CST,1) nstpstmp = CLng ( dminmaxtmp / dstptmp ) If nstpstmp < 1 Then nstpstmp = 1 dUVWvalue(iDir_CST,3) = dminmaxtmp / nstpstmp '---------------------------------------------------------------------------------- Dim sDataFile_CST As String Dim sPointxyzFile_CST As String sDataFile_CST = GetProjectPath("Result") + sLogFilename_CST + ".dat" sPointxyzFile_CST = GetProjectPath("Result") + sLogFilename_CST + ".xyz" If bLogFileFirstEval Then Open sLogFile_CST For Append As #1 Open sDataFile_CST For Output As #2 Open sPointxyzFile_CST For Output As #3 Print #2, _ PP12(GetScriptSetting("coord1","")) + _ PP12(GetScriptSetting("coord2","")) + _ PP12(GetScriptSetting("coord3","")) + _ PP12("delta_w") + PP12("Ew_real") + PP12("Ew_imag") + PP12("cos(alfa)") + PP12("sin(alfa)") + PP12("Vsum_real") + PP12("Vsum_imag") Print #2, _ PP12("--------------------") + PP12("--------------------") + PP12("--------------------") + _ PP12("--------------------") + PP12("--------------------") + PP12("--------------------") + _ PP12("--------------------") + PP12("--------------------") + PP12("--------------------") + _ PP12("--------------------") Print #1, vbCrLf + _ " Logfile of Voltage Integration" + vbCrLf + _ " ==============================" + vbCrLf Print #1, PP25L("Stepsize") + ": " + CStr(ddStep) Print #1, _ vbCrLf + _ PP8("") + PP12("low") + PP12("high") + PP12("stepsize") + vbCrLf + _ PP8("") + PP12("----------------") + PP12("----------------") + PP12("----------------") + vbCrLf + _ PP8(GetScriptSetting("coord1","")) + PP12(dUVWvalue(1,1))+PP12(dUVWvalue(1,2))+PP12(dUVWvalue(1,3)) + vbCrLf + _ PP8(GetScriptSetting("coord2","")) + PP12(dUVWvalue(2,1))+PP12(dUVWvalue(2,2))+PP12(dUVWvalue(2,3)) + vbCrLf + _ PP8(GetScriptSetting("coord3","")) + PP12(dUVWvalue(3,1))+PP12(dUVWvalue(3,2))+PP12(dUVWvalue(3,3)) + vbCrLf End If ' bLogFileFirstEval '---------------------------------------------------------------------------------- ' finally set min startpoint (1d => ONLY in IDIR, 2d=> ALL, but not for IDIR) at half stepsize dUVWvalue(iDir_CST,1) = dUVWvalue(iDir_CST,1) + 0.5 * dUVWvalue(iDir_CST,3) ' . loop over abc (fit stepsize to range, then start at step/2) ' do a = amin + astep/2, am Ende der Loop: a = a + astep until a > amax ' for a=amin to amax step astep (astep=1 amin=amax falls keine Loop) Dim u_CST As Double, v_CST As Double, w_CST As Double Dim x_CST As Double, y_CST As Double, z_CST As Double Dim dVoxel_Unit As Double, dVoxel_SI As Double dVoxel_Unit = 1 ' angle-stepwidth needs to be taken in radian, new array dStepLength(1-3) Dim dStepLength(3) As Double For nIndex = 1 To 3 dStepLength(nIndex) = dUVWvalue(nIndex,3) Next dVoxel_Unit = dVoxel_Unit * dStepLength(iDir_CST) dVoxel_SI = dVoxel_Unit * (Units.GetGeometryUnitToSI()) Dim dRef_Voxel_Unit As Double, dRef_Voxel_SI As Double, dRsinTheta As Double Dim sFieldCST As String, bScalar As Boolean Dim sComponentCST As String Dim sComplexCST As String Dim sActionCST As String sFieldCST = "Modes\Mode " + Trim(Str(iModeNumber)) + "\e" sComponentCST = "Tangential" sActionCST = GetScriptSetting("a0DValue","") Mesh.ViewMeshMode False If (Not SelectTreeItem("2D/3D Results\"+ sFieldCST)) Then CalculateEigenModeResult = lib_rundef ReportError "Result not found in tree: " + sFieldCST Exit Function End If Plot3DPlotsOn2DPlane False bScalar = bScalarField(sFieldCST) Dim bLokVA_CST As Boolean, bLokVB_CST As Boolean, bLokVC_CST As Boolean bLokVA_CST = False ' rfw, rfz or rtf bLokVB_CST = False ' uvw bLokVC_CST = False ' xyz Dim va_CST(2) As Double, vb_CST(2) As Double, vc_CST(2) As Double For nIndex = 0 To 2 va_CST(nIndex) = 0.0 ' component in rfw, rfz or rtf coordinates vb_CST(nIndex) = 0.0 ' component in uvw coordinates vc_CST(nIndex) = 0.0 ' component in xyz coordinates Next Dim im1Dir_CST As Integer im1Dir_CST = iDir_CST-1 Select Case sComponentCST Case "Scalar" ' vector transformation not required for scalar ' MsgBox "hello scalar" Case "Tangential" ' ----------------------------------- ' always true for cartesian + global ' ----------------------------------- bLokVC_CST = True vc_CST(im1Dir_CST) = 1.0 End Select Dim bFieldError As Boolean Dim vxre As Double, vxim As Double Dim vyre As Double, vyim As Double Dim vzre As Double, vzim As Double Dim vxam As Double, vxph As Double Dim vyam As Double, vyph As Double Dim vzam As Double, vzph As Double Dim vxTmp As Double, vyTmp As Double, vzTmp As Double, vNowCST As Double Dim dSumVoxel_Unit As Double Dim dSumIntegral As Double Dim dMaxCST As Double Dim dMinCST As Double Dim nDataCST As Long nDataCST = 0 dSumVoxel_Unit = 0.0 dSumIntegral = 0.0 dMaxCST = lib_rundef ' -1.23456e27 dMinCST = - lib_rundef ' 1.23456e27 Dim rbeta As Double, alfa As Double, cosa As Double, sina As Double, dw As Double Dim iTTF As Integer, vwsumre As Double, vwsumim As Double, alfa_fac As Double, stmp As String iTTF = CInt(GetScriptSetting("Check_ttf","0")) dw = dUVWvalue(iDir_CST,3)* Units.GetGeometryUnitToSI() vwsumre = 0.0 vwsumim = 0.0 If (iTTF = 0) Then alfa = 0 cosa = 1 sina = 0 Else rbeta = Evaluate(GetScriptSetting("beta","not used")) alfa_fac = Units.GetGeometryUnitToSI() * (2 * Pi * frq_cst * Units.GetFrequencyUnitToSI()) / (rbeta * CLight) End If Dim bTake_this_point As Boolean Dim uvw_CST(2) As Double, bbb(2) As Double, xyz_CST(2) As Double VectorPlot3D.Reset ' necessary to reset list items ' =============================================== ' --- Loop ONE - writing points into list ' =============================================== For u_CST = dUVWvalue(1,1) To dUVWvalue(1,2) STEP dUVWvalue(1,3) uvw_CST(0) = u_CST For v_CST = dUVWvalue(2,1) To dUVWvalue(2,2) STEP dUVWvalue(2,3) uvw_CST(1) = v_CST For w_CST = dUVWvalue(3,1) To dUVWvalue(3,2) STEP dUVWvalue(3,3) uvw_CST(2) = w_CST ' if not cartesian : transfer uvw into cartesian xyz_CST xyz_CST(0) = uvw_CST(0) xyz_CST(1) = uvw_CST(1) xyz_CST(2) = uvw_CST(2) x_CST = xyz_CST(0) y_CST = xyz_CST(1) z_CST = xyz_CST(2) ' check abc against box (bei maxrange) + solid (if selected), remember solid-ID (iNowSolid_CST) bTake_this_point = False If (x_CST >= x1box) And (x_CST <= x2box) And (y_CST >= y1box) And (y_CST <= y2box) And (z_CST >= z1box) And (z_CST <= z2box) Then bTake_this_point = True End If If (bTake_this_point) Then bFieldError = VectorPlot3D.AddListItem ( x_CST, y_CST, z_CST ) End If Next w_CST Next v_CST Next u_CST ' =============================================== ' --- after Loop ONE - calculate list ' =============================================== VectorPlot3D.CalculateList ' =============================================== ' --- Loop TWO - reading fieldvalues from list ' =============================================== Dim i_CST_GetListItem As Long i_CST_GetListItem = 0 For u_CST = dUVWvalue(1,1) To dUVWvalue(1,2) STEP dUVWvalue(1,3) uvw_CST(0) = u_CST For v_CST = dUVWvalue(2,1) To dUVWvalue(2,2) STEP dUVWvalue(2,3) uvw_CST(1) = v_CST For w_CST = dUVWvalue(3,1) To dUVWvalue(3,2) STEP dUVWvalue(3,3) uvw_CST(2) = w_CST ' if not cartesian : transfer uvw into cartesian xyz_CST xyz_CST(0) = uvw_CST(0) xyz_CST(1) = uvw_CST(1) xyz_CST(2) = uvw_CST(2) x_CST = xyz_CST(0) y_CST = xyz_CST(1) z_CST = xyz_CST(2) ' check abc against box (bei maxrange) + solid (if selected), remember solid-ID (iNowSolid_CST) bTake_this_point = False If (x_CST >= x1box) And (x_CST <= x2box) And (y_CST >= y1box) And (y_CST <= y2box) And (z_CST >= z1box) And (z_CST <= z2box) Then bTake_this_point = True End If If (bTake_this_point) Then bFieldError = VectorPlot3D.GetListItem ( i_CST_GetListItem, vxre, vyre, vzre, vxim, vyim, vzim ) i_CST_GetListItem = i_CST_GetListItem + 1 If bLogFileFirstEval Then Print #3,PP12(x_CST) + PP12(y_CST) + PP12(z_CST) End If If ( Not bFieldError ) Then If bLogFileFirstEval Then Print #2,PP12(x_CST) + PP12(y_CST) + PP12(z_CST) + " Problem in reading fieldvalue" End If Else If (iTTF = 1) Then alfa = xyz_CST(iDir_CST-1) * alfa_fac cosa = Cos(alfa) sina = Sin(alfa) End If If iDir_CST=1 Then vwsumre = vwsumre + dw * (vxre*cosa - vxim*sina) vwsumim = vwsumim + dw * (vxim*cosa + vxre*sina) stmp = PP12(vxre) + PP12(vxim) ElseIf iDir_CST=2 Then vwsumre = vwsumre + dw * (vyre*cosa - vyim*sina) vwsumim = vwsumim + dw * (vyim*cosa + vyre*sina) stmp = PP12(vyre) + PP12(vyim) ElseIf iDir_CST=3 Then vwsumre = vwsumre + dw * (vzre*cosa - vzim*sina) vwsumim = vwsumim + dw * (vzim*cosa + vzre*sina) stmp = PP12(vzre) + PP12(vzim) End If If bLogFileFirstEval Then Print #2,PP12(u_CST) + PP12(v_CST) + PP12(w_CST) + PP12(dw) + stmp + PP12(cosa) + PP12(sina) + PP12(vwsumre) + PP12(vwsumim) End If End If dSumVoxel_Unit = dSumVoxel_Unit + dVoxel_Unit nDataCST = nDataCST + 1 End If Next w_CST Next v_CST Next u_CST Dim vwfull As Double vwfull = Sqr(vwsumim*vwsumim+vwsumre*vwsumre) If bLogFileFirstEval Then Print #1, "Summary of electric voltage-integration:" + vbCrLf + _ "========================================" + vbCrLf + vbCrLf + _ "frequency = " + CStr(frq_cst) + " " + Units.GetFrequencyUnit + vbCrLf + _ "beta = " + CStr(rbeta) + vbCrLf + _ "V_real = " + CStr(vwsumre) + vbCrLf + _ "V_imag = " + CStr(vwsumim) + vbCrLf + _ "V_full = " + CStr(vwfull) + " = absolute value of int(Ez*exp(ikz)dz) k=2*pi*freq/beta/clight" + vbCrLf Print #1, " NData Points = "+CStr(nDataCST) + vbCrLf + vbCrLf Close #3 Close #2 Close #1 CST_AppendFile sLogFile_CST, sDataFile_CST Kill sDataFile_CST End If End If Dim cst_value As Double cst_value = lib_rundef Select Case s0DValue Case "Frequency" cst_value = frq_cst Case "Q-Factor (Perturbation)" cst_value = q_cst ' (= omega * energy/loss_rms = omega * 2*energy/loss_peak) Case "Total Energy" cst_value = eng_cst Case "Total Loss (Pert., Aver.)" cst_value = pw_cst ' (= loss_average = 0.5*loss_peak) Case "R over Q" cst_value = vwfull*vwfull/(2*Pi* frq_cst*Units.GetFrequencyUnitToSI() * eng_cst) Case "Shunt Impedance" cst_value = vwfull*vwfull/pw_cst Case "Voltage" cst_value = vwfull Case "Q-Factor (lossy Eigenmode)" With Result3D("^mode_e_" + Trim(Str(iModeNumber))) cst_value = .GetQFactor End With If bLogFileFirstEval Then Open sLogFile_CST For Append As #1 Print #1, _ PP15L("Q-Factor") + " = " + PP15(cst_value) + vbCrLf Close #1 End If ' bLogFileFirstEval Case "Q-Factor (external)" With Result3D("^mode_e_" + Trim(Str(iModeNumber))) cst_value = .GetExternalQFactor End With If bLogFileFirstEval Then Open sLogFile_CST For Append As #1 Print #1, _ PP15L("Q-Factor") + " = " + PP15(cst_value) + vbCrLf Close #1 End If ' bLogFileFirstEval Case "Q-Factor (loaded)" With Result3D("^mode_e_" + Trim(Str(iModeNumber))) cst_value = .GetExternalQFactor If((Abs(q_cst) < 1e-18) Or (Abs(cst_value) < 1e-18)) Then cst_value = lib_rundef Else cst_value =(1/cst_value+1/q_cst)^-1 End If End With If bLogFileFirstEval Then Open sLogFile_CST For Append As #1 Print #1, _ PP15L("Q-Factor") + " = " + PP15(cst_value) + vbCrLf Close #1 End If ' bLogFileFirstEval Case "Loaded Frequency" With Result3D("^mode_e_" + Trim(Str(iModeNumber))) cst_value = .GetLoadedFrequency End With If bLogFileFirstEval Then Open sLogFile_CST For Append As #1 Print #1, _ PP15L("Loaded Frequency") + " = " + PP15(cst_value) + vbCrLf Close #1 End If ' bLogFileFirstEval End Select CalculateEigenModeResult = cst_value ' Shell("notepad.exe " + sLogFile_CST, 1) End Function 'Const lib_rundef = -1.2345678e27 Sub Main2 ' ------------------------------------------------------------------------------------------------- ' Main: This function serves as a main program for testing purposes. ' You need to rename this function to "Main" for debugging the result template. ' ' PLEASE NOTE that a result template file must not contain a main program for ' proper execution by the framework. Therefore please ensure to rename this function ' to e.g. "Main2" before the result template can be used by the framework. ' ------------------------------------------------------------------------------------------------- ' Activate the StoreScriptSetting / GetScriptSetting functionality. Clear the data in order to ' provide well defined environment for testing. ActivateScriptSettings True ClearScriptSettings ' Now call the define method and check whether it is completed successfully If (Define("test", True, False)) Then MsgBox Cstr(Evaluate0D) ' If the define method is executed properly, call the Evaluate1D method and plot the curve Dim stmpfile As String stmpfile = "Test1D_tmp.txt" Dim r1d As Object Set r1d = Evaluate1D r1d.Save stmpfile r1d.AddToTree "1D Results\Test 1D" SelectTreeItem "1D Results\Test 1D" With Resulttree .UpdateTree .RefreshView End With End If ' Deactivate the StoreScriptSetting / GetScriptSetting functionality. ActivateScriptSettings False End Sub