
# ICEM CFD solver interface routine for the manager.
#
# Copyright (c) 1993-1995 ICEM Systems.

proc cfl3d_write_input {} {
    global confname file_name cfl3d_output_path icem_fluent icem_powermesh
    global cfl3d_params cfl3d_param_table
    global file_name env

    set domains [domain_select $file_name(domains_dir) "Select structured/superdomain domains." mixed_super 1]    
    if {$domains == {}} return
    
    get_boco_topo

    set outfile $file_name(transfer_dir)/cfl3d
    
    set scale 0
    set x 1.0
    set y 1.0
    set z 1.0
    set double 0
    
    if {![dialog .cfl3d "CFL3D" \
	"Please edit the following CFL3D (6.0) options. " {
	{topofile -type path -title "Topo file" -help "Topology file"}
	{bocofile -type path -title "Boco file" -help "Boundary condition file"}
	{double -opt {{"single precision" 0} {"double precision" 1}} \
		-title "Grid binary format"}
	{scale -opt {{"Yes" 1} {"No" 0}} -title "Scaling" \
		-help "Scaling of coordinates (enter 3 values for x, y & z"}
	{x -type string -active {$scale} -title "x scaling factor" \
                -help "Enter x scaling factor"}
        {y -type string -active {$scale} -title "y scaling factor" \
                -help "Enter y scaling factor"}
        {z -type string -active {$scale} -title "z scaling factor" \
		-help "Enter z scaling factor"}
	{outfile -type path -title "Output file" -help "Output file"}
    }]} return
    if {![file exists $topofile]} {
        errormsg "Topology file doesn't exist!"
        return
    }
    if {![file exists $bocofile]} {
        errormsg "Boundary condition file doesn't exist!"
        return
    }
    solver_params_load cfl3d cfl3d_params
    if ![solver_params "CFL3D Solver Parameters" cfl3d_params $cfl3d_param_table] return
    set paramfile [solver_params_save cfl3d cfl3d_params]
    cmd_rm domain_list
#   set fp [open domain_list w]
#   foreach d $domains { puts $fp $d }
#   close $fp
    set text ""
    foreach d $domains { append text "$d\n" }
    ic_write_file domain_list $text
    set command "\"$cfl3d_output_path\" -t \"$topofile\" -b \"$bocofile\" -f \"$ftopofile\""
    if $scale {set command "$command -scale $x,$y,$z"}
    if $double {set command "$command -dbl"}
    set command "$command -cfl \"$paramfile\" -dom_list domain_list \"$outfile\""
    
    runxcom ICEM-CFD/CFL3D-Interface $command "" 1 0
    cmd_rm domain_list
}

set cfl3d_param_table {
    { file2 "plot3d grid" "" "-columnspan 4" }
    { file3 "plot3d solution" "" "-columnspan 4" }
    newrow
    { file4 "main output" "" "-columnspan 4" }
    { file5 "residual & force coeff. history" "" "-columnspan 4" }
    newrow
    { file6 "turbulence model residual history" "" "-columnspan 4" }
    { file7 "Baldwin-Lomax output" "" "-columnspan 4" }
    newrow
    { file8 "secondary output" "" "-columnspan 4" }
    { file9 "printout" "" "-columnspan 4" }
    newrow
    { file10 "unsteady pressures from forced oscillations" "" "-columnspan 4" }
    { file11 "interpolation coefficients for chimera grids" "" "-columnspan 4" }
    newrow
    { file12 "interpolation coefficients for patched grids" "" "-columnspan 4" }
    { file13 "restart" "" "-columnspan 4" }
    newrow
    { title "title" "" "-columnspan 8" }
    newrow
    XMACH
    ALPHA
    BETA
    REUE
    TINF
    IALPH
    IHSTRY
    newrow
    SREF
    CREF
    BREF
    XMC
    YMC
    ZMC
    newrow
    DT
    IREST
    IFLAGTS
    FMAX
    CFLTAU
    newrow
    NPRINT
    NWREST
    ICHK
    NTSTEP
    ITA
    newrow
    IVISC(I)
    IVISC(J)
    IVISC(K)
    IDIAG(I)
    IDIAG(J)
    IDIAG(K)
    IFLIM(I)
    IFLIM(J)
    IFLIM(K)
    newrow
    IFDS(I)
    IFDS(J)
    IFDS(K)
    RKAP0(I)
    RKAP0(J)
    RKAP0(K)
    newrow
    MSEQ
    MGFLAG
    ICONSF
    MTT
    NGAM
    newrow
    ISSC
    EPSSSC(1)
    EPSSSC(2)
    EPSSSC(3)
    ISSR
    EPSSSR(1)
    EPSSSR(2)
    EPSSSR(3)
    newrow
    NCYC
    MGLEVG
    NEMGL
    NITFO
}
