# This subroutine collects all turbo-related parameters for the current
# problem:
#  $inletLoc    - inlet region(s)
#  $outletLoc   - outlet region(s)
#  $bladeRowLoc - rotor lade region(s)
#  $nMainBlades - number of main rotor blades in 360
#  $pref        - reference pressure
#  $omega       - rotor angular velocity
#  $axis        - component of the internally generated COORDINATE FRAME, pointing
#                 in direction of the rotation axis (i.e. z_rotaxInternal)
#

! no warnings 'redefine';
! use strict;
!
! sub collectTurboInfo {
!
! my ($domainList) = @_;
! my @domains = ();
! my ($domain, $angVel, $axisFrom, $axisTo);
!
! my ($inletLoc, $outletLoc, $bladeRowLoc, $axis, $omega, $nMainBlades, $pref);
!
# Currently,  we should only allow turbo macro calculations for 
# 1. a list of individual domains
# 2. a single domain group.
! if ( $domainList !~ m/[,]+/g && getType($domainList) eq "DOMAIN GROUP" ) {
!   $domainList = getValue($domainList, "Member List");
!   @domains = split(/\s*,\s*/, $domainList );
!   foreach $domain ( @domains ) {
    # Test for global inlet (no upstream domain)
!     if( !getValue( $domain, "UpStream Domain" ) ) {
!       $inletLoc = getValue( $domain, "Inlet Region" );
!     }
      # Test for global outlet (no upstream domain)
!     if( !getValue( $domain, "DownStream Domain" ) ) {
!       $outletLoc = getValue( $domain, "Outlet Region" );
!     }
      # Test for rotating domain (non-zero angular velocity)
!     $angVel = getValue( $domain, "Angular Velocity" );
!     if( $angVel && getExprVal($angVel) ) {
!       $omega = $angVel;
!       $nMainBlades = getValue( $domain, "Number of Components in 360" );
!       $bladeRowLoc = getValue( $domain, "Blade Region" );
!       $axisFrom = getValue( $domain, "Current Rotation Axis From" );
!       $axisTo = getValue( $domain, "Current Rotation Axis To" );
!     }
!     $pref = getValue( $domain, "Reference Pressure" );
!   } # for each domain
! } 
! else {
    # if individual domains are specificed, we assume 
    # that the list order is the order of connection
!   @domains = split(/\s*,\s*/, $domainList );
!   if ( $domains[0] ) {
!     $inletLoc = getValue( $domains[0], "Inlet Region" );
!   }
!   if ( $domains[$#domains] ) {
!     $outletLoc = getValue( $domains[$#domains], "Outlet Region" );
!   }
!   foreach $domain ( @domains ) {
      # Test for rotating domain (non-zero angular velocity)
!     $angVel = getValue( $domain, "Angular Velocity" );
!     if( $angVel && getExprVal($angVel) ) {
!       $omega = $angVel;
!       $nMainBlades = getValue( $domain, "Number of Components in 360" );
!       $bladeRowLoc = getValue( $domain, "Blade Region" );
!       $axisFrom = getValue( $domain, "Current Rotation Axis From" );
!       $axisTo = getValue( $domain, "Current Rotation Axis To" );
!     }
!     $pref = getValue( $domain, "Reference Pressure" );
!   } # for each domain
! }
!
! if ( defined $nMainBlades && $nMainBlades <= 0 ) {
!   reportError( "Number of Main Blades has to be greater than zero." );
!   return ();
! }
! if ( defined $bladeRowLoc && !$bladeRowLoc ) {
!   reportError( "Blade row region has to be specified." );
!   return ();
! }

# Construct a Coord Frame object and set Z to point in the direction of
# the rotation axis. This object is needed for quantitative.
! if ( $axisFrom && $axisTo ) {
!   if ( $axisFrom eq $axisTo ) {
!     reportError( "Axis of Rotation From and To must be differnt points." );
!     return ();
!   }
!   my @axisFromComp = split(/\s*,\s*/, $axisFrom );
!   my @axisToComp = split(/\s*,\s*/, $axisTo );
!   if ( @axisFromComp < 3 || @axisToComp < 3 ) {
!     reportError( "Axis of rotation is not correctly specified (three floats per point needed)." );
!     return ();
!   }

!   if( verboseOn() ) {
!     print "\nInput to performance calculation:\n";
!     print "  Inlet Region = $inletLoc\n";
!     print "  Outlet Region = $outletLoc\n";
!     print "  Blade Row Region = $bladeRowLoc\n";
!     print "  Reference Pressure = $pref\n";
!     print "  Omega = $omega\n";
!     print "  Number of Main Blades = $nMainBlades\n";
!     print "  Rotation Axis = ($axisFrom) - ($axisTo)\n";
!   }

!   my ($av0,$au0) = evaluate($axisFromComp[0]);
!   my ($av2,$au2) = evaluate($axisFromComp[2]);
!   my $a0 = ++$av0 . " [$au0]";
!   my $a2 = ++$av2 . " [$au2]";

    COORDINATE FRAME: rotaxInternal
      Axis 3 Point = $axisToComp[0], $axisToComp[1], $axisToComp[2]
      Coord Frame Type = Cartesian
      Origin Point = $axisFromComp[0], $axisFromComp[1], $axisFromComp[2]
      Plane 13 Point = $a0, $axisFromComp[1], $a2
    END
    # In case we are processing this as a part of an 11.0 session file,
    # ensure the coord frame is hidden
    > hide rotaxInternal
!   $axis = "z_rotaxInternal";
! }
! 
! return ($inletLoc, $outletLoc, $bladeRowLoc, $axis, $omega, $nMainBlades, $pref);
!
! }

#
# Subroutine to construct blade torque expression
! sub getBladeTorqueExpr {
!
! my ($bladeRegionStr, $rotationAxis) = @_;
! my @bladeRegionList = split(/\s*,\s*/,$bladeRegionStr);
! my $bladeTorqueExpr="";
!
! if ( @bladeRegionList < 1 ) {
!   reportError( "At least one blade region must be specified." );
!   return $bladeTorqueExpr;
! }
!
! my $isValidBlade = 1;
! if ( @bladeRegionList > 1 ) {
!   foreach my $blade ( @bladeRegionList ) {
!      if (getType($blade) ne "BOUNDARY" ) {
!        $isValidBlade = 0;
!        last;
!      }
!   }
! }
!
! $bladeTorqueExpr = "torque_$rotationAxis\(\)\@$bladeRegionList[0]";
! for (my $b=1; $b < @bladeRegionList; $b++) {
!   $bladeTorqueExpr .= " \+ torque_$rotationAxis\(\)\@$bladeRegionList[$b]"; 
! }
!
! return ($bladeTorqueExpr, $isValidBlade);
! }
!
#
# Subroutine to construct blade force expression
! sub getBladeForceExpr {
!
! my ($bladeRegionStr, $rotationAxis) = @_;
! my @bladeRegionList = split(/\s*,\s*/,$bladeRegionStr);
! my $bladeForceExpr="";
!
! if ( @bladeRegionList < 1 ) {
!   reportError( "At least one blade region must be specified." );
!   return $bladeForceExpr;
! }
!
! my $isValidBlade = 1;
! if ( @bladeRegionList > 1 ) {
!   foreach my $blade ( @bladeRegionList ) {
!      if (getType($blade) ne "BOUNDARY" ) {
!        $isValidBlade = 0;
!        last;
!      }
!   }
! }
!
! $bladeForceExpr = "force_$rotationAxis\(\)\@$bladeRegionList[0]";
! for (my $b=1; $b < @bladeRegionList; $b++) {
!   $bladeForceExpr .= " \+ force_$rotationAxis\(\)\@$bladeRegionList[$b]"; 
! }
!
! return ($bladeForceExpr, $isValidBlade);
! }
!
! sub getExprOnLocators {
!
! my ($exprStr, $locatorStr) = @_;
! my @locators = split(/\s*,\s*/,$locatorStr);
! my $outExprStr="";
!
! if ( @locators < 1 ) {
!   reportError( "Empty locator list." );
!   return $outExprStr;
! }
!
# remove component tag
! $locators[0] =~ s/.*\s*:\s*(.*)$/$1/;
! $outExprStr = $exprStr . "\@$locators[0]";
! for (my $l=1; $l < @locators; $l++) {
!   $locators[$l] =~ s/.*\s*:\s*(.*)$/$1/;
!   $outExprStr .= " \+ $exprStr\@$locators[$l]"; 
! }
!
! return $outExprStr;
! }


