Navigation: Scripting Reference Manual > Script Examples > Examples - Material Script Command

 

Examples - Material Script Command

 

Contact Us: fredsupport@photonengr.com

 

These examples cover the basic FRED scripting commands involving materials:

"Add" - adds a new material to the existing list,

"Append" - appends a wavelength to the table of an existing material,

"Find" - used to determine the identifier of an existing material,

"Get" - retrieves information from an existing material,

"GetIth" - retrieves material parameters at the ith wavelength in its list,

"GetGRINMaterialNumWavelengths" - retrieves the number of wavelength entries in a GRIN material definition,

"Init" - initializes a structure with default values,

"RemoveIth" - removes the ith wavelength from the material list along with the corresponding parameters at that wavelength,

"RefractiveIndex"- returns the real or imaginary part of a material refractive index at a specified wavelength,

"Set" - sets properties of an existing material, and

"SetIth" - sets the ith wavelength and associated parameters for an existing material.

The material structures listed below contain the parameters required to fully define material types:

T_MODELMATERIAL

T_SAMPLEDMATERIAL

T_GRINCOMMON

T_BIREFSAMPLE

 

FRED offers types of material models:

Sampled Material - user specified a list of wavelengths and corresponding complex refractive indicies. 

Model Material - user specified refractive index and Abbe number at the He "d" line (0.5875618 mm). 

Gradient Index - Luneberg, Maxwell, Spherical, SELFOC, Axial, Radial, & scripted. 

Birefringent/Optically Active - uniaxial crystals with ordinary & extraordinary indicies or Optical Activity.with gyrotopic coefficients. 

Catalog glasses - Materials from Schott, Ohara, Hoya, CorningSA, Pilkington, Schott Radiation Resistant, or Custom catalogs. 


"Add" a Material

 

To "Add" a Sampled material requires at least these four steps:

 

Declare the appropriate structure.

Set the desired parameters of that material structure.

"Add" the material.

Update FRED.

 

To "Add" a Sampled material, first declare a T_SAMPLEDMATERIAL structure and assign a name and description to the new material. Declare arrays to hold the wavelength list and the corresponding real and imaginary indicies at those wavelengths. Finally, pass the wavelength and index information to FRED through the AddSampledMaterial command. Finally, Update the material database.

 

Dim m As T_SAMPLEDMATERIAL
m.Name="Material 1"
m.Description=""
Dim wavls#(1), rindx#(1), imags#(1)
wavls(0)=0.296728 : rindx(0)=1.5 : imags(0)=0
wavls(1)=0.587562 : rindx(1)=1 : imags(1)=0
m_id = AddSampledMaterial( m, wavls, rindx, imags )
Update

Print "The index of the new Sampled material is ", id
 

 

To "Add" a Model material requires only four steps:

Declare the appropriate structure.

Set the desired parameters of that material structure.

"Add" the material.

Update FRED.

 

Dim mymat As T_MODELMATERIAL

mymat.Name="mynewglass"
mymat.Description="ficticious glass"
mymat.Nd=1.62985
mymat.Vd=27.8

id = AddModelMaterial ( mymat )

Update

Print "The index of the new model material is ", id
 

 

To "Add" a Catalog glass, specify the glass name and the catalog name then Update the material database:

 

Dim gName$,catname$
gName="PBM5"
catname="Ohara"
id = AddCatalogGlass ( gName, catname )
Update

Print "The index of the new catalog glass is ", id
 

 

To "Add" a Maxwell GRIN material, specify a wavelength along with N0 & R0 values at that wavelength. Always Update the material database.:

 

Dim wv#,N0#,R0#

wv=0.5786
N0=1.5
R0=0.0245
id = AddMaxwellGRINMaterial ( wv, N0, R0 )
Update

Print "The index of the new Maxwell GRIN material is ", id

 

 

To "Add" a SELFOC material, specify a wavelength and populate an array with the N0 & N# values for that wavelength. Finally, Update the material database.:

 

Dim wave#
Dim coefs(2) As Double

wave=0.75
coefs(0)=1.6
coefs(1)=0.06
coefs(2)=3.4e-3
id = AddSelfocGRINMaterial ( wave, coefs )

Update

 

To add a birefringent material, declare a T_BIREFSAMPLE structure and specify the material name and description. Assign the desired refractive indicies or gyrotropic coefficients then create the material using the AddBirefringentMaterial command. [The default crystal axis is in the z-direction. See SetBirefringentMaterialCrystalAxis below for guidance on setting a different crystal axis direction.] Don't forget to Update the material database.

 

Dim xtal As T_BIREFSAMPLE
Dim bname$,desc$
 

bname="mycrystal"
desc=""

xtal.WaveLen=0.6328
xtal.NOrd=1.62953
xtal.NExt=1.65108
bid = AddBirefringentMaterial ( bname, desc, xtal )
Update

 

To "Add" a GRIN material defined by a user script, specify the full path of script file. FRED assumes that the file is in your current directory otherwise. Assign a name to the material as well.

 

scrptid = AddScriptGRINMaterial ("mynewgrin.frs")

Dim scrptname As String

scrptname="CustomGRIN"

SetMaterialName scrptid, scrptname


 

"Find" a material identifier

 

Use FindMaterial to retrieve the identifier of an existing material:

 

lunid=FindMaterial("myluneberg")


 

"Append" a wavelength and its corresponding data

 

If additional material data is needed, use an "Append" command to add it. These entries are appended to the end of an existing list.

 

To append more data to an existing Lundberg material, first determine the identifier of the material with FindMaterial.

 

lunid=FindMaterial("myluneberg")
wave=0.6328
N0=1.653
R0=0.045
Print lunid
AppendLunebergGRINMaterial lunid, wave, N0, R0


 

"Get" data from an existing material

 

To "Get" common data from an existing material, first declare a T_GRINCOMMON structure then find the material indentifier.

 

Dim GCom As T_GRINCOMMON
gid=FindMaterial("grinmat")
GetGRINMaterialCommon gid, GCom
Print "step size", GCom.StepSize
Print "x offset", GCom.XOffset
Print "y offset", GCom.YOffset
Print "z offset", GCom.ZOffset
Print "maximum number of steps", GCom.MaxNSteps


 

"GetIth" wavelength and its corresponding data

 

Use the "GetIth" commands to retrieve data from a GRIN material or Glue at a specific wavelength.

 

 

To retrieve the ith wavelength and its corresponding data from an existing SELFOC material, first find its identifier. Since the GetIthSelfocGRINMaterial command returns a wavelength and its corresponding coefficients, declare a wavelength variable and an array to hold the coefficients. After choosing the index of the desired wavelength, issue the GetIthSelfocGRINMaterial command.

 

sfid=FindMaterial("selfocfiber")

Dim Wave As Double
Dim Coeffs() As Double

WavelenNum=1
GetIthSelfocGRINMaterial sfid, WavelenNum, Wave, Coeffs
Print "Wavelength ", Wave
For i=0 To UBound(Coeffs)
 Print "coefficient ",i,"  value ",Coeffs(i)
Next i


"GetGRINMaterialNumWavelengths"

 

Use this command to retrieve the number of wavelength entries in a GRIN material definition:

 

gid=FindMaterial("AxRadMat")
nw=GetGRINMaterialNumWavelengths(gid)
Print "Material id ",gid," has ",nw," wavelength entries"


 

"Init" a material

 

The "Init" commands initialize either Model material or GRIN Common structures. These commands are used to set/return a material to its default set of values.

 

Dim mat As T_MODELMATERIAL
InitModelMaterial mat
Print "Nd ", mat.Nd
Print "Vd ", mat.Vd
Print "Material name ", mat.Name
Print "Material Description ", mat.Description

 

or

 

Dim grincom As T_GRINCOMMON

InitGRINMaterialCommon grincom

Print "step size ", grincom.StepSize
Print "x offset ", grincom.XOffset
Print "y offset ", grincom.YOffset
Print "z offset ", grincom.ZOffset
Print "maximum number of steps ", grincom.MaxNSteps


 

"RemoveIth" wavelength and its corresponding data

 

The "RemoveIth" commands remove a selected set of material parameters from a material model.

 

gid=FindMaterial("MaxwellMat")
nw=GetGRINMaterialNumWavelengths(gid)
Print "Material id ",gid," has ",nw," wavelength entries"
 

indx=2 'remove the third entry
 

RemoveIthMaxwellGRINMaterial gid, indx

nw=GetGRINMaterialNumWavelengths(gid)
Print "Material id ",gid," now has ",nw," wavelength entries"


 

"RefractiveIndex" retrieval

 

Retrieve the real (or imaginary) part of a material refractive index at a specified wavelength:

 

matid1=FindMaterial("Optical Cement")
wv1=0.6328
rn1=RefractiveIndex (matid1, wv1)
Print "real part of index at ",wv1," is ",rn1

matid2=FindMaterial("amber")
wv2=0.2804
in2=RefractiveIndexImag (matid2, wv2)
Print "imaginary part of index at ",wv2," is ",in2


 

"Set" the parameters of a material

 

Use the "Set" commands to change specific parameters of an existing material, assign a script defining a GRIN material, change the GRIN common parameters, or define a new crystal axis orientation for a birefringent material.

 

 

To change the script file defining an existing user scripted GRIN material, specify the new filename:

 

Dim newscript As String

newscript="anothergrin.frs"

SetScriptGRINMaterial scrptid, newscript

Update

 

To change the settings of a GRIN common for an existing material, first declare a T_GRINCOMMON structure and initialize its values. Alter the desired values, then use SetGRINMaterialCommon to put the new data into the material definition.

 

Dim gparm As T_GRINCOMMON
gid=FindMaterial("MaxwellMat")

InitGRINMaterialCommon gparm
gparm.StepSize=0.005
SetGRINMaterialCommon gid,gparm
Update

 

As mentioned earlier, a birefringent material has its crystal axis defined along the z-direction by default. To change the crystal axis direction, define a new direction vector then use SetBirefringentMaterialCrystalAxis to reorient the crystal.

 

matid=FindMaterial("Mica")

'define a new unit vector (need not be normalized)
X=0:Y=1:Z=1
 

SetBirefringentMaterialCrystalAxis matid, X, Y, Z
Update

 


See Also….

 

Advanced Raytrace

Basic Raytrace

Coatings

Curves

Elements

Entity Info

General Ray Data

Gratings

Importance Sampling

Linear Transforms

Ray Buffer Handling

Ray Data Get/Set

Ray Path

Raytrace Control

Scatter

Sources

Surfaces

 

 

 

 

 

Copyright © Photon Engineering, LLC