Description This function performs an energy density (power/volume) calculation using rays which exist on a specific surface and stores the result of the calculation in an array variable. The third argument of the command is a T_ANALYSIS structure, which defines a sampling grid (pixels, orientation and location) over which the distribution is computed but does not define any ray selection filter operations. Energy density is effectively an Irradiance calculation without the cosine projection and allows you to analyze an energy distribution longitudinal to the propagation direction (ex. through focus).
Syntax count = EnergyDensity( n, nCoordSys, ana, data())
Parameters count (Long) Returned number of rays that were included in the calculation.
n As Long Node number of the surface to be used as the ray selection filter. Only rays which exist on this surface at the time of the EnergyDensity call will be included in the calculation.
nCoordSys As Long Node number of the entity whose coordinate system the ana structure is expressed in. If the ana structure was initialized using the LoadAnalysis command, the value of nCoordSys should be set to -1.
ana As T_ANALYSIS Structure defining a sample area over which the calculation will be performed. This variable may be initialized manually or by calling LoadAnalysis. If LoadAnalysis is used, note that the T_ANALYSIS structure is defined in global coordinates and therefore nCoordSys = -1.
data() As Double After the EnergyDensity function is called, this variable contains the result of the analysis and has the same dimensions as the number of pixels in x and y as defined by the T_ANALYSIS structure. The data is presented as column, row for indexing purposes and when used in conjunction with the ArrayStats command, the variables used for minimum and maximum value pixel locations will have the same relationship (i.e. minLoc(0) = column index of minimum value, minLoc(1) = row index of minimum value).
Example The example below demonstrates how to use the EnergyDensity command in conjunction with the LoadAnalysis and ArrayStats subroutines to obtain the array of energy density values from a sampling grid and report the statistics of the array data. Emphasis is placed on understanding the coordinate system relationship between the EnergyDensity function arguments and the T_ANALYSIS structure initialization from LoadAnalysis.
Sub Main
'Document cleanup DeleteRays() ARNDeleteAllNodes() ClearOutputWindow()
'We are interested in calculating the analysis for rays on this surface Dim nSurf As Long nSurf = FindFullName( "Geometry.Detector.Surface" )
'We want to use a T_ANALYSIS grid specification identical to 'one of our existing analysis surfaces. This specifies which 'analysis surface we want to copy the template from. Dim anaNode As Long anaNode = FindFullName( "Analysis Surface(s).Detector Analysis" )
'Use the analysis node as a template for our T_ANALYSIS structure 'by calling the LoadAnalysis function 'NOTE: The structure is expressed in GLOBAL COORDINATES Dim tAna As T_ANALYSIS LoadAnalysis( anaNode, tAna )
'Create and trace the active source EnableTextPrinting(False) TraceCreate() EnableTextPrinting(True)
'Calculation 'Note that the second argument specifies the coordinate system of the 'T_ANALYSIS structure. Since we used LoadAnalysis, this needs to be 'in Global Coordinates (i.e. -1) Dim data() As Double EnableTextPrinting(False) EnergyDensity( nSurf, -1, tAna, data() ) EnableTextPrinting(True)
'Now that we have the array of values, compute the statistics 'of the result. Dim dMin As Double, dMax As Double, dAve As Double, dSd As Double Dim minLoc() As Long, maxLoc() As Long ArrayStats( data(), dMin, dMax, dAve, dSd, minLoc(), maxLoc() )
'Print the result Print "" Print "Distribution statistics:" Print "Minimum value: " & Chr(9) & dMin Print "Maximum value: " & Chr(9) & dMax Print "Average value: " & Chr(9) & dAve Print "Standard deviation: " & Chr(9) & dSd Print "Pixel coordinates of minimum value: " & Chr(9) & minLoc(0) & Chr(9) & minLoc(1) Print "Pixel coordinates of maximum value: " & Chr(9) & maxLoc(0) & Chr(9) & maxLoc(1) Print ""
End Sub
See Also
|