constant

constant

Describes a function with a constant return value.

Constant UserFunc Parameters

UserFuncs with kind=constant take the following attribute:

value (vector of floats)

The vector-valued result of the function.

Examples

This example shows a function that returns whether the point (x,y) falls within a rod, where the rod centers are specified in a list (and the rods extend in the z direction). (Such a list cannot be used directly in a UserFunc expression, though one can use the vector(…) function. However, here the constant function gets around that problem.)

$ ROD_RADII = 0.2
$ ROD_CENTERS_X = [1. 0.5   -0.5 -1. -0.5   0.5]
$ ROD_CENTERS_Y = [0. 0.866 0.866 0. -0.866 -0.866]
<UserFunc isInRod>
  kind = expression
  inputOrder = [ x y ]
  <Input x>
    kind = arbitraryVector
    types = [float]
  </Input>
  <Input y>
    kind = arbitraryVector
    types = [float]
  </Input>
  <UserFunc rcx>
    kind = constant
    value = ROD_CENTERS_X
  </UserFunc>
  <UserFunc rcy>
    kind = constant
    value = ROD_CENTERS_Y
  </UserFunc>
  expression = or( (x-rcx)^2 + (y-rcy)^2 < ROD_RADII^2 )
</UserFunc>

This expression uses folding and threading to return 1 if (x,y) is within at least one of the rods, or 0 if (x,y) is not within any of the rods. Briefly, the subtracting, squaring, addition, and less-than operators are threaded through the vector values of rcx and rcy, yielding a vector such as vector(0,0,0,1,0,0), indicating that (x,y) falls within the fourth rod (but not any of the other rods). The or-function is then folded over the vector, yielding 1 if any element of the vector is 1.