! use File::Copy;
! use Cwd;

COMMAND FILE:
  CFX Pre Version = 12.0
END

>load mode=new
> update

! getEgFile("Bump2Dpatran.out","Bump2DExpressions.ccl");

>writeCaseFile filename=Bump2D.cfx
> update

>gtmImport filename=Bump2Dpatran.out, type=Patran, \
genOpt= -n, units=m, nameStrategy= Assembly
> update


>importccl filename=Bump2DExpressions.ccl, mode = \
append, autoLoadLibrary = none
> 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
END
> update

FLOW: Flow Analysis 1
  &replace   DOMAIN: Default Domain
    Coord Frame = Coord 0
    Domain Type = Fluid
    Location = Primitive 3D
    BOUNDARY: Default Domain Default
      Boundary Type = WALL
      Create Other Side = Off
      Interface Boundary = Off
      Location = BACK,BOTTOM1,BOTTOM2,BOTTOM3,FRONT,INFLOW,OUTFLOW,TOP
      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:Default Domain Default
    DOMAIN MODELS:
      BUOYANCY MODEL:
        Buoyancy Reference Density = DenRef
        Gravity X Component = 0 [m s^-2]
        Gravity Y Component = -g
        Gravity Z Component = 0 [m s^-2]
        Option = Buoyant
        BUOYANCY REFERENCE LOCATION:
          Option = Automatic
        END # BUOYANCY REFERENCE LOCATION:
      END # BUOYANCY MODEL:
      DOMAIN MOTION:
        Option = Stationary
      END # DOMAIN MOTION:
      MESH DEFORMATION:
        Option = None
      END # MESH DEFORMATION:
      REFERENCE PRESSURE:
        Reference Pressure = 1 [atm]
      END # REFERENCE PRESSURE:
    END # DOMAIN MODELS:
    FLUID DEFINITION: Air
      Material = Air at 25 C
      Option = Material Library
      MORPHOLOGY:
        Option = Continuous Fluid
      END # MORPHOLOGY:
    END # FLUID DEFINITION:Air
    FLUID DEFINITION: Water
      Material = Water
      Option = Material Library
      MORPHOLOGY:
        Option = Continuous Fluid
      END # MORPHOLOGY:
    END # FLUID DEFINITION:Water
    FLUID MODELS:
      COMBUSTION MODEL:
        Option = None
      END # COMBUSTION MODEL:
      FLUID: Air
        FLUID BUOYANCY MODEL:
          Option = Density Difference
        END # FLUID BUOYANCY MODEL:
      END # FLUID:Air
      FLUID: Water
        FLUID BUOYANCY MODEL:
          Option = Density Difference
        END # FLUID BUOYANCY MODEL:
      END # FLUID:Water
      HEAT TRANSFER MODEL:
        Fluid Temperature = 25 [C]
        Homogeneous Model = True
        Option = Isothermal
      END # HEAT TRANSFER MODEL:
      THERMAL RADIATION MODEL:
        Option = None
      END # THERMAL RADIATION MODEL:
      TURBULENCE MODEL:
        Option = k epsilon
        BUOYANCY TURBULENCE:
          Option = None
        END # BUOYANCY TURBULENCE:
      END # TURBULENCE MODEL:
      TURBULENT WALL FUNCTIONS:
        Option = Scalable
      END # TURBULENT WALL FUNCTIONS:
    END # FLUID MODELS:
    FLUID PAIR: Air | Water
      INTERPHASE TRANSFER MODEL:
        Option = None
      END # INTERPHASE TRANSFER MODEL:
      MASS TRANSFER:
        Option = None
      END # MASS TRANSFER:
      SURFACE TENSION MODEL:
        Option = None
      END # SURFACE TENSION MODEL:
    END # FLUID PAIR:Air | Water
    MULTIPHASE MODELS:
      Homogeneous Model = On
      FREE SURFACE MODEL:
        Option = Standard
      END # FREE SURFACE MODEL:
    END # MULTIPHASE MODELS:
  END # DOMAIN:Default Domain
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Default Domain
    &replace     BOUNDARY: inflow
      Boundary Type = INLET
      Interface Boundary = Off
      Location = INFLOW
      BOUNDARY CONDITIONS:
        FLOW REGIME:
          Option = Subsonic
        END # FLOW REGIME:
        MASS AND MOMENTUM:
          Normal Speed = 0.26 [m s^-1]
          Option = Normal Speed
        END # MASS AND MOMENTUM:
        TURBULENCE:
          Eddy Length Scale = UpH
          Fractional Intensity = 0.05
          Option = Intensity and Length Scale
        END # TURBULENCE:
      END # BOUNDARY CONDITIONS:
      FLUID: Air
        BOUNDARY CONDITIONS:
          VOLUME FRACTION:
            Option = Value
            Volume Fraction = UpVFAir
          END # VOLUME FRACTION:
        END # BOUNDARY CONDITIONS:
      END # FLUID:Air
      FLUID: Water
        BOUNDARY CONDITIONS:
          VOLUME FRACTION:
            Option = Value
            Volume Fraction = UpVFWater
          END # VOLUME FRACTION:
        END # BOUNDARY CONDITIONS:
      END # FLUID:Water
    END # BOUNDARY:inflow
  END # DOMAIN:Default Domain
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Default Domain
    &replace     BOUNDARY: outflow
      Boundary Type = OUTLET
      Interface Boundary = Off
      Location = OUTFLOW
      BOUNDARY CONDITIONS:
        FLOW REGIME:
          Option = Subsonic
        END # FLOW REGIME:
        MASS AND MOMENTUM:
          Option = Static Pressure
          Relative Pressure = DownPres
        END # MASS AND MOMENTUM:
      END # BOUNDARY CONDITIONS:
    END # BOUNDARY:outflow
  END # DOMAIN:Default Domain
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Default Domain
    &replace     BOUNDARY: front
      Boundary Type = SYMMETRY
      Interface Boundary = Off
      Location = FRONT
    END # BOUNDARY:front
  END # DOMAIN:Default Domain
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Default Domain
    &replace     BOUNDARY: back
      Boundary Type = SYMMETRY
      Interface Boundary = Off
      Location = BACK
    END # BOUNDARY:back
  END # DOMAIN:Default Domain
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Default Domain
    &replace     BOUNDARY: top
      Boundary Type = OPENING
      Interface Boundary = Off
      Location = TOP
      BOUNDARY CONDITIONS:
        FLOW REGIME:
          Option = Subsonic
        END # FLOW REGIME:
        MASS AND MOMENTUM:
          Option = Entrainment
          Relative Pressure = 0 [Pa]
        END # MASS AND MOMENTUM:
        TURBULENCE:
          Option = Zero Gradient
        END # TURBULENCE:
      END # BOUNDARY CONDITIONS:
      FLUID: Air
        BOUNDARY CONDITIONS:
          VOLUME FRACTION:
            Option = Value
            Volume Fraction = 1
          END # VOLUME FRACTION:
        END # BOUNDARY CONDITIONS:
      END # FLUID:Air
      FLUID: Water
        BOUNDARY CONDITIONS:
          VOLUME FRACTION:
            Option = Value
            Volume Fraction = 0
          END # VOLUME FRACTION:
        END # BOUNDARY CONDITIONS:
      END # FLUID:Water
    END # BOUNDARY:top
  END # DOMAIN:Default Domain
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  DOMAIN: Default Domain
    &replace     BOUNDARY: bottom
      Boundary Type = WALL
      Create Other Side = Off
      Interface Boundary = Off
      Location = BOTTOM1,BOTTOM2,BOTTOM3
      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:bottom
  END # DOMAIN:Default Domain
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  &replace   INITIALISATION:
    Option = Automatic
    FLUID: Air
      INITIAL CONDITIONS:
        VOLUME FRACTION:
          Option = Automatic with Value
          Volume Fraction = UpVFAir
        END # VOLUME FRACTION:
      END # INITIAL CONDITIONS:
    END # FLUID:Air
    FLUID: Water
      INITIAL CONDITIONS:
        VOLUME FRACTION:
          Option = Automatic with Value
          Volume Fraction = UpVFWater
        END # VOLUME FRACTION:
      END # INITIAL CONDITIONS:
    END # FLUID:Water
    INITIAL CONDITIONS:
      Velocity Type = Cartesian
      CARTESIAN VELOCITY COMPONENTS:
        Option = Automatic with Value
        U = 0.26 [m s^-1]
        V = 0 [m s^-1]
        W = 0 [m s^-1]
      END # CARTESIAN VELOCITY COMPONENTS:
      STATIC PRESSURE:
        Option = Automatic with Value
        Relative Pressure = UpPres
      END # STATIC PRESSURE:
      TURBULENCE INITIAL CONDITIONS:
        Option = Medium Intensity and Eddy Viscosity Ratio
      END # TURBULENCE INITIAL CONDITIONS:
    END # INITIAL CONDITIONS:
  END # INITIALISATION:
END # FLOW:Flow Analysis 1
> update

FLOW: Flow Analysis 1
  &replace   MESH ADAPTION:
    Activate Adaption = On
    Domain Name = Default Domain
    Save Intermediate Files = Off
    Subdomain List = Assembly
    ADAPTION ADVANCED OPTIONS:
      Node Allocation Parameter = 1.6
      Number of Adaption Levels = 2
    END # ADAPTION ADVANCED OPTIONS:
    ADAPTION CONVERGENCE CRITERIA:
      Adaption Target Residual = 0.001
      Maximum Iterations per Step = 100
      Option = RMS Norm for Residuals
    END # ADAPTION CONVERGENCE CRITERIA:
    ADAPTION CRITERIA:
      Maximum Number of Adaption Steps = 2
      Node Factor = 4
      Option = Multiple of Initial Mesh
      Variables List = Air.Volume Fraction
    END # ADAPTION CRITERIA:
    ADAPTION METHOD:
      Minimum Edge Length = 0.0
      Option = Solution Variation
    END # ADAPTION METHOD:
  END # MESH ADAPTION:
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 = 200
      Minimum Number of Iterations = 1
      Physical Timescale = 0.25 [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:
    MULTIPHASE CONTROL:
      Volume Fraction Coupling = Coupled
    END # MULTIPHASE CONTROL:
  END # SOLVER CONTROL:
END # FLOW:Flow Analysis 1
> update

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

>writeCaseFile filename=Bump2D.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";
!                }
!
!       }
! }
