用FRED模拟沃拉斯顿棱镜偏振器(2)

[复制链接]
cherryjhy 发表于 2023-5-10 17:56:01 | 显示全部楼层 |阅读模式
2. 可在Materials 树形文件夹下查看CaCO3材料是否已经添加进去?
1-160121230422319.png.jpg


3. 在树形文件夹中选择:Embedded Scripts /Birefringent material creator右键选择“.Run an Embedded script.

1-160121230452120.png.jpg

公布脚本代码如下,用户不需要对如下脚本做任何的修改。

Dim biref As T_BIREFSAMPLE
Dim matlist() As String
Dim matOrdId As Long, matExtraId As Long, id As Long
Dim wavStart As Double, wavEnd As Double, wavSteps As Double, wav As Double
Dim axis_x As Double, axis_y As Double, axis_z As Double
Dim newName As String

Sub Main

    'Generate list of materials
    ReDim matlist(GetMaterialCount()-1)
    For i = 0 To GetMaterialCount()-1
        matlist(i)=GetMaterialName(i)
    Next i

    Begin Dialog UserDialog 660,266,"Birefringent Material Creator" ' %GRID:10,7,1,1
        GroupBox 430,7,220,105,"Select Wavelength Range",.GroupBox2
        Text 440,84,80,14,"Total Steps:",.TextSteps
        Text 480,28,40,14,"Start:",.TextStart
        GroupBox 10,7,410,168,"Select Materials",.GroupBox1
        ListBox 220,49,180,112,matlist(),.ListBoxMat2
        Text 220,28,180,14,"Extraordinary axis material:",.TextMat2
        ListBox 30,49,180,112,matlist(),.ListBoxMat1
        Text 30,28,180,14,"Ordinary axis material:",.TextMat1
        TextBox 530,28,90,21,.TextBoxStart
        TextBox 530,84,90,21,.TextBoxSteps
        Text 480,56,40,14," End: ",.TextEnd
        TextBox 530,56,90,21,.TextBoxEnd
        Text 20,182,140,14,"New material name:",.TextNewMat
        TextBox 20,203,390,21,.TextBoxNewMat
        OKButton 150,238,90,21
        CancelButton 370,238,90,21
        GroupBox 430,119,220,105,"Crystal Axis Vector",.GroupBox3
        Text 500,140,30,14,"X:",.Text1
        TextBox 530,140,90,21,.TextBoxX
        Text 500,168,20,14,"Y:",.Text2
        Text 500,196,20,14,"Z:",.Text3
        TextBox 530,196,90,21,.TextBoxZ
        TextBox 530,168,90,21,.TextBoxY
    End Dialog
    Dim dlg As UserDialog

    'Insert default values
    dlg.TextBoxStart="0.4"
    dlg.TextBoxEnd="0.7"
    dlg.TextBoxSteps="101"
    dlg.TextBoxNewMat="Birefringent Material"
    dlg.TextBoxX = "0"
    dlg.TextBoxY = "0"
    dlg.TextBoxZ = "1"

    'Run dialog
    ok = Dialog (dlg)

    If ok=0 Then    'cancel button was pressed
        Print "Execution cancelled."
        End
    End If

    'Assign values from dialog
    matOrdId = FindMaterial(matlist(dlg.ListBoxMat1))
    matExtraId = FindMaterial(matlist(dlg.ListBoxMat2))
    wavStart = CDbl(dlg.TextBoxStart)
    wavEnd = CDbl(dlg.TextBoxEnd)
    wavSteps = CDbl(dlg.TextBoxSteps)
    newName = dlg.TextBoxNewMat
    axis_x = CDbl(dlg.TextBoxX)
    axis_y = CDbl(dlg.TextBoxY)
axis_z = CDbl(dlg.TextBoxZ)

    'Print warning if material of the same name already exists
    Print " "
    If FindMaterial(newName) > 0 Then
        Print "Warning: A material named " & newName & " already exists."
    End If

    'Create material
    wavDelta = (wavEnd-wavStart)/(wavSteps-1)
    For wav = wavStart To wavEnd+0.00001 Step wavDelta
        biref.wavelen = wav
        biref.NOrd = RefractiveIndex( matOrdId,  wav )
        biref.NExt = RefractiveIndex( matExtraId,  wav )
        biref.GOrd=0
        biref.GExt=0

        If wav = wavStart Then  'Create material
            id = AddBirefringentMaterial (newName, "Birefringent using " & GetMaterialName(matOrdId) & " (no) & " & GetMaterialName(matExtraId) & " (ne)", biref )
        Else                    'Add data to the list
            AppendBirefringentMaterialSample id, biref
        End If
    Next wav

    'Set crystal axis
    SetLength3D axis_x,axis_y,axis_z,1
    SetBirefringentMaterialCrystalAxis id, axis_x, axis_y, axis_z

    Print "New birefringent material created: " & newName

    Update

End Sub



回复

使用道具 举报

全部回复0 显示全部楼层
暂无回复,精彩从你开始!

快速回帖

您需要登录后才可以回帖 登录 | 立即注册 手机动态码快速登录

本版积分规则

关于楼主

高级会员
  • 主题

    820
  • 回答

    812
  • 积分

    821
联系客服 关注微信 访问手机版 返回顶部 返回列表