# @(#)fluent.tcl	    1.1 11 May 1995
# name changes FLUENT -> Fluent 30 Aug 1995
# Fluent Inc. customizations included below.
#
# ICEM CFD solver interface routine for the manager.
#
# Copyright (c) 1993-1995 ICEM Systems.

proc fluent_write_input {} {
    global confname file_name fluent_output_path env
    global superdomain_path domain_type icem_fluent icem_powermesh
    global file_name
    
    set create_super 0
    set doms [domain_select $file_name(domains_dir) "You may either select a superdomain or \
a set of structured domains.  If you select structured domains, they will be \
converted into a superdomain using the \"Structured -> Super\" program." \
    struct 0]
    if {$doms == {}} return
    if {[llength $doms] == 1} {
	case $domain_type([lindex $doms 0]) in {
	    super1 {
		set super $doms
	    }
	    struct {
		set create_super 1
	    }
	    default {
		errormsg "Bad domain type \"$which\""
		return
	    }
	}
    } else {
	set create_super 1
    }

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

    if { !$icem_fluent && !$icem_powermesh } {
	set outfile $file_name(transfer_dir)/fluent.grd
    } else {
		if {$icem_fluent} {
			set outfile [string toupper fluent].GRD
		} else {
		    set outfile $file_name(transfer_dir)/fluent.grd
		}
    }

    if {$create_super} {
	set super $file_name(domains_dir)/super_domain.1
	infomsg "Creating superdomain \"super_domain.1\"from structured domains"
	
	set text ""
	foreach d $doms { append text "$d\n" }
	ic_write_file domain_list $text
	
	runcom "\"$superdomain_path\" -t \"$topofile\" \
		-o \"$super\" -dom_list domain_list"
    }
        
    set params {}
    if { !$icem_fluent && !$icem_powermesh } {
   	 lappend params {v4grid -opt {{"Fluent/V4" 1} {"Fluent/BFC" 0}} \
		-title "Grid file type" -help "Grid file type"}
    } else {
         lappend params {v4grid -opt {{"Fluent/V4" 1}} \
                -title "Grid file type" -help "Grid file type"}
    }
    lappend params {bocofile -type path -title "Boco file" \
	-help "Boundary condition file"}
    lappend params {outfile -type path -title "Output file" -help "Output file"}
    if {![dialog .fluent "Fluent" \
	  "Please edit the following fluent options." $params]} return
     
    if {[file exists $outfile] && \
        [query_question .query "Overwrite $outfile?"] != "*okay*"} return

    if {![file exists $bocofile]} {
	errormsg "File $bocofile doesn't exist"
	return
    }
    
#   set command "\"$fluent_output_path\" -dom \"$super\" -b \"$bocofile\" -conf \"$confname\""
    set command "\"$fluent_output_path\" -dom \"$super\" -b \"$bocofile\" -f \"$ftopofile\" -t \"$topofile\""
    if {$v4grid} {set command "$command -v4"}
    set command "$command \"$outfile\""
    
    runcom $command ""
    cmd_rm domain_list
}

