! use File::Copy;
! use Cwd;

COMMAND FILE:
  CFX Pre Version = 12.0
END

>load mode=new
> update

! getEgFile("Cavitation.gtm");

>writeCaseFile filename=CavitationIni.cfx
> update

>gtmImport filename=Cavitation.gtm, \
type=GTM, units=m, nameStrategy= Assembly
> update

# Imported library information
LIBRARY:
  &replace MATERIAL: Water Vapour at 25 C
    Material Description = Water (saturated vapour) at 25 C
    Option = Pure Substance
    Thermodynamic State = Gas
    Material Group = Water Data, Constant Property Gases, Interphase Mass \
Transfer
    PROPERTIES: PROPERTIES
      Option = General Material
      DYNAMIC VISCOSITY: DYNAMIC VISCOSITY
        Dynamic Viscosity = 9.8626E-06 [kg m^-1 s^-1]
        Option = Value
      END
      REFRACTIVE INDEX: REFRACTIVE INDEX
        Option = Value
        Refractive Index = 1.0 [m m^-1]
      END
      SCATTERING COEFFICIENT: SCATTERING COEFFICIENT
        Option = Value
        Scattering Coefficient = 0.0 [m^-1]
      END
      ABSORPTION COEFFICIENT: ABSORPTION COEFFICIENT
        Absorption Coefficient = 1.0 [m^-1]
        Option = Value
      END
      THERMAL CONDUCTIVITY: THERMAL CONDUCTIVITY
        Option = Value
        Thermal Conductivity = 0.01854 [W m^-1 K^-1]
      END
      EQUATION OF STATE: EQUATION OF STATE
        Density = 0.02308 [kg m^-3]
        Molar Mass = 18.02 [kg kmol^-1]
        Option = Value
      END
      SPECIFIC HEAT CAPACITY: SPECIFIC HEAT CAPACITY
        Option = Value
        Specific Heat Capacity = 1911.6 [J kg^-1 K^-1]
        Specific Heat Type = Constant Pressure
      END
      REFERENCE STATE: REFERENCE STATE
        Option = Specified Point
        Reference Pressure = 3.169E-2 [bar]
        Reference Specific Enthalpy = -1.3424249E+7 [J/kg]
        Reference Specific Entropy = 1.0475125E+04 [J/kg/K]
        Reference Temperature = 25 [C]
      END
      THERMAL EXPANSIVITY: THERMAL EXPANSIVITY
        Option = Value
        Thermal Expansivity = 0.003356 [K^-1]
      END
    END
  END
END

LIBRARY:
  &replace MATERIAL: Water at 25 C
    Material Description = Water (saturated liquid) at 25 C
    Option = Pure Substance
    Thermodynamic State = Liquid
    Material Group = Water Data, Constant Property Liquids, Interphase Mass \
Transfer
    PROPERTIES: PROPERTIES
      Option = General Material
      DYNAMIC VISCOSITY: DYNAMIC VISCOSITY
        Dynamic Viscosity = 8.899E-4 [kg m^-1 s^-1]
        Option = Value
      END
      REFRACTIVE INDEX: REFRACTIVE INDEX
        Option = Value
        Refractive Index = 1.0 [m m^-1]
      END
      SCATTERING COEFFICIENT: SCATTERING COEFFICIENT
        Option = Value
        Scattering Coefficient = 0.0 [m^-1]
      END
      ABSORPTION COEFFICIENT: ABSORPTION COEFFICIENT
        Absorption Coefficient = 1.0 [m^-1]
        Option = Value
      END
      THERMAL CONDUCTIVITY: THERMAL CONDUCTIVITY
        Option = Value
        Thermal Conductivity = 0.6069 [W m^-1 K^-1]
      END
      EQUATION OF STATE: EQUATION OF STATE
        Density = 997.0 [kg m^-3]
        Molar Mass = 18.02 [kg kmol^-1]
        Option = Value
      END
      SPECIFIC HEAT CAPACITY: SPECIFIC HEAT CAPACITY
        Option = Value
        Specific Heat Capacity = 4181.7 [J kg^-1 K^-1]
        Specific Heat Type = Constant Pressure
      END
      REFERENCE STATE: REFERENCE STATE
        Option = Specified Point
        Reference Specific Enthalpy = -1.5866449E+7 [J/kg]
        Reference Specific Entropy = 2.82482E+03 [J/kg/K]
        Reference Temperature = 25 [C]
        Reference Pressure = 3.169E-2 [bar]
      END
      THERMAL EXPANSIVITY: THERMAL EXPANSIVITY
        Option = Value
        Thermal Expansivity = 2.57E-04 [K^-1]
      END
    END
  END
END
> update

PHYSICS OPTIONS CONTROL:
  Automatic Physics Update = On
  Beta Physics Enabled = Off
  Constant Physics Control = On
  Default Boundary Type = Standard
  Default Domain Enabled = On
  Default Interface Enabled = Off
  Interface Generation Method = One per Interface Type
  Physics Validation Disabled = Off
  Show Interface Boundaries in Outline Tree = On
END
> update

PRIMITIVE2D:BLD HIGH
  Prim2d Visibility = On
END
PRIMITIVE2D:BLD LOW
  Prim2d Visibility = On
END
PRIMITIVE2D:HUB INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:HUB OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:HUB Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:INFLOW INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:INFLOW OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:INFLOW Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:OUTFLOW INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:OUTFLOW OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:OUTFLOW Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:PER1 INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:PER1 OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:PER1 Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:PER2 INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:PER2 OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:PER2 Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:SHROUD INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:SHROUD OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:SHROUD Passage
  Prim2d Visibility = On
END
> update

PRIMITIVE2D:BLD HIGH
  Prim2d Visibility = On
END
PRIMITIVE2D:BLD LOW
  Prim2d Visibility = On
END
PRIMITIVE2D:HUB INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:HUB OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:HUB Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:INFLOW INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:INFLOW OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:INFLOW Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:OUTFLOW INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:OUTFLOW OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:OUTFLOW Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:PER1 INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:PER1 OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:PER1 Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:PER2 INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:PER2 OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:PER2 Passage
  Prim2d Visibility = On
END
PRIMITIVE2D:SHROUD INBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:SHROUD OUTBlock
  Prim2d Visibility = On
END
PRIMITIVE2D:SHROUD Passage
  Prim2d Visibility = On
END
> update

>rename, from=/FLOW:Flow Analysis 1/DOMAIN:Default Domain, to=Pump
> update

FLOW: Flow Analysis 1
  &replace   DOMAIN: Pump
    Coord Frame = Coord 0
    Domain Type = Fluid
    Location = Inlet,Outlet,Passage Main
    BOUNDARY: Pump Default
      Boundary Type = WALL
      Create Other Side = Off
      Interface Boundary = Off
      Location = BLD HIGH,BLD LOW,HUB INBlock,HUB OUTBlock,HUB Passage,\
INFLOW INBlock,OUTFLOW OUTBlock,PER1 INBlock,PER1 OUTBlock,PER1 Passage,PER2 \
INBlock,PER2 OUTBlock,PER2 Passage,SHROUD INBlock,SHROUD OUTBlock,SHROUD Passage
      BOUNDARY CONDITIONS:
        MASS AND MOMENTUM:
          Option = No Slip Wall
        END # MASS AND MOMENTUM:
        WALL ROUGHNESS:
          Option = Smooth Wall
        END # WALL ROUGHNESS:
      END # BOUNDARY CONDITIONS:
    END # BOUNDARY:Pump Default
    DOMAIN MODELS:
      BUOYANCY MODEL:
        Option = Non Buoyant
      END # BUOYANCY MODEL:
      DOMAIN MOTION:
        Angular Velocity = 132 [radian s^-1]
        Option = Rotating
        AXIS DEFINITION:
          Option = Coordinate Axis
          Rotation Axis = Coord 0.3
        END # AXIS DEFINITION:
      END # DOMAIN MOTION:
      MESH DEFORMATION:
        Option = None
      END # MESH DEFORMATION:
      REFERENCE PRESSURE:
        Reference Pressure = 0 [atm]
      END # REFERENCE PRESSURE:
    END # DOMAIN MODELS:
    FLUID DEFINITION: Liquid Water
      Material = Water at 25 C
      Option = Material Library
      MORPHOLOGY:
        Option = Continuous Fluid
      END # MORPHOLOGY:
    END # FLUID DEFINITION:Liquid Water
    FLUID MODELS:
      COMBUSTION MODEL:
        Option = None
      END # COMBUSTION MODEL:
      HEAT TRANSFER MODEL:
        Fluid Temperature = 25 [C]
        Option = Isothermal
      END # HEAT TRANSFER MODEL:
      THERMAL RADIATION MODEL:
        Option = None
      END # THERMAL RADIATION MODEL:
      TURBULENCE MODEL:
        Option = k epsilon
      END # TURBULENCE MODEL:
      TURBULENT WALL FUNCTIONS:
        Option = Scalable
      END # TURBULENT WALL FUNCTIONS:
    END # FLUID MODELS:
  END # DOMAIN:Pump
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Pump
    &replace     BOUNDARY: Inlet
      Boundary Type = INLET
      Frame Type = Stationary
      Interface Boundary = Off
      Location = INBlock INFLOW
      BOUNDARY CONDITIONS:
        FLOW DIRECTION:
          Option = Cartesian Components
          Unit Vector X Component = 0
          Unit Vector Y Component = 0
          Unit Vector Z Component = 1
        END # FLOW DIRECTION:
        FLOW REGIME:
          Option = Subsonic
        END # FLOW REGIME:
        MASS AND MOMENTUM:
          Option = Stationary Frame Total Pressure
          Relative Pressure = 100000 [Pa]
        END # MASS AND MOMENTUM:
        TURBULENCE:
          Eddy Length Scale = 0.03 [m]
          Fractional Intensity = 0.03
          Option = Intensity and Length Scale
        END # TURBULENCE:
      END # BOUNDARY CONDITIONS:
    END # BOUNDARY:Inlet
  END # DOMAIN:Pump
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Pump
    &replace     BOUNDARY: Outlet
      Boundary Type = OUTLET
      Frame Type = Stationary
      Interface Boundary = Off
      Location = OUTBlock OUTFLOW
      BOUNDARY CONDITIONS:
        FLOW REGIME:
          Option = Subsonic
        END # FLOW REGIME:
        MASS AND MOMENTUM:
          Mass Flow Rate = 16 [kg s^-1]
          Option = Mass Flow Rate
        END # MASS AND MOMENTUM:
      END # BOUNDARY CONDITIONS:
    END # BOUNDARY:Outlet
  END # DOMAIN:Pump
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Pump
    &replace     BOUNDARY: Stationary Wall
      Boundary Type = WALL
      Create Other Side = Off
      Frame Type = Rotating
      Interface Boundary = Off
      Location = OUTBlock HUB,OUTBlock SHROUD
      BOUNDARY CONDITIONS:
        MASS AND MOMENTUM:
          Option = No Slip Wall
          WALL VELOCITY:
            Option = Counter Rotating Wall
          END # WALL VELOCITY:
        END # MASS AND MOMENTUM:
        WALL ROUGHNESS:
          Option = Smooth Wall
        END # WALL ROUGHNESS:
      END # BOUNDARY CONDITIONS:
    END # BOUNDARY:Stationary Wall
  END # DOMAIN:Pump
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  &replace   DOMAIN INTERFACE: Periodic Interface
    Boundary List1 =
    Boundary List2 =
    Filter Domain List1 = -- All Domains --
    Filter Domain List2 = -- All Domains --
    Interface Region List1 = INBlock PER1,OUTBlock PER1,Passage PER1
    Interface Region List2 = INBlock PER2,OUTBlock PER2,Passage PER2
    Interface Type = Fluid Fluid
    INTERFACE MODELS:
      Option = Rotational Periodicity
      AXIS DEFINITION:
        Option = Coordinate Axis
        Rotation Axis = Coord 0.3
      END # AXIS DEFINITION:
    END # INTERFACE MODELS:
    MESH CONNECTION:
      Option = Automatic
    END # MESH CONNECTION:
  END # DOMAIN INTERFACE:Periodic Interface
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  &replace   DOMAIN INTERFACE: Inblock to Passage Interface
    Boundary List1 =
    Boundary List2 =
    Filter Domain List1 = -- All Domains --
    Filter Domain List2 = -- All Domains --
    Interface Region List1 = OUTFLOW INBlock
    Interface Region List2 = INFLOW Passage
    Interface Type = Fluid Fluid
    INTERFACE MODELS:
      Option = General Connection
      FRAME CHANGE:
        Option = None
      END # FRAME CHANGE:
      MASS AND MOMENTUM:
        Option = Conservative Interface Flux
        MOMENTUM INTERFACE MODEL:
          Option = None
        END # MOMENTUM INTERFACE MODEL:
      END # MASS AND MOMENTUM:
      PITCH CHANGE:
        Option = None
      END # PITCH CHANGE:
    END # INTERFACE MODELS:
    MESH CONNECTION:
      Option = Direct
    END # MESH CONNECTION:
  END # DOMAIN INTERFACE:Inblock to Passage Interface
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  &replace   DOMAIN INTERFACE: Passage to Outblock Interface
    Boundary List1 =
    Boundary List2 =
    Filter Domain List1 = -- All Domains --
    Filter Domain List2 = -- All Domains --
    Interface Region List1 = OUTFLOW Passage
    Interface Region List2 = INFLOW OUTBlock
    Interface Type = Fluid Fluid
    INTERFACE MODELS:
      Option = General Connection
      FRAME CHANGE:
        Option = None
      END # FRAME CHANGE:
      MASS AND MOMENTUM:
        Option = Conservative Interface Flux
        MOMENTUM INTERFACE MODEL:
          Option = None
        END # MOMENTUM INTERFACE MODEL:
      END # MASS AND MOMENTUM:
      PITCH CHANGE:
        Option = None
      END # PITCH CHANGE:
    END # INTERFACE MODELS:
    MESH CONNECTION:
      Option = Direct
    END # MESH CONNECTION:
  END # DOMAIN INTERFACE:Passage to Outblock Interface
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  &replace   INITIALISATION:
    Frame Type = Stationary
    Option = Automatic
    INITIAL CONDITIONS:
      Velocity Type = Cartesian
      CARTESIAN VELOCITY COMPONENTS:
        Option = Automatic with Value
        U = 0 [m s^-1]
        V = 0 [m s^-1]
        W = 1 [m s^-1]
      END # CARTESIAN VELOCITY COMPONENTS:
      STATIC PRESSURE:
        Option = Automatic with Value
        Relative Pressure = 100000 [Pa]
      END # STATIC PRESSURE:
      TURBULENCE INITIAL CONDITIONS:
        Option = Intensity and Length Scale
        EDDY LENGTH SCALE:
          Eddy Length Scale = 0.03 [m]
          Option = Automatic with Value
        END # EDDY LENGTH SCALE:
        FRACTIONAL INTENSITY:
          Fractional Intensity = 0.03
          Option = Automatic with Value
        END # FRACTIONAL INTENSITY:
      END # TURBULENCE INITIAL CONDITIONS:
    END # INITIAL CONDITIONS:
  END # INITIALISATION:
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  &replace   SOLVER CONTROL:
    Turbulence Numerics = First Order
    ADVECTION SCHEME:
      Option = High Resolution
    END # ADVECTION SCHEME:
    CONVERGENCE CONTROL:
      Maximum Number of Iterations = 500
      Minimum Number of Iterations = 1
      Physical Timescale = 0.001 [s]
      Timescale Control = Physical Timescale
    END # CONVERGENCE CONTROL:
    CONVERGENCE CRITERIA:
      Residual Target = 7.5e-6
      Residual Type = RMS
    END # CONVERGENCE CRITERIA:
    DYNAMIC MODEL CONTROL:
      Global Dynamic Model Control = On
    END # DYNAMIC MODEL CONTROL:
  END # SOLVER CONTROL:
END # FLOW:Flow Analysis 1
> update

>writeCaseFile filename=CavitationIni.def,\
operation=write def file

>writeCaseFile

# Subroutine for copying the file
!no warnings 'redefine';
! sub getEgFile {
!       my $egdir;

!       my @files = @_;
!       foreach my $file (@files) {
                 # Skip if the file exists already
!                next if -e $file;
!                unless ($egdir = $ENV{"CFX_EG_DIR"}) {
!                        die "Examples directory variable CFX_EG_DIR not set.";
!                }
                 # Use backslash if it's a windows filepath
!                my $workdir = cwd();
!                if ($egdir =~ /\\/) {
!                       my $egfile = "$egdir\\$file";
!                       copy($egfile,".") || die "\nThe tutorial file \"$file\" was not found in the working directory. Please populate the working directory (\"$workdir\") with the required files as described in the tutorial.\n";
!                }
                 # Or a forward slash if it's Unix
!                else {
!                       my $egfile = "$egdir\/$file";
!                       copy($egfile,".") || die "\nThe tutorial file \"$file\" was not found in the working directory. Please populate the working directory (\"$workdir\") with the required files as described in the tutorial.\n";
!                }
!
!       }
! }
