### 17.1.4. Example 4: Creating a Complex Quantitative Subroutine

This example is a complex quantitative subroutine that takes slices through the manifold geometry, as shown below, compares the mass flow through the two sides of the initial branch, and computes the pressure drop through to the four exit locations.

    ! sub manifoldCalcs{
    # call the previously defined subroutine (Example 3) make the
    # upstream and downstream cutting planes
    ! makePlanes();
    #
    # Bound the two planes so they each just cut one side of the branch.
    PLANE:plane1
    Plane Bound = Circular
    Bound Radius = 0.025
    END
    PLANE:plane2
    Plane Bound = Circular
    Bound Radius = 0.025
    END
    # Calculate mass flow through each using the predefined
    # 'evaluate' Power Syntax subroutine and output the results
    ! ($mass1, $mfunits) = evaluate( "massFlow()\@plane1" );
    ! ($mass2) = evaluate( "massFlow()\@plane2" );
    ! $sum = $mass1+$mass2;
    ! print "Mass flow through branch 1 = $mass1 [$mfunits]\n";
    ! print "Mass flow through branch 2 = $mass2 [$mfunits]\n";
    ! print "Total = $sum [$mfunits]\n";
    # Now calculate pressure drops and mass flows through the exits
    # calculate the average pressure at the inlet
    !($Pin, $punits) = evaluate( "massFlowAve(Pressure)\@in1" );
    # Set-up an array that holds the approximate X location of each
    # of the 4 exits. We then loop over the array to move the outlet
    # plane and re-do the pressure drop calculation at each exit.
    ! @Xlocs = (0.15,0.25,0.35,0.45);
    ! $sum = 0;
    ! for ($i=0;$i<4;$i++) {
    PLANE:outlet
       Option = Point and Normal
       Normal = 0,-1,-1
       Point = $Xlocs[$i],-0.06,-0.2
       Plane Bound = Circular
       Bound Radius = 0.05
    END
    ! ($Pout, $punits) =  evaluate( "massFlowAve(Pressure)\@outlet" );
    ! ($massFl) = evaluate( "massFlow()\@outlet" );
    ! $sum += $massFl;
    ! $Dp = $Pin-$Pout;
    ! $ii = $i+1;
    ! print "At outlet \#$ii: Dp=$Dp [$punits], Mass Flow=$massFl [$mfunits]\n";
    ! } # end loop
    ! print "Total Mass Flow = $sum  [$mfunits]\n";
    !} # end subroutine

After processing these commands to define the subroutine, you can execute it, in the same way as any other subroutine, by typing `!manifoldCalcs();` in the Command Editor dialog box.

Release 18.2 - © ANSYS, Inc. All rights reserved.