17.1.2. Example 2: Using a for Loop

This example demonstrates using Power Syntax that wraps a for loop around some CCL Object definitions to repetitively change the visibility on the outer boundaries.

# Make the outer boundaries gradually transparent in
# the specified number of steps.
!$numsteps = 10;
!for ($i=0; $i < $numsteps; $i++) {
   ! $trans = ($i+1)/$numsteps;
   BOUNDARY:in
      Visibility = 1
      Transparency = $trans
   END
   BOUNDARY:out
      Visibility = 1
      Transparency = $trans
   END
   BOUNDARY:Default
      Visibility = 1
      Transparency = $trans
   END
!}

The first line of Power Syntax simply defines a scalar variable called numsteps. Scalar variables (that is, simple single-valued variables) begin with a $ symbol in Perl. The next line defines a for loop that increments the variable i up to numsteps. Next, you determine the fraction you are along in the loop and assign it to the variable trans. The object definitions then use trans to set their transparency and then repeat. Note how Perl variables can be directly embedded into the object definitions. The final line of Power Syntax (!}) closes the for loop.


Note:  Function-specific Perl subroutines do not allow phase-specific evaluations; that is, you can get only bulk results (such as mass flow for all phases). A workaround is to use "evaluate" subroutine, which evaluates any CEL expression.

For example instead of

! $val = massFlow("Inlet", "Water")   # Does NOT work

you need to use:

! ($val, $units) = evaluate( "Water.massFlow()\@Inlet");