Navigation: Scripting Reference Manual > Functions & Subroutines > ARNAccumulate

 

ARNAccumulate

 

Contact Us: fredsupport@photonengr.com

 

Description

Performs a linear combination of multiple ARNs and creates a new ARN that contains the resulting data.  The new ARN data is formed from dNew = SF1*d1 + SF2*d2 + ... + SFN*dN, where dN represents the data array of the N'th ARN in the linear combination and SFN represents the scale factor applied to each cell in the data array dN.  This script function is different from the ARNLinearCombination routine in that ARNAccumulate operates on an arbitrary number of ARNs while ARNLinearCombination only operates on two ARNs.  The ARNAccumulate() function provides script functionality equivalent to the Linear Combination option in the GUI.

 

This function requires that the ARNs being accumulated have the same data type (ex. double, complex, etc.) and the same data grid shape.

 

Syntax

newARN = ARNAccumulate( arnList(), sf() )

 

Parameters

newARN (Long)

Return value indicating the node number of the newly created ARN that contains the accumulated data.

 

arnList( ) As Long

An array of ARN node numbers whose data will be scaled and combined.  At least one ARN must be provided in arnList().  See Example 3 below demonstrating how to scale the data in a single ARN.

 

sf() As Double

An array of scale factors applied to the data in each ARN of the corresponding arnList() array.  If the sf() array is length 1 (i.e. Dim sf(0) As Double ), then the scale factor value in the array will be applied to all nodes in the arnList() array.  Otherwise, the sf() array must be the same length as the arnList() array and the scale factor value at each index in the sf() array is applied to the corresponding ARN at the same index in the arnList() array.

 

Example 1 - Single sf() Array Value

The example below performs a raytrace inside of a loop with 10 iterations.  For each iteration, an Irradiance analysis is performed and the result is sent to an ARN and the node number of each ARN is stored in an array variable called arnList().  The scale factors array is defined as a single array element with the value 1/nIter, with the single array element size indicating that the supplied scale factor should be applied to all ARNs in the arnList() array.  ARNAccumulate is called (the data in this ARN is the average irradiance distribution for the 10 iterations) and the resulting ARN is displayed in a chart window.

 

Sub Main

 

    'Delete existing nodes

    ARNDeleteAllNodes()

 

    Dim nIter As Long, ana As Long

    nIter = 10

    ana   = FindFullName( "Analysis Surface(s).Detector Entity 1 - Ana" )

 

    Dim curIter As Long, curArn As Long, arnList() As Long

    ReDim arnList(nIter-1)

    For curIter = 1 To nIter

        'Raytrace and perform analysis

        TraceCreate()

        IrradianceToARN( ana, "Irradiance Iter " & CStr(curIter), curArn )

 

        'Store the analysis result node number in an array for later

        arnList(curIter-1) = curArn

    Next

 

    'Define the scale factor for each ARN

    'If scale factor array is length 1, value applies to all ARNs in the list

    Dim sf(0) As Double

    sf(0) = 1/nIter

 

    'Perform the linear combination and display the result

    Dim accumARN As Long

    accumARN = ARNAccumulate( arnList(), sf() )

    ARNSetName( accumARN, "Average Irradiance - Scripting" )

    ARNDisplayInChart( accumARN, "" )

 

End Sub

 

Example 2 - sf() Array of Length N

The example below is a variation on Example 1 except that the sf() array is dimensioned to have the same length as arnList() and each index of the sf() array is populated with a scale factor value.  Note that in this example all values in the sf() array are equal to 1/nIter, but this is not a general requirement.  The sf() array values can be unique scale factors applied to each corresponding ARN in the arnList() array.

 

Sub Main

 

    'Delete existing nodes

    ARNDeleteAllNodes()

 

    Dim nIter As Long, ana As Long

    nIter = 10

    ana   = FindFullName( "Analysis Surface(s).Detector Entity 1 - Ana" )

 

    Dim curIter As Long, curArn As Long, arnList() As Long, sf() As Double

    ReDim arnList(nIter-1)

    ReDim sf(nIter-1)

    For curIter = 1 To nIter

        'Raytrace and perform analysis

        TraceCreate()

        IrradianceToARN( ana, "Irradiance Iter " & CStr(curIter), curArn )

 

        'Store the analysis result node number in an array for later

        'Populate scale factors array

        arnList(curIter-1) = curArn

        sf(curIter-1)      = 1/nIter

    Next

 

    'Perform the linear combination and display the result

    Dim accumARN As Long

    accumARN = ARNAccumulate( arnList(), sf() )

    ARNSetName( accumARN, "Average Irradiance - Scripting" )

    ARNDisplayInChart( accumARN, "" )

 

End Sub

 

Example 3 - Scaling a Single ARN

The example below demonstrates how to scale the data of a single ARN using the ARNAccumulate() function.

 

Sub Main

          

    Dim arn(0) As Long, sf(0) As Double, newARN As Long

    arn(0) = ARNFindName( "Irradiance Iter 1" )

    sf(0)  = 0.1

    newARN = ARNAccumulate( arn(), sf() )

    ARNDisplayInChart( newARN, "" )

 

End Sub

 

See Also

All ARN Scripting Commands

ARNLinearCombination

 

 

 

 

 

Copyright © Photon Engineering, LLC