# Vista TF Pump Report

COMMAND FILE:
  CFX Post Version = 12.0
END

!  use PlotToolsExt;
!  use VistaTFChartExt;

### This is the defined interface for the Vista TF Reports
#
# $uniqueName   = unique name string for identifying report objects from different solutions
# $userLabel    = user specified name for the Vista TF results; may not be unique
# $resultsName  = prefix or postfix name for the solution files
# $path         = directory path to the results (assumes all files are in the same directory)
# $numBladeRows = number of bladerows for loading the auxiliary data files

!sub CreateVistaTFReport
!{
!  my ($uniqueName, $userLabel, $resultsName, $path, $numBladeRows) = @_;

#### Report Description

REPORT:
  FILE INFORMATION OPTIONS:
    Include In Report = false
#    This Exists = true
  END
  MESH STATISTICS OPTIONS:
    Include In Report = false
#    This Exists = true
  END
  PHYSICS SUMMARY OPTIONS:
    Include In Report = false
#    This Exists = true
  END
  SOLUTION SUMMARY OPTIONS:
    Include In Report = false
#    This Exists = true
  END
  PREVIEW:
    This Exists = true
    OUTPUT SETTINGS:
      Chart Image Type = png
      Chart Size = Custom
      Custom Chart Size Height = 384
      Custom Chart Size Width = 480
      Custom Figure Size Height = 576
      Custom Figure Size Width = 720
      Figure Image Type = png
      Figure Size = Custom
      Fit Views = Off
      This Exists = false
    END
  END
  PUBLISH:
    Report Format = HTML
    Save Images In Separate Folder = true
    This Exists = true
    OUTPUT SETTINGS:
      Chart Image Type = png
      Chart Size = Custom
      Custom Chart Size Height = 384
      Custom Chart Size Width = 480
      Custom Figure Size Height = 576
      Custom Figure Size Width = 720
      Figure Image Type = png
      Figure Size = Custom
      Fit Views = Off
      This Exists = false
    END
  END
END
TITLE PAGE:
  Include ANSYS Logo = On
  Include Custom Logo = Off
  Include Date = On
  Include TOC = On
  Show Captions in TOC = true
  Title Page Exists = true
END

REPORT:
  REPORT PROPERTIES:
    Report Template Name = Vista TF Pump Report
    Keywords = turbo, pump, impeller, rotor
    Report Template Description = A report for a pump through flow analysis using Vista TF.
  END
  PUBLISH:
    Default Report Name = Vista TF Pump Report
    Report Path = ./PumpReport.htm
  END
END
TITLE PAGE:
  Report Title = A Vista TF Results Analysis for a Pump
END

#### Dummy variable to work around Post bug

USER SCALAR VARIABLE:Dummy
  Boundary Values = Conservative
  Calculate Global Range = Off
  Expression = 1
  Recipe = Expression
END

#### Computed performance results

COMMENT: $uniqueName Tabular Data
  Comment Exists = True
  Comment Heading = $userLabel: Summary of Quantitative Data
  Comment Text = 
  Heading Level = 1
END

# Load the global parameters

!  my $globalFile = $path . '/global_' . $resultsName . '.csv';
!  open(FH, $globalFile);  
LIBRARY:
  CEL:
    EXPRESSIONS:
!  my $line;
!  while ( $line = <FH> ) {
#    Strip blank lines and comment lines and add $uniqueName identifier to each expression
!    if ( $line !~ m/^\s*?#|^\s*$/ ) {
!      my $newline = $uniqueName . ' ' . $line;
$newline
!    }
!  }
!  close(FH);
    END
  END
END

# Convert efficiencies to %

!  foreach my $expr ("$uniqueName etas tt", "$uniqueName etas ts", "$uniqueName etap tt", "$uniqueName etap ts") {
!    if ( exprExists($expr) ) {
!      my $newExpr = $expr . ' pct';
LIBRARY:
  CEL:
    EXPRESSIONS:
      $newExpr = $expr * 100
    END
  END
END
!    }
!  }

# Compute fluid density, if necessary

!  if ( !exprExists("$uniqueName ref rho") && exprExists("$uniqueName ref u")
!     && exprExists("$uniqueName ref d")) {
LIBRARY:
  CEL:
    EXPRESSIONS:
      $uniqueName ref rho = $uniqueName ref re * $uniqueName ref mue / ($uniqueName ref u * $uniqueName ref d)
    END
  END
END
!  }

# Compute pressure rise and head

!  if ( exprExists("$uniqueName pt out") && exprExists("$uniqueName ps out")
!    && exprExists("$uniqueName ref pt") && exprExists("$uniqueName ref omega")
!    && exprExists("$uniqueName ref mass in") && exprExists("$uniqueName ref d") ) {
!    my $omegaAbs;
!    my $omega1;
!    my $omega2;
!    my $omegaUnits;
!    my $val;
!    ($omegaAbs, $omegaUnits) = evaluate( "$uniqueName ref omega" );
!    ($val, $dummy) = evaluate( "1 [rad]" );
!    if ( $val == 1 )
!    {
!      $omega1 = "$omegaAbs [$omegaUnits] / 1 [rad]";
!    }
!    else
!    {
!      $omega1 = "$omegaAbs [$omegaUnits]  * pi / 180 [degree]";
!    }
LIBRARY:
  CEL:
    EXPRESSIONS:
      $uniqueName ref n = $omega1
      $uniqueName delta p tt = $uniqueName pt out - $uniqueName ref pt
      $uniqueName delta p ts = $uniqueName ps out - $uniqueName ref pt
      $uniqueName head tt = $uniqueName delta p tt / ($uniqueName ref rho * g)
      $uniqueName head ts = $uniqueName delta p ts / ($uniqueName ref rho * g)
      $uniqueName ref volume in = $uniqueName ref mass in / $uniqueName ref rho
      $uniqueName capacity coef = $uniqueName ref volume in / ($uniqueName ref n * ($uniqueName ref d)^3)
      $uniqueName head coef = g * $uniqueName head tt / (($uniqueName ref n)^2 * ($uniqueName ref d)^2)
    END
  END
END
!  }


!  my @exprList = (
!              'Rotation Speed', "$uniqueName ref rpm", '%7.4f',
!              'Mass Flow Rate', "$uniqueName ref mass in", '%7.4f',
!              'Volume Flow Rate', "$uniqueName ref volume in", '%7.4f',
!              'Inlet Total Pressure', "$uniqueName pt inbc", '%7.4f',
!              'Inlet Swirl', "$uniqueName alpha inbc", '%7.4f',
!              'Ref. Diameter', "$uniqueName ref d", '%7.4f',
!              'Ref. Tip Speed', "$uniqueName ref u", '%7.4f',
!              'Ref. Density', "$uniqueName ref rho", '%7.4f',
!              'Ref. Dynamic Viscosity', "$uniqueName ref mue", '%7.4f',
!              'Ref. Flow Coefficient', "$uniqueName ref phi", '%7.4f',
!              'Ref. Reynolds Number', "$uniqueName ref re", '%7.4f',
!              'Input Power', "$uniqueName power", '%7.4f',
!              'Pressure Rise t-t', "$uniqueName delta p tt", '%7.4f',
!              'Pressure Rise t-s', "$uniqueName delta p ts", '%7.4f',
!              'Head t-t', "$uniqueName head tt", '%7.4f',
!              'Head t-s', "$uniqueName head ts", '%7.4f',
!              'Capacity Coefficient', "$uniqueName capacity coef", '%7.4f',
!              'Head Coefficient', "$uniqueName head coef", '%7.4f',
!              'Isentropic Efficiency t-t %', "$uniqueName etas tt pct", '%7.4f',
!              'Isentropic Efficiency t-s %', "$uniqueName etas ts pct", '%7.4f',
!              'Polytropic Efficiency t-t %', "$uniqueName etap tt pct", '%7.4f',
!              'Polytropic Efficiency t-s %', "$uniqueName etap ts pct", '%7.4f' );

!  my $tableName = "Table 1 $uniqueName Summary Table";
!  my $tableCaption = "$userLabel: Summary of Input and Performance Results";
!  PlotToolsExt::CreateResultsTable( $tableName, $tableCaption, @exprList );

#### Load the 2D Surface Data and Plot the 2D Mesh

# This is one object that must override the state of an existing Post object of the same name.

!  my $TFSurface = "$uniqueName Surface";
!  my $surfaceData = $path . '/' . $resultsName . '.csv';

!  if ( objectExists( $TFSurface ) ) {
USER SURFACE:$TFSurface
  Option = From File
  Input File = $surfaceData
END
> forceupdate /USER SURFACE:$TFSurface
!  }
!  else {
USER SURFACE:$TFSurface
  Option = From File
  Input File = $surfaceData
  Colour = 0.8, 0.8, 0.8
  Colour Mode = Constant
  Draw Faces = Off
  Draw Lines = On
  Lighting = Off
  Line Colour = 0, 0, 0
  Line Colour Mode = Default
  Line Width = 1
  Render Edge Angle = 0 [degree]
  Transparency = 0.0
  OBJECT VIEW TRANSFORM:
    Apply Reflection = Off
    Apply Rotation = Off
    Apply Scale = Off
    Apply Translation = Off
  END
END
!  }
!  my $edgeContour = "$TFSurface Edge Contour";
!  my $edgePolyline1 = "$TFSurface Edge Polyline 1";
!  my $edgePolyline2 = "$TFSurface Edge Polyline 2";
!  if ( !objectExists( $edgeContour ) ) {
CONTOUR:$edgeContour
  Apply Instancing Transform = Off
  Clip Contour = Off
  Colour Map = Default Colour Map
  Colour Scale = Linear
  Colour Variable = q_o on $TFSurface
  Colour Variable Boundary Values = Conservative
  Constant Contour Colour = Off
  Contour Range = User Specified
  Culling Mode = No Culling
  Draw Contours = Off
  Font = Sans Serif
  Fringe Fill = On
  Instancing Transform = /DEFAULT INSTANCE TRANSFORM:Default Transform
  Lighting = Off
  Line Colour = 0, 0, 0
  Line Colour Mode = Default
  Line Width = 1
  Location List = /USER SURFACE:$TFSurface
  Max =  2 [kg kg^-1]
  Min = -2 [kg kg^-1]
  Number of Contours = 5
  Show Numbers = Off
  Specular Lighting = Off
  Surface Drawing = Smooth Shading
  Text Colour = 0, 0, 0
  Text Colour Mode = Default
  Text Height = 0.024
  Transparency = 0.0
  Value List = 0 [kg kg^-1],1 [kg kg^-1]
  Visibility = Off
END
POLYLINE:$edgePolyline1
  Apply Instancing Transform = Off
  Colour = 0, 0, 0
  Colour Mode = Constant
  Contour Level = 2
  Contour Name = /CONTOUR:$edgeContour
  Line Width = 3
  Option = From Contour
  Range = Local
  Visibility = On
END
POLYLINE:$edgePolyline2
  Apply Instancing Transform = Off
  Colour = 0, 0, 0
  Colour Mode = Constant
  Contour Level = 4
  Contour Name = /CONTOUR:$edgeContour
  Line Width = 3
  Option = From Contour
  Range = Local
  Visibility = On
END
!  }

>delete /COMMENT:User Data

#### Create 2D Meridional Plots

COMMENT:$uniqueName Meridionial Plots
  Comment Exists = True
  Comment Heading = $userLabel: Meridionial Plots
  Comment Text = 
  Heading Level = 1
END

!  my $firstTime = 1;
!  my @vars   = ( "Cm", "Cu", "p", "error" );
!  my @labels = ( "Cm", "Cu", "P", "Solution Error" );
!  for (my $i = 0; $i < @vars; $i++ ) {
!    my $varName = $vars[$i];
!    my $varLabel = $labels[$i];
!    my $num = $i + 1;
!    if ( getValue("$varName on $TFSurface", "User Level") ne "" ) {
!      my $contourName = "Plot $num $uniqueName Contour of $varLabel";
!      my $caption = "$userLabel: Contour of $varLabel"; 
!      if ( objectExists( $contourName ) ) {
!        $firstTime = 0;
!      }
!      PlotToolsExt::CreateTFContourPlot( $contourName, $caption, $varName, $varLabel, $TFSurface, 20 );
>show /USER SURFACE:$TFSurface, view=/VIEW:$contourName View
>show /POLYLINE:$edgePolyline1, view=/VIEW:$contourName View
>show /POLYLINE:$edgePolyline2, view=/VIEW:$contourName View
!    }
!  }
!  if ( $firstTime ) {
!    my $firstPlot = "Plot 1 $uniqueName Contour of Cm View";
!    if ( objectExists( $firstPlot ) ) {
>setViewportView cmd=set, view=$firstPlot, viewport=1
>centerview 1
!    }
!  }

#### Create 1D Plots for each Bladerow

COMMENT: $uniqueName Blade Row Charts
  Comment Exists = True
  Comment Heading = $userLabel: Blade Row Charts
  Comment Text = 
  Heading Level = 1
END

!  my @list = ( "Hub", "Mean", "Tip", "Loading" );

!  for (my $i = 1; $i <= $numBladeRows; $i++) { 

#### Load 1D Data

!    my $fileNum = ( $i < 10 ) ? '0' . $i : $i;

!    foreach my $name ( @list ) {
!      my $polyLine = $uniqueName . ' Row ' . $i . ' ' . $name;
!      my $fileName = $path . '/' . 'row_' . $fileNum . '_' . lc($name) . '_' . $resultsName . '.csv';
#!      print "Loading polyline data for $polyLine\n";
POLYLINE:$polyLine
  Option = From File
  Input File = $fileName
END
> forceupdate /POLYLINE:$polyLine
!    }

#### Create Charts

COMMENT:$uniqueName Row $i
  Comment Exists = True
  Comment Heading = Charts for Row $i
  Comment Text = #
  Heading Level = 2
END

!    my $chartname = "Chart 1 $uniqueName Row $i Tip W";
!    my $title = "Relative Velocity (W) on Tip Streamline";
!    my $chart = new VistaTFChartExt( $chartname, $title, 'f_bl', 'Relative Velocity' );
!    $chart->Caption( "$userLabel: $title" );
!    $chart->AddLine( "$uniqueName Row $i Tip", 'w', 'mid-passage' );
!    $chart->AddLine( "$uniqueName Row $i Tip", 'w_s', 'suction side' );
!    $chart->AddLine( "$uniqueName Row $i Tip", 'w_p', 'pressure side' );
!    $chart->Plot();

!    $chartname = "Chart 2 $uniqueName Row $i Mean W";
!    $title = "Relative Velocity (W) on Mean Streamline";
!    $chart = new VistaTFChartExt( $chartname, $title, 'f_bl', 'Relative Velocity' );
!    $chart->Caption( "$userLabel: $title" );
!    $chart->AddLine( "$uniqueName Row $i Mean", 'w', 'mid-passage' );
!    $chart->AddLine( "$uniqueName Row $i Mean", 'w_s', 'suction side' );
!    $chart->AddLine( "$uniqueName Row $i Mean", 'w_p', 'pressure side' );
!    $chart->Plot();

!    $chartname = "Chart 3 $uniqueName Row $i Hub W";
!    $title = "Relative Velocity (W) on Hub Streamline";
!    $chart = new VistaTFChartExt( $chartname, $title, 'f_bl', 'Relative Velocity' );
!    $chart->Caption( "$userLabel: $title" );
!    $chart->AddLine( "$uniqueName Row $i Hub", 'w', 'mid-passage' );
!    $chart->AddLine( "$uniqueName Row $i Hub", 'w_s', 'suction side' );
!    $chart->AddLine( "$uniqueName Row $i Hub", 'w_p', 'pressure side' );
!    $chart->Plot();

!    $chartname = "Chart 4 $uniqueName Row $i c_btob";
!    $title = "Meridional Variation in Blade to Blade Loading Parameter";
!    $chart = new VistaTFChartExt( $chartname, $title, 'f_bl', 'c_btob' );
!    $chart->Caption( "$userLabel: $title" );
!    $chart->AddLine( "$uniqueName Row $i Tip", 'c_btob', 'tip' );
!    $chart->AddLine( "$uniqueName Row $i Mean", 'c_btob', 'mean' );
!    $chart->AddLine( "$uniqueName Row $i Hub", 'c_btob', 'hub' );
!    $chart->Plot();

!    $chartname = "Chart 5 $uniqueName Row $i Beta";
!    $title = "Meridional Variation in Beta (Blade and Flow Angles)";
!    $chart = new VistaTFChartExt( $chartname, $title, 'f_bl', 'Beta <units>' );
!    $chart->Caption( "$userLabel: $title" );
!    $chart->AddLine( "$uniqueName Row $i Tip", 'beta_bl', 'beta_bl tip' );
!    $chart->AddLine( "$uniqueName Row $i Mean", 'beta_bl', 'beta_bl mean' );
!    $chart->AddLine( "$uniqueName Row $i Hub", 'beta_bl', 'beta_bl hub' );
!    $chart->AddLine( "$uniqueName Row $i Tip", 'beta_fl', 'beta_fl tip' );
!    $chart->AddLine( "$uniqueName Row $i Mean", 'beta_fl', 'beta_fl mean' );
!    $chart->AddLine( "$uniqueName Row $i Hub", 'beta_fl', 'beta_fl hub' );
!    $chart->Plot();

!    $chartname = "Chart 6 $uniqueName Row $i P";
!    $title = "Meridional Variation in Static Pressure";
!    $chart = new VistaTFChartExt( $chartname, $title, 'f_bl', 'Static Pressure <units>' );
!    $chart->Caption( "$userLabel: $title" );
!    $chart->AddLine( "$uniqueName Row $i Tip", 'p', 'tip' );
!    $chart->AddLine( "$uniqueName Row $i Mean", 'p', 'mean' );
!    $chart->AddLine( "$uniqueName Row $i Hub", 'p', 'hub' );
!    $chart->Plot();

!    $chartname = "Chart 7 $uniqueName Row $i Loading Parameters";
!    $title = "Spanwise Variation in Loading Parameters";
!    $chart = new VistaTFChartExt( $chartname, $title, 'f_qo', 'Loading Parameter' );
!    $chart->Caption( "$userLabel: $title" );
!    $chart->AddLine( "$uniqueName Row $i Loading", 'de_haller', 'De Haller' );
!    $chart->AddLine( "$uniqueName Row $i Loading", 'Lambda' );
!    $chart->AddLine( "$uniqueName Row $i Loading", 'cp_ideal' );
!    $chart->AddLine( "$uniqueName Row $i Loading", 'df_lieblein', 'Lieblein Diffusion Factor' );
!    $chart->Plot();

!    $chartname = "Chart 8 $uniqueName Row $i Angles";
!    $title = "Spanwise Variation in Incidence and Deviation Angles";
!    $chart = new VistaTFChartExt( $chartname, $title, 'f_qo', 'Angle <units>' );
!    $chart->Caption( "$userLabel: $title" );
!    $chart->AddLine( "$uniqueName Row $i Loading", 'incidence' );
!    $chart->AddLine( "$uniqueName Row $i Loading", 'deviation' );
!    $chart->Plot();
!  }
!}

#### This function is needed for the included perl modules

#### runCCL
!sub runCCL
!{
!  my ($ccl) = @_;
!  my @list = split('\n', $ccl);
!  my $line;
!  foreach $line (@list) {
# For debugging, uncomment the following line:
#!   print "runCCL: $line,"\n";
$line
!  }
!}


