Formulas
The CSL language is centered around formulas and rules. Formulas establish values for a module’s outputs.
A formula is essentially a named expression. Here is a typical example from aPriori’s plastic molding starting points:
 
computedCycleTime = (injectTime + coolTime + ejectTime ) / numCavities
 
In this formula, injectTime, coolTime, ejectTime, and numCavities (number of mold cavities) refer to other formulas in the same module. In the course of evaluating a given formula, the cost engine evaluates the formulas and rules referred to by the given formula. Here is the formula for coolTime:
 
coolTime = 0 - _
(((nominalWallThickness)^2)/(2*constants.pi*thermalDiffusivity) _
*ln((constants.pi/4)*(ejectDeflectionTemp - moldTemp)/ _
(meltingTemp - moldTemp)))
 
Here, nominalWallThickness is derived from a setup option. constants is a standard input that provides access to useful constants such as pi. thermalDiffusivity, ejectDeflectionTemp, moldTemp, and meltingTemp are all derived from attributes of the current material, with the following formulas:
 
thermalDiffusivity = material.thermalDiffusivity
moldTemp = material.moldTemp
meltingTemp = material.meltingTemp
ejectDeflectionTemp = material.ejectDeflectionTemp
 
In these formulas, material is a standard input. It has a field (such as meltingTemp) for each material attribute (as listed in the Material Composition table of aPriori’s Material Selection dialog). CSL code accesses fields of an input with the dot notion shown above.
Note that the cost engine generally evaluates only those formulas that must be evaluated in order to assign values to the module’s outputs (but see Set Blocks in Cost Scripting Language Reference). So some formulas in a module might never be evaluated.
In addition to formulas, CSL also supports function definitions, which are essentially parameterized formulas. Here is an example:
 
GetLaborCost(laborTime, laborRate) = laborRate * laborTime / SEC_PER_HR
 
Function invocation expressions specify actual parameters for the definition’s formal parameters. CSL includes a number of predefined functions, such as ln, the natural logarithm function, used above in the coolTime formula. See Predefined Functions in Cost Scripting Language Referencefor a list of predefined functions.
A formula or function definition must end with a line break. Line breaks in the middle of a formula or function definition are generally allowed only through the use of a line continuation, a space followed by an underscore, as shown in the coolTime formula, above.