#### Centrifugal Compressor Report Template

COMMAND FILE:
  CFX Post Version = 15.0
END


#### Report Description

REPORT:
  Excluded Report Items = /COMMENT:User Data
  REPORT PROPERTIES:
    Report Template Name = Centrifugal Compressor Report (Beta)
    Keywords = turbo, centrifugal, radial, rotor
    Report Template Description = A report for a centrifugal compressor analysis.
    Report Support Level = Beta
  END
  PUBLISH:
    Default Report Name = Centrifugal Compressor Report (Beta)
    Report Path = ./CentrifugalCompressorReport.htm
  END
  FILE INFORMATION OPTIONS: 
    Include In Report = false
  END
  MESH STATISTICS OPTIONS: 
    Include In Report = false
  END
  PHYSICS SUMMARY OPTIONS: 
    Include In Report = false
  END
END
TITLE PAGE:
  Report Title = Centrifugal Compressor Report (Beta)
END


! use PlotToolsTBRBetaExt;
! use TurboSystemExt;
! use TurboStageExt;
! use BladeLoadingChartExt;
! use StreamwiseChartExt;
! use SpanwiseChartExt;
! use strict;
! no warnings qw(redefine);


#### runCCL - Needed to run CCL from the perl modules

! sub runCCL
! {
!   my ($ccl, $echoOnly) = @_;
!   my @list = split('\n', $ccl);
!   my $line;
!   foreach $line (@list) {
#!     print $line,"\n";
!     if (!$echoOnly) {
$line
!     }
!   }
! }


#### Turbo Initialization

# Run the Post turbo initialization
> turbo init
> turbo more_vars

# Set the default span locations for plots and charts
! my @spanLoc = (0.5);

# Select the active case to post-process
! my $case_name = getValue('DATA READER', 'Active Case Name');

# Create and initialize the TurboSystem object
! my $ts = new TurboSystemExt($case_name);
! $ts->InitializeFromPostTurboInfo();
! $ts->CreateLocators();
! $ts->SortComponents();

# Assume compressible flow if not already set by TurboSystem property
! $ts->FlowType('Compressible');

#! $ts->Dump();

# Determine if solution contains TBR data (Fourier Storage)
! my $extTBR = PlotToolsTBRBetaExt::isCaseTBR() ? '.Trnavg' : '';  # Set variable extension to be the transient average

# Determine the stages for a compressor, where each stage begins with a rotor
# This algorithm is very simplistic and considers IGV's, EGV's and volutes as part of the stage
! sub DetermineCompressorStages {
!   my ($system) = @_;
!   my @stageList = ();
#   Label the stages as 'Stage 1', 'Stage 2', etc.
!   my $label = 'Stage ';
!   my $i = 1;
!   my $stage = new TurboStageExt( 'Stage ' . $i );
!   foreach my $comp (@{$system->Components()}) {
!     if ( $comp->Type() eq 'Rotor' && $stage->NumComponents() > 0) {
!       push(@stageList, $stage);
!       $i++;
!       $stage = new TurboStageExt( 'Stage ' . $i );
!     }
!     $stage->AddComponent($comp);
!   }
!   push(@stageList, $stage);
!   return @stageList;
! }
! my @stages = DetermineCompressorStages($ts);


#### Define the default expressions for all machine types

# The second (optional) argument (+/-1) specifies the sign convention for the
# tangential direction.  If left unspecified, it will be computed based on the
# sign of omega for the first rotor.  If no rotor exists, it will be 1.
! PlotToolsTBRBetaExt::CreateCommonCEL($ts);


#### Complete Meridional View

COMMENT:Introduction
  Comment Heading = Introduction
  Heading Level = 1
  Comment Text = \
  <p>This report summarizes the results of a CFD analysis performed for the centrifugal compressor geometry shown in Figure 1.  In the following sections both quantitative and qualitative results are presented in the form of tables, charts and plots.</p>
END

!   PlotToolsTBRBetaExt::CreateMeridionalGeometryView( 'Complete', $ts->Components() );


#### Performance Results

COMMENT:Performance Results
  Comment Heading = Performance Results
  Heading Level = 1
  Comment Text = \
  <p>The quantitative results are summarized in the following tables.  The first table shows the overall performance.  The next series of tables shows the performance results for each stage.</p>
END


#### Overall Performance Results

COMMENT:Overall Performance Results
  Comment Heading = Overall Performance Results
  Heading Level = 2
  Comment Text = \
  <p>The following table gives the overall performance for the machine.</p>
END

!sub CreateOverallTable {
!  my ($system) = @_;

!  my $hasRotor = $system->HasRotor();
!  my $firstName = $system->FirstComponent()->Name();
!  my $lastName = $system->LastComponent()->Name();
!  my $lastOut = $system->LastComponent()->OutletName();
!  my @list = ();

# Create the expresssions
LIBRARY:
  CEL:
    EXPRESSIONS:

!  if ( $hasRotor ) {
!    if ( exprExists("$firstName mfr") ) {
!      push(@list, 'Inlet Mass Flow Rate', "$firstName mfr", '%7.4f');
!    }
!    if ( exprExists("$firstName Q0 in") && exprExists("$lastName Pt out") ) {
!      push(@list, 'Inlet Volume Flow Rate', "$firstName Q0 in", '%7.4f');
!    }
!    if ( ! $extTBR && exprExists("$firstName Pt in") && exprExists("$lastName Pt out") ) {
       Total Pressure Ratio = ($lastName Pt out + Reference Pressure)/($firstName Pt in + Reference Pressure)
!      push(@list, 'Total Pressure Ratio', 'Total Pressure Ratio', '%7.4f');
!    }
!    if ( ! $extTBR && exprExists("$firstName Tt in") && exprExists("$lastName Tt out") ) {
       Total Temperature Ratio = $lastName Tt out / $firstName Tt in
!      push(@list, 'Total Temperature Ratio', 'Total Temperature Ratio', '%7.4f');
!    }
!    if ( ! $extTBR && objectExists('Isentropic Compression Efficiency') ) {
       Effs out = 100 * massFlowAve(Isentropic Compression Efficiency)@$lastOut
!      push(@list, 'Total-to-Total Isentropic Efficiency %', 'Effs out', '%7.4f');
!    }
!    if ( ! $extTBR && objectExists('Polytropic Compression Efficiency') ) {
       Effp out = 100 * massFlowAve(Polytropic Compression Efficiency)@$lastOut
!      push(@list, 'Total-to-Total Polytropic Efficiency %', 'Effp out', '%7.4f');
!    }
!  }
!  else {
!    push(@list, 'Inlet Mass Flow Rate', "$firstName mfr", '%7.4f');
!    if ( ! $extTBR && exprExists("$firstName Q0 in") ) {
!      push(@list, 'Inlet Volume Flow Rate', "$firstName Q0 in", '%7.4f');
!    }
!    if ( ! $extTBR && exprExists("$firstName Pt in") && exprExists("$lastName Pt out") ) {
       Total Pressure Ratio = ($lastName Pt out + Reference Pressure)/($firstName Pt in + Reference Pressure)
!      push(@list, 'Total Pressure Ratio', 'Total Pressure Ratio', '%7.4f');
!    }
!  }

    END
  END
END

!  PlotToolsTBRBetaExt::CreateResultsTable('Overall Performance Results Table', 'Overall Performance Results Table', @list);
!}

! CreateOverallTable($ts);


#### Stage Performance Results

COMMENT:Stage Performance Results
  Comment Heading = Stage Performance Results
  Heading Level = 2
  Comment Text = \
  <p>The following table(s) give a summary of the performance results for each stage.</p>
END

# Define the expressions specific to axial compressors
!sub CreateStageTable {
!  my ($stage) = @_;

!  my $name = $stage->Name();

# Find the rotor, if it exists
!  my $rotor = $stage->Rotor();

!  my @list = ();

# Create the expresssions
LIBRARY:
  CEL:
    EXPRESSIONS:

!  if ( $rotor ) {
!    my $rotorName = $rotor->Name();
!    my $rotorOut = $rotor->OutletName();
!    my $lastName = $stage->LastComponent()->Name();
!    my $lastOut = $stage->LastComponent()->OutletName();

!    push(@list, 'Rotation Speed', $rotorName . ' omega', '%7.4f');

!    if ( exprExists("$rotorName mfr") ) {
!      push(@list, 'Mass Flow Rate', "$rotorName mfr", '%7.4f');
!    }

!    if ( exprExists($rotorName . ' Q0 in') ) {
!      push(@list, 'Inlet Volume Flow Rate', "$rotorName Q0 in", '%7.4f');
!    }

!    if ( exprExists("$rotorName D te") ) {
       $name R ref = $rotorName D te * 0.5
!      push(@list, 'Reference Radius', "$name R ref", '%7.4f');
!    }

!    if ( ! $extTBR && exprExists("$rotorName mfr") && exprExists("$rotorName Ht in") ) {
       $name Input Power = $rotorName mfr * ($lastName Ht out - $rotorName Ht in)
!      push(@list, 'Input Power', "$name Input Power", '%7.4f');
!    }

!    if ( exprExists("$rotorName Q0 in") && exprExists("$rotorName U te") && exprExists("$rotorName D te") ) {
       $name Inlet Flow Coefficient = $rotorName Q0 in / ($rotorName U te * $rotorName D te^2)
!      push(@list, 'Inlet Flow Coefficient', $name . ' Inlet Flow Coefficient', '%7.4f');
!    }

!    if ( exprExists("$rotorName U le") && exprExists("$rotorName Ht in") ) {
       $name Work Input Coefficient = ($rotorName Ht out - $rotorName Ht in) / $rotorName U te^2
!      push(@list, 'Work Input Coefficient', "$name Work Input Coefficient", '%7.4f');
!    }

!    if ( ! $extTBR && exprExists("$lastName Pt out") && exprExists("$rotorName Pt in") ) {
       $name Total Pressure Ratio = ($lastName Pt out + Reference Pressure)/($rotorName Pt in + Reference Pressure)
!      push(@list, 'Total Pressure Ratio', "$name Total Pressure Ratio", '%7.4f');
!    }

!    if ( ! $extTBR && exprExists("$lastName Tt out") && exprExists("$rotorName Tt in") ) {
       $name Total Temperature Ratio = $lastName Tt out / $rotorName Tt in
!      push(@list, 'Total Temperature Ratio', "$name Total Temperature Ratio", '%7.4f');
!    }

!    if ( exprExists("$lastName Hp out") && exprExists("$rotorName Hp in") && exprExists("$rotorName U te") ) {
       $name Polytropic Head = $lastName Hp out - $rotorName Hp in
!      push(@list, 'Polytropic Head', "$name Polytropic Head", '%7.4f');
       $name Polytropic Head Coefficient = $name Polytropic Head / $rotorName U te^2
!      push(@list, 'Polytropic Head Coefficient', "$name Polytropic Head Coefficient", '%7.4f');
!      if ( ! $extTBR && exprExists("$lastName Ht out") && exprExists("$rotorName Ht in") ) {
         $name Effp out = 100 * $name Polytropic Head / ($lastName Ht out - $rotorName Ht in)
!        push(@list, 'Total-to-Total Polytropic Efficiency %', $name . ' Effp out', '%7.4f');
!      }
!    }

!    if ( ! $extTBR && exprExists("$lastName Pt out") && exprExists("$rotorName Pt te") && exprExists("$rotorName P te") && exprExists("$lastName P out") ) {
       $name Diffuser Y1 = ($rotorName Pt te - $lastName Pt out)/($rotorName Pt te + Reference Pressure)
!      push(@list, 'Diffuser Loss Coef., Y1', "$name Diffuser Y1", '%7.4f');
       $name Diffuser Y2 = ($rotorName Pt te - $lastName Pt out)/($lastName Pt out + Reference Pressure)
!      push(@list, 'Diffuser Loss Coef., Y2', "$name Diffuser Y2", '%7.4f');
       $name Diffuser Y3 = ($rotorName Pt te - $lastName Pt out)/($rotorName Pt te - $rotorName P te)
!      push(@list, 'Diffuser Loss Coef., Y3', "$name Diffuser Y3", '%7.4f');
       $name Diffuser Y4 = ($rotorName Pt te - $lastName Pt out)/($lastName Pt out - $lastName P out)
!      push(@list, 'Diffuser Loss Coef., Y4', "$name Diffuser Y4", '%7.4f');
       $name Diffuser Cp = ($lastName P out - $rotorName P te)/($rotorName Pt te - $rotorName P te)
!      push(@list, 'Diffuser Cp', "$name Diffuser Cp", '%7.4f');
!    }
!  }
!  else {
!    my $firstComp = $stage->FirstComponent();
!    my $firstName = $firstComp->Name();
!    my $lastName = $stage->LastComponent()->Name();

!    if ( exprExists("$firstName mfr") ) {
!      push(@list, 'Mass Flow Rate', "$firstName mfr", '%7.4f');
!    }

!    if ( exprExists("$firstName Q0 in") ) {
!      push(@list, 'Inlet Volume Flow Rate', "$firstName Q0 in", '%7.4f');
!    }

!    if ( ! $extTBR && exprExists("$lastName Pt out") && exprExists("$firstName Pt in") && exprExists("$firstName P in") && exprExists("$lastName P out") ) {
       $name Diffuser Y1 = ($firstName Pt in - $lastName Pt out)/($firstName Pt in + Reference Pressure)
!      push(@list, 'Loss Coefficient, Y1', "$name Diffuser Y1", '%7.4f');
       $name Diffuser Y2 = ($firstName Pt in - $lastName Pt out)/($lastName Pt out + Reference Pressure)
!      push(@list, 'Loss Coefficient, Y2', "$name Diffuser Y2", '%7.4f');
       $name Diffuser Y3 = ($firstName Pt in - $lastName Pt out)/($firstName Pt in - $firstName P in)
!      push(@list, 'Loss Coefficient, Y3', "$name Diffuser Y3", '%7.4f');
       $name Diffuser Y4 = ($firstName Pt in - $lastName Pt out)/($lastName Pt out - $lastName P out)
!      push(@list, 'Loss Coefficient, Y4', "$name Diffuser Y4", '%7.4f');
       $name Diffuser Cp = ($lastName P out - $firstName P in)/($firstName Pt in - $firstName P in)
!      push(@list, 'Diffuser Cp', "$name Diffuser Cp", '%7.4f');
!    }
!  }

    END
  END
END

!  PlotToolsTBRBetaExt::CreateStageResultsTable("$name Performance Results", $stage, @list);
!}

# Create a performance results table for each stage
! foreach my $stage (@stages) { CreateStageTable($stage) }


#### Component Summary Data

COMMENT:Component Summary Data
  Comment Heading = Component Summary Data
  Heading Level = 1
  Comment Text = \
  <p>The table(s) below give a summary of the mass or area averaged solution variables and derived quantities computed at the inlet, leading edge (LE Cut), trailing edge (TE Cut) and outlet locations.  The flow angles Alpha and Beta are relative to the meridional plane.</p>
END

# Create a data table for each component
! foreach my $comp (@{$ts->Components()}) { PlotToolsTBRBetaExt::CreateComponentDataTable($comp) }


#### Meanline 1D Charts

COMMENT:Meanline 1D Charts
  Comment Heading = Meanline 1-D Charts
  Heading Level = 1
  Comment Text = \
  <p>The following charts show streamwise mass or area averaged quantities from the inlet to the outlet of the full machine.</p>
END

! if ( objectExists('Mach Number') ) {
!   my $streamchart1 = new StreamwiseChartExt( 'Streamwise Mach Number Chart' );
!   if ( $streamchart1 ) {
!     $streamchart1->Caption( 'Chart showing streamwise, area averaged relative Mach number versus averaged normalized M.' );
!     $streamchart1->AddLine( "Mach Number$extTBR", 'area', 5, "Mach$extTBR" );
!     $streamchart1->Plot();
!   }
! }

! if ( ! $extTBR && objectExists('Static Entropy') ) {
!   my $streamchart2 = new StreamwiseChartExt( 'Streamwise Entropy Chart' );
!   if ( $streamchart2 ) {
!     $streamchart2->Caption( 'Chart showing streamwise, mass averaged static entropy versus averaged normalized M.' );
!     $streamchart2->AddLine( 'Static Entropy', 'mass', 5, 's' );
!     $streamchart2->Plot();
!   }
! }


#### Stage Plots

COMMENT:Stage Plots
  Comment Heading = Stage Plots
  Heading Level = 1
  Comment Text = \
  <p>The following plots show, for each stage, a meridional view of the geometry, blade-to-blade contour and vector views, and circumferentially averaged meridional views.</p>
END

! foreach my $stage (@stages) {
!   my $label = $stage->Name();

COMMENT:$label Plots
  Comment Heading = $label Plots
  Heading Level = 2
  Comment Text =
END

#   Meridional Geometry View
!   PlotToolsTBRBetaExt::CreateMeridionalGeometryView( $stage->Name(), $stage->Components(), 1 );

#   Blade-to-blade views for each span location in @spanLoc
!   if ( objectExists('Mach Number') ) {
!     foreach my $loc (@spanLoc) {
!       PlotToolsTBRBetaExt::CreateBladetoBladeContourView( $stage->Name(), $stage->Components(), "Mach Number$extTBR", "M rel$extTBR", $loc );
!     }
!   }

!   foreach my $loc (@spanLoc) {
!     PlotToolsTBRBetaExt::CreateBladetoBladeVectorView( $stage->Name(), $stage->Components(), $loc );
!   }

!   if ( objectExists('Static Entropy') ) {
!     foreach my $loc (@spanLoc) {
!       PlotToolsTBRBetaExt::CreateBladetoBladeContourView( $stage->Name(), $stage->Components(), "Static Entropy$extTBR", "s$extTBR", $loc );
!     }
!   }

#   Meridional Contour views
!   PlotToolsTBRBetaExt::CreateMeridionalContourView( $stage->Name(), $stage->Components(), "Pressure$extTBR", "P$extTBR" );
!   if ( objectExists("Mach Number$extTBR") ) {
!     PlotToolsTBRBetaExt::CreateMeridionalContourView( $stage->Name(), $stage->Components(), "Mach Number$extTBR", "M rel$extTBR" );
!   }
!   PlotToolsTBRBetaExt::CreateMeridionalContourView( $stage->Name(), $stage->Components(), "Velocity$extTBR Meridional", "Cm$extTBR" );

!}


#### Component Charts

COMMENT:Component Charts
  Comment Heading = Component Charts
  Heading Level = 1
  Comment Text = \
  <p>The following charts show blade loading and spanwise-averaged quantities for each component.</p>
END


#### Blade Loading Charts

COMMENT:Blade Loading Charts
  Comment Heading = Blade Loading Charts
  Heading Level = 2
  Comment Text = \
  <p>The following charts show the blade loading for each component.</p>
END

! foreach my $comp (@{$ts->Components()}) {
!   if ( $comp->HasBlade() ) {
!     my $name = $comp->Name();
!     my $chart = new BladeLoadingChartExt( "$name Blade Loading Chart", "Pressure$extTBR", "P$extTBR" );
!     if ( $chart ) {
!       $chart->Caption( $name . ' blade loading chart (' . $comp->DomainShortName() . ')' );
!       foreach my $loc (@spanLoc) {
!         $chart->AddLine( $comp, $loc );
!       }
!       $chart->Plot();
!     }
!   }
! }


#### Spanwise Charts

COMMENT:Spanwise Charts
  Comment Heading = Spanwise Charts
  Heading Level = 2
  Comment Text = \
  <p>The following charts show circumferentially averaged quantities along hub-to-shroud lines located at the leading and trailing edges of the blade.</p>
END

!sub spancharts {
!   my $comp = shift;
!
!   if ( $comp->HasBlade() ) {
!     my $name = $comp->Name();
!     my $leLoc = $comp->LEStreamLoc();
!     my $teLoc = $comp->TEStreamLoc();

!     if ( objectExists("$name Flow Angle Alpha") && objectExists("$name Flow Angle Beta") ) {
!       my $chart = new SpanwiseChartExt( $name . ' Spanwise Flow Angles at LE Chart' );
!       if ( $chart ) {
!         $chart->Caption( $name . ' chart showing circumferentially averaged flow angle at the LE (' . $comp->DomainShortName() . ')' );
!         if ( $comp->Type() eq 'Rotor' ) {
!           if ( objectExists("$name Flow Angle Alpha") ) {
!             $chart->AddLine( "$name Flow Angle Alpha", $leLoc, 'area', 20, "Alpha" );
!           }
!           if ( objectExists("$name Flow Angle Beta") ) {
!             $chart->AddLine( "$name Flow Angle Beta", $leLoc, 'area', 20, "Beta" );
!           }
!         }
!         else {
!           if ( objectExists("$name Flow Angle Beta") ) {
!             $chart->AddLine( "$name Flow Angle Beta", $leLoc, 'area', 20, "Beta" );
!           }
!         }
!         $chart->Plot();
!       }
!     }

!     if ( objectExists("Mach Number$extTBR") ) {
!       my $chart = new SpanwiseChartExt( "$name Spanwise Relative Mach Number at LE Chart" );
!       if ( $chart ) {
!         $chart->Caption( $name . ' chart showing circumferentially averaged relative Mach number at the LE (' . $comp->DomainShortName() . ')' );
!         $chart->AddLine( "Mach Number$extTBR", $leLoc, 'area', 20, "M rel$extTBR" );
!         $chart->Plot();
!       }
!     }

!     if ( objectExists("$name Flow Angle Alpha") && objectExists("$name Flow Angle Beta") ) {
!       my $chart = new SpanwiseChartExt( $name . ' Spanwise Flow Angles at TE Chart' );
!       if ( $chart ) {
!         $chart->Caption( $name . ' chart showing circumferentially averaged flow angle at the TE (' . $comp->DomainShortName() . ')' );
!         if ( $comp->Type() eq 'Rotor' ) {
!           if ( objectExists("$name Flow Angle Alpha") ) {
!             $chart->AddLine( "$name Flow Angle Alpha", $teLoc, 'area', 20, "Alpha" );
!           }
!           if ( objectExists("$name Flow Angle Beta") ) {
!             $chart->AddLine( "$name Flow Angle Beta", $teLoc, 'area', 20, "Beta" );
!           }
!         }
!         else {
!           if ( objectExists("$name Flow Angle Beta") ) {
!             $chart->AddLine( "$name Flow Angle Beta", $teLoc, 'area', 20, "Beta" );
!           }
!         }
!         $chart->Plot();
!       }
!     }

!     if ( objectExists("Mach Number$extTBR") ) {
!       my $chart = new SpanwiseChartExt( $name . ' Spanwise Mach Number at TE Chart' );
!       if ( $chart ) {
!         if ( $comp->Type() eq 'Rotor' ) {
!           $chart->Caption( $name . ' chart showing circumferentially averaged relative and absolute Mach number at the TE (' . $comp->DomainShortName() . ')' );
!           $chart->AddLine( "Mach Number$extTBR", $teLoc, 'area', 20, "M rel$extTBR" );
!           if ( objectExists("Mach Number in Stn Frame$extTBR") ) {
!               $chart->AddLine( "Mach Number in Stn Frame$extTBR", $teLoc, 'area', 20, "M abs$extTBR" );
!           }
!         }
!         else {
!           $chart->Caption( $name . ' chart showing circumferentially averaged Mach number at the TE (' . $comp->DomainShortName() . ')' );
!           if ( objectExists("Mach Number in Stn Frame$extTBR") ) {
!               $chart->AddLine( "Mach Number$extTBR", $teLoc, 'area', 20, "M abs$extTBR" );
!           }
!         }
!         $chart->Plot();
!       }
!     }

!     if ( objectExists("Velocity$extTBR Meridional") ) {
!       my $chart = new SpanwiseChartExt( $name . ' Spanwise Meridional Velocity at TE Chart' );
!       if ( $chart ) {
!         $chart->Caption( $name . ' chart showing circumferentially averaged Cm at the TE (' . $comp->DomainShortName() . ')' );
!         $chart->AddLine( "Velocity$extTBR Meridional", $teLoc, 'area', 20, "Cm$extTBR" );
!         $chart->Plot();
!       }
!     }
!   }
! }

# Create spanwise charts for each component
! foreach my $comp (@{$ts->Components()}) { spancharts($comp) }

# Set initial view to first stage geometry view
! my $firstStage = $stages[0]->Name();
>setViewportView cmd=set, view=/VIEW:$firstStage Geometry Meridional View, viewport=1
>centerview 1

