#### Pump Report Template

COMMAND FILE:
  CFX Post Version = 12.0
END


#### Report Description

REPORT:
  Excluded Report Items = /COMMENT:User Data
  REPORT PROPERTIES:
    Report Template Name = Pump Report
    Keywords = turbo, axial, radial, turbine, rotor
    Report Template Description = A report for a pump analysis.
  END
  PUBLISH:
    Default Report Name = Pump Report
    Report Path = ./PumpReport.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 = Pump Report
END


! use PlotToolsExt;
! 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

# Determine if solution contains TBR data (Fourier Storage)
! if ( objectExists('Velocity.Trnavg') ) {
!   my $error = 'Transient Blade Row data exists.  This report is not suitable for transient data.';
!   if (defined(&CUEPost::reportError)) { CUEPost::reportError($error) }
!   else { print $error, "\n" }
! }

# 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 incompressible flow
! $ts->FlowType('Incompressible');

#! $ts->Dump();

# Determine the stages for a pump, where each stage begins with a rotor
# This algorithm is very simplistic and considers IGV's and volutes as part of the stage
!sub DeterminePumpStages {
!  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 = DeterminePumpStages($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.
! PlotToolsExt::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 pump 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

!   PlotToolsExt::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 ) {
!    my @rotors = ();
!    foreach my $comp (@{$system->Components}) {
!      if ( $comp->Type() eq 'Rotor' ) {
!        push(@rotors, $comp->Name());
!      }
!    }
     Inlet Volume Flow Rate = $firstName mfr / $firstName rho in
!    push(@list, 'Inlet Volume Flow Rate', 'Inlet Volume Flow Rate', '%7.4f');
!    push(@list, 'Reference Density', $firstName . ' rho in', '%7.4f');
     Head Rise = $lastName H out - $firstName H in
!    push(@list, 'Head Rise', 'Head Rise', '%7.4f');
!    my $power = join(' Shaft Power + ', @rotors) . ' Shaft Power';
     Input Power = $power
!    push(@list, 'Input Power', 'Input Power', '%7.4f');
!  }
!  else {
     Inlet Volume Flow Rate = $firstName mfr / $firstName rho in
!    push(@list, 'Inlet Volume Flow Rate', 'Inlet Volume Flow Rate', '%7.4f');
     Head Loss = $firstName H in - $lastName H out
!    push(@list, 'Head Loss', 'Head Loss', '%7.4f');
!  }

    END
  END
END
 
!  PlotToolsExt::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');
     $name Q in = $rotorName mfr / $name rho ref
!    push(@list, 'Inlet Volume Flow Rate', $name . ' Q in', '%7.4f');
     $name rho ref = $rotorName rho in
!    push(@list, 'Reference Density', $name . ' rho ref', '%7.4f');
     $name D ref = $rotorName D te * 0.5
!    push(@list, 'Reference Diameter', $name . ' D ref', '%7.4f');
     $name Input Power = $rotorName Shaft Power
!    push(@list, 'Input Power', $name . ' Input Power', '%7.4f');
     $name Capacity Coefficient = $name Q in/($rotorName n * $name D ref^3)
!    push(@list, 'Capacity Coefficient', $name . ' Capacity Coefficient', '%7.4f');
     $name Head Coefficient = g * ($lastName H out - $rotorName H in) / ($rotorName n * $name D ref)^2
!    push(@list, 'Head Coefficient', $name . ' Head Coefficient', '%7.4f');
     $name Power Coefficient = $rotorName Shaft Power / ($name rho ref * $rotorName n^3 * $name D ref^5)
!    push(@list, 'Power Coefficient', $name . ' Power Coefficient', '%7.4f');
     $name Head tt = $lastName H out - $rotorName H in
!    push(@list, 'Total-to-Total Head', $name . ' Head tt', '%7.4f');
     $name Head ts = $lastName Hp out - $rotorName H in
!    push(@list, 'Total-to-Static Head', $name . ' Head ts', '%7.4f');
     $name Eff tt = $name Q in * ($lastName Pt out - $rotorName Pt in) / $rotorName Shaft Power * 100
!    push(@list, 'Total-to-Total Efficiency %', $name . ' Eff tt', '%7.4f');
     $name Eff ts = $name Q in * ($lastName P out - $rotorName Pt in) / $rotorName Shaft Power * 100
!    push(@list, 'Total-to-Static Efficiency %', $name . ' Eff ts', '%7.4f');
     $name Diffuser Y1 = ($rotorName Pt te - $lastName Pt out)/$rotorName Pt te
!    push(@list, 'Diffuser Loss Coef., Y1', $name . ' Diffuser Y1', '%7.4f');
     $name Diffuser Y2 = ($rotorName Pt te - $lastName Pt out)/$lastName Pt out
!    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();
     $name Q in = $firstName mfr / $name rho ref
!    push(@list, 'Inlet Volume Flow Rate', $name . ' Q in', '%7.4f');
     $name rho ref = $firstName rho in
!    push(@list, 'Reference Density', $name . ' rho ref', '%7.4f');
     $name Head Loss = $firstName H in - $lastName H out 
!    push(@list, 'Head Loss', $name . ' Head Loss', '%7.4f');
     $name Diffuser Y1 = ($firstName Pt in - $lastName Pt out)/$firstName Pt in
!    push(@list, 'Loss Coefficient, Y1', $name . ' Diffuser Y1', '%7.4f');
     $name Diffuser Y2 = ($firstName Pt in - $lastName Pt out)/$lastName Pt out
!    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

!  PlotToolsExt::CreateResultsTable("$name Performance Results", "$name Performance Results", @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()}) { PlotToolsExt::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

! my $streamchart1 = new StreamwiseChartExt( 'Streamwise Velocity Chart' );
! if ( $streamchart1 ) {
!   $streamchart1->Caption( 'Chart showing streamwise, area averaged Cm versus averaged normalized M.' );
!   $streamchart1->AddLine( 'Velocity Meridional', 'area', 5, 'Cm' );
!   $streamchart1->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
!   PlotToolsExt::CreateMeridionalGeometryView( $stage->Name(), $stage->Components(), 1 );

#   Blade-to-blade views for each span location in @spanLoc
!   foreach my $loc (@spanLoc) {
!     PlotToolsExt::CreateBladetoBladeContourView( $stage->Name(), $stage->Components(), 'Pressure', 'P', $loc );
!   }
!   foreach my $loc (@spanLoc) {
!     PlotToolsExt::CreateBladetoBladeVectorView( $stage->Name(), $stage->Components(), $loc );
!   }
!   foreach my $loc (@spanLoc) {
!     PlotToolsExt::CreateBladetoBladeContourView( $stage->Name(), $stage->Components(), 'Total Pressure', 'Ptr', $loc );
!   }

#   Meridional Contour views
!   PlotToolsExt::CreateMeridionalContourView( $stage->Name(), $stage->Components(), 'Pressure', 'P' );
!   PlotToolsExt::CreateMeridionalContourView( $stage->Name(), $stage->Components(), 'Velocity Meridional', 'Cm' );

!}


#### 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', 'P' );
!     if ( $chart ) {
!       $chart->Caption( $name . ' blade loading chart' );
!       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 $chart = new SpanwiseChartExt( $name . ' Spanwise Flow Angles at LE Chart' );
!     if ( $chart ) {
!       $chart->Caption( $name . ' chart showing circumferentially averaged flow angle at the LE' );
!       if ( $comp->Type() eq 'Rotor' ) {
!         $chart->AddLine( "$name Flow Angle Alpha", $leLoc, 'area', 20, 'Alpha' );
!         $chart->AddLine( "$name Flow Angle Beta", $leLoc, 'area', 20, 'Beta' );
!       }
!       else {
!         $chart->AddLine( "$name Flow Angle Beta", $leLoc, 'area', 20, 'Beta' );
!       }
!       $chart->Plot();
!     }
!     my $teLoc = $comp->TEStreamLoc();
!     $chart = new SpanwiseChartExt( $name . ' Spanwise Flow Angles at TE Chart' );
!     if ( $chart ) {
!       $chart->Caption( $name . ' chart showing circumferentially averaged flow angle at the TE' );
!       if ( $comp->Type() eq 'Rotor' ) {
!         $chart->AddLine( "$name Flow Angle Alpha", $teLoc, 'area', 20, 'Alpha' );
!         $chart->AddLine( "$name Flow Angle Beta", $teLoc, 'area', 20, 'Beta' );
!       }
!       else {
!         $chart->AddLine( "$name Flow Angle Beta", $teLoc, 'area', 20, 'Beta' );
!       }
!       $chart->Plot();
!     }
!     $chart = new SpanwiseChartExt( $name . ' Spanwise Meridional Velocity at TE Chart' );
!     if ( $chart ) {
!       $chart->Caption( $name . ' chart showing circumferentially averaged Cm at the TE' );
!       $chart->AddLine( 'Velocity Meridional', $teLoc, 'area', 20, 'Cm' );
!       $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

