Local UserFuncs are <UserFunc> blocks that appear within a UserFunc block
of kind = expression
(or within an <Expression> block), and can be called
by the expression. Local functions are accessible only within the
surrounding block.
Local functions can be used to simplify an expression; they can also be used to lookup values based on other simulation objects (such as fields).
The following UserFunc contains a local UserFunc named mySqr:
<UserFunc f>
kind = expression
inputOrder = [ y ]
<Input y>
kind = arbitraryVector
types = [float]
</Input>
<UserFunc mySqr>
kind = expression
inputOrder = [x]
<Input y>
kind = arbitraryVector
types = [float]
</Input>
expression = x*x
</UserFunc>
expression = mySqr(y)*mySqr(y+1) + y
</UserFunc>
The expression of <UserFunc f>
specifies the argument when it
calls mySqr. This example can be contrasted with that using Terms
(see Term Block).
While local UserFuncs and Terms (Term Block)
of kind = expression
may helpfully
simplify expressions, this may result in
decreased performance. Where speed is important, it may be better to use
pre-processor macros and pre-processor variables instead. For example,
in the above we could probably benefit by replacing UserFunc mySqr
with:
<macro mySqr(x)>
(x*x)
</macro>