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

proc alpha_flow_write_input {} {
    global file_name confname alpha_flow_output_path
    global file_name
    
    get_boco_topo

    set outputfile $file_name(transfer_dir)/alpha_flow
    set input 0
    set scale 0
    set thickness 0
    set x 1
    set y 1
    set z 1
    set format 0
    set fam_group 0

    if {![dialog .alpha_flow "ALPHA-FLOW" \
          "Please edit the following ALPHA-FLOW options. " {
	       {input -opt {{BFC-Compressible 0} {BFC-Incompressible 1} \
		{Cartesian 2} {Cylindrical 3}} -title "Select grid type"}
               {outputfile -type path -title "Set prefix of output file(s)"}
               {bocofile -type path -title "Boundary condition file" }
	       {topofile -type path -active {$input<2} -title "Topology file"}
	       {fam_group -opt {{Yes 1} {No 0}} \
                   -title "Create groups according to mesher families"}
	       {thickness -type string -active {$input==1} -title "Thickness"}
	       {scale -opt {{"Yes" 1} {"No" 0}} -title "Scaling"}
               {x -type string -active {$scale} -title "x scaling factor" }
               {y -type string -active {$scale} -title "y scaling factor" }
               {z -type string -active {$scale} -title "z scaling factor" }
	       {format -opt {{Yes 1} {No 0}} -active {$input<2} \
		-title "Formatted BFC grid file?" }
           }]} return
   
    if {[file exists $outputfile.geo] && \
        [query_question .query "Overwrite $outputfile.geo?"] != "*okay*"} return

    if {![file exists $bocofile]} {
        errormsg "File $bocofile doesn't exist"
        return
    }

    if {$input<2} {

        set seldoms [domain_select $file_name(domains_dir) "Select structured domains." struct 0]

 	if {$seldoms == {}} {
             errormsg "No domains selected"
             return
        }

        if {![file exists $topofile]} {
             errormsg "Topo file $topofile doesn't exist"
             return
        }

        cmd_rm domain_list
        set text ""
        foreach d $seldoms { append text "$d\n" }
        ic_write_file domain_list $text

#       set fp [open domain_list w]
#       foreach d $seldoms { puts $fp $d }
#       close $fp

	set command "\"$alpha_flow_output_path\" -dom_list domain_list \
	    -b \"$bocofile\" -t \"$topofile\" \"$outputfile\" -f \"$ftopofile\"" 
	if $input  {set command "$command -inc -thick $thickness"}

    } else {

	set uns_dom [domain_select $file_name(domains_dir) "Select an unstructured (cartesian or \
	cylindrical) domain" unstruct 0]

	if {$uns_dom == {}} return

	if {$input==2} {set command "\"$alpha_flow_output_path\" -cart \
	    -b \"$bocofile\""}
	if {$input==3} {set command "\"$alpha_flow_output_path\" -cyl \
	    -b \"$bocofile\""}
	set command "$command \"$uns_dom\" \"$outputfile\""

    }
    if $format {set command "$command -fmt"}
    if $scale  {set command "$command -scale $x,$y,$z"}
    if $fam_group {set command "$command -fam"}

    runxcom ICEM-CFD/ALPHA-FLOW-Interface $command "" 1 0
    cmd_rm domain_list
}
