
# This code creates the ICEM CFD Manager.
#
# Copyright (c) 1993 - 1996 Pacific Marketing and Consulting, Inc,
#       and ICEM Systems, GmbH.  All rights reserved.
# Author:  Michael E. Hohemeyer, hohmeyer@icemcfd.com

# Stuff to deal with prism offsets.

proc add_prisms { } {

	global place env tetra_path cutter_path


	set tetra_file [domain_select $place/domains "Select a tetra mesh." unstruct 0]
	if {$tetra_file == {}} return

	set prism_file $place/domains/prism
	set tetin_file $place/mesh/tetin1
	set offset_command "$env(ICEM_ACN)/icemcfd/offset $tetra_file $tetin_file $prism_file"

#	puts $offset_command
	runxcom PRISMS_INWARD "$offset_command" "" 0 0

# create the tetin file
	set tetin_prism $place/mesh/tetin_prism

	set fp [ open $tetin_prism w ]
	puts $fp "boco_file $place/mesh/boco"

# for each surface in the old tetin file create a new surface
# with the same pid in the new tetin file
	set ot [ open $tetin_file r ]

	set pid 0
	while { ! [ eof $ot ] } {
		set line [ gets $ot ]
		if { [ lindex $line 0 ] == "define_surface" } {
			puts $fp "$line pid $pid"
			puts $fp "unstruct_mesh $place/domains/prism"
			incr pid
		}
	}




	puts $fp "define_curve"
	puts $fp "unstruct_curve $place/domains/prism"
	puts $fp "prescribed_point $place/domains/prism"
	puts $fp "define_group 0 1"
	puts $fp "0"
	puts $fp "define_model 100 no_smear"
	set lines [cmd_grep material_point $place/mesh/tetin1]
	puts $fp $lines
	puts $fp "return"

	close $fp

# create the param file
	set uncut_inside $place/domains/uncut_inside
	build_tetra_param_file tetra_params $tetin_prism $uncut_inside

# mesh the insides
	set tetra_command "$tetra_path tetra_params"
	runxcom MESH_MIDDLE "$tetra_command" "" 0 0


# run the cutter
	set inside $place/domains/inside
	set cutter_command "$cutter_path $uncut_inside $tetin_prism $inside"
	puts $cutter_command
	runxcom CUTTER "$cutter_command" "" 0 0

# create prisms
	set hybrid_file $place/domains/hybrid
	set prism_command "$env(ICEM_ACN)/icemcfd/prism $tetin_file $inside $prism_file $hybrid_file"
	puts $prism_command
	runxcom EXTRUDE_PRISMS "$prism_command" "" 0 0

#	runxcom ADD_PRISMS "$offset_command&& $tetra_command&& $cutter_command&& $prism_command" "" 1 1

#	runxcom ADD_PRISMS "$prism_command" "" 1 1

}
