#
# A CFD-Post session file for creating a Cp polar at a specified location
#

# Macro GUI begin
#
# macro name = Cp Polar Plot
# macro subroutine = cpPolar
# macro report file = cpPolar_report.html
#
# macro parameter = separator
#  type = Separator
#
# macro parameter = comment
#  type = Comment
#  default = This macro generates Cp plot at a specified location
#
# macro parameter = separator
#  type = Separator
#
# macro parameter = Boundary List
#  type = Location
#  location type = Boundary
#
# macro parameter = Slice Normal
#  type = Combo
#  list = x, y, z
#  default = z
#
# macro parameter = Slice Position
#  type = Float
#  quantity type = length
#  range = -10 [m], 10 [m]
#  default = 0 [m]
#
# macro parameter = Inlet Region
#  type = Location
#  location type = BOUNDARY
#
# macro parameter = Ref. Pressure
#  type = Float
#  quantity type = pressure
#  range = 0 [Pa], 200000 [Pa]
#  default = 100000 [Pa]
#
# macro parameter = Plot Axis
#  type = Combo
#  list = x, y, z
#  default = x
#
#
# Macro GUI end

! no warnings 'redefine';

! sub cpPolar {
! ($bndName, $axis, $position, $inlet, $pref, $xDir) = @_;

LIBRARY:
CEL:
EXPRESSIONS:
  dynHead = 0.5 * areaAve(Density)@$inlet * areaAve(Velocity)@$inlet^2
  cpExp = (Pressure - $pref)/dynHead
END
END
END

USER SCALAR VARIABLE: cp
  Recipe = Expression
  Expression = cpExp
END

! $axis = substr(uc($axis),0,1);

! if ($axis eq "X") {
!  $axisSpec = "1,0,0";
!  $posSpec = "$position,0,0";
! } elsif ($axis eq "Y") {
!  $axisSpec = "0,1,0";
!  $posSpec = "0,$position,0";
! } else {
!  $axisSpec = "0,0,1";
!  $posSpec = "0,0,$position";
! }

PLANE: cpPlane
  Option = Point and Normal
  Point = $posSpec
  Normal = $axisSpec
  Visibility = Off
END

POLYLINE: cpLine
  Option = Boundary Intersection
  Boundary List = $bndName
  Location = cpPlane
  Colour = 1,0,0
END

! $flowDir = substr(uc($xDir),0,1);


CHART:CpChart
  Chart Legend = Off
  Chart Title = Cp Polar on $bndName at $axis = $position
  Chart Type = XY
  Chart X Axis Label = $xDir
  Chart Y Axis Label = Pressure Coefficient
  Range Selection = Automatic
  CHART LINE:ChartLine
   Chart X Variable = $xDir
   Chart Y Variable = cp
   Location = cpLine
  END
END

# Wait 2 seconds for the charter to save the plot image
!sleep 2;

> chart print, Chart Name = CpChart, filename = CpChart.png, \
    x size = 600, y size = 500, format = png

# create output file

! open(OFH,">cpPolar_report.html");
! print OFH "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">\n";
! print OFH "<html>\n";
! print OFH "<head>\n";
! print OFH "   <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
! print OFH "   <meta name=\"Author\" content=\"CFD-Post\">\n";
! print OFH "   <meta name=\"GENERATOR\" content=\"CFD-Post\">\n";
! print OFH "   <title>Cp polar</title>\n";
! print OFH "</head>\n";
! print OFH "<body>\n";
! print OFH "<b><i><font color=\"#000099\"><font size=+4>Cp Polar Report</font></font></b></i>\n";
! print OFH "<hr NOSHADE WIDTH=\"100%\">\n";
! $fileName = getValue("DATA READER","Current Results File");
! $date = scalar(localtime);
! print OFH "<p>Generated by CFD-Post from results file <i>$fileName</i> at <i>$date</i>\n";
! print OFH "<p><b><font size=+2>User Input</font></b>\n";
! print OFH "<table BORDER CELLPADDING=2 >\n";
! print OFH "<tr>\n";
! print OFH "<td>Boundary Location</td><td>$bndName</td>\n";
! print OFH "</tr>\n";
! print OFH "<tr>\n";
! print OFH "<td>Intersection position</td><td>$axis = $position</td>\n";
! print OFH "</tr>\n";
! print OFH "<tr>\n";
! print OFH "<td>Plot X-axis Variable</td><td>$xDir</td>\n";
! print OFH "</tr>\n";
! print OFH "<tr>\n";
! print OFH "<td>Inlet Location</td><td>$inlet</td>\n";
! print OFH "</tr>\n";
! print OFH "<tr>\n";
! print OFH "<td>Reference pressure [pa]</td><td>$pref</td>\n";
! print OFH "</tr>\n";
! print OFH "</table>\n";
! print OFH "<b><font size=+2>Cp Polar Plot</font></b>\n";
! print OFH "<p><img SRC=\"CpChart.png\" NOSAVE height=500 width=600>\n";
! print OFH "</body>\n";
! print OFH "</html>\n";
!close(OFH)

!}
