! use File::Copy;
! use Cwd;

COMMAND FILE:
  CFX Pre Version = 12.0
END

>load mode=new
> update

! getEgFile("StaticMixerMesh.gtm");

>writeCaseFile filename=StaticMixer.cfx
> update

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

>delete /FLOW:Flow Analysis 1/DOMAIN:Default Domain,/FLOW:Flow Analysis 1/\
ANALYSIS TYPE:ANALYSIS TYPE
FLOW: Flow Analysis 1
  &replace ANALYSIS TYPE:
    Option = Steady State
    EXTERNAL SOLVER COUPLING:
      Option = None
    END
  END
  &replace OUTPUT CONTROL:
    RESULTS:
      File Compression Level = Default
      Option = Standard
    END
  END
  &replace SOLUTION UNITS:
    Angle Units = [rad]
    Length Units = [m]
    Mass Units = [kg]
    Solid Angle Units = [sr]
    Temperature Units = [K]
    Time Units = [s]
  END
  &replace SOLVER CONTROL:
    Turbulence Numerics = First Order
    ADVECTION SCHEME:
      Option = High Resolution
    END
    CONVERGENCE CONTROL:
      Length Scale Option = Conservative
      Maximum Number of Iterations = 100
      Minimum Number of Iterations = 1
      Timescale Control = Auto Timescale
      Timescale Factor = 1.0
    END
    CONVERGENCE CRITERIA:
      Residual Target = 1.E-4
      Residual Type = RMS
    END
    DYNAMIC MODEL CONTROL:
      Global Dynamic Model Control = On
    END
  END
  &replace DOMAIN: Default Domain
    Coord Frame = Coord 0
    Domain Type = Fluid
    Location = B1.P3
    DOMAIN MODELS:
      BUOYANCY MODEL:
        Option = Non Buoyant
      END
      DOMAIN MOTION:
        Option = Stationary
      END
      MESH DEFORMATION:
        Option = None
      END
      REFERENCE PRESSURE:
        Reference Pressure = 1 [atm]
      END
    END
    FLUID DEFINITION: Water
      Material = Water
      Option = Material Library
      MORPHOLOGY:
        Option = Continuous Fluid
      END
    END
    FLUID MODELS:
      COMBUSTION MODEL:
        Option = None
      END
      HEAT TRANSFER MODEL:
        Option = Thermal Energy
      END
      THERMAL RADIATION MODEL:
        Option = None
      END
      TURBULENCE MODEL:
        Option = k epsilon
      END
      TURBULENT WALL FUNCTIONS:
        Option = Scalable
      END
    END
    BOUNDARY: in1
      Boundary Type = INLET
      Interface Boundary = Off
      Location = in1
      BOUNDARY CONDITIONS:
        FLOW REGIME:
          Option = Subsonic
        END
        HEAT TRANSFER:
          Option = Static Temperature
          Static Temperature = 315 [K]
        END
        MASS AND MOMENTUM:
          Normal Speed = 2 [m s^-1]
          Option = Normal Speed
        END
        TURBULENCE:
          Option = Medium Intensity and Eddy Viscosity Ratio
        END
      END
    END
    BOUNDARY: in2
      Boundary Type = INLET
      Interface Boundary = Off
      Location = in2
      BOUNDARY CONDITIONS:
        FLOW REGIME:
          Option = Subsonic
        END
        HEAT TRANSFER:
          Option = Static Temperature
          Static Temperature = 285 [K]
        END
        MASS AND MOMENTUM:
          Normal Speed = 2 [m s^-1]
          Option = Normal Speed
        END
        TURBULENCE:
          Option = Medium Intensity and Eddy Viscosity Ratio
        END
      END
    END
    BOUNDARY: out
      Boundary Type = OUTLET
      Interface Boundary = Off
      Location = out
      BOUNDARY CONDITIONS:
        FLOW REGIME:
          Option = Subsonic
        END
        MASS AND MOMENTUM:
          Option = Average Static Pressure
          Pressure Profile Blend = 0.05
          Relative Pressure = 0 [Pa]
        END
        PRESSURE AVERAGING:
          Option = Average Over Whole Outlet
        END
      END
    END
  END
END
LIBRARY:
  &replace MATERIAL GROUP: Air Data
    Group Description = Ideal gas and constant property air. Constant \
properties are for dry air at STP (0 C, 1 atm) and 25 C, 1 atm.
  END
  &replace MATERIAL GROUP: CHT Solids
    Group Description = Pure solid substances that can be used for conjugate \
heat transfer.
  END
  &replace MATERIAL GROUP: Calorically Perfect Ideal Gases
    Group Description = Ideal gases with constant specific heat capacity. \
Specific heat is evaluated at STP.
  END
  &replace MATERIAL GROUP: Constant Property Gases
    Group Description = Gaseous substances with constant properties. \
Properties are calculated at STP (0C and 1 atm). Can be combined with NASA SP-\
273 materials for combustion modelling.
  END
  &replace MATERIAL GROUP: Constant Property Liquids
    Group Description = Liquid substances with constant properties.
  END
  &replace MATERIAL GROUP: Dry Peng Robinson
    Group Description = Materials with properties specified using the built \
in Peng Robinson equation of state. Suitable for dry real gas modelling.
  END
  &replace MATERIAL GROUP: Dry Redlich Kwong
    Group Description = Materials with properties specified using the built \
in Redlich Kwong equation of state. Suitable for dry real gas modelling.
  END
  &replace MATERIAL GROUP: Dry Steam
    Group Description = Materials with properties specified using the IAPWS \
equation of state. Suitable for dry steam modelling.
  END
  &replace MATERIAL GROUP: Gas Phase Combustion
    Group Description = Ideal gas materials which can be use for gas phase \
combustion. Ideal gas specific heat coefficients are specified using the NASA SP-\
273 format.
  END
  &replace MATERIAL GROUP: IAPWS IF97
    Group Description = Liquid, vapour and binary mixture materials which \
use the IAPWS IF-97 equation of state. Materials are suitable for compressible \
liquids, phase change calculations and dry steam flows.
  END
  &replace MATERIAL GROUP: Interphase Mass Transfer
    Group Description = Materials with reference properties suitable for \
performing either Eulerian or Lagrangian multiphase mass transfer problems. \
Examples include cavitation, evaporation or condensation.
  END
  &replace MATERIAL GROUP: Liquid Phase Combustion
    Group Description = Liquid and homogenous binary mixture materials which \
can be included with Gas Phase Combustion materials if combustion modelling also \
requires phase change (eg: evaporation) for certain components.
  END
  &replace MATERIAL GROUP: Particle Solids
    Group Description = Pure solid substances that can be used for particle \
tracking
  END
  &replace MATERIAL GROUP: Peng Robinson Dry Hydrocarbons
    Group Description = Common hydrocarbons which use the Peng Robinson \
equation of state. Suitable for dry real gas models.
  END
  &replace MATERIAL GROUP: Peng Robinson Dry Refrigerants
    Group Description = Common refrigerants which use the Peng Robinson \
equation of state. Suitable for dry real gas models.
  END
  &replace MATERIAL GROUP: Peng Robinson Dry Steam
    Group Description = Water materials which use the Peng Robinson equation \
of state. Suitable for dry steam modelling.
  END
  &replace MATERIAL GROUP: Peng Robinson Wet Hydrocarbons
    Group Description = Common hydrocarbons which use the Peng Robinson \
equation of state. Suitable for condensing real gas models.
  END
  &replace MATERIAL GROUP: Peng Robinson Wet Refrigerants
    Group Description = Common refrigerants which use the Peng Robinson \
equation of state. Suitable for condensing real gas models.
  END
  &replace MATERIAL GROUP: Peng Robinson Wet Steam
    Group Description = Water materials which use the Peng Robinson equation \
of state. Suitable for condensing steam modelling.
  END
  &replace MATERIAL GROUP: Real Gas Combustion
    Group Description = Real gas materials which can be use for gas phase \
combustion. Ideal gas specific heat coefficients are specified using the NASA SP-\
273 format.
  END
  &replace MATERIAL GROUP: Redlich Kwong Dry Hydrocarbons
    Group Description = Common hydrocarbons which use the Redlich Kwong \
equation of state. Suitable for dry real gas models.
  END
  &replace MATERIAL GROUP: Redlich Kwong Dry Refrigerants
    Group Description = Common refrigerants which use the Redlich Kwong \
equation of state. Suitable for dry real gas models.
  END
  &replace MATERIAL GROUP: Redlich Kwong Dry Steam
    Group Description = Water materials which use the Redlich Kwong equation \
of state. Suitable for dry steam modelling.
  END
  &replace MATERIAL GROUP: Redlich Kwong Wet Hydrocarbons
    Group Description = Common hydrocarbons which use the Redlich Kwong \
equation of state. Suitable for condensing real gas models.
  END
  &replace MATERIAL GROUP: Redlich Kwong Wet Refrigerants
    Group Description = Common refrigerants which use the Redlich Kwong \
equation of state. Suitable for condensing real gas models.
  END
  &replace MATERIAL GROUP: Redlich Kwong Wet Steam
    Group Description = Water materials which use the Redlich Kwong equation \
of state. Suitable for condensing steam modelling.
  END
  &replace MATERIAL GROUP: Soot
    Group Description = Solid substances that can be used when performing \
soot modelling
  END
  &replace MATERIAL GROUP: User
    Group Description = Materials that are defined by the user
  END
  &replace MATERIAL GROUP: Water Data
    Group Description = Liquid and vapour water materials with constant \
properties. Can be combined with NASA SP-273 materials for combustion modelling.
  END
  &replace MATERIAL GROUP: Wet Peng Robinson
    Group Description = Materials with properties specified using the built \
in Peng Robinson equation of state. Suitable for wet real gas modelling.
  END
  &replace MATERIAL GROUP: Wet Redlich Kwong
    Group Description = Materials with properties specified using the built \
in Redlich Kwong equation of state. Suitable for wet real gas modelling.
  END
  &replace MATERIAL GROUP: Wet Steam
    Group Description = Materials with properties specified using the IAPWS \
equation of state. Suitable for wet steam modelling.
  END
  &replace MATERIAL: Air Ideal Gas
    Material Description = Air Ideal Gas (constant Cp)
    Material Group = Air Data, Calorically Perfect Ideal Gases
    Object Origin = Default
    Option = Pure Substance
    Thermodynamic State = Gas
    PROPERTIES:
      Option = General Material
      ABSORPTION COEFFICIENT:
        Absorption Coefficient = 0.01 [m^-1]
        Option = Value
      END
      DYNAMIC VISCOSITY:
        Dynamic Viscosity = 1.831E-05 [kg m^-1 s^-1]
        Option = Value
      END
      EQUATION OF STATE:
        Molar Mass = 28.96 [kg kmol^-1]
        Option = Ideal Gas
      END
      REFERENCE STATE:
        Option = Specified Point
        Reference Pressure = 1 [atm]
        Reference Specific Enthalpy = 0. [J/kg]
        Reference Specific Entropy = 0. [J/kg/K]
        Reference Temperature = 25 [C]
      END
      REFRACTIVE INDEX:
        Option = Value
        Refractive Index = 1.0 [m m^-1]
      END
      SCATTERING COEFFICIENT:
        Option = Value
        Scattering Coefficient = 0.0 [m^-1]
      END
      SPECIFIC HEAT CAPACITY:
        Option = Value
        Specific Heat Capacity = 1.0044E+03 [J kg^-1 K^-1]
        Specific Heat Type = Constant Pressure
      END
      THERMAL CONDUCTIVITY:
        Option = Value
        Thermal Conductivity = 2.61E-2 [W m^-1 K^-1]
      END
    END
  END
  &replace MATERIAL: Air at 25 C
    Material Description = Air at 25 C and 1 atm (dry)
    Material Group = Air Data, Constant Property Gases
    Object Origin = Default
    Option = Pure Substance
    Thermodynamic State = Gas
    PROPERTIES:
      Option = General Material
      ABSORPTION COEFFICIENT:
        Absorption Coefficient = 0.01 [m^-1]
        Option = Value
      END
      DYNAMIC VISCOSITY:
        Dynamic Viscosity = 1.831E-05 [kg m^-1 s^-1]
        Option = Value
      END
      EQUATION OF STATE:
        Density = 1.185 [kg m^-3]
        Molar Mass = 28.96 [kg kmol^-1]
        Option = Value
      END
      REFERENCE STATE:
        Option = Specified Point
        Reference Pressure = 1 [atm]
        Reference Specific Enthalpy = 0. [J/kg]
        Reference Specific Entropy = 0. [J/kg/K]
        Reference Temperature = 25 [C]
      END
      REFRACTIVE INDEX:
        Option = Value
        Refractive Index = 1.0 [m m^-1]
      END
      SCATTERING COEFFICIENT:
        Option = Value
        Scattering Coefficient = 0.0 [m^-1]
      END
      SPECIFIC HEAT CAPACITY:
        Option = Value
        Specific Heat Capacity = 1.0044E+03 [J kg^-1 K^-1]
        Specific Heat Type = Constant Pressure
      END
      THERMAL CONDUCTIVITY:
        Option = Value
        Thermal Conductivity = 2.61E-02 [W m^-1 K^-1]
      END
      THERMAL EXPANSIVITY:
        Option = Value
        Thermal Expansivity = 0.003356 [K^-1]
      END
    END
  END
  &replace MATERIAL: Aluminium
    Material Group = CHT Solids, Particle Solids
    Option = Pure Substance
    Thermodynamic State = Solid
    PROPERTIES:
      Option = General Material
      EQUATION OF STATE:
        Density = 2702 [kg m^-3]
        Molar Mass = 26.98 [kg kmol^-1]
        Option = Value
      END
      REFERENCE STATE:
        Option = Specified Point
        Reference Specific Enthalpy = 0 [J/kg]
        Reference Specific Entropy = 0 [J/kg/K]
        Reference Temperature = 25 [C]
      END
      SPECIFIC HEAT CAPACITY:
        Option = Value
        Specific Heat Capacity = 9.03E+02 [J kg^-1 K^-1]
      END
      THERMAL CONDUCTIVITY:
        Option = Value
        Thermal Conductivity = 237 [W m^-1 K^-1]
      END
    END
  END
  &replace MATERIAL: Copper
    Material Group = CHT Solids, Particle Solids
    Option = Pure Substance
    Thermodynamic State = Solid
    PROPERTIES:
      Option = General Material
      EQUATION OF STATE:
        Density = 8933 [kg m^-3]
        Molar Mass = 63.55 [kg kmol^-1]
        Option = Value
      END
      REFERENCE STATE:
        Option = Specified Point
        Reference Specific Enthalpy = 0 [J/kg]
        Reference Specific Entropy = 0 [J/kg/K]
        Reference Temperature = 25 [C]
      END
      SPECIFIC HEAT CAPACITY:
        Option = Value
        Specific Heat Capacity = 3.85E+02 [J kg^-1 K^-1]
      END
      THERMAL CONDUCTIVITY:
        Option = Value
        Thermal Conductivity = 401.0 [W m^-1 K^-1]
      END
    END
  END
  &replace MATERIAL: Soot
    Material Group = Soot
    Option = Pure Substance
    Thermodynamic State = Solid
    PROPERTIES:
      Option = General Material
      ABSORPTION COEFFICIENT:
        Absorption Coefficient = 0 [m^-1]
        Option = Value
      END
      EQUATION OF STATE:
        Density = 2000 [kg m^-3]
        Molar Mass = 12 [kg kmol^-1]
        Option = Value
      END
      REFERENCE STATE:
        Option = Automatic
      END
    END
  END
  &replace MATERIAL: Steel
    Material Group = CHT Solids, Particle Solids
    Option = Pure Substance
    Thermodynamic State = Solid
    PROPERTIES:
      Option = General Material
      EQUATION OF STATE:
        Density = 7854 [kg m^-3]
        Molar Mass = 55.85 [kg kmol^-1]
        Option = Value
      END
      REFERENCE STATE:
        Option = Specified Point
        Reference Specific Enthalpy = 0 [J/kg]
        Reference Specific Entropy = 0 [J/kg/K]
        Reference Temperature = 25 [C]
      END
      SPECIFIC HEAT CAPACITY:
        Option = Value
        Specific Heat Capacity = 4.34E+02 [J kg^-1 K^-1]
      END
      THERMAL CONDUCTIVITY:
        Option = Value
        Thermal Conductivity = 60.5 [W m^-1 K^-1]
      END
    END
  END
  &replace MATERIAL: Water
    Material Description = Water (liquid)
    Material Group = Water Data, Constant Property Liquids
    Object Origin = Default
    Option = Pure Substance
    Thermodynamic State = Liquid
    PROPERTIES:
      Option = General Material
      ABSORPTION COEFFICIENT:
        Absorption Coefficient = 1.0 [m^-1]
        Option = Value
      END
      DYNAMIC VISCOSITY:
        Dynamic Viscosity = 8.899E-4 [kg m^-1 s^-1]
        Option = Value
      END
      EQUATION OF STATE:
        Density = 997.0 [kg m^-3]
        Molar Mass = 18.02 [kg kmol^-1]
        Option = Value
      END
      REFERENCE STATE:
        Option = Specified Point
        Reference Pressure = 1 [atm]
        Reference Specific Enthalpy = 0.0 [J/kg]
        Reference Specific Entropy = 0.0 [J/kg/K]
        Reference Temperature = 25 [C]
      END
      REFRACTIVE INDEX:
        Option = Value
        Refractive Index = 1.0 [m m^-1]
      END
      SCATTERING COEFFICIENT:
        Option = Value
        Scattering Coefficient = 0.0 [m^-1]
      END
      SPECIFIC HEAT CAPACITY:
        Option = Value
        Specific Heat Capacity = 4181.7 [J kg^-1 K^-1]
        Specific Heat Type = Constant Pressure
      END
      THERMAL CONDUCTIVITY:
        Option = Value
        Thermal Conductivity = 0.6069 [W m^-1 K^-1]
      END
      THERMAL EXPANSIVITY:
        Option = Value
        Thermal Expansivity = 2.57E-04 [K^-1]
      END
    END
  END
  &replace MATERIAL: Water Ideal Gas
    Material Description = Water Vapour Ideal Gas (100 C and 1 atm)
    Material Group = Calorically Perfect Ideal Gases, Water Data
    Option = Pure Substance
    Thermodynamic State = Gas
    PROPERTIES:
      Option = General Material
      ABSORPTION COEFFICIENT:
        Absorption Coefficient = 1.0 [m^-1]
        Option = Value
      END
      DYNAMIC VISCOSITY:
        Dynamic Viscosity = 9.4E-06 [kg m^-1 s^-1]
        Option = Value
      END
      EQUATION OF STATE:
        Molar Mass = 18.02 [kg kmol^-1]
        Option = Ideal Gas
      END
      REFERENCE STATE:
        Option = Specified Point
        Reference Pressure = 1.014 [bar]
        Reference Specific Enthalpy = 0. [J/kg]
        Reference Specific Entropy = 0. [J/kg/K]
        Reference Temperature = 100 [C]
      END
      REFRACTIVE INDEX:
        Option = Value
        Refractive Index = 1.0 [m m^-1]
      END
      SCATTERING COEFFICIENT:
        Option = Value
        Scattering Coefficient = 0.0 [m^-1]
      END
      SPECIFIC HEAT CAPACITY:
        Option = Value
        Specific Heat Capacity = 2080.1 [J kg^-1 K^-1]
        Specific Heat Type = Constant Pressure
      END
      THERMAL CONDUCTIVITY:
        Option = Value
        Thermal Conductivity = 193E-04 [W m^-1 K^-1]
      END
    END
  END
END

>physicsupdate
> update

FLOW: Flow Analysis 1
  &replace   SOLVER CONTROL:
    Turbulence Numerics = First Order
    ADVECTION SCHEME:
      Option = Upwind
    END # ADVECTION SCHEME:
    CONVERGENCE CONTROL:
      Maximum Number of Iterations = 100
      Minimum Number of Iterations = 1
      Physical Timescale = 2 [s]
      Timescale Control = Physical Timescale
    END # CONVERGENCE CONTROL:
    CONVERGENCE CRITERIA:
      Residual Target = 1.E-4
      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=StaticMixer.def,\
operation=write def file


>writeCaseFile filename=StaticMixer.cfx



# 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";
!                }
!
!       }
! }
