<!--{{{-->
<link rel='alternate' type='application/rss+xml' title='RSS' href='index.xml' />
<!--}}}-->
Background: #fff
Foreground: #000
PrimaryPale: #8cf
PrimaryLight: #18f
PrimaryMid: #04b
PrimaryDark: #014
SecondaryPale: #ffc
SecondaryLight: #fe8
SecondaryMid: #db4
SecondaryDark: #841
TertiaryPale: #eee
TertiaryLight: #ccc
TertiaryMid: #999
TertiaryDark: #666
Error: #f88
/*{{{*/
body {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}

a {color:[[ColorPalette::PrimaryMid]];}
a:hover {background-color:[[ColorPalette::PrimaryMid]]; color:[[ColorPalette::Background]];}
a img {border:0;}

h1,h2,h3,h4,h5,h6 {color:[[ColorPalette::SecondaryDark]]; background:transparent;}
h1 {border-bottom:2px solid [[ColorPalette::TertiaryLight]];}
h2,h3 {border-bottom:1px solid [[ColorPalette::TertiaryLight]];}

.button {color:[[ColorPalette::PrimaryDark]]; border:1px solid [[ColorPalette::Background]];}
.button:hover {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::SecondaryLight]]; border-color:[[ColorPalette::SecondaryMid]];}
.button:active {color:[[ColorPalette::Background]]; background:[[ColorPalette::SecondaryMid]]; border:1px solid [[ColorPalette::SecondaryDark]];}

.header {background:[[ColorPalette::PrimaryMid]];}
.headerShadow {color:[[ColorPalette::Foreground]];}
.headerShadow a {font-weight:normal; color:[[ColorPalette::Foreground]];}
.headerForeground {color:[[ColorPalette::Background]];}
.headerForeground a {font-weight:normal; color:[[ColorPalette::PrimaryPale]];}

.tabSelected{color:[[ColorPalette::PrimaryDark]];
	background:[[ColorPalette::TertiaryPale]];
	border-left:1px solid [[ColorPalette::TertiaryLight]];
	border-top:1px solid [[ColorPalette::TertiaryLight]];
	border-right:1px solid [[ColorPalette::TertiaryLight]];
}
.tabUnselected {color:[[ColorPalette::Background]]; background:[[ColorPalette::TertiaryMid]];}
.tabContents {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::TertiaryPale]]; border:1px solid [[ColorPalette::TertiaryLight]];}
.tabContents .button {border:0;}

#sidebar {}
#sidebarOptions input {border:1px solid [[ColorPalette::PrimaryMid]];}
#sidebarOptions .sliderPanel {background:[[ColorPalette::PrimaryPale]];}
#sidebarOptions .sliderPanel a {border:none;color:[[ColorPalette::PrimaryMid]];}
#sidebarOptions .sliderPanel a:hover {color:[[ColorPalette::Background]]; background:[[ColorPalette::PrimaryMid]];}
#sidebarOptions .sliderPanel a:active {color:[[ColorPalette::PrimaryMid]]; background:[[ColorPalette::Background]];}

.wizard {background:[[ColorPalette::PrimaryPale]]; border:1px solid [[ColorPalette::PrimaryMid]];}
.wizard h1 {color:[[ColorPalette::PrimaryDark]]; border:none;}
.wizard h2 {color:[[ColorPalette::Foreground]]; border:none;}
.wizardStep {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];
	border:1px solid [[ColorPalette::PrimaryMid]];}
.wizardStep.wizardStepDone {background:[[ColorPalette::TertiaryLight]];}
.wizardFooter {background:[[ColorPalette::PrimaryPale]];}
.wizardFooter .status {background:[[ColorPalette::PrimaryDark]]; color:[[ColorPalette::Background]];}
.wizard .button {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::SecondaryLight]]; border: 1px solid;
	border-color:[[ColorPalette::SecondaryPale]] [[ColorPalette::SecondaryDark]] [[ColorPalette::SecondaryDark]] [[ColorPalette::SecondaryPale]];}
.wizard .button:hover {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::Background]];}
.wizard .button:active {color:[[ColorPalette::Background]]; background:[[ColorPalette::Foreground]]; border: 1px solid;
	border-color:[[ColorPalette::PrimaryDark]] [[ColorPalette::PrimaryPale]] [[ColorPalette::PrimaryPale]] [[ColorPalette::PrimaryDark]];}

.wizard .notChanged {background:transparent;}
.wizard .changedLocally {background:#80ff80;}
.wizard .changedServer {background:#8080ff;}
.wizard .changedBoth {background:#ff8080;}
.wizard .notFound {background:#ffff80;}
.wizard .putToServer {background:#ff80ff;}
.wizard .gotFromServer {background:#80ffff;}

#messageArea {border:1px solid [[ColorPalette::SecondaryMid]]; background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]];}
#messageArea .button {color:[[ColorPalette::PrimaryMid]]; background:[[ColorPalette::SecondaryPale]]; border:none;}

.popupTiddler {background:[[ColorPalette::TertiaryPale]]; border:2px solid [[ColorPalette::TertiaryMid]];}

.popup {background:[[ColorPalette::TertiaryPale]]; color:[[ColorPalette::TertiaryDark]]; border-left:1px solid [[ColorPalette::TertiaryMid]]; border-top:1px solid [[ColorPalette::TertiaryMid]]; border-right:2px solid [[ColorPalette::TertiaryDark]]; border-bottom:2px solid [[ColorPalette::TertiaryDark]];}
.popup hr {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::PrimaryDark]]; border-bottom:1px;}
.popup li.disabled {color:[[ColorPalette::TertiaryMid]];}
.popup li a, .popup li a:visited {color:[[ColorPalette::Foreground]]; border: none;}
.popup li a:hover {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; border: none;}
.popup li a:active {background:[[ColorPalette::SecondaryPale]]; color:[[ColorPalette::Foreground]]; border: none;}
.popupHighlight {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
.listBreak div {border-bottom:1px solid [[ColorPalette::TertiaryDark]];}

.tiddler .defaultCommand {font-weight:bold;}

.shadow .title {color:[[ColorPalette::TertiaryDark]];}

.title {color:[[ColorPalette::SecondaryDark]];}
.subtitle {color:[[ColorPalette::TertiaryDark]];}

.toolbar {color:[[ColorPalette::PrimaryMid]];}
.toolbar a {color:[[ColorPalette::TertiaryLight]];}
.selected .toolbar a {color:[[ColorPalette::TertiaryMid]];}
.selected .toolbar a:hover {color:[[ColorPalette::Foreground]];}

.tagging, .tagged {border:1px solid [[ColorPalette::TertiaryPale]]; background-color:[[ColorPalette::TertiaryPale]];}
.selected .tagging, .selected .tagged {background-color:[[ColorPalette::TertiaryLight]]; border:1px solid [[ColorPalette::TertiaryMid]];}
.tagging .listTitle, .tagged .listTitle {color:[[ColorPalette::PrimaryDark]];}
.tagging .button, .tagged .button {border:none;}

.footer {color:[[ColorPalette::TertiaryLight]];}
.selected .footer {color:[[ColorPalette::TertiaryMid]];}

.sparkline {background:[[ColorPalette::PrimaryPale]]; border:0;}
.sparktick {background:[[ColorPalette::PrimaryDark]];}

.error, .errorButton {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::Error]];}
.warning {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::SecondaryPale]];}
.lowlight {background:[[ColorPalette::TertiaryLight]];}

.zoomer {background:none; color:[[ColorPalette::TertiaryMid]]; border:3px solid [[ColorPalette::TertiaryMid]];}

.imageLink, #displayArea .imageLink {background:transparent;}

.annotation {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; border:2px solid [[ColorPalette::SecondaryMid]];}

.viewer .listTitle {list-style-type:none; margin-left:-2em;}
.viewer .button {border:1px solid [[ColorPalette::SecondaryMid]];}
.viewer blockquote {border-left:3px solid [[ColorPalette::TertiaryDark]];}

.viewer table, table.twtable {border:2px solid [[ColorPalette::TertiaryDark]];}
.viewer th, .viewer thead td, .twtable th, .twtable thead td {background:[[ColorPalette::SecondaryMid]]; border:1px solid [[ColorPalette::TertiaryDark]]; color:[[ColorPalette::Background]];}
.viewer td, .viewer tr, .twtable td, .twtable tr {border:1px solid [[ColorPalette::TertiaryDark]];}

.viewer pre {border:1px solid [[ColorPalette::SecondaryLight]]; background:[[ColorPalette::SecondaryPale]];}
.viewer code {color:[[ColorPalette::SecondaryDark]];}
.viewer hr {border:0; border-top:dashed 1px [[ColorPalette::TertiaryDark]]; color:[[ColorPalette::TertiaryDark]];}

.highlight, .marked {background:[[ColorPalette::SecondaryLight]];}

.editor input {border:1px solid [[ColorPalette::PrimaryMid]];}
.editor textarea {border:1px solid [[ColorPalette::PrimaryMid]]; width:100%;}
.editorFooter {color:[[ColorPalette::TertiaryMid]];}

#backstageArea {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::TertiaryMid]];}
#backstageArea a {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::Background]]; border:none;}
#backstageArea a:hover {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; }
#backstageArea a.backstageSelTab {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
#backstageButton a {background:none; color:[[ColorPalette::Background]]; border:none;}
#backstageButton a:hover {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::Background]]; border:none;}
#backstagePanel {background:[[ColorPalette::Background]]; border-color: [[ColorPalette::Background]] [[ColorPalette::TertiaryDark]] [[ColorPalette::TertiaryDark]] [[ColorPalette::TertiaryDark]];}
.backstagePanelFooter .button {border:none; color:[[ColorPalette::Background]];}
.backstagePanelFooter .button:hover {color:[[ColorPalette::Foreground]];}
#backstageCloak {background:[[ColorPalette::Foreground]]; opacity:0.6; filter:'alpha(opacity=60)';}
/*}}}*/
/*{{{*/
* html .tiddler {height:1%;}

body {font-size:.75em; font-family:arial,helvetica; margin:0; padding:0;}

h1,h2,h3,h4,h5,h6 {font-weight:bold; text-decoration:none;}
h1,h2,h3 {padding-bottom:1px; margin-top:1.2em;margin-bottom:0.3em;}
h4,h5,h6 {margin-top:1em;}
h1 {font-size:1.35em;}
h2 {font-size:1.25em;}
h3 {font-size:1.1em;}
h4 {font-size:1em;}
h5 {font-size:.9em;}

hr {height:1px;}

a {text-decoration:none;}

dt {font-weight:bold;}

ol {list-style-type:decimal;}
ol ol {list-style-type:lower-alpha;}
ol ol ol {list-style-type:lower-roman;}
ol ol ol ol {list-style-type:decimal;}
ol ol ol ol ol {list-style-type:lower-alpha;}
ol ol ol ol ol ol {list-style-type:lower-roman;}
ol ol ol ol ol ol ol {list-style-type:decimal;}

.txtOptionInput {width:11em;}

#contentWrapper .chkOptionInput {border:0;}

.externalLink {text-decoration:underline;}

.indent {margin-left:3em;}
.outdent {margin-left:3em; text-indent:-3em;}
code.escaped {white-space:nowrap;}

.tiddlyLinkExisting {font-weight:bold;}
.tiddlyLinkNonExisting {font-style:italic;}

/* the 'a' is required for IE, otherwise it renders the whole tiddler in bold */
a.tiddlyLinkNonExisting.shadow {font-weight:bold;}

#mainMenu .tiddlyLinkExisting,
	#mainMenu .tiddlyLinkNonExisting,
	#sidebarTabs .tiddlyLinkNonExisting {font-weight:normal; font-style:normal;}
#sidebarTabs .tiddlyLinkExisting {font-weight:bold; font-style:normal;}

.header {position:relative;}
.header a:hover {background:transparent;}
.headerShadow {position:relative; padding:4.5em 0 1em 1em; left:-1px; top:-1px;}
.headerForeground {position:absolute; padding:4.5em 0 1em 1em; left:0px; top:0px;}

.siteTitle {font-size:3em;}
.siteSubtitle {font-size:1.2em;}

#mainMenu {position:absolute; left:0; width:10em; text-align:right; line-height:1.6em; padding:1.5em 0.5em 0.5em 0.5em; font-size:1.1em;}

#sidebar {position:absolute; right:3px; width:16em; font-size:.9em;}
#sidebarOptions {padding-top:0.3em;}
#sidebarOptions a {margin:0 0.2em; padding:0.2em 0.3em; display:block;}
#sidebarOptions input {margin:0.4em 0.5em;}
#sidebarOptions .sliderPanel {margin-left:1em; padding:0.5em; font-size:.85em;}
#sidebarOptions .sliderPanel a {font-weight:bold; display:inline; padding:0;}
#sidebarOptions .sliderPanel input {margin:0 0 0.3em 0;}
#sidebarTabs .tabContents {width:15em; overflow:hidden;}

.wizard {padding:0.1em 1em 0 2em;}
.wizard h1 {font-size:2em; font-weight:bold; background:none; padding:0; margin:0.4em 0 0.2em;}
.wizard h2 {font-size:1.2em; font-weight:bold; background:none; padding:0; margin:0.4em 0 0.2em;}
.wizardStep {padding:1em 1em 1em 1em;}
.wizard .button {margin:0.5em 0 0; font-size:1.2em;}
.wizardFooter {padding:0.8em 0.4em 0.8em 0;}
.wizardFooter .status {padding:0 0.4em; margin-left:1em;}
.wizard .button {padding:0.1em 0.2em;}

#messageArea {position:fixed; top:2em; right:0; margin:0.5em; padding:0.5em; z-index:2000; _position:absolute;}
.messageToolbar {display:block; text-align:right; padding:0.2em;}
#messageArea a {text-decoration:underline;}

.tiddlerPopupButton {padding:0.2em;}
.popupTiddler {position: absolute; z-index:300; padding:1em; margin:0;}

.popup {position:absolute; z-index:300; font-size:.9em; padding:0; list-style:none; margin:0;}
.popup .popupMessage {padding:0.4em;}
.popup hr {display:block; height:1px; width:auto; padding:0; margin:0.2em 0;}
.popup li.disabled {padding:0.4em;}
.popup li a {display:block; padding:0.4em; font-weight:normal; cursor:pointer;}
.listBreak {font-size:1px; line-height:1px;}
.listBreak div {margin:2px 0;}

.tabset {padding:1em 0 0 0.5em;}
.tab {margin:0 0 0 0.25em; padding:2px;}
.tabContents {padding:0.5em;}
.tabContents ul, .tabContents ol {margin:0; padding:0;}
.txtMainTab .tabContents li {list-style:none;}
.tabContents li.listLink { margin-left:.75em;}

#contentWrapper {display:block;}
#splashScreen {display:none;}

#displayArea {margin:1em 17em 0 14em;}

.toolbar {text-align:right; font-size:.9em;}

.tiddler {padding:1em 1em 0;}

.missing .viewer,.missing .title {font-style:italic;}

.title {font-size:1.6em; font-weight:bold;}

.missing .subtitle {display:none;}
.subtitle {font-size:1.1em;}

.tiddler .button {padding:0.2em 0.4em;}

.tagging {margin:0.5em 0.5em 0.5em 0; float:left; display:none;}
.isTag .tagging {display:block;}
.tagged {margin:0.5em; float:right;}
.tagging, .tagged {font-size:0.9em; padding:0.25em;}
.tagging ul, .tagged ul {list-style:none; margin:0.25em; padding:0;}
.tagClear {clear:both;}

.footer {font-size:.9em;}
.footer li {display:inline;}

.annotation {padding:0.5em; margin:0.5em;}

* html .viewer pre {width:99%; padding:0 0 1em 0;}
.viewer {line-height:1.4em; padding-top:0.5em;}
.viewer .button {margin:0 0.25em; padding:0 0.25em;}
.viewer blockquote {line-height:1.5em; padding-left:0.8em;margin-left:2.5em;}
.viewer ul, .viewer ol {margin-left:0.5em; padding-left:1.5em;}

.viewer table, table.twtable {border-collapse:collapse; margin:0.8em 1.0em;}
.viewer th, .viewer td, .viewer tr,.viewer caption,.twtable th, .twtable td, .twtable tr,.twtable caption {padding:3px;}
table.listView {font-size:0.85em; margin:0.8em 1.0em;}
table.listView th, table.listView td, table.listView tr {padding:0px 3px 0px 3px;}

.viewer pre {padding:0.5em; margin-left:0.5em; font-size:1.2em; line-height:1.4em; overflow:auto;}
.viewer code {font-size:1.2em; line-height:1.4em;}

.editor {font-size:1.1em;}
.editor input, .editor textarea {display:block; width:100%; font:inherit;}
.editorFooter {padding:0.25em 0; font-size:.9em;}
.editorFooter .button {padding-top:0px; padding-bottom:0px;}

.fieldsetFix {border:0; padding:0; margin:1px 0px;}

.sparkline {line-height:1em;}
.sparktick {outline:0;}

.zoomer {font-size:1.1em; position:absolute; overflow:hidden;}
.zoomer div {padding:1em;}

* html #backstage {width:99%;}
* html #backstageArea {width:99%;}
#backstageArea {display:none; position:relative; overflow: hidden; z-index:150; padding:0.3em 0.5em;}
#backstageToolbar {position:relative;}
#backstageArea a {font-weight:bold; margin-left:0.5em; padding:0.3em 0.5em;}
#backstageButton {display:none; position:absolute; z-index:175; top:0; right:0;}
#backstageButton a {padding:0.1em 0.4em; margin:0.1em;}
#backstage {position:relative; width:100%; z-index:50;}
#backstagePanel {display:none; z-index:100; position:absolute; width:90%; margin-left:3em; padding:1em;}
.backstagePanelFooter {padding-top:0.2em; float:right;}
.backstagePanelFooter a {padding:0.2em 0.4em;}
#backstageCloak {display:none; z-index:20; position:absolute; width:100%; height:100px;}

.whenBackstage {display:none;}
.backstageVisible .whenBackstage {display:block;}
/*}}}*/
/***
StyleSheet for use when a translation requires any css style changes.
This StyleSheet can be used directly by languages such as Chinese, Japanese and Korean which need larger font sizes.
***/
/*{{{*/
body {font-size:0.8em;}
#sidebarOptions {font-size:1.05em;}
#sidebarOptions a {font-style:normal;}
#sidebarOptions .sliderPanel {font-size:0.95em;}
.subtitle {font-size:0.8em;}
.viewer table.listView {font-size:0.95em;}
/*}}}*/
/*{{{*/
@media print {
#mainMenu, #sidebar, #messageArea, .toolbar, #backstageButton, #backstageArea {display: none !important;}
#displayArea {margin: 1em 1em 0em;}
noscript {display:none;} /* Fixes a feature in Firefox 1.5.0.2 where print preview displays the noscript content */
}
/*}}}*/
<!--{{{-->
<div class='header' macro='gradient vert [[ColorPalette::PrimaryLight]] [[ColorPalette::PrimaryMid]]'>
<div class='headerShadow'>
<span class='siteTitle' refresh='content' tiddler='SiteTitle'></span>&nbsp;
<span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'></span>
</div>
<div class='headerForeground'>
<span class='siteTitle' refresh='content' tiddler='SiteTitle'></span>&nbsp;
<span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'></span>
</div>
</div>
<div id='mainMenu' refresh='content' tiddler='MainMenu'></div>
<div id='sidebar'>
<div id='sidebarOptions' refresh='content' tiddler='SideBarOptions'></div>
<div id='sidebarTabs' refresh='content' force='true' tiddler='SideBarTabs'></div>
</div>
<div id='displayArea'>
<div id='messageArea'></div>
<div id='tiddlerDisplay'></div>
</div>
<!--}}}-->
<!--{{{-->
<div class='toolbar' macro='toolbar [[ToolbarCommands::ViewToolbar]]'></div>
<div class='title' macro='view title'></div>
<div class='subtitle'><span macro='view modifier link'></span>, <span macro='view modified date'></span> (<span macro='message views.wikified.createdPrompt'></span> <span macro='view created date'></span>)</div>
<div class='tagging' macro='tagging'></div>
<div class='tagged' macro='tags'></div>
<div class='viewer' macro='view text wikified'></div>
<div class='tagClear'></div>
<!--}}}-->
<!--{{{-->
<div class='toolbar' macro='toolbar [[ToolbarCommands::EditToolbar]]'></div>
<div class='title' macro='view title'></div>
<div class='editor' macro='edit title'></div>
<div macro='annotations'></div>
<div class='editor' macro='edit text'></div>
<div class='editor' macro='edit tags'></div><div class='editorFooter'><span macro='message views.editor.tagPrompt'></span><span macro='tagChooser excludeLists'></span></div>
<!--}}}-->
To get started with this blank [[TiddlyWiki]], you'll need to modify the following tiddlers:
* [[SiteTitle]] & [[SiteSubtitle]]: The title and subtitle of the site, as shown above (after saving, they will also appear in the browser title bar)
* [[MainMenu]]: The menu (usually on the left)
* [[DefaultTiddlers]]: Contains the names of the tiddlers that you want to appear when the TiddlyWiki is opened
You'll also need to enter your username for signing your edits: <<option txtUserName>>
These [[InterfaceOptions]] for customising [[TiddlyWiki]] are saved in your browser

Your username for signing your edits. Write it as a [[WikiWord]] (eg [[JoeBloggs]])

<<option txtUserName>>
<<option chkSaveBackups>> [[SaveBackups]]
<<option chkAutoSave>> [[AutoSave]]
<<option chkRegExpSearch>> [[RegExpSearch]]
<<option chkCaseSensitiveSearch>> [[CaseSensitiveSearch]]
<<option chkAnimate>> [[EnableAnimations]]

----
Also see [[AdvancedOptions]]
<<importTiddlers>>
{{{
struct _BOND
{
	struct _BOND *next;
	struct _BOND *prev;
	POINT  *start;
	POINT  *end;
	double length;
	double length0;			/* for fixed length bond */

	struct _BOND_TRI **_btris;	/* Bounding triangles in angle order */
};
}}}
src/front/fdecs.h
{{{
#define Backward_curve_redistribute(fr,c,status)			\
    ((Backward_curve_redistribute_function(fr) != NULL) ?	\
	 (*Backward_curve_redistribute_function(fr))(fr,c,status) : status)
#define Backward_curve_redistribute_function(fr)			\
    (Curve_redistribution_info(fr).Redistributors.backward_cur_redist)
#define	Curve_redistribution_info(fr)	Redistribution_info(fr).Curve_redist
#define Redistribution_info(fr)	(fr)->Redist
}}}
src/intfc/int.h
{{{
typedef int COMPONENT;		/* Labels Connected Domains */
}}}
{{{
struct _CURVE
{

	int _boundary;		/* Mandatory first element,  see notes on
				 *  boundary macros below */
	struct _CURVE *obj;	/* refers back to curve, see boundary macro */
	struct _HYPER_SURF *hs;
	struct _HYPER_SURF_BDRY *hsb;

	/* Topological Part: */
	struct _INTERFACE *interface;
	struct _NODE *start;
	struct _NODE *end;

	struct _SURFACE **pos_surfaces;
	struct _SURFACE **neg_surfaces;
	int	number;
	int	redist_order;

	/* Representation Specific Part: */
	BOND *first;
	BOND *last;
	int num_points;
	int orientation;	/* Orientation of closed curve */
				/* 1 for positive, -1 for negative */

	int  sindx, eindx;
};
}}}
src/front/fdecs.h
{{{
#define Curve_redistribute(fr,force)					\
	((Curve_redistribution_function(fr) != NULL) ?			\
			(*Curve_redistribution_function(fr))(fr,force) : YES)
#define Curve_redistribution_function(fr)				\
	(Curve_redistribution_info(fr).Redistributors.curve_redist_func)
#define	Curve_redistribution_info(fr)	Redistribution_info(fr).Curve_redist
#define Redistribution_info(fr)	(fr)->Redist
}}}
This section introduce the data structure of ~FornTier, including the main structure [[Front]] and related structures such as [[RECT_GRID]], [[INTERFACE]] etc.
----
A [[Front]] consists of an interface (see int.c for documentation) and the values of the physical state variables on each side of the interface, together with further variables which specify algorithms for the processing of fronts.
[[Front]]
|[[RECT_GRID]] Rectangular Grid |
|[[PP_GRID]] Parallel Processing Grid|
|[[FrontPreAdvance]]|
|[[Front Advance]]|
|[[vfunc]]|
|[[Redist]]  defines the curve and surface redistribution functions.|
|[[INTERFACE]]|
----
[[interface related structure]]
|[[POINT]]|[[NODE]]|
|[[BOND]]|[[TRI]]|[[HYPER_SURF_ELEMMENT]]|
|[[CURVE]]|[[HYPER_SURF_BDRY]]|
|[[SURFACE]]|[[HYPER_SURF]]|
----
[[Introduction]]
src/front/fdecs.h
{{{
struct _F_BASIC_DATA {
	/* Need to assign before calling FrontInitStandardIO() */
        int dim;

	/* The following will get from FrontInitStandardIO() */
	char 	in_name[200];
	char 	out_name[200];
	int 	subdomains[MAXD];
	bool 	ReadFromInput;
	bool 	RestartRun;
	int 	RestartStep;
        char 	restart_name[200];
	char	restart_state_name[200];

	/* The following are needed before FrontStartUp() */
        float 	L[MAXD],U[MAXD];
        int 	gmax[MAXD];
        int 	boundary[MAXD][2];
	size_t 	size_of_intfc_state;
};
typedef struct _F_BASIC_DATA F_BASIC_DATA;
}}}
*[[F_BASIC_DATA]] input and output filenames
*[[FrontOutputTimeControl]] control output timing
!~FronTier input file
*[[FrontInitStandardIO]] Handle the command line parameters
*[[FrontReadRegularDomainInfo]] Read in domain information from input file include domain range, grid number and boundary type.
*[[FrontReadTimeControlInfo]] Read in max time, max time step, print interval, time step factor, redistribution interval etc. from input file.

!~FronTier output file
FrontPrintOut function will generate a geomview directory and a general file. Geomview directory contains the following files:
axes.list  bdry.list  curves.list  ggrid.list  grid.list  surfs.list  vgrid.list
We can use geomview to visualize these files. 

A general file contains all the information about the front interface.

FrontMovieFrame function will generate a vtk directory with following files in it: 
3d-intfc.vtk  box.vtk
We can use Visit to visualize these two files.

!!!Naming convention
The geomview directory name is ''outfilename-gv.ts[timestep]''
where outfilename is specified by -o option, if -o is not specified, use "intfc" as the default name, timestep is a 7 digit integer number.
The general file name is  ''outfilename.ts[timestep]''
The vtk directory name is ''outfilename-vtk.ts[timestep]''
!!![[FrontPrintOut]]->[[print_front_output]]
gv file
#[[gview_plot_interface]] -> [[f_gview_plot_interface]] -> [[geomview_interface_plot]]
##[[gview_plot_cube]]
###[[get_list_file_name]]
###[[gview_bounding_box]] this function print the bounding box coordinates of the grid
##[[gview_plot_axes]]
###[[get_list_file_name]]
###[[gview_bounding_box]] this function print the bounding box coordinates of the grid
##[[gview_plot_surfaces]]
##[[gview_plot_curves]]
----
general file
#[[print_title]] print time of running and machine information
#*[[print_machine_parameters]]
#[[fprint_front_time_stamp]] print time step and dt
#[[fprint_interface]] -> [[i_fprint_interface]]
##[[fprint_node]] -> [[i_fprint_node]]
##[[fprint_curve]] -> [[i_fprint_curve]]
###[[fprint_tris_on_curve]]
###[[user_fprint_curve]] -> [[f_user_fprint_curve]]
##[[fprint_surface]] -> [[i_fprint_surface]]
###[[fprint_triangle_numbers]]
###[[user_fprint_surface]] -> [[f_user_fprint_surface]]
####[[fprint_wave_type]] -> [[f_fprint_wave_type]]
##[[fprint_comp_equiv_lists]]
##[[user_fprint_interface]] -> [[f_user_fprint_interface]]
###[[f_fprint_boundary_state_data]]
###[[f_fprint_Dirichlet_bdry_states]]
!!![[FrontMovieFrame]] -> [[show_front_output]]
vtk file
#[[vtk_interface_plot]]
#*[[vtk_plot_curves]]
#*[[vtk_plot_surfaces]]
----
src/front/fdecs.h
{{{
#define Forward_curve_redistribute(fr,c,status)				\
    ((Forward_curve_redistribute_function(fr) != NULL) ?		\
         (*Forward_curve_redistribute_function(fr))(fr,c,status) : status)
#define Forward_curve_redistribute_function(fr)				\
    (Curve_redistribution_info(fr).Redistributors.forward_cur_redist)
}}}
src/front/fdecs.h
{{{
struct _Front {
		/* Grid Specification */
	RECT_GRID *rect_grid;		/* Grid Info */
	PP_GRID* pp_grid;

		/* advancing the front */
	int	(*_advance_front)(float,float*,struct _Front*,
				  struct _Front**,POINTER);

		/* Copy and freeing front */
	void	(*_free_front)(struct _Front*);
	void	(*_copy_into_front)(struct _Front*,struct _Front*);
	struct _Front*	(*_copy_front)(struct _Front*);

		/* printing the front */
	void	(*_print_Front_structure)(struct _Front*);
	void	(*_fprint_front)(struct _Front*,FILE*);
	void	(*_read_print_front)(INIT_DATA*,struct _Front*);

		/* State Variable Specification */
	size_t  sizest;			/* Size of State Variables in Bytes */
	void (*_hyp_solution)(float*,COMPONENT,HYPER_SURF*,SIDE,struct _Front*,
					POINTER,Locstate,Locstate);
	void (*_hyp_grad_solution)(float*,COMPONENT,HYPER_SURF*,SIDE,
					struct _Front*,POINTER,Locstate*);
	void (*_state_interpolator)(float,float,float*,Locstate,float*,
				       	Locstate,RECT_GRID*,Locstate);
	bool (*_tri_state_interpolator)(float,float,float,float*,Locstate,
				   	float*,Locstate,float*,Locstate,
					RECT_GRID*,Locstate);
	void (*transform_state)(Locstate,AFLIN*); /* Coordinate transforms
						     on states */

		/* Hyper surface corresponder */
	bool (*_is_correspondence_possible)(HYPER_SURF*,HYPER_SURF*,
					       HYPER_SURF_BDRY**,
					       HYPER_SURF_BDRY**);

		/* Redistribution Specification */
	REDIST_CONTROL  Redist;         /* Redistribution control parameters */

		/* Time Step Selection */
	bool (*_last_time_step_modification)(void);
					/* Computes front maximum time step */
	float (*max_front_time_step)(struct _Front*,float*);
	struct	_MAX_FRONT_SPEED	*_MaxFrontSpeed;
	TSTEP_CONTROL	Tstep;

		/* Real and mesh times for front->interf */
	float dt, *dt_frac, time, max_time;
	float print_time_interval, movie_frame_interval;
	int step, max_step;
	int num_mts,_max_num_mts;
	bool   redis_flag; /*flag for the redistribution after LGB*/
	float distance, dismin, dismax, hmin_fre, hmax_fre;
	bool print_sdl_file;

		/* Advancing the Front */
	int  hyperbolic;
	int  npts_tan_sten;
	int  movingframe;
	bool adaptive_partition;     /* Use adaptive partition if YES */
	POINTER vparams;	/* parameters for velocity function */
	POINTER extra;		/* pointer to extra data structure */
	COMPONENT *hdf_comps;	/* Saved for hdf plotting */
	HDF_MOVIE_VAR *hdf_movie_var;	/* variables for hdf movies */
	int  (*init_topology_of_new_interface)(struct _Front*,struct _Front*);
	struct _F_WAVE_CAPTURE *_f_wave_capture;
	void (*_init_propagate)(struct _Front*);
	void (*curve_propagate)(struct _Front*,POINTER,CURVE*,CURVE*,float);
	int  (*node_propagate)(struct _Front*,POINTER,NODE*,NODE*,RPROBLEM**,
			       float,float*,NODE_FLAG,POINTER);
	void (*_point_propagate)(struct _Front*,POINTER,POINT*,POINT*,
			        HYPER_SURF_ELEMENT*,HYPER_SURF*,float,float*);
	void (*_point_propagate_along_wall)(struct _Front*,POINTER,POINT*,
				BOND*,CURVE*,HYPER_SURF_ELEMENT*,HYPER_SURF*,
				POINT*,float,float*);
	void (*bond_propagate)(struct _Front*,POINTER,BOND*,BOND*,
			       CURVE*,float);
	int  (*snd_node_propagate)(struct _Front*,struct _Front*,POINTER,
				INTERFACE*,NODE*,NODE*,float);
	void (*tan_curve_propagate)(struct _Front*,struct _Front*,INTERFACE*,
				CURVE*,CURVE*,float);
	bool (*_tan_point_propagate)(struct _Front*,POINT*,POINT*,
				HYPER_SURF_ELEMENT*,HYPER_SURF*,float,int);
	void (*_npt_tang_solver)(float,float,Tan_stencil*,
	                        Locstate,Locstate,struct _Front*);
	void (*_one_side_npt_tang_solver)(float,float,Tan_stencil*,Locstate,
				struct _Front*);
	void (*impose_bc)(POINT*,BOND*,CURVE*,float*,struct _Front*,
			  bool,bool);
	int  (*vfunc)(POINTER,struct _Front*,POINT*,HYPER_SURF_ELEMENT*,
				HYPER_SURF*,float*); /* analytical velo func */
#if defined(THREED)
	bool (*_untrack_surface)(SURFACE*,COMPONENT,struct _Front*);
	bool (*_reconstruct_front_at_grid_crossing)(struct _Front*);
	bool (*_repair_front_at_grid_crossing)(struct _Front*);
	void (*_principal_tangent)(POINT*,HYPER_SURF_ELEMENT*,HYPER_SURF*,
				float*,float*);
	void (*surface_propagate)(struct _Front*,struct _Front*,POINTER,
				float,float*);
#endif /* defined(THREED) */

		/* Untangling the Front */
	bool (*_check_delete_redundant_node)(NODE*,CURVE*,CURVE*);
	int  (*fr_bdry_untangle)(struct _Front*,CROSS**,RPROBLEM*,NODE*,int);
	int  (*fr_vec_bdry_untangle)(CURVE*,CURVE*,CURVE**,ORIENTATION,
				ANGLE_DIRECTION,int,struct _Front*);
	int  (*untangle_front)(struct _Front*,CROSS**,int);
	int  (*grid_based_untangle)(struct _Front*,CROSS**);
	bool (*_replace_unphys_loop)(NNLIST*,NNLIST**,CURVE**,
				struct _Front*,int,float,int);
	int  (*B_node_bifurcation)(struct _Front*,POINTER,O_CURVE*,O_CURVE*,
				O_CURVE*,O_CURVE*,O_CURVE*,O_CURVE*,O_CURVE*,
				O_CURVE*,O_CURVE*,O_CURVE*,POINT*,Locstate,
				Locstate,ANGLE_DIRECTION,RPROBLEM**,
				float,float*,NODE_FLAG);
	int  (*twodrproblem)(struct _Front*,struct _Front*,POINTER,RPROBLEM**);
	bool (*_untrack_curve)(O_CURVE*,O_CURVE*,COMPONENT,float,
			        struct _Front*,POINTER,RPROBLEM*,
				UNTRACK_FLAG);
#if defined(ONED)
	bool (*_untrack_point)(POINT*,COMPONENT,struct _Front*);
#endif /* defined(ONED) */
	void (*identify_physical_node)(NODE*);
	void (*init_2drproblem)(RPROBLEM*,struct _Front*);
	void (*phys_split_bdry_cross)(CURVE**,CURVE**);
	void (*phys_set_node_types)(struct _Front*);
	void (*parallel_refl_vec_wave)(CURVE*,int,int,CURVE*,int,int,
				RPROBLEM*,struct _Front*,POINTER);

		/* Identification of boundary states and components */

	int  (*neumann_bdry_state)(float*,COMPONENT,POINT*,HYPER_SURF*,
				struct _Front*,POINTER,Locstate);
	ANGLE_DIRECTION  (*_find_i_to_prop_dir)(struct _Front*,POINTER,NODE*,
				CURVE*,ORIENTATION,float,COMPONENT*,POINT*,
				float*);
	int  (*is_nzn_bdry)(float,float,COMPONENT,CURVE*);

		/*Locstate allocation and clearing*/

	void (*_alloc_state)(Locstate*,size_t);
	void (*_clear_state)(Locstate,size_t);
	void (*_obstacle_state)(Locstate,size_t);

		/* Output printout functions */

	int nfloats;			/* Number of floats in Locstate */
	void (*print_state)(Locstate);
	void (*_fgraph_front_states)(FILE*,struct _Front*);
	void (*_fprint_header_for_graph_curve_states)(FILE*,struct _Front*,
				const char*);
	void (*_fgraph_curve_states)(FILE*,CURVE*,struct _Front*,float*);
	void (*_check_front_state_consistency)(struct _Front*);
	void (*mass_consv_diagn_driver)(struct _Front*,POINTER,float);

	struct	_FlowSpecifiedRegion *head_fsr;

	void (*_EnforceFlowSpecifedStates)(struct _Front*);

		/* Marker for Copy Routine */
	int FDIVIDER;

		/* (the rest of the front consists of pointers) */

	INTERFACE *interf;		/* Interface */
	INTERFACE *grid_intfc;		/* Grid Interface */
	INTERFACE *emb_grid_intfc;	/* Grid Interface for embedded bdry */

#if defined(USE_OVERTURE)

        int     (*_normal_advance_front)(float,float*,struct _Front*,
                                struct _Front**,POINTER);
        int     (*_tangnt_advance_front)(float,float*,struct _Front*,
                                struct _Front**,POINTER);
        int     (*_redist_advance_front)(float,float*,struct _Front*,
                                struct _Front**,POINTER);

                /* deep Copy and freeing front, create rect_grid */
        void    (*_deep_free_front)(struct _Front*);
        struct _Front*  (*_deep_copy_front)(struct _Front*);

        int                       use_overture_state;
        POINTER                   cg_over;   /* pointer of CompositeGrid */
        int                       patch_number;
        int                       patch_level;
        int                       NumberOfLevels;
        int                       totalNumberOfPatches;
/*         Neighbor                        *neighbor; */
        Patch_bdry_flag           *pd_flag;
        struct _Front             *newfront;
#endif /* defined(USE_OVERTURE) */
};
typedef struct _Front Front;
}}}
!![[FrontAdvance]] -> [[advance_front]]
*[[advance_front2d]]
*#[[intfc_propagate]]
*#*[[f_second_order_intfc_propagate2d]]
*#[[curve_propagate]] 
*#*[[f_curve_propagate2d]]
*#**[[point_propagate]]
*#**[[first_order_point_propagate]]
*#**[[fourth_order_point_propagate]]
*#[[node_propagate]]
*#*[[f_node_propagate]]
*#**[[closed_node_propagate]]
*#***[[point_propagate]]
*#***[[first_order_point_propagate]]
*#***[[fourth_order_point_propagate]]
*#[[redistribute2d]]
*##[[Curve_redistribute]]
*##*[[full_redistribute]]
*##*redistribute vector curve
*##*[[Forward_curve_redistribute]]
*##*[[Backward_curve_redistribute]]  redistribute in another direction
*##**[[equi_curve_redistribute]]
*##**#[[Front_spacing]]
*##**#[[scaled_bond_length]]
*##**#[[curve_delete_very_short_bonds]]
*##**#[[cross_rect_grid_bdry]] test if a bond is crossing the grid boundary
*##**#[[equi_redist_curve_seg]]
*##**##[[replace_curve_seg_by_bond]]
*##**##[[insert_point_in_bond]]
*##**##*[[i_user_interface]]
*##**##*[[f_insert_point_in_bond]]
*##**##*#[[i_insert_point_in_bond]]
*##**##*#[[f_user_2d_insert_point_in_bond]]
*## [[closed_curve_node_redistribution]]
*[[advance_front3d_tracking_control]]
**~LOCALLY_GRID_BASED_TRACKING: [[mixed_advace_front3d]]
***[[preserve_front_advance_front3d]]
***#[[propagate_3d_front]]
***##[[init_intfc_curvature3d]]
***##[[propagate_surface_points]]
***##*[[point_propagate]]
***##*[[first_order_point_propagate]]
***##*[[fourth_order_point_propagate]]
***##[[surface_propagate]]
***##*[[f_surface_propagate]]
***##[[propagate_curve_point]]
***##[[propagate_node_points]]
***##[[propagate_points_tangentially]]
***#[[redistribute]]
***#*[[redistribute3d]]
***#*#[[scatter_front]]
***#*#[[repair_front_at_grid_crossing]]
***#*##[[repair_intfc3d_in_box]]
***#*###[[track_comp_and_repair3d]]
***#*####[[adjust_crossings]]
***#*####*[[adjust_for_min_spacing]]
***#*####[[fill_physical_comps]]
***#*####*[[check_and_unset_bad_comp]]
***#*####[[fill_comp_with_component3d]]
***#*####*[[check_and_unset_bad_comp]]
*[[scatter_front]]
*#[[form_subintfc_via_communication]]
*#*[[f_intfc_communication2d]]
*#*[[f_intfc_communication3d]]
!![[assign_interface_and_free_front]] Copies fr->interf into newfr->interf and then frees fr.
*[[assign_front_interface]]
src/front/fmap.c
{{{
EXPORT	int FrontAdvance(
        float    dt,
        float    *dt_frac,
        Front    *front,
        Front    **newfront,
        POINTER  wave)
{
	int status,count;
	float start_dt = dt;

	*dt_frac = 1.0;
	front->dt_frac = dt_frac;
        status = advance_front(front->dt,dt_frac,front,newfront,wave);

        count = 0;
        while (status == MODIFY_TIME_STEP || status == REPEAT_TIME_STEP)
        {
	    if (status == MODIFY_TIME_STEP)
            	front->dt = (*dt_frac)*start_dt;
            status = advance_front(front->dt,dt_frac,front,newfront,wave);
            count++;
            if (count > 10) 
	    {
		screen("ERROR: in FrontAdvance() modified step 10 times\n");
	    	clean_up(ERROR);
	    }
        }
}	/* end FrontAdvance */
}}}
src/front/finit.c
{{{
EXPORT	void FrontInitIntfc(
        Front  *front,
	LEVEL_FUNC_PACK *level_func_pack)
{
	switch (front->rect_grid->dim)
	{
	case 1:
	    FrontInitIntfc1d(front,level_func_pack);
	    break;
	case 2:
	    FrontInitIntfc2d(front,level_func_pack);
	    break;
	case 3:
	    FrontInitIntfc3d(front,level_func_pack);
	    break;
	default: 
	    screen("Unknown dimension!\n");
	    clean_up(ERROR);
	}
	clip_front_to_subdomain(front);
}	/* end FrontInitIntfc */

}}}
src/front/finit.c
{{{
LOCAL   void FrontInitIntfc1d(
	Front *front,
        LEVEL_FUNC_PACK *level_func_pack)
{
	RECT_GRID *gr = front->rect_grid;
	INTERFACE *intfc = front->interf;
        double **points = level_func_pack->point_array;
        POINT *p;
        const double eps = 10.0*MACH_EPS;

	if (level_func_pack->num_points == 1 &&
	    level_func_pack->point_array != NULL)
	{
            p = make_point(points[0],level_func_pack->neg_component,
                                 level_func_pack->pos_component);
            wave_type(Hyper_surf(p)) = FIRST_PHYSICS_WAVE_TYPE;
	}
	else
	    intfc->default_comp = level_func_pack->pos_component;

        set_topological_grid(intfc,computational_grid(intfc));

        (void) set_boundary(intfc,&topological_grid(intfc),
                            intfc->default_comp,eps);
}       /* end FrontInitIntfc1d */
}}}
src/front/finit.c
{{{
LOCAL   void FrontInitIntfc2d(
	Front *front,
	LEVEL_FUNC_PACK *level_func_pack)
{
	RECT_GRID *gr = front->rect_grid;
	INTERFACE *intfc = front->interf;
	char s[10];
	const double eps = 10.0*MACH_EPS;
	CURVE **c,*curve;
	COMPONENT left_c,right_c;

	copy_rect_grid(computational_grid(intfc),gr);

	if (level_func_pack == NULL)
	{
	    prompt_make_level_curves(intfc,gr,&left_c,&right_c);
	}
	else if (level_func_pack->func != NULL)
	{
	    double (*func)(POINTER,double*);
	    POINTER func_params;
	    left_c = level_func_pack->neg_component;
	    right_c = level_func_pack->pos_component;
	    func = level_func_pack->func;
	    func_params = level_func_pack->func_params;
	    make_level_curve(gr,intfc,left_c,right_c,func,func_params,NO);
	}
	else if (level_func_pack->point_array != NULL)
	{
	    double **point_array = level_func_pack->point_array;
	    int num_points = level_func_pack->num_points;
	    bool is_closed_curve = level_func_pack->is_closed_curve;
	    left_c = level_func_pack->neg_component;
	    right_c = level_func_pack->pos_component;
	    if (!make_array_curve(intfc,left_c,right_c,num_points,
	    		point_array,is_closed_curve))
            {
            	screen("make_array_curve() failed!\n");
            	clean_up(ERROR);
	    }
	}
	else
	{
	    intfc->default_comp = level_func_pack->pos_component;
	}

	set_topological_grid(intfc,computational_grid(intfc));

	(void) set_boundary(intfc,&topological_grid(intfc),
			    intfc->default_comp,eps);
	for (c = intfc->curves; c && *c; ++c)
	{
	    if (negative_component(*c) == left_c &&
		positive_component(*c) == right_c)
	    {
		if (level_func_pack == NULL) 
	    	    wave_type(*c) = FIRST_PHYSICS_WAVE_TYPE;
		else if (level_func_pack->wave_type != UNKNOWN_WAVE_TYPE)
		{
		    wave_type(*c) = level_func_pack->wave_type;
		    /* Not a boundary 5.16.09 XL
		    if (wave_type(*c) == DIRICHLET_BOUNDARY ||
			wave_type(*c) == NEUMANN_BOUNDARY)
		    {
			set_is_bdry(*c);
		    }
		    */
		}
		else
	    	    wave_type(*c) = FIRST_PHYSICS_WAVE_TYPE;

		if ((*c)->start == (*c)->end)
		    node_type((*c)->start) = CLOSED_NODE;
	    	else
		{
		    set_boundary_node_type((*c)->start,intfc);
		    set_boundary_node_type((*c)->end,intfc);
		}
		if (!is_bdry(*c))
		    start_status(*c) = end_status(*c) = INCIDENT;
		else
		    start_status(*c) = end_status(*c) = FIXED;
	    }
	}

	rect_bdry_redist2d(intfc,computational_grid(intfc),0);
}	/* end FrontInitIntfc2d */
}}}
src/front/finit.c
{{{
LOCAL   void FrontInitIntfc3d(
	Front *front,
	LEVEL_FUNC_PACK *level_func_pack)
{
	RECT_GRID *gr = front->rect_grid;
	INTERFACE *intfc = front->interf;
	SURFACE *surf = NULL;
	COMPONENT neg_comp,pos_comp;
	const float eps = 10.0*MACH_EPS;

	copy_rect_grid(computational_grid(intfc),gr);

	if (level_func_pack == NULL)
	{
	    surf = prompt_make_level_surface(intfc,gr);
	    interface_reconstructed(intfc) = YES;
	}
	else if (level_func_pack->read_sdl_input)
	{
	    neg_comp = level_func_pack->neg_component;
	    pos_comp = level_func_pack->pos_component;
	    if (!read_sdl_surface(intfc,neg_comp,pos_comp,
	    		level_func_pack->sdl_name,&surf))
	    {
		screen("read_sdl_surface() failed!\n");
		clean_up(ERROR);
	    }
	}
	else if (level_func_pack->read_vtk_input)
	{
	    neg_comp = level_func_pack->neg_component;
	    pos_comp = level_func_pack->pos_component;
	    if (!read_vtk_surface(intfc,neg_comp,pos_comp,
	    		level_func_pack->vtk_name,&surf))
	    {
		screen("read_sdl_surface() failed!\n");
		clean_up(ERROR);
	    }
	}
	else if (level_func_pack->is_mono_hs)
	{
            pos_comp = level_func_pack->pos_component;
	    neg_comp = level_func_pack->pos_component+1;
	    if (!make_level_surface(gr,intfc,neg_comp,pos_comp,
			level_func_pack->func,level_func_pack->func_params,
			&surf))
	    {
		screen("make_level_surface() failed!\n");
		clean_up(ERROR);
	    }
	    cut_surface(surf,level_func_pack->constr_func,
			level_func_pack->constr_params,YES);
	    install_hsbdry_on_surface(surf,MONO_COMP_HSBDRY);
	    negative_component(surf) = positive_component(surf);
	}
	else
	{
	    float (*func)(POINTER,float*);
	    POINTER func_params;
	    neg_comp = level_func_pack->neg_component;
	    pos_comp = level_func_pack->pos_component;
	    func = level_func_pack->func;
	    func_params = level_func_pack->func_params;
	    if (!make_level_surface(gr,intfc,neg_comp,pos_comp,func,
			func_params,&surf))
	    {
		screen("make_level_surface() failed!\n");
		clean_up(ERROR);
	    }
	}
	if (surf)
	    wave_type(surf) = FIRST_PHYSICS_WAVE_TYPE;

	set_topological_grid(intfc,computational_grid(intfc));

	if (level_func_pack->set_3d_bdry)
	{
	    clip_front_to_rect_boundary_type(front);
	    (void) set_boundary(intfc,gr,intfc->default_comp,eps);
	}
}	/* end FrontInitIntfc3d */
}}}
{{{
LOCAL   void FrontInitIntfc3d(
        Front *front,
        LEVEL_FUNC_PACK *level_func_pack)
{
        RECT_GRID *gr = front->rect_grid;
        INTERFACE *intfc = front->interf;
        const float eps = 10.0*MACH_EPS;

        CURVE           **jet;
        SURFACE         **surfs ;
        JET_PARAMS      jet_paramsa, jet_paramsb;
        BDRY_BOX_PARAMS bp;
        FUEL_PARAMS     fuel_params;
        //Gas_param       *gas_paramsa, *gas_paramsb,  *gas_paramsc;
        float           *L = gr->GL;
        float           *U = gr->GU;
        float           *h = gr->h;
        float           coords[MAXD];
        char            s[1024];
        int             i, dim = gr->dim;
        float           r_i, w_w, h_i, r_n, h_l, h_u;
        float           cen[3], h_in[3], h_out[3], ratio;
        float           tol = MIN_SC_SEP(intfc);
        int             is,ic;

        copy_rect_grid(computational_grid(intfc),gr);

        //debug_print("jet","Entered init_fuel_injection_jet3d()\n");

        //#bjet2 TMP fix
        //make_bubbles(NULL, front);

        //set_obstacle_comp_type(comp_type(COMPOBST),front);
        //exclude_comp(COMPD,intfc);
        //set_obstacle_comp_type(comp_type(COMPD),front);

        bp.L = gr->GL;         bp.U = gr->GU;

        fuel_params.bp = &bp;

        fuel_params.comp_top = exterior_component(front->interf);
        //fuel_params.comp_obst = COMPOBST;
        fuel_params.comp_fluid = 2;
        fuel_params.comp_gas = 1;
        //fuel_params.comp_bot = exterior_component(front->interf);

        uni_array(&surfs,10,sizeof(SURFACE*));
        uni_array(&jet,10,sizeof(CURVE*));

        //bi_array(&(fuel_params.file_r), 80, 360, FLOAT);
        //printf("#get surf_polar.\n");
        //get_file_r(fuel_params.file_r, 80, 360);

        is = ic = 0;

        make_surfaces_from_comp(gr, flowin_comp_func, (POINTER)&fuel_params,
                        surfs, jet, &is, &ic);

        //free(fuel_params.file_r);
        //TMP 
        //make_surfaces_from_files(gr, surfs, jet, &is, &ic); 

        printf("End make_jet_surfaces,is = %d,ic = %d\n", is, ic);

        order_interface(intfc);

        null_sides_are_consistent();
        check_print_intfc("After init jet", "init_jet", 'f',
               intfc, 1, 1, NO);

        init_types_from_comp((POINTER)&fuel_params);
        //do not change this one.
        init_wave_curve_types(intfc, surfs, jet, is, ic);
        init_rect_boundary(front);

        interface_reconstructed(intfc) = NO;

        //intfc->modified = YES;
        //print_interface(intfc);
        //clean_up(0);

        set_topological_grid(intfc,computational_grid(intfc));

        //if (level_func_pack->set_3d_bdry)
        //{
        //    clip_front_to_rect_boundary_type(front);
        //    (void) set_boundary(intfc,gr,intfc->default_comp,eps);
        //}

        debug_print("jet","Left init_fuel_injection_jet3d()\n");
} 
}}}
src/front/fmap.c
{{{
EXPORT	void	FrontInitStandardIO(
	int		argc,
	char		**argv,
	F_BASIC_DATA 	*f_basic)
{
	char *in_name      = f_basic->in_name;
	char *out_name     = f_basic->out_name;
	char *restart_name = f_basic->restart_name;
	int  *subdomains   = f_basic->subdomains;
	f_basic->ReadFromInput = NO;
	f_basic->RestartRun = NO;
#if defined(__MPI__)
        pp_init(&argc,&argv);
#endif /* defined(__MPI__) */
	argc--;
	argv++;
	strcpy(out_name,"intfc");
	/* we can invoke as ./example only, this will output to terminal*/
	while (argc >= 1)
	{
	    if (argv[0][0] != '-')
	      {/* run ./example - will result problem*/
		printf("Usage: example -o output\n");
		exit(1);
	    }
	    switch(argv[0][1]) {
	    case 'i':
	    case 'I':
	    	f_basic->ReadFromInput = YES;
	    	zero_scalar(in_name,200);
		/*#define zero_scalar(s,num)	(void) memset((POINTER)(s),0,num)*/
                strcpy(in_name,argv[1]);
                argc -= 2;
		argv += 2;
		break;
	    case 'r':
	    case 'R':
	    	f_basic->RestartRun = YES;
	    	zero_scalar(restart_name,200);
                strcpy(restart_name,argv[1]);
                argc -= 2;
		argv += 2;
		break;
	    case 't':
	    case 'T':
	    	f_basic->RestartStep = atoi(argv[1]);
                argc -= 2;
                argv += 2;
                break;
	    case 'd':
	    case 'D':
	    	f_basic->dim = atoi(argv[1]);
                argc -= 2;
                argv += 2;
                break;
	    case 'o':
	    case 'O':
		zero_scalar(out_name,200);
		strcpy(out_name,argv[1]);
#if defined(__MPI__)
                sprintf(out_name,"%s.%d",out_name,pp_mynode());
#endif /* defined(__MPI__) */
		freopen(out_name,"w",stdout);
		/*redirect stdout to out_name*/
		zero_scalar(out_name,200);
		strcpy(out_name,argv[1]);
		argc -= 2;
		argv += 2;
		break;
#if defined(__MPI__)
            case 'p':
            case 'P':
                int i,total_num_proc = 1;
                for (i = 0; i < MAXD; ++i)
                {
                    if (argc < 2 || argv[1][0] == '-') break;
                    argc -= 1;
                    argv += 1;
                    subdomains[i] = atoi(argv[0]);
                    total_num_proc *= subdomains[i];
                }
                argc -= 1;
                argv += 1;
                if (total_num_proc != pp_numnodes())
                {
                    printf("total number of processors for the partition %d "
                           "does not equal to requested np %d\n",
                           total_num_proc,pp_numnodes());
                    clean_up(ERROR);
                }
#endif /* defined(__MPI__) */
	    }
	}
}	/* end FrontInitStatndardIO */
}}}
src/front/fvelo.c
{{{
EXPORT void FrontInitVelo(
	Front *front,
	VELO_FUNC_PACK *velo_func_pack)
{
	char s[100];
	int dim = front->rect_grid->dim;

	/* Initialize front velocity field */

	if (velo_func_pack == NULL)
	{
	    screen("\n\t\tSpecifying Velocity Field\n\n");
	    screen("Supported velocity fields are \n"
	       "\tTranslation (t)\n"
	       "\tRadial motion (r)\n"
	       "\tShear motion (s)\n"
	       "\tSinusiodal motion (w)\n"
	       "\tCircular rotation (c)\n"
	       "\tNormal motion (n)\n"
	       "\tCurvature dependent motion (k)\n"
	       "\tFlame motion (f)\n"
	       "\tBurgers equation solver (b)\n"
	       "\tBi-Polar velocity (h)\n"
	       "\tVortex velocity (v)\n"
	       "\tDouble vortex velocity (d)\n"
	       "Enter choice: ");
	    (void) Scanf("%s\n",s);
	    switch (s[0])
	    {
	    case 'T':
	    case 't':
	    	front->vfunc = translation_vel;
	    	init_translation_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    	break;
	    case 'R':
	    case 'r':
	    	front->vfunc = radial_motion_vel;
	    	init_radial_motion_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    	break;
	    case 'S':
	    case 's':
	    	front->vfunc = shear_motion_vel;
	    	init_shear_motion_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    	break;
	    case 'W':
	    case 'w':
	    	front->vfunc = sine_motion_vel;
	    	init_sine_motion_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    break;
	    case 'C':
	    case 'c':
	    	front->vfunc = circular_rotation_vel;
	    	init_circular_rotation_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    	break;
	    case 'B':
	    case 'b':
	    	front->vfunc = burgers_vel;
	    	init_burgers_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    break;
	    case 'H':
	    case 'h':
	    	front->vfunc = bipolar_vel;
	    	init_bipolar_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    	break;
	    case 'N':
	    case 'n':
	    	front->vfunc = normal_vel;
	    	init_norv_params(&front->vparams,dim);
	    	front->_point_propagate = first_order_point_propagate;
	    	break;
	    case 'K':
	    case 'k':
	    	front->vfunc = curvature_vel;
	    	init_curvature_params(&front->vparams,dim);
	    	front->_point_propagate = first_order_point_propagate;
	    	break;
	    case 'F':
	    case 'f':
	    	front->vfunc = flame_vel;
	    	init_flame_params(&front->vparams,dim);
	    	front->_point_propagate = first_order_point_propagate;
	    	break;
	    case 'V':
	    case 'v':
	    	front->vfunc = vortex_vel;
	    	init_vortex_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    	break;
	    case 'D':
	    case 'd':
	    	front->vfunc = double_vortex_vel;
	    	init_bipolar_params(&front->vparams,dim);
	    	front->_point_propagate = fourth_order_point_propagate;
	    	break;
	    default:
	    	screen("Unsupported velocity field for first "	
		       "order point propagation\n");
	    	clean_up(ERROR);
	    }
	}
	else
	{
	    front->vfunc = velo_func_pack->func;
	    front->vparams = velo_func_pack->func_params;
	    if (velo_func_pack->point_propagate != NULL)
	    	front->_point_propagate = velo_func_pack->point_propagate;
	    else
	    	front->_point_propagate = first_order_point_propagate;
	}
}	/* end FrontInitVelo_function */
}}}
src/front/fmap.c
{{{
EXPORT	void FrontMovieFrame(
	Front *front,
	char *out_name,
	bool print_in_binary)
{
	show_front_output(front,out_name,print_in_binary);
}	/* end FrontMovieFrame */
}}}
src/front/fmap.c
{{{
EXPORT	float FrontOutputTimeControl(
	Front *front,
	bool *is_movie_time,
	bool *is_print_time,
	bool *time_limit_reached,
	int *im,		/* Printing number */
	int *ip)		/* Movie Frame number */
{
	float time = front->time;
	float dt = front->dt;
	float new_dt;
	float dt1,dt2,dt3;

	*is_movie_time = *is_print_time = *time_limit_reached = NO;

	dt1 = (*im)*front->movie_frame_interval - time;
	dt2 = (*ip)*front->print_time_interval - time;
	dt3 = front->max_time - time;
	new_dt = min3(dt1,dt2,dt3);

	if (front->step >= front->max_step)
            *time_limit_reached = YES;

	if (new_dt > dt) 
	    return dt;

	if (dt1 == new_dt)
	{
	    *is_movie_time = YES;
	    (*im)++;
	}
        if (dt2 == new_dt)
        {
            *is_print_time = YES;
	    (*ip)++;
        }
        if (dt3 == new_dt)
        {
            *time_limit_reached = YES;
        }
	return new_dt;
}	/* end FrontOutputTimeControl */
}}}
src/front/fmap.c
{{{
EXPORT void FrontPreAdvance(
	Front *front,
	double dt)
{
	INTERFACE *intfc = front->interf;
	CURVE **c;
	int i,j,index,max_body_index = -1;
	int dim = front->rect_grid->dim;
	double *torque,**force;
	double t,f[MAXD];

	for (c = intfc->curves; c && *c; ++c)
	{
	    if (wave_type(*c) == MOVABLE_BODY_BOUNDARY)
		if (body_index(*c) > max_body_index)
		    max_body_index = body_index(*c);
	}
	max_body_index++;
	pp_global_imax(&max_body_index,1);
	if (max_body_index == 0) return;

	uni_array(&torque,max_body_index,FLOAT);
	bi_array(&force,max_body_index,MAXD,FLOAT);
	for (i = 0; i < max_body_index; ++i)
	{
	    torque[i] = 0.0;
	    for (j = 0; j < dim; ++j)
	    	force[i][j] = 0.0;
	}

	for (c = intfc->curves; c && *c; ++c)
	{
	    if (wave_type(*c) == MOVABLE_BODY_BOUNDARY)
	    {
		if (motion_type(*c) == PRESET_MOTION) continue;
		index = body_index(*c);
		FrontForceAndTorqueOnCurve(front,*c,dt,f,&t);
		torque[index] += t;
	    	for (j = 0; j < dim; ++j)
	    	    force[index][j] += f[j];
	    }
	}
	for (i = 0; i < max_body_index; ++i)
	{
	    pp_global_sum(force[i],dim);
	    pp_global_sum(&torque[i],1);
	}
	for (c = intfc->curves; c && *c; ++c)
	{
	    if (wave_type(*c) == MOVABLE_BODY_BOUNDARY)
	    {
		index = body_index(*c);
		if (motion_type(*c) == PRESET_MOTION) 
		{
		    if (debugging("rigid_body"))
		    {
		    	printf("Body index: %d\n",index);
		    	printf("Preset motion\n");
		    	printf("angular_velo = %f\n",angular_velo(*c));
		    	printf("center_of_mass_velo = %f  %f\n",
					center_of_mass_velo(*c)[0],
					center_of_mass_velo(*c)[1]);
		    }
		    continue;
		}
		angular_velo(*c) += dt*torque[index]/mom_inertial(*c);
		if (motion_type(*c) != ROTATION)
		{
		    for (i = 0; i < dim; ++i)
		    {
		    	center_of_mass_velo(*c)[i] +=
                        	dt*force[index][i]/total_mass(*c);
		    }
		}
		else 
		{
		    for (i = 0; i < dim; ++i)
		    	center_of_mass_velo(*c)[i] = 0.0;
		}
		for (i = 0; i < dim; ++i)
                    center_of_mass(*c)[i] += dt*center_of_mass_velo(*c)[i];
		if (debugging("rigid_body"))
		{
		    printf("Body index: %d\n",index);
		    printf("torque = %f\n",torque[index]);
		    printf("force = %f %f\n",force[index][0],force[index][1]);
		    printf("angular_velo = %f\n",angular_velo(*c));
		    printf("center_of_mass = %f  %f\n",
			center_of_mass(*c)[0],center_of_mass(*c)[1]);
		    printf("center_of_mass_velo = %f  %f\n",
			center_of_mass_velo(*c)[0],center_of_mass_velo(*c)[1]);
		}
	    }
	}
	free_these(2,force,torque);
}	/* end FrontPreAdvance */
}}}
src/front/fmap.c
{{{
EXPORT	void FrontPrintOut(
	Front *front,
	char *out_name)
{
	print_front_output(front,out_name);
}	/* end FrontPrintOut */
}}}
src/front/fmap.c
{{{
EXPORT	void FrontProp(
	Front *front)
{
	double dt_frac;
	Front *newfront;

	FrontAdvance(front->dt,&dt_frac,front,&newfront,
                                (POINTER)NULL);
	FrontFreeGridIntfc(front);
        assign_interface_and_free_front(front,newfront);
	FrontMakeGridIntfc(front);
}	/* end FrontProp */
}}}
src/front/fmap.c
{{{
EXPORT void FrontReadRegularDomainInfo(
        char *in_name,
        F_BASIC_DATA *f_basic)
{
	
	FILE *infile;
	char input_string[200],sbdry[200];
	int i;

	infile = fopen(in_name,"r");
	for (i = 0; i < f_basic->dim; ++i)
	{
	    sprintf(input_string,"Domain limit in %d-th dimension:",i);
	    fgetstring(infile,input_string);
	    fscanf(infile,"%lf %lf",&f_basic->L[i],&f_basic->U[i]);
	}
	fgetstring(infile,"Computational grid:");
	for (i = 0; i < f_basic->dim; ++i)
	{
	    fscanf(infile,"%d",&f_basic->gmax[i]);
	}
	for (i = 0; i < f_basic->dim; ++i)
	{
	    sprintf(input_string,"Lower boundary in %d-th dimension:",i);
	    fgetstring(infile,input_string);
	    fscanf(infile,"%s",sbdry);
	    switch (sbdry[0])
	    {
	    case 'R':
	    case 'r':
	    	f_basic->boundary[i][0] = REFLECTION_BOUNDARY;
		break;
	    case 'P':
	    case 'p':
	    	f_basic->boundary[i][0] = PERIODIC_BOUNDARY;
		break;
	    case 'D':
	    case 'd':
	    	f_basic->boundary[i][0] = DIRICHLET_BOUNDARY;
	    	break;
	    case 'N':
	    case 'n':
	    	f_basic->boundary[i][0] = NEUMANN_BOUNDARY;
	    	break;
	    default:
	    	printf("Unknown boundary!\n");
		clean_up(ERROR);
	    }
	    sprintf(input_string,"Upper boundary in %d-th dimension:",i);
	    fgetstring(infile,input_string);
	    fscanf(infile,"%s",sbdry);
	    switch (sbdry[0])
	    {
	    case 'R':
	    case 'r':
	    	f_basic->boundary[i][1] = REFLECTION_BOUNDARY;
		break;
	    case 'P':
	    case 'p':
	    	f_basic->boundary[i][1] = PERIODIC_BOUNDARY;
		break;
	    case 'D':
	    case 'd':
	    	f_basic->boundary[i][1] = DIRICHLET_BOUNDARY;
	    	break;
	    case 'N':
	    case 'n':
	    	f_basic->boundary[i][1] = NEUMANN_BOUNDARY;
	    	break;
	    default:
	    	printf("Unknown boundary!\n");
		clean_up(ERROR);
	    }
	}
	fclose(infile);
}	/* end FrontReadRegularDomainInfo */
}}}
src/front/fmap.c
{{{
EXPORT void FrontReadRegularDomainInfo(
        char *in_name,
        F_BASIC_DATA *f_basic)
{
	
	FILE *infile;
	char input_string[200],sbdry[200];
	int i;

	infile = fopen(in_name,"r");
	for (i = 0; i < f_basic->dim; ++i)
	{
	    sprintf(input_string,"Domain limit in %d-th dimension:",i);
	    fgetstring(infile,input_string);
	    fscanf(infile,"%lf %lf",&f_basic->L[i],&f_basic->U[i]);
	}
	fgetstring(infile,"Computational grid:");
	for (i = 0; i < f_basic->dim; ++i)
	{
	    fscanf(infile,"%d",&f_basic->gmax[i]);
	}
	for (i = 0; i < f_basic->dim; ++i)
	{
	    sprintf(input_string,"Lower boundary in %d-th dimension:",i);
	    fgetstring(infile,input_string);
	    fscanf(infile,"%s",sbdry);
	    switch (sbdry[0])
	    {
	    case 'R':
	    case 'r':
	    	f_basic->boundary[i][0] = REFLECTION_BOUNDARY;
		break;
	    case 'P':
	    case 'p':
	    	f_basic->boundary[i][0] = PERIODIC_BOUNDARY;
		break;
	    case 'D':
	    case 'd':
	    	f_basic->boundary[i][0] = DIRICHLET_BOUNDARY;
	    	break;
	    case 'N':
	    case 'n':
	    	f_basic->boundary[i][0] = NEUMANN_BOUNDARY;
	    	break;
	    default:
	    	printf("Unknown boundary!\n");
		clean_up(ERROR);
	    }
	    sprintf(input_string,"Upper boundary in %d-th dimension:",i);
	    fgetstring(infile,input_string);
	    fscanf(infile,"%s",sbdry);
	    switch (sbdry[0])
	    {
	    case 'R':
	    case 'r':
	    	f_basic->boundary[i][1] = REFLECTION_BOUNDARY;
		break;
	    case 'P':
	    case 'p':
	    	f_basic->boundary[i][1] = PERIODIC_BOUNDARY;
		break;
	    case 'D':
	    case 'd':
	    	f_basic->boundary[i][1] = DIRICHLET_BOUNDARY;
	    	break;
	    case 'N':
	    case 'n':
	    	f_basic->boundary[i][1] = NEUMANN_BOUNDARY;
	    	break;
	    default:
	    	printf("Unknown boundary!\n");
		clean_up(ERROR);
	    }
	}
	fclose(infile);
}	/* end FrontReadRegularDomainInfo */
}}}
src/front/fmap.c
{{{
EXPORT void FrontReadTimeControlInfo(
	char *in_name,
        Front *front)
{
	FILE *infile;

	infile = fopen(in_name,"r");
	fgetstring(infile,"Max time:");
	fscanf(infile,"%lf",&front->max_time);
	fgetstring(infile,"Max step:");
	fscanf(infile,"%d",&front->max_step);
	fgetstring(infile,"Print interval:");
	fscanf(infile,"%lf",&front->print_time_interval);
	fgetstring(infile,"Movie frame interval:");
	fscanf(infile,"%lf",&front->movie_frame_interval);
	fgetstring(infile,"CFL factor:");
	fscanf(infile,"%lf",&(Time_step_factor(front)));
	fgetstring(infile,"Redistribution interval:");
	fscanf(infile,"%d",&(Frequency_of_redistribution(front,GENERAL_WAVE)));
	fclose(infile);
}	/* end FrontReadTimeControlInfo */
}}}
src/front/fmap.c
{{{
EXPORT  void FrontRedistMesh(
        Front *fr)
{
        INTERFACE *intfc = fr->interf;
        CURVE **c;
        SURFACE **s;
        int dim = intfc->dim;
        bool force_redistribute = YES;

        switch (dim)
        {
        case 2:
            Curve_redistribute(fr,&force_redistribute);
            break;
        case 3:
	    reset_normal_on_intfc(fr->interf);
            Surface_redistribute(fr,&force_redistribute);
        }
}       /* end FrontRedistMesh */
}}}
src/front/finit.c
{{{
EXPORT  void    FrontStartUp(
        Front *front,
	F_BASIC_DATA *ft_basic)
{
#if defined(PP_MODE)
       	PP_GRID *pp_grid = NULL;
#endif /* defined(PP_MODE) */
       	IMPORT bool suppress_prompts;
       	int i,j,dim;
        static const int DEFAULT_BUF_WIDTH = 3;
        static RECT_GRID comp_grid;
        static F_INIT_DATA Init;
	int **rect_bdry_type;

	start_clock("FrontStartUp");
        setbuf(stdin,NULL);
        init_clean_up(NULL,NULL);

	if(ft_basic == NULL) /* call build-in functions to prompt data */
	{
        	suppress_prompts = YES;
		Init.use_default_front_data = YES;

		screen("Welcome to the World of Partial Interfaces!\n");
		init_prompting_and_debugging(init_data(&Init));
        	set_binary_output(NO);
		screen("Enter the interface dimension: ");
		(void) Scanf("%d\n",&dim);

        	for (i = 0; i < dim; ++i)
        	{
            		subdomains(init_data(&Init))[i] = 1;
            		buffer_zones(init_data(&Init))[i] = DEFAULT_BUF_WIDTH 
					+ MAXD/3;
        	}

        	/* Init rectangular grids */
		comp_grid.dim = dim;
		i_init_remap_and_rect_grid(&comp_grid);
        	front->rect_grid = &comp_grid;

		Init._StateSize = front->sizest;
		set_size_of_intfc_state(front->sizest);
        	f_set_interface_hooks(dim,init_data(&Init));

        	/* Init front interface */

        	i_intfc(&Init) = front->interf = make_interface(dim);
		bi_array(&rect_bdry_type,MAXD,2,INT);
        	init_rect_bdry_type(rect_bdry_type,front->rect_grid);

        	copy_rect_grid(computational_grid(front->interf),
                        front->rect_grid);
        	set_test_front(&Init,front);
		delete_interface(front->interf);
		set_size_of_intfc_state(front->sizest);
        	i_intfc(&Init) = front->interf = make_interface(dim);
		for (i = 0; i < dim; ++i)
		{
		    for (j = 0; j < 2; ++j)
		    {
			rect_boundary_type(front->interf,i,j) = 
				rect_bdry_type[i][j];
		    }
		}
		free(rect_bdry_type);

	}
	else 	/* use supplied data to initialize front */
	{
		Init.use_default_front_data = NO;
		init_default_debugging(init_data(&Init));
        	set_binary_output(NO);
		dim = ft_basic->dim;

        	for (i = 0; i < dim; ++i)
        	{
            		subdomains(init_data(&Init))[i] = 1;
            		buffer_zones(init_data(&Init))[i] = DEFAULT_BUF_WIDTH 
					+ MAXD/3;
#if defined(__MPI__)
                        subdomains(init_data(&Init))[i] =
                                        ft_basic->subdomains[i];
#endif /* defined(__MPI__) */
        	}
		Init._StateSize = front->sizest = 
				ft_basic->size_of_intfc_state;
		set_size_of_intfc_state(front->sizest);

        	f_set_interface_hooks(dim,init_data(&Init));
		if (ft_basic->RestartRun)
		{
		    IO_TYPE io_type;
		    int grid_set;
		    FILE *rfile;
		    rfile = fopen(ft_basic->restart_name,"r");
		    determine_io_type(rfile,&io_type);
		    read_print_front_time_and_step(front,io_type.file);
		    i_intfc(&Init) = front->interf = 
		    	read_print_interface((INIT_DATA*)&Init,&io_type,
					NO,&grid_set);
        	    front->rect_grid = &comp_grid;
		    copy_rect_grid(front->rect_grid,
		    		computational_grid(front->interf));
        	    set_default_front(&Init,front);
		    set_size_of_intfc_state(front->sizest);
		}
		else
		{
        	    /* Init rectangular grids */
		    comp_grid.dim = dim;
		    set_remap_and_rect_grid(ft_basic->L,ft_basic->U,
			    ft_basic->gmax,IDENTITY_REMAP,&comp_grid);
        	    front->rect_grid = &comp_grid;

        	    /* Init front interface */

        	    i_intfc(&Init) = front->interf = make_interface(dim);

        	    copy_rect_grid(computational_grid(front->interf),
                            front->rect_grid);
        	    set_default_front(&Init,front);
		    delete_interface(front->interf);
		    set_size_of_intfc_state(front->sizest);
        	    i_intfc(&Init) = front->interf = make_interface(dim);
		    copy_rect_grid(computational_grid(front->interf),
		        	    front->rect_grid);
		    for (i = 0; i < dim; ++i)
		    {
		        for (j = 0; j < 2; ++j)
		        {
			    rect_boundary_type(front->interf,i,j) = 
				    ft_basic->boundary[i][j];
		        }
		    }
		}
	}
        front->pp_grid = set_pp_grid((INIT_DATA*)&Init,&comp_grid);

        /* front hook up and initialization */
        front->_tan_point_propagate = NULL;
        front->_reconstruct_front_at_grid_crossing =
                        rebuild_intfc_at_crossings3d;
        front->_repair_front_at_grid_crossing =
                        repair_intfc_at_crossings3d;

	front->hdf_movie_var = NULL;
	stop_clock("FrontStartUp");
	return;
}       /* end FrontStartUp */

}}}
src/front/fdecs.h
{{{
#define Front_spacing(fr,i) 						\
		(Redistribution_info(fr).spacing[i])
}}}
To get started with this blank [[TiddlyWiki]], you'll need to modify the following tiddlers:
* [[SiteTitle]] & [[SiteSubtitle]]: The title and subtitle of the site, as shown above (after saving, they will also appear in the browser title bar)
* [[MainMenu]]: The menu (usually on the left)
* [[DefaultTiddlers]]: Contains the names of the tiddlers that you want to appear when the TiddlyWiki is opened
You'll also need to enter your username for signing your edits: <<option txtUserName>>
src/intfc/int.h
{{{
	/* Hypersurface Data structures */

struct _HYPER_SURF
{
	union {
		int	*bptr;
		POINT	*p;
		CURVE	*c;
		SURFACE	*s;
	} obj;

	struct _INTERFACE *interface;
	struct _HYPER_SURF *hs;
	/*
	 * NOTE on components.  The positive side of a hypersurface is by
	 * definition the side into which the hypersurface normal points.
	 *
	 * For points in 1D this is the right side of the point and the
	 * negative side is the left side.
	 *
	 * For curves in 2D the positive side is the right side of curve
	 * and the negative side is the left side of the curve when
	 * viewed in a direction aligned with the curve tangent (ie from the
	 * start to end of a bond).
	 *
	 * For surfaces in 3D the positive side is defined as the side
	 * into which the normal points. The normal vector on a triangle
	 * has direction given by the vector cross product (p1 - p0)X(p2 - p0)
	 * so standing on point p0 and looking into the normal direction we
	 * are looking into the local positive side of surface.  The negative
	 * side is of curve the side opposite to the positive side.
	 */

	COMPONENT pos_comp, neg_comp;
	int pp_index;  /* Identifies families of connected hypersurfaces */
        struct _DYNAMIC_COMP_CHANGE {
            bool   change;
            int    side;
            COMPONENT  new_comp;
        } dyn_comp_ch;
};
}}}
src/intfc/int.h
{{{
struct _HYPER_SURF_BDRY
{
	union {
		int	*bptr;
		NODE	*n;
		CURVE	*c;
	} obj;
	struct _INTERFACE *interface;
	struct _HYPER_SURF_BDRY *hsb;
};
}}}
src/intfc/int.h
{{{
union _HYPER_SURF_ELEMENT {
	byte	bt;
	BOND	b;
	TRI	tri;
};
typedef union _HYPER_SURF_ELEMENT HYPER_SURF_ELEMENT;
}}}
src/intfc/int.h
{{{
struct _INTERFACE
{
	struct _HYPER_SURF	**hss;
	struct _HYPER_SURF_BDRY **hses;

	struct _POINT	**points; /* Pointer to Set of Points */
	struct _NODE	**nodes;	/* Pointer to Set of Nodes */
	struct _CURVE	**curves;	/* Pointer to Set of Curves */
	struct _SURFACE **surfaces;	/* Pointer to Set of Surfaces */
	struct _C_CURVE **c_curves;	/* c_curves on interface */

	int		dim;		/* Dimension of Imbedding Space */
	int		num_points;	/* Total from curves */

	/* Internal Variables: */
	struct Table	*table;	/* Pointer to Interface Table */
	bool	modified;	/* Interface Recently Modified */
	bool	normal_unset;	/* Normal unset since last modify */
	bool	curvature_unset;/* Curvature unset since last modify */
	bool            _interface_reconstructed;
	int		rect_bdry_type[MAXD][2];
	COMPONENT	elliptic_comp;	/* component of elliptic region */
	COMPONENT	default_comp;	/* for subdomain with no surf */
	struct _INTERFACE  *prev_interf;
	POINTER		e_comps;
	struct	_TRI	**point_tri_store;
};
}}}
!![[FrontInitStandardIO]] Handles the command line parameters
!![[FrontStartUp]] Initialize the Front
*#[[f_set_interface_hooks]] Set function pointers
*#[[set_remap_and_rect_grid]]
*##[[set_remap]] [x,y,z],[r,z,theta],[r,theta,phi] for Cartesian, cylindrical and spherical
*## L[dim] and U[dim] are the lower and upper limit of the coordinate, gmax[dim] is the number of grid, h[dim] is the grid size
*##[[set_rect_grid]]
*###[[area_of_rect_grid]] From this function, theta in cylindrical coordinate ranges [0,1].
*#[[make_interface]]
*##[[i_user_hook]]
*##[[user_make_interface]] -> [[f_user_make_interface]]
*###[[f_user_hook]]
*#[[copy_rect_grid]]
*#[[set_default_front]]
*##[[set_front_hooks]]
*##[[set_front_pp_grid]]
*##[[set_default_front_options]]
*##[[f_set_default_front_parameters]] set default values for most front fields
*###[[set_advance_front]] set front advance function pointers
*##[[init_front]]
*#[[delete_interface]] -> [[f_delete_interface]]  clean up the interface for next step's make_interface, why?
*##[[remove_corresponds_to_deleted_interface]]
*##[[rst_cor_after_delete_interface]]
*##[[i_delete_interface]]
*#[[make_interface]]
*#[[copy_rect_grid]]
*#[[set_pp_grid]]
!![[FrontInitIntfc]] Initialize the [[INTERFACE]] using level function
*[[LEVEL_FUNC_PACK]]
----
*[[FrontInitIntfc1d]]
*#[[make_point]] -> [[f_make_point]] -> [[i_make_point]]
*##[[make_hypersurface]]-> [[f_make_hypersurface]] -> [[i_make_hypersurface]]
*#[[set_topological_grid]]
*#[[set_boundary]] -> [[f_set_boundary1d]] -> [[i_set_boundary1d]]
*[[FrontInitIntfc2d]]
*#[[copy_rect_grid]]
*#[[make_level_curv]]
*##[[assign_two_comp_domain]]
*##[[count_crx_through_comp2]]
*##[[install_grid_crx2d]]
*##[[make_node]] -> [[f_Point]]
*##[[make_curv]] -> [[f_make_curve]]
*###[[i_make_curve]]
*###[[f_user_2d_make_curve]]
*##[[make_grid_curves]]
*###[[construct_comp2_blk]]
*#[[make_array_curve]]
*#[[set_topological_grid]]
*#[[rect_bdry_redist2d]]
*##[[rect_bdry_curve_redist]]
*[[FrontInitIntfc3d]]

!![[FrontInitVelo]] initializes the velocity function
*[[VELO_FUNC_PACK]]
----
!![[liquid initialization]]



!! About ~FronTier
~FronTier is a set of libraries that implements differnt types of Front Traking algorithms.
Front Tracking is a numerical method for the solution of partial differential equations whose solutions have discontinuities.  

There were some useful tutorial about FronTier.
[[A Short Course in Front Tracking by John W. Grove|http://frontier.ams.sunysb.edu/shock_hmpg/FTnotes/frontier/index.htm]]
[[FronTier Source Notes by Wei Guo|http://www.ams.sunysb.edu/~shock/FTdoc/src_notes/ftnote/doc.ps]]
[[David Saltz and Folkert Tangerman|http://frontier.ams.sunysb.edu/shock_hmpg/FTdoc/FTmain.html]]

!! About this documentation
src/front/fdecs.h
{{{
struct _LEVEL_FUNC_PACK {
	/* Not needed for restart initialization */
        COMPONENT neg_component;
        COMPONENT pos_component;

	/* For level set initialization */
        double (*func)(POINTER,double*);
        POINTER func_params;
	/* For constrained level set initialization */
        bool (*constr_func)(POINTER,double*);
        POINTER constr_params;

	/* For point array initialization */
	int num_points;
	double **point_array;
	bool is_closed_curve;
	/* For initialization by reading SDL file */
	bool read_sdl_input;
	char *sdl_name;
	/* For initialization by reading VTK file */
	bool read_vtk_input;
	char *vtk_name;
	bool is_mono_hs;
	int wave_type;
	
	bool set_3d_bdry;
};
typedef struct _LEVEL_FUNC_PACK LEVEL_FUNC_PACK;
}}}
liquid/liquid.h
{{{
class L_CARTESIAN{
	Front *front;
public:
	L_CARTESIAN(Front &front);
	// constructor
	~L_CARTESIAN();

	double m_dt;			// time increment
	double max_speed;		// for stability of convection
	double max_dt;			// max_dt from cartesian
	double *top_h;

	void initMesh(void);		// setup the cartesian grid
	void readFrontInteriorStates(char *state_name);
	void printFrontInteriorStates(char *state_name);
	void initMovieVariables();
	void setInitialCondition(void);
	void getVelocity(double *p, double *U);
	void setInitialIntfc(LEVEL_FUNC_PACK*,char*);

	// main step function
	void solve(double dt);		

	// member data: RECT_GRID
	int dim;

private:
	// On topological grid
	RECT_GRID *top_grid;
	double *array;		// for scatter states;
	double *top_L,*top_U;
	int *top_gmax;
	COMPONENT *top_comp;
	EQN_PARAMS *eqn_params;

	int *lbuf,*ubuf,*gmax;
	int **ij_to_I,**I_to_ij;	// Index mapping for 2D
	int ***ijk_to_I,**I_to_ijk;	// Index mapping for 3D

	// Sweeping limites
	int imin,jmin,kmin;
	int imax,jmax,kmax;

	// member data: mesh storage
	std::vector<L_RECTANGLE> 	cell_center;

	// member data: 
	int m_comp[2];
	double m_mu[2];
	double m_rho[2];		// two component at most
	double m_smoothing_radius;	// used by getSmoothingFunction()

	double hmin;			// smallest spacing
	double m_t;                     // time

	// for parallel partition
	int             NLblocks,ilower,iupper;
        int             *n_dist;

	void setComponent(void);	// init components	
	double getSmoothingFunction(double r);	// Heaviside function
	void makeGridIntfc();
	void deleteGridIntfc();
	void augmentMovieVariables(void);
	void setDirichletBounrady();	// TMP for testing
	void copyMeshStates();
	void sampleVelocity(SAMPLE sample);
	void sampleVelocity2d(SAMPLE sample);
	void sampleVelocity3d(SAMPLE sample);
	void compareVelocity(int idir);

	// Initialization of interface
	void initRayleiTaylorIntfc(LEVEL_FUNC_PACK*,char*);
	void initCirclePlaneIntfc(LEVEL_FUNC_PACK*,char*);

	// Initialization of states
	void initRayleiTaylorStates(char*);

	/*TMP*/
	void checkStates();

	// parallelization related functions
	//
	void scatMeshArray();
	void setGlobalIndex();

	void setIndexMap(void);
		// for computeProjection(), 
		// should be changed to use setIndexMap() only.

	void setSmoothedProperties(void); // smooth discontinuous properties
       	void setSmoothedProperties2d(void); // for 2D
        void setSmoothedProperties3d(void); // for 3D

	// -------------------------------------------------------
	// 		incompressible solver functions
	// -------------------------------------------------------
	void setAdvectionDt(void);
	void computeAdvection(void);
	void computeAdvection2d(void);
	void computeAdvection3d(void);
	
	double computeVelocityDivergence(int indexRectangle);
	double computeVelocityDivergence2d(int indexRectangle);
	double computeVelocityDivergence3d(int indexRectangle);

	void computePressureGradient(int indexRectangle, double *gradP);
	void computePressureGradient2d(int indexRectangle, double *gradP);
	void computePressureGradient3d(int indexRectangle, double *gradP);

	void computeDiffusion(void);	// Crank Nicolson method, wrong
	void compDiffWithSmoothProperty(void);
	void compDiffWithSmoothProperty2d(void);
	void compDiffWithSmoothProperty3d(void);
	void compDiffWithSmoothProperty2d_decoupled(void);
	void compDiffWithSmoothProperty3d_decoupled(void);
					// Crank Nicolson method

	void computeProjection(void);		
	void computeProjection2d(void);		
	void computeProjection3d(void);		

	void computeNewVelocity(void);
	void computeNewVelocity2d(void);
	void computeNewVelocity3d(void);
					// time n+1 velocity

	void compSGS(void);             // subgrid model by Hyunkyung Lim

	void computeSourceTerm(double *coords, L_STATE &state); 
	void computeSourceTerm(double *coords, double t, L_STATE &state); 

	void computeExactSolution(double *coords, L_STATE &state); 

	void getPressureJumpParameter(double *coords0, double *coords1, 
			double &theta, double &jumpPressure, 
			double &jumpDerivative);

	// velocity field query
	void getVelocityGradient(double *p,double *gradU,double *gradV);

	// ----------------------------------------------------------
	// 		utility functions
	// ----------------------------------------------------------

	int getEdgeIndex(double i, double j);
	void getEdgeIndex(int indexEdge, double &i, double &j);

	void getRectangleIndex(int indexRectangle, int &i, int &j);
	void getRectangleIndex(int indexRectangle, int &i, int &j, int &k);
	int getRectangleComponent(int index);	// the center component
	void getRectangleCenter(int index, double *coords);
	void getRectangleCenter(int index0, int index1, double *coords);
	
	int getInteger(double i);
	bool isInteger(double i);

	double getVorticity(int i, int j);
	double getVorticityX(int i, int j, int k);
	double getVorticityY(int i, int j, int k);
	double getVorticityZ(int i, int j, int k);
	double getDistance(double *coords0, double *coords1);

			// incompletely implemented
	void getNearestInterfacePoint(COMPONENT comp,double *q,double *p); 
		
	int  getComponent(int *icoords);	
	int  getComponent(double *coords);	
	void save(char *filename);
	/*TMP*/
	void check_ceiling();
}
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::initMovieVariables()
{
	int i,j,k,index;
	static HDF_MOVIE_VAR *hdf_movie_var;
	static double *pres,*vort,*xvel,*yvel,*zvel;
	int n;
	HDF_MOVIE_OPTION *hdf_movie_option = eqn_params->hdf_movie_option;

	if (hdf_movie_var == NULL)
	{
	    scalar(&hdf_movie_var,sizeof(HDF_MOVIE_VAR));
	    switch (dim)
	    {
	    case 2:
		hdf_movie_var->num_var = n = 0;
	    	bi_array(&hdf_movie_var->var_name,4,100,sizeof(char));
	    	uni_array(&hdf_movie_var->top_var,4,sizeof(double*));
	    	uni_array(&hdf_movie_var->obstacle_comp,4,sizeof(COMPONENT));
		if (hdf_movie_option->plot_pres)
		{
	    	    sprintf(hdf_movie_var->var_name[n],"pres");
	    	    hdf_movie_var->get_state_var[n] = getStatePres;
	    	    hdf_movie_var->top_var[n] = eqn_params->pres;
	    	    hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    hdf_movie_var->num_var = ++n;
		}
		if (hdf_movie_option->plot_vort)
		{
	    	    sprintf(hdf_movie_var->var_name[n],"vort");
	    	    hdf_movie_var->get_state_var[n] = getStateVort;
	    	    hdf_movie_var->top_var[n] = eqn_params->vort;
	    	    hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    hdf_movie_var->num_var = ++n;
		}
		if (hdf_movie_option->plot_velo)
		{
	    	    sprintf(hdf_movie_var->var_name[n],"xvel");
	    	    hdf_movie_var->get_state_var[n] = getStateXvel;
	    	    hdf_movie_var->top_var[n] = eqn_params->vel[0];
	    	    hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    hdf_movie_var->num_var = ++n;
	    	    sprintf(hdf_movie_var->var_name[n],"yvel");
	    	    hdf_movie_var->get_state_var[n] = getStateYvel;
	    	    hdf_movie_var->top_var[n] = eqn_params->vel[1];
	    	    hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    hdf_movie_var->num_var = ++n;
		}
		break;
	    case 3:
		hdf_movie_var->num_var = n = 0;
	    	bi_array(&hdf_movie_var->var_name,12,100,sizeof(char));
	    	uni_array(&hdf_movie_var->top_var,12,sizeof(double*));
	    	uni_array(&hdf_movie_var->idir,12,sizeof(int));
	    	uni_array(&hdf_movie_var->obstacle_comp,12,sizeof(COMPONENT));
		if (hdf_movie_option->plot_cross_section[0])
		{
		    if (hdf_movie_option->plot_pres)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"pres-yz");
	    	    	hdf_movie_var->get_state_var[n] = getStatePres;
	    		hdf_movie_var->top_var[n] = eqn_params->pres;
	    		hdf_movie_var->idir[n] = 0;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		    if (hdf_movie_option->plot_velo)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"velo-yz-y");
	    	    	hdf_movie_var->get_state_var[n] = getStateYvel;
	    		hdf_movie_var->top_var[n] = eqn_params->vel[1];
	    		hdf_movie_var->idir[n] = 0;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
	    	    	sprintf(hdf_movie_var->var_name[n],"velo-yz-z");
	    	    	hdf_movie_var->get_state_var[n] = getStateZvel;
	    		hdf_movie_var->top_var[n] = eqn_params->vel[2];
	    		hdf_movie_var->idir[n] = 0;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		    if (hdf_movie_option->plot_vort)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"vort-yz");
	    	    	hdf_movie_var->get_state_var[n] = getStateXvort;
	    		hdf_movie_var->top_var[n] = eqn_params->vort3d[0];
	    		hdf_movie_var->idir[n] = 0;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		}
		if (hdf_movie_option->plot_cross_section[1])
		{
		    if (hdf_movie_option->plot_pres)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"pres-xz");
	    	    	hdf_movie_var->get_state_var[n] = getStatePres;
	    		hdf_movie_var->top_var[n] = eqn_params->pres;
	    		hdf_movie_var->idir[n] = 1;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		    if (hdf_movie_option->plot_velo)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"velo-xz-x");
	    	    	hdf_movie_var->get_state_var[n] = getStateXvel;
	    		hdf_movie_var->top_var[n] = eqn_params->vel[0];
	    		hdf_movie_var->idir[n] = 1;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
	    	    	sprintf(hdf_movie_var->var_name[n],"velo-xz-z");
	    	    	hdf_movie_var->get_state_var[n] = getStateZvel;
	    		hdf_movie_var->top_var[n] = eqn_params->vel[2];
	    		hdf_movie_var->idir[n] = 1;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		    if (hdf_movie_option->plot_vort)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"vort-xz");
	    	    	hdf_movie_var->get_state_var[n] = getStateYvort;
	    		hdf_movie_var->top_var[n] = eqn_params->vort3d[1];
	    		hdf_movie_var->idir[n] = 1;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		}
		if (hdf_movie_option->plot_cross_section[2])
		{
		    if (hdf_movie_option->plot_pres)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"pres-xy");
	    	    	hdf_movie_var->get_state_var[n] = getStatePres;
	    		hdf_movie_var->top_var[n] = eqn_params->pres;
	    		hdf_movie_var->idir[n] = 2;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		    if (hdf_movie_option->plot_velo)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"velo-xy-x");
	    	    	hdf_movie_var->get_state_var[n] = getStateXvel;
	    		hdf_movie_var->top_var[n] = eqn_params->vel[0];
	    		hdf_movie_var->idir[n] = 2;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
	    	    	sprintf(hdf_movie_var->var_name[n],"velo-xy-y");
	    	    	hdf_movie_var->get_state_var[n] = getStateYvel;
	    		hdf_movie_var->top_var[n] = eqn_params->vel[1];
	    		hdf_movie_var->idir[n] = 2;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		    if (hdf_movie_option->plot_vort)
		    {
	    	    	sprintf(hdf_movie_var->var_name[n],"vort-xy");
	    	    	hdf_movie_var->get_state_var[n] = getStateZvort;
	    		hdf_movie_var->top_var[n] = eqn_params->vort3d[2];
	    		hdf_movie_var->idir[n] = 2;
	    	    	hdf_movie_var->obstacle_comp[n] = SOLID_COMP;
		    	hdf_movie_var->num_var = ++n;
		    }
		}
	    }
	}
	front->hdf_movie_var = hdf_movie_var;
}	/* end initMovieVariables */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::printFrontInteriorStates(char *out_name)
{
	int i,j,k,l,index;
	char filename[100];
	FILE *outfile;
	INTERFACE *intfc = front->interf;
        STATE *sl,*sr;
        POINT *p;
        HYPER_SURF *hs;
        HYPER_SURF_ELEMENT *hse;

	sprintf(filename,"%s-state.ts%s",out_name,
			right_flush(front->step,7));
#if defined(__MPI__)
	if (pp_numnodes() > 1)
            sprintf(filename,"%s-nd%s",filename,right_flush(pp_mynode(),4));
#endif /* defined(__MPI__) */
	sprintf(filename,"%s-liquid",filename);
	outfile = fopen(filename,"w");

        /* Initialize states at the interface */
        fprintf(outfile,"Interface liquid states:\n");
        int count = 0;
        next_point(intfc,NULL,NULL,NULL);
        while (next_point(intfc,&p,&hse,&hs))
        {
            count++;
            slsr(p,hse,hs,(POINTER*)&sl,(POINTER*)&sr);
            fprintf(outfile,"%20.16f %20.16f\n",getStatePres(sl),
				getStatePres(sr));
	    if (dim == 2) 
	    {
            	fprintf(outfile,"%20.16f %20.16f\n",getStateXvel(sl),
				getStateXvel(sr));
            	fprintf(outfile,"%20.16f %20.16f\n",getStateYvel(sl),
				getStateYvel(sr));
            	fprintf(outfile,"%20.16f %20.16f\n",getStateVort(sl),
				getStateVort(sr));
	    }
	    if (dim == 3) 
	    {
            	fprintf(outfile,"%20.16f %20.16f\n",getStateXvel(sl),
				getStateXvel(sr));
            	fprintf(outfile,"%20.16f %20.16f\n",getStateYvel(sl),
				getStateYvel(sr));
            	fprintf(outfile,"%20.16f %20.16f\n",getStateZvel(sl),
				getStateZvel(sr));
	    }
        }
	
	fprintf(outfile,"\nInterior liquid states:\n");
	switch (dim)
	{
	case 2:
	    for (i = 0; i <= top_gmax[0]; ++i)
	    for (j = 0; j <= top_gmax[1]; ++j)
	    {
		index = d_index2d(i,j,top_gmax);
	        fprintf(outfile,"%20.16f\n",
			cell_center[index].m_state.m_rho);
	        fprintf(outfile,"%20.16f\n",
			cell_center[index].m_state.m_P);
	        fprintf(outfile,"%20.16f\n",
			cell_center[index].m_state.m_mu);
	    	for (l = 0; l < dim; ++l)
	            fprintf(outfile,"%20.16f\n",
			    cell_center[index].m_state.m_U[l]);
	    }
	    break;
	case 3:
	    for (i = 0; i <= top_gmax[0]; ++i)
	    for (j = 0; j <= top_gmax[1]; ++j)
	    for (k = 0; k <= top_gmax[2]; ++k)
	    {
		index = d_index3d(i,j,k,top_gmax);
	        fprintf(outfile,"%20.16f\n",
			cell_center[index].m_state.m_rho);
	        fprintf(outfile,"%20.16f\n",
			cell_center[index].m_state.m_P);
	        fprintf(outfile,"%20.16f\n",
			cell_center[index].m_state.m_mu);
	    	for (l = 0; l < dim; ++l)
	            fprintf(outfile,"%20.16f\n",
			    cell_center[index].m_state.m_U[l]);
	    }
	}
	fclose(outfile);
}
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::setInitialCondition(void)
{
	int i;
	double coords[MAXD];
	L_STATE state;

	FrontMakeGridIntfc(front);
	setDomain();
	m_rho[0] = eqn_params->rho1;		
	m_rho[1] = eqn_params->rho2;		
	m_mu[0] = eqn_params->mu1;		
	m_mu[1] = eqn_params->mu2;		
	if (eqn_params->prob_type == FLUID_SOLID_CIRCLE ||
	    eqn_params->prob_type == FLUID_CRYSTAL)
	    m_comp[0] = SOLID_COMP;
	else
	    m_comp[0] = LIQUID_COMP1;
	m_comp[1] = LIQUID_COMP2;

	m_smoothing_radius = top_h[0] < top_h[1] ? top_h[1] : top_h[0];
	m_smoothing_radius *= 2.0;

	// cell_center
	for (i = 0; i < cell_center.size(); i++)
	{
	    getRectangleCenter(i, coords);
	    computeExactSolution(coords,cell_center[i].m_state);
	}
	copyMeshStates();
}	/* end setInitialCondition */
}}}
[[Introduction]]
[[Data Structure]]
[[Initialization]]
[[File I/O]]
[[Front Advance]]
[[Redistribution]]
[[src]]
[[liquid]]
[[liquid_HK]]
[[Programming Issues]]
NumGeom
[[GettingStarted]]
{{{
 /* A Node of an Interface: */
struct _NODE
{
	int _boundary;		/* Mandatory first element,  see notes on
				 *  boundary macros below */
	struct _NODE *obj;	/* refers back to node, see boundary macro */
	struct _HYPER_SURF_BDRY *hsb;

	struct _INTERFACE *interface;
	POINT *posn;

	struct _CURVE **in_curves;	/* Pointer to Set of In Curves */
	struct _CURVE **out_curves;	/* Pointer to Set of Out Curves */
};
}}}
~NumGeom related 

[[PointArrayRing1]]
[[PointArrayRing2]]
[[Tri_normal]]
[[sqrt_normal]]
src/intfc/int.h
{{{
 /* Point in the Plane: */
struct _POINT
{
	int _boundary;		/* Mandatory first element,  see notes on
				 * boundary macros below */

	double	_coords[MAXD];

	struct {
	    unsigned int _boundary : 1;
	    unsigned int _user0 : 1;
	    unsigned int _user1 : 1;
	    unsigned int _user2 : 1;
	    unsigned int _user3 : 1;
	    unsigned int _user4 : 1;
	    unsigned int _user5 : 1;
	    unsigned int _user6 : 1;
	    unsigned int _user7 : 1;
	    unsigned int _user8 : 1;
	    unsigned int _user9 : 1;
	} _point_flags;

	struct _INTERFACE *interface;
	struct _POINT *obj;	/* refers back to point, see boundary macro */
	struct _HYPER_SURF *hs;
	union _HYPER_SURF_ELEMENT *hse;
	struct _TRI **tris;	/* 3D for tris with vertex as the point */
	int num_tris;

	union {
	    bool      _sorted;
	    POINTER	 _opaque_pointer;
	    struct _NODE *_node;
	    int          _index;
	} private_data;
	double		_nor[3];
	double		_nor0[3];	// First order normal for WLSP
	double		curvature;
	double           vel[3];
	bool		crx;
	int		indx;
};
}}}
src/intfc/int.h
{{{
		/* Structure Defining a Parallel Processing Grid: */

typedef struct {
	double   *dom[MAXD];     /* corner position of domain */
	int     gmax[MAXD];     /* # of subdomains in each dir */
	int	buf[MAXD];	/* shaded subdomain extension. every mesh
				block has the same buffer extension.	*/
	int	nn;		/* total number of nodes 		*/	
	RECT_GRID Global_grid;	/* Rect_grid of total region		*/
	RECT_GRID Zoom_grid;	/* Rect_grid for subdomain		*/
} PP_GRID; 
}}}
src/intfc/isub.c
{{{
EXPORT	void	PointArrayRing2(
	POINT *p,
	HYPER_SURF_ELEMENT *hse,
	HYPER_SURF *hs,
	int *npts1,
	int *npts2,
	POINT **pts1,
	POINT **pts2)
{
	INTERFACE *intfc = hs->interface;
	int i,j,k,l,nt;
	POINT *pp;
	TRI *t;
	bool pp_in_lists;

	PointArrayRing1(p,hse,hs,npts1,pts1);
	*npts2 = 0;
	for (i = 0; i < *npts1; ++i)
	{
	    nt = set_tri_list_around_point(pts1[i],Tri_of_hse(pts1[i]->hse),
	    		&Tri_list_at_vertex.tris,intfc);
	    for (j = 0; j < nt; ++j)
	    {
	    	t = Tri_list_at_vertex.tris[j];
		for (k = 0; k < 3; ++k)
		{
		    pp = Point_of_tri(t)[k];
		    pp_in_lists = NO;
		    if (pp == p) continue;
		    pp_in_lists = pointer_in_list((POINTER)pp,*npts1,
		    			(POINTER*)pts1);
		    if (pp_in_lists) continue;
		    pp_in_lists = pointer_in_list((POINTER)pp,*npts2,
		    			(POINTER*)pts2);
		    if (!pp_in_lists)
		    {
		    	pp->hse = Hyper_surf_element(t);
			pts2[(*npts2)++] = pp;
		    }
		}
	    }
	}
}	/* end PointArrayRing2 */
}}}
[[Proper use of IMPORT,  LOCAL,  and EXPORT]]
src/util/cdecs.h
{{{
#define   IMPORT        extern
#define   LOCAL         static
#define   EXPORT      
#define   LIB_LOCAL

/****
*******************Proper use of IMPORT,  LOCAL,  and EXPORT ******************

The explanation of the LOCAL vs.  static is due to the split nature of
the construction in C.  The static declaration really does two things,
first it declares a variable to be static,  that is its value is retained
from one function call to another,  the second effect is that the variable
becomes local,  that is its access is restricted to the enclosing block.
Actually in C all variables declared within a block (brackets) are local,
so the second case only applies to external variables in a file.  The
default is that externals are global (ie known to all files),  so that to
restrict the scope of an external variable the static is declaration is
used.  Note that all external variable are by default static and global.
The defines EXPORT,  IMPORT,  and LOCAL were designed to explicitly
declare the scope of a given procedure or variable,  thus leaving the
declaration static to perform its first (primary) function.  Thus the
declarations should be used as follows

EXPORT - any variable or procedure with global scope,  this includes
all functions to be called outside of their file of definition,  as well
as any transfile global variables (these are strongly discouraged).

IMPORT - any variable or procedure which is defined elsewhere,  IMPORT
is really just another name for extern and serves exactly the same function.
IMPORTED variable are just that,  variables or procedures that are imported
from somewhere else.

LOCAL - any variable or procedure whose scope is to be limited to its
file of definition.

static - any variable (presumably within a block) whose value is static and
will not change between function calls to that block.

Even though in C LOCAL and static are the same,  we see that the division
of this single variable into two types provides a useful documentation
function by separating the static declaration from the access restriction.

*****/
}}}
intfc/geom.h
{{{
		/* Structure Defining a Regular Rectangular Grid: */
/*
*	Support has been added to support virtual domain buffer zones
*	as well as possibly nonconstant grid spacings.  The storage
*	for the grid lines and spacings is taken from the single
*	array glstore.  The allocated size of glstore should be
*
*				dim-1
*				-----
*				\
*				 \
*	size_of(glstore) =        \	(3*(gmax[i]+ub[i]+lb[i]) + 1)
*				  /
*				 /
*				/
*				-----
*				i = 0
*
*	Which is just the combined length of the edge and dl uni_arrays.
*	This storage should be mapped out as follows
*	
*	edge[0] = glstore + lb[0]
*	edge[i]   = edge[i-1]   + gmax[i-1]   + ub[i-1]   + 1 + lb[i]	(i > 0)
*	dl[0]     = edge[dim-1] + gmax[dim-1] + ub[dim-1] + 1 + lb[0]
*	dl[i]     = dl[i-1]     + gmax[i-1]   + ub[i-1]       + lb[i]	(i > 0)
*	center[0] = dl[dim-1]   + gmax[dim-1] + ub[dim-1]     + lb[0]
*	center[i] = center[i-1] + gmax[i-1]   + ub[i-1]       + lb[i]	(i > 0)
*
*	This arrangement has the following benefits,
*
*	1. Storage need only be allocated once for grid line storage
*	2. The addresses edge[i] - glstore,  center[i] - slstore,
*	   and dl[i] - glstore are absolute numbers independent of processor.
*	   This is exploited in the pointer reconstruction for the topological
*	   grid that is transferred across multiple processors with the
*	   interface.
*
*	   Note that in the the case of the topological grid,  consistency
*	   requires that glstore be allocated by store().
*
*	All allocation of the edge, center, and dl fields should be done through
*	provided functions.
*
*	Besides supporting parallel virtual domains,  the precomputation
*	of the grid cell boundaries and centers should provide increased
*	efficiency in many cases.  Also note that the cell centers, edges
*	and spacings are related by the formulas:
*
*	dl[i][j] = edge[i][j+1] - edge[i][j]
*	center[i][j] = 0.5 * (edge[i][j+1] + edge[i][j])
*/

struct _RECT_GRID {
	double L[3];	  /* Lower corner of rectangle containing grid */
	double U[3];	  /* Upper corner of rectangle containing grid */
	double h[3];	  /* Average grid spacings in the grid	       */
	int   gmax[3];	  /* Number of grid blocks 		       */
	int   dim;	  /* Dimension of Grid */

		/* Specifications for virtual domains and variable grids */

	double GL[3];	  /* Lower corner of global grid */
	double GU[3];	  /* Upper corner of global grid */
	double VL[3];	  /* Lower corner of virtual domain */
	double VU[3];	  /* Upper corner of virtual domain */
	int   lbuf[3];	  /* Lower buffer zone width */
	int   ubuf[3];	  /* Upper buffer zone width */

		/* Specifications for variable mesh grids */

	double *edges[3];	/* Coordinate cell edges */
	double *centers[3];	/* Coordinate cell centers */
	double *dh[3];	   	/* Coordindate cell widths */
	double *glstore;	   	/* Storage for edges, centers and dh arrays */
	int   variable_mesh[3]; /* YES for variable dh in ith direction */

	struct _REMAP {
	    GEOMETRY_REMAP remap;
	    const char     *remap_name;
	    const char     *dnm[3],   /* Symbolic names for coord. directions*/
	                   *Dnm[3],
	                   *dirs[3];
	    double          area;      /* Total (Remappped) Computational Area */
	    /*grid cell area*/
	    double          (*Area)(const double*,const struct _RECT_GRID*);
	} Remap;
}; 
typedef struct _RECT_GRID RECT_GRID;
}}}
src/front/fdecs.h
{{{
struct _REDIST_CONTROL {

	REDISTRIBUTION_MODE _Redistribution_mode;
	CURVE_REDIST_OPTIONS _CurveRedistributionOptions;
#if defined(THREED)
	SURFACE_REDIST_OPTIONS _SurfaceRedistributionOptions;
#endif /* defined(THREED) */

	/* Redistribution initializer */
	void (*_init_redistribute)(INIT_DATA*,struct _Front*);
	void (*_rect_boundary_redistribute)(INTERFACE*,RECT_GRID*,int);

	struct _CURVE_REDISTRIBUTE {
	    struct _CURVE_REDISTRIBUTORS {
	    	/* Redistribute Algorithm for curves*/
	    	bool (*curve_redist_func)(struct _Front*,bool*);

	    	/* Forward orient curve redistribute */
	    	bool (*forward_cur_redist)(struct _Front*,CURVE*,bool);

	    	/* Backward orient curve redistribute */
	    	bool (*backward_cur_redist)(struct _Front*,CURVE*,bool);

	    	/* Node redistribute */
 	    	bool (*node_redistribute)(struct _Front*,bool);
	    } Redistributors;

		/* Clean up function for interface */
	    struct _CURVE_CLEANERS {
	    	void	(*_delete_small_loops)(struct _Front*);
	    	void	(*_delete_fold_back_bonds)(struct _Front*,CURVE*,float,
                                                   int*,int*);
	    	void	(*_delete_exterior_curves)(struct _Front*,INTERFACE*);
	    	bool	(*_delete_phys_remn_on_bdry)(struct _Front*);
	    	bool (*_delete_point_adjacent_to_node)(struct _Front*,
                                                          CURVE*,ORIENTATION);
	    } Cleaners;

			/* Grid based redist. of rect bdry */
	    bool rect_bdry_redist;
	    	/* Big Angles not Truncated in Redis */
	    float cos_big_angle[2];
	    	/* Arc Length along the Front */
	    float length;
	} Curve_redist;

#if defined(THREED)
	struct _SURFACE_REDISTRIBUTE {
	    /* Redistribute Algorithm for surfaces*/
	    bool (*surface_redist_func)(struct _Front*,bool*);
	    	/* maximum length for bond in 3d curve */
	    float max_len[2];
	    	/* minimum length for bond in 3d curve */
	    float min_len[2];
	    	/* square of maximum area allowed for triangle */
	    float max_area2[2];
	    	/* square of minimum area allowed for triangle */
	    float min_area2[2];
	    	/* linear tolerance of aspect ratio     */
	    float max_sqr_tri_len;
	    	/* square of maximum scaled triangle side length */
	    float ar_tol[2];


	} Surface_redist;
#endif /* defined(THREED) */

	float grid_size_redist;         /*Nmber of grid size to redistribute*/
	int count_redist;		/* Number of calls to Redistribute */
	int freq_redist[3];		/* Frequency for Redistribution */
	int freq_reconstruct;		/* Frequency for reconstruction */
					/* (for hybrid tracking) */
	float spacing[2];		/* Spacing of Points on 2d Front */
	bool intfc_redistributed;	/* Yes if redistribute was performed */
	TRACKING_ALGORITHM tracking_algorithm;	/* method of tracking */
};
typedef struct _REDIST_CONTROL REDIST_CONTROL;
}}}
[[redistribute]]
*[[redistribute1d]]
*[[redistribute2d]]
*#[[Curve_redistribute]]
*#*[[full_redistribute]]
*#*redistribute vector curve
*#*[[Forward_curve_redistribute]]
*#*[[Backward_curve_redistribute]]  redistribute in another direction
*#**[[equi_curve_redistribute]]
*#**#[[Front_spacing]]
*#**#[[scaled_bond_length]]
*#**#[[curve_delete_very_short_bonds]]
*#**#[[cross_rect_grid_bdry]] test if a bond is crossing the grid boundary
*#**#[[equi_redist_curve_seg]]
*#**##[[replace_curve_seg_by_bond]]
*#**##[[insert_point_in_bond]]
*#**##*[[i_user_interface]]
*#**##*[[f_insert_point_in_bond]]
*#**##*#[[i_insert_point_in_bond]]
*#**##*#[[f_user_2d_insert_point_in_bond]]
*# [[closed_curve_node_redistribution]]
*[[redistribute3d]]
By default, Front advance does not invoke [[Surface_redistribute]]
example3d/example09.c
[[FrontRedistMesh]]
*Curve
*Surface
*#[[reset_normal_on_intfc]]
*#*[[set_normal_of_tri]]
*#[[Surface_redistribute]]
*#*[[surface_redistribute]]
*#**[[redistribute_surface]] redistribute the triangulation using mid-edge insertion or edge collapse
*#***[[tri_status]]
*#***[[Tri_on_side]]
*#***[[PointArrayRing2]]
*#**#[[insert_point_in_tri_side]]
*#**#[[delete_min_side_of_tri]]



{{{
struct _SURFACE
{
	int _boundary;		/* Mandatory first element,  see notes on
				 *  boundary macros below */
	struct _SURFACE *obj;	/* refers back to surface, see boundary macro */
	struct _HYPER_SURF *hs;

	/* Topological Part */

	struct _INTERFACE *interface;

	/*
	 * SURFACE BOUNDARIES.  The boundary of a surface consists of
	 * a set of curves gathered into two classes,  pos_curves and
	 * neg_curves.  A given curve is defined as positive with respect
	 * the surface if its orientation agrees with that of the adjoining
	 * triangles that connect the curve to the surface, negative otherwise.
	 * Triangles are assumed to be oriented in a counter clockwise manner
	 * where observed from the side into which the normal vector points.
	 * Thus if the vertices of a triangle are p[0], p[1], p[2], then the
	 * normal has direction given by the vector cross product
	 * (p[1] - p[0])X(p[2] - p[0]).
	 * This means that a curve is positive with respect to a surface if
	 * each bond on that curve statisfies bond->start = p[i] and
	 * bond->end = p[(i+1)%3] for the triangle connected to that bond.
	 * Similarlly the curve is negative if bond->start = p[i] and
	 * bond->end = p[(i-1)%3].  It is assumed that all triangles on
	 * a surface are oriented consistently.
	 */

	struct _CURVE **pos_curves;	/* pos orient curves in bdry */
	struct _CURVE **neg_curves;	/* neg orient curves in bdry */

	int number;
	int redist_order;

	struct _C_CURVE **c_curves;	/* c_curves on surface */

	TRI_LIST_HEAD _First_tri;
	struct _TRI  _Last_tri;

	/* Representation Specific Part */

	int num_tri;
};
}}}
by [[Duo Wang|http://www.ams.sunysb.edu/~duowang/]]
~FronTier Notes               
src/front/fdecs.h
{{{
#define Redistribution_info(fr)	(fr)->Redist
#define	Surface_redistribution_info(fr)	Redistribution_info(fr).Surface_redist

#define Surface_redistribution_function(fr)				\
	(Surface_redistribution_info(fr).surface_redist_func)

#define Surface_redistribute(fr,force)					\
	((Surface_redistribution_function(fr) != NULL) ?		\
			(*Surface_redistribution_function(fr))(fr,force) : YES)
}}}
src/intfc/table.h
{{{
struct Table {
	struct Table 	*next; 		/* Pointer to Next Table */
	struct Table 	*prev; 		/* Pointer to Previous Table */
	struct Chunk 	*first_chunk;	/* List of Allocated Chunks */
	struct Chunk	*last_chunk;	
	struct Chunk    *big_chunks;    /* Oversized chunks */
	ALIGN		*top;		/* Low Free location in Top Chunk */
	size_t		_ChunkSize;	/* Size of interface chunks in ALIGNS*/
	size_t		remainder;	/* Space left in Top Chunk in ALIGNS */
	int		num_chunks;	/* Number of allocated chunks */

	INTERFACE 	*interface;	/* The Associated Interface */

			/* Quantities used by component(): */

	RECT_GRID 	rect_grid;	/* Regular Rectangular Grid */
	bool		fixed_grid;	/* Fixed Grid supplied Previously */
	bool		new_grid;	/* Flags a change of grid. */
	COMPONENT	max_comp;	/* Largest COMPONENT value */
	COMPONENT	min_comp;	/* Smallest COMPONENT value */
	COMPONENT	ext_comp;	/* Exterior COMPONENT value */
	int		max_pp_indx;	/* Largest pp_index */

			/* Interface-rect_grid structure */
	int		n_crx;
	int		n_segs;
	int             *seg_crx_count;
        int             **seg_crx_lists;
        int             *seg_crx_lists_store;
        CRXING          *crx_store;
	COMPONENT       *components;
	COMPONENT       *cg_comps;

	int     *edge_flag;
        int     n_curve_crx;
        int     *curve_crx_count;
        int     **curve_crx_lists;
        int     *curve_crx_lists_store;
        CRXING  *curve_crx_store;
        int     *curve_crx_type;

	/* ONED */
	COMPONENT       *compon1d;        /* COMPONENT in each Grid Block */
	int             *num_of_points; /* Number POINTS in each Grid zone */
	POINT           ***pts_in_zone; /* points in each zone */
	/* TWOD */
	COMPONENT	**compon2d;	/* COMPONENT in each Grid Block */
	int		**num_of_bonds;	/* Number BONDS in each Grid Block */
	BOND		****bonds;	/* BOND lists in each Grid Block */
	CURVE		****curves;	/* CURVE lists in each Grid Block */

			/* Quantities used by loc_comp_list: */
	
	BOND		**bondstore;	/* Storage for BOND Lists */
	CURVE		**curvestore;	/* Storage for CURVE Lists */

	/* THREED */
	COMPONENT	***compon3d;	/* COMPONENT in each Grid Block */
	int		***num_of_tris;	/* Number TRIS in each Grid Block */
	TRI		*****tris;	/* TRI lists in each Grid Block */
	SURFACE		*****surfaces;	/* SURFACE lists in each Grid Block */
	double		***area;	/* Surface area in each Grid Block */
	double		***vol_frac;	/* Volume frac in each Grid Block */

			/* Quantities used by loc_comp_list: */
	
	TRI		**tristore;	/* Storage for TRI Lists */
	SURFACE		**surfacestore;	/* Storage for SURFACE Lists */

			/* Quantities used by next_point(): */
	POINT		**cur_point;
	NODE		**cur_node;	/* Current NODE for next_point() */
	CURVE		**cur_curve;	/* Current CURVE for next_point() */
	BOND		*cur_bond;	/* Current BOND for next_point() */
	TRI		*cur_tri;
	SURFACE		**cur_surface;
	int		np_do_p_curs;	/* Used by next_point3d() */
	int		np_do_n_curs;	/* Used by next_point3d() */

	/* This part is for elliptic solver */
	RECT_GRID	aug_comp_grid;
	BLK_EDGE	**blk_edge;
	int       	n_c_crx;         
	int       	n_c_segs;
	int		*c_seg_crx_count;
	int		**c_seg_crx_lists;
	CRXING		*c_crx_store;
	COMPONENT	*c_components;
	COMPONENT	*c_cg_comps;  /* On aug_comp_grid  */
	TG_PT     	*c_node_points,*c_cg_npts;
	int c_nnx,c_nny,c_nnz; 	 /* Number of nodes on aug_comp_grid */
	int c_node_offset;       /* same meaning as node_offset, on */
				 /* aug_comp_grid */
        int c_cell_offset;       /* same meaning as cell_offset, on */
				 /* aug_comp_grid */
	int       n_c_node_points;
	int	  n_c_tg_pts;
	int	  n_c_fr_pts;
	int       n_c_reg_nodes;       /* count on aug_comp_grid,
                                      * same meaning as n_node_points, etc.. */
	int       *c_seg_crx_lists_store;
	int       *blk_type;
	/* End part for elliptic solver */

	bool         _no_topology_lists;/*Disables topology construction*/
};
}}}
src/intfc/int.h
{{{
struct _TRI
{
	POINT *__pts[3];
	/* object adj to edge ij */
	TRI_NEIGHBOR neighbor[3];
	struct _SURFACE	*surf;		/* surface in which the triangle lies */
	struct _TRI *prev;
	struct _TRI *next;
	int boundary;		/* tri bonds on interface curves? */
	int order;		/* used as an identification for a tri, avoid 
				   the conflict with _index in private_data. */
	union
	{
	    int		   _index;
	    POINTER 	   _workspace;
	    struct _C_BOND **_tri_cross_list;
	    int		   _icoords[3];
	    bool           _projection_computed;
	    bool	   _modified;
	    /* The following is used in ellip for 3d tetrahedral mesh */
	    struct
            {
                char c0;
                char c1;
                char c2;
                char c3;
            } c;
	} private_data;
};
}}}
src/intfc/int.h
{{{
#define	Tri_on_side(_tri_,side)	     ((Tri_neighbor(_tri_) + (side))->tri)
}}}
src/front/fdecs.h
{{{
struct _VELO_FUNC_PACK {
        int (*func)(POINTER,Front*,POINT*,HYPER_SURF_ELEMENT*,
                        HYPER_SURF*,double*);
	void (*point_propagate)(struct _Front*,POINTER,POINT*,POINT*,
                        HYPER_SURF_ELEMENT*,HYPER_SURF*,double,double*);
        POINTER func_params;
};
typedef struct _VELO_FUNC_PACK VELO_FUNC_PACK;
}}}
src/front/fgb3dutil.c
{{{
EXPORT	void adjust_crossings(
	int      *smin,
	int      *smax,
	INTERFACE *intfc)
{
	RECT_GRID      *gr = &topological_grid(intfc);
	int 	       ix,iy,iz;
	GRID_DIRECTION dir[3] = {EAST,NORTH,UPPER};
	int 	       ip[3],i,j,k,l,m,nc,list1;
	CRXING 	       *crx1;
	float 	       grid_crds;
	float 	       *L = gr->L;
	float 	       *h = gr->h;
	Table	       *T = table_of_interface(intfc);
	int		*gmax = gr->gmax;

	for (iz = smin[2]; iz <= smax[2]; ++iz)
	{
	    ip[2] = iz;
	    for (iy = smin[1]; iy <= smax[1]; ++iy)
	    {
	        ip[1] = iy;
	        for (ix = smin[0]; ix <= smax[0]; ++ix)
	        {
	            ip[0] = ix;
	            for (i = 0; i < 3; ++i)
	            {
	                if (ix == smax[0] && dir[i] == EAST)
	                    continue;
	                if (iy == smax[1] && dir[i] == NORTH)
	                    continue;
	                if (iz == smax[2] && dir[i] == UPPER)
	                    continue;
	                k = seg_index3d(ix,iy,iz,dir[i],gmax);
	                nc = T->seg_crx_count[k];
			if (nc != 0)
			{
	                    list1 = T->seg_crx_lists[k][0];
	                    crx1 = T->crx_store+list1;
	                    grid_crds = L[i] + ip[i]*h[i];

			    /*
			    if( (ip[0] == 13 && ip[1] == 11 && ip[2] == 42 && dir[i] == NORTH) ) 
			    {
				add_to_debug("tst_crx");
				for (j = 0; j < nc; j++)
				    print_general_vector("bf_adj=", Coords(crx1[j].pt), 3, "\n");
			    }
			    */

			    adjust_for_min_spacing(crx1,grid_crds,h,nc,i);

			    /*
			    if(debugging("tst_crx"))
			    {
				for (j = 0; j < nc; j++)
				    print_general_vector("af_adj=", Coords(crx1[j].pt), 3, "\n");
				remove_from_debug("tst_crx");
			    }
			    */

			} 
	            }
	        }
	    }
	}
}		/*end adjust_crossings */
}}}
src/front/fgb3dutil.c
{{{
LOCAL void adjust_for_min_spacing(
	CRXING		*crxings,
	float		crds_start,
	float		*h,
	int		n_crx,
	int		dir)
{
	int	i;
	float	crds_end;
	float	mgs = 0.004*h[dir];/*TOLERANCE*/
	float   pmin, pmax;
	float   ps=HUGE, pe=-HUGE, nps, npe, m, b;

	crds_end = crds_start + h[dir];
	pmin = crds_start + mgs;
	pmax = crds_end - mgs;
	for (i = 0; i < n_crx; i++)
	{
	      ps = min(Coords(crxings[i].pt)[dir],ps);
	      pe = max(Coords(crxings[i].pt)[dir],pe);
	}
	if ((pmin <= ps) && (pe <= pmax))
	    return;
	if (n_crx == 1)
	{
	    if (ps <= pmin)
	        Coords(crxings[0].pt)[dir] = pmin;
	    if (pe >= pmax)
	        Coords(crxings[0].pt)[dir] = pmax;
	    return;
	}
	nps = (pmax - pmin)/h[dir];

	b = Coords(crxings[0].pt)[dir];
	if (pe <= pmin)
	{
	    for (i = 0; i < n_crx; i++)
		Coords(crxings[i].pt)[dir] = pmin + nps*(Coords(crxings[i].pt)[dir] - b);
	    return;
	}

	b = Coords(crxings[n_crx-1].pt)[dir];
	if (ps >= pmax)
	{
	    for (i = 0; i < n_crx; i++)
		Coords(crxings[i].pt)[dir] = pmax - nps*(b - Coords(crxings[i].pt)[dir]);
	    return;
	}
	
	nps = max(ps,pmin);
	npe = min(pe,pmax);
	m = (npe - nps)/(pe - ps);
	b = (nps*pe - npe*ps)/(pe - ps);
	for (i = 0; i < n_crx; ++i)
	{    
	    Coords(crxings[i].pt)[dir] = m*Coords(crxings[i].pt)[dir] + b;
	}
}		/*end adjust_for_min_spacing*/
}}}
src/front/fdecs.h
{{{
#define advance_front(dt,dt_frac,front,newfront,wave)			\
	(*(front)->_advance_front)(dt,dt_frac,front,newfront,wave)
}}}
src/front/fadv.c
{{{
 int advance_front2d(
	float    dt,
	float    *dt_frac,
	Front    *front,
	Front    **newfront,
	POINTER  wave)
{
	CURVE      *oldc,*tempc,*newc;
	CURVE	   **c;
	INTERFACE  *tempintfc;
	NODE 	   *oldn,*tempn,*newn;
	NODE_FLAG  flag;
	RPROBLEM   *rp;
	RPROBLEM   *rp1;
	bool	   scatter_normally_propagated_front = YES;
	bool	   scatter_tangentially_propagated_front = YES;
	bool	   stat;
	bool       do_redist;
	int        status;
	long       intfc_modified;
	long       redo_advance_front;
	static const char *fname = "advance_front2d()";
	int	   debug_flag = NO;

	debug_print("front","Entered %s(step %d time %g dt %g)\n",fname,
	        	        front->step,front->time,dt);
	debug_front("old_front","into advance front",front);

	*newfront = copy_front(front);
	Interface_redistributed(*newfront) = NO;
	do_redist = (front->num_mts == 0) ? YES : NO;

begin_advance_front2d:
	redo_advance_front = 0;
	tempintfc = NULL;
	rp = NULL;
	set_to_next_node_only(flag);

	set_node_doubly_linked_list(front->interf);

	        /* Initialize Newfront */

	start_clock("init_new_front");
	capture_waves(front);
	print_storage("before init_new_front","ADV_storage");
	        /* TODO: Remove this option!!!!! */
	if (front->init_topology_of_new_interface)
	    status = (*front->init_topology_of_new_interface)(front,*newfront);
	else 
	{
	    set_size_of_intfc_state(size_of_state(front->interf));
	    set_copy_intfc_states(NO);
	    set_add_to_correspond_list(YES);
	    (*newfront)->interf = pp_copy_interface(front->interf);
	    reset_hs_flags_on_intfc((*newfront)->interf);
	    status = ((*newfront)->interf != NULL) ? GOOD_STEP : ERROR_IN_STEP;
	    set_copy_intfc_states(YES);
	}
	if (front->pp_grid)
	    status = syncronize_time_step_status(status,front->pp_grid);
	if (status != GOOD_STEP) 
	{
	    (void) printf("WARNING in advance_front2d(), "
	                  "unable to copy interface\n");
	    status = ERROR_IN_STEP;
	    stop_clock("init_new_front");
	    return return_advance_front(front,newfront,status,fname);
	}
	print_storage("after init_new_front","ADV_storage");
	stop_clock("init_new_front");

	        /* Set Default Propagation Limits */

	set_propagation_limits(front,*newfront);

	        /* Propagate the Curves */

	if (front->curve_propagate != NULL) 
	{
	    start_clock("curve_propagate");
	    if (debugging("front"))
	    	(void) printf("Loop over Curves\n");
	    for (c = front->interf->curves; c && *c; ++c) /* advance different curve parts */ 
	    {
	        oldc = *c;
	        if (((newc = correspond_curve(oldc)) != NULL) &&
	    	     (correspond_curve(newc) != NULL))
	        {
	    	    if (debugging("propagate"))
	                (void) printf("\t\tpropagating curve %llu\n",
		                      curve_number(oldc));
		    curve_propagate(front,wave,oldc,newc,dt);
		    //f_curve_propagate2d
		}
	    }
	    debug_front("cp_front","after curve prop",*newfront);
	    stop_clock("curve_propagate");
	}

		/* Propagate the Nodes */

	if (debugging("front"))
	{
	    print_correspond_hyper_surf_list(front->interf);
	    print_correspond_hyper_surf_list((*newfront)->interf);
	}
	if (front->node_propagate != NULL) 
	{
	    start_clock("node_propagate");
	    set_corresponds_for_node_prop(front->interf,(*newfront)->interf);
	    oldn = first_node(front->interf);
	    while (oldn != NULL) 
	    {
	        newn = correspond_node(oldn);
	        if (debugging("crx_status"))
	            print_linked_node_list((*newfront)->interf);
	        status = (newn != NULL) ?
	            (*front->node_propagate)(front,wave,oldn,newn,&rp,
	        			     dt,dt_frac,flag,NULL) : GOOD_NODE;

	        if (debugging("crx_status"))
	        if (is_bad_status(status) &&
	          (point_in_buffer(Coords(oldn->posn),front->rect_grid) == YES))
	        {
	            print_node_status("WARNING in advance_front2d(), "
	                              "node_propagation returns ",status,"\n");
	            (void) printf("Problem occurs in buffer zone - ignoring\n");
	            if (set_node_states_and_continue(oldn,newn,front))
	                status = GOOD_NODE;
	        }

	        switch (status) 
	        {
	        case GOOD_NODE:
	            oldn = adv_node_loop_after_good_prop(oldn,newn,&rp);
	            break;
	        case PSEUDOCROSS_NODE_NODE:
	            debug_print("PSEUDOCROSS","PSEUDOCROSS case\n");
	            oldn = reorder_node_loop(oldn,newn);
	            break;
	        case CROSS_NODE_NODE:
	        case BIFURCATION_NODE:
	            debug_print("CROSS","CROSS case\n");
	            oldn = next_node(oldn);
	            break;
	        case CROSS_PAST_CURVE_NODE:
	            print_node_status("WARNING in advance_front2d(), "
	                              "node_propagate failed with status ",
				      status,"\n");
	            print_node(oldn);
	            if (debugging("CROSS_PAST"))
	            {
	                (void) printf("Cross past curve case\n"
	                              "dt_frac = %g\n",*dt_frac);
	                (void) printf("Reducing time step\n");
	            }
		    status = node_modify_time_step(oldn,front,dt_frac,
					           MODIFY_TIME_STEP);
	            free_rp_list(&rp);
	            goto sync_prop_stat1;
	        case MODIFY_TIME_STEP_NODE:
	            (void) printf("WARNING in advance_front2d(), "
	                          "node_propagate returns "
	                          "MODIFY_TIME_STEP_NODE\n");
	            free_rp_list(&rp);
		    status = node_modify_time_step(oldn,front,NULL,
						   MODIFY_TIME_STEP);
	            goto sync_prop_stat1;
	        case REPEAT_TIME_STEP_NODE:
	            (void) printf("WARNING in advance_front2d(), "
	                          "node_propagate returns "
	                          "REPEAT_TIME_STEP_NODE\n");
	            free_rp_list(&rp);
		    status = node_modify_time_step(oldn,front,NULL,
					           REPEAT_TIME_STEP);
	            goto sync_prop_stat1;
	        case NO_CROSS_NODE:
	            print_node_status("WARNING in advance_front2d(), "
	                              "node_propagate failed with status ",
	                              status,"\n");
	            print_node(oldn);
	            if (debugging("NO_CROSS"))
	            {
	                (void) printf("No cross case\n");
	                (void) printf("dt_frac = %g\n",*dt_frac);
	                (void) printf("Reducing time step\n");
	            }
	            free_rp_list(&rp);
		    status = node_modify_time_step(oldn,front,dt_frac,
					           MODIFY_TIME_STEP);
	            goto sync_prop_stat1;
	        case ERROR_NODE:
	        default:
	            print_node_status("WARNING in advance_front2d(), "
	                              "node_propagate failed with status ",
	                              status,"\n");
	            print_node(oldn);
	            if (debugging("ERROR_NODE"))
	            {
	                (void) printf("Old interface:\n");
	                print_interface(front->interf);
	                print_correspond_hyper_surf_list(front->interf);
	                (void) printf("New interface:\n");
	                print_interface((*newfront)->interf);
	                print_correspond_hyper_surf_list((*newfront)->interf);
	            }
		    status = node_modify_time_step(oldn,front,dt_frac,
					           ERROR_IN_STEP);
	            free_rp_list(&rp);
	            goto sync_prop_stat1;
	        }
	    } /* end of while (oldn != NULL) */
	    set_correspond_hyper_surf_bdrys_to_NULL(front->interf);
	    set_correspond_hyper_surf_bdrys_to_NULL((*newfront)->interf);
	    if (rp && (front->twodrproblem != NULL)) 
	    {
	        for (rp1 = rp; rp1; rp1 = rp1->prev) 
	        {
	            debug_front("2drp_front",
	                "new between node loop and rp loop",*newfront);
	                    
	            status = (*front->twodrproblem)(front,*newfront,wave,&rp1);

	            /* At this point, rp is nothing more than a valid element
	             * of the list which provides a starting point
	             * for deleting the list.  If we delete an element of
	             * the list in front->twodrproblem (presumably due to
	             * merging two RPROBLEM's), then rp may point to freed
	             * storage and will need to be updated.  rp1 should still
	             * be a valid element of the list.
	             */
	            rp = rp1;

		    if (status != GOOD_STEP)
		    {
	                print_time_step_status("WARNING in advance_front2d(), "
					       "rp failed with status = ",
					       status,"\n");
	                switch (status) 
	                {
	                case GOOD_STEP:
			    break;

		        case REPEAT_TIME_STEP:
	                    break;

	                case MODIFY_TIME_STEP:
		            status = rp_modify_time_step(rp1,front,status);
			    if (status == MODIFY_TIME_STEP)
			    {
	                        *dt_frac = rp1->dt_frac;
	                        if (debugging("2drp"))
	                        {
	                            print_rproblem(rp1);
	                            (void) printf("dt_frac %g\n",*dt_frac);
	                            (void) printf("Reducing time step\n");
	                        }
			        *dt_frac = limit_dt_frac(*dt_frac,front);
			    }
	                    break;

	                case ERROR_IN_STEP:
	                default:
	                    print_rproblem(rp1);
	                    /* Try reducing the time step */
		            status = rp_modify_time_step(rp1,front,status);
	                    if (status == MODIFY_TIME_STEP)
	                        *dt_frac *=
				    TIME_STEP_REDUCTION_FACTOR(front->interf);
	                    break;
	                }
		    }
	            if (status != GOOD_STEP)
			break;
	        }
	        free_rp_list(&rp);
	        debug_front("2drp_front","after 2drp loop",*newfront);
	    }
	    else if (rp) 
	    {
	        for (rp1 = rp; rp1; rp1 = rp1->prev) 
	            print_rproblem(rp1);
	        free_rp_list(&rp);
	        (void) printf("WARNING in advance_front2d(), "
	                      "CROSS code needed\n");
	        status = ERROR_IN_STEP;
	    }

sync_prop_stat1:
	    stop_clock("node_propagate");
	    if (front->pp_grid)
	    	status = syncronize_time_step_status(status,front->pp_grid);
	    if (status != GOOD_STEP)
	        return return_advance_front(front,newfront,status,fname);
	}

	stat = consistent_propagated_loop_orientations(dt,dt_frac,front,wave);
	if (stat == NO)
	{
	    (void) printf("WARNING in advance_front2d(), "
		          "Inconsistent orientation of propagated loop "
	                  "detected after point and node propagations");
	    if (pp_numnodes() > 1)
		(void) printf(" on processor %d\n",pp_mynode());
	    else
		(void) printf("\n");
	}
	if (pp_min_status(stat) == NO)
	{
	    if (stat == YES)
	    {
	        (void) printf("WARNING in advance_front2d(), "
		              "Inconsistent orientation of propagated loop "
	                      "detected on a remote processor "
			      "after point and node propagations ");
	    }
	    status = MODIFY_TIME_STEP;
	    goto sync_prop_stat2;
	}

	/* Make Temp Interface for Tangential Propagation */

	set_node_doubly_linked_list((*newfront)->interf);
	if (front->snd_node_propagate) 
	{
	    start_clock("snd_copy_interface");
	    print_storage("before snd_copy_interface","ADV_storage");
	    tempintfc = (*newfront)->interf;
	    set_size_of_intfc_state(size_of_state(tempintfc));
	    set_add_to_correspond_list(YES);
	    if (((*newfront)->interf = pp_copy_interface(tempintfc)) == NULL)
	    {
	    	(void) printf("WARNING in advance_front2d(), "
		              "unable to copy interface\n");
		status = ERROR_IN_STEP;
		goto sync_prop_stat2;
	    }
	    copy_hypersurface_flags((*newfront)->interf);
	    interpolate_intfc_states((*newfront)->interf) = YES;
	    print_storage("after snd_copy_interface","ADV_storage");
	    stop_clock("snd_copy_interface");
	}

	/* Second Propagation for the States Around the Nodes */

	if (front->snd_node_propagate) 
	{
	    start_clock("snd_node_propagate");
	    if (debugging("front"))
	    	(void) printf("Second Loop over Nodes\n");

	    tempn = first_node(tempintfc);
	    newn = first_node((*newfront)->interf);
	    while (newn != NULL)
	    {
	    	(*front->snd_node_propagate)(front,*newfront,wave,
	    				     tempintfc,tempn,newn,dt);
	    	tempn = next_node(tempn);
	    	newn = next_node(newn);
	    }

	    debug_front("snd_front","after snd_node prop",*newfront);
	    stop_clock("snd_node_propagate");
	}

	if (tempintfc)
	    (void) delete_interface(tempintfc);
	print_storage("after delete tempintfc","ADV_storage");

		/* Redistribute the New Front */

	switch (redistribute(*newfront,do_redist,NO)) 
	{
	case	GOOD_REDISTRIBUTION:
	    status = GOOD_STEP;
	    break;
	
	case	UNABLE_TO_UNTANGLE:
	    (void) printf("WARNING in advance_front2d(), "
	                  "redistribution of front failed\n"
	                  "Restarting advance_front2d()\n");
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    break;

	case	MODIFY_TIME_STEP_REDISTRIBUTE:
	    (void) printf("WARNING in advance_front2d(), "
	                  "redistribute returns\n"
	                  "\t\tMODIFY_TIME_STEP_REDISTRIBUTE, dt_frac = %g\n",
			  *dt_frac);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    break;
		
	case	BAD_REDISTRIBUTION:
	default:
	    (void) printf("WARNING in advance_front2d(), "
	                  "redistribution of front failed\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    break;
	}
	if (front->pp_grid)
	    status = syncronize_time_step_status(status,front->pp_grid);
	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);

	Redistribution_count(front) = Redistribution_count(*newfront);
	(*newfront)->step = front->step + 1;
	(*newfront)->time = front->time + dt;
	debug_front("redist_front","after redistribution",*newfront);


	/* Communicate topologically propagated front */
	if (scatter_normally_propagated_front == YES)
	{
	    start_clock("scatter_front");
	    if (!scatter_front(*newfront))
	    {
	    	(void) printf("WARNING in advance_front2d(), "
	    	              "scatter_front() failed for "
	    	              "normally propagated front\n");
	    	scatter_normally_propagated_front = NO;
	    	scatter_tangentially_propagated_front = NO;
	    	(void) delete_interface((*newfront)->interf);
	    	(*newfront)->interf = NULL;
	    	goto begin_advance_front2d;
	    }
	    stop_clock("scatter_front");
	}

	debug_front("node_front","after node loop",*newfront);
	if (debugging("front"))
	{
	    print_correspond_hyper_surf_list(front->interf);
	    print_correspond_hyper_surf_list((*newfront)->interf);
	}

	if (front->mass_consv_diagn_driver)
	    (*front->mass_consv_diagn_driver)(front,wave,dt);

	if (debugging("bond_lengths"))
	    check_bond_lengths((*newfront)->interf);

	/* Check for the geometric orientation of loops */

	/* ONLY check loops that will not be deleted !!!! */
	delete_small_loops(*newfront);

		/* Delete non-boundary curves that lie  */
		/* fully on or exterior to the boundary */

	delete_exterior_curves(*newfront,front->interf);
	debug_front("dec_front","after delete_exterior_curves:",*newfront);

	interpolate_intfc_states((*newfront)->interf) = YES;

	/* Make Temp Interface for Tangential Propagation */

	if (front->tan_curve_propagate) 
	{
	    start_clock("snd_copy_interface");
	    print_storage("before snd_copy_interface","ADV_storage");
	    tempintfc = (*newfront)->interf;
	    set_size_of_intfc_state(size_of_state(tempintfc));
	    set_add_to_correspond_list(YES);
	    if (((*newfront)->interf = pp_copy_interface(tempintfc)) == NULL)
	    {
	    	(void) printf("WARNING in advance_front2d(), "
		              "unable to copy interface\n");
		status = ERROR_IN_STEP;
		goto sync_prop_stat2;
	    }
	    copy_hypersurface_flags((*newfront)->interf);
	    interpolate_intfc_states((*newfront)->interf) = YES;
	    print_storage("after snd_copy_interface","ADV_storage");
	    stop_clock("snd_copy_interface");
	}

	/* Tangential Sweep for States on the Curves */

	if (front->tan_curve_propagate) 
	{
	    start_clock("tan_curve_propagate");
	    if (debugging("front"))
	    	(void) printf("Second Loop over Curves\n");
	    for (c = tempintfc->curves; c && *c; ++c)
	    {
	    	tempc = *c;
	    	newc = correspond_curve(tempc);
	    	(*front->tan_curve_propagate)(front,*newfront,
	    				      tempintfc,tempc,newc,dt);
	    }
	    debug_front("tcp_front","after tan_curve_propagate:",*newfront);
	    stop_clock("tan_curve_propagate");
	}

	if (tempintfc)
	    (void) delete_interface(tempintfc);
	print_storage("after delete tempintfc","ADV_storage");


		/* Provide robustness for untangle algorithms */

		/*   delete remnants of scalar physical   */
		/*  curves sticking to NEUMANN boundaries */
		/* Add to delete_exterior_curves()? */

	if (pp_min_status(delete_phys_remn_on_bdry(*newfront)) == NO)
	{
	    (void) printf("WARNING in advance_front2d(), "
	                  "delete_phys_remn_on_bdry() detected error\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    goto sync_prop_stat2;
	}
	debug_front("dspr_front",
		    "after 1st delete_phys_remn_on_bdry():",*newfront);

sync_prop_stat2:
	if (front->pp_grid)
	    status = syncronize_time_step_status(status,front->pp_grid);
	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);

	/* Communicate tangentially propagated front */
	if (scatter_tangentially_propagated_front == YES)
	{
	    start_clock("scatter_front");
	    if (!scatter_front(*newfront))
	    {
	    	(void) printf("WARNING in advance_front2d(), "
	    	              "scatter_front() failed for "
	    	              "tangentially propagated front\n");
	    	scatter_normally_propagated_front = NO;
	    	scatter_tangentially_propagated_front = NO;
	    	(void) delete_interface((*newfront)->interf);
	    	(*newfront)->interf = NULL;
	    	goto begin_advance_front2d;
	    }
	    stop_clock("scatter_front");
	}

	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);


		/* 	Post-process newfront->interf	   */
		/* Provide robustness after redistribution */
		/*   for node propagate on next time step  */

		/* Delete non-boundary curves that lie  */
		/* fully on or exterior to the boundary */

	delete_exterior_curves(*newfront,front->interf);
	debug_front("dec_front","after delete_exterior_curves:",*newfront);

		/*  delete remnants of scalar physical    */
		/* curves sticking to NEUMANN boundaries  */
		/* Add to delete_exterior_curves()? */

	if (pp_min_status(delete_phys_remn_on_bdry(*newfront)) == NO)
	{
	    (void) printf("WARNING in advance_front2d(), "
	                  "delete_phys_remn_on_bdry() detected error\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    return return_advance_front(front,newfront,status,fname);
	}
	debug_front("dspr_front",
		    "after 2nd delete_phys_remn_on_bdry():",*newfront);

	/* These guys keep sneaking through !! */
	/* This should be the most effective place for this call */
	/* Brent - I believe it is better to have the function at
	*  the end of advance_front2d() applied to the newfront
	*  instead of at the beginning applied to front.
	*  In general our policy should be never to modify the
	*  old interface data.
	*/
	delete_small_loops(*newfront);
	debug_front("dsloop_front","after delete_small_loops():",*newfront);

	test_for_mono_comp_curves((*newfront)->interf);

	/* Check if post processing has changed topology */

	intfc_modified = (*newfront)->interf->modified;
	pp_global_lmax(&intfc_modified,1L);
	if (intfc_modified)
	{
	    if (!scatter_front(*newfront))
	    {
	    	(void) printf("WARNING in advance_front2d(), "
	    	              "final scatter_front() failed\n");
	    	*dt_frac = Max_time_step_modification_factor(front);
	        return return_advance_front(front,newfront,
		                            MODIFY_TIME_STEP,fname);
	    }
	    stat = make_bond_comp_lists((*newfront)->interf);
	    if (pp_min_status(stat) == FUNCTION_FAILED)
	    {
	    	screen("ERROR in advance_front2d(), "
	    	       "make_bond_comp_lists() failed\n");
	    	clean_up(ERROR);
	    }
	}

	return return_advance_front(front,newfront,GOOD_STEP,fname);
}		/*end advance_front2d*/
}}}
src/front/fadv.c
{{{
LOCAL 	int 	advance_front3d_tracking_control(
	float	dt,
	float	*dt_frac,
	Front	*front,
	Front	**newfront,
	POINTER	wave)
{
	int step_status;

	DEBUG_ENTER(advance_front3d_tracking_control)

  	switch(Tracking_algorithm(front))
	{
	case NO_DYNAMIC_TRACKING:
	    step_status = GOOD_STEP;
	    break;

	case GRID_FREE_TRACKING:
	    step_status = preserve_front_advance_front3d(dt,dt_frac,front,
							 newfront,wave);
	    break;

	case GRID_BASED_TRACKING:
	    step_status = reconstruct_front_advance_front3d(dt,dt_frac,front,
						            newfront,wave);
	    break;
	
	case THREE_COMP_GRID_BASED_TRACKING:
	    step_status = reconstruct_front_advance_front3d(dt,dt_frac,front,
						            newfront,wave);
	    break;

	case MIXED_TRACKING:
	case LOCALLY_GRID_BASED_TRACKING:
	    step_status = mixed_advance_front3d(dt,dt_frac,front,
						newfront,wave);
	    break;

	case HYBRID_TRACKING:
	    step_status = hybrid_advance_front3d(dt,dt_frac,front,
						 newfront,wave);
	    break;

	default:
	    screen("ERROR in advance_front3d_tracking_control()\n"
		   "Unknown Tracking algorithm = %d\n",
		   Tracking_algorithm(front));
	    clean_up(ERROR);
	}
	if (step_status == GOOD_STEP)
            front->redis_flag = (*newfront)->redis_flag;
	else
	    front->redis_flag = NO;
	DEBUG_LEAVE(advance_front3d_tracking_control)
	return step_status;
}		/*end advance_front3d_tracking_control*/
}}}
src/intfc/igrid.c
{{{
LOCAL	double area_of_rect_grid(
	const RECT_GRID *rect_grid)
{
	double       area;
	const double *L = rect_grid->L, *U = rect_grid->U;
	int         i, dim = rect_grid->dim;

	area = -HUGE_VAL;
	switch (rect_grid->Remap.remap) 
	{
	case IDENTITY_REMAP:
	    area = U[0] - L[0];
	    for (i = 1; i < dim; ++i)
	    	area *= U[i] - L[i];
	    break;
	case CYLINDRICAL_REMAP:
	    if (L[0] < 0.0)
	        area = PI*(U[0]*U[0] + L[0]*L[0]);
	    else
	        area = PI*(U[0]+L[0])*(U[0]-L[0]);
	    for (i = 1; i < dim; ++i)
	    	area *= U[i] - L[i];
	    break;
	case SPHERICAL_REMAP:
	    area = 4.0/3.0*PI*(U[0]*U[0]*U[0] - L[0]*L[0]*L[0]);
	    break;
	default:
	    screen("ERROR in area_of_rect_grid(), "
	           "illegal or unavailable geometry\n");
	    clean_up(ERROR);
	}
	if (area <= 0.0)
	{
	    screen("ERROR in area_of_rect_grid(), "
	           "Nonpositive computational area\n");
	    (void) printf("dim = %d, remap = %d, area = %g\n",
	                  dim,rect_grid->Remap.remap,area);
	    if (1 <= dim && dim <= 3)
	    {
	        print_general_vector("L = ",L,dim,", ");
	        print_general_vector("U = ",U,dim,"\n");
	    }
	    else
	        (void) printf("Invalid dimension %d\n",dim);
	    clean_up(ERROR);
	}
	return area;
}		/*end area_of_rect_grid*/
}}}
src/front/fsub.c
{{{
/*
*			assign_front_interface():
*
*/

EXPORT void assign_front_interface(
	Front		*left,
	Front		*right)
{
	if (left != NULL)
	    (void) delete_interface(left->interf);

	left->interf = right->interf;
}		/*end assign_front_interface*/
}}}
src/front/fsub.c
{{{
/*
*
*			assign_interface_and_free_front():
*
*	Copies fr->interf into newfr->interf and then frees fr.
*/

EXPORT	void	assign_interface_and_free_front(
	Front		*newfr,
	Front		*fr)
{
	assign_front_interface(newfr,fr);
	fr->interf = NULL;
	free_front(fr);
}		/*end assign_interface_and_free_front*/
}}}
src/intfc/imksurf.c
{{{
/**********************************************************************
*	This function sets components for a two component domain      *
*	described by the rectangular grid gr, the side func < 0       *
*	will be ft_assigned neg_comp while the side func > 0 will be     *
*	ft_assigned pos_comp.   					      *
**********************************************************************/

LOCAL	void assign_two_comp_domain(
	double (*func)(POINTER,double*),
	POINTER func_params,
	COMPONENT ***comp,
	RECT_GRID gr,
	COMPONENT neg_comp,
	COMPONENT pos_comp)
{
	int i,j,k;
	int *gmax = gr.gmax;
	double *L = gr.L;
	double *h = gr.h;
	double coords[3];

	for (i = 0; i <= gmax[0]; ++i)
	{
	    coords[0] = L[0] + i*h[0];
	    for (j = 0; j <= gmax[1]; ++j)
	    {
	    	coords[1] = L[1] + j*h[1];
	    	for (k = 0; k <= gmax[2]; ++k)
		{
	    	    coords[2] = L[2] + k*h[2];
		    if (comp[i][j][k] != NO_COMP) continue;
		    if ((*func)(func_params,coords) > 0)
		    	comp[i][j][k] = pos_comp;
		    else 
		    	comp[i][j][k] = neg_comp;
		}
	    }
	}
}	/* end assign_two_comp_domain */
}}}
src/front/fgb3dutil.c
{{{
LOCAL	int check_and_unset_bad_comp(
	int      *smin,
	int      *smax,
	INTERFACE *intfc)
{
	RECT_GRID	gr = topological_grid(intfc);
	GRID_DIRECTION 	dir[6] = {WEST,EAST,SOUTH,NORTH,LOWER,UPPER};
	int 		ip[3],i,k,num_bad_nb;
	int		status = YES;
	int		*gmax = gr.gmax;
	Table		*T = table_of_interface(intfc);
	COMPONENT       *comp = T->components;
	int		*ef = T->edge_flag;
	bool		***unset;
	DEBUG_ENTER(check_and_unset_bad_comp)

	tri_array(&unset,gmax[0]+1,gmax[1]+1,gmax[2]+1,sizeof(bool));
	for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
	{
	    for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
	    {
	        for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
	        {
		    num_bad_nb = 0;
	            for (i = 0; i < 6; ++i)
	            {
	                if (ip[0] == smin[0] && dir[i] == WEST)
	                    continue;
	                if (ip[0] == smax[0] && dir[i] == EAST)
	                    continue;
	                if (ip[1] == smin[1] && dir[i] == SOUTH)
	                    continue;
	                if (ip[1] == smax[1] && dir[i] == NORTH)
	                    continue;
	                if (ip[2] == smin[2] && dir[i] == LOWER)
	                    continue;
	                if (ip[2] == smax[2] && dir[i] == UPPER)
	                    continue;
			
			k = seg_index3d(ip[0],ip[1],ip[2],dir[i],gmax);
			if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			    continue;

			if (unphysical_edge(ip,dir[i],intfc,smin,smax,MULTIPLE) 
					!= YES)
	                {
			    ++num_bad_nb;
			    status = NO;
	                }
	            }
		    if (num_bad_nb != 0)
		    	unset[ip[0]][ip[1]][ip[2]] = YES;
		    else
		    	unset[ip[0]][ip[1]][ip[2]] = NO;
	        }
	    }
	}
	if (status == YES)
	{
	    free_these(1,unset);
	    DEBUG_LEAVE(check_and_unset_bad_comp)
	    return status;
	}
	for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
	{
	    for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
	    {
	        for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
	        {
		    if (unset[ip[0]][ip[1]][ip[2]] == YES)
		    	comp[d_index3d(ip[0],ip[1],ip[2],gmax)] = NO_COMP;
	        }
	    }
	}
	free_these(1,unset);
	DEBUG_LEAVE(check_and_unset_bad_comp)
	return status;
}	/* end check_and_unset_bad_comp */
}}}
src/intfc/iredist.c
{{{
/*
*			closed_curve_node_redistribute():
*
*	A node on a closed curve never gets redistributed. With the
*	assumption that a node on a closed curve is more of a convenience
*	than an important point, this routine randomly changes the
*	position of the node on a closed curve each time redistribute
*	is called.
*/

EXPORT	bool closed_curve_node_redistribute(
	INTERFACE	*intfc,
	bool		status)
{
	BOND		*b;
	CURVE		**c;

#if defined(DEBUG_NODE_PROPAGATE)
        if (debugging("noCCNR"))
	    return status;
#endif /* defined(DEBUG_NODE_PROPAGATE) */
	for (c = intfc->curves; *c ; ++c)
	{
	    if (is_bdry(*c))
		continue;
	    if (!is_closed_curve(*c))
		continue;

			/* pick a random bond - any bond */

	    b = random_bond_on_curve(*c);
	    if (!move_closed_loop_node(*c,b))
		status = NO;
	}
	return status;
}		/*end closed_curve_node_redistribute*/
#endif /* defined(TWOD) */
}}}
src/front/fnode.c
{{{
EXPORT int closed_node_propagate(
	Front		*fr,
	POINTER		wave,
	NODE		*oldn,
	NODE		*newn,
	float		dt)
{
	CURVE		*oldc, *newc;
	POINT		*np;
	Locstate	lst, rst;
	float		V[MAXD];
	size_t 		szst = fr->sizest;
	int		i, dim = fr->interf->dim;

	debug_print("closed_node","Entered closed_node_propagate()\n");
#if defined(DEBUG_NODE_PROPAGATE)
	if (debugging("closed_node")) 
	{
	    (void) printf("\n\tOLD NODE:\n");
	    print_node(oldn);
	}
#endif /* defined(DEBUG_NODE_PROPAGATE) */

	oldc = oldn->out_curves[0];
#if defined(DEBUG_NODE_PROPAGATE)
	if (debugging("closed_node")) 
	{
	    (void) printf("\t\tOLD CURVE:\n");
	    print_curve(oldc);
	}
#endif /* defined(DEBUG_NODE_PROPAGATE) */

	np = newn->posn;
	oldn->posn->hse = Hyper_surf_element(oldc->first);
	oldn->posn->hs = Hyper_surf(oldc);
	point_propagate(fr,wave,oldn->posn,np,oldc->first,oldc,dt,V);

	newc = find_correspond_curve(oldc,newn,newn,fr,newn->interface);

	lst = left_state(np);		rst = right_state(np);
	ft_assign( left_start_state(newc),lst,szst);
	ft_assign(right_start_state(newc),rst,szst);
	ft_assign(   left_end_state(newc),lst,szst);
	ft_assign(  right_end_state(newc),rst,szst);

	set_bond_length(newc->first,dim);
	set_bond_length(newc->last,dim);

	propagation_status(newn) = PROPAGATED_NODE;

	    /* WARNING: Node_vel of closed nodes is undefined */
	for (i = 0; i < dim; ++i)
	    Node_vel(newn)[i] = ERROR_FLOAT;

#if defined(DEBUG_NODE_PROPAGATE)
	if (debugging("closed_node")) 
	{
	    (void) printf("\n\tNEW NODE:\n");
	    print_node(newn);
	    (void) printf("\t\tNEW CURVE:\n");
	    print_curve(newc);
	}
#endif /* defined(DEBUG_NODE_PROPAGATE) */
	debug_print("closed_node","Left closed_node_propagate()\n");
	return GOOD_NODE;
}		/*end closed_node_propagate*/
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::compDiffWithSmoothProperty(void)
{
	switch (dim)
        {
        case 2:
            //return compDiffWithSmoothProperty2d();
            return compDiffWithSmoothProperty2d_decoupled();
        case 3:
            //return compDiffWithSmoothProperty3d();
            return compDiffWithSmoothProperty3d_decoupled();
        }
}       /* end compDiffWithSmoothProperty */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::compDiffWithSmoothProperty2d_decoupled(void)
{
        int comp,index,index0,index1,index2,index3,index4,index5,
                size,coeffx,coeffy,coeffz;
        int I,I_nb[4];
        double coords[MAXD],coeff[4],mu[4],mu0,rho,corner[4],rhs;
        L_STATE state;
        int i,j,l,nb;
        INTERFACE *intfc = front->interf;
        double speed;
        double *x;

        setIndexMap();

        size = iupper - ilower;
        uni_array(&x,size,sizeof(double));

	for (l = 0; l < dim; ++l)
	{
            PETSc solver;
            solver.Create(ilower, iupper-1, 5, 0);

            for (j = jmin; j <= jmax; j++)
            for (i = imin; i <= imax; i++)
            {
            	I  = ij_to_I[i][j];
            	if (I == -1) continue;

            	index  = d_index2d(i,j,top_gmax);
            	index0 = d_index2d(i-1,j,top_gmax);
            	index1 = d_index2d(i+1,j,top_gmax);
            	index2 = d_index2d(i,j-1,top_gmax);
            	index3 = d_index2d(i,j+1,top_gmax);

            	I_nb[0] = ij_to_I[i-1][j];
            	I_nb[1] = ij_to_I[i+1][j];
            	I_nb[2] = ij_to_I[i][j-1];
            	I_nb[3] = ij_to_I[i][j+1];

            	for (nb = 0; nb < 4; nb++)
            	{
                    if (I_nb[nb] == -1)
                        corner[nb] = 0;
                    else
                    	corner[nb] = 1;
            	}
            	mu0   = cell_center[index].m_state.m_mu;
            	rho   = cell_center[index].m_state.m_rho;
            	mu[0] = 1.0/2 * (mu0 + cell_center[index0].m_state.m_mu);//left
            	mu[1] = 1.0/2 * (mu0 + cell_center[index1].m_state.m_mu);//right
            	mu[2] = 1.0/2 * (mu0 + cell_center[index2].m_state.m_mu);//down
            	mu[3] = 1.0/2 * (mu0 + cell_center[index3].m_state.m_mu);//up

            	coeff[0] = 0.5*m_dt/rho * mu[0]/(top_h[0]*top_h[0]);
            	coeff[1] = 0.5*m_dt/rho * mu[1]/(top_h[0]*top_h[0]);
            	coeff[2] = 0.5*m_dt/rho * mu[2]/(top_h[1]*top_h[1]);
            	coeff[3] = 0.5*m_dt/rho * mu[3]/(top_h[1]*top_h[1]);

            	getRectangleCenter(index, coords);
            	computeSourceTerm(coords, state);

        	//first equation
            	solver.Add_A(I,I,1+coeff[0]+coeff[1]+coeff[2]+coeff[3]);
            	solver.Add_A(I,I_nb[0],-coeff[0]*corner[0]);
            	solver.Add_A(I,I_nb[1],-coeff[1]*corner[1]);
            	solver.Add_A(I,I_nb[2],-coeff[2]*corner[2]);
            	solver.Add_A(I,I_nb[3],-coeff[3]*corner[3]);
            	rhs = m_dt*state.m_U[l];
            	rhs += (1-coeff[0]-coeff[1]-coeff[2]-coeff[3])
				*cell_center[index].m_state.m_U[l];
            	rhs += coeff[0]*cell_center[index0].m_state.m_U[l]*corner[0];
            	rhs += coeff[1]*cell_center[index1].m_state.m_U[l]*corner[1];
            	rhs += coeff[2]*cell_center[index2].m_state.m_U[l]*corner[2];
            	rhs += coeff[3]*cell_center[index3].m_state.m_U[l]*corner[3];

            	solver.Add_b(I, rhs);
            }

            solver.SetMaxIter(500);
            solver.SetTol(1e-6);
            solver.Solve();

            // get back the solution
            solver.Get_x(x);

            int num_iter;
            double rel_residual;
            solver.GetNumIterations(&num_iter);
            solver.GetFinalRelativeResidualNorm(&rel_residual);

            if (debugging("PETSc"))
                (void) printf("L_CARTESIAN::compDiffWithSmoothProperty: "
                        "num_iter = %d, rel_residual = %le. \n",
                        num_iter,rel_residual);

            for (j = jmin; j <= jmax; j++)
            for (i = imin; i <= imax; i++)
            {
                I = ij_to_I[i][j];
                index = d_index2d(i,j,top_gmax);
                if (I >= 0)
                {
                    cell_center[index].m_state.m_U[l] = x[I-ilower];
                }
                else
                {
                    cell_center[index].m_state.m_U[l] = 0.0;
                }
            }

            for (j = jmin; j <= jmax; j++)
            for (i = imin; i <= imax; i++)
            {
                index  = d_index2d(i,j,top_gmax);
                array[index] = cell_center[index].m_state.m_U[l];
            }
            scatMeshArray();
            for (j = 0; j <= top_gmax[1]; j++)
            for (i = 0; i <= top_gmax[0]; i++)
            {
                index  = d_index2d(i,j,top_gmax);
                cell_center[index].m_state.m_U[l] = array[index];
            }
        }
        for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
            speed = fabs(cell_center[index].m_state.m_U[0]) +
                    fabs(cell_center[index].m_state.m_U[1]);
            if (speed > max_speed)
                    max_speed = speed;
	}
        pp_global_max(&max_speed,1);

        free_these(1,x);
}       /* end compDiffWithSmoothProperty2d_decoupled */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::compDiffWithSmoothProperty3d_decoupled(void)
{
        int comp,index,index0,index1,index2,index3,index4,index5,
                size,coeffx,coeffy,coeffz;
        int I,I_nb[6];
        double coords[MAXD],coeff[6],mu[6],mu0,rho,corner[6],rhs;
        L_STATE state;
        int i,j,k,l,nb;
        INTERFACE *intfc = front->interf;
        double speed;
        double *x;

        setIndexMap();

        size = iupper - ilower;
        uni_array(&x,size,sizeof(double));

	for (l = 0; l < dim; ++l)
	{
            PETSc solver;
            solver.Create(ilower, iupper-1, 7, 0);

            for (k = kmin; k <= kmax; k++)
            for (j = jmin; j <= jmax; j++)
            for (i = imin; i <= imax; i++)
            {
            	I  = ijk_to_I[i][j][k];
            	if (I == -1) continue;

            	index  = d_index3d(i,j,k,top_gmax);
            	index0 = d_index3d(i-1,j,k,top_gmax);
            	index1 = d_index3d(i+1,j,k,top_gmax);
            	index2 = d_index3d(i,j-1,k,top_gmax);
            	index3 = d_index3d(i,j+1,k,top_gmax);
            	index4 = d_index3d(i,j,k-1,top_gmax);
            	index5 = d_index3d(i,j,k+1,top_gmax);

            	I_nb[0] = ijk_to_I[i-1][j][k];
            	I_nb[1] = ijk_to_I[i+1][j][k];
            	I_nb[2] = ijk_to_I[i][j-1][k];
            	I_nb[3] = ijk_to_I[i][j+1][k];
            	I_nb[4] = ijk_to_I[i][j][k-1];
            	I_nb[5] = ijk_to_I[i][j][k+1];

            	for (nb = 0; nb < 6; nb++)
            	{
                    if (I_nb[nb] == -1)
                        corner[nb] = 0;
                    else
                    	corner[nb] = 1;
            	}
            	mu0   = cell_center[index].m_state.m_mu;
            	rho   = cell_center[index].m_state.m_rho;
            	mu[0] = 1.0/2 * (mu0 + cell_center[index0].m_state.m_mu);//left
            	mu[1] = 1.0/2 * (mu0 + cell_center[index1].m_state.m_mu);//right
            	mu[2] = 1.0/2 * (mu0 + cell_center[index2].m_state.m_mu);//down
            	mu[3] = 1.0/2 * (mu0 + cell_center[index3].m_state.m_mu);//up
            	mu[4] = 1.0/2 * (mu0 + cell_center[index4].m_state.m_mu);//lower
            	mu[5] = 1.0/2 * (mu0 + cell_center[index5].m_state.m_mu);//upper

            	coeff[0] = 0.5*m_dt/rho * mu[0]/(top_h[0]*top_h[0]);
            	coeff[1] = 0.5*m_dt/rho * mu[1]/(top_h[0]*top_h[0]);
            	coeff[2] = 0.5*m_dt/rho * mu[2]/(top_h[1]*top_h[1]);
            	coeff[3] = 0.5*m_dt/rho * mu[3]/(top_h[1]*top_h[1]);
            	coeff[4] = 0.5*m_dt/rho * mu[4]/(top_h[2]*top_h[2]);
            	coeff[5] = 0.5*m_dt/rho * mu[5]/(top_h[2]*top_h[2]);

            	getRectangleCenter(index, coords);
            	computeSourceTerm(coords, state);

        	//first equation
            	solver.Add_A(I,I,1+coeff[0]+coeff[1]+coeff[2]+
                                        coeff[3]+coeff[4]+coeff[5]);
            	solver.Add_A(I,I_nb[0],-coeff[0]*corner[0]);
            	solver.Add_A(I,I_nb[1],-coeff[1]*corner[1]);
            	solver.Add_A(I,I_nb[2],-coeff[2]*corner[2]);
            	solver.Add_A(I,I_nb[3],-coeff[3]*corner[3]);
            	solver.Add_A(I,I_nb[4],-coeff[4]*corner[4]);
            	solver.Add_A(I,I_nb[5],-coeff[5]*corner[5]);
            	rhs = m_dt*state.m_U[l];
            	rhs += (1-coeff[0]-coeff[1]-coeff[2]-coeff[3]-coeff[4]-
				coeff[5])*cell_center[index].m_state.m_U[l];
            	rhs += coeff[0]*cell_center[index0].m_state.m_U[l]*corner[0];
            	rhs += coeff[1]*cell_center[index1].m_state.m_U[l]*corner[1];
            	rhs += coeff[2]*cell_center[index2].m_state.m_U[l]*corner[2];
            	rhs += coeff[3]*cell_center[index3].m_state.m_U[l]*corner[3];
            	rhs += coeff[4]*cell_center[index4].m_state.m_U[l]*corner[4];
            	rhs += coeff[5]*cell_center[index5].m_state.m_U[l]*corner[5];

            	solver.Add_b(I, rhs);
            }

            solver.SetMaxIter(500);
            solver.SetTol(1e-6);
            solver.Solve();

            // get back the solution
            solver.Get_x(x);

            int num_iter;
            double rel_residual;
            solver.GetNumIterations(&num_iter);
            solver.GetFinalRelativeResidualNorm(&rel_residual);

            if (debugging("PETSc"))
                (void) printf("L_CARTESIAN::compDiffWithSmoothProperty: "
                        "num_iter = %d, rel_residual = %le. \n",
                        num_iter,rel_residual);

            for (j = jmin; j <= jmax; j++)
            for (i = imin; i <= imax; i++)
            for (k = kmin; k <= kmax; k++)
            {
                I = ijk_to_I[i][j][k];
                index = d_index3d(i,j,k,top_gmax);
                if (I >= 0)
                {
                    cell_center[index].m_state.m_U[l] = x[I-ilower];
                }
                else
                {
                    cell_center[index].m_state.m_U[l] = 0.0;
                }
            }

            for (j = jmin; j <= jmax; j++)
            for (i = imin; i <= imax; i++)
            for (k = kmin; k <= kmax; k++)
            {
                index  = d_index3d(i,j,k,top_gmax);
                array[index] = cell_center[index].m_state.m_U[l];
            }
            scatMeshArray();
            for (j = 0; j <= top_gmax[1]; j++)
            for (i = 0; i <= top_gmax[0]; i++)
            for (k = 0; k <= top_gmax[2]; k++)
            {
                index  = d_index3d(i,j,k,top_gmax);
                cell_center[index].m_state.m_U[l] = array[index];
            }
        }
        for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
        for (k = kmin; k <= kmax; k++)
	{
            speed = fabs(cell_center[index].m_state.m_U[0]) +
                    fabs(cell_center[index].m_state.m_U[1]) +
                    fabs(cell_center[index].m_state.m_U[2]);
            if (speed > max_speed)
                    max_speed = speed;
	}
        pp_global_max(&max_speed,1);

        free_these(1,x);
}       /* end compDiffWithSmoothProperty3d_decoupled */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeAdvection(void)
{
	switch (dim)
	{
	case 2:
	    return computeAdvection2d();
	case 3:
	    return computeAdvection3d();
	}
}	/* end computeAdvection */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeAdvection2d(void)
{
	int i,j,k,index,index00,index01,index10,index11,size;
	L_STATE state;
	COMPONENT comp;
	double speed;
	double *u, *v;
	double u0,v0,u00,u01,u10,u11,v00,v01,v10,v11;
	double crx_coords[MAXD];
	int icoords[MAXD];

	size = (top_gmax[0]+1)*(top_gmax[1]+1);
	uni_array(&u,size,sizeof(double));
	uni_array(&v,size,sizeof(double));

	for (j = 0; j <= top_gmax[1]; j++)
	for (i = 0; i <= top_gmax[0]; i++)
	{
	    index = d_index2d(i,j,top_gmax);
	    u[index] = cell_center[index].m_state.m_U[0];
	    v[index] = cell_center[index].m_state.m_U[1];
	}

	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{	
	    icoords[0] = i;
	    icoords[1] = j;
	    index  = d_index2d(i,j,top_gmax);
	    comp = top_comp[index];
	    if (comp == SOLID_COMP)
	    {
	    	cell_center[index].m_state.m_U[0] = 0.0; 
	    	cell_center[index].m_state.m_U[1] = 0.0; 
		continue;
	    }
	    u0 = u[index];
	    v0 = v[index];
	    index00 = d_index2d(i-1,j,top_gmax);
	    if (liquid_comp(top_comp[index00]))
	    {
	        u00 = u[index00];
	        v00 = v[index00];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,WEST,comp,getStateXvel,
                                        &u00,crx_coords);
		FrontStateAtGridCrossing(front,icoords,WEST,comp,getStateYvel,
                                        &v00,crx_coords);
	    }
	    index01 = d_index2d(i+1,j,top_gmax);
	    if (liquid_comp(top_comp[index01]))
	    {
	    	u01 = u[index01];
	    	v01 = v[index01];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,EAST,comp,getStateXvel,
                                        &u01,crx_coords);
		FrontStateAtGridCrossing(front,icoords,EAST,comp,getStateYvel,
                                        &v01,crx_coords);
	    }
	    index10 = d_index2d(i,j-1,top_gmax);
	    if (liquid_comp(top_comp[index10]))
	    {
	    	u10 = u[index10];
	    	v10 = v[index10];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,SOUTH,comp,getStateXvel,
                                        &u10,crx_coords);
		FrontStateAtGridCrossing(front,icoords,SOUTH,comp,getStateYvel,
                                        &v10,crx_coords);
	    }
	    index11 = d_index2d(i,j+1,top_gmax);
	    if (liquid_comp(top_comp[index11]))
	    {
	    	u11 = u[index11];
	    	v11 = v[index11];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,NORTH,comp,getStateXvel,
                                        &u11,crx_coords);
		FrontStateAtGridCrossing(front,icoords,NORTH,comp,getStateYvel,
                                        &v11,crx_coords);
	    }

	    cell_center[index].m_state.m_U[0] += -m_dt*(
				burger_flux(u00,u0,u01)/top_h[0] +
				linear_flux(v0,u10,u0,u11)/top_h[1]);

	    cell_center[index].m_state.m_U[1] += - m_dt*(
				linear_flux(u0,v00,v0,v01)/top_h[0] +
			 	burger_flux(v10,v0,v11)/top_h[1]);

	    speed = fabs(cell_center[index].m_state.m_U[0]) +
		    fabs(cell_center[index].m_state.m_U[1]);
	    if (speed > max_speed)
		max_speed = speed;
	}
	for (k = 0; k < 2; ++k)
	{
	    for (j = jmin; j <= jmax; j++)
	    for (i = imin; i <= imax; i++)
	    {	
	    	index  = d_index2d(i,j,top_gmax);
	    	array[index] = cell_center[index].m_state.m_U[k];
	    }
	    scatMeshArray();
	    for (j = 0; j <= top_gmax[1]; j++)
	    for (i = 0; i <= top_gmax[0]; i++)
	    {	
	    	index  = d_index2d(i,j,top_gmax);
	    	cell_center[index].m_state.m_U[k] = array[index];
	    }
	}
	pp_global_max(&max_speed,1);
	free_these(2,u,v);
}	/* end computeAdvection2d */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeAdvection3d(void)
{
	int i,j,k,l;
	int index,index00,index01,index10,index11,index20,index21,size;
	L_STATE state;
	COMPONENT comp;
	double speed;
	double *u, *v, *w;
	double u0,u00,u01,u10,u11,u20,u21;
	double v0,v00,v01,v10,v11,v20,v21;
	double w0,w00,w01,w10,w11,w20,w21;
	double crx_coords[MAXD];
	int icoords[MAXD];

	size = (top_gmax[0]+1)*(top_gmax[1]+1)*(top_gmax[2]+1);
	uni_array(&u,size,sizeof(double));
	uni_array(&v,size,sizeof(double));
	uni_array(&w,size,sizeof(double));

	for (k = 0; k <= top_gmax[2]; k++)
	for (j = 0; j <= top_gmax[1]; j++)
	for (i = 0; i <= top_gmax[0]; i++)
	{
	    index = d_index3d(i,j,k,top_gmax);
	    u[index] = cell_center[index].m_state.m_U[0];
	    v[index] = cell_center[index].m_state.m_U[1];
	    w[index] = cell_center[index].m_state.m_U[2];
	}

	for (k = kmin; k <= kmax; k++)
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{	
	    icoords[0] = i;
	    icoords[1] = j;
	    icoords[2] = k;
	    index  = d_index3d(i,j,k,top_gmax);
	    comp = top_comp[index];
	    if (comp == SOLID_COMP)
	    {
	    	cell_center[index].m_state.m_U[0] = 0.0; 
	    	cell_center[index].m_state.m_U[1] = 0.0; 
	    	cell_center[index].m_state.m_U[2] = 0.0; 
		continue;
	    }
	    u0 = u[index];
	    v0 = v[index];
	    w0 = w[index];
	    // To continue
	    index00 = d_index3d(i-1,j,k,top_gmax);
	    if (liquid_comp(top_comp[index00]))
	    {
	        u00 = u[index00];
	        v00 = v[index00];
	        w00 = w[index00];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,WEST,comp,getStateXvel,
                                        &u00,crx_coords);
		FrontStateAtGridCrossing(front,icoords,WEST,comp,getStateYvel,
                                        &v00,crx_coords);
		FrontStateAtGridCrossing(front,icoords,WEST,comp,getStateZvel,
                                        &w00,crx_coords);
	    }
	    index01 = d_index3d(i+1,j,k,top_gmax);
	    if (liquid_comp(top_comp[index01]))
	    {
	    	u01 = u[index01];
	    	v01 = v[index01];
	    	w01 = w[index01];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,EAST,comp,getStateXvel,
                                        &u01,crx_coords);
		FrontStateAtGridCrossing(front,icoords,EAST,comp,getStateYvel,
                                        &v01,crx_coords);
		FrontStateAtGridCrossing(front,icoords,EAST,comp,getStateZvel,
                                        &w01,crx_coords);
	    }
	    index10 = d_index3d(i,j-1,k,top_gmax);
	    if (liquid_comp(top_comp[index10]))
	    {
	    	u10 = u[index10];
	    	v10 = v[index10];
	    	w10 = w[index10];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,SOUTH,comp,
				getStateXvel,&u10,crx_coords);
		FrontStateAtGridCrossing(front,icoords,SOUTH,comp,
				getStateYvel,&v10,crx_coords);
		FrontStateAtGridCrossing(front,icoords,SOUTH,comp,
				getStateZvel,&w10,crx_coords);
	    }
	    index11 = d_index3d(i,j+1,k,top_gmax);
	    if (liquid_comp(top_comp[index11]))
	    {
	    	u11 = u[index11];
	    	v11 = v[index11];
	    	w11 = w[index11];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,NORTH,comp,
				getStateXvel,&u11,crx_coords);
		FrontStateAtGridCrossing(front,icoords,NORTH,comp,
				getStateYvel,&v11,crx_coords);
		FrontStateAtGridCrossing(front,icoords,NORTH,comp,
				getStateZvel,&w11,crx_coords);
	    }
	    index20 = d_index3d(i,j,k-1,top_gmax);
	    if (liquid_comp(top_comp[index20]))
	    {
	    	u20 = u[index20];
	    	v20 = v[index20];
	    	w20 = w[index20];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,LOWER,comp,
				getStateXvel,&u20,crx_coords);
		FrontStateAtGridCrossing(front,icoords,LOWER,comp,
				getStateYvel,&v20,crx_coords);
		FrontStateAtGridCrossing(front,icoords,LOWER,comp,
				getStateZvel,&w20,crx_coords);
	    }
	    index21 = d_index3d(i,j,k+1,top_gmax);
	    if (liquid_comp(top_comp[index21]))
	    {
	    	u21 = u[index21];
	    	v21 = v[index21];
	    	w21 = w[index21];
	    }
	    else
	    {
		FrontStateAtGridCrossing(front,icoords,UPPER,comp,
				getStateXvel,&u21,crx_coords);
		FrontStateAtGridCrossing(front,icoords,UPPER,comp,
				getStateYvel,&v21,crx_coords);
		FrontStateAtGridCrossing(front,icoords,UPPER,comp,
				getStateZvel,&w21,crx_coords);
	    }

	    cell_center[index].m_state.m_U[0] += -m_dt*(
				burger_flux(u00,u0,u01)/top_h[0] +
				linear_flux(v0,u10,u0,u11)/top_h[1] +
				linear_flux(w0,u20,u0,u21)/top_h[2]);

	    cell_center[index].m_state.m_U[1] += - m_dt*(
				linear_flux(u0,v00,v0,v01)/top_h[0] +
			 	burger_flux(v10,v0,v11)/top_h[1] +
				linear_flux(w0,v20,v0,v21)/top_h[2]);

	    cell_center[index].m_state.m_U[2] += - m_dt*(
				linear_flux(u0,w00,w0,w01)/top_h[0] +
				linear_flux(v0,w10,w0,w11)/top_h[1] +
			 	burger_flux(w20,w0,w21)/top_h[2]);

	    speed = fabs(cell_center[index].m_state.m_U[0]) +
		    fabs(cell_center[index].m_state.m_U[1]) +
		    fabs(cell_center[index].m_state.m_U[2]);
	    if (speed > max_speed)
		max_speed = speed;
	}
	for (l = 0; l < 3; ++l)
	{
	    for (k = kmin; k <= kmax; k++)
	    for (j = jmin; j <= jmax; j++)
	    for (i = imin; i <= imax; i++)
	    {	
	    	index  = d_index3d(i,j,k,top_gmax);
	    	array[index] = cell_center[index].m_state.m_U[l];
	    }
	    scatMeshArray();
	    for (k = 0; k <= top_gmax[2]; k++)
	    for (j = 0; j <= top_gmax[1]; j++)
	    for (i = 0; i <= top_gmax[0]; i++)
	    {	
	    	index  = d_index3d(i,j,k,top_gmax);
	    	cell_center[index].m_state.m_U[l] = array[index];
	    }
	}
	pp_global_max(&max_speed,1);
	free_these(3,u,v,w);
}	/* end computeAdvection3d */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeNewVelocity2d(void)
{
	int i, j, k, index0, index;
	double gradP[2], rho;
	COMPONENT comp;
	double speed;

	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index = d_index2d(i,j,top_gmax);
	    comp = top_comp[index];
	    if (!liquid_comp(comp))
	    {
		cell_center[index].m_state.m_U[0] = 0.0;
		cell_center[index].m_state.m_U[1] = 0.0;
		continue;
	    }
	    rho = cell_center[index].m_state.m_rho;
	    computePressureGradient(index,gradP);
	    cell_center[index].m_state.m_U[0] -= 1.0/rho*gradP[0];
	    cell_center[index].m_state.m_U[1] -= 1.0/rho*gradP[1];
	    speed = fabs(cell_center[index].m_state.m_U[0]) +
		    fabs(cell_center[index].m_state.m_U[1]);
	    if (speed > max_speed)
		max_speed = speed;
	}
	for (k = 0; k < 2; ++k)
	{
	    for (j = jmin; j <= jmax; j++)
            for (i = imin; i <= imax; i++)
	    {	
	    	index  = d_index2d(i,j,top_gmax);
	    	array[index] = cell_center[index].m_state.m_U[k];
	    }
	    scatMeshArray();
	    for (j = 0; j <= top_gmax[1]; j++)
	    for (i = 0; i <= top_gmax[0]; i++)
	    {	
	    	index  = d_index2d(i,j,top_gmax);
	    	cell_center[index].m_state.m_U[k] = array[index];
	    }
	}
	pp_global_max(&max_speed,1);
}	/* end computeNewVelocity2d */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeNewVelocity3d(void)
{
	int i, j, k, l, index;
	double gradP[3], rho;
	COMPONENT comp;
	double speed;

	for (k = kmin; k <= kmax; k++)
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index = d_index3d(i,j,k,top_gmax);
	    comp = top_comp[index];
	    if (!liquid_comp(comp))
	    {
		for (l = 0; l < 3; ++l)
		    cell_center[index].m_state.m_U[l] = 0.0;
		continue;
	    }
	    rho = cell_center[index].m_state.m_rho;
	    computePressureGradient(index,gradP);
	    speed = 0.0;
	    for (l = 0; l < 3; ++l)
	    {
	    	cell_center[index].m_state.m_U[l] -= 1.0/rho*gradP[l];
		speed += fabs(cell_center[index].m_state.m_U[l]);
	    }
	    if (speed > max_speed)
		max_speed = speed;
	}
	for (l = 0; l < 3; ++l)
	{
	    for (k = kmin; k <= kmax; k++)
	    for (j = jmin; j <= jmax; j++)
            for (i = imin; i <= imax; i++)
	    {	
	    	index  = d_index3d(i,j,k,top_gmax);
	    	array[index] = cell_center[index].m_state.m_U[l];
	    }
	    scatMeshArray();
	    for (k = 0; k <= top_gmax[2]; k++)
	    for (j = 0; j <= top_gmax[1]; j++)
	    for (i = 0; i <= top_gmax[0]; i++)
	    {	
	    	index  = d_index3d(i,j,k,top_gmax);
	    	cell_center[index].m_state.m_U[l] = array[index];
	    }
	}
	pp_global_max(&max_speed,1);
}	/* end computeNewVelocity3d */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeNewVelocity(void)
{
	switch (dim)
	{
	case 2:
	    return computeNewVelocity2d();
	case 3:
	    return computeNewVelocity3d();
	}
}	/* end computeNewVelocity */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeProjection2d(void)
{
	int index, index_nb[4], size;
	double rhs, coeff[4], rho[4], rho0;
	int I,I_nb[4];
	int i,j,l,icoords[MAXD];
	INTERFACE *intfc = front->interf;
	double P_max,P_min;
	int icrds_Pmax[MAXD],icrds_Pmin[MAXD];
	COMPONENT comp;
	double aII,rho_nb[4];
	double coords[MAXD],crx_coords[MAXD];

	PETSc solver;
	solver.Create(ilower, iupper-1, 5, 0);
	size = iupper - ilower;

	setIndexMap();

	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index  = d_index2d(i,j,top_gmax);
	    comp = top_comp[index];
	    I = ij_to_I[i][j];
	    if (I == -1) continue;

	    index_nb[0] = d_index2d(i-1,j,top_gmax);
	    index_nb[1] = d_index2d(i+1,j,top_gmax);
	    index_nb[2] = d_index2d(i,j-1,top_gmax);
	    index_nb[3] = d_index2d(i,j+1,top_gmax);
	    I_nb[0] = ij_to_I[i-1][j];
	    I_nb[1] = ij_to_I[i+1][j];
	    I_nb[2] = ij_to_I[i][j-1];
	    I_nb[3] = ij_to_I[i][j+1];
	    icoords[0] = i;
	    icoords[1] = j;
	
	    for (l = 0; l < 4; ++l)
	    {
		if (I_nb[l] == -1)
		    index_nb[l] = index;
	    }

	    rho0   = cell_center[index].m_state.m_rho;
	    for (l = 0; l < 4; ++l)
	    {
	    	rho[l] = 1.0/2*(rho0 + cell_center[index_nb[l]].m_state.m_rho);
	    	coeff[l] = 1/rho[l]/(top_h[l/2]*top_h[l/2]); 
	    }

	    rhs = computeVelocityDivergence(index);

	    aII = 0.0;
	    for (l = 0; l < 4; ++l)
	    {
	    	if (I_nb[l] != -1)
		{
		    solver.Add_A(I,I_nb[l],coeff[l]);
                    aII += -coeff[l];
		}
	    }
            if (aII != 0.0)
                solver.Add_A(I,I,aII);
            else
            {
                solver.Add_A(I,I,1.0);
                rhs = cell_center[index].m_state.m_P;
            }
            solver.Add_b(I,rhs);
	}
	
	solver.SetMaxIter(500);
	solver.SetTol(1e-8);
	solver.Solve_withPureNeumann();

	double *x;
	uni_array(&x,size,sizeof(double));
	solver.Get_x(x);

	int num_iter = 0;
	double rel_residual = 0;
	solver.GetNumIterations(&num_iter);
	solver.GetFinalRelativeResidualNorm(&rel_residual);

	if (debugging("PETSc"))
	    (void) printf("L_CARTESIAN::computeProjection: "
	       		"num_iter = %d, rel_residual = %le \n", 
			num_iter, rel_residual);
	
	P_max = -HUGE;		P_min = HUGE;
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index = d_index2d(i,j,top_gmax);
	    I = ij_to_I[i][j];
	    cell_center[index].m_state.m_P = x[I-ilower];
	    if (P_max < cell_center[index].m_state.m_P)
	    {
		P_max = cell_center[index].m_state.m_P;
		icrds_Pmax[0] = i;
		icrds_Pmax[1] = j;
	    }
	    if (P_min > cell_center[index].m_state.m_P)
	    {
		P_min = cell_center[index].m_state.m_P;
		icrds_Pmin[0] = i;
		icrds_Pmin[1] = j;
	    }
	}
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index  = d_index2d(i,j,top_gmax);
	    array[index] = cell_center[index].m_state.m_P;
	}
	scatMeshArray();
	for (j = 0; j <= top_gmax[1]; j++)
	for (i = 0; i <= top_gmax[0]; i++)
	{
	    index  = d_index2d(i,j,top_gmax);
	    cell_center[index].m_state.m_P = array[index];
	}
	if (debugging("trace"))
	{
	    printf("In computeProjection(): \n");
	    printf("P_max = %f  occured at (%d %d)\n",P_max,icrds_Pmax[0],
				icrds_Pmax[1]);
	    printf("P_min = %f  occured at (%d %d)\n",P_min,icrds_Pmin[0],
				icrds_Pmin[1]);
	}
	free_these(1,x);
}	/* end computeProjection2d */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeProjection3d(void)
{
	int index, index_nb[6], size;
	double rhs, coeff[6], rho[6], rho0;
	int I,I_nb[6];
	int i,j,k,l,icoords[MAXD];
	INTERFACE *intfc = front->interf;
	double P_max,P_min;
	int icrds_Pmax[MAXD],icrds_Pmin[MAXD];
	COMPONENT comp;
	double aII,rho_nb[4];
	double coords[MAXD],crx_coords[MAXD];

	PETSc solver;
	solver.Create(ilower, iupper-1, 7, 0);
	size = iupper - ilower;

	setIndexMap();

	for (k = kmin; k <= kmax; k++)
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index  = d_index3d(i,j,k,top_gmax);
	    comp = top_comp[index];
	    I = ijk_to_I[i][j][k];
	    if (I == -1) continue;

	    index_nb[0] = d_index3d(i-1,j,k,top_gmax);
	    index_nb[1] = d_index3d(i+1,j,k,top_gmax);
	    index_nb[2] = d_index3d(i,j-1,k,top_gmax);
	    index_nb[3] = d_index3d(i,j+1,k,top_gmax);
	    index_nb[4] = d_index3d(i,j,k-1,top_gmax);
	    index_nb[5] = d_index3d(i,j,k+1,top_gmax);
	    I_nb[0] = ijk_to_I[i-1][j][k];
	    I_nb[1] = ijk_to_I[i+1][j][k];
	    I_nb[2] = ijk_to_I[i][j-1][k];
	    I_nb[3] = ijk_to_I[i][j+1][k];
	    I_nb[4] = ijk_to_I[i][j][k-1];
	    I_nb[5] = ijk_to_I[i][j][k+1];
	    icoords[0] = i;
	    icoords[1] = j;
	    icoords[2] = k;
	
	    rho0   = cell_center[index].m_state.m_rho;
	    for (l = 0; l < 6; ++l)
	    {
		if (I_nb[l] == -1)
		    index_nb[l] = index;
		rho[l] = 1.0/2*(rho0 + cell_center[index_nb[l]].m_state.m_rho);
		coeff[l] = 1/rho[l]/sqr(top_h[l/2]);
	    }

	    rhs = computeVelocityDivergence(index);

	    aII = 0.0;
	    for (l = 0; l < 6; ++l)
	    {
	    	if (I_nb[l] != -1)
		{
		    solver.Add_A(I,I_nb[l],coeff[l]);
                    aII += -coeff[l];
		}
	    }
            if (aII != 0.0)
                solver.Add_A(I,I,aII);
            else
            {
                solver.Add_A(I,I,1.0);
                rhs = cell_center[index].m_state.m_P;
            }
            solver.Add_b(I,rhs);
	}
	
	solver.SetMaxIter(500);
	solver.SetTol(1e-8);
	solver.Solve_withPureNeumann();

	double *x;
	uni_array(&x,size,sizeof(double));
	solver.Get_x(x);

	int num_iter = 0;
	double rel_residual = 0;
	solver.GetNumIterations(&num_iter);
	solver.GetFinalRelativeResidualNorm(&rel_residual);

	if (debugging("PETSc"))
	    (void) printf("L_CARTESIAN::computeProjection: "
	       		"num_iter = %d, rel_residual = %le \n", 
			num_iter, rel_residual);
	
	P_max = -HUGE;		P_min = HUGE;
	for (k = kmin; k <= kmax; k++)
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index = d_index3d(i,j,k,top_gmax);
	    I = ijk_to_I[i][j][k];
	    cell_center[index].m_state.m_P = x[I-ilower];
	    if (P_max < cell_center[index].m_state.m_P)
	    {
		P_max = cell_center[index].m_state.m_P;
		icrds_Pmax[0] = i;
		icrds_Pmax[1] = j;
		icrds_Pmax[2] = k;
	    }
	    if (P_min > cell_center[index].m_state.m_P)
	    {
		P_min = cell_center[index].m_state.m_P;
		icrds_Pmin[0] = i;
		icrds_Pmin[1] = j;
		icrds_Pmin[2] = k;
	    }
	}
	for (k = kmin; k <= kmax; k++)
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index  = d_index3d(i,j,k,top_gmax);
	    array[index] = cell_center[index].m_state.m_P;
	}
	scatMeshArray();
	for (k = 0; k <= top_gmax[2]; k++)
	for (j = 0; j <= top_gmax[1]; j++)
	for (i = 0; i <= top_gmax[0]; i++)
	{
	    index  = d_index3d(i,j,k,top_gmax);
	    cell_center[index].m_state.m_P = array[index];
	}
	if (debugging("trace"))
	{
	    printf("In computeProjection(): \n");
	    printf("P_max = %f  occured at (%d %d %d)\n",P_max,icrds_Pmax[0],
				icrds_Pmax[1],icrds_Pmax[2]);
	    printf("P_min = %f  occured at (%d %d %d)\n",P_min,icrds_Pmin[0],
				icrds_Pmin[1],icrds_Pmax[2]);
	}
	free_these(1,x);
}	/* end computeProjection3d */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::computeProjection(void)
{
	switch (dim)
	{
	case 2:
	    return computeProjection2d();
	case 3:
	    return computeProjection3d();
	}
}	/* end computeProjection */
}}}
src/intfc/imkcurve.c
{{{
EXPORT	int construct_comp2_blk(
	BLK_CRX *blk_crx,
	BLK_TRI *blk_mem)
{
	int       i,j,k,is;
	COMPONENT ***comp = blk_crx->comp;
	int       num_crx, case_found;
	BBI_POINT *crxs[12];
	static COMPONENT ****prime_comp;
	static BLK_CRX *bc_rot;
	void (*blk_intfc_comp2[14])(BLK_CRX*, BLK_TRI*) =
	{
	    blk_case01_comp2,
	    blk_case02_comp2,
	    blk_case03_comp2,
	    blk_case04_comp2,
	    blk_case05_comp2,
	    blk_case06_comp2,
	    blk_case07_comp2,
	    blk_case08_comp2,
	    blk_case09_comp2,
	    blk_case10_comp2,
	    blk_case11_comp2,
	    blk_case12_comp2,
	    blk_case13_comp2,
	    blk_case14_comp2,
	};

	if (prime_comp == NULL)
	{
	    quad_array(&prime_comp,14,2,2,2,sizeof(COMPONENT));
	    set_prime_components(prime_comp);
	}

	blk_mem->num_surfaces = 1;
	blk_mem->num_curves = 0;
	num_crx = 0;
	for (j = 0; j < 2; ++j)
	{
	    for (k = 0; k < 2; ++k)
	    {
	        if (comp[0][j][k] != comp[1][j][k])
	        {
	            crxs[num_crx] = crx_in_idir(blk_crx,j,k);
	            if (crxs[num_crx] == NULL)
		    {
	                return FUNCTION_FAILED;
		    }
	            ++num_crx;
	        }
	    }
	}

	for (k = 0; k < 2; ++k)
	{
	    for (i = 0; i < 2; ++i)
	    {
	        if (comp[i][0][k] != comp[i][1][k])
	        {
	            crxs[num_crx] = crx_in_jdir(blk_crx,k,i);
	            if (crxs[num_crx] == NULL)
		    {
	                return FUNCTION_FAILED;
		    }
	            ++num_crx;
	        }
	    }
	}

	for (i = 0; i < 2; ++i)
	{
	    for (j = 0; j < 2; ++j)
	    {
	        if (comp[i][j][0] != comp[i][j][1])
	        {
	            crxs[num_crx] = crx_in_kdir(blk_crx,i,j);
	            if (crxs[num_crx] == NULL)
		    {
	                return FUNCTION_FAILED;
		    }
	            ++num_crx;
	        }
	    }
	}
	if (num_crx == 0)
	{
	    /* No interface, but ONFRONT, this happens */
	    blk_mem->num_tris[0] = 0;
	    return FUNCTION_SUCCEEDED;
	}
	
	for (i = 1; i < num_crx; ++i)
	{
	    if (crxs[i]->s != crxs[0]->s)
	    {  
		printf("surface_numbe of crxs[0]->s = %llu\n",
				surface_number(crxs[0]->s));    
		printf("surface_numbe of crxs[i]->s = %llu\n",
				surface_number(crxs[i]->s));
	        screen("ERROR in construct_comp2_blk(), more than "
	               "one surface in a block, code needed\n");
		(void) printf("crx[%d]->hs = %p  crx[0] = %p\n",
		              i,crxs[i]->s,crxs[0]->s);
                (void) printf("i = %d,num_crx = %d\n",i,num_crx);
		clean_up(ERROR);
	    }
	}
	if (blk_crx->nv[0] > 4)
	{
	    screen("ERROR: in construct_comp2_blk(), no such case!\n");
	    clean_up(ERROR);
	}

	is = is_surface(blk_crx,crxs[0]->s);
	blk_mem->first[is] = NULL;
	blk_mem->num_tris[is] = 0;
	blk_mem->surfs[is] = crxs[0]->s;
	if (bc_rot == NULL) bc_rot = alloc_blk_crx(NO);
	copy_blk_crx(blk_crx, bc_rot);

	/* begin 24-rotation */
	
	case_found = NO;
	for (j = 0; j <= 24; j++)
	{
	    for (i = 0; i < 14; i++)
	    {
	        if (compare_comp(bc_rot->comp, prime_comp, i)) 
	        { 
	            blk_intfc_comp2[i](bc_rot, blk_mem);
		    case_found = YES;
	            break;
	        }
	    }
	    if (case_found == YES) break;
	    rot24(bc_rot, j);
	}

	if (case_found == NO)
	{
	    (void)printf("ERROR: in construct_comp2_blk() No case is found\n");
	    for (i = 0; i < 2; i++)
	    for (j = 0; j < 2; j++) 
	    for (k = 0; k < 2; k++)
	    {
	        (void)printf("comp[%d][%d][%d] = %d\n",i,j,k,comp[i][j][k]);
	        clean_up(ERROR);
	    }
	}

	blk_mem->num_null_sides[is] = 3*blk_mem->num_tris[is];

	if (debugging("print_blk_tri"))
	{
	    (void) printf("debugging(print_blk_tri), "
			  "printing blk_mem BEFORE stitching inside.\n" );
	    print_blk_tri(blk_mem);
	}

	stitch_inside_blk(blk_mem);

	if (debugging("print_blk_tri"))
	{
	    (void) printf("debugging(print_blk_tri), "
			  "printing blk_mem AFTER stitching inside.\n" );
	    print_blk_tri(blk_mem);
	}

	return FUNCTION_SUCCEEDED;
}	/* end reconstruct_blk_intfc */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::copyMeshStates()
{
	int i,j,k,d,index;
	POINT *p;
        HYPER_SURF *hs;
        HYPER_SURF_ELEMENT *hse;
	INTERFACE *intfc = front->interf;
	double **vel = eqn_params->vel;
	double *pres = eqn_params->pres;
	double *vort = eqn_params->vort;
	double **vort3d = eqn_params->vort3d;

	switch (dim)
	{
	case 2:
	    for (i = imin; i <= imax; ++i)
	    for (j = jmin; j <= jmax; ++j)
	    {
	    	index  = d_index2d(i,j,top_gmax);
		if (liquid_comp(top_comp[index]))
		{
	    	    pres[index] = cell_center[index].m_state.m_P;
	    	    vel[0][index] = cell_center[index].m_state.m_U[0];
	    	    vel[1][index] = cell_center[index].m_state.m_U[1];
		    vort[index] = getVorticity(i,j);
		}
		else
		{
	    	    pres[index] = 0.0;
	    	    vel[0][index] = 0.0;
	    	    vel[1][index] = 0.0;
		    vort[index] = 0.0;
		}
	    }
	    FrontScatExpDualGridArray(pres,front);
	    FrontScatExpDualGridArray(vort,front);
	    FrontScatExpDualGridArray(vel[0],front);
	    FrontScatExpDualGridArray(vel[1],front);
	    break;
	case 3:
	    for (i = imin; i <= imax; ++i)
	    for (j = jmin; j <= jmax; ++j)
	    for (k = kmin; k <= kmax; ++k)
	    {
	    	index  = d_index3d(i,j,k,top_gmax);
		if (liquid_comp(top_comp[index]))
		{
	    	    pres[index] = cell_center[index].m_state.m_P;
	    	    vel[0][index] = cell_center[index].m_state.m_U[0];
	    	    vel[1][index] = cell_center[index].m_state.m_U[1];
	    	    vel[2][index] = cell_center[index].m_state.m_U[2];
		    vort3d[0][index] = getVorticityX(i,j,k);
		    vort3d[1][index] = getVorticityY(i,j,k);
		    vort3d[2][index] = getVorticityZ(i,j,k);
		}
		else
		{
	    	    pres[index] = 0.0;
		    for (d = 0; d < 3; ++d)
		    {
	    	    	vel[d][index] = 0.0;
		    	vort3d[d][index] = 0.0;
		    }
		}
	    }
	    FrontScatExpDualGridArray(pres,front);
	    FrontScatExpDualGridArray(vel[0],front);
	    FrontScatExpDualGridArray(vel[1],front);
	    FrontScatExpDualGridArray(vel[2],front);
	    FrontScatExpDualGridArray(vort3d[0],front);
	    FrontScatExpDualGridArray(vort3d[1],front);
	    FrontScatExpDualGridArray(vort3d[2],front);
	    break;
	}
}	/* end copyMeshStates */
}}}
src/intfc/igrid.c
{{{
/*
*			copy_rect_grid():
*
*	Copy the RECT_GRID structure data_gr into the rect_grid copy_gr.
*/

EXPORT	void	copy_rect_grid(
	RECT_GRID	*copy_gr,
	const RECT_GRID	*data_gr)
{
	int		i, dim;

	debug_print("cp_rect_grid","Entered copy_rect_grid()\n");

	if (copy_gr == NULL || data_gr == NULL)
	{
	    debug_print("cp_rect_grid","Left copy_rect_grid(), Null grid\n");
	    return;
	}
	dim = data_gr->dim;
	*copy_gr = *data_gr;
	for (i = 0; i < dim; ++i)
	{
	    copy_gr->edges[i] = NULL;
	    copy_gr->centers[i] = NULL;
	    copy_gr->dh[i] = NULL;
	    copy_gr->variable_mesh[i] = NO;
	}
	copy_gr->glstore = NULL;
	debug_print("cp_rect_grid","Left copy_rect_grid()\n");
}		/*end copy_rect_grid*/
}}}
src/intfc/imkcurve
{{{
LOCAL	int count_crx_through_comp2d(
	int *gmax,
	COMPONENT **comp)
{
	int i,j,num_crx,num_comp;

	num_crx = 0;
	for (i = 0; i <= gmax[0]; ++i)
	{
	    for (j = 0; j <= gmax[1]; ++j)
	    {
		if (i != gmax[0])
		{
		    if (comp[i][j] != comp[i+1][j])
			    ++num_crx;
		}
		if (j != gmax[1])
		{
		    if (comp[i][j] != comp[i][j+1])
			    ++num_crx;
		}
	    }
	}
	return num_crx;
}	/* end count_crx_through_comp */
}}}
src/front/ftop.c
{{{
EXPORT   bool  cross_rect_grid_bdry(
        BOND *b,
        RECT_GRID *rgr)
{
        float *L = rgr->L;         
	float *U = rgr->U;
        int i,dim = rgr->dim;
        POINT *ps = b->start;
        POINT *pe = b->end;

        for (i = 0; i < dim; ++i)
        {
            if (Coords(ps)[i] < L[i] && Coords(pe)[i] > L[i])
                return YES;
            if (Coords(ps)[i] > L[i] && Coords(pe)[i] < L[i])
                return YES;
            if (Coords(ps)[i] < U[i] && Coords(pe)[i] > U[i])
                return YES;
            if (Coords(ps)[i] > U[i] && Coords(pe)[i] < U[i])
                return YES;
        }
        return NO;
}       /* end cross_rect_grid_bdry */
}}}
src/front/ftop.c
{{{
EXPORT	void curve_delete_very_short_bonds(
	CURVE		*c)
{
	BOND		*b;
	RECT_GRID	*gr = computational_grid(c->interface);
	float		*h = gr->h;
	float		min_sc_sep = MIN_SC_SEP(c->interface);
	int		dim = gr->dim;

	/* Note: it may be necessary to allow this function to return a
	 * status to indicate failure. */

redo:
	for (b = c->first; b != NULL; b = b->next)
	{
	    if (scaled_bond_length(b,h,dim) < min_sc_sep)
	    {
		if (b->prev == NULL)
		{
		    if (b->next == NULL)
			return;
		    if (cross_rect_grid_bdry(b,gr) &&
		    	cross_rect_grid_bdry(b->next,gr)) continue;
		    if (delete_start_of_bond(b->next,c)==FUNCTION_FAILED)
		    {
			(void) printf("WARNING in "
				      "curve_delete_very_short_bonds(), "
				      "delete_start_of_bond() failed "
				      "at point adjacent to node\n");
			continue;
		    }

		    goto redo;	/* may be multiple short bonds in a row */
		}
		else
		{
		    if (cross_rect_grid_bdry(b->prev,gr) &&
		    	cross_rect_grid_bdry(b,gr)) 
			continue;
		    if (delete_start_of_bond(b,c) == FUNCTION_FAILED)
		    {
			(void) printf("WARNING in "
				      "curve_delete_very_short_bonds(), "
				      "delete_start_of_bond() failed\n");
			continue;
		    }
		}
	    }
	}
}		/*end curve_delete_very_short_bonds*/
}}}
{{{
void (*curve_propagate)(struct _Front*,POINTER,CURVE*,CURVE*,float);
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::deleteGridIntfc()
{
	FrontFreeGridIntfc(front);
}
}}}
src/intfc/userhools.c
{{{
EXPORT	int delete_interface(
	INTERFACE	*intfc)
{
	if (intfc == NULL) /*Nothing to do*/
	    return 1;
	return (*i_user_interface(intfc)._delete_interface)(intfc);
}		/*end delete_interface*/
}}}
src/front/fredist3d.c
{{{
LOCAL bool delete_min_side_of_tri(
	TRI	  *tri,
	int	  side,
	SURFACE	  *s,
	POINTER_Q **pq,
	Front     *fr)
{
	INTERFACE	*intfc;
	TRI	*nbtri, *t, *nbt, **tmp_tris;
	TRI	*new_tris[500], *in_tris[200], *tris[2][100];
	POINT	*p[4], *pt, *pmid, *plist[2][100];
	int	i, j, k, nt, np[2], nside, ntris[2];
	bool	rm_flag;
	static	int	cnt = 0;
	FILE	*file;
	char	fname[100];

	DEBUG_ENTER(delete_min_side_of_tri)

	//printf("#tri side %d %d\n", tri, side);

	intfc = fr->interf;
	p[0] = Point_of_tri(tri)[side];
	p[1] = Point_of_tri(tri)[Next_m3(side)];

	if(Boundary_point(p[0]) || Boundary_point(p[1]))
	{
	    DEBUG_LEAVE(delete_min_side_of_tri)
	    return YES;
	}

	nbtri = Tri_on_side(tri,side);
	for(nside=0; nside<3; nside++)
	    if (Tri_on_side(nbtri,nside) == tri)
		break;

	p[2] = Point_of_tri(tri)[Prev_m3(side)];
	p[3] = Point_of_tri(nbtri)[Prev_m3(nside)];

	for(k=0; k<2; k++)
	{
	    ntris[k] = set_tri_list_around_point(p[k],tri,&tmp_tris,intfc);
	    for(i=0; i<ntris[k]; i++)
	    {
		tris[k][i] = tmp_tris[i];
	        *pq = dequeue(tris[k][i],*pq);
	    }

	    np[k] = 0;
	    //finding bounding points except the 4 common points.
	    for(i=0; i<ntris[k]; i++)
	    {
		t = tris[k][i];
		j = Vertex_of_point(t, p[k]);
		pt = Point_of_tri(t)[Prev_m3(j)];
		
		for(j=0; j<4; j++)
		    if(pt == p[j])
			break;
		if(j < 4)
		    continue;

		plist[k][np[k]] = pt;
		np[k]++;
	    }
	}

	//skip the bdry case.
	if(Boundary_point(p[2]) || Boundary_point(p[3]))
	{
	    DEBUG_LEAVE(delete_min_side_of_tri)
	    return YES;
	}
	for(i=0; i<np[0]; i++)
	    if(Boundary_point(plist[0][i]))
	    {
		DEBUG_LEAVE(delete_min_side_of_tri)
		return YES;
	    }
	for(i=0; i<np[1]; i++)
	    if(Boundary_point(plist[1][i]))
	    {
		DEBUG_LEAVE(delete_min_side_of_tri)
		return YES;
	    }

	//check if there are duplicate points in the bounding tris.
	rm_flag = NO;
	if(np[0] > 0 && np[1] > 0)
	{
	    //the general case, test duplicate points
	    for(i=0; i<np[0]; i++)
		for(j=0; j<np[1]; j++)
		    if(plist[0][i] == plist[1][j])
			rm_flag = YES;
	}
	else if(np[0] == 0 && np[1] == 0)
	{
	    //the tetrahedron case
	    rm_flag = YES;
	}

	//printf("#shape np %3d  %3d %3d\n", rm_flag, np[0], np[1]);
	if(rm_flag)
	{
	    nt = 0;
	    for(k=0; k<2; k++)
		nt = merge_tris_set(in_tris, nt, tris[k], ntris[k]);

	    if(debugging("delete_dup"))
	    {
		sprintf(fname,"dup_min%d_%d.plt",pp_mynode(),cnt);
		cnt++;
		printf("debug file %s\n", fname);
		
		file = fopen(fname,"w");
		tecplot_show_tris("in_tris", in_tris, nt, file);
		fclose(file);
	    }
    
	    nt = remove_tris_and_seal(new_tris, in_tris, nt, s, pq, intfc);
	
	    if(debugging("delete_dup"))
	    {
		file = fopen(fname,"a");
		tecplot_show_tris("new_tris", new_tris, nt, file);
		fclose(file);
	    }
	    
	    DEBUG_LEAVE(delete_min_side_of_tri)
	    return   nt==-1 ? NO : YES;
	}

	//collapse two tris.
	pmid = average_points(YES,p[0],Hyper_surf_element(tri),Hyper_surf(s),
				  p[1],Hyper_surf_element(tri),Hyper_surf(s));
	
	//change the point for the surrounding tris.
	for (i = 0; i < 2; ++i)
	{
	    for (j = 0; j < ntris[i]; ++j)
	    {
		t = tris[i][j];
		k = Vertex_of_point(t,p[i]);
		Point_of_tri(t)[k] = pmid;
		if ((t != tri) && (t != nbtri))
		    set_normal_of_tri(t);
	    }
	}

	//change tri neighbor for tri.
	nbt = Tri_on_side(tri,Next_m3(side));
	t = Tri_on_side(tri,Prev_m3(side));
	for(i=0; i<3; i++)
	{
	    if (Tri_on_side(t,i) == tri)
		Tri_on_side(t,i) = nbt;
	    if (Tri_on_side(nbt,i) == tri)
		Tri_on_side(nbt,i) = t;
	}
	
	//change tri neighbor for nbtri.
	nbt = Tri_on_side(nbtri,Next_m3(nside));
	t = Tri_on_side(nbtri,Prev_m3(nside));
	for (i = 0; i < 3; ++i)
	{
	    if (Tri_on_side(t,i) == nbtri)
		Tri_on_side(t,i) = nbt;
	    if (Tri_on_side(nbt,i) == nbtri)
		Tri_on_side(nbt,i) = t;
	}
	
	remove_tri_from_surface(tri,s,YES);
	remove_tri_from_surface(nbtri,s,YES);
	
	DEBUG_LEAVE(delete_min_side_of_tri)
	return YES;
}
}}}
src/front/fredist2d.c
{{{
EXPORT	bool equi_curve_redistribute(
	Front		*fr,
	CURVE		*c,
	bool		status)
{
	BOND		*b;
	float		fr_space;
	RECT_GRID	*rgr = fr->rect_grid;
	float		*h = rgr->h;
	float		c_len;
	int		dim = rgr->dim;
	int		nbds;

	DEBUG_ENTER(equi_curve_redistribute)
		/* Conditionally skip boundary curves */

	if (wave_type(c) == PASSIVE_BOUNDARY && (c->num_points > 2))
	{
	    DEBUG_LEAVE(equi_curve_redistribute)
	    return status;
	}
	if (is_subdomain_boundary(Hyper_surf(c)))
	{
	    DEBUG_LEAVE(equi_curve_redistribute)
	    return YES;
	}

	fr_space = Front_spacing(fr,
			 (wave_type(c) >= FIRST_VECTOR_PHYSICS_WAVE_TYPE) ?
				VECTOR_WAVE : GENERAL_WAVE);

	if (DEBUG)
	{
	    (void) printf("curve - ");
	    print_curve(c);
	}


	    /* Compute curve_length */

	c_len = 0.0;
	for (b = c->first;  b;  b = b->next)
	{
	    c_len += scaled_bond_length(b,h,dim);
	}

	    /* For short, non-boundary curves with few points - each */
	    /* such curve is equi-distributed, however the number   */
	    /* of points currently on the curve remains unchanged   */

	nbds = c->num_points - 1;
	if (DEBUG)
	    (void) printf("nbds %d\n",nbds);
	if (wave_type(c) >= FIRST_PHYSICS_WAVE_TYPE && 
			is_short_curve(c,POSITIVE_ORIENTATION,rgr,1.5))
	{
	    (void) expand_redist_cur(fr,c);
	    DEBUG_LEAVE(equi_curve_redistribute)
	    return status;
	}
	else if ((!is_bdry_like_curve(c)) && (nbds <= 4))
	{
	    if (c_len < 1.5 * fr_space * nbds)
	    {
		if (DEBUG)
		    (void) printf("c_len %g < tol %g",c_len,1.5*fr_space*nbds);
		if (nbds > 1)
		{
		    if (DEBUG)
			(void) printf("nbds > 1\n");
		    equi_redist_curve_seg(c,c->first,c->last,nbds,
					  c_len,fr_space,rgr);
		    if (DEBUG)
		    {
		    	(void) printf("After equi_redist_curve_seg:\n");
		    	(void) printf("curve - ");
			print_curve(c);
		    }
		}
		DEBUG_LEAVE(equi_curve_redistribute)
		return status;
	    }
	}

	    /* Pass 1, delete very short bonds */

	curve_delete_very_short_bonds(c);
	if (DEBUG)
	{
	    (void) printf("After delete_very_short_bonds:\ncurve - ");
	    print_curve(c);
	}

	    /* Can't redistribute single bond, short_curves */

	if ((c->first == c->last) && (c_len < fr_space))
	{
	    if (DEBUG)
		(void) printf("single_bond, short curve\n");
	    DEBUG_LEAVE(equi_curve_redistribute)
	    return status;
	}

	b = c->first;
        while (b)
        {
            c_len = 0.0;
            BOND *be,*bs = b;
            for (;  b;  b = b->next)
            {
                c_len += scaled_bond_length(b,h,dim);
                be = b;
		if (cross_rect_grid_bdry(b,rgr)) break;
            }
	    b = be->next;
            equi_redist_curve_seg(c,bs,be,-1,c_len,fr_space,rgr);
        }
	if (DEBUG)
	{
	    (void) printf("After equi_redist_curve_seg:\ncurve - ");
	    print_curve(c);
	}
	DEBUG_LEAVE(equi_curve_redistribute)
	return status;
}		/*end equi_curve_redistribute*/
}}}
src/front/iredist.c
{{{
EXPORT	void equi_redist_curve_seg(
	CURVE		*c,
	BOND		*bs,
	BOND		*be,
	int		nbds, 
/*if nbds<0, number of points changed, if nbds<=1, number of points unchanged*/
	float		seg_len,
	float		space,
	RECT_GRID	*rgr)
{
	BOND		*b, *bstart, *bend;
	float		b_len, sc_len, offset, s, oms;
	float		coords[MAXD];
	float		*h = rgr->h;
	int		dim = rgr->dim;
	int		new_nbds;

	DEBUG_ENTER(equi_redist_curve_seg)
	if (nbds <= 0)
	{
	    new_nbds = (int)(ceil((double)seg_len/(double)space));
	    b_len = seg_len/(float)new_nbds;
	}
	else
	{
	    new_nbds = nbds;
	    b_len = seg_len/(float)new_nbds;
	}
	if (new_nbds <= 1)
	{
	    if (is_closed_curve(c) && bs == c->first && be == c->last)
	    {
	    	new_nbds = c->num_points - 1;
	    	if (new_nbds > 1)
	            equi_redist_curve_seg(c,bs,be,new_nbds,
					  seg_len,space,rgr);
	    }
	    else
	        replace_curve_seg_by_bond(c,bs,be);

	    DEBUG_LEAVE(equi_redist_curve_seg)
	    return;
	}

	offset = b_len;
	bstart = bs;		bend = be->next;
	while (bstart != bend)
	{
	    b = bstart;
	    while ((sc_len = scaled_bond_length(b,h,dim)) < offset)
	    {
	    	if (b->next == bend)
	    	{
	    	    replace_curve_seg_by_bond(c,bstart,b);
	    	    goto leave;
	    	}
	    	offset -= sc_len;
	    	b = b->next;
	    }
	    if ((b->next != bend) ||
	        (sc_len >= offset + MIN_SC_SEP(c->interface)))
	    {
	    	s = offset/sc_len;	oms = 1.0 - s;
	    	coords[0] = oms * Coords(b->start)[0] + s * Coords(b->end)[0];
	    	coords[1] = oms * Coords(b->start)[1] + s * Coords(b->end)[1];
	    	if (insert_point_in_bond(Point(coords),b,c) !=
		    FUNCTION_SUCCEEDED)
	    	{
	    	    screen("ERROR in equi_redist_curve_seg(), "
	    	           "insert_point_in_bond failed\n");
	    	    clean_up(ERROR);
	    	}
	    }
	    replace_curve_seg_by_bond(c,bstart,b);
	    bstart = bstart->next;
	    offset = b_len;
	}

leave:
	DEBUG_LEAVE(equi_redist_curve_seg)
	return;
}		/*end equi_redist_curve_seg*/
}}}
src/front/fint.c
{{{
EXPORT	POINT *f_Point(
	double		*coords)
{
	POINT		*p;
	INTERFACE	*intfc = current_interface();
	size_t		sizest;

	if ((p = i_Point(coords)) == NULL)
	    return NULL;
	if ((sizest = size_of_state(intfc)) != 0)
	{
	    left_state(p) = alloc_intfc_state(intfc,sizest);
	    right_state(p) = alloc_intfc_state(intfc,sizest);
	    if (right_state(p) == NULL)
	        return NULL;
	}
	else
	{
	    left_state(p)  = NULL;
	    right_state(p) = NULL;
	}
	return p;
}		/*end f_Point*/
}}}
src/front/fprop2d.c
{{{
EXPORT void f_curve_propagate2d(
	Front		*fr,
	POINTER		wave,
	CURVE		*oldc,
	CURVE		*newc,
	float		dt)
{
	BOND		*oldb = oldc->first;
	BOND		*newb = newc->first;
	float		V[MAXD];
	int		dim = fr->interf->dim;	
	float		L[MAXD],U[MAXD];	/* propagation boundary */

	debug_print("f_curve_propagate","Entered f_curve_propagate2d\n");

	if ((fr->_point_propagate == NULL)   ||
	    (oldc == NULL)                   ||
	    (newc == NULL)                   ||
	    (correspond_curve(oldc) != newc) ||
	    (correspond_curve(newc) != oldc))
	    return;

	set_propagation_bounds(fr,L,U);
	while (oldb) 
	{
	    if ((oldb != oldc->last) && (!n_pt_propagated(newb->end)))
	    {
	    	n_pt_propagated(newb->end) = YES;
		if (out_of_bound(oldb->end,L,U,dim)) 
		{
		    Locstate newsl,newsr;
		    Locstate oldsl,oldsr;
		    slsr(newb->end,Hyper_surf_element(newb),Hyper_surf(newc),
		    		&newsl,&newsr);
		    slsr(oldb->end,Hyper_surf_element(oldb),Hyper_surf(oldc),
		    		&oldsl,&oldsr);
		    ft_assign(newsl,oldsl,fr->sizest);                 
		    ft_assign(newsr,oldsr,fr->sizest);
		    continue;
		}
	    	point_propagate(fr,wave,oldb->end,newb->end,oldb->next,
				oldc,dt,V);
	    }
	    if (fr->bond_propagate != NULL)
	    	(*fr->bond_propagate)(fr,wave,oldb,newb,oldc,dt);
	    else
	    	set_bond_length(newb,dim); /* Update new bond length */
	    if (oldb == oldc->last)  /* if reach the last bond */
		break;
	    oldb = oldb->next; 
	    newb = newb->next;
	}
	debug_print("f_curve_propagate","Leaving f_curve_propagate2d\n");
}		/*end f_curve_propagate2d*/
}}}
src/front/fint.c
{{{
EXPORT	int f_delete_interface(
	INTERFACE	*intfc)
{
	int status;

	remove_corresponds_to_deleted_interface(intfc);
	rst_cor_after_delete_interface(intfc);
	status = i_delete_interface(intfc);
	return status;
}		/*end f_delete_interface*/
}}}
src/front/fint.h
{{{
LOCAL	void f_fprint_Dirichlet_bdry_states(
	FILE		*file,
	INTERFACE	*intfc)
{
	HYPER_SURF **hs;
	int	   i, dim = intfc->dim;
	static const char *hsname[] = { "point", "curve", "surface" };

	(void) fprintf(file,"\n\n");
	(void) foutput(file);
	(void) fprintf(file,
	               "Hypersurface Dirichlet boundary state information ");
	(void) fprintf(file,"for interface %llu\n",interface_number(intfc));
	for (i = 0, hs = intfc->hss; hs && *hs; ++i, ++hs)
	{
	    if (wave_type(*hs) != DIRICHLET_BOUNDARY)
	        continue;
	    (void) fprintf(file,"Boundary state index for %s %d = %d\n",
	                   hsname[dim-1],i,bstate_index(*hs));
	}
	(void) foutput(file);
	(void) fprintf(file,
	             "End hypersurface Dirichlet boundary state information ");
	(void) fprintf(file,"for interface %llu\n",interface_number(intfc));
	(void) fprintf(file,"\n\n");
}		/*end f_fprint_Dirichlet_bdry_states*/
}}}
src/front/fint.h
{{{
EXPORT	void	f_fprint_boundary_state_data(
	FILE		*file,
	INTERFACE	*intfc,
	BOUNDARY_STATE	*bstate)
{
	(void) fprintf(file,"Boundary state:");
	if (bstate->_boundary_state == NULL)
	    (void) fprintf(file," NONE\n");
	else
	{
	    (void) fprintf(file,"\n");
	    fprint_state_data(file,bstate->_boundary_state,intfc);
	}
	(void) fprintf(file,"Boundary state function = ");
	if (bstate->_boundary_state_function == NULL)
	    (void) fprintf(file,"NONE\n");
	else
	    (void) fprintf(file,"%s\n",bstate->_boundary_state_function_name);
}		/*end f_fprint_boundary_state_data*/
}}}
src/front/fint.h
{{{
EXPORT	void f_fprint_wave_type(
	FILE		*file,
	const char	*mesg1,
	int		w_type,
	const char	*mesg2,
	INTERFACE       *intfc)
{
	if (mesg1 != NULL)
	    (void) fprintf(file,"%s",mesg1);
	(void) fprintf(file,"%s",wave_type_as_string(w_type,intfc));
	if (mesg2 != NULL)
	    (void) fprintf(file,"%s",mesg2);
}		/*end f_fprint_wave_type*/
}}}
src/front/fprint.c
{{{
EXPORT  void    f_gview_plot_interface(
	const char *dname,
	INTERFACE  *intfc)
{
	RECT_GRID *gr = computational_grid(intfc);
	geomview_interface_plot(dname,intfc,gr);
}               /*end f_default_gview_plot_interface*/
}}}
src/front/fint.c
{{{
EXPORT	bool f_insert_point_in_bond(
	POINT		*p,
	BOND		*b,
	CURVE		*c)
{
	bool status = FUNCTION_FAILED;
	if (i_insert_point_in_bond(p,b,c) != FUNCTION_SUCCEEDED)
	    return status;
	switch (c->interface->dim)
	{
#if defined(TWOD)
	case 2:
	    status = f_user_2d_insert_point_in_bond(p,b,c);
	    break;
#endif /* defined(TWOD) */
#if defined(THREED)
	case 3:
	    status = f_user_3d_insert_point_in_bond(b);
	    break;
#endif /* defined(THREED) */
	}
	return status;
}		/*end f_insert_point_in_bond*/
}}}
src/front/fscat2d.c
{{{
/*
*		f_intfc_communication2d():
*
*	This function drives the interface communication.  Communication is
*	only performed if necessary.  Non-reflecting boundaries are processed
*	first.  One coordinate direction is considered at a time, and the
*	interface merged before going to the other direction.  Also, a
*	consistency check is performed on the components, which should catch
*	any errors made in the interface reconstruction.
*/

EXPORT bool f_intfc_communication2d(
	Front		*fr)
{
	COMPONENT	i_comp;
	INTERFACE	*intfc = fr->interf;
	INTERFACE	*sav_intfc;
	O_NODE		*onode_list;
	RECT_GRID	*gr = fr->rect_grid;
	double		coords[MAXD];
	bool		status = FUNCTION_SUCCEEDED;
	int		i, dir, dim = gr->dim;
	static bool	exists_refl[MAXD];
	static bool	exists_subd[MAXD];
	static int	**refl_lbuf = NULL, **refl_ubuf = NULL;
	static int	**subd_lbuf = NULL, **subd_ubuf = NULL;

	DEBUG_ENTER(f_intfc_communication2d)
	DEBUG_INTERFACE("Interface into f_intfc_communication2d()",
			intfc);

	if (refl_lbuf == NULL)
	{
	    bi_array(&refl_lbuf,MAXD,MAXD,INT);
	    bi_array(&refl_ubuf,MAXD,MAXD,INT);
	    bi_array(&subd_lbuf,MAXD,MAXD,INT);
	    bi_array(&subd_ubuf,MAXD,MAXD,INT);

	    for (dir = 0; dir < dim; ++dir)
	    {
	    	exists_subd[dir] = NO;
	    	exists_refl[dir] = NO;

	    	for (i = 0; i < dim; ++i)
	    	{
	    	    refl_lbuf[i][dir] = 0;
	    	    refl_ubuf[i][dir] = 0;

	    	    subd_lbuf[i][dir] = 0;
	    	    subd_ubuf[i][dir] = 0;
	    	}

	    	if (rect_boundary_type(intfc,dir,0) == SUBDOMAIN_BOUNDARY)
	    	{
	    	    exists_subd[dir] = YES;
	    	    subd_lbuf[dir][dir] = gr->lbuf[dir];
	    	}
	    	else if (rect_boundary_type(intfc,dir,0) == REFLECTION_BOUNDARY)
	    	{
	    	    exists_refl[dir] = YES;
	    	    refl_lbuf[dir][dir] = gr->lbuf[dir];
	    	}

	    	if (rect_boundary_type(intfc,dir,1) == SUBDOMAIN_BOUNDARY)
	    	{
	    	    exists_subd[dir] = YES;
	    	    subd_ubuf[dir][dir] = gr->ubuf[dir];
	    	}
	    	else if (rect_boundary_type(intfc,dir,1) == REFLECTION_BOUNDARY)
	    	{
	    	    exists_refl[dir] = YES;
	    	    refl_ubuf[dir][dir] = gr->ubuf[dir];
	    	}
	    }
	}

	sav_intfc = current_interface();
	set_current_interface(intfc);

	/* Find an interior component on this processor's domain.  This
	 * is needed to initialize the components on the subdomain
	 * boundaries when no physical curves appear on this processor. */

	for (i = 0; i < dim; ++i)
	    coords[i] = grid_center_coord(i,gr);
	i_comp = (intfc->modified) ?
	    long_component(coords,intfc) : component(coords,intfc);

	delete_subdomain_curves(intfc);
	delete_passive_boundaries(intfc);

	DEBUG_INTERFACE("Interface after delete subdomain and passive curves",
			intfc);

	for (dir = 0; dir < dim; ++dir)
	{
	    if (exists_subd[dir])
		status = perform_interface_communication(fr,subd_lbuf[dir],
							 subd_ubuf[dir],dir);
	    if (!status)
	    {
		(void) printf("WARNING in "
			      "f_intfc_communication2d(), "
		              " perform_interface_communication() failed "
		              "at subdomain boundary\n");
	    }
	    status = pp_min_status(status);
	    if (!status)
	    {
		set_current_interface(sav_intfc);
		DEBUG_LEAVE(f_intfc_communication2d)
		return status;
	    }
	}
	for (dir = 0; dir < dim; ++dir)
	{
	    if (exists_refl[dir])
	        status = perform_interface_communication(fr,refl_lbuf[dir],
							 refl_ubuf[dir],dir);
	    if (!status)
	    {
		(void) printf("WARNING in "
			      "f_intfc_communication2d(), "
		              "perform_interface_communication() failed "
		              "at reflection boundary\n");
	    }
	    status = pp_min_status(status);
	    if (!status)
	    {
		set_current_interface(sav_intfc);
		DEBUG_LEAVE(f_intfc_communication2d)
		return status;
	    }
	}
	status = delete_double_cut_curves(intfc);
	status = pp_min_status(status);
	if (status == FUNCTION_FAILED)
	{
	    (void) printf("First call of check_for_cut_nodes() failed\n");
	    (void) printf("Delete double cut nodes and try again.\n");
	    for (dir = 0; dir < dim; ++dir)
	    {
	    	if (exists_subd[dir])
		    status = perform_interface_communication(fr,subd_lbuf[dir],
							 subd_ubuf[dir],dir);
	    	if (!status)
	    	{
		    (void) printf("WARNING in "
			      "f_intfc_communication2d(), "
		              " perform_interface_communication() failed "
		              "at subdomain boundary\n");
	    	}
	    	status = pp_min_status(status);
	    	if (!status)
	    	{
		    set_current_interface(sav_intfc);
		    DEBUG_LEAVE(f_intfc_communication2d)
		    return status;
	    	}
	    }
	    for (dir = 0; dir < dim; ++dir)
	    {
	    	if (exists_refl[dir])
	            status = perform_interface_communication(fr,refl_lbuf[dir],
							 refl_ubuf[dir],dir);
	    	if (!status)
	    	{
		    (void) printf("WARNING in "
			      "f_intfc_communication2d(), "
		              "perform_interface_communication() failed "
		              "at reflection boundary\n");
	    	}
	    	status = pp_min_status(status);
	    	if (!status)
	    	{
		    set_current_interface(sav_intfc);
		    DEBUG_LEAVE(f_intfc_communication2d)
		    return status;
	    	}
	    }
	}

	/* TODO:  a post-processing loop is needed here to shift the
	 * subdomain nodes onto VL.  A problem can occur for periodic 
	 * boundaries on restart, where some accuracy is lost in VL or VU,
	 * so that the subdomains have different sizes on each side of the
	 * domain.  This will leave the curves hanging over the edge on the
	 * shorter side, and these nodes will not be processed when
	 * creating the subdomain boundary.
	 * A better solution would be to guarantee the location of the
	 * virtual boundaries, perhaps by printing them out as an integer
	 * multiple of the mesh spacing instead of an absolute (double)
	 * value. */

	status = set_subdomain_boundary(fr,i_comp);
	if (!status)
	{
	    (void) printf("WARNING in f_intfc_communication2d(), "
	                  "set_subdomain_boundary() failed\n");
	    if (DEBUG)
	    {
	    	(void) printf("Offending interface: \n");
	    	print_interface(fr->interf);
	    }
	}

	/* The following code is intended to tell whether the scatter
	 * succeeded by identifying problems/inconsistencies in the
	 * new interface. */

	if (check_for_cut_nodes(intfc))
	{
	    status = FUNCTION_FAILED;
#if defined(USE_OVERTURE)
            (void) printf("WARNING in f_intfc_communication2d(), "
                   "check_for_cut_nodes() detected cut node on "
		   "patch[%d], level[%d]\n",fr->patch_number, fr->patch_level);
            clean_up(ERROR);
#else
	    (void) printf("WARNING in f_intfc_communication2d(), "
	                  "check_for_cut_nodes() detected cut node\n");
#endif /* if defined(USE_OVERTURE) */
	}
	else if (check_comps_at_nodes(fr->interf,&onode_list) != 0)
	{
	    status = FUNCTION_FAILED;
	    (void) printf("WARNING in f_intfc_communication2d(), "
	                  "check_comps_at_nodes() detected inconsistency\n");
	    if (DEBUG)
	    {
		print_onode_list(&onode_list);
		(void) printf("Offending interface\n");
		print_interface(fr->interf);
	    }
	}
	status = pp_min_status(status);
	if (status == FUNCTION_FAILED) 
	{
	    set_current_interface(sav_intfc);
	    DEBUG_INTERFACE("Interface after f_intfc_communication2d()",intfc);
	    DEBUG_LEAVE(f_intfc_communication2d)
	    return status;
	}

	/* Zero length bonds can be produced, especially on an elliptic
	 * interface.  If this happens AT a node, the component check gets
	 * confused because it computes an angle for each  curve at a node
	 * using only the node position and the adjacent point.  
	 * The operation should be places after checking nodes consistency
	 *                          Xiaolin Li 6/29/09 */

#if defined(USE_OVERTURE)
        /* The flag use_delete_short_bonds is set to be NO
         * only in assembly_distribute_patch_fronts(),
         * before scatter the glued interfaces.
         */
        if(use_delete_short_bonds == YES)
            intfc_delete_very_short_bonds(fr);
        else
           use_delete_short_bonds = YES;
#else /* if defined(USE_OVERTURE) */
        intfc_delete_very_short_bonds(fr);
#endif /* if defined(USE_OVERTURE) */

	set_current_interface(sav_intfc);

	DEBUG_INTERFACE("Interface after f_intfc_communication2d()",intfc);
	DEBUG_LEAVE(f_intfc_communication2d)
	return status;
}		/*end f_intfc_communication2d*/
}}}
src/front/fint.h
{{{
EXPORT CURVE *f_make_curve(
	COMPONENT	left_c,
	COMPONENT	right_c,
	NODE		*start,
	NODE		*end)
{
	CURVE		*curve;

	curve = i_make_curve(left_c,right_c,start,end);

	if (curve == NULL) 
	    return NULL;
	switch (curve->interface->dim)
	{
	case 2:
	    curve = f_user_2d_make_curve(curve);
	    break;
	case 3:
	    break;
	}
	curve_tangent(curve) = NULL;
	curve_tangent_name(curve) = NULL;
	return curve;
}		/*end f_make_curve*/
}}}
src/front/fint.h
{{{
EXPORT HYPER_SURF *f_make_hypersurface(
	COMPONENT	neg_comp,
	COMPONENT	pos_comp)
{
	HYPER_SURF	*hs = i_make_hypersurface(neg_comp,pos_comp);

	wave_type(hs) = ERROR;
	/* Defaults for Hs_flag(hs) */
	do_not_redistribute(hs)                 = NO;
	never_redistribute(hs)                  = NO;
	untracked_hyper_surf(hs)                = NO;
	redistribute_by_time_step_frequency(hs) = YES;
	redistribute_hyper_surface(hs)          = NO;
	perform_redistribution_function(hs) =
	    default_perform_redistribution_function(hs->interface);
	redistribution_direction(hs) = FORWARD_REDISTRIBUTION;
	hypersurface_normal(hs) = NULL;
	hypersurface_normal_name(hs) = NULL;
	hs_copied_from(hs) = NULL;
	hs_copied_to(hs) = NULL;

	return hs;
}		/*end f_make_hypersurface*/
}}}
src/front/fint.h
{{{
EXPORT	POINT *f_make_point(
	double		*coords,
	COMPONENT	left_c,
	COMPONENT	right_c)
{
	POINT		*p;

	if ((p = i_make_point(coords,left_c,right_c)) == NULL)
	    return NULL;

	bstate_index(p) = -1;
	return p;
}		/*end f_make_point*/
}}}
src/front/fnode.c
{{{
EXPORT int f_node_propagate(
	Front		*fr,
	POINTER		p2wave,
	NODE		*oldn,
	NODE		*newn,
	RPROBLEM	**rp,
	float		dt,
	float		*dt_frac,
	NODE_FLAG	flag,
	POINTER		user)
{
	int		status = ERROR_NODE;
	int		i, dim = fr->rect_grid->dim;

	debug_print("node_propagate","Entered f_node_propagate()\n");

#if defined(DEBUG_NODE_PROPAGATE)
	if (debugging("node_propagate")) print_node(oldn);
#endif /* defined(DEBUG_NODE_PROPAGATE) */

	if (oldn != NULL && oldn->in_curves==NULL && oldn->out_curves==NULL) 
	{
	    status = GOOD_NODE;
	    return status;
	}

		/* Propagate node according to its type */

	switch (node_type(newn)) 
	{
	case PASSIVE_NODE:
	    assign_states_on_passive_curves_at_node(newn);
	    status = GOOD_NODE;
	    propagation_status(newn) = PROPAGATED_NODE;
	    for (i = 0; i < dim; i++)
	        Node_vel(newn)[i] = 0.0;
	    break;

	case FIXED_NODE:
	    /* There is no need for this.   XL 08-7-27
	    if (is_virtual_fixed_node(newn))
	        status = pp_node_propagate(fr,p2wave,oldn,newn,rp,dt,dt_frac);
	    else
	    */
	    status = fixed_node_propagate(fr,p2wave,oldn,newn,dt);
	    break;

	case SUBDOMAIN_NODE:
	    status = pp_node_propagate(fr,p2wave,oldn,newn,rp,dt,dt_frac);
	    break;

	case CLOSED_NODE:
	    status = closed_node_propagate(fr,p2wave,oldn,newn,dt);
	    break;

	case DIRICHLET_NODE:
	    status = B_node_propagate(fr,p2wave,oldn,newn,rp,dt,dt_frac,flag);
	    break;

	case NEUMANN_NODE: 
	    status = B_node_propagate(fr,p2wave,oldn,newn,rp,dt,dt_frac,flag);
	    break;

	default:
	    screen("ERROR in f_node_propagate(), "
	           "unknown node type %d\n",node_type(newn));
	    clean_up(ERROR);
	    break;
	}

	debug_print("node_propagate","Left f_node_propagate(), \n");
#if defined(DEBUG_NODE_PROPAGATE)
	if (debugging("node_propagate")) print_node(newn);
#endif /* defined(DEBUG_NODE_PROPAGATE) */
	return status;
}	/*end f_node_propagate*/
}}}
src/front/fprop2d.c
{{{
LOCAL void f_second_order_intfc_propagate2d(
	Front		*fr,
	POINTER		wave,
	INTERFACE	*old_intfc,
	INTERFACE	*new_intfc,
	double		dt)
{
	INTERFACE	*tmp_intfc;
	HYPER_SURF              *oldhs, *tmphs, *newhs;
        HYPER_SURF_ELEMENT      *oldhse, *tmphse, *newhse;
	CURVE              	**oldc, **tmpc, **newc;
        BOND      		*oldb, *tmpb, *newb;
        POINT                   *oldp, *tmpp, *newp;
	int		i;
	double		V[MAXD];

	set_copy_intfc_states(NO);
	tmp_intfc = pp_copy_interface(fr->interf);

	/* Compute v(x^n, t^n) */

	for (oldc = old_intfc->curves, tmpc = tmp_intfc->curves;
	     oldc && *oldc; ++oldc, ++tmpc)
	{
	    for (oldb = (*oldc)->first, tmpb = (*tmpc)->first;
		 oldb != NULL; oldb = oldb->next, tmpb = tmpb->next)
	    {
		if (oldb == (*oldc)->last && !is_closed_node((*oldc)->end))
		    continue;
		oldp = oldb->end;	tmpp = tmpb->end;
		oldhse = Hyper_surf_element(oldb);
		oldhs = Hyper_surf(*oldc);
	    	point_propagate(fr,wave,oldp,tmpp,oldhse,oldhs,dt,V);
	    }
	}

	/* Compute v(x^(n+1), t^(n+1)) */

	for (newc = new_intfc->curves, tmpc = tmp_intfc->curves;
	     newc && *newc; ++newc, ++tmpc)
	{
	    for (newb = (*newc)->first, tmpb = (*tmpc)->first;
		 newb != NULL; newb = newb->next, tmpb = tmpb->next)
	    {
		tmpp = tmpb->end;	newp = newb->end;
		tmphse = Hyper_surf_element(tmpb);
		tmphs = Hyper_surf(*tmpc);
	    	point_propagate(fr,wave,tmpp,newp,tmphse,tmphs,dt,V);
	    }
	}

	/* Compute x^(n+1) = x^n + 0.5*dt*(v(x^n,t^n) + v(x^(n+1), t^(n+1)) */

	for (oldc = old_intfc->curves, tmpc = tmp_intfc->curves, 
	     newc = new_intfc->curves;
	     oldc && *oldc; ++oldc, ++tmpc, ++newc)
	{
	    for (oldb = (*oldc)->first, tmpb = (*tmpc)->first,
		 newb = (*newc)->first; oldb != NULL; 
		 oldb = oldb->next, tmpb = tmpb->next, newb = newb->next)
	    {
		oldp = oldb->end;	
		tmpp = tmpb->end;	
		newp = newb->end;
	    	for (i = 0; i < 2; ++i)
	    	    Coords(newp)[i] = Coords(oldp)[i] + 0.5*(oldp->vel[i] +
					tmpp->vel[i])*dt;
		if (newb == (*newc)->last && is_closed_node((*newc)->end))
		{
		    propagation_status((*newc)->end) = PROPAGATED_NODE;
		    set_bond_length((*newc)->first,2);
		    set_bond_length((*newc)->last,2);
		}
		else
		    set_bond_length(newb,2);
	    }
	}

	delete_interface(tmp_intfc);
}	/* end f_second_order_intfc_propagate2d */
}}}
src/front/fuserintfc.c
{{{
LOCAL bool f_set_boundary1d(
        INTERFACE       *intfc,
        RECT_GRID       *gr,
        COMPONENT       default_comp,
        double           eps)
{
        bool            status;
        bool            sav_copy = copy_intfc_states();
        POINT           **p;

        set_copy_intfc_states(NO);
        status = i_set_boundary1d(intfc,gr,default_comp,eps);
        for (p = intfc->points; p && *p; ++p)
        {
            if (!is_bdry(*p)) continue;
            assign_boundary_point_wave_type(*p,intfc,gr,eps);
        }
        set_copy_intfc_states(sav_copy);
        return status;
}               /*end f_set_boundary1d*/
}}}
src/front/fsub.c
{{{
/*
*			f_set_default_front_parameters():
*
*	Sets default values for most fields in the front structure.  Fields
*	not initialized in this function are indicated by comments below.  As
*	of this writing, the order below reflects the declaration of the Front
*	structure in fdecs.h as much as possible.
*	Note: this function assumes that fr->rect_grid->dim and fr->sizest
*	have already been set.
*/

EXPORT	void	f_set_default_front_parameters(
	INIT_DATA	*init,
	Front		*fr)
{
	int		 dim = fr->rect_grid->dim;

	F_USER_INTERFACE *fuh = f_user_hook(dim);

	/*
	 * Remark: set_advance_front uses the value of Tracking_algorithm(fr)
	 * to select the appropriate advance_front function (in 3D)
	 * so the default value of this flag must be set prior to calling
	 * set_advance_front.
	 */
	Tracking_algorithm(fr) = (init != NULL) ?
	    tracking_algorithm(init) : NO_DYNAMIC_TRACKING;
	set_advance_front(init,fr);

	fr->_free_front =				f_free_front;
	fr->_copy_front =				f_copy_front;
	fr->_copy_into_front =				f_copy_into_front;

	fr->_print_Front_structure =			f_print_Front_structure;
	fr->_fprint_front =				f_fprint_front;
	fr->_read_print_front =				f_read_print_front;

#if defined(USE_OVERTURE)
        fr->_deep_free_front =                          f_deep_free_front;
        fr->_deep_copy_front =                          f_deep_copy_front;
#endif /* if defined(USE_OVERTURE) */

	/*	fr->sizest (assumed already set) */
	fr->_state_interpolator = linear_state_interpolator;
	fr->_tri_state_interpolator = linear_tri_state_interpolator;
	fr->transform_state =				NULL;

	fr->_is_correspondence_possible =		NULL; 

	/*	fr->Redist */
	Node_redistribute_function(fr) =		NULL;

	fr->max_front_time_step =			f_max_front_time_step;
	/*	fr->_MaxFrontSpeed  (see below) */
	/*	fr->Tstep */

	/*	fr->dt */
	/*	fr->dt_frac */
	/*	fr->time */
	/*	fr->step */

	fr->hyperbolic =				FULL_STATES;
	/*	fr->npts_tan_sten */
	fr->init_topology_of_new_interface =		NULL;
	f_wave_capture(fr) =				NULL;
	fr->_init_propagate =				NULL;
	fr->curve_propagate =				NULL; 
	fr->node_propagate =				NULL; 
	/*	fr->_point_propagate */
	fr->bond_propagate =				NULL;
	fr->snd_node_propagate =			NULL; 
	fr->tan_curve_propagate =			NULL; 
	/*	fr->_npt_tang_solver */
	/*	fr->_one_side_npt_tang_solver */
	fr->impose_bc =					NULL;

	fr->_untrack_point = NULL;
	fr->_untrack_curve = NULL;
	fr->_untrack_surface = NULL;

	switch (dim)
	{
	case 1:
	    fr->fr_bdry_untangle =		NULL;
	    fr->_check_delete_redundant_node =	NULL;
	    fr->_replace_unphys_loop = 		NULL;
	    fr->_untrack_point =		f_untrack_point;
	    break;
	case 2:
	    if (init != NULL)
	        set_tangent_operator(tangent_method(init),dim);
	    fr->_check_delete_redundant_node =	NULL;
	    fr->fr_bdry_untangle =		f_boundary_untangle;
	    fr->_replace_unphys_loop = 		f_replace_unphys_loop;
	    Rect_boundary_redistribute_function(fr) = rect_bdry_redist2d;
	    fr->_untrack_curve =		f_untrack_curve;
	    fr->curve_propagate =		f_curve_propagate2d; 
	    fr->node_propagate = 		f_node_propagate;
	    fr->untangle_front =		scalar_unravel; 
	    fr->grid_based_untangle =		f_grid_based_untangle;
	    fr->intfc_propagate =		NULL; 
	    break;
	case 3:
	    if (init != NULL)
	    {
	        set_normal3d_method(normal3d_method(init),dim);
		
	    	/* Who did this and for what?
		if (fr->interf != NULL)
		    f_user_interface(fr->interf) = *fuh;
	    	*/
	    }
	    if (debugging("no_tan_prop"))
	        fr->_tan_point_propagate =		NULL;
	    else
	        fr->_tan_point_propagate =		f_tan_point_propagate;
	    fr->_check_delete_redundant_node =	NULL;
	    fr->fr_bdry_untangle =		NULL;
	    fr->_replace_unphys_loop = 		NULL;
	    fr->_reconstruct_front_at_grid_crossing =
	        	rebuild_intfc_at_crossings3d;
	    fr->_repair_front_at_grid_crossing =
                        repair_intfc_at_crossings3d;
	    fr->_untrack_surface =		f_untrack_surface;
	    fr->surface_propagate =		f_surface_propagate; 
	    break;
	}

	fr->fr_vec_bdry_untangle =			NULL; 
	fr->B_node_bifurcation =			NULL; 
	fr->twodrproblem =				f_2drproblem; 
	fr->identify_physical_node =		f_identify_physical_node; 
	fr->init_2drproblem =				f_init_2drproblem; 
	fr->phys_split_bdry_cross =			NULL; 
	fr->phys_set_node_types =			NULL; 
	fr->parallel_refl_vec_wave =			NULL;

	fr->tan_curve_propagate =			NULL; 
	fr->_fgraph_front_states =			NULL; 
	fr->_fgraph_curve_states =			NULL; 
	fr->_fprint_header_for_graph_curve_states =	NULL; 
	fr->_find_i_to_prop_dir =			NULL;

	fr->neumann_bdry_state =			NULL;
	fr->_find_i_to_prop_dir = 			NULL;
	fr->is_nzn_bdry =				NULL;

	fr->_alloc_state = fuh->_alloc_state;
	fr->_clear_state = fuh->_clear_state;
	fr->_obstacle_state = fuh->_obstacle_state;

	MaxFrontSpeed(fr) = (init != NULL) ? InitialMaxFrontSpeed(init) : NULL;

	/*      fr->nfloats */
	fr->print_state =				NULL;
	fr->_fgraph_front_states =			NULL;
	fr->_fprint_header_for_graph_curve_states = 	NULL;
	fr->_fgraph_curve_states =			NULL;
	fr->mass_consv_diagn_driver =			NULL;

	fr->head_fsr =					AddToFsrList(NULL);

	/*	fr->FDIVIDER */
	/*	fr->interf */

}		/*end f_set_default_front_parameters*/
}}}
src/front/fuserintfc.c
{{{
EXPORT	void f_set_interface_hooks(
	int		dim,
	INIT_DATA       *init)
{
	I_USER_INTERFACE *iuh = i_user_hook(dim);
	F_USER_INTERFACE *fuh = f_user_hook(dim);
	int	         i;

	/* Front extended structure sizes */
	iuh->size_interface = sizeof(F_INTERFACE);
	iuh->size_point = sizeof(F_POINT);
	iuh->size_curve = sizeof(F_CURVE);
	iuh->size_node = sizeof(F_NODE);
	iuh->size_hyper_surf = sizeof(F_HYPER_SURF);
	iuh->size_hyper_surf_bdry = sizeof(F_HYPER_SURF_BDRY);
	switch (dim)
	{
	case 1:
	    break;
	case 2:
	    break;
	case 3:
	    iuh->size_bond_tri = sizeof(F_BOND_TRI);
	    break;
	}

	/* Front extended function pointers */
	iuh->_read_boundary_type_from_string = f_read_wave_type_from_string;
	iuh->_fprint_boundary_type = f_fprint_wave_type;
	iuh->_user_make_interface = f_user_make_interface;
	iuh->_copy_interface = f_copy_interface;
	iuh->_user_read_print_interface = f_user_read_print_interface;
	iuh->_user_fprint_interface = f_user_fprint_interface;
	iuh->_delete_interface = f_delete_interface;
	iuh->_user_fprint_intfc_rect_grids = f_user_fprint_intfc_rect_grids;
	iuh->_user_read_print_intfc_rect_grids =
	    f_user_read_print_intfc_rect_grids;
	iuh->_Point = f_Point;
	iuh->_Static_point = f_Static_point;
	iuh->_average_points = f_average_points;
	iuh->_copy_point = f_copy_point;
	iuh->_reconstruct_interface_pointers = f_reconstruct_interface_pointers;
	iuh->_fset_hyper_surf_color = f_fset_hyper_surf_color;
	iuh->_zoom_interface = f_zoom_interface;
	iuh->_reflect_point = f_reflect_point;
	iuh->_make_hypersurface = f_make_hypersurface;
	iuh->_user_copy_hyper_surf = f_user_copy_hyper_surf;
	iuh->_make_hypersurface_boundary = f_make_hypersurface_boundary;
	iuh->_make_node = f_make_node;
	iuh->_copy_node = f_copy_node;
	iuh->_delete_node = f_delete_node;
	iuh->_user_fprint_node = f_user_fprint_node;
	iuh->_user_read_node = f_user_read_node;
	iuh->_user_read_print_node = f_user_read_print_node;
	iuh->_make_curve = f_make_curve;
	iuh->_copy_curve = f_copy_curve;
	iuh->_delete_curve = f_delete_curve;
	iuh->_user_fprint_curve = f_user_fprint_curve;
	iuh->_user_read_curve = f_user_read_curve;
	iuh->_user_read_print_curve = f_user_read_print_curve;
	iuh->_user_split_curve = f_user_split_curve;
	iuh->_user_join_curves = f_user_join_curves;
	iuh->_insert_point_in_bond = f_insert_point_in_bond;
	iuh->_delete_start_of_bond = f_delete_start_of_bond;
	iuh->_delete_end_of_bond = f_delete_end_of_bond;
	iuh->_reconstruct_point_pointers = f_reconstruct_point_pointers;
	iuh->_reconstruct_node_pointers = f_reconstruct_node_pointers;
	iuh->_reconstruct_bond_pointers = f_reconstruct_bond_pointers;
	iuh->_reconstruct_curve_pointers = f_reconstruct_curve_pointers;
	iuh->_invert_curve = f_invert_curve;
	iuh->_reverse_curve = f_reverse_curve;
	iuh->_is_subdomain_boundary = f_is_subdomain_boundary;
	iuh->_cross_tolerance = f_cross_tolerance;
	iuh->_receive_interface = f_receive_interface;
	switch (dim)
	{
	case 1:
	    iuh->_make_point = f_make_point;
	    iuh->_set_boundary = f_set_boundary1d;
	    break;
	case 2:
	    iuh->_reflect_node = f_reflect_node2d;
	    iuh->_reflect_curve = f_reflect_curve2d;
	    iuh->_attach_curve_to_node = f_attach_curve_to_node;
	    iuh->_move_closed_loop_node = f_move_closed_loop_node;
	    iuh->_is_subdomain_node = f_is_subdomain_node;
	    iuh->_is_virtual_fixed_node = f_is_virtual_fixed_node;
	    iuh->_set_boundary = f_set_boundary2d;
	    break;
	case 3:
	    iuh->_reflect_surface = f_reflect_surface;
	    iuh->_CBond = f_CBond;
	    iuh->_insert_point_in_tri = f_insert_point_in_tri;
	    iuh->_insert_point_in_tri_side = f_insert_point_in_tri_side;
	    iuh->_link_tri_to_bond = f_link_tri_to_bond;
	    iuh->_reverse_bond = f_reverse_bond;
	    iuh->_reorder_curve_link_list = f_reorder_curve_link_list;
	    iuh->_join_surfaces = f_join_surfaces;
	    iuh->_make_surface = f_make_surface;
	    iuh->_copy_surface = f_copy_surface;
	    iuh->_delete_surface = f_delete_surface;
	    iuh->_user_fprint_surface = f_user_fprint_surface;
	    iuh->_user_read_surface = f_user_read_surface;
	    iuh->_user_read_print_surface = f_user_read_print_surface;
	    iuh->_user_install_faces = f_user_install_faces;
	    iuh->_assign_curve_boundary_flag = f_assign_curve_boundary_flag;
	    iuh->_set_boundary = f_set_boundary3d;
	    iuh->_gview_plot_interface = f_gview_plot_interface;
	    iuh->_consistent_interface = f_consistent_interface;
	    iuh->_sort_bond_tris = f_sort_bond_tris;
            //#bjet2
	    iuh->_assign_btri_states = f_assign_btri_states;
	    iuh->_detach_one_surface = f_detach_one_surface;
	    break;
	}

	/* Allocated boundary state array */
	fuh->_num_bstates = 6;
	uni_array(&fuh->_bstates,fuh->_num_bstates+1,sizeof(BOUNDARY_STATE*));
	++fuh->_bstates;
	for (i = -1; i < fuh->_num_bstates; ++i)
	    fuh->_bstates[i] = NULL;
}		/*end f_set_interface_hooks*/
}}}
src/front/fprop3d.c
{{{
EXPORT void f_surface_propagate(
	Front 		*front, 
	Front 		*newfront, 
	POINTER		wave,
	float		dt,
	float		*V)
{
	INTERFACE 		*intfc_old = front->interf;
	INTERFACE		*intfc_new = newfront->interf;
	HYPER_SURF		*oldhs, *newhs;
	HYPER_SURF_ELEMENT 	*oldhse, *newhse;
	POINT			*oldp, *newp;
	DEBUG_ENTER(f_surface_propagate)

	start_clock("surface_propagate");
	(void) next_point(intfc_old,NULL,NULL,NULL);
	(void) next_point(intfc_new,NULL,NULL,NULL);
	while (next_point(intfc_old,&oldp,&oldhse,&oldhs) && 
	       next_point(intfc_new,&newp,&newhse,&newhs))
	{	
	    point_propagate(front,wave,oldp,newp,oldhse,oldhs,dt,V);
		 	
	    if (Boundary_point(newp))
	    {
		Locstate newsl,newsr;
		
		slsr(newp,newhse,newhs,&newsl,&newsr);
		ft_assign(newsl,left_state(newp),front->sizest);
		ft_assign(newsr,right_state(newp),front->sizest);
	    }
	}	

	stop_clock("surface_propagate");
	DEBUG_LEAVE(f_surface_propagate)
}		/*end f_surface_propagate*/
}}}
src/front/fint.c
{{{
LOCAL	bool f_user_2d_insert_point_in_bond(
	POINT		*p,
	BOND		*b,
	CURVE		*c)
{
	BOND		*bnew;
	Locstate	start_left_state,start_right_state;
	Locstate	end_left_state,end_right_state;
	float		len,total_len,para;
	INTERFACE	*intfc;

	bnew = b->next;
	intfc = current_interface();
	if (interpolate_intfc_states(intfc) && size_of_state(intfc) != 0)
	{
	    if (b->prev == NULL)
	    {
	    	start_left_state = left_start_state(c);
	    	start_right_state = right_start_state(c);
	    }
	    else
	    {
	    	start_left_state = left_state(b->start);
	    	start_right_state = right_state(b->start);
	    }
	    if (bnew->next == NULL)
	    {
	    	end_left_state = left_end_state(c);
	    	end_right_state = right_end_state(c);
	    }
	    else
	    {
	    	end_left_state = left_state(bnew->end);
	    	end_right_state = right_state(bnew->end);
	    }
	    len = bond_length(b);
	    total_len = len + bond_length(bnew);
	    para = (total_len > 0.0) ? len/total_len : 0.5;
	    bi_interpolate_intfc_states(intfc,1.0-para,para,
			                Coords(b->start),start_left_state,
			                Coords(bnew->end),end_left_state,
			                left_state(b->end));
	    bi_interpolate_intfc_states(intfc,1.0-para,para,
			                Coords(b->start),start_right_state,
			                Coords(bnew->end),end_right_state,
			                right_state(b->end));
	}
	return FUNCTION_SUCCEEDED;
}		/*end f_user_2d_insert_point_in_bond*/
}}}
src/front/fint.c
{{{
LOCAL	CURVE	*f_user_2d_make_curve(
	CURVE		*curve)
{
	size_t		sizest;
	INTERFACE	*intfc = curve->interface;

	if ((sizest = size_of_state(intfc)) != 0)
	{
	    left_start_state(curve) = alloc_intfc_state(intfc,sizest);
	    left_end_state(curve) = alloc_intfc_state(intfc,sizest);
	    right_start_state(curve) = alloc_intfc_state(intfc,sizest);
	    right_end_state(curve) = alloc_intfc_state(intfc,sizest);
	    if (right_end_state(curve) == NULL)
	        return NULL;
	}
	else 
	{
	    left_start_state(curve) = NULL;
	    left_end_state(curve) = NULL;
	    right_start_state(curve) = NULL;
	    right_end_state(curve) = NULL;
	}
	if (!rst_cor_after_make_hyper_surf(Hyper_surf(curve)))
	    return NULL;
	bstate_index(curve) = -1;
	if (is_mono_comp_curve(curve))
	    mono_comp_curves(curve->interface) = YES;
	return curve;
}		/*end f_user_2d_make_curve*/
}}}
src/front/fint.h
{{{
EXPORT	void f_user_fprint_curve(
	FILE		*file,
	CURVE		*curve)
{
	switch (curve->interface->dim) 
	{ 
	case 1: 
	    return; 
	case 2:
	    fprint_wave_type(file,"\n\tcurve->wave_type = ",
			     wave_type(curve),"\n",curve->interface);
            /* FIXME. Implementation of bool is compiler dependent. */
	    fprintf(file,"\tHs_flag(curve) = %d\n",Hs_flag(curve));
	    fprint_redistribution_direction(file,
					    "\n\tredistribution_direction = ",
					    redistribution_direction(curve),
					    "\n");
	    (void) fprintf(file,"\tSpecialized curve normal function = ");
	    if (hypersurface_normal(curve))
	        (void) fprintf(file,"%s\n",hypersurface_normal_name(curve));
	    else
	        (void) fprintf(file,"none\n");
	    if (wave_type(curve) == MOVABLE_BODY_BOUNDARY)
            {
                (void) fprintf(file,"\tBody index = ");
                (void) fprintf(file,"%d\n",body_index(Hyper_surf(curve)));
                (void) fprintf(file,"\tTotal mass = ");
                (void) fprintf(file,"%"FFMT"\n",total_mass(Hyper_surf(curve)));
                (void) fprintf(file,"\tMoment of inertial = ");
                (void) fprintf(file,"%"FFMT"\n",
                                mom_inertial(Hyper_surf(curve)));
                (void) fprintf(file,"\tCenter of Mass = ");
                (void) fprintf(file,"%"FFMT" %"FFMT"\n",
                                center_of_mass(Hyper_surf(curve))[0],
                                center_of_mass(Hyper_surf(curve))[1]);
                (void) fprintf(file,"\tAngular velocity = ");
                (void) fprintf(file,"%"FFMT"\n",
                                angular_velo(Hyper_surf(curve)));
                (void) fprintf(file,"\tCenter of mass velocity = ");
                (void) fprintf(file,"%"FFMT" %"FFMT"\n",
                                center_of_mass_velo(Hyper_surf(curve))[0],
                                center_of_mass_velo(Hyper_surf(curve))[1]);
                (void) fprintf(file,"\tMotion type = %d\n",
                               motion_type(Hyper_surf(curve)));
	    }
	    break;
	case 3:
	    fprint_hsbdry_type(file,"\n\tHypersurface boundary type = ",
			       hsbdry_type(curve),"\n",curve->interface);
	    break; 
	}
	(void) fprintf(file,"\tSpecialized curve tangent function = ");
	if (curve_tangent_name(curve))
	    (void) fprintf(file,"%s\n",curve_tangent_name(curve));
	else
	    (void) fprintf(file,"none\n");
}		/*end f_user_fprint_curve*/
}}}
src/front/fint.h
{{{
EXPORT	void	f_user_fprint_interface(
	FILE		*file,
	INTERFACE	*intfc)
{
	int		i;
	int		print_bstates = NO;

	(void) fprintf(file,"\n");
	(void) foutput(file);
	(void) fprintf(file,"Interface normal and tangent operators\n");
	(void) fprintf(file,"Interface normal function = %s\n",
	               interface_normal_name(intfc));
	(void) fprintf(file,"Interface tangent function = %s\n",
	               interface_tangent_name(intfc));
	(void) fprintf(file,"End interface normal and tangent operators\n");

	for (i = 0; i < num_bstates(intfc); ++i)
	{
	    if (bstate_list(intfc)[i] != NULL)
	    {
	    	print_bstates = YES;
	    	break;
	    }
	}

	(void) fprintf(file,"\n");
	if (print_bstates)
	{
	    BOUNDARY_STATE *bstate;

	    (void) foutput(file);
	    (void) fprintf(file,"Boundary state data for interface %llu\n",
		                interface_number(intfc));
	    (void) fprintf(file,"num_bstates = %d\n",num_bstates(intfc));
	    for (i = 0; i < num_bstates(intfc); ++i)
	    {
		bstate = bstate_list(intfc)[i];
		if (bstate != NULL)
		{
	    	    (void) fprintf(file,"Boundary state data for index %d\n",i);
		    (*bstate->_fprint_boundary_state_data)(file,intfc,bstate);
	    	    (void) fprintf(file,
				  "\nEnd Boundary state data for index %d\n",i);
		}
		else
	    	    (void) fprintf(file,
				"No boundary state data for index %d\n",i);
	    }
	    (void) foutput(file);
	    (void) fprintf(file,"End Boundary state data for interface %llu\n",
		    interface_number(intfc));
        }

	(void) fprintf(file,"\n");
	(void) foutput(file);
	(void) fprintf(file,"Excluded Components List:\n");
	(void) fprintf(file,"Number of excluded components = %d\n",
		       excluded_comps(intfc).ncomps);
	for (i = 0; i < excluded_comps(intfc).ncomps; ++i)
	    (void) fprintf(file,"Excluded component %d = %d\n",i,
			   excluded_comps(intfc).comps[i]);
	(void) foutput(file);
	(void) fprintf(file,"End Excluded Components List:\n");
	f_fprint_Dirichlet_bdry_states(file,intfc);
}		/*end f_user_fprint_interface*/
}}}
src/front/fint.h
{{{
EXPORT	void	f_user_fprint_surface(
	FILE		*file,
	SURFACE		*s)
{
	fprint_wave_type(file,"\n\tsurface->wave_type = ",
		         wave_type(s),"\n",s->interface);
	(void) fprintf(file,"\tSpecialized surface normal function = ");
	if (hypersurface_normal(s))
	    (void) fprintf(file,"%s\n",hypersurface_normal_name(s));
	else
	    (void) fprintf(file,"none\n");
}		/*end f_user_fprint_surface*/
}}}
src/front/fuserintfc.c
{{{
EXPORT	F_USER_INTERFACE *f_user_hook(
	int		dim)
{
	static F_USER_INTERFACE Fuser_hooks[3];
	static bool first = YES;

	if (first == YES)
	{
	    int i;
	    static F_INTERFACE_TOLERANCES Itol;

	    first = NO;

	    /* Set default values for F_INTERFACE_TOLERANCES */
	    Itol._DtReductionFac      = 0.8;

	    /* Set default values for Fuser_hooks fields*/

	    /* fields valid for all dimensions */

	    for (i = 0; i < 3; ++i)
	    {
	        zero_scalar(&Fuser_hooks[i]._computational_grid,
			    sizeof(RECT_GRID));
	        Fuser_hooks[i]._bstates = NULL;
	        Fuser_hooks[i]._num_bstates = 0;
	        Fuser_hooks[i]._first_node = 0;
	        Fuser_hooks[i]._last_node = 0;
	        Fuser_hooks[i]._sizest = 0;
	        Fuser_hooks[i]._interpolate_intfc_states = NO;
	        Fuser_hooks[i]._mono_comp_curves = NO;
	        Fuser_hooks[i]._fprint_wave_type = f_fprint_wave_type;
	        Fuser_hooks[i]._wave_type_as_string = f_wave_type_as_string;
	        Fuser_hooks[i]._read_wave_type_from_string =
		    f_read_wave_type_from_string;
	        Fuser_hooks[i]._bi_interpolate_intfc_states =
		    linear_state_interpolator;
	        Fuser_hooks[i]._fprint_state_data = f_fprint_state_data;
	        Fuser_hooks[i]._read_print_state_data = f_read_print_state_data;
	        Fuser_hooks[i]._nearest_intfc_state = f_nearest_intfc_state;
	        Fuser_hooks[i]._reflect_state = f_reflect_state;
	        Fuser_hooks[i]._fprint_intfc_state = f_fprint_intfc_state;
	        Fuser_hooks[i]._alloc_state = f_alloc_state;
	        Fuser_hooks[i]._alloc_intfc_state = f_alloc_intfc_state;
	        Fuser_hooks[i]._clear_state = f_clear_state;
	        Fuser_hooks[i]._obstacle_state = f_clear_state;
	        Fuser_hooks[i]._FInterfaceTolerances = Itol;
	        Fuser_hooks[i]._default_perform_redistribution_function =
		    f_perform_redistribution;
	        Fuser_hooks[i]._merge_hs_flags = f_merge_hs_flags;
	        Fuser_hooks[i]._interface_tangent_function._tangent = f_tangent;
	        Fuser_hooks[i]._interface_tangent_function._tangent_name =
		    strdup("f_tangent");
	        Fuser_hooks[i]._set_tangent_function = f_set_tangent_function;
	        Fuser_hooks[i]._set_normal_function = f_set_normal_function;
	        Fuser_hooks[i]._alloc_MaxFrontSpeed = f_alloc_MaxFrontSpeed;
	    }

	    /* fields valid for both 2D and 3D */
	    for (i = 1; i < 3; ++i)
	    {
	        Fuser_hooks[i]._fprint_hsbdry_type = f_fprint_hsbdry_type;
	        Fuser_hooks[i]._read_hsbdry_type_from_string =
		    f_read_hsbdry_type_from_string;
	        Fuser_hooks[i]._tri_interpolate_intfc_states =
		    linear_tri_state_interpolator;
	        Fuser_hooks[i]._read_print_boundary_state_data =
		    f_read_print_boundary_state_data;
	    }

	    /* Dimension specific fields */
	    Fuser_hooks[0]._fprint_hsbdry_type = NULL;
	    Fuser_hooks[0]._read_hsbdry_type_from_string = NULL;
	    Fuser_hooks[0]._slsr = slsr1d;
	    Fuser_hooks[0]._tri_interpolate_intfc_states = NULL;
	    Fuser_hooks[0]._state_along_hypersurface_element = state_at_point;
	    Fuser_hooks[0]._form_subintfc_via_communication =
			f_intfc_communication1d;
	    Fuser_hooks[0]._fshow_intfc_states = f_fshow_intfc_states1d;

	    Fuser_hooks[0]._mean_curvature_at_point = NULL;
	    Fuser_hooks[0]._interface_normal_function._normal = normal1d;
	    Fuser_hooks[0]._interface_normal_function._normal_name =
	        	strdup("normal1d");

	    Fuser_hooks[1]._slsr = slsr2d;
	    Fuser_hooks[1]._state_along_hypersurface_element = state_along_bond;
	    Fuser_hooks[1]._form_subintfc_via_communication =
			f_intfc_communication2d;

	    Fuser_hooks[1]._fshow_intfc_states = f_fshow_intfc_states2d;
	    Fuser_hooks[1]._mean_curvature_at_point =
			f_wlsp_curvature;
	    Fuser_hooks[1]._interface_normal_function._normal = 
			f_wlsp_normal;
	    Fuser_hooks[1]._interface_normal_function._normal_name =
	        	strdup("first_order_normal2d");

	    Fuser_hooks[2]._slsr = slsr3d;
	    Fuser_hooks[2]._state_along_hypersurface_element = state_in_tri;
	    Fuser_hooks[2]._form_subintfc_via_communication =
			f_intfc_communication3d;
	    Fuser_hooks[2]._fshow_intfc_states = f_fshow_intfc_states3d;
	    Fuser_hooks[2]._mean_curvature_at_point =
			f_wlsp_curvature;
	    Fuser_hooks[2]._interface_normal_function._normal =
	        	f_wlsp_normal;
	    Fuser_hooks[2]._interface_normal_function._normal_name =
	        	strdup("f_wlsp_normal");
	}
	if (dim < 1 || dim > 3)
	{
	    screen("ERROR in f_user_hook(), invalid dim %d\n",dim);
	    clean_up(ERROR);
	    return NULL;
	}
	else
	    return Fuser_hooks + dim - 1;
}		/*end f_user_hook*/
}}}
src/front/fint.c
{{{
EXPORT	void	f_user_make_interface(
	INTERFACE	*intfc)
{
	F_USER_INTERFACE *fuh;
	int		dim;

	dim = intfc->dim;
	fuh = f_user_hook(dim);
	f_user_interface(intfc) = *fuh;
	size_of_state(intfc) = size_of_intfc_state;
	set_size_of_intfc_state(0);
}		/*end f_user_make_interface*/
}}}
src/front/fgb3dutil.c
{{{
EXPORT	void  fill_comp_with_component3d(
	int      *smin,
        int      *smax,
        int      *gmax,
        INTERFACE *intfc)
{
	Table		*T = table_of_interface(intfc);
	COMPONENT 	*comp = T->components;
	RECT_GRID	*gr = &topological_grid(intfc);
	int 		i, ip[3];
	float           coords[3], *L=gr->L, *h=gr->h;
	float		nodetol = 1.0e-8;
	bool		status;
	
	DEBUG_ENTER(fill_comp_with_component3d)

	intfc->modified = NO;

	for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
	{
	    for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
	    {
                for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
		{
		    if (comp[d_index3d(ip[0],ip[1],ip[2],gmax)] == NO_COMP)
		    {
			//DEBUG_TMP print_int_vector("fill_comp_with_component3d, ip=", ip, 3, "\n");
			
			//L[i] + h[i]*ip[i]  is the corner of a block, it can make component3d unstable.
			for (i = 0; i < 3; i++)
			    coords[i] = L[i] + h[i]*(ip[i] + nodetol);

			//if((ip[0] == 2 && ip[1] == 20 && ip[2] == 2 && pp_mynode() == 7) ||
			//   (ip[0] == 22 && ip[1] == 20 && ip[2] == 2 && pp_mynode() == 6))
			//    add_to_debug("fill_comp");
		        
			comp[d_index3d(ip[0],ip[1],ip[2],gmax)] =
				          component(coords,intfc);
			//remove_from_debug("fill_comp");

			//DEBUG_TMP print_general_vector("coords=", coords, 3, "\n");
			//DEBUG_TMP printf("comp = %d\n", comp[d_index3d(ip[0],ip[1],ip[2],gmax)]);
		    }
		}
	    }
	}
	status = check_and_unset_bad_comp(smin,smax,intfc);
	
	//if (debugging("crx_intfc"))
	if(NO && !status)
	{
	    printf("After fill_comp_with_component3d, bad comps are found.\n");
	    show_grid_components(smin,smax,2,intfc);
	}
	
	DEBUG_LEAVE(fill_comp_with_component3d)
}
}}}
src/front/fgb3dutil.c
{{{
EXPORT	void fill_physical_comps(
        int      *smin,
        int      *smax,
        int      *gmax,
        INTERFACE *intfc)
{
	int 		k,l,nc,list,step,i;
	int 		ip[3];
	float           coords[3], *L, *h;
	Table		*T = table_of_interface(intfc);
	COMPONENT 	*comp = T->components;
	int		*ef = T->edge_flag;
	COMPONENT 	cn;
	CRXING          *crx;
	bool		status;
	RECT_GRID	gr = topological_grid(intfc);

	DEBUG_ENTER(fill_physical_comps)
	
	L = gr.L;
	h = gr.h;

	if (intfc->surfaces == NULL  ||  
	    is_outside_surfaces(intfc,&gr) ||
	    T->n_crx == 0)
	{
	    printf("#fill phy no surfs  %d  %d  %d, default_comp = %d \n", 
		intfc->surfaces, is_outside_surfaces(intfc,&gr), 
		T->n_crx, intfc->default_comp); 

	    for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
	        for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
	            for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
	    	        comp[d_index3d(ip[0],ip[1],ip[2],gmax)] = intfc->default_comp;
	    
	    DEBUG_LEAVE(fill_physical_comps)
	    return;
	}
	for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
	{
	    for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
	    {
		for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
		{
		    if (comp[d_index3d(ip[0],ip[1],ip[2],gmax)] == NO_COMP)
		    {
			// if smin[0] or smax[0] is not NO_COMP, walk... will fill 
			//comp in direction, if for example smin[0] is NO_COMP, two case.
			//(1) edge has no crx, need to continue because code can not determine
			//the component.
			//(2) edge has one crx, smin[0]+1 will determine the component, and walk..
			//will fill the comp at sin[0]
			if(ip[0] == smin[0] || ip[0] == smax[0])
				continue;

		    	k = seg_index3d(ip[0],ip[1],ip[2],WEST,gmax);
			if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			    continue;

		    	nc = T->seg_crx_count[k];
		    	if (nc == 0)
			{
		    	    k = seg_index3d(ip[0],ip[1],ip[2],EAST,gmax);
			    if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			        continue;
		    	    nc = T->seg_crx_count[k];
		    	    if (nc == 0)
		    	    	continue;
		    	    list = T->seg_crx_lists[k][0];
		    	    crx = T->crx_store+list;
		    	    comp[d_index3d(ip[0],ip[1],ip[2],gmax)] 
			    			= crx->lcomp;
			}
			else
			{
		    	    list = T->seg_crx_lists[k][nc-1];
		    	    crx = T->crx_store+list;
		    	    comp[d_index3d(ip[0],ip[1],ip[2],gmax)] 
			    			= crx->ucomp;
			}
			

		    }

		    if (ip[0] != 0)
		    {
	            	cn = comp[d_index3d(ip[0]-1,ip[1],ip[2],gmax)];
		    	if (cn == NO_COMP)
			{
			    step = walk_comp_along_grid_line(intfc,smin,smax,
					                     gmax,ip,WEST);
			}
		    }
		    if (ip[0] != smax[0])
		    {
	            	cn = comp[d_index3d(ip[0]+1,ip[1],ip[2],gmax)];
		    	if (cn == NO_COMP)
		    	{
			    step = walk_comp_along_grid_line(intfc,smin,smax,
					                     gmax,ip,EAST);
			    ip[0] += step;
		    	}
		    }
		}
	    }
	}
	
	if(debugging("tst_comp3d1"))
	{
 	    printf("#inside comp x af\n");
	    show_grid_components(smin,smax,2,intfc);
	}

	status = check_and_unset_bad_comp(smin,smax,intfc);
	

	if (status == YES)
	{
	    if (debugging("crx_intfc"))
	    {
	        printf("After first check: status = %d\n",status);
	        show_grid_components(smin,smax,2,intfc);
	    }
	    DEBUG_LEAVE(fill_physical_comps)
	    return;
	}
	for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
	{
	    for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
	    {
	    	for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
		{
		    if (comp[d_index3d(ip[0],ip[1],ip[2],gmax)] == NO_COMP)
		    {
			if(ip[1] == smin[1] || ip[1] == smax[1])
				continue;

		    	k = seg_index3d(ip[0],ip[1],ip[2],SOUTH,gmax);
			if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			    continue;
		    	nc = T->seg_crx_count[k];
		    	if (nc == 0)
			{
		    	    k = seg_index3d(ip[0],ip[1],ip[2],NORTH,gmax);
			    if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			        continue;
		    	    nc = T->seg_crx_count[k];
		    	    if (nc == 0)
		    	    	continue;
		    	    list = T->seg_crx_lists[k][0];
		    	    crx = T->crx_store+list;
		    	    comp[d_index3d(ip[0],ip[1],ip[2],gmax)] 
			    			= crx->lcomp;
			}
			else
			{
		    	    list = T->seg_crx_lists[k][nc-1];
		    	    crx = T->crx_store+list;
		    	    comp[d_index3d(ip[0],ip[1],ip[2],gmax)] 
			    			= crx->ucomp;
			}
		    }

		    if (ip[1] != 0)
		    {
	            	cn = comp[d_index3d(ip[0],ip[1]-1,ip[2],gmax)];
		    	if (cn == NO_COMP)
			    step = walk_comp_along_grid_line(intfc,smin,smax,
					                     gmax,ip,SOUTH);
		    }
		    if (ip[1] != smax[1])
		    {
	            	cn = comp[d_index3d(ip[0],ip[1]+1,ip[2],gmax)];
		    	if (cn == NO_COMP)
		    	{
			    step = walk_comp_along_grid_line(intfc,smin,smax,
					                     gmax,ip,NORTH);
			    ip[1] += step;
		    	}
		    }
		}
	    }
	}
	
	if(debugging("show_3c_comp"))
	{
 	    printf("#inside comp y bf\n");
	    show_grid_components(smin,smax,2,intfc);
	}

	status = check_and_unset_bad_comp(smin,smax,intfc);
	
	if(debugging("show_3c_comp"))
	{
 	    printf("#inside comp y af\n");
	    show_grid_components(smin,smax,2,intfc);
	}
	
	if (status == YES)
	{
	    if (debugging("crx_intfc"))
	    {
	        printf("After second check: status = %d\n",status);
	        show_grid_components(smin,smax,2,intfc);
	    }
	    DEBUG_LEAVE(fill_physical_comps)
	    return;
	}
	for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
	{
	    for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
	    {
	        for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
		{
		    if (comp[d_index3d(ip[0],ip[1],ip[2],gmax)] == NO_COMP)
		    {
		        if(ip[2] == smin[2] || ip[2] == smax[2])
				continue;

		    	k = seg_index3d(ip[0],ip[1],ip[2],LOWER,gmax);
			if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			    continue;
		    	nc = T->seg_crx_count[k];
		    	if (nc == 0)
			{
		    	    k = seg_index3d(ip[0],ip[1],ip[2],UPPER,gmax);
			    if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			        continue;
		    	    nc = T->seg_crx_count[k];
		    	    if (nc == 0)
		    	    	continue;
		    	    list = T->seg_crx_lists[k][0];
		    	    crx = T->crx_store+list;
		    	    comp[d_index3d(ip[0],ip[1],ip[2],gmax)] 
			    			= crx->lcomp;
			}
			else
			{
		    	    list = T->seg_crx_lists[k][nc-1];
		    	    crx = T->crx_store+list;
		    	    comp[d_index3d(ip[0],ip[1],ip[2],gmax)] 
			    			= crx->ucomp;
			}
		    }

		    if (ip[2] != 0)
		    {
	            	cn = comp[d_index3d(ip[0],ip[1],ip[2]-1,gmax)];
		    	if (cn == NO_COMP)
			    step = walk_comp_along_grid_line(intfc,smin,smax,
					                     gmax,ip,LOWER);
		    }
		    if (ip[2] != smax[2])
		    {
	            	cn = comp[d_index3d(ip[0],ip[1],ip[2]+1,gmax)];
		    	if (cn == NO_COMP)
		    	{
			    step = walk_comp_along_grid_line(intfc,smin,smax,
					                     gmax,ip,UPPER);
			    ip[2] += step;
		    	}
		    }
		}
	    }
	}
	
	if(debugging("show_3c_comp"))
	{
 	    printf("#inside comp z af\n");
	    show_grid_components(smin,smax,2,intfc);
	}
	
	status = check_and_unset_bad_comp(smin,smax,intfc);
	
	if (status == YES)
	{
	    if (debugging("crx_intfc"))
	    {
	        printf("After third check: status = %d\n",status);
	        show_grid_components(smin,smax,2,intfc);
	    }
	    DEBUG_LEAVE(fill_physical_comps)
	    return;
        }

        for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
	{
	    for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
	    {
	        for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
		{
		    if (comp[d_index3d(ip[0],ip[1],ip[2],gmax)] == NO_COMP)
		    {
		        if(ip[0] == smin[0] || ip[0] == smax[0])
				continue;

		        k = seg_index3d(ip[0],ip[1],ip[2],WEST,gmax);
			if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			    continue;
			nc = T->seg_crx_count[k];
			if (nc == 0)
			{
			    k = seg_index3d(ip[0],ip[1],ip[2],EAST,gmax);
			    if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			        continue;
			    nc = T->seg_crx_count[k];
			    if (nc == 0)
			        continue;
			    list = T->seg_crx_lists[k][0];
			    crx = T->crx_store+list;
			    comp[d_index3d(ip[0],ip[1],ip[2],gmax)]
			                        = crx->lcomp;
			}
			else
			{
			    list = T->seg_crx_lists[k][nc-1];
			    crx = T->crx_store+list;
			    comp[d_index3d(ip[0],ip[1],ip[2],gmax)]
			                        = crx->ucomp;
			}
		    }

		    if (ip[0] != 0)
		    {
		        cn = comp[d_index3d(ip[0]-1,ip[1],ip[2],gmax)];
			if (cn == NO_COMP)
			    step = walk_comp_along_grid_line(intfc,smin,smax,
			                                     gmax,ip,WEST);
		    }
		    if (ip[0] != smax[0])
		    {
		        cn = comp[d_index3d(ip[0]+1,ip[1],ip[2],gmax)];
			if (cn == NO_COMP)
			{
			    step = walk_comp_along_grid_line(intfc,smin,smax,
			                                     gmax,ip,EAST);
			    ip[0] += step;
			}
		    }
		}
	    }
	}
	status = check_and_unset_bad_comp(smin,smax,intfc);
	
	if(debugging("show_3c_comp"))
	{
 	    printf("#inside comp x1 af\n");
	    show_grid_components(smin,smax,2,intfc);
	}
	
	if (status == YES)
	{
	    DEBUG_LEAVE(fill_physical_comps)
	    return;
	}
	for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
	{
	    for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
            {
	        for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
		{
		    if (comp[d_index3d(ip[0],ip[1],ip[2],gmax)] == NO_COMP)
		    {
		 	if(ip[1] == smin[1] || ip[1] == smax[1])
				continue;

		        k = seg_index3d(ip[0],ip[1],ip[2],SOUTH,gmax);
			if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			    continue;
			nc = T->seg_crx_count[k];
			if (nc == 0)
			{
			    k = seg_index3d(ip[0],ip[1],ip[2],NORTH,gmax);
			    if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			        continue;
			    nc = T->seg_crx_count[k];
			    if (nc == 0)
			        continue;
			    list = T->seg_crx_lists[k][0];
			    crx = T->crx_store+list;
			    comp[d_index3d(ip[0],ip[1],ip[2],gmax)]
			                        = crx->lcomp;
			}
			else
			{
			    list = T->seg_crx_lists[k][nc-1];
			    crx = T->crx_store+list;
			    comp[d_index3d(ip[0],ip[1],ip[2],gmax)]
			                        = crx->ucomp;
			}
		    }

		    if (ip[1] != 0)
		    {
		        cn = comp[d_index3d(ip[0],ip[1]-1,ip[2],gmax)];
			if (cn == NO_COMP)
			    step = walk_comp_along_grid_line(intfc,smin,smax,
			                                     gmax,ip,SOUTH);
		    }
		    if (ip[1] != smax[1])
		    {
		        cn = comp[d_index3d(ip[0],ip[1]+1,ip[2],gmax)];
			if (cn == NO_COMP)
			{
			    step = walk_comp_along_grid_line(intfc,smin,smax,
			                                     gmax,ip,NORTH);
			    ip[1] += step;
			}
		    }
		}
	    }
	}
	status = check_and_unset_bad_comp(smin,smax,intfc);
	
	if(debugging("show_3c_comp"))
	{
 	    printf("#inside comp y1 af\n");
	    show_grid_components(smin,smax,2,intfc);
	}

	if (status == YES)
	{
	    DEBUG_LEAVE(fill_physical_comps)
	    return;
        }
	for (ip[1] = smin[1]; ip[1] <= smax[1]; ++ip[1])
	{
	    for (ip[0] = smin[0]; ip[0] <= smax[0]; ++ip[0])
	    {
	        for (ip[2] = smin[2]; ip[2] <= smax[2]; ++ip[2])
		{
		    if (comp[d_index3d(ip[0],ip[1],ip[2],gmax)] == NO_COMP)
		    {
		 	if(ip[2] == smin[2] || ip[2] == smax[2])
				continue;

		         k = seg_index3d(ip[0],ip[1],ip[2],LOWER,gmax);
			 if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			     continue;
			 nc = T->seg_crx_count[k];
			 if (nc == 0)
		         {
			     k = seg_index3d(ip[0],ip[1],ip[2],UPPER,gmax);
			     if(use_wall_edge()  &&  ef[k] != INSIDE_WALL)
			         continue;
			     nc = T->seg_crx_count[k];
			     if (nc == 0)
			         continue;
			     list = T->seg_crx_lists[k][0];
                             crx = T->crx_store+list;
			     comp[d_index3d(ip[0],ip[1],ip[2],gmax)]
			                         = crx->ucomp;
			 }
		    }

		    if (ip[2] != 0)
		    {
		        cn = comp[d_index3d(ip[0],ip[1],ip[2]-1,gmax)];
			if (cn == NO_COMP)
			    step = walk_comp_along_grid_line(intfc,smin,smax,
			                                     gmax,ip,LOWER);
		    }

		    if (ip[2] != smax[2])
		    {
		        cn = comp[d_index3d(ip[0],ip[1],ip[2]+1,gmax)];
			if (cn == NO_COMP)
			{
			    step = walk_comp_along_grid_line(intfc,smin,smax,
			                                     gmax,ip,UPPER);
			    ip[2] += step;
			}
		    }
		}
	    }	    
	}
       	
        status = check_and_unset_bad_comp(smin,smax,intfc);
 	
	if(debugging("tst_comp3d1"))
	{
 	    printf("#inside comp z1 af\n");
	    show_grid_components(smin,smax,2,intfc);
	    //clean_up(0);
	}
	
	DEBUG_LEAVE(fill_physical_comps)
	
}	/* end fill_physical_comps */
}}}
src/front/fprop3d.c
{{{
EXPORT  void first_order_point_propagate(
        Front *front,
        POINTER wave,
        POINT *oldp,
        POINT *newp,
        HYPER_SURF_ELEMENT *oldhse,
        HYPER_SURF         *oldhs,
        float              dt,
        float              *V)
{
        float vel[MAXD],s;
        int i, dim = front->rect_grid->dim;

        if (wave_type(oldhs) < FIRST_PHYSICS_WAVE_TYPE)
        {
            for (i = 0; i < dim; ++i)
	    {
                Coords(newp)[i] = Coords(oldp)[i];
	    }
            return;
        }

        (*front->vfunc)(front->vparams,front,oldp,oldhse,oldhs,vel);
        for (i = 0; i < dim; ++i)
        {
            Coords(newp)[i] = Coords(oldp)[i] + dt*vel[i];
            set_max_front_speed(i,fabs(vel[i]),NULL,Coords(newp),front);
        }
	s = mag_vector(vel,dim);
	set_max_front_speed(dim,s,NULL,Coords(newp),front);
}       /* first_order_point_propagate */
}}}
liquid/liquid.c
{{{
static  void fluid_driver(
        Front *front,
	L_CARTESIAN &l_cartesian)
{
        int ip,im;
        Front *newfront;
        double dt_frac,CFL,tmp;
	bool is_print_time,is_movie_time,time_limit_reached;
	int i,dim = front->rect_grid->dim;

	Curve_redistribution_function(front) = full_redistribute;

	FrontReadTimeControlInfo(in_name,front);
	CFL = Time_step_factor(front);

	if (RestartRun)
	{
	    FrontScatIntfcBuffer(front);
	}
	else
	{
	    FrontRedistMesh(front);
            front->time = 0.0;
            front->dt = 0.0;
            front->step = 0; 
	}

	if (RestartRun)
	    l_cartesian.readFrontInteriorStates(restart_state_name);
	else
	    l_cartesian.setInitialCondition();

        if (!RestartRun)
        {
            // Front standard output
            FrontPrintOut(front,out_name);
	    if (debugging("trace")) 
		printf("Calling initMovieVariable()\n");
	    l_cartesian.initMovieVariables();
	    if (debugging("trace")) 
		printf("Calling FrontMovieFrame()\n");
            FrontMovieFrame(front,out_name,binary);
	    l_cartesian.printFrontInteriorStates(out_name);
            
	    if (debugging("trace"))
		printf("Calling initial FrontAdvance()\n");
	    FrontMakeGridIntfc(front);
            FrontAdvance(front->dt,&dt_frac,front,&newfront,
                                (POINTER)NULL);
	    FrontFreeGridIntfc(front);
            assign_interface_and_free_front(front,newfront);
            
            ip = im = 1;
            front->dt = CFL*FrontHypTimeStep(front);
	    for (i = 0; i < dim; ++i)
	    	front->dt = min(front->dt,CFL*l_cartesian.top_h[i]);
            //for (i = 1; i < 3; ++i)
            //   front->dt = min(front->dt,CFL*l_cartesian.top_h[i]);
            //front->dt = min(front->dt,2.538*CFL*l_cartesian.top_h[0]);
        }
        else
        {
            ip = (int)(front->time/front->print_time_interval + 1.0);
            im = (int)(front->time/front->movie_frame_interval + 1.0);
        }

        front->dt = FrontOutputTimeControl(front,
                        &is_movie_time,&is_print_time,
                        &time_limit_reached,&im,&ip);

	if (debugging("trace"))
	{
	    printf("CFL = %f\n",CFL);
	    printf("Frequency_of_redistribution(front,GENERAL_WAVE) = %d\n",
			Frequency_of_redistribution(front,GENERAL_WAVE));
	}

	if (debugging("trace")) printf("Before time loop\n");
        for (;;)
        {
            /* Propagating interface for time step dt */

	    if (debugging("trace")) printf("Begin a time step\n");
	    FrontMakeGridIntfc(front);
	    if (debugging("trace")) printf("Passed FrontMakeGridIntfc()\n");
            FrontAdvance(front->dt,&dt_frac,front,&newfront,
                                (POINTER)NULL);
	    if (debugging("trace")) printf("Passed FrontAdvance()\n");
	    FrontFreeGridIntfc(front);
	    //if (debugging("trace")) printf("Passed FrontFreeGridIntfc()\n");
            //assign_interface_and_free_front(front,newfront);

	    if (debugging("trace")) printf("Begin calling solve()\n");
	    l_cartesian.solve(front->dt);
	    if (debugging("trace")) printf("Passed solve()\n");

            if (debugging("trace")) printf("Passed FrontFreeGridIntfc()\n");
            assign_interface_and_free_front(front,newfront);

            ++front->step;
            front->time += front->dt;
				
            //Next time step determined by maximum speed of previous
            //step, assuming the propagation is hyperbolic and
            //is not dependent on second order derivatives of
            //the interface such as curvature, and etc.

            front->dt = CFL*min(FrontHypTimeStep(front),l_cartesian.max_dt);
	
            /* Output section */

            printf("\ntime = %f   step = %5d   next dt = %f\n",
                        front->time,front->step,front->dt);
            fflush(stdout);

            if (is_print_time || time_limit_reached)
	    {
            	FrontPrintOut(front,out_name);
		l_cartesian.printFrontInteriorStates(out_name);
	    }
            if (is_movie_time || time_limit_reached)
	    {
	    	if (debugging("trace")) 
		    printf("Calling initMovieVariable()\n");
	        l_cartesian.initMovieVariables();
	    	if (debugging("trace")) 
		    printf("Calling FrontMovieFrame()\n");
            	FrontMovieFrame(front,out_name,binary);
	    }

            if (time_limit_reached)
                    break;

	    if (debugging("storage"))
	    {
		char s[100];
		sprintf(s,"Storage at end of time step %d",front->step);
		print_storage(s,"storage");
	    }
            front->dt = FrontOutputTimeControl(front,
                        &is_movie_time,
                        &is_print_time,
                        &time_limit_reached,
                        &im,&ip);
        }
	if (debugging("trace")) printf("After time loop\n");
}       /* end fluid_driver */
}}}
src/front/fuserhooks.c
{{{
EXPORT	bool	form_subintfc_via_communication(
	Front* fr)
{
	if (fr == NULL || fr->interf == NULL)
	    return FUNCTION_FAILED;
	return (*f_user_interface(fr->interf)._form_subintfc_via_communication)(fr);
}		/*end form_subintfc_via_communication*/
}}}
src/front/fprop3d.c
{{{
EXPORT void fourth_order_point_propagate(
        Front *front,
        POINTER wave,
        POINT *oldp,
        POINT *newp,
        HYPER_SURF_ELEMENT *oldhse,
        HYPER_SURF         *oldhs,
        float              dt,
        float              *V)
{
        float vel[MAXD],vm1[MAXD],vm2[MAXD],vm3[MAXD],s;
/* MAXD is set to 3 */
        int i, dim = front->rect_grid->dim;

        if (wave_type(oldhs) < FIRST_PHYSICS_WAVE_TYPE)
        {
            for (i = 0; i < dim; ++i)
	    {
                Coords(newp)[i] = Coords(oldp)[i];
	    }
            return;
        }

        /* Use fourth order Runge Kutta method */

        (*front->vfunc)(front->vparams,front,oldp,oldhse,oldhs,vel);
        for (i = 0; i < dim; ++i)
            Coords(newp)[i] = Coords(oldp)[i] + 0.5*dt*vel[i];
        (*front->vfunc)(front->vparams,front,newp,oldhse,oldhs,vm1);
        for (i = 0; i < dim; ++i)
            Coords(newp)[i] = Coords(oldp)[i] + 0.5*dt*vm1[i];
        (*front->vfunc)(front->vparams,front,newp,oldhse,oldhs,vm2);
        for (i = 0; i < dim; ++i)
            Coords(newp)[i] = Coords(oldp)[i] + dt*vm2[i];
        (*front->vfunc)(front->vparams,front,newp,oldhse,oldhs,vm3);

        for (i = 0; i < dim; ++i)
        {
            Coords(newp)[i] = Coords(oldp)[i] + dt*(vel[i] + 2.0*vm1[i]
                        +2.0*vm2[i] + vm3[i])/6.0;
            set_max_front_speed(i,fabs(vel[i]),NULL,Coords(newp),front);
        }
/* mag_vector, return 2-norm of vel */
	s = mag_vector(vel,dim);
	set_max_front_speed(dim,s,NULL,Coords(newp),front);
}       /* fourth_order_point_propagate */
}}}
src/intfc/iecomps.c
{{{
/*
*			fprint_comp_equiv_lists():
*
*	This function prints out the lists of equivalent components in 
*	intfc->e_comps.
*/

EXPORT void fprint_comp_equiv_lists(
	FILE      *file,
	INTERFACE *intfc)
{
	EQUIV_COMPS	*e_comps;
	int		i, n;

	(void) foutput(file);
	(void) fprintf(file,"Equivalent Component list for interface %llu\n",
		       interface_number(intfc));
	for (n=0, e_comps=E_comps(intfc); e_comps != NULL;
 	     e_comps=e_comps->next, ++n);
	(void) fprintf(file,"%d Equivalence classes\n",n);
	for (e_comps = E_comps(intfc); e_comps != NULL; e_comps = e_comps->next)
	{
	    if (e_comps->comp != NULL)
	    {
	        n = e_comps->n_equiv;
	        (void) fprintf(file,"    %d equivalent components ",n);
	        for (i = 0; i < n; ++i)
	    	    (void) printf(" %d",e_comps->comp[i]);
	        (void) printf("\n");
	    }
	    else
	        (void) fprintf(file,"    0 equivalent components\n");
	}
	(void) fprintf(file,"End Equivalent Component list for interface %llu\n",
		       interface_number(intfc));
}		/*end print_comp_equiv_list*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	void fprint_curve(
	FILE		*file,
	CURVE		*c)
{
	if (c == NULL || c->interface == NULL)
	    return;
	(*i_user_interface(c->interface)._fprint_curve)(file,c);
}		/*end fprint_curve*/
}}}
src/front/fprint.c
{{{
LOCAL 	void fprint_front_time_stamp(
	FILE *file,
	Front *front)
{
        if (file == NULL)
            return;
        (void) fprintf(file,"\n\n\n\n");
        (void) foutput(file);
        (void) fprintf(file,"\tTime Data:  t = %-"FFMT" j = %-10d dt = %-"FFMT"\n",
                       front->time,front->step,front->dt);	
}	/* end fprint_front_time_stamp */
}}}
src/inftc/userhooks.c
{{{
EXPORT	void fprint_interface(
	FILE		*file,
	INTERFACE	*intfc)
{
	if (intfc == NULL)
	    return;
	(*i_user_interface(intfc)._fprint_interface)(file,intfc);
}		/*end fprint_interface*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	void fprint_node(
	FILE		*file,
	NODE		*n)
{
	if (n == NULL || n->interface == NULL)
	    return;
	(*i_user_interface(n->interface)._fprint_node)(file,n);
}		/*end fprint_node*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	void fprint_surface(
	FILE		*file,
	SURFACE		*s)
{
	if (s == NULL || s->interface == NULL)
	    return;
	(*i_user_interface(s->interface)._fprint_surface)(file,s);
}		/*end fprint_surface*/
}}}
src/intfc/int3d.h
{{{
/*
*			fprint_triangle_numbers():
*
*	This routine prints the triangle and the information on its three
*	boundaries. If the boundary is a triangle, its index number is printed.
*	If it is a bond, the bond address is printed. It is assumed that the
*	index numbers are correctly stored in Tri_index(tri).
*/


LOCAL void fprint_triangle_numbers(
	FILE		*file,
	TRI		*tri)
{
	INTERFACE  *intfc = current_interface();
	POINT	   *p;
	int	   i, side;
	static const char *sideno[] = {"01", "12", "20"};

	if (tri == NULL)
	{
	    (void) fprintf(file,"NULL Triangle\n"); 
	    return;
	}
	(void) fprintf(file,"\tTri %d Borders",Tri_index(tri));
	for (side = 0; side < 3; ++side)
	{
	    if (is_side_bdry(tri,side))
	    {
		BOND_TRI *bt = Bond_tri_on_side(tri,side);
		if (bt == NULL)
		    (void) fprintf(file," Bond%s NULL",sideno[side]);
		else
	    	    (void) fprintf(file," Bond%s %llu",sideno[side],
				    bond_number(bt->bond,intfc));
	    }
	    else if (Tri_on_side(tri,side) == NULL)
		(void) fprintf(file," Tri%s NULL",sideno[side]);
	    else
		(void) fprintf(file," Tri%s %d",sideno[side],
			       Tri_index(Tri_on_side(tri,side)));

	}
	(void) fprintf(file," Boundary %d\n",Boundary_tri(tri));

	(void) fprintf(file,"\tPoints - Indices %-4d %-4d %-4d Positions",
		       Index_of_point(Point_of_tri(tri)[0]),
		       Index_of_point(Point_of_tri(tri)[1]),
		       Index_of_point(Point_of_tri(tri)[2]));
	if (is_binary_output() == YES)
	{
	    (void) fprintf(file,"\f%c",9);
	    for (i = 0; i < 3; ++i)
	    {
	    	p = Point_of_tri(tri)[i];
	    	(void) fwrite((const void *) Coords(p),FLOAT,3,file);
	    }
	}
	else
	{
	    static const char *fmt[] = {	" %-"FFMT" %-"FFMT" %-"FFMT" ->",
					        " %-"FFMT" %-"FFMT" %-"FFMT" ->",
					        " %-"FFMT" %-"FFMT" %-"FFMT};
	    for (i = 0; i < 3; ++i)
	    {
	    	p = Point_of_tri(tri)[i];
	    	(void) fprintf(file,fmt[i],
			       Coords(p)[0],Coords(p)[1],Coords(p)[2]);
	    }
	}
	(void) fprintf(file,"\n");
}		/*end fprint_triangle_numbers*/
}}}
src/intfc/int3d.c
{{{
/*
*			fprint_tris_on_curve():
*
*	This routine prints the bond addresses and for each bond,
*	the bounding tris in angle order.  The tris are printed in terms of
*	their index number in the double linked list (ie distance from first)
*	in the surface they belong to.	It is assumed that these index numbers 
*	are already set before this routine is called, by a call to 
*	set_tri_array_numbers for each surface in question.
*/

LIB_LOCAL void fprint_tris_on_curve(
	FILE		*file,
	CURVE		*curve)
{
	BOND		*b;
	BOND_TRI	**btris;
	char		s[20];
	int		i;
 
	(void) fprintf(file,"\n");
	b = curve->first;
	(void) fprintf(file,"\tOrdered tri indices\n");
	b = curve->first;
	(void) fprintf(file,"%-10s ","Bond");
	for (btris = Btris(b), i = 0; btris && *btris; ++btris, ++i)
	{
	    (void) sprintf(s,"btri[%d]",i);
	    (void) fprintf(file,"%-10s",s);
	}
	(void) fprintf(file,"\n");

	for (b = curve->first; b; b = b->next)
	{
	    (void) fprintf(file,"%-10llu ",bond_number(b,curve->interface));
	    for (btris = Btris(b); btris && *btris; ++btris)
	    	(void) fprintf(file,"%-10d ",Tri_index((*btris)->tri));
	    (void) fprintf(file,"\n");
	}
	(void) fprintf(file,"\n");
}		/*end fprint_tris_on_curve*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	void	fprint_wave_type(
	FILE* file,
	const char *mesg1,
	int        w_type,
	const char *mesg2,
	INTERFACE* intfc)
{
	if (intfc == NULL)
	    return;
	(*f_user_interface(intfc)._fprint_wave_type)(file,mesg1,w_type,
	                                             mesg2,intfc);
}		/*end fprint_wave_type*/
}}}
include:
* [[front/fdecs.h]]
----
Function prototype declarations for front directory
include:
* [[intfc/int.h]] [[front/frp.h]] [[front/fvelo.h]] [[front/fuserint.h]] [[front/fprotos.h]] 
if defined(USE_HDF)
* hdf.h mfhdf.h
----
This header file first defines enum values returned by some functions and flags indicating the front status
include
|[[front/fdecs.h]]|
Contains structures related to the solution of two dimensional Riemann problems.
include:
* [[front/fdecs.h]]
----
User Supplied Operations
include
none
Contains structures related to velocity functions
src/front/fredist2d.c
{{{
EXPORT bool full_redistribute(
	Front		*fr,
	bool		*force_redist)
{
	CURVE	**c;
	bool	status = YES;
	bool	force;
	int	redist_nodes;

	DEBUG_ENTER(full_redistribute)
	if (DEBUG)
	{
	    (void) printf("Unredistributed interface\n");
	    (void) printf("*force_redist = %s\n",y_or_n(*force_redist));
	    print_interface(fr->interf);
	}

	    /* Check on redistribution conditions */

	force = *force_redist;
	*force_redist = NO; /*set force_redist flag back to NO*/
	if (force)
	    redist_nodes = YES;
	else if (Redistribution_count(fr) < 0)
	    redist_nodes = NO;
	else
	    redist_nodes = redist_needed(fr,GENERAL_NODE);

	    /* Redistribute rect boundary curves */

	if (Use_rect_boundary_redistribution(fr))
	    rect_boundary_redistribute(fr->interf,fr->rect_grid,fr->step,fr);

	    /* Redistribute vector curves */

	for (c = fr->interf->curves; *c ; ++c) 
	{
	    if (perform_redistribution(*c,fr,force))
	    {
		switch (redistribution_direction(*c))
		{
		case FORWARD_REDISTRIBUTION:
	            status = Forward_curve_redistribute(fr,*c,status);
		    if (status)
		    {
		        redistributed(*c) = YES;
			redistribution_direction(*c) = BACKWARD_REDISTRIBUTION;
		    }
		    break;
		case BACKWARD_REDISTRIBUTION:
		    status = Backward_curve_redistribute(fr,*c,status);
		    if (status)
		    {
		        redistributed(*c) = YES;
			redistribution_direction(*c) = FORWARD_REDISTRIBUTION;
		    }
		    break;
		}
	    }
	}
	Redistribution_count(fr)++;

		/* Redistribute non-uni_array curves */

	if (redist_nodes)
	    status = Node_redistribute(fr,status);

	for (c = fr->interf->curves; *c ; ++c) 
	    if (redistributed(*c))
	        Interface_redistributed(fr) = YES;

	if (debugging("redistribute"))
	{
	    if (Interface_redistributed(fr))
	    {
	    	(void) printf("Redistributed interface\n");
	    	print_interface(fr->interf);
	    }
	    else
	    	(void) printf("Interface left unredistributed\n");
	}
	if (debugging("ck_b_len"))
	{
	    BOND *bb;
	    CURVE *cc;
	    float len;

	    (void) printf("Checking bond lengths after redistribution\n");
	    (void) next_bond(fr->interf,NULL,NULL);
	    while (next_bond(fr->interf,&bb,&cc))
	    {
	    	print_bond(bb);
	    	len = separation(bb->start,bb->end,fr->rect_grid->dim);
	    	(void) printf("Computed length = %g, "
	    	              "Computed length - bond_length = %g\n\n",
		              len,len - bond_length(bb));
	    }
	}
	DEBUG_LEAVE(full_redistribute)
	return status;
}		/*end full_redistribute*/
}}}
src/intfc/igview.c
{{{
EXPORT void geomview_interface_plot(
	const char *dname,
	INTERFACE  *intfc,
	RECT_GRID  *gr)
{
	double *BBL = topological_grid(intfc).GL;
	double *BBU = topological_grid(intfc).GU;

	if (intfc->dim != 3)
	    return;
	if (create_directory(dname,YES) == FUNCTION_FAILED)
	{
	    (void) printf("WARNING in geomview_interface_plot(), directory "
			  "%s doesn't exist and can't be created\n",dname);
	    return;
	}

	gview_plot_cube(dname,"grid",gr->L,gr->U,BBL,BBU);
	gview_plot_cube(dname,"vgrid",gr->VL,gr->VU,BBL,BBU);
	gview_plot_cube(dname,"ggrid",gr->GL,gr->GU,BBL,BBU);
	gview_plot_axes(dname,"axes",BBL,BBU,BBL,BBU);

	gview_plot_surfaces(intfc,gr,BBL,BBU,YES,dname,"surfs",
			    NO,pRED,pRED);

	gview_plot_surfaces(intfc,gr,BBL,BBU,YES,dname,"bdry",
			    YES,pBLUE,pGREEN);

	gview_plot_curves(intfc,BBL,BBU,dname,"curves",pYELLOW,5);
}		/*end geomview_interface_plot*/
}}}
src/front/foverture_adv.c
{{{
LOCAL   char   *get_list_file_name(
        char       *fname,
        const char *dname,
        const char *name,
        size_t     *fname_len)
{
        size_t len;
        if (dname == NULL)
            dname = "";
        len = strlen(dname)+1+strlen(name)+6;
        if (*fname_len < len)
        {
            *fname_len = len;
            if (fname != NULL)
                free(fname);
            uni_array(&fname,*fname_len,CHAR);
        }
        if (strlen(dname) != 0)
            (void) sprintf(fname,"%s/%s.list",dname,name);
        else
            (void) sprintf(fname,"%s.list",name);
        return fname;
}
}}}
src/intfc/igview.c
{{{
EXPORT	void	gview_bounding_box(
	FILE        *file,
	const double *BBL,
	const double *BBU,
	int         indent_level,
	const char  *indent)
{
	char bindent[256];
	char vfmt[256];
	int  i;

	bindent[0] = '\0';
	for (i = 0; i < indent_level; ++i)
	    (void) strcat(bindent,indent);

	(void) sprintf(vfmt,"%s%s%s\n",bindent,indent,"%-9g %-9g %-9g");
	/* Print bounding verticies */
	(void) fprintf(file,"%s{\n",bindent);
	(void) fprintf(file,"%s%sSKEL\n",bindent,indent);
	(void) fprintf(file,"%s%s%6d %6d\n",bindent,indent,8,8);
	(void) fprintf(file,vfmt,BBL[0],BBL[1],BBL[2]);
	(void) fprintf(file,vfmt,BBU[0],BBL[1],BBL[2]);
	(void) fprintf(file,vfmt,BBU[0],BBU[1],BBL[2]);
	(void) fprintf(file,vfmt,BBL[0],BBU[1],BBL[2]);
	(void) fprintf(file,vfmt,BBL[0],BBL[1],BBU[2]);
	(void) fprintf(file,vfmt,BBU[0],BBL[1],BBU[2]);
	(void) fprintf(file,vfmt,BBU[0],BBU[1],BBU[2]);
	(void) fprintf(file,vfmt,BBL[0],BBU[1],BBU[2]);
	for (i = 0; i < 8; ++i)
	    (void) fprintf(file,"%s%s%-9d %-9d %-9d\n",bindent,indent,2,i,i);
	(void) fprintf(file,"%s}\n",bindent);
}		/*end gview_bounding_box*/
}}}
src/intfc/igview.c
{{{
EXPORT	void	gview_plot_axes(
	const char  *dname,
	const char  *name,
	const double *L,
	const double *U,
	const double *BBL,
	const double *BBU)
{
	FILE              *file;
	static char       *fname = NULL;
	static size_t     fname_len = 0;
	static const char *indent = "    ";

	fname = get_list_file_name(fname,dname,name,&fname_len);

	if ((file = fopen(fname,"w")) == NULL)
	{
	    (void) printf("WARNING in gview_plot_axes(), "
	                  "can't open %s\n",fname);
	    return;
	}
	(void) fprintf(file,"{ LIST\n");

	gview_bounding_box(file,BBL,BBU,1,indent);

	/* Print Coordinate axes */
	(void) fprintf(file,"%s{\n",indent);
	(void) fprintf(file,"%s%sVECT\n",indent,indent);
	(void) fprintf(file,"%s%s%6d %6d %6d\n",indent,indent,3,6,3);
	(void) fprintf(file,"%s%s%6d %6d %6d\n",indent,indent,2,2,2);
	(void) fprintf(file,"%s%s%6d %6d %6d\n",indent,indent,1,1,1);
	(void) fprintf(file,"%s%s%-9g %-9g %-9g\n",
			    indent,indent,L[0],L[1],L[2]);
	(void) fprintf(file,"%s%s%-9g %-9g %-9g\n",
			    indent,indent,U[0],L[1],L[2]);
	(void) fprintf(file,"%s%s%-9g %-9g %-9g\n",
			    indent,indent,L[0],L[1],L[2]);
	(void) fprintf(file,"%s%s%-9g %-9g %-9g\n",
			    indent,indent,L[0],U[1],L[2]);
	(void) fprintf(file,"%s%s%-9g %-9g %-9g\n",
			    indent,indent,L[0],L[1],L[2]);
	(void) fprintf(file,"%s%s%-9g %-9g %-9g\n",
			    indent,indent,L[0],L[1],U[2]);
	(void) fprintf(file,"%s%s%6g %6g %6g %6g\n",
			    indent,indent,1.0,0.0,0.0,0.0);
	(void) fprintf(file,"%s%s%6g %6g %6g %6g\n",
			    indent,indent,0.0,1.0,0.0,0.0);
	(void) fprintf(file,"%s%s%6g %6g %6g %6g\n",
			    indent,indent,0.0,0.0,1.0,0.0);
	(void) fprintf(file,"%s}\n",indent);

	(void) fprintf(file,"}\n");
	(void) fclose(file);
}		/*end gview_plot_axes*/
}}}
src/intfc/igview.c
{{{
LOCAL void gview_plot_cube(
	const char *dname,
	const char *gname,
	const double *L,
	const double *U,
	const double *BBL,
	const double *BBU)
{
	FILE              *file;
	char              fmt[256];
	static const char *indent = "    ";
	static char       *fname = NULL;
	static size_t     fname_len = 0;

	fname = get_list_file_name(fname,dname,gname,&fname_len);

	if ((file = fopen(fname,"w")) == NULL)
	{
	    (void) printf("WARNING in gview_plot_cube(), "
	    	          "can't open %s\n",fname);
	    return;
	}
	(void) sprintf(fmt,"%s%s%s\n",indent,indent,
		                      "%-9g %-9g %-9g "
		                      "%-9g %-9g %-9g "
		                      "%-9g %-9g %-9g "
		                      "%-9g %-9g %-9g");
	(void) fprintf(file,"{ LIST\n");
	gview_bounding_box(file,BBL,BBU,1,indent);
	(void) fprintf(file,"%s{\n",indent);
	(void) fprintf(file,"%s%sQUAD\n",indent,indent);
	/* Lower face, z = L[2] */
	(void) fprintf(file,fmt,L[0],L[1],L[2],U[0],L[1],L[2],
				U[0],U[1],L[2],L[0],U[1],L[2]);
	/* Upper face, z = U[2] */
	(void) fprintf(file,fmt,L[0],L[1],U[2],U[0],L[1],U[2],
	                        U[0],U[1],U[2],L[0],U[1],U[2]);
	/* back face, x = L[0] */
	(void) fprintf(file,fmt,L[0],L[1],L[2],L[0],U[1],L[2],
	                        L[0],U[1],U[2],L[0],L[1],U[2]);
	/* front face, x = U[0] */
	(void) fprintf(file,fmt,U[0],L[1],L[2],U[0],U[1],L[2],
	                        U[0],U[1],U[2],U[0],L[1],U[2]);
	/* left face, y = L[1] */
	(void) fprintf(file,fmt,L[0],L[1],L[2],U[0],L[1],L[2],
	                        U[0],L[1],U[2],L[0],L[1],U[2]);
	/* right face, y = U[1] */
	(void) fprintf(file,fmt,L[0],U[1],L[2],U[0],U[1],L[2],
	                        U[0],U[1],U[2],L[0],U[1],U[2]);
	(void) fprintf(file,"%s}\n",indent);
	(void) fprintf(file,"}\n");

	(void) fclose(file);
}		/*end gview_plot_cube*/
}}}
src/intfc/igview.c
{{{
LOCAL   void    gview_plot_curves(
        INTERFACE     *intfc,
	const double   *BBL,
	const double   *BBU,
        const char    *dname,
        const char    *name,
	SURFACE_COLOR color,
	int	      width)
{
        FILE              *file;
        POINT             *ps, *pe;
        CURVE             **c;
        BOND              *b;
        static const char *indent = "    ";
        int               num_bonds,i;
	static char       *fname = NULL;
	static size_t     fname_len = 0;

	fname = get_list_file_name(fname,dname,name,&fname_len);

        if ((file = fopen(fname,"w")) == NULL)
        {
	    screen("WARNING in gview_plot_curves(), "
		   "can't open %s\n",fname);
	    return;
        }

        (void) fprintf(file,"{ LIST\n");

	gview_bounding_box(file,BBL,BBU,1,indent);

        for (c = intfc->curves; c && *c; ++c)
        {
            num_bonds = (*c)->num_points - 1;
            (void) fprintf(file,"%s{appearance{*linewidth %d}\n"
			   "%s%sVECT\n%s%s%6d %6d %6d\n",
			   indent,width,indent,indent,indent,indent,
			   num_bonds,2*num_bonds,1);
            /* may make for very long lines! */
            (void) fprintf(file,"%s%s",indent,indent);
            for (i = 0; i < num_bonds; ++i)
            {
                (void) fprintf(file,"2 ");
            }
            (void) fprintf(file,"\n");
            (void) fprintf(file,"%s%s1 ",indent,indent);
            for (i = 0; i < num_bonds - 1; ++i)
            {
                (void) fprintf(file,"0 ");
            }
            (void) fprintf(file,"\n");
            for (b = (*c)->first; b; b = b->next)
            {
                ps = b->start;
                pe = b->end;
                (void) fprintf(file,"%s%s%-9g %-9g %-9g %-9g %-9g %-9g\n",
			       indent,indent,Coords(ps)[0], Coords(ps)[1],
			       Coords(ps)[2],Coords(pe)[0],Coords(pe)[1],
			       Coords(pe)[2]);
            }
	    (void) fprintf(file,"%s%s",indent,indent);
	    write_color(file,color,0.75);
            (void) fprintf(file,"%s}\n",indent);
        }
        (void) fprintf(file,"}\n");
        fclose(file);
}               /*end gview_plot_curves*/
}}}
src/intfc/userhools.c
{{{
EXPORT	void gview_plot_interface(
	const char *dname,
	INTERFACE  *intfc)
{
	if (intfc == NULL)
	    return;
	(*i_user_interface(intfc)._gview_plot_interface)(dname,intfc);
}		/*end gview_plot_interface*/
}}}
src/intfc/igview.c
{{{
LOCAL	void	gview_plot_surfaces(
	INTERFACE     *intfc,
	RECT_GRID     *gr,
	const double   *BBL,
	const double   *BBU,
	bool          clip,
	const char    *dname,
	const char    *name,
	bool	      bdry,
	SURFACE_COLOR color1,
	SURFACE_COLOR color2)
{
	FILE	          *file;
	POINT             *p;
	SURFACE	          **s;
	TRI	          *tri;
	bool              plot_surf,plot_tri;
	double 	          D, intensity = .5;
	double             L[MAXD],U[MAXD],tol[MAXD];
	double	          *crds;
	int	          num_surfs, num_tris, i, j, k, l;
	int               npts, ntris, count = 0;
	static const char *indent = "    ";
	static double      *pts = NULL;
	static int        *verts = NULL;
	static int        alloc_len_verts = 0, alloc_len_pts = 0;
	static char       *fname = NULL;
	static size_t     fname_len = 0;

	fname = get_list_file_name(fname,dname,name,&fname_len);

	for (num_tris = 0, s = intfc->surfaces; s && *s; ++s)
	{
	    num_tris += (*s)->num_tri;
	    for (tri=first_tri(*s); !at_end_of_tri_list(tri,*s); tri=tri->next)
	    {
	        for (k = 0; k < 3; ++k)
		    Index_of_point(Point_of_tri(tri)[k]) = -1;
	    }
	}
	
	if (alloc_len_pts < 3*intfc->num_points)
	{
	    if (pts != NULL)
		free(pts);
	    alloc_len_pts = 3*intfc->num_points;
	    uni_array(&pts,alloc_len_pts,FLOAT);
	}
	if (alloc_len_verts < 4*num_tris)
	{
	    if (verts != NULL)
		free(verts);
	    alloc_len_verts = 4*num_tris;
	    uni_array(&verts,alloc_len_verts,INT);
	}
	for (i = 0; i < 3; i++)
	{
	    L[i] = gr->L[i] - 0.5*gr->h[i];
	    U[i] = gr->U[i] + 0.5*gr->h[i];
	    tol[i] = 0.00001*gr->h[i];
	}

        for (npts=0, ntris=0, num_surfs=0, s = intfc->surfaces; s && *s; ++s)
	{
	    if (bdry == YES  &&  !Boundary(*s))
		continue; 
	    if (bdry == NO  &&  Boundary(*s))
		continue;
	    if (clip == YES)
	    {
		plot_surf = NO;
	        for (tri = first_tri(*s); !at_end_of_tri_list(tri,*s); 
		     tri = tri->next)
	        {
		    plot_tri = NO;
		    for (k = 0; k < 3; ++k)
		    {
			crds = Coords(Point_of_tri(tri)[k]);
	                for (l = 0; l < 3; ++l)
			    if ((crds[l] < L[l] - tol[l]) || 
			        (crds[l] > U[l] + tol[l]))
				break;
			if (l == 3) /* a point is inside the domain */
			{
			    plot_tri = plot_surf = YES;
			    break;
		        }
		    }
		    if (plot_tri)
		    {
			for (k = 0; k < 3; ++k)
			{
		            p = Point_of_tri(tri)[k];
			    if (Index_of_point(p) == -1)
			    {
			        crds = Coords(p);
	                        for (l = 0; l < 3; ++l)
				    pts[3*npts+l] = crds[l];
				Index_of_point(p) = npts++;
			    }
			    verts[4*ntris+k] = Index_of_point(p);
			}
			verts[4*ntris+3] = num_surfs;
			++ntris;
		    }
		}
		if (plot_surf == YES)
		    ++num_surfs;
	    }
	    else
	    {
	        for (tri = first_tri(*s); !at_end_of_tri_list(tri,*s); 
		     tri = tri->next)
	        {
	            for (k = 0; k < 3; ++k)
		    {
		        p = Point_of_tri(tri)[k];
			if (Index_of_point(p) == -1)
			{
			    crds = Coords(p);
	                    for (l = 0; l < 3; ++l)
				pts[3*npts+l] = crds[l];
			    Index_of_point(p) = npts++;
			}
			verts[4*ntris+k] = Index_of_point(p);
		    }
		    verts[4*ntris+3] = num_surfs;
		    ++ntris;
		}
		++num_surfs;
	    }
	}
	if (num_surfs == 0)
	    return;

	if ((file = fopen(fname,"w")) == NULL)
	{
	    (void) printf("WARNING in gview_plot_surfaces(), "
	                  "can't open %s\n",fname);
	    return;
	}
	(void) fprintf(file,"{ LIST\n");

	gview_bounding_box(file,BBL,BBU,1,indent);

	(void) fprintf(file,"%s{\n%s%sOFF\n%s%s%6d %6d %6d\n",indent,
		       indent,indent,indent,indent,npts,ntris,0);
	for (i = 0; i < npts; ++i)
	{
	    (void) fprintf(file,"%s%s%-9g %-9g %-9g\n",indent,indent,
			   pts[3*i],pts[3*i+1],pts[3*i+2]);
	}
	D = (num_surfs == 1) ? 1.0 : 1/(num_surfs - 1.0);
	for (j = 0; j < ntris; ++j)
	{
	    (void) fprintf(file,"%s%s%-4d %-4d %-4d %-4d ",indent,indent,
			   3,verts[4*j],verts[4*j+1],verts[4*j+2]);
	    write_interpolated_color(file,color1,color2,verts[4*j+3]/D,
				     intensity);
	}
	(void) fprintf(file,"%s}\n",indent);
	(void) fprintf(file,"}\n");
	(void) fclose(file);
}		/*end gview_plot_surfaces*/
}}}
src/intfc/intfc.c
{{{
/*
*			i_delete_interface():
*
*	Deletes a previosly created interface.   Returns 1 if successful
*	or 0 if the given interface did not exist.
*/

EXPORT int i_delete_interface(
	INTERFACE	*intfc)
{
	struct Table	*T;

	if (DEBUG) (void) printf("Entered i_delete_interface(%llu)\n",
	    		         interface_number(intfc));
	if (intfc==NULL)
	{
	    return 0;
	}

	    	/* Find Table and Previous Table: */
	if ((T = table_of_interface(intfc)) == NULL) /* No match */
	{
	    return 0;
	}

	        /* Reset Current Interface: */
	if (intfc==cur_intfc)
	{ 
	    cur_IT = NULL; 
	    cur_intfc = NULL; 
	}

	        /* Free the Chunks: */
	ReturnChunksToFreeList(T->first_chunk,T->last_chunk);
	T->first_chunk = T->last_chunk = NULL;

		/* Free the big chunks */
	while (T->big_chunks != NULL)
	{
	    struct Chunk *chunk = T->big_chunks;
	    T->big_chunks = chunk->prev;
	    free(chunk);
	}

	        /* Free the bond, curve, component lists: */
	if (T->compon1d)
	    free(T->compon1d);
	if (T->num_of_points)
	    free(T->num_of_points);
	if (T->pts_in_zone)
	    free(T->pts_in_zone);
	if (T->compon2d)
	    free(T->compon2d);
	if (T->num_of_bonds)
	    free(T->num_of_bonds);
	if (T->bonds)
	    free(T->bonds);
	if (T->bondstore)
	    free(T->bondstore);
	if (T->curves)
	    free(T->curves);
	if (T->curvestore)
	    free(T->curvestore);
	if (T->compon3d)
	    free(T->compon3d);
	if (T->num_of_tris)
	    free(T->num_of_tris);
	if (T->tris)
	    free(T->tris);
	if (T->tristore)
	    free(T->tristore);
	if (T->surfaces)
	    free(T->surfaces);
	if (T->surfacestore)
	    free(T->surfacestore);

	        /* Unlink and Free the Table: */
	if (T->prev != NULL)
	    T->prev->next = T->next;
	else
	{
	    FirstIT = T->next;
	    if (FirstIT != NULL)
	        FirstIT->prev = NULL;
	}
	if (T->next != NULL)
	    T->next->prev = T->prev;
	else
	{
	    LastIT = T->prev;
	    if (LastIT != NULL)
	        LastIT->next = NULL;
	}

	ReturnTableToFreeList(T);

	if (cur_intfc == NULL)
	{
	    cur_IT = LastIT; 
	    if (cur_IT != NULL)
	        cur_intfc = cur_IT->interface; 
	}
	if (DEBUG)
	    (void) printf("Left i_delete_interface()\n\n");
	return 1;
}		/*end i_delete_interface*/
}}}
src/intfc/intfc.c
{{{
/*
*				i_fprint_curve():
*
*		Prints a given curve, showing all of its bonds.
*/

LIB_LOCAL void i_fprint_curve(
	FILE		*file,
	CURVE		*curve)
{
	BOND		*bond;
	POINT		*p;
	int		i, dim;
	int		k;
	const char	*endchar;
	SURFACE		**surf;

	(void) fprintf(file,"\tCurve %llu:\n",curve_number(curve));
	if (curve == NULL)
	{
	    (void) fprintf(file,"\t\tNULL Curve\n\tEnd of Curve\n\n");
	    return;
	}
	if (curve->interface == NULL)
	{
	    (void) fprintf(file,"\t\tDELETED Curve\n\tEnd of Curve\n\n");
	    return;
	}
	dim = curve->interface->dim;
	switch (dim)
	{
	case 2:
	    (void) fprintf(file,"\tHypersurface of curve = %llu\n",
	    	       hypersurface_number(Hyper_surf(curve)));
	    (void) fprintf(file,
	    	"\tLeft Component = %-4d   Right Component = %-4d    ",
	    negative_component(curve),positive_component(curve));
	    break;
	case 3:
	    (void) fprintf(file,"\tBoundary Status:   ");
	    break;
	}
	(void) fprintf(file,"%s\n",
	           is_bdry(curve) ? "Boundary Curve" : "Interior Curve");
	(void) fprintf(file,"\tStart Node = %-8llu   End Node = %-8llu\n",
	           node_number(curve->start),node_number(curve->end));
	if (dim == 3)
	{
	    (void) fprintf(file,"\t%d Surfaces at Curve-> ",
	    	           (int)Num_surfaces_bding_curve(curve));
	    if (Btris(curve->first) == NULL)
	    (void) fprintf(file,"NULL");
	    else
	    {
	    	BOND_TRI **btris = Btris(curve->first);

	    	for (; btris && *btris; ++btris)
	    	    (void) fprintf(file,"%llu ",
	            surface_number(Surface_of_tri((*btris)->tri)));
	    }
	    (void) fprintf(file,"\n");
	    (void) fprintf(file,"\t%d Pos_surfaces->  ",
	    	        (int)Num_pos_surfaces_of_curve(curve));
	    if ((surf = curve->pos_surfaces) == NULL) 
	    	(void) fprintf(file,"NULL");
	    else 
	    	while (*surf)
	        (void) fprintf(file,"%llu ",surface_number(*surf++));
	    (void) fprintf(file,"\n");
	    (void) fprintf(file,"\t%d Neg_surfaces->  ",
	    	        (int)Num_neg_surfaces_of_curve(curve));
	    if ((surf = curve->neg_surfaces) == NULL) 
	    (void) fprintf(file,"NULL");
	    else 
	    while (*surf)
	        (void) fprintf(file,"%llu ",surface_number(*surf++));
	    (void) fprintf(file,"\n");
	    (void) fprintf(file,"\tEnd Bounding Surface Data\n");
	}
	(void) fprintf(file,"\t%d Points on Curve\n",curve->num_points);

	if (is_binary_output() == YES)
	{
	    for (i = 0,bond = curve->first; bond != NULL; ++i,bond = bond->next)
	    {
	    	if (i%4 == 0)
	    	{
	    	    int remaining = curve->num_points - i;
	    	    (void) fprintf(file,"\f%c",dim*min(4,remaining));
	    	}
	    	(void) fwrite((const void*)Coords(bond->start),FLOAT,dim,file);
	    }
	    if (i%4 == 0)
	        (void) fprintf(file,"\f%c",dim);
	    (void) fwrite((const void*)Coords(curve->last->end),FLOAT,dim,file);
	}
	else
	{
	    int bonds_per_line;
	    bonds_per_line = (dim == 2) ? 4 : 2;
	    (void) fprintf(file,"\n\t");
	    for (i = 1,bond = curve->first; bond != NULL; bond = bond->next,++i)
	    {
	    	p = bond->start;
	    	endchar = i%bonds_per_line ? " " : "\n\t";
	    	if (p == NULL)
	    	    (void) fprintf(file,"NULL ->%s",endchar);
	        else
	        {
	            for (k = 0; k < dim; ++k)
	                (void) fprintf(file,"%- "FFMT" ",Coords(p)[k]);
	            (void) fprintf(file,"->%s",endchar);
	        }
	    }

	    if ((curve->last != NULL) && (curve->last->end != NULL))
	    {
	    	p = curve->last->end;
	    	for (k = 0; k < dim; ++k)
	    	    (void) fprintf(file,"%- "FFMT" ",Coords(p)[k]);
	    	(void) fprintf(file,"\n");
	    }
	}
	if (dim == 3)
	    fprint_tris_on_curve(file,curve);


	user_fprint_curve(file,curve);
	(void) fprintf(file,"\tEnd of Curve\n\n");
}		/*end i_fprint_curve*/
}}}
src/intfc/intfc.c
{{{
/*
*			i_fprint_interface():
*
*		Prints an interface in a readable format.
*/

EXPORT void i_fprint_interface(
	FILE		*file,
	INTERFACE	*infc)
{
	int		  i;
	const char *direction[3] = { "x", "y", "z"};
	RECT_GRID         *gr = &topological_grid(infc);

	(void) foutput(file);
	(void) fprintf(file,"Interface %llu ",interface_number(infc));
	if (infc == NULL)
	{
	    (void) fprintf(file,"Dimension %d\n",-1);
	    (void) fprintf(file,"End Interface\n\n");
	    return;
	}
	(void) fprintf(file,"Dimension %d Remap Geometry %s\n",
		       infc->dim,gr->Remap.remap_name);
	if (exists_interface(infc) != YES)
	{
	    (void) fprintf(file,"Invalid Interface - "
	                        "Probably already deleted\n");
	    (void) fprintf(file,"End Interface\n\n");
	    return;
	}

	fprint_intfc_rect_grids(file,infc);

	switch (infc->dim)
	{
	case 1:
	{
	    POINT		**pt;

	    (void) fprintf(file,"%d Points:\n",infc->num_points);
	    if ((pt = infc->points) != NULL)
	        while (*pt) fprint_point(file,*pt++);
	    (void) fprintf(file,"End Points\n\n");
	    break;
	}
	case 2:
	{
	    CURVE		**cur;
	    NODE		**nod;

	    (void) fprintf(file,"%d Nodes:\n",
	                   (int)size_of_pointers((POINTER *)infc->nodes));
	    if ((nod = infc->nodes) != NULL)
	        while (*nod) fprint_node(file,*nod++);
	    (void) fprintf(file,"End Nodes\n\n");

	    (void) fprintf(file,"%d Curves:\n",
	                   (int)size_of_pointers((POINTER *)infc->curves));
	    if ((cur = infc->curves) != NULL)
	        while (*cur) fprint_curve(file,*cur++);
	    (void) fprintf(file,"End Curves\n\n");
	    break;
	}
	case 3:
	{
	    CURVE		**cur;
	    NODE		**nod;
	    SURFACE		**surf;

	    set_tri_array_numbers(infc,LOCAL_INDICES);

	    (void) fprintf(file,"%d Nodes:\n",
	                   (int)size_of_pointers((POINTER *)infc->nodes));
	    if ((nod = infc->nodes) != NULL)
	        while (*nod) fprint_node(file,*nod++);
	    (void) fprintf(file,"End Nodes\n\n");

	    (void) fprintf(file,"%d Curves:\n",
	                   (int)size_of_pointers((POINTER *)infc->curves));
	    if ((cur = infc->curves) != NULL)
	        while (*cur) fprint_curve(file,*cur++);
	    (void) fprintf(file,"End Curves\n\n");

	    (void) fprintf(file,"%d Surfaces:\n",
	        (int)size_of_pointers((POINTER *)infc->surfaces));
	    if ((surf = infc->surfaces) != NULL)
	        while (*surf) fprint_surface(file,*surf++);
	    (void) fprintf(file,"End Surfaces\n\n");
	    null_tri_array_numbers(infc);
	    break;
	}
	}
	(void) fprintf(file,"%d Points in Interface\n",infc->num_points);
	(void) foutput(file);
	(void) fprintf(file,"Rectangular Boundary Types for Interface %llu\n",
	           interface_number(infc));
	(void) fprintf(file,"\n\t\tLOWER BOUNDARY\t\t\tUPPER BOUNDARY\n");
	for (i = 0; i < infc->dim; ++i)
	{
	    (void) fprintf(file,"%s-direction\t",direction[i]);
	    fprint_boundary_type(file,"",rect_boundary_type(infc,i,0),"",infc);
	    (void) fprintf(file,"\t\t");
	    fprint_boundary_type(file,"",rect_boundary_type(infc,i,1),
	    	                 "\n",infc);
	}
	(void) fprintf(file,"\n");
	(void) fprintf(file,
		       "End Rectangular Boundary Types for Interface %llu\n",
	               interface_number(infc));

	(void) fprintf(file,"\n");
	(void) foutput(file);
	(void) fprintf(file,"Random number seeds\n");
	(void) fprintf(file,"random01_seed = 0x%x 0x%x 0x%x\n",
	               Random01_seed(infc)[0],
	               Random01_seed(infc)[1],
	               Random01_seed(infc)[2]);
	(void) fprintf(file,"End Random number seeds\n");
	(void) fprintf(file,"\n");
	fprint_comp_equiv_lists(file,infc);
	(void) fprintf(file,"\n");
	user_fprint_interface(file,infc);
	(void) foutput(file);
	(void) fprintf(file,"End Interface\n\n");
}		/*end i_fprint_interface*/
}}}
src/intfc/intfc.c
{{{
/*
*			i_fprint_node():
*
*	Prints a Node.
*/


LIB_LOCAL void i_fprint_node(
	FILE		*file,
	NODE		*node)
{
	CURVE		**cur;
	int		dim;

	(void) fprintf(file,"\tNode %llu:\n",node_number(node));
	if (node == NULL)
	{ 
	    (void) fprintf(file,"\t\tNULL Node\n\t\tEnd Node\n");
	    return;
	}
	(void) fprintf(file,"\t\t%s Node\n",
	           is_bdry(node) ? "Boundary" : "Interior");
	dim = node->interface->dim;
	(void) fprintf(file,"\t\tPosition  ");
	if (node->posn == NULL)
	    (void) fprintf(file,"NULL\n");
	else if (is_binary_output() == YES)
	{
	    (void) fprintf(file,"\f%c",dim);
	    (void) fwrite((const void *)Coords(node->posn),FLOAT,dim,file);
	    (void) fprintf(file,"\n");
	}
	else
	{
	    const char	*vname[3] = {"x =", "   y =", "   z ="};
	    int		k;

	    for (k = 0; k < dim; ++k)
	        (void) fprintf(file,"%s %"FFMT,vname[k],Coords(node->posn)[k]);
	    (void) fprintf(file,"\n");
	}
	(void) fprintf(file,"\t\tIn_curves->  ");
	if ((cur = node->in_curves) == NULL) 
	    (void) fprintf(file,"NULL");
	else 
	    while (*cur) (void) fprintf(file,"%llu ",curve_number(*cur++));
	(void) fprintf(file,"\n");

	(void) fprintf(file,"\t\tOut_curves-> ");
	if ((cur = node->out_curves) == NULL) 
	    (void) fprintf(file,"NULL");
	else
	    while (*cur) (void) fprintf(file,"%llu ",curve_number(*cur++));
	(void) fprintf(file,"\n");

	user_fprint_node(file,node);
	(void) fprintf(file,"\tEnd Node\n\n");
}		/*end i_fprint_node*/
}}}
src/intfc/int3d.h
{{{
/*
*			i_fprint_surface():
*
*	Prints a formatted surface. It is assumed that the tri index numbers
*	have already been set before this routine is called.
*/

LIB_LOCAL void i_fprint_surface(
	FILE		*file,
	SURFACE		*s)
{
	size_t num_pos_c, num_neg_c;
	int    num_tri;
	int    i, num_points;
	CURVE  **pos_cur,**neg_cur;
	TRI    *tri;
	POINT  *p;

	(void) fprintf(file,"\tSurface %llu:\n",surface_number(s));
	if (s == NULL)
	{
	    (void) fprintf(file,"\t\t NULL Surface\n\tEnd of Surface\n\n");
	    return;
	}
	(void) fprintf(file,"\tHypersurface of surface = %llu\n",
		       hypersurface_number(Hyper_surf(s)));
	(void) fprintf(file,"\tHypersurface index = %d\n",
		       Hyper_surf_index(s));
	(void) fprintf(file,"\tPositive Component = %-4d   "
			    "Negative Component = %-4d    ",
		            positive_component(s),negative_component(s));
	(void) fprintf(file,"%s\n\n",
		       is_bdry(s) ? "Boundary Surface" : "Interior Surface");

	num_pos_c = Num_pos_curves_of_surface(s);
	num_neg_c = Num_neg_curves_of_surface(s);
	pos_cur = s->pos_curves;
	neg_cur = s->neg_curves;

	(void) fprintf(file,"\t%lu Positively Oriented Bounding Curves : ",
		       num_pos_c);
	while (num_pos_c--)
		(void) fprintf(file,"%llu ",curve_number(*pos_cur++));
	(void) fprintf(file,"\n");
	(void) fprintf(file,"\t%lu Negatively Oriented Bounding Curves : ",
		       num_neg_c);
	while (num_neg_c--)
		(void) fprintf(file,"%llu ",curve_number(*neg_cur++));
	(void) fprintf(file,"\n\n");

	for (tri = first_tri(s); !at_end_of_tri_list(tri,s); tri = tri->next)
	{
		Index_of_point(Point_of_tri(tri)[0]) =
		    Index_of_point(Point_of_tri(tri)[1]) =
		    Index_of_point(Point_of_tri(tri)[2]) = ERROR;
	}
	num_points = 0;
	for (tri = first_tri(s); !at_end_of_tri_list(tri,s); tri = tri->next)
	{
	    for (i = 0; i < 3; ++i)
	    {
	    	p = Point_of_tri(tri)[i];
	    	if (Index_of_point(p) == ERROR)
	    	    Index_of_point(p) = num_points++;
	    }
	}
	(void) fprintf(file,"\t%d Points on Surface\n",num_points);

	num_tri = s->num_tri;
	(void) fprintf(file,"\t%d Triangles on Surface\n",num_tri);
	for (tri = first_tri(s); !at_end_of_tri_list(tri,s); tri = tri->next)
	    fprint_triangle_numbers(file,tri);

	user_fprint_surface(file,s);
	(void) fprintf(file,"\tEnd of Surface\n\n");
}		/*end i_fprint_surface*/
}}}
src/intfc/intfc.c
{{{
/*
*			i_insert_point_in_bond():
*
*	Inserts point p into a bond b on a curve c.   The bond is changed
*	into two bonds with the point at their common point.
*	Returns 1 if successful, or 0 on error.   Errors occur if p,b or 
*	c is NULL or if space cannot be allocated for a new bond.
*/

EXPORT bool i_insert_point_in_bond(
	POINT		*p,
	BOND		*b,
	CURVE		*c)
{
	BOND		*bnew;

	if ((p==NULL) || (b==NULL) || (c==NULL) || (bnew=Bond(p,b->end))==NULL) 
	    return FUNCTION_FAILED; 

	bnew->prev = b;
	if (b->next != NULL)
	    b->next->prev = bnew;
	else
	    c->last = bnew;				/* End of Curve */
	bnew->next = b->next;
	b->next = bnew;
	b->end  = p;
	b->length = separation(b->start,p,c->interface->dim);
	++c->num_points;
	++c->interface->num_points;
	if (c->interface->dim == 2)
	{
	    bnew->start->hse = bnew->end->hse = Hyper_surf_element(bnew);
	    bnew->start->hs = bnew->end->hs = Hyper_surf(c);
	}
	else if (c->interface->dim == 3)
	{
	    split_tris_at_split_bond(p,b,c);
	    Boundary_point(p) = 1;
	}
	c->interface->modified = YES;
	return FUNCTION_SUCCEEDED;
}		/*end i_insert_point_in_bond*/
}}}
src/inftc/intfc.c
{{{

/*
*			i_make_curve():
*
*	Creates a new curve separating specified components
*	and joining two specified nodes.   The curve consists
*	of one bond joining the two nodes.
*
*	Returns a pointer to the created curve or NULL on error..
*/

/*ARGSUSED*/
EXPORT CURVE *i_make_curve(
	COMPONENT	neg_comp,
	COMPONENT	pos_comp,
	NODE		*start,
	NODE		*end)
{
	CURVE		*curve;
	INTERFACE	*intfc;
	size_t		size_curve;

	if (start==NULL || end==NULL) 
	{
	    if (DEBUG)
	    (void) printf("start %llu end %llu make_curve returns NULL (1)\n",
	              node_number(start),node_number(end));
	    return NULL;
	}
	if ((intfc=start->interface)==NULL || intfc!=end->interface)
	{
	    if (DEBUG)
	    {
	        (void) printf("intfc: start %llu end %llu ",
	        	  interface_number(intfc),
	        	  interface_number(end->interface));
	        (void) printf("make_curve returns NULL (2)\n");
	    }
	    return NULL;
	}
	if (intfc != cur_intfc)
	{
	    if (DEBUG)
	    {
	        (void) printf("intfc %llu cur %llu ",
	        	  interface_number(intfc),
	        	  interface_number(cur_intfc));
	        (void) printf("make_curve returns NULL (3)\n");
	    }
	    return NULL;

	}
	size_curve =  i_user_interface(intfc).size_curve;

	if ((curve = (CURVE *)store(size_curve)) == NULL)
	{
	    if (DEBUG)
		(void) printf("make_curve returns NULL (4)\n");
	    return NULL;
	}

	if (! add_to_pointers(curve,&start->out_curves))
	{
	    if (DEBUG)
		(void) printf("make_curve returns NULL (5)\n");
	    return NULL;
	}
	if (! add_to_pointers(curve,&end->in_curves))
	{
	    if (DEBUG)
		(void) printf("make_curve returns NULL (6)\n");
	    return NULL;
	}
	if (! add_to_pointers(curve,&intfc->curves))
	{
	    if (DEBUG)
		(void) printf("make_curve returns NULL (7)\n");
	    return NULL;
	}

	curve->interface = intfc;
	curve->obj = curve;
	curve->redist_order = 1;	// default
	switch (intfc->dim)
	{
	case 2:
	    Hyper_surf(curve) = make_hypersurface(neg_comp,pos_comp);
	    Curve_of_hs(Hyper_surf(curve)) = curve;
	    curve->interface->num_points += 2;
	    curve->orientation = 0;
	    break;
	case 3:
	    Hyper_surf_bdry(curve) = make_hypersurface_boundary();
	    Curve_of_hsb(Hyper_surf_bdry(curve)) = curve;
	    break;
	default:
	    break;
	}
	curve->start = start;
	curve->end = end;
	if ((curve->first = Bond(start->posn,end->posn)) == NULL)
	{
	    return NULL; 
	}
	if (intfc->dim == 2)
	{
	    curve->first->start->hse = Hyper_surf_element(curve->first);
	    curve->first->end->hse = Hyper_surf_element(curve->first);
	    curve->first->start->hs = Hyper_surf(curve);
	    curve->first->end->hs = Hyper_surf(curve);
	}
	cur_intfc->modified = YES;
	curve->last = curve->first;
	curve->num_points = 2;
	set_not_bdry(curve);
	return curve;
}		/*end i_make_curve*/

}}}
src/intf/intfc.c
{{{
EXPORT HYPER_SURF *i_make_hypersurface(
	COMPONENT	neg_comp,
	COMPONENT	pos_comp)
{
	HYPER_SURF	*hs;
	size_t		size_hyper_surf;

	size_hyper_surf = i_user_interface(cur_intfc).size_hyper_surf;
	hs = (HYPER_SURF *)store(size_hyper_surf);
	if (hs == NULL)
	{
	    if (DEBUG)
	        (void) printf("i_make_hypersurface returns NULL (8)\n");
	    return NULL;
	}
	if (!add_to_pointers(hs,&hyper_surf_list(cur_intfc)))
	{
	    if (DEBUG)
	        (void) printf("i_make_hypersurface returns NULL (8)\n");
	    return NULL;
	}
	Hyper_surf(hs) = hs;
	hs->interface = cur_intfc;
	negative_component(hs) = new_component(neg_comp);
	positive_component(hs) = new_component(pos_comp);
	cur_intfc->modified = YES;

	return hs;
}		/*end i_make_hypersurface*/
}}}
src/intf/intfc.c
{{{
/*
*			i_make_point():
*
*       Allocates a point structure in the current interface and
*       installs it in the point-list of the interface.  The
*       point will have position  p  which may be NULL.  
*
*	This function is separate from i_Point() in order to support
*	the component arguments, although i_Point() is used as the basic
*	storage allocator.  This function can only be used in ONED.
*
*       Returns a pointer to the new point, or NULL on error.
*/

EXPORT POINT *i_make_point(
	double		*coords,
	COMPONENT	neg_comp,
	COMPONENT	pos_comp)
{
	POINT *newpoint;
	POINT **p, *antep;
	int   i;

	if (cur_intfc->dim != 1)
	    return NULL;
	if ((newpoint = Point(coords)) == NULL)
	    return NULL;

	Hyper_surf(newpoint) = make_hypersurface(neg_comp,pos_comp);
	if (Hyper_surf(newpoint) == NULL)
	    return NULL;
	Point_of_hs(Hyper_surf(newpoint)) = newpoint;
	newpoint->obj = newpoint;
	newpoint->interface = cur_intfc;

	for (antep = NULL, p = cur_intfc->points; p && *p; ++p)
	{
	    if (coords[0] > Coords(*p)[0])
		antep = *p;
	    else
		break;
	}
	if (!add_to_ordered_pointers(newpoint,antep,&cur_intfc->points))
	    return NULL;
	if (antep == NULL)/*move new point to start of array*/
	{
	    for (i = cur_intfc->num_points; i > 0; --i)
	        cur_intfc->points[i] = cur_intfc->points[i-1];
	    cur_intfc->points[0] = newpoint;
	}
	    					    
	cur_IT->max_comp = max(cur_IT->max_comp,max(neg_comp,pos_comp));
	cur_IT->min_comp = min(cur_IT->min_comp,min(neg_comp,pos_comp));
	++cur_intfc->num_points;
	cur_intfc->modified = YES;
	return newpoint;
}		/*end i_make_point*/
}}}
src/intfc/setb1d.c
{{{
/*
*				i_set_boundary1d():
*
*	Sets the boundary for an interface defined in a rectangle.
*	The interface may be arbitrarily complicated.   It is assumed
*	that all interface points lie within or on the rectangle.
*	If the interface already contains boundary curves, these will
*	be discarded.   The routine considers the given interior
*	curves and constructs a set of boundary curves such that the
*	rectangle is divided into connected components each of exactly
*	one component number.   The component number of the exterior
*	is arbitrarily ft_assigned as one greater that that of any interior
*	region.   The new boundary curves are then added to the
*	interface.   Corresponding NODES have their boundary field set.
*
*	This routine sets the current interface to intfc.
*
*	Returns 1 if successful or zero on error.
*	The routine checks the validity of the component ft_assignments of the
*	given interface and returns 0 if these are not consistent.   A zero
*	return may also be caused by an invalid interface pointer.
*/

EXPORT bool i_set_boundary1d(
	INTERFACE	*intfc,
	RECT_GRID	*gr,
	COMPONENT	i_comp,
	double		eps)	/* boundary distance tolerance */
{
	int		outside;	/* Component Number of Exterior */
	double		*L = gr->VL;
	double		*U = gr->VU;
	POINT		*pt, *pointl, *pointr;

	DEBUG_ENTER(i_set_boundary1d)

		/* Check Validity of Interface and Set Storage Allocation: */

#if defined(DEBUG_SETB1D)
	if (DEBUG)
	{
	    print_general_vector("L = ",L,intfc->dim,NO);
	    print_general_vector(", U = ",U,intfc->dim,NO);
	    (void) printf(", eps = %g, i_comp = %d\n",eps,i_comp);
	    print_interface(intfc);
	}
#endif /* defined(DEBUG_SETB1D) */

	if (exists_interface(intfc) != YES)
	{
	    DEBUG_LEAVE(i_set_boundary1d)
	    return FUNCTION_FAILED;
	}
	set_current_interface(intfc);

		/* Get rid of Old Boundary Points if Any: */

	outside = exterior_component(intfc);

#if defined(DEBUG_SETB1D)
	if (DEBUG)  (void) printf("\nOutside Component = %d\n\n",outside);
#endif /* defined(DEBUG_SETB1D) */

	if (intfc->num_points > 0)
	{
	    pt = intfc->points[0];
	    if (!is_bdry(pt) || (Coords(pt)[0] > (L[0]+eps)))
	    {
	        pointl = make_point(L,outside,negative_component(pt));
	        set_is_bdry(pointl);
		if (is_bdry(pt) && (Coords(pt)[0] <= (L[0]+eps)))
		    delete_point(pt);
	    }
	    else
	    {
	        pointl = pt;
	        Coords(pointl)[0] = L[0];
	    }
	    pt = intfc->points[intfc->num_points-1];
	    if (!is_bdry(pt) || (Coords(pt)[0] < (U[0]-eps)))
	    {
	        pointr = make_point(U,positive_component(pt),outside);
	        set_is_bdry(pointr);
		if (is_bdry(pt) && (Coords(pt)[0] >= (U[0]-eps)))
		    delete_point(pt);
	    }
	    else
	    {
	        pointr = pt;
	        Coords(pointr)[0] = U[0];
	    }
	}
	else
	{
	    pointl = make_point(L,outside,i_comp);
	    set_is_bdry(pointl);
	    pointr = make_point(U,i_comp,outside);
	    set_is_bdry(pointr);
	}
	if (intfc->table->new_grid || intfc->modified)
	    if (!make_point_comp_lists(intfc))
		return FUNCTION_FAILED;

#if defined(DEBUG_SETB1D)
	if (DEBUG)
	{
	    print_interface(intfc);
	    (void) printf("Leaving set_boundary1d()\n\n");
	}
#endif /* defined(DEBUG_SETB1D) */
	DEBUG_LEAVE(i_set_boundary1d)
	return FUNCTION_SUCCEEDED;
}		/*end i_set_boundary1d*/
}}}
src/intfc/iuserintfc.c
{{{
EXPORT	I_USER_INTERFACE *i_user_hook(
	int		dim)
{
	int                     i;
	static bool             first = YES;
	static I_USER_INTERFACE User_hooks[3];

	if (first == YES)
	{
	    static COMP_LIST Default_excluded_comps = { 0,
							0,
							NULL,
							i_is_excluded_comp,
							i_add_comp_to_list
						      };
	    first = NO;
	    for (i = 0; i < MAXD; ++i)
	    {
	        User_hooks[i].size_interface = sizeof(I_INTERFACE);
	        User_hooks[i].size_point = sizeof(POINT);
	        User_hooks[i].size_hyper_surf = sizeof(HYPER_SURF);
	        User_hooks[i]._read_boundary_type_from_string =
		    i_read_boundary_type_from_string;
	        User_hooks[i]._fprint_boundary_type = i_fprint_boundary_type;
	        User_hooks[i]._user_make_interface = i_user_make_interface;
	        User_hooks[i]._copy_interface = i_copy_interface;
	        User_hooks[i]._user_copy_hyper_surf = i_user_copy_hyper_surf;
	        User_hooks[i]._user_read_print_interface =
		    i_user_read_print_interface;
	        User_hooks[i]._fprint_interface = i_fprint_interface;
	        User_hooks[i]._user_fprint_interface = i_user_fprint_interface;
	        User_hooks[i]._delete_interface = i_delete_interface;
	        User_hooks[i]._make_hypersurface = i_make_hypersurface;
	        User_hooks[i]._make_hypersurface_boundary =
		    i_make_hypersurface_boundary;
	        User_hooks[i]._fprint_intfc_rect_grids =
		    i_fprint_intfc_rect_grids;
	        User_hooks[i]._user_fprint_intfc_rect_grids =
		    i_user_fprint_intfc_rect_grids;
		User_hooks[i]._read_print_intfc_rect_grids =
		    i_read_print_intfc_rect_grids;
	        User_hooks[i]._user_read_print_intfc_rect_grids =
		    i_user_read_print_intfc_rect_grids;
		User_hooks[i]._Static_point = i_Static_point;
	        User_hooks[i]._average_points = i_average_points;
	        User_hooks[i]._copy_point = i_copy_point;
	        User_hooks[i]._send_interface = i_send_interface;
	        User_hooks[i]._receive_interface = i_receive_interface;
	        User_hooks[i]._reconstruct_interface_pointers = 
		    i_reconstruct_interface_pointers;
	        User_hooks[i]._reconstruct_point_pointers = 
		    i_reconstruct_point_pointers;
	        User_hooks[i]._print_number_of_tangles =
		    i_print_number_of_tangles;
	        User_hooks[i]._is_subdomain_boundary = i_is_subdomain_boundary;
	        User_hooks[i]._fset_hyper_surf_color = i_fset_hyper_surf_color;
	        User_hooks[i]._zoom_interface = i_zoom_interface;
	        User_hooks[i]._reflect_point = i_reflect_point;
	        User_hooks[i]._InterfaceTolerances._Parallel =
		    0.00000762939453125; /*PARALLEL 2^-17 */
	        User_hooks[i]._InterfaceTolerances._Min_sin_sqr = 1.0e-6;
		User_hooks[i]._InterfaceTolerances._MinScaledLength =
		    pow(2.0,-10.0);
		User_hooks[i]._InterfaceTolerances._MinScaledSeparation = 
		    pow(2.0,-7.0);
		User_hooks[i]._InterfaceTolerances._EndOfCurve =
		    1.0 - User_hooks[i]._InterfaceTolerances.
		    _MinScaledSeparation;
		User_hooks[i]._InterfaceTolerances._StartOfCurve =
		    User_hooks[i]._InterfaceTolerances._MinScaledSeparation;
		User_hooks[i]._InterfaceTolerances._TolFac = 32.0;
		User_hooks[i]._InterfaceTolerances._RcbMinScaledSep =
		    User_hooks[i]._InterfaceTolerances._MinScaledLength;
		User_hooks[i]._InterfaceTolerances._RobustFac = 0.01;
		User_hooks[i]._InterfaceTolerances._RcbMacTol = 1.0e-5;
		User_hooks[i]._InterfaceTolerances._RcbcRobustFac =
		    User_hooks[i]._InterfaceTolerances._MinScaledLength;
		User_hooks[i]._InterfaceTolerances._ReflectTol = 0.0001;
		User_hooks[i]._InterfaceTolerances._ShortCurveNumPoints = 3;
	        User_hooks[i]._cross_tolerance = i_cross_tolerance;
	        User_hooks[i]._excluded_comps = Default_excluded_comps;
		User_hooks[i]._random01_seed[0] = 0xab83;
		User_hooks[i]._random01_seed[1] = 0x0023;
		User_hooks[i]._random01_seed[2] = 0x3eaa;
		User_hooks[i]._random01 = i_random01;
	    }
#if defined(ONED)
	    User_hooks[0]._ChunkSize = 1250*sizeof(ALIGN);
	    User_hooks[0]._nip = nearest_interface_point1d;
	    User_hooks[0]._lnip = long_nearest_interface_point1d;
	    User_hooks[0]._next_point = next_point1d;
	    User_hooks[0]._next_hypersurface = next_hypersurface1d;
	    User_hooks[0]._make_point = i_make_point;
	    User_hooks[0]._Point = i_Point;
	    User_hooks[0]._delete_point = i_delete_point;
	    User_hooks[0]._fprint_point = i_fprint_point;
	    User_hooks[0]._user_fprint_point = i_user_fprint_point;
	    User_hooks[0]._read_point = i_read_point;
	    User_hooks[0]._user_read_point = i_user_read_point;
	    User_hooks[0]._read_print_point = i_read_print_point;
	    User_hooks[0]._user_read_print_point = i_user_read_print_point;
	    User_hooks[0]._set_boundary = i_set_boundary1d;
	    User_hooks[0]._intersections = i_intersections1d;
	    User_hooks[0]._print_intersections = i_print_intersections1d;
	    User_hooks[0]._reflect_interface = i_reflect_interface1d;
	    User_hooks[0]._make_interface_topology_lists =
		make_point_comp_lists;
#endif /* defined(ONED) */

#if defined(TWOD) || defined(THREED)
	    for (i = 1; i < MAXD; ++i)
	    {
	        User_hooks[i].size_bond = sizeof(BOND);
	        User_hooks[i].size_curve = sizeof(CURVE);
	        User_hooks[i].size_node = sizeof(NODE);
	        User_hooks[i].size_hyper_surf_element =
		    sizeof(HYPER_SURF_ELEMENT);
	        User_hooks[i].size_hyper_surf_bdry = sizeof(HYPER_SURF_BDRY);
	        User_hooks[i].size_o_node = sizeof(O_NODE);
	        User_hooks[i]._make_node = i_make_node;
	        User_hooks[i]._copy_node = i_copy_node;
	        User_hooks[i]._delete_node = i_delete_node;
	        User_hooks[i]._fprint_node = i_fprint_node;
	        User_hooks[i]._user_fprint_node = i_user_fprint_node;
	        User_hooks[i]._read_node = i_read_node;
	        User_hooks[i]._user_read_node = i_user_read_node;
	        User_hooks[i]._user_read_print_node = i_user_read_print_node;
	        User_hooks[i]._make_curve = i_make_curve;
	        User_hooks[i]._copy_curve = i_copy_curve;
	        User_hooks[i]._delete_curve = i_delete_curve;
	        User_hooks[i]._fprint_curve = i_fprint_curve;
	        User_hooks[i]._user_fprint_curve = i_user_fprint_curve;
	        User_hooks[i]._read_curve = i_read_curve;
	        User_hooks[i]._user_read_curve = i_user_read_curve;
	        User_hooks[i]._user_read_print_curve = i_user_read_print_curve;
	        User_hooks[i]._user_split_curve = i_user_split_curve;
	        User_hooks[i]._user_join_curves = i_user_join_curves;
	        User_hooks[i]._Bond = i_Bond;
	        User_hooks[i]._Point = i_Point;
	        User_hooks[i]._insert_point_in_bond = i_insert_point_in_bond;
	        User_hooks[i]._delete_start_of_bond = i_delete_start_of_bond;
	        User_hooks[i]._delete_end_of_bond = i_delete_end_of_bond;
	        User_hooks[i]._reconstruct_node_pointers = 
		    i_reconstruct_node_pointers;
	        User_hooks[i]._reconstruct_bond_pointers = 
		    i_reconstruct_bond_pointers;
	        User_hooks[i]._reconstruct_curve_pointers = 
		    i_reconstruct_curve_pointers;
	        User_hooks[i]._attach_curve_to_node = i_attach_curve_to_node;
	        User_hooks[i]._invert_curve = i_invert_curve;
	        User_hooks[i]._reverse_curve = i_reverse_curve;
	        User_hooks[i]._move_closed_loop_node = i_move_closed_loop_node;
	        User_hooks[i]._is_subdomain_node = i_is_subdomain_node;
	        User_hooks[i]._reflect_curve = i_reflect_curve;
	        User_hooks[i]._reflect_node = i_reflect_node;
	    }
#endif /* defined(TWOD) || defined(THREED) */

#if defined(TWOD)
	    User_hooks[1]._ChunkSize = 12500*sizeof(ALIGN);
	    User_hooks[1]._nip = nearest_interface_point2d;
	    User_hooks[1]._lnip = long_nearest_interface_point2d;
	    User_hooks[1]._nsip = nearest_similar_interface_point2d;
	    User_hooks[1]._lnsip = long_nearest_similar_interface_point2d;
	    User_hooks[1]._next_point = next_point2d;
	    User_hooks[1]._next_hypersurface = next_hypersurface2d;
	    User_hooks[1]._set_boundary = i_set_boundary2d;
	    User_hooks[1]._intersections = i_intersections2d;
	    User_hooks[1]._print_intersections = i_print_intersections2d;
	    User_hooks[1]._print_crossing_elements =
		i_print_crossing_elements2d;
	    User_hooks[1]._is_virtual_fixed_node = i_is_virtual_fixed_node;
	    User_hooks[1]._reflect_interface = i_reflect_interface2d;
	    User_hooks[1]._make_interface_topology_lists = 
		make_bond_comp_lists;
	    User_hooks[1]._gview_plot_interface = i_gview_plot_interface;
	    User_hooks[1]._consistent_interface = i_consistent_interface;
#endif /* defined(TWOD) */
#if defined(THREED)
	    User_hooks[2].size_bond_tri = sizeof(BOND_TRI);
	    User_hooks[2].size_tri = sizeof(TRI);
	    if (debugging("MinTStor"))
	        set_tri_storage_type(MIN_TRI_STORAGE);
	    else if (debugging("FullTGeo"))
	        set_tri_storage_type(FULL_TRI_GEOMETRY);
	    else
	        set_tri_storage_type(TRI_PLUS_NORMAL);
	    User_hooks[2].size_surface = sizeof(SURFACE);
	    User_hooks[2]._ChunkSize = 50000*sizeof(ALIGN);
	    User_hooks[2]._nip = nearest_interface_point3d;
	    User_hooks[2]._lnip = long_nearest_interface_point3d;
	    User_hooks[2]._nsip = nearest_similar_interface_point3d;
	    User_hooks[2]._lnsip = long_nearest_similar_interface_point3d;
	    User_hooks[2]._next_point = next_point3d;
	    User_hooks[2]._next_hypersurface = next_hypersurface3d;
	    User_hooks[2]._gview_plot_interface = i_gview_plot_interface;
	    User_hooks[2]._link_tri_to_bond = i_link_tri_to_bond;
	    User_hooks[2]._reverse_bond = i_reverse_bond;
	    User_hooks[2]._reorder_curve_link_list = i_reorder_curve_link_list;
	    User_hooks[2]._insert_point_in_tri = i_insert_point_in_tri;
	    User_hooks[2]._insert_point_in_tri_side = 
		i_insert_point_in_tri_side;
	    User_hooks[2]._undo_insert_point_in_tri =
		i_undo_insert_point_in_tri;
	    User_hooks[2]._undo_insert_point_in_tri_side = 
		i_undo_insert_point_in_tri_side;
	    User_hooks[2]._make_tri = i_make_tri;
	    User_hooks[2]._CBond = i_CBond;
	    User_hooks[2]._make_surface = i_make_surface;
	    User_hooks[2]._join_surfaces = i_join_surfaces;
	    User_hooks[2]._copy_surface = i_copy_surface;
	    User_hooks[2]._delete_surface = i_delete_surface;
	    User_hooks[2]._fprint_surface = i_fprint_surface;
	    User_hooks[2]._user_fprint_surface = i_user_fprint_surface;
	    User_hooks[2]._read_surface = i_read_surface;
	    User_hooks[2]._user_read_surface = i_user_read_surface;
	    User_hooks[2]._user_read_print_surface = i_user_read_print_surface;
	    User_hooks[2]._reconstruct_surface_pointers = 
		i_reconstruct_surface_pointers;
	    User_hooks[2]._reconstruct_tri_pointers = 
		i_reconstruct_tri_pointers;
	    User_hooks[2]._set_boundary = i_set_boundary3d;
	    User_hooks[2]._user_install_faces = i_user_install_faces;
	    User_hooks[2]._assign_curve_boundary_flag = 
		i_assign_curve_boundary_flag;
	    User_hooks[2]._intersections = i_intersections3d;
	    User_hooks[2]._print_intersections = i_print_intersections3d;
	    User_hooks[2]._print_crossing_elements =
		i_print_crossing_elements3d;
	    User_hooks[2]._is_virtual_fixed_node = i_is_virtual_fixed_node;
	    User_hooks[2]._reflect_interface = i_reflect_interface3d;
	    User_hooks[2]._reflect_surface = i_reflect_surface;
	    User_hooks[2]._make_interface_topology_lists = make_tri_comp_lists;
	    User_hooks[2]._consistent_interface = i_consistent_interface;
	    User_hooks[2]._sort_bond_tris = i_sort_bond_tris;
#endif /* defined(THREED) */
	}
	if (dim < 1 || dim > 3)
	{
	    screen("ERROR in i_user_hook(), invalid dim %d\n",dim);
	    clean_up(ERROR);
	    return NULL;
	}
	else
	    return User_hooks + dim - 1;
}		/*end i_user_hook*/
}}}
src/front/userint.h
{{{
#define	i_user_interface(intfc)	(i_interface(intfc)->I_user_intfc)
#define	i_interface(intfc)	((I_INTERFACE*) (intfc))
struct _I_INTERFACE {
	INTERFACE Intfc;
	I_USER_INTERFACE I_user_intfc;
};
typedef struct _I_INTERFACE I_INTERFACE;

struct _I_USER_INTERFACE {

	/* Sizes of interface data structures */
	size_t	size_interface;
	size_t	size_point;
	size_t	size_bond;
	size_t	size_curve;
	size_t	size_node;
#if defined(THREED)
	size_t	size_bond_tri;
	size_t	size_tri;
	size_t	size_surface;
#endif /* defined(THREED) */
	size_t	size_hyper_surf;
	size_t	size_hyper_surf_element;
	size_t	size_hyper_surf_bdry;
	size_t	size_o_node;

	/* Variables for interface store*/
	size_t	_ChunkSize;

	/* Dimensionally dependent functions for topology indentification */

 	/* nearest_interface_point() */
	bool	(*_nip)(float*,COMPONENT,INTERFACE*,USE_BOUNDARIES,HYPER_SURF*,
			float*,float*,HYPER_SURF_ELEMENT**,HYPER_SURF**);

	/* long_nearest_interface_point() */
	bool	(*_lnip)(float*,COMPONENT,INTERFACE*,USE_BOUNDARIES,HYPER_SURF*,
			 float*,float*,HYPER_SURF_ELEMENT**,HYPER_SURF**);

	/* nearest_similar_interface_point() */
	bool	(*_nsip)(float*,COMPONENT,COMPONENT,INTERFACE*,USE_BOUNDARIES,
			 HYPER_SURF*,float*,float*,HYPER_SURF_ELEMENT**,
			 HYPER_SURF**);

	/* long_nearest_similar_interface_point() */
	bool	(*_lnsip)(float*,COMPONENT,COMPONENT,struct _INTERFACE*,
			  USE_BOUNDARIES,HYPER_SURF*,float*,float*,
			  HYPER_SURF_ELEMENT**,HYPER_SURF**);

	/* Dimensionally dependent functions for interface element looping */

	bool	(*_next_point)(struct _INTERFACE*,POINT**,
			       HYPER_SURF_ELEMENT**,HYPER_SURF**);
	bool	(*_next_hypersurface)(struct _INTERFACE*,HYPER_SURF**);

	/* Functions used for I/O of boundary type data */

	int	(*_read_boundary_type_from_string)(const char*);
	void	(*_fprint_boundary_type)(FILE*,const char*,int,const char*,
	                                 struct _INTERFACE*);

	/* User defined hooks to interface utility functions */

	/* Interface utility functions */
	void	(*_user_make_interface)(INTERFACE*);
	INTERFACE	*(*_copy_interface)(INTERFACE*);
	int	(*_user_read_print_interface)(INIT_DATA*,const IO_TYPE*,
	                                      INTERFACE*,bool);
	void	(*_fprint_interface)(FILE*,INTERFACE*);
#if defined(THREED)
	void	(*_gview_plot_interface)(const char*,INTERFACE*);
#endif /* defined(THREED) */
	void	(*_user_fprint_interface)(FILE*,INTERFACE*);
	int	(*_delete_interface)(INTERFACE*);

	/* Hypersurface utility functions */
	HYPER_SURF	*(*_make_hypersurface)(COMPONENT,COMPONENT);
	void		(*_user_copy_hyper_surf)(HYPER_SURF*,HYPER_SURF*);

	/* Hypersurface boundary utility functions */
	HYPER_SURF_BDRY	*(*_make_hypersurface_boundary)(void);

	/* Node utility functions */
	NODE	*(*_make_node)(POINT*);
	NODE	*(*_copy_node)(NODE*);
	bool	(*_delete_node)(NODE*);
	void	(*_fprint_node)(FILE*,NODE*);
	void	(*_user_fprint_node)(FILE*,NODE*);
	NODE	*(*_read_node)(INTERFACE*,int);
	int	(*_user_read_node)(NODE*);
	void	(*_user_read_print_node)(NODE*,const IO_TYPE*,bool);

	/* Rect grid utility functions */
		/*Writing*/
	void	(*_fprint_intfc_rect_grids)(FILE*,INTERFACE*);
	void	(*_user_fprint_intfc_rect_grids)(FILE*,INTERFACE*);
		/*Reading*/
	int	(*_read_print_intfc_rect_grids)(const IO_TYPE*,INTERFACE*,
	                                        REMAP*);
	void	(*_user_read_print_intfc_rect_grids)(const IO_TYPE*,INTERFACE*,
						     bool,REMAP*);

	/* Curve utility functions */
	CURVE	*(*_make_curve)(COMPONENT,COMPONENT,NODE*,NODE*);
	CURVE	*(*_copy_curve)(CURVE*,NODE*,NODE*);
	int	(*_delete_curve)(CURVE*);
	void	(*_fprint_curve)(FILE*,CURVE*);
	void	(*_user_fprint_curve)(FILE*,CURVE*);
	CURVE	*(*_read_curve)(INTERFACE*,int);
	void	(*_user_read_curve)(CURVE*);
	bool	(*_user_read_print_curve)(CURVE*,const IO_TYPE*,bool);
	bool	(*_user_split_curve)(int,POINT*,BOND*,CURVE*,CURVE**);
	bool	(*_user_join_curves)(CURVE*,CURVE*,CURVE*);

	/* Bond utilities */
	BOND	*(*_Bond)(POINT*,POINT*);
#if defined(THREED)
	BOND_TRI *(*_link_tri_to_bond)(BOND_TRI*,TRI*,SURFACE*,BOND*,CURVE*);
	void 	(*_reverse_bond)(BOND*);
	void 	(*_reorder_curve_link_list)(CURVE*);
#endif /* defined(THREED) */

	/* Point utility functions */
	POINT	*(*_Point)(float*);
	POINT	*(*_Static_point)(INTERFACE*);
	POINT	*(*_copy_point)(POINT*);
	POINT   *(*_average_points)(bool,POINT*,HYPER_SURF_ELEMENT*,HYPER_SURF*,
		                         POINT*,HYPER_SURF_ELEMENT*,HYPER_SURF*);
#if defined(ONED)
	POINT	*(*_make_point)(float*,COMPONENT,COMPONENT);
	int	(*_delete_point)(POINT*);
	void	(*_fprint_point)(FILE*,POINT*);
	void	(*_user_fprint_point)(FILE*,POINT*);
	POINT	*(*_read_point)(INTERFACE*,int);
	void	(*_user_read_point)(INTERFACE*,POINT*);
	POINT	*(*_read_print_point)(INTERFACE*,const IO_TYPE*,bool);
	void	(*_user_read_print_point)(POINT*,const IO_TYPE*,bool);
#endif /* defined(ONED) */
	bool	(*_insert_point_in_bond)(POINT*,BOND*,CURVE*);
	bool	(*_delete_start_of_bond)(BOND*,CURVE*);
	bool	(*_delete_end_of_bond)(BOND*,CURVE*);
#if defined(THREED)
	SURFACE *(*_join_surfaces)(CURVE*);
	bool	(*_insert_point_in_tri)(POINT*,TRI*,SURFACE*);
	bool	(*_insert_point_in_tri_side)(POINT*,int,TRI*,SURFACE*);
	bool	(*_undo_insert_point_in_tri)(POINT*,TRI*,SURFACE*);
	bool	(*_undo_insert_point_in_tri_side)(POINT*,int,TRI*,SURFACE*);
#endif /* defined(THREED) */

#if defined(THREED)
	/* Tri utility functions */
	TRI *(*_make_tri)(POINT*,POINT*,POINT*,
			  POINTER,POINTER,POINTER,int);

	/* Surface utility functions */
	SURFACE	*(*_make_surface)(COMPONENT,COMPONENT,CURVE**,CURVE**);
	SURFACE	*(*_copy_surface)(SURFACE*,CURVE**,CURVE**,bool);
	int	(*_delete_surface)(SURFACE*);
	void	(*_fprint_surface)(FILE*,SURFACE*);
	void	(*_user_fprint_surface)(FILE*,SURFACE*);
	SURFACE	*(*_read_surface)(INTERFACE*,int);
	void	(*_user_read_surface)(SURFACE*);
	void	(*_user_read_print_surface)(SURFACE*,const IO_TYPE*,bool);

	/* C_BOND utility functions */
	C_BOND *(*_CBond)(C_BOND*,POINT*,POINT*,TRI*,TRI*);
	bool	(*_sort_bond_tris)(INTERFACE*);
        //#bjet2
	bool    (*_assign_btri_states)(BOND_TRI*,BOND_TRI*);
#endif /* defined(THREED) */

	/* Parallel communication utilities */
	void	(*_send_interface)(INTERFACE*,int);
	INTERFACE	*(*_receive_interface)(int);
	void	(*_reconstruct_interface_pointers)(INTERFACE*,struct Table*,
						   POINTER*,POINTER*);
	void	(*_reconstruct_point_pointers)(POINT*,INTERFACE*,INTERFACE*,
					       POINTER*,POINTER*,int);
	void	(*_reconstruct_node_pointers)(NODE*,INTERFACE*,INTERFACE*,
					      POINTER*,POINTER*,int);
	void	(*_reconstruct_bond_pointers)(BOND*,INTERFACE*,INTERFACE*,
					      POINTER*,POINTER*,int);
	void	(*_reconstruct_curve_pointers)(CURVE*,INTERFACE*,INTERFACE*,
					       POINTER*,POINTER*,int);
#if defined(THREED)
	void	(*_reconstruct_surface_pointers)(SURFACE*,INTERFACE*,
						 INTERFACE*,POINTER*,
						 POINTER*,int);
	void	(*_reconstruct_tri_pointers)(TRI*,INTERFACE*,INTERFACE*,
					     POINTER*,POINTER*,int);
#endif /* defined(THREED) */

	bool	(*_set_boundary)(INTERFACE*,RECT_GRID*,COMPONENT,float);
#if defined(THREED)
	void	(*_user_install_faces)(SURFACE*,int);
	void	(*_assign_curve_boundary_flag)(CURVE*);
	
	//#bjet2
	void    (*_check_print_intfc)(const char*,const char*,char,INTERFACE*,
				int,int,bool);
	SURFACE *(*_detach_one_surface)(SURFACE *); 
	void    (*_print_wall_crx)(const char*,int*,int,int,CRXING*);
	void    (*_print_wall_curve_crx)(const char*,int*,int,int,CRXING*);
	void    (*_print_wall_curve_crx0)(const char*,POINT *, int,CRXING*);

#endif /* defined(THREED) */

	bool	(*_intersections)(INTERFACE*,CROSS**,const bool);
	float   (*_cross_tolerance)(INTERFACE*);
	void	(*_print_intersections)(CROSS*,INTERFACE*);
	int	(*_print_number_of_tangles)(const char*,INTERFACE*,CROSS*);
	void	(*_print_crossing_elements)(CROSS*,INTERFACE*);

	CURVE	*(*_attach_curve_to_node)(CURVE*,POINT*,BOND*,NODE*);
	void	(*_invert_curve)(CURVE*);
	void	(*_reverse_curve)(CURVE*);
	bool	(*_move_closed_loop_node)(CURVE*,BOND*);
	bool	(*_is_subdomain_boundary)(HYPER_SURF*);
	bool	(*_is_subdomain_node)(NODE*);
	bool	(*_is_virtual_fixed_node)(NODE*);
	void	(*_fset_hyper_surf_color)(FILE*,HYPER_SURF*);
	INTERFACE	*(*_zoom_interface)(INTERFACE*,RECT_GRID*,
					    float*,float*,float**);
	void	(*_reflect_interface)(INTERFACE*,float*,float*);
#if defined(THREED)
	void	(*_reflect_surface)(SURFACE*,float*,float*);
#endif /* defined(THREED) */
	void	(*_reflect_curve)(CURVE*,float*,float*);
	void	(*_reflect_node)(NODE*,float*,float*);
	void	(*_reflect_point)(POINT*,float*,float*,INTERFACE*);
	bool	(*_make_interface_topology_lists)(INTERFACE*);

	float	(*_random01)(INTERFACE*);
	unsigned short int _random01_seed[3];

	COMP_LIST	_excluded_comps;

	/* Debugging utilities */
#if defined(THREED)
	bool	(*_consistent_interface)(INTERFACE*);
#endif /* defined(THREED) */

	struct _I_INTERFACE_TOLERANCES {
		float	_Parallel;
		float   _Min_sin_sqr;
		float	_MinScaledSeparation;
		float	_MinScaledLength;
		float   _EndOfCurve;
		float   _StartOfCurve;
		float   _RcbMinScaledSep;
		float   _RobustFac;
		float   _RcbMacTol;
		float   _RcbcRobustFac;
		float   _ReflectTol;
		float   _TolFac;
		int	_ShortCurveNumPoints;
	} _InterfaceTolerances;
};
typedef struct _I_USER_INTERFACE I_USER_INTERFACE;
}}}

}}}
liquid/liqinit.c
{{{
void L_CARTESIAN::initCirclePlaneIntfc(
	LEVEL_FUNC_PACK *level_func_pack,
	char *inname)
{
	FILE *infile = fopen(inname,"r");
	static CIRCLE_PARAMS *circle_params;
	int i,dim;

	eqn_params = (EQN_PARAMS*)front->extra;
	scalar(&circle_params,sizeof(CIRCLE_PARAMS));
        circle_params->dim = dim = front->rect_grid->dim;
        circle_params->add_plan_surf = NO;
        CursorAfterString(infile,"Enter the center of the circle:");
        for (i = 0; i < dim; ++i)
            fscanf(infile,"%lf",&circle_params->cen[i]);
        CursorAfterString(infile,"Enter radius of the circle:");
        fscanf(infile,"%lf",&circle_params->R);

        if (eqn_params->prob_type == BUBBLE_SURFACE)
        {
            CursorAfterString(infile,"Enter height of the surface:");
            fscanf(infile,"%lf",&circle_params->H);
            circle_params->add_plan_surf = YES;
        }
	level_func_pack->func_params = (POINTER)circle_params;

	switch (eqn_params->prob_type)
	{
	case TWO_FLUID_BUBBLE:
        case BUBBLE_SURFACE:
            level_func_pack->neg_component = LIQUID_COMP1;
            level_func_pack->pos_component = LIQUID_COMP2;
            level_func_pack->func = level_circle_func;
            level_func_pack->wave_type = FIRST_PHYSICS_WAVE_TYPE;
	    CursorAfterString(infile,"Enter density and viscosity of fluid 1:");            fscanf(infile,"%lf %lf",&eqn_params->rho1,&eqn_params->mu1);
            CursorAfterString(infile,"Enter density and viscosity of fluid 2:");            fscanf(infile,"%lf %lf",&eqn_params->rho2,&eqn_params->mu2);
            break;
        case FLUID_SOLID_CIRCLE:
            level_func_pack->neg_component = SOLID_COMP;
            level_func_pack->pos_component = LIQUID_COMP2;
            level_func_pack->func = level_circle_func;
            level_func_pack->wave_type = NEUMANN_BOUNDARY;
            CursorAfterString(infile,"Enter density and viscosity of the fluid:");
            fscanf(infile,"%lf %lf",&eqn_params->rho2,&eqn_params->mu2);
            break;
	}
	CursorAfterString(infile,"Enter gravity:");
        for (i = 0; i < dim; ++i)
            fscanf(infile,"%lf",&eqn_params->gravity[i]);
	fclose(infile);	
}	/* end initCirclePlaneIntfc */
}}}
liquid/liqinit.c
{{{
void L_CARTESIAN::initRayleiTaylorIntfc(
	LEVEL_FUNC_PACK *level_func_pack,
	char *inname)
{
	EQN_PARAMS *eqn_params = (EQN_PARAMS*)front->extra;
	static FOURIER_POLY level_func_params;
	static double L[MAXD],U[MAXD];
	FILE *infile = fopen(inname,"r");
	int i,j,num_modes;
	char mesg[100];

	dim = level_func_params.dim = front->rect_grid->dim;
	level_func_params.L = L;
	level_func_params.U = U;
	for (i = 0; i < dim; ++i)
	{
	    level_func_params.L[i] = front->rect_grid->L[i];
	    level_func_params.U[i] = front->rect_grid->U[i];
	}

	level_func_pack->neg_component = LIQUID_COMP1;
        level_func_pack->pos_component = LIQUID_COMP2;
	level_func_pack->wave_type = FIRST_PHYSICS_WAVE_TYPE;
	CursorAfterString(infile,"Enter mean position of fluid interface:");
	fscanf(infile,"%lf",&level_func_params.z0);
	CursorAfterString(infile,"Enter number of sine modes:");
	fscanf(infile,"%d",&num_modes);
	level_func_params.num_modes = num_modes;
	bi_array(&level_func_params.nu,num_modes,dim-1,sizeof(double));
	uni_array(&level_func_params.phase,num_modes,sizeof(double));
	uni_array(&level_func_params.A,num_modes,sizeof(double));
	for (i = 0; i < num_modes; ++i)
	{
	    sprintf(mesg,"Enter frequency of mode %d:",i+1);
	    CursorAfterString(infile,mesg);
	    for (j = 0; j < dim; ++j)
	    	fscanf(infile,"%lf",&level_func_params.nu[i][j]);
	    sprintf(mesg,"Enter amplitude of mode %d:",i+1);
	    CursorAfterString(infile,mesg);
	    fscanf(infile,"%lf",&level_func_params.A[i]);
	    sprintf(mesg,"Enter phase of mode %d:",i+1);
	    CursorAfterString(infile,mesg);
	    fscanf(infile,"%lf",&level_func_params.phase[i]);
	}
	CursorAfterString(infile,"Enter density and viscosity of fluid 1:");
        fscanf(infile,"%lf %lf",&eqn_params->rho1,&eqn_params->mu1);
        CursorAfterString(infile,"Enter density and viscosity of fluid 2:");
        fscanf(infile,"%lf %lf",&eqn_params->rho2,&eqn_params->mu2);
	CursorAfterString(infile,"Enter gravity:");
        for (i = 0; i < dim; ++i)
            fscanf(infile,"%lf",&eqn_params->gravity[i]);

	level_func_pack->func_params = (POINTER)&level_func_params;
	level_func_pack->func = level_wave_func;
	fclose(infile);
}	/* end initRayleiTaylor */
}}}
src/front/finit.c
{{{
/*
*			     init_front():
*
*	Initialization of a front involves setting various parameters 
*	such as the type of redistribute algorithm to be used, 
*	the front spacing, the time step factor.
*/


EXPORT void init_front(
	INIT_DATA     *init,
	Front	      *front)
{
	debug_print("init","Entered init_front()\n");

	Clear_redistribution_parameters(front);
	front->redis_flag = NO;
	front->dismin = front->dismax = front->distance = 0.0;
        front->hmin_fre = front->hmax_fre = 0.0;
	if (restart_io_type(init) != NULL)
	    read_print_front(init,front);

		/* Choose Redistribution Method */

	Init_redistribution(init,front);

	    /* Choose Constant to Increase/Decrease Time-Steps */

	front->Tstep = time_step_control_options(init);

	debug_print("init","Left init_front()\n");
}		/*end init_front*/
}}}
{{{
EXPORT void   init_intfc_curvature3d(
       Front               *front,
       INTERFACE           *intfc)
{
       HYPER_SURF              *hs;
       HYPER_SURF_ELEMENT      *hse;
       POINT                   *p;
     
      
       (void) next_point(intfc,NULL,NULL,NULL);
       while (next_point(intfc,&p,&hse,&hs))
           p->curvature = mean_curvature_at_point(p,hse,hs,front);
       
       //fix 3 comp curve case and also a nan bug
       (void) next_point(intfc,NULL,NULL,NULL);
       while (next_point(intfc,&p,&hse,&hs))
       {
	   if(Boundary_point(p))
	   {
               p->curvature = 0.0;
	       continue;
	   }
	   
	   if(isnan(p->curvature))
	   {
		int	i, nt;
		TRI	**ptris;

		//in this case, triangle with 0 area may appear.
		printf("WARNING init_intfc_curvature3d, "
	       	       "p->curvature=%24.16e, set to 0.0\n", p->curvature);
		print_general_vector("p=", Coords(p), 3, "\n");
		nt = set_tri_list_around_point(p,Tri_of_hse(hse),&ptris,intfc);
		p->curvature = 0.0;
		for(i=0; i<nt; i++)
		    print_tri(ptris[i], intfc);
		tecplot_tris("cur_tst", ptris, nt);
	   }
       }
}
}}}
src/intfc/userhooks.c
{{{
EXPORT	bool insert_point_in_bond(
	POINT		*p,
	BOND		*b,
	CURVE		*c)
{
	if (c == NULL || c->interface == NULL)
	    return FUNCTION_FAILED;
	return (*i_user_interface(c->interface)._insert_point_in_bond)(p,b,c);
}		/*end insert_point_in_bond*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	bool	insert_point_in_tri_side(
	POINT	*p,
	int	side,
	TRI	*tri,
	SURFACE	*s)
{
	INTERFACE *intfc;
	if ((s == NULL) || ((intfc = s->interface) == NULL))
	    return FUNCTION_FAILED;
	return (*i_user_interface(intfc)._insert_point_in_tri_side)(p,side,tri,
								    s);
}		/*end insert_point_in_tri_side*/
}}}
src/intfc/imkcurve.c
{{{
LOCAL	int install_grid_crx2d(
	double (*func)(POINTER,double*),
        POINTER func_params,
	EG_CRX_2D *eg_crx,
	RECT_GRID *grid)
{
	double coords1[MAXD];
	double coords2[MAXD];
	double crds_crx[MAXD];
	double *L = grid->L;
	double *h = grid->h;
	int *gmax = grid->gmax;
	int dim = grid->dim;
	int i,j,n_crx;
	BBI_POINT ***x_crx = eg_crx->x_crx;
	BBI_POINT ***y_crx = eg_crx->y_crx;
	BBI_POINT *crx_store = eg_crx->crx_store;
	COMPONENT **comp = eg_crx->comp;

	n_crx = 0;

	/* install x-crossings */

	for (j = 0; j <= gmax[1]; ++j)
	{
	    coords1[1] = coords2[1] = L[1] + j*h[1];
	    for (i = 0; i < gmax[0]; ++i)
	    {
		x_crx[i][j] = NULL;
		if (comp[i][j] != comp[i+1][j])
		{
		    coords1[0] = L[0] + i*h[0];
		    coords2[0] = L[0] + (i+1)*h[0];
		    if (! grid_line_crx_in_dir(func,func_params,
				dim,coords1,coords2,crds_crx,0))
		    {
			screen("ERROR: in install_grid_crx(), no x-crxing!");
			clean_up(ERROR);
		    }
		    if (crds_crx[0] - coords1[0] < 0.004*h[0])
			crds_crx[0] = coords1[0] + 0.004*h[0];
		    if (coords2[0] - crds_crx[0] < 0.004*h[0])
			crds_crx[0] = coords2[0] - 0.004*h[0];
		    crx_store[n_crx].p = Point(crds_crx);
		    x_crx[i][j] = &crx_store[n_crx++];
		}
	    }
	}

	/* install y-crossings */

	for (i = 0; i <= gmax[0]; ++i)
	{
	    coords1[0] = coords2[0] = L[0] + i*h[0];
	    for (j = 0; j < gmax[1]; ++j)
	    {
		y_crx[i][j] = NULL;
		if (comp[i][j] != comp[i][j+1])
		{
		    coords1[1] = L[1] + j*h[1];
		    coords2[1] = L[1] + (j+1)*h[1];
		    if (!grid_line_crx_in_dir(func,func_params,
			dim,coords1,coords2,crds_crx,1))
		    {
			screen("ERROR: in install_grid_crx(), no y-crxing!");
			clean_up(ERROR);
		    }
		    if (crds_crx[1] - coords1[1] < 0.004*h[1])
			crds_crx[1] = coords1[1] + 0.004*h[1];
		    if (coords2[1] - crds_crx[1] < 0.004*h[1])
			crds_crx[1] = coords2[1] - 0.004*h[1];
		    crx_store[n_crx].p = Point(crds_crx);
		    y_crx[i][j] = &crx_store[n_crx++];
		}
	    }
	}

	return n_crx;
}	/* end install_grid_crx */
}}}
{{{
	INTERFACE *interf;		/* Interface */
}}}
[[POINT]]
|int _BOUNDARY|
|double _coords[MAXD]|
|[[point_flags]]|
|[[INTERFACE]]|
|[[POINT]] :points to itself|
|[[HYPER_SURF]]|
|[[HYPER_SURF_ELEMMENT]]|
|[[TRI]]|
|int num_tris|
|[[private_data]]|
|double _nor[3]   /*normal*/|
|double _nor0[3]  /*First order normal for WLSP*/|
|double curvature  /*mean curvature*/|
|double vel[3]|
|bool crx|
|int indx|
[[NODE]]
|int _boundary|
|[[NODE]]  /* refer to itself */|
|[[HYPER_SURF_BDRY]]|
|[[POINT]] *posn|
|[[CURVE]] **in_curves /* Pointer to Set of In Curves */|
|[[CURVE]] **out_curves  /* Pointer to Set of Out Curves */|
[[CURVE]]
|int _boundary;		/* Mandatory first element,  see notes on  boundary macros below */|
|[[CURVE]] *obj;	/* refers back to curve, see boundary macro */|
|[[HYPER_SURF]] *hs;|
|[[HYPER_SURF_BDRY]] *hsb;|
|[[INTERFACE]] *interface;|
|[[NODE]] *start;|
|[[NODE]] *end;|
|[[SURFACE]] **pos_surfaces;|
|[[SURFACE]] **neg_surfaces;|
|int	number;|
|int	redist_order;|
|[[BOND]] *first;|
|[[BOND]] *last;|
|int num_points;|
|int orientation;	/* Orientation of closed curve  1 for positive, -1 for negative */|
|int  sindx, eindx;|
[[HYPER_SURF_BDRY]]
|obj|
|[[INTERFACE]]|
|[[HYPER_SURF_BDRY]]|
[[HYPER_SURF]]
|[[obj]]  a union of point, curve or surface|
|[[INTERFACE]] /*points to the parent interface*/|
|[[HYPER_SURF]] points to itself|
|[[COMPONENT]] different side of [[obj]]|
|int pp_index;  /* Identifies families of connected hypersurfaces */|

[[INTERFACE]] in intfc/int.h
|[[HYPER_SURF]]|
|[[HYPER_SURF_BDRY]]|
|[[POINT]]|
|[[NODE]]|
|[[CURVE]]|
|[[SURFACE]]|
|[[C_CURVE]]|
|[[TABLE]]|
|[[INTERFACE]] *prev_interf|
|[[TRI]]|
include
|[[util/cdecs.h]]|
defines the pointers queue
include
|[[util/cdecs.h]]|[[util/vmalloc]]|[[intfc/triangledefs.h]]|
----
This header file defines the dimension, remap type, regular grid 
include
|[[intfc/int.h]]|[[intfc/ilocprotos.h]]
Defines INTERFACE_ADDRESSES
include
None
Function Declarations Internal to Interface
include
|[[intfc/geom.h]]|[[intfc/array.h]]|[[intfc/table.h]]|[[intfc/userint.h]]|[[intfc/iprotos.h]]|[[intfc/int_amr.h]]|
Defines the interface and related structures, such as Point, Node, Bond
include
|[[intfc/int.h]]|
Defines [[PATCH_BDRY_FLAG]] structure
include
|[[intfc/int.h]]|
Defines function prototypes related to [[intfc]]
include
|[[intfc/int.h]]|
Defines the [[TABLE]] structure used in [[INTERFACE]]
include
|[[util/cdecs.h]]|[[util/vmalloc]]|
Include file for programs that call Triangle.    Accompanies Triangle Version 1.3   
include
|[[intfc/int.h]]|
Defines  User Supplied Operations, all kinds of function pointers
src/front/fdecs.h
{{{
#define intfc_propagate(fr,wave,old_intfc,new_intfc,dt)			\
    if ((fr)->intfc_propagate != NULL)					\
	(*(fr)->intfc_propagate)(fr,wave,old_intfc,new_intfc,dt);
}}}
liquid/liqinit.c
{{{
void L_CARTESIAN::setInitialIntfc(
        LEVEL_FUNC_PACK *level_func_pack,
        char *inname)
{
        eqn_params = (EQN_PARAMS*)front->extra;
        switch (eqn_params->prob_type)
        {
	case TWO_FLUID_BUBBLE:
        case FLUID_SOLID_CIRCLE:
        case BUBBLE_SURFACE:
            initCirclePlaneIntfc(level_func_pack,inname);
            break;
        case TWO_FLUID_RT:
            initRayleiTaylorIntfc(level_func_pack,inname);
            break;
        }
}       /* end setInitialIntfc */
}}}
liquid/lcartsn.c
{{{
// for initial condition: 
// 		setInitialCondition();	
// this function should be called before solve()
// for the source term of the momentum equation: 	
// 		computeSourceTerm();
void L_CARTESIAN::solve(double dt)
{
	m_dt = dt;
	max_speed = 0.0;

	start_clock("solve");
	makeGridIntfc();

	setComponent();
	if (debugging("trace"))
	    printf("Passed setComponent()\n");
	setGlobalIndex();
	if (debugging("trace"))
	    printf("Passed setGlobalIndex()\n");
	setSmoothedProperties();
	if (debugging("trace"))
	    printf("Passed setSmoothedProperties()\n");
	
	// 1) solve for intermediate velocity
	computeAdvection();
	if (debugging("trace"))
	    printf("max_speed after computeAdvection(): %20.14f\n",
				max_speed);
	
	start_clock("compDiffWithSmoothProperty");
	compDiffWithSmoothProperty();
	stop_clock("compDiffWithSmoothProperty");

        start_clock("compSGS");
        //compSGS();	//Subgrid model by Hyunkyun Lim
        stop_clock("compSGS");

	if (debugging("trace"))
	    printf("max_speed after compDiffWithSmoothProperty(): %20.14f\n",
				max_speed);

	// 2) projection step
	start_clock("computeProjection");
	computeProjection();
	stop_clock("computeProjection");

	start_clock("computeNewVelocity");
	computeNewVelocity();
	if (debugging("sample_velocity"))
	{
	    sampleVelocity(VERTICAL_CENTER);
	    sampleVelocity(HORIZONTAL_UPPER_EDGE);
	    sampleVelocity(HORIZONTAL_LOWER_EDGE);
	}
	stop_clock("computeNewVelocity");

	if (debugging("trace"))
	    printf("max_speed after computeNewVelocity(): %20.14f\n",
				max_speed);

	start_clock("copyMeshStates");
	copyMeshStates();
	stop_clock("copyMeshStates");

	setAdvectionDt();
	deleteGridIntfc();
	stop_clock("solve");
}	/* end solve */
}}}
!!input
*[[read_liquid_params]] Read liquid problem type
*[[read_movie_option]] Options for making hdf movie file
*[[l_cartesian.setInitialIntfc]]
**[[initCirclePlaneIntf]]
**[[initRayleiTaylorIntfc]] Read in frequency, amplitude, density, viscosity, surface tension and gravity etc.
*[[read_dirichlet_bdry_data]]
!!output file
*liquid code will make a directory "gv-init" directory of geomview file of the initial interface in the current dirctory
 state-liquid file
*[[L_CARTESIAN::printFrontInteriorStates]]
----
main()
#[[l_cartesian.setInitialIntfc]]
#*[[initCirclePlaneIntf]]
#[[FrontInitIntfc]]

[[fluid_driver]]
for(;;)
#[[FrontProp]]
##[[FrontAdvance]]
##[[FrontFreeGridIntfc]]
##[[assign_interface_and_free_front]]
##[[FrontMakeGridIntfc]]
#[[l_cartesian.solve(front->dt)]]
#*[[L_CARTESIAN]]
##[[setDomain]]
##[[setComponent]]
##[[setGlobalIndex]]
##[[setSmoothedProperties]]
##*[[setSmoothedProperties2d]]
##*[[setSmoothedProperties3d]]
##[[computeAdvection]]
##*[[computeAdvection2d]]
##*[[computeAdvection3d]]
##[[compDiffWithSmoothProperty]]
##*[[compDiffWithSmoothProperty2d_decouple]]
##*[[compDiffWithSmoothProperty3d_decouple]]
##[[computeProjection]]
##*[[computeProjectio2d]]
##*[[computeProjectio3d]]
##[[computeNewVelocity]]
##*[[computeNewVelocit2d]]
##*[[computeNewVelocit3d]]
##[[copyMeshStates]]
##[[setAdvectionDt]]

[[L_CARTESIAN::setInitialCondition]]
[[L_CARTESIAN::initMovieVariables]]
----
[[FrontInitIntfc3d_HK]]
[[fluid_driver]]
for(;;)
#[[FrontMakeGridIntfc]]
#[[FrontAdvance]]
#[[FrontFreeGridIntfc]]
#[[l_cartesian.solve(front->dt)]]
#*[[L_CARTESIAN]]
##[[makeGridIntfc]]
##[[setComponent]]
##[[setGlobalIndex]]
##[[setSmoothedProperties]]
##*[[setSmoothedProperties2d]]
##*[[setSmoothedProperties3d]]
##[[computeAdvection]]
##*[[computeAdvection2d]]
##*[[computeAdvection3d]]
##[[compDiffWithSmoothProperty]]
##*[[compDiffWithSmoothProperty2d_decouple]]
##*[[compDiffWithSmoothProperty3d_decouple]]
##[[computeProjection]]
##*[[computeProjectio2d]]
##*[[computeProjectio3d]]
##[[computeNewVelocity]]
##*[[computeNewVelocit2d]]
##*[[computeNewVelocit3d]]
##[[copyMeshStates]]
##[[setAdvectionDt]]
##[[deleteGridIntfc]]
#[[assign_interface_and_free_front]]
liquid/lcartsn.c
{{{
void L_CARTESIAN::makeGridIntfc()
{
	static bool first = YES;
	INTERFACE *grid_intfc;
	Table *T;
	int i,size;

	FrontMakeGridIntfc(front);

	grid_intfc = front->grid_intfc;
	top_grid = &topological_grid(grid_intfc);
	lbuf = front->rect_grid->lbuf;
	ubuf = front->rect_grid->ubuf;
	top_gmax = top_grid->gmax;
	top_L = top_grid->L;
	top_U = top_grid->U;
	top_h = top_grid->h;
	dim = grid_intfc->dim;
	T = table_of_interface(grid_intfc);
	top_comp = T->components;
	eqn_params = (EQN_PARAMS*)front->extra;
	
	hmin = top_h[0];
	size = top_gmax[0]+1;
        for (i = 1; i < dim; ++i)
	{
            if (hmin > top_h[i]) hmin = top_h[i];
	    size *= (top_gmax[i]+1);
	}

	switch (dim)
	{
	case 2:
	    if (first)
	    {
                scalar(&field,sizeof(FIELD));
                eqn_params->field = field;
	    	uni_array(&array,size,sizeof(double));
	    	uni_array(&eqn_params->pres,size,sizeof(double));
	    	uni_array(&eqn_params->vort,size,sizeof(double));
	    	bi_array(&eqn_params->vel,2,size,sizeof(double));
	    	first = NO;
	    }
	    imin = (lbuf[0] == 0) ? 1 : lbuf[0];
	    jmin = (lbuf[1] == 0) ? 1 : lbuf[1];
	    imax = (ubuf[0] == 0) ? top_gmax[0] - 1 : top_gmax[0] - ubuf[0];
	    jmax = (ubuf[1] == 0) ? top_gmax[1] - 1 : top_gmax[1] - ubuf[1];
	    break;
	case 3:
	    if (first)
	    {
                scalar(&field,sizeof(FIELD));
                eqn_params->field = field;
	    	uni_array(&array,size,sizeof(double));
	    	uni_array(&eqn_params->pres,size,sizeof(double));
	    	bi_array(&eqn_params->vel,3,size,sizeof(double));
	    	bi_array(&eqn_params->vort3d,3,size,sizeof(double));
	    	first = NO;
	    }
	    imin = (lbuf[0] == 0) ? 1 : lbuf[0];
	    jmin = (lbuf[1] == 0) ? 1 : lbuf[1];
	    kmin = (lbuf[2] == 0) ? 1 : lbuf[2];
	    imax = (ubuf[0] == 0) ? top_gmax[0] - 1 : top_gmax[0] - ubuf[0];
	    jmax = (ubuf[1] == 0) ? top_gmax[1] - 1 : top_gmax[1] - ubuf[1];
	    kmax = (ubuf[2] == 0) ? top_gmax[2] - 1 : top_gmax[2] - ubuf[2];
	    break;
	}
}

}}}
src/intfc/imkcurve.c
{{{
EXPORT CURVE *make_array_curve(
	INTERFACE   *intfc,
	COMPONENT   left_comp,
	COMPONENT   right_comp,
	int	    num_points,
	double	    **point_array,
	bool	    is_closed_curve)
{
	int i;
	CURVE *c;
	NODE *ns,*ne;
	INTERFACE *save_intfc;
	double coords[MAXD];

	save_intfc = current_interface();
        set_current_interface(intfc);

	if (is_closed_curve)
	{
	    coords[0] = point_array[0][0];
	    coords[1] = point_array[0][1];
	    ns = ne = make_node(Point(coords));
	}
	else
	{
	    coords[0] = point_array[0][0];
	    coords[1] = point_array[0][1];
	    ns = make_node(Point(coords));
	    coords[0] = point_array[num_points-1][0];
	    coords[1] = point_array[num_points-1][1];
	    ne = make_node(Point(coords));
	    num_points--;
	}
	c = make_curve(left_comp,right_comp,ns,ne);
	for (i = 1; i < num_points; ++i)
	{
	    coords[0] = point_array[i][0];
	    coords[1] = point_array[i][1];
	    insert_point_in_bond(Point(coords),c->last,c);
	}

	set_current_interface(save_intfc);
	return c;
}	/* end make_array_curve */
}}}
src/inftc/userhooks.c
{{{
EXPORT	CURVE *make_curve(
	COMPONENT	left_c,
	COMPONENT	right_c,
	NODE		*start,
	NODE		*end)
{
	INTERFACE *intfc = current_interface();

	if (intfc == NULL)
	    return NULL;
	return (*i_user_interface(intfc)._make_curve)(left_c,right_c,start,end);
}		/*end make_curve*/
}}}
src/intfc/imkcurve.c
{{{
LOCAL	void make_grid_curves(
	BLK_CRX_2D      *blk_crx,
	const EG_CRX_2D *eg_crx,
	int             *gmax,
	BOND		**first,
	int		*num_segs)
{
	int i,j,k,num_blk;
	BLK_BOND *bm,***blk_mem,*blk_mem_store;
	BOND *b;

	num_blk = 0;
	for (i = 0; i < gmax[0]; ++i)
	{
	    for (j = 0; j < gmax[1]; ++j)
	    {
		    if (onfront_block2d(i,j,eg_crx))
			++num_blk;
	    }
	}
	bi_array(&blk_mem,gmax[0],gmax[1],sizeof(BLK_BOND*));
        uni_array(&blk_mem_store,num_blk,sizeof(BLK_BOND));

	num_blk = 0;
	for (i = 0; i < gmax[0]; ++i)
	{
	    for (j = 0; j < gmax[1]; ++j)
	    {
		if (onfront_block2d(i,j,eg_crx))
		{
		    bm = blk_mem[i][j] = &blk_mem_store[num_blk++];
		    bm->blk_info = blk_crx->blk_info;
		    assign_blk_crx2d(blk_crx,i,j,eg_crx);
		    switch (blk_crx->blk_type)
		    {
		    case COMP2_BLOCK:
			construct_comp2_blk2d(blk_crx,bm);
			break;
		    default:
			screen("UNKNOWN BLOCK: code needed!\n");
			clean_up(ERROR);
		    }
		    if (i != 0 && blk_mem[i-1][j] != NULL)
			connect_adj_blk(blk_mem[i-1][j],bm);
		    if (j != 0 && blk_mem[i][j-1] != NULL)
			connect_adj_blk(blk_mem[i][j-1],bm);
		}
	    }
	}
	*num_segs = 0;
	for (i = 0; i < num_blk; ++i)
	{
	    int nc = blk_mem_store[i].num_curves;
	    for (j = 0; j < nc; ++j)
	    {
	    	int nb = blk_mem_store[i].num_bonds[j];
		for (k = 0; k < nb; ++k)
		{
		    if (blk_mem_store[i].bonds[j][k]->prev == NULL)
		    	first[(*num_segs)++] = blk_mem_store[i].bonds[j][k];
		}
	    }
	}

	free_these(2,blk_mem,blk_mem_store);
}	/* end make_grid_curves */
}}}
src/inftc/userhooks.c
{{{
EXPORT	HYPER_SURF *make_hypersurface(
	COMPONENT	left_c,
	COMPONENT	right_c)
{
	INTERFACE *intfc = current_interface();

	if (intfc == NULL)
	    return NULL;
	return (*i_user_interface(intfc)._make_hypersurface)(left_c,right_c);
}		/*end make_hypersurface*/
}}}
src/intfc/intfc.c
{{{
/*
*				make_interface():
*
*	Creates a new Interface and an associated Table in the
*	Interface Table List.   Apart from the Table, no other
*	storage is allocated here.   However both the cur_intfc
*	and cur_IT are set to point to the newly created object
*	provided the allocation is successful.
*
*	Returns a pointer to the interface, or NULL if out of
*	space.
*/

EXPORT INTERFACE *make_interface(
	int		dim)
{
	I_USER_INTERFACE *uh;
	int		i, j;

	    /* Allocate a new Table Entry: */

	if (DEBUG)
	    (void) printf("\n\nEntered make_interface()\n");
	if (new_table(dim) == NULL)
	    return NULL;
	cur_intfc->dim = dim;

	cur_intfc->num_points = 0;
	for (i = 0; i < dim; ++i)
	    for (j = 0; j < 2; ++j)
	        rect_boundary_type(cur_intfc,i,j) = UNKNOWN_BOUNDARY_TYPE;

	interface_reconstructed(cur_intfc) = NO;
	uh = i_user_hook(dim);
	i_user_interface(cur_intfc) = *uh;
	user_make_interface(cur_intfc);
	cur_intfc->normal_unset = YES;
	cur_intfc->curvature_unset = YES;

	if (DEBUG)
	    (void) printf("Left make_interface()\n\n");
	return cur_intfc;
}		/*end make_interface*/
}}}
src/intfc/imkcurve
{{{
/*******************************************************************
*       This function make a curve described by the function       *
*       func = 0. The negative side of the curve has right_comp    *
*       and the positive side of the curve has left_comp.          *
*******************************************************************/

EXPORT CURVE *make_level_curve(
	RECT_GRID   *rgr,
	INTERFACE   *intfc,
	COMPONENT   left_comp,
	COMPONENT   right_comp,
	double       (*func)(POINTER,double*),
        POINTER     func_params,
	bool	    use_dual_grid)
{
	int		i,num_crx,num_segs,np,*gmax;
	RECT_GRID	dual_gr,*grid;
	CURVE		*curve;
	EG_CRX_2D	Eg_crx;
	BLK_INFO	blk_info;
	static BLK_CRX_2D  *blk_crx;
	double		coords[2] = {0.0,0.0};
	NODE		*ns,*ne;
	BOND 		*b,*first[MAX_NUM_SEGMENTS];
        INTERFACE       *save_intfc;

        save_intfc = current_interface();
        set_current_interface(intfc);

	if (blk_crx == NULL)
	    blk_crx = alloc_blk_crx2d(NO);

	zero_scalar(&Eg_crx,sizeof(EG_CRX_2D));
	if (use_dual_grid)
	{
	    set_grid_for_surface_construction(&dual_gr,rgr);
	    grid = &dual_gr;
	}
	else
	    grid = rgr;
	gmax = grid->gmax;
	bi_array(&Eg_crx.comp,gmax[0]+1,gmax[1]+1,sizeof(COMPONENT));

	reset_domain_comp2d(Eg_crx.comp,grid);
	assign_two_comp_domain2d(func,func_params,Eg_crx.comp,
				grid,right_comp,left_comp);
	num_crx = count_crx_through_comp2d(gmax,Eg_crx.comp);
	if (num_crx == 0)
	{
	    intfc->default_comp = Eg_crx.comp[0][0];
	    free_these(1,Eg_crx.comp);
	    return NULL;
	}

	bi_array(&Eg_crx.x_crx,gmax[0],gmax[1]+1,sizeof(BBI_POINT*));
        bi_array(&Eg_crx.y_crx,gmax[0]+1,gmax[1],sizeof(BBI_POINT*));
        uni_array(&Eg_crx.crx_store,num_crx,sizeof(BBI_POINT));

	num_crx = install_grid_crx2d(func,func_params,&Eg_crx,grid);

	ns = make_node(Point(coords));
	ne = make_node(Point(coords));
	curve = make_curve(left_comp,right_comp,ns,ne);

	curve->first = curve->last = NULL;

	blk_info.num_surfs = 1;
	uni_array(&blk_info.curves,1,sizeof(CURVE*));
	uni_array(&blk_info.cur_bonds,1,sizeof(BOND*));

	blk_info.cur_bonds[0] = NULL;
	blk_info.curves[0] = curve;
	curve->num_points = 0;

	blk_crx->comps[0] = right_comp;
	blk_crx->comps[1] = left_comp;
	blk_crx->blk_info = &blk_info;

	for (i = 0; i < num_crx; ++i)
	    Eg_crx.crx_store[i].c = curve;

	make_grid_curves(blk_crx,&Eg_crx,gmax,first,&num_segs);
	curve->num_points = 2;
	for (b = curve->first; b->next != NULL; b = b->next)
	    curve->num_points++;
	curve->last = b;
	if (curve->start->posn == curve->end->posn)
	{
	    change_node_of_curve(curve,NEGATIVE_ORIENTATION,curve->start);
	    delete_node(ne);
	}
	if (num_segs != 1)
	{
	    CURVE *c;
	    for (i = 0; i < num_segs; ++i)
	    {
	    	if (first[i]->start == curve->start->posn)
		    continue;
		np = 2;
		for (b = first[i]; b->next != NULL; b = b->next) ++np;
		if (b->end == first[i]->start)
		{
		    ns = ne = make_node(first[i]->start);
		}
		else
		{
		    ns = make_node(first[i]->start);
		    ne = make_node(b->end);
		}
		c = make_curve(left_comp,right_comp,ns,ne);
		c->first = first[i];
		c->last = b;
		c->num_points = np;
	    }
	}

	free_these(3,Eg_crx.x_crx,Eg_crx.y_crx,Eg_crx.crx_store);
	free_these(3,Eg_crx.comp,blk_info.curves,blk_info.cur_bonds);
	set_current_interface(save_intfc);
	if (num_segs == 1) return curve;
	else return NULL;
}	/* end make_level_surface */
}}}
src/intfc/imksurf.c
{{{
EXPORT bool make_level_surface(
	RECT_GRID   *rgr,
	INTERFACE   *intfc,
	COMPONENT   neg_comp,
	COMPONENT   pos_comp,
	float       (*func)(POINTER,float*),
        POINTER     func_params,
	SURFACE     **s)
{
	int		i,num_crx, *gmax;
	RECT_GRID	dual_gr;
	SURFACE		*surf;
	EG_CRX		Eg_crx;
	BLK_INFO	blk_info;
	static BLK_CRX  *blk_crx;
        INTERFACE       *save_intfc;

        save_intfc = current_interface();
        set_current_interface(intfc);
	if (blk_crx == NULL)
	    blk_crx = alloc_blk_crx(NO);

	zero_scalar(&Eg_crx,sizeof(EG_CRX));

	set_grid_for_surface_construction(&dual_gr,rgr);
	gmax = dual_gr.gmax;
	tri_array(&Eg_crx.comp,gmax[0]+1,gmax[1]+1,gmax[2]+1,
			sizeof(COMPONENT));

	reset_domain_comp(Eg_crx.comp,dual_gr);
	assign_two_comp_domain(func,func_params,Eg_crx.comp,
				dual_gr,neg_comp,pos_comp);
	num_crx = count_crx_through_comp(gmax,Eg_crx.comp);

	alloc_grid_crx_mem(&Eg_crx,gmax,num_crx,NO);

	num_crx = install_grid_crx(func,func_params,&Eg_crx,dual_gr,
				neg_comp,pos_comp);

	surf = make_surface(neg_comp,pos_comp,NULL,NULL);

	first_tri(surf) = last_tri(surf) = NULL;

	blk_info.num_surfs = 1;
	uni_array(&blk_info.surfs,1,sizeof(SURFACE*));
	uni_array(&blk_info.cur_tris,1,sizeof(TRI*));

	blk_info.cur_tris[0] = NULL;
	blk_info.surfs[0] = surf;
	surf->num_tri = 0;

	blk_crx->comps[0] = pos_comp;
	blk_crx->comps[1] = neg_comp;
	blk_crx->blk_info = &blk_info;

	for (i = 0; i < num_crx; ++i)
	    Eg_crx.crx_store[i].s = surf;
	
	make_grid_surfaces(blk_crx,&Eg_crx,gmax,NO);

	if (first_tri(surf) != NULL)
	{
	    last_tri(surf) = blk_info.cur_tris[0];
	    last_tri(surf)->next = tail_of_tri_list(surf);
	    first_tri(surf)->prev = head_of_tri_list(surf);
	    reset_intfc_num_points(surf->interface);
	    interface_reconstructed(surf->interface) = YES;
	}
	else
	    delete_surface(surf);

	free_grid_crx_mem(&Eg_crx,NO);
	free_these(3,Eg_crx.comp,blk_info.surfs,blk_info.cur_tris);
	*s = surf;
	interface_reconstructed(intfc) = YES;
	intfc->modified = YES;
	set_current_interface(save_intfc);
	return YES;
}	/* end make_level_surface */
}}}
src/intfc/userhooks.c
{{{
EXPORT	NODE *make_node(
	POINT		*p)
{
	INTERFACE *intfc = current_interface();

	if (intfc == NULL)
	    return NULL;
	return (*i_user_interface(current_interface())._make_node)(p);
}		/*end make_node*/
}}}
src/inftc/userhooks.c
{{{
EXPORT	POINT *make_point(
	double		*crds,
	COMPONENT	ncomp,
	COMPONENT	pcomp)
{
	INTERFACE	*intfc = current_interface();

	if (intfc == NULL)
	    return NULL;
	return (*i_user_interface(intfc)._make_point)(crds,ncomp,pcomp);
}		/*end make_point*/
}}}
src/front/fadv.c
{{{
LOCAL int mixed_advance_front3d(
	float		dt,
	float		*dt_frac,
	Front		*front,
	Front		**newfront,
	POINTER		wave)
{
	int status;
	float   dt_frac_restore = *dt_frac;
	DEBUG_ENTER(mixed_advance_front3d)

	if (debugging("mixed"))
	{
	    (void) printf("TIMESTEP = %d\n",front->step);
	    (void) printf("MIXED  Redistribution_count(front) = %d\n",
			  Redistribution_count(front));
	    (void) printf("MIXED  Frequency_of_reconstruction(front) = %d\n",
			  Frequency_of_reconstruction(front));
	}
	status = preserve_front_advance_front3d(dt,dt_frac,
				    front,newfront,wave);

	//do not use grid based

	DEBUG_LEAVE(mixed_advance_front3d)
	return status;
}		/*end mixed_advance_front3d*/
}}}
{{{
	int  (*node_propagate)(struct _Front*,POINTER,NODE*,NODE*,RPROBLEM**,
			       float,float*,NODE_FLAG,POINTER);
}}}
src/intfc/int.h
{{{
	union {
		int	*bptr;
		POINT	*p;
		CURVE	*c;
		SURFACE	*s;
	} obj;
}}}
{{{
	struct {
	    unsigned int _boundary : 1;
	    unsigned int _user0 : 1;
	    unsigned int _user1 : 1;
	    unsigned int _user2 : 1;
	    unsigned int _user3 : 1;
	    unsigned int _user4 : 1;
	    unsigned int _user5 : 1;
	    unsigned int _user6 : 1;
	    unsigned int _user7 : 1;
	    unsigned int _user8 : 1;
	    unsigned int _user9 : 1;
	} _point_flags;
}}}
{{{
	void (*_point_propagate)(struct _Front*,POINTER,POINT*,POINT*,
			        HYPER_SURF_ELEMENT*,HYPER_SURF*,float,float*);
}}}
src/front/fadv.c
{{{
LOCAL int preserve_front_advance_front3d(
	float		dt,
	float		*dt_frac,
	Front		*front,
	Front		**newfront,
	POINTER		wave)
{
	static const char *fname = "preserve_front_advance_front3d";
	bool	   has_tracked_surfaces;
	int	   status;
	bool	   do_redist = YES;
	int	   i;

	DEBUG_ENTER(preserve_front_advance_front3d)

	debug_print("front","Entered %s(step %d time %g dt %g)\n",fname,
				front->step,front->time,dt);
	debug_front("old_front","into advance front",front);

	do_redist = NO;
	if (front->step % Frequency_of_redistribution(front,GENERAL_WAVE) == 0)
	    do_redist = YES;

	*newfront = copy_front(front);
	(*newfront)->redis_flag = front->redis_flag;
	Interface_redistributed(*newfront) = NO;
	has_tracked_surfaces = (front->interf->surfaces != NULL) ? YES : NO;
	if (pp_max_status(has_tracked_surfaces) == NO)
	{
	    set_size_of_intfc_state(size_of_state(front->interf));
	    set_copy_intfc_states(YES);
	    (*newfront)->interf = pp_copy_interface(front->interf);
	    status = ((*newfront)->interf != NULL) ? GOOD_STEP : ERROR_IN_STEP;
	    return return_advance_front(front,newfront,status,fname);
	}

	start_clock("copy_interface");

		/* Initialize Newfront */

	set_size_of_intfc_state(size_of_state(front->interf));
	set_copy_intfc_states(NO);
	(*newfront)->interf = pp_copy_interface(front->interf);
	if ((*newfront)->interf == NULL)
	{
	    (void) printf("WARNING in advance_3d_front(), "
	                  "unable to copy interface\n");
	    return return_advance_front(front,newfront,ERROR_IN_STEP,fname);
	}
	stop_clock("copy_interface");

		/* Propagate points on surfaces */

	start_clock("propagate");
	set_copy_intfc_states(YES);

	status = propagate_3d_front(wave,front,*newfront,dt,dt_frac,NO);

	if (status != GOOD_STEP)
	{
	    (void) printf("WARNING in preserve_front_advance_front3d(), "
			  "status from propagate_3d_front() != GOOD_STEP\n");
	    print_time_step_status("time step status = ",status,"\n");
	    return return_advance_front(front,newfront,status,fname);
	}

	debug_front("final_front","after scatter front:",*newfront);
	stop_clock("propagate");

		/* Redistribute the New Front */

	interpolate_intfc_states((*newfront)->interf) = YES;
	switch (redistribute(*newfront,do_redist,NO)) 
	{
	case GOOD_REDISTRIBUTION:
	    Redistribution_count(front) = Redistribution_count(*newfront);
	    status = GOOD_STEP;
	    break;
	
	case UNABLE_TO_UNTANGLE:
	    *dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf);
	    status = MODIFY_TIME_STEP;
	    (void) printf("WARNING in %s(), UNABLE_TO_UNTANGLE, "
	                  "redistribution of front failed\n",fname);
	    (void) printf("dt_frac set to %g\n",*dt_frac);
	    break;

	case MODIFY_TIME_STEP_REDISTRIBUTE: /* Not supported in 3d */
	    *dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf);
	    status = MODIFY_TIME_STEP;
	    (void) printf("WARNING in %s(), "
			  "MODIFY_TIME_STEP_REDISTRIBUTE, ",fname);
	    (void) printf("dt_frac set to %g\n",*dt_frac);
	    break;
		
	case BAD_REDISTRIBUTION:
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    (void) printf("WARNING in %s(), BAD_REDISTRIBUTION, ",fname);
	    (void) printf("dt_frac set to %g\n",*dt_frac);
	    break;
	
	case INCONSISTENT_RECONSTRUCTION:
	    status = REPEAT_TIME_STEP;
	    (void) printf("WARNING in %s(), INCONSISTENT_RECONSTRUCTION\n",
	    		   fname);
	    break;

	default:
	    (void) printf("WARNING in %s(), "
	                  "unknown redistribution status\n",fname);
	    debug_front("ERROR_front","after error",*newfront);
	    clean_up(ERROR);
	    break;
	}
	if (status == GOOD_STEP)
	    reset_normal_on_intfc((*newfront)->interf);
	if (debugging("final_front"))
	    print_Front_structure(front);
	
	if(status == REPEAT_TIME_STEP)
	{
	    if(recon_repeat() >= 1)
	    {
		printf("ERROR preserve_front_advance_front3d, "
		       "repeat time step twice.\n");
		clean_up(ERROR);
	    }
	    else
	    {
		set_repeat(1);
	    }
	}
	else
	    set_repeat(0);

	return return_advance_front(front,newfront,status,fname);
}		/*end preserve_front_advance_front3d*/
}}}
src/front/fprint.c
{{{
EXPORT void print_front_output(
	Front *front,
	char *out_name)
{
	FILE *out_file;
	char dirname[200];
	char intfc_name[200],comp_name[200];
	int step = front->step;
	int dim = front->rect_grid->dim;
	bool save_binary_output = is_binary_output();

	sprintf(dirname,"%s-gv.ts%s",out_name,right_flush(step,7));
#if defined(__MPI__)
	sprintf(dirname,"%s-nd%s",dirname,right_flush(pp_mynode(),4));
#endif /* defined(__MPI__) */
	if (dim != 1)
	    gview_plot_interface(dirname,front->interf);
	sprintf(intfc_name,"%s.ts%s",out_name,right_flush(step,7));
#if defined(__MPI__)
	sprintf(intfc_name,"%s-nd%s",intfc_name,right_flush(pp_mynode(),4));
#endif /* defined(__MPI__) */
	out_file = fopen(intfc_name,"w");
	set_binary_output(YES);
	print_title(out_file,"");
	fprint_front_time_stamp(out_file,front);
	fprintf(out_file,"\n#");
	fprint_interface(out_file,front->interf);
	fclose(out_file);
	if (front->rect_grid->dim == 2)
	{
	    sprintf(comp_name,"%s-comp.ts%s",out_name,right_flush(step,7));
#if defined(__MPI__)
	    sprintf(comp_name,"%s-nd%s",comp_name,right_flush(pp_mynode(),4));
#endif /* defined(__MPI__) */
	    out_file = fopen(comp_name,"w");
	    (void) make_bond_comp_lists(front->interf);
	    show_COMP(out_file,front->interf);
	    fclose(out_file);
	}
	set_binary_output(save_binary_output);
}	/* end print_front_output */
}}}
src/util/simpleio.c
{{{
EXPORT	void	print_machine_parameters(
	FILE *file)
{
	struct utsname Uts;

	(void) foutput(file);
	(void) fprintf(file,"#MACHINE PARAMETERS\n");
	(void) uname(&Uts);
	(void) fprintf(file,"#\tHostname                 = %s\n",Uts.nodename);
	(void) fprintf(file,"#\tOperating System         = %s\n",Uts.sysname);
	(void) fprintf(file,"#\tOS Release               = %s\n",Uts.release);
	(void) fprintf(file,"#\tOS Version               = %s\n",Uts.version);
	(void) fprintf(file,"#\tCPU Type                 = %s\n",Uts.machine);
	(void) fprintf(file,"#\tByte Ordering            = ");
	switch (ft_endian_type())
	{
	case FT_BIG_ENDIAN:
	    (void) fprintf(file,"Big Endian\n");
	    break;
	case FT_LITTLE_ENDIAN:
	    (void) fprintf(file,"Little Endian\n");
	    break;
	case FT_UNKNOWN_ENDIAN:
	default:
 	    (void) printf("Undetermined Endian\n");
	    break;
	}
	(void) fprintf(file,"#\tFloating Point Word Size = %lu\n",
	               sizeof(double));
	(void) fprintf(file,"\n");
}		/*end print_machine_parameters*/
}}}
src/util/simpleio.c
{{{
/*
*			print_title():
*
*	Prints a Run-time Header.
*/

EXPORT void print_title(
	FILE       *file,
	const char *title)
{
	time_t		tvec;
	
	(void) time(&tvec);		/* Get Run Time */

	(void) fprintf(file,"%s",title);
	(void) fprintf(file,"\n\t\tDATE OF RUN  %s\n\n",ctime(&tvec));
	print_machine_parameters(file);
}		/*end print_title*/
}}}
{{{
LOCAL int propagate_3d_front(
	POINTER		wave,
	Front		*front,
	Front		*newfront,
	float		dt,
	float		*dt_frac,
	bool		reconstruct_front)
{
	INTERFACE	*intfc_old;
	float		V[MAXD];
	int             step_status, tangent_status;
	DEBUG_ENTER(propagate_3d_front)

	debug_print("front","Entered propagate_3d_front().\n");

	intfc_old = front->interf;

 	if (front->step == 0)
            init_intfc_curvature3d2(newfront,newfront->interf);

	//after redistribute or restart, the curvature is not calculated.
        init_intfc_curvature3d(front, front->interf);
	
	if (front->_point_propagate != NULL)
	{
	    bool tri_list_status;
	    start_clock("normal_propagate");

	    tri_list_status = 
	        make_tri_comp_lists(intfc_old) == FUNCTION_FAILED ? NO : YES;

	    if (pp_min_status(tri_list_status) == NO)
	    {
	        stop_clock("normal_propagate");
	    	screen("ERROR in propagate_3d_front(), "
	    	       "make_tri_comp_lists() failed\n");
	    	clean_up(ERROR);
	    }
	    
	    /* Set Default Propagation Limits */

	    set_propagation_limits(front,newfront);

	    start_clock("init_propagate");
	    init_propagate(front);
	    stop_clock("init_propagate");

	    //set_wall_flag_for_surface(front->interf);

	    if (front->_point_propagate != NULL)
                propagate_surface_points(front,newfront,wave,dt,V);
	    else if (front->surface_propagate != NULL)
	        surface_propagate(front,newfront,wave,dt,V);
	    
	    if (front->curve_propagate != NULL)
	        propagate_curve_points(front,newfront,wave,dt);
	
	    if (front->node_propagate != NULL)
	    {
	        step_status = propagate_node_points(front,newfront,
						    wave,dt,dt_frac);
		if (step_status != GOOD_STEP)
		{
		    DEBUG_LEAVE(propagate_3d_front)
		    return step_status;
		}
	    }
	    reset_normal_on_intfc(newfront->interf);
	    debug_front("np_front","after normal propagation",newfront);
	    stop_clock("normal_propagate");
	}
	
	debug_propagate_3d_front(newfront);

	interface_reconstructed(newfront->interf) = NO;
	prev_interface(newfront->interf) = front->interf;

	if (reconstruct_front == YES)
	{
	    bool reconstruct_status;
	    start_clock("reconstruct_front");
	    
	    reconstruct_status = reconstruct_front_at_grid_crossing(newfront);
	    
	    reconstruct_status = pp_min_status(reconstruct_status);
	    if (!reconstruct_status)
	    {
	    	stop_clock("reconstruct_front");
	    	(void) printf("WARNING in propagate_3d_front(), "
	    	              "reconstruct_front failed, "
	    	              "MODIFY_TIME_STEP\n");
	    	*dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf);
		(void) printf("dt_frac = %g after scaling by "
			      "TIME_STEP_REDUCTION_FACTOR(front->interf)"
			      " = %g\n",*dt_frac,
			      TIME_STEP_REDUCTION_FACTOR(front->interf));
		DEBUG_LEAVE(propagate_3d_front)
		return MODIFY_TIME_STEP; 
	    }
	    stop_clock("reconstruct_front");
	}

	start_clock("scatter_front");
	if (!scatter_front(newfront))
	{
	    stop_clock("scatter_front");
	    (void) printf("WARNING in propagate_3d_front(), "
	                  "1st scatter_front() failed\n"
	                  "MODIFY_TIME_STEP\n");  
	    *dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf);
	    DEBUG_LEAVE(propagate_3d_front)
	    return MODIFY_TIME_STEP; 
	}
	stop_clock("scatter_front");

	if (front->_tan_point_propagate != NULL)
	{
	    start_clock("tangentiall");
	    
	    tangent_status = propagate_points_tangentially(front,newfront,
							   reconstruct_front,
							   dt,dt_frac,
							   (front->step)%2);
	    if (tangent_status != GOOD_STEP)
	    {
		DEBUG_LEAVE(propagate_3d_front)
		return tangent_status;
	    }
	    
	    tangent_status = propagate_points_tangentially(front,newfront,
							   reconstruct_front,
							   dt,dt_frac,
							   (front->step+1)%2);
	    if (tangent_status != GOOD_STEP)
	    {
		DEBUG_LEAVE(propagate_3d_front)
		return tangent_status;
	    }

	    stop_clock("tangentiall");
	}

	debug_print("front","Left propagate_3d_front()\n");
	DEBUG_LEAVE(propagate_3d_front)
	return GOOD_STEP; 
}		/*end propagate_3d_front*/
}}}
src/front/fadv.c
{{{
LOCAL	void propagate_curve_points(
	Front	*front,
	Front	*newfront,
	POINTER wave,
	float	dt)
{
  	CURVE	**new_curves;
	
	DEBUG_ENTER(propagate_curve_points)
	start_clock("curve_propagate");

	detach_and_propagate_curves(front, newfront, wave, dt);

	order_interface(newfront->interf);
        for(new_curves = newfront->interf->curves; 
	    new_curves && *new_curves; new_curves++)
            reorder_curve_link_list(*new_curves);

	stop_clock("curve_propagate");
	
	DEBUG_LEAVE(propagate_curve_points)
}		/*end propagate_curve_points*/
}}}
src/front/fadv.c
{{{
LOCAL 	int	propagate_node_points(
	Front	*front,
	Front	*newfront,
	POINTER	wave,
	float	dt,
	float	*dt_frac)
{
	NODE		**on, *oldn, **nn, *newn;
	NODE_FLAG	flag;
	int		step_status, node_status;
	RPROBLEM	*rp;
	DEBUG_ENTER(propagate_node_points)

	start_clock("node_propagate");
	set_to_next_node_only(flag);
	step_status = GOOD_STEP;
	for (on = front->interf->nodes, nn = newfront->interf->nodes;
	     on && *on && nn && *nn && step_status==GOOD_STEP;
	     ++on , ++nn)
	{
	    oldn = *on;
	    newn = *nn;
	    node_status = (*front->node_propagate)(front,wave,oldn,newn,
						   &rp,dt,dt_frac,
						   flag,NULL);
	    switch(node_status)	
	    {
	    case GOOD_NODE:
	        break;
	    case ERROR_NODE:
	    default:
	        print_node_status("WARNING in propagate_node_points(), "
			          "node propagate failed with node_status ",
		                  node_status,"\n");
		step_status = ERROR_IN_STEP;
		break;
	    }
	}
	stop_clock("node_propagate");
	if (front->pp_grid)
	    step_status = syncronize_time_step_status(step_status,front->pp_grid);
	DEBUG_LEAVE(propagate_node_points)
	return step_status; 
}		/*end propagate_node_points*/
}}}
src/front/fadv.c
{{{
/*
*			propagate_points_tangentially():
*
*	This is the main driver program for the tangential sweep in 3D.
*	The procedure is to copy the incoming interface of newfront
*	into intfc_new, perform a loop over the two (geometrically identical)
*	interfaces intfc_tmp = newfront->interf,  and intfc_new and install
*	the output from the pointwise tan_point_propagate function into the
*	states on intfc_new.  At the end of the loop the original
*	newfront->interf = intfc_tmp is deleted and intfc_new is installed
*	as newfront->interf.  Finally the updated interface is marked as
*	reconstructed (since it is a copy of a reconstructed interface), and
*	the new front states are scattered across processors.
*
*	NOTE: The current tangential sweep function, f_tan_point_propagate,
*	implicitly assumes that the triangles about a given point project onto
*	the tangent plane defined by the discrete normal vector in such a
*	way as to produce a regular non-intersecting polygon.  This assumption
*	can be violated when a point is the vertex of a cone-like object.
*	Whether this occurs or not depends on the choice of the normal uni_array.
*	Internally, f_tan_point_propagate will attempt to compute an alternative
*	normal vector that does not produce a tangled projection.  If this is
*	not possible,  then f_tan_point_propagate will return a failure status.
*	If this occurs propagate_points_tangentially will remove the
*	offending point,  rescatter the modified interfaces,  recopy intfc_new,
*	and restart the tangential sweep loop.  Needless to say,  this is a
*	rather inefficient solution to the problem.  The hope is that such
*	irregular cases will be rare and this problem will only occur
*	infrequently in a given run.  Thus the goal is to have a robust,  if
*	costly,  way of treating such geometric degeneracies.
*/

LOCAL int propagate_points_tangentially(
	Front		*front,
	Front		*newfront,
	int		reconstruct_front,
	float		dt,
	float		*dt_frac,
	int		dir)
{
	INTERFACE               *intfc_tmp, *intfc_new;
	HYPER_SURF		*tmphs;
	HYPER_SURF_ELEMENT 	*tmphse;
	SURFACE                 **s_tmp, **s_new;
	POINT			*tmpp, *newp;
	TRI                     *tri_tmp, *tri_new;
	int                     i;
	bool                    modified;
	DEBUG_ENTER(propagate_points_tangentially)

	start_clock("copy_interface");
	intfc_tmp = newfront->interf;
	set_size_of_intfc_state(size_of_state(front->interf));
	if ((intfc_new = pp_copy_interface(intfc_tmp)) == NULL)
	{
	    screen("ERROR in propagate_points_tangentially(), "
		   "unable to copy interface\n");
	    clean_up(ERROR);
	}
	stop_clock("copy_interface");
	if (debugging("consistency") && !consistent_interface(intfc_new))
	{
	    screen("ERROR in propagate_points_tangentially(), "
		   "intfc_new is inconsistent\n");
	    clean_up(ERROR);
	}
	
	start_clock("tan_propagate");

	modified = NO;
	/* Reset sort status for points on intfc_tmp and intfc_new */
	(void) next_point(intfc_tmp,NULL,NULL,NULL);
	(void) next_point(intfc_new,NULL,NULL,NULL);
	for (s_tmp = intfc_tmp->surfaces, s_new = intfc_new->surfaces;
		s_tmp && *s_tmp && s_new && *s_new; ++s_tmp, ++s_new)
	{
	  tmphs = Hyper_surf(*s_tmp);
	  for (tri_tmp = first_tri(*s_tmp), tri_new = first_tri(*s_new);
	       !at_end_of_tri_list(tri_tmp,*s_tmp) &&
	       !at_end_of_tri_list(tri_new,*s_new);
	       tri_tmp = tri_tmp->next, tri_new = tri_new->next)
	  {
	    tmphse = Hyper_surf_element(tri_tmp);
	    for (i = 0; i < 3; ++i)
	    {
	      tmpp = Point_of_tri(tri_tmp)[i];
	      newp = Point_of_tri(tri_new)[i];
	      if (!sorted(tmpp) && !sorted(newp))
	      {
	        if (tan_point_propagate(front,tmpp,newp,tmphse,tmphs,dt,dir))
		  sorted(tmpp) = sorted(newp) = YES;
		else
		{
		  sorted(tmpp) = sorted(newp) = YES;
		}
	      }
	      else if (!sorted(tmpp) || !sorted(newp))
	      {
	        screen("ERROR in propagate_points_tangentially(), "
		       "point lists in intfc_tmp and intfc_new "
		       "inconsistent\n");
	        clean_up(ERROR);
	      }
	    }
	  }
	}
	stop_clock("tan_propagate");

	(void) delete_interface(intfc_tmp);
	newfront->interf = intfc_new;
	debug_front("tp_front","after tangential propagation",newfront);

	start_clock("scatter_front");
	start_clock("copy_interface");
	set_size_of_intfc_state(size_of_state(front->interf));
	if ((intfc_new = pp_copy_interface(newfront->interf)) == NULL)
	{
	    screen("ERROR in propagate_points_tangentially(), "
		   "unable to copy interface\n");
	    clean_up(ERROR);
	}
	stop_clock("copy_interface");

        init_intfc_curvature3d(newfront,newfront->interf);
	
	if(NO)
	{
	    char    s[50], sn[50];

	    sprintf(sn, "%s", right_flush(pp_mynode(),PP_NODE_FIELD_WIDTH));
	    sprintf(s, "curvature%s_%s", right_flush(newfront->step, 
	    			TSTEP_FIELD_WIDTH), sn);
	    tecplot_interface_states(s, newfront->interf);
	}
	
	for (i = 0; i < 2; ++i)
	{
	  if (scatter_front(newfront))
	      break;
	  else
	  {
	    printf("\n entered else part!");
	    delete_interface(newfront->interf);
	    newfront->interf = intfc_new;
	    start_clock("copy_interface");
	    set_size_of_intfc_state(size_of_state(front->interf));
	    if ((intfc_new = pp_copy_interface(newfront->interf)) == NULL)
	    {
	      screen("ERROR in propagate_points_tangentially(), "
		     "unable to copy interface\n");
	      clean_up(ERROR);
	    }
	    stop_clock("copy_interface");
	    interface_reconstructed(newfront->interf) = NO;
	    if (i == 1)
	    {
	      if (redistribute(newfront,YES,NO) != GOOD_REDISTRIBUTION) 
	      {
		  i = 2;
		  break;
	      }
	    }
	  }
	}
	if (intfc_new != NULL)
	    delete_interface(intfc_new);
	if (i == 2)
	{
	  (void) printf("WARNING in propagate_points_tangentially(), "
			"2nd scatter_front() failed\n"
			"MODIFY_TIME_STEP_NODE\n");
	  *dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf);
	  DEBUG_LEAVE(propagate_points_tangentially)
	  return MODIFY_TIME_STEP; 
	}
	stop_clock("scatter_front");
	DEBUG_LEAVE(propagate_points_tangentially)
	return GOOD_STEP;
}		/*end propagate_points_tangentially*/
}}}
{{{
LOCAL void propagate_surface_points(
        Front           *front,
        Front           *newfront,
        POINTER         wave,
        float           dt,
        float           *V)
{
        INTERFACE               *intfc_old = front->interf;
        INTERFACE               *intfc_new = newfront->interf;
        HYPER_SURF              *oldhs, *newhs;
        HYPER_SURF_ELEMENT      *oldhse, *newhse;
        POINT                   *oldp, *newp;
        DEBUG_ENTER(propagate_surface_points)

        start_clock("surface_propagate");

	(void) next_point(intfc_old,NULL,NULL,NULL);
        (void) next_point(intfc_new,NULL,NULL,NULL);
        while (next_point(intfc_old,&oldp,&oldhse,&oldhs) &&
             next_point(intfc_new,&newp,&newhse,&newhs))
        {
	    if(Boundary_point(newp))
	        continue;
	    point_propagate(front,wave,oldp,newp,oldhse,oldhs,dt,V);
	}

        stop_clock("surface_propagate");
        DEBUG_LEAVE(propagate_surface_points)
}               /*end propagate_surface_points*/
}}}
liquid/liqsub.c
{{{
void read_dirichlet_bdry_data(
	char *inname,
	Front *front,
	F_BASIC_DATA f_basic)
{
	char msg[100],s[100];
	int i,k,dim = front->rect_grid->dim;
	FILE *infile = fopen(inname,"r");
	STATE state;
	HYPER_SURF *hs;

	for (i = 0; i < dim; ++i)
	{
	    if (f_basic.boundary[i][0] == DIRICHLET_BOUNDARY)
	    {
		hs = NULL;
	        if (rect_boundary_type(front->interf,i,0) == DIRICHLET_BOUNDARY)
		    hs = BoundaryHyperSurf(front->interf,DIRICHLET_BOUNDARY,
					i,0);
		sprintf(msg,"For lower boundary in %d-th dimension",i);
		CursorAfterString(infile,msg);
		CursorAfterString(infile,"Enter type of Dirichlet boundary:");
		fscanf(infile,"%s",s);
		switch (s[0])
		{
		case 'c':			// Constant state
		case 'C':
		    CursorAfterString(infile,"Enter velocity:");
		    for (k = 0; k < dim; ++k)
			fscanf(infile,"%lf",&state.vel[k]);
		    CursorAfterString(infile,"Enter pressure:");
		    fscanf(infile,"%lf",&state.pres);
		    FrontSetDirichletBoundary(front,NULL,NULL,
					(POINTER)&state,hs);
		    break;
		case 'f':			// Flow through state
		case 'F':
		    FrontSetDirichletBoundary(front,flowThroughBoundaryState,
					"flowThroughBoundaryState",NULL,hs);
		    break;
		}
	    }
            if (f_basic.boundary[i][1] == DIRICHLET_BOUNDARY)
	    {
		hs = NULL;
                if (rect_boundary_type(front->interf,i,1) == DIRICHLET_BOUNDARY)                    hs = BoundaryHyperSurf(front->interf,DIRICHLET_BOUNDARY,
                                                i,1);
		sprintf(msg,"For upper boundary in %d-th dimension",i);
		CursorAfterString(infile,msg);
		CursorAfterString(infile,"Enter type of Dirichlet boundary:");
		fscanf(infile,"%s",s);
		switch (s[0])
		{
		case 'c':			// Constant state
		case 'C':
		    CursorAfterString(infile,"Enter velocity:");
		    for (k = 0; k < dim; ++k)
			fscanf(infile,"%lf ",&state.vel[k]);
		    CursorAfterString(infile,"Enter pressure:");
		    fscanf(infile,"%lf",&state.pres);
		    FrontSetDirichletBoundary(front,NULL,NULL,
					(POINTER)&state,hs);
		    break;
		case 'f':			// Flow through state
		case 'F':
		    FrontSetDirichletBoundary(front,flowThroughBoundaryState,
					"flowThroughBoundaryState",NULL,hs);
		    break;
		}
	    }
	}
	fclose(infile);
}	/* end read_dirichlet_bdry_data */
}}}
liquid/lphys.c
{{{
extern void read_liquid_params(
	char *inname,
	EQN_PARAMS *eqn_params)
{
	static CIRCLE_PARAMS *circle_params;
	static SINE_PARAMS *sine_params;
	char string[100];
	int i,dim = eqn_params->dim;
	FILE *infile = fopen(inname,"r");

	eqn_params->prob_type = ERROR_TYPE;
	CursorAfterString(infile,"Enter problem type:");
	fscanf(infile,"%s",string);
	if (string[0] == 'T' || string[0] == 't')
	{
	    if (string[10] == 'B' || string[10] == 'b')
	    	eqn_params->prob_type = TWO_FLUID_BUBBLE;
	    else if (string[10] == 'R' || string[10] == 'r')
	    	eqn_params->prob_type = TWO_FLUID_RT;
	} 
	else if (string[0] == 'F' || string[0] == 'f')
	    eqn_params->prob_type = FLUID_SOLID_CIRCLE;
	else if (string[0] == 'B' || string[0] == 'b')
	    eqn_params->prob_type = BUBBLE_SURFACE;

	assert(eqn_params->prob_type != ERROR_TYPE);

	fclose(infile);
}	/* end read_liquid_params */
}}}
liquid/lphys.c
{{{
extern void read_movie_options(
	char *inname,
	EQN_PARAMS *eqn_params)
{
	static HDF_MOVIE_OPTION *hdf_movie_option;
	FILE *infile = fopen(inname,"r");
	char string[100];

	scalar(&hdf_movie_option,sizeof(HDF_MOVIE_OPTION));
	zero_scalar(hdf_movie_option,sizeof(HDF_MOVIE_OPTION));
	eqn_params->hdf_movie_option = hdf_movie_option;
	CursorAfterString(infile,"Type y to make movie of pressure:");
	fscanf(infile,"%s",string);
	if (string[0] == 'Y' || string[0] == 'y')
	    hdf_movie_option->plot_pres = YES;
	CursorAfterString(infile,"Type y to make movie of vorticity:");
	fscanf(infile,"%s",string);
	if (string[0] == 'Y' || string[0] == 'y')
	    hdf_movie_option->plot_vort = YES;
	CursorAfterString(infile,"Type y to make movie of velocity:");
	fscanf(infile,"%s",string);
	if (string[0] == 'Y' || string[0] == 'y')
	    hdf_movie_option->plot_velo = YES;

	if (eqn_params->dim == 3)
	{
	    CursorAfterString(infile,"Type y to make yz cross section movie:");
	    fscanf(infile,"%s",string);
	    if (string[0] == 'Y' || string[0] == 'y')
		hdf_movie_option->plot_cross_section[0] = YES;
	    CursorAfterString(infile,"Type y to make xz cross section movie:");
	    fscanf(infile,"%s",string);
	    if (string[0] == 'Y' || string[0] == 'y')
		hdf_movie_option->plot_cross_section[1] = YES;
	    CursorAfterString(infile,"Type y to make xy cross section movie:");
	    fscanf(infile,"%s",string);
	    if (string[0] == 'Y' || string[0] == 'y')
		hdf_movie_option->plot_cross_section[2] = YES;
	}
	fclose(infile);
}	/* end read_movie_options */
}}}
src/intfc/iredist.c
{{{
EXPORT	void	rect_bdry_curve_redist(
	CURVE		*c,
	ORIENTATION	orient,
	RECT_GRID	*gr,
	double		*tol)
{
	BOND		*b, *bb;
	double		tolx = tol[0], toly = tol[1];
	double		*ps, *pe;
	double		x, y, coords[MAXD];
	int		ixs, ixe, iys, iye, ix, iy;
	int		ibegin, ifinish;
	ORIENTATION	opor = Opposite_orient(orient);
	int		di;

	DEBUG_ENTER(rect_bdry_curve_redist)
	ps = Coords(c->start->posn);		pe = Coords(c->end->posn);

	if (fabs(ps[1]-pe[1]) < fabs(ps[0]-pe[0]))
	{

	    /* horizontal boundary */

	    ixs = rb_cell_index(ps,0,gr);
	    ixe = rb_cell_index(pe,0,gr);

	    if (ixe == ixs)
	    {
	    	while (c->first != c->last)
		    i_delete_point_adjacent_to_node(c,POSITIVE_ORIENTATION);
	    	DEBUG_LEAVE(rect_bdry_curve_redist)
	    	return;
	    }
	    if (orient == POSITIVE_ORIENTATION)
	    {
	    	di = (ps[0] < pe[0]) ? 1 : -1;
	    	ibegin = ixs;
	    	ifinish = ixe;
	    }
	    else
	    {
	    	di = (ps[0] < pe[0]) ? -1 : 1;
	    	ibegin = ixe;
	    	ifinish = ixs;
	    }

			/* Check positions at nodes */
		
	    x = cell_center(ibegin,0,gr);
	    if ((fabs(x - Coords(Node_of(c,orient)->posn)[0]) < tolx) ||
	    				(!Between(x,ps[0],pe[0])))
	    	ibegin += di;

	    x = cell_center(ifinish,0,gr);
	    if ((fabs(x - Coords(Node_of(c,opor)->posn)[0]) < tolx) ||
	    				(!Between(x,ps[0],pe[0])))
	    	ifinish -= di;

	    if (di*(ibegin - ifinish) > 0)
	    {
	    	while (c->first != c->last)
		    i_delete_point_adjacent_to_node(c,POSITIVE_ORIENTATION);
	    	DEBUG_LEAVE(rect_bdry_curve_redist)
	    	return;
	    }

	    coords[1] = y = Coords(c->start->posn)[1];
	    b = Bond_at_node(c,orient);
	    for (ix = ibegin; di*(ifinish - ix) >= 0; ix += di)
	    {
	        x = cell_center(ix,0,gr);
	        for (bb = b; bb != NULL; bb = Following_bond(bb,orient))
	        {
	    	    if (fabs(x-Coords(Point_of_bond(bb,opor))[0]) < tolx)
	    	    {
	    		Coords(Point_of_bond(bb,opor))[0] = x;
	    		break;
	    	    }
	    	    else if (Between(x,Coords(bb->start)[0],Coords(bb->end)[0]))
	    	    {
	    	        coords[0] = x;
	    	        if (insert_point_in_bond(Point(coords),bb,c) !=
			    FUNCTION_SUCCEEDED)
	    	        {
	    	            screen("ERROR in rect_bdry_curve_redist(), "
	    	                   "insert_point_in_bond failed\n");
	    	            clean_up(ERROR);
	    	        }
	    	        if (orient == NEGATIVE_ORIENTATION) 
	    	        {
	    		    if (bb == b)
				b = bb->next;
	    		    bb = bb->next;
	    	        }
	    	        break;
	            }
	        }
		if (bb == NULL)
		{
		    bb = Bond_at_node(c,opor);
		    if (bb == b) break;
		}
		if (orient == POSITIVE_ORIENTATION)
		{
		    replace_curve_seg_by_bond(c,b,bb);
		    b = b->next;
		}
		else
		{
		    replace_curve_seg_by_bond(c,bb,b);
		    b = bb->prev;
		}
		if (b == NULL) break;
	    }
	    if (orient == POSITIVE_ORIENTATION)
	    	replace_curve_seg_by_bond(c,b,Bond_at_node(c,opor));
	    else
	    	replace_curve_seg_by_bond(c,Bond_at_node(c,opor),b);
	}
	else if (fabs(ps[0]-pe[0]) < fabs(ps[1]-pe[1]))
	{	
	    /* vertical boundary */

	    iys = rb_cell_index(ps,1,gr);
	    iye = rb_cell_index(pe,1,gr);
	    if (iye == iys)
	    {
	    	while (c->first != c->last)
		    i_delete_point_adjacent_to_node(c,POSITIVE_ORIENTATION);
	    	DEBUG_LEAVE(rect_bdry_curve_redist)
	    	return;
	    }
	    if (orient == POSITIVE_ORIENTATION)
	    {
	    	di = (ps[1] < pe[1]) ? 1 : -1;
	    	ibegin = iys;
	    	ifinish = iye;
	    }
	    else
	    {
	    	di = (ps[1] < pe[1]) ? -1 : 1;
	    	ibegin = iye;
	    	ifinish = iys;
	    }

	    /* Check positions at nodes */

	    y = cell_center(ibegin,1,gr);
	    if ((fabs(y - Coords(Node_of(c,orient)->posn)[1]) < toly) ||
	    				(!Between(y,ps[1],pe[1])))
	    	ibegin += di;

	    y = cell_center(ifinish,1,gr);
	    if ((fabs(y - Coords(Node_of(c,opor)->posn)[1]) < toly) ||
	    				(!Between(y,ps[1],pe[1])))
	        ifinish -= di;

	    if (di*(ibegin - ifinish) > 0)
	    {
	    	while (c->first != c->last)
		    i_delete_point_adjacent_to_node(c,POSITIVE_ORIENTATION);
	    	DEBUG_LEAVE(rect_bdry_curve_redist)
	    	return;
	    }

	    coords[0] = x = Coords(c->start->posn)[0];
	    b = Bond_at_node(c,orient);
	    for (iy = ibegin; di*(ifinish - iy) >= 0; iy += di)
	    {
	        y = cell_center(iy,1,gr);
	        for (bb = b; bb != NULL; bb = Following_bond(bb,orient))
	        {
	    	    if (fabs(y-Coords(Point_of_bond(bb,opor))[1]) < toly)
	    	    {
	    		Coords(Point_of_bond(bb,opor))[1] = y;
	    		break;
	    	    }
	    	    else if (Between(y,Coords(bb->start)[1],Coords(bb->end)[1]))
	    	    {
	    	        coords[1] = y;

	    	        if (insert_point_in_bond(Point(coords),bb,c) !=
			    FUNCTION_SUCCEEDED)
	    	        {
	    	            screen("ERROR in rect_bdry_curve_redist(), "
	    	                   "insert_point_in_bond failed\n");
	    	            clean_up(ERROR);
	    	        }
	    	        if (orient == NEGATIVE_ORIENTATION)
	    	        {
	    	            if (bb == b) b = bb->next;
	    	            bb = bb->next;
	    	        }
	    	        break;
	    	    }
	        }  
		if (bb == NULL)
		{
		    bb = Bond_at_node(c,opor);
		    if (bb == b) break;
		}
		if (orient == POSITIVE_ORIENTATION)
		{
		    replace_curve_seg_by_bond(c,b,bb);
		    b = b->next;
		}
		else
		{
		    replace_curve_seg_by_bond(c,bb,b);
		    b = bb->prev;
		}
		if (b == NULL)
		    break;
	    }
	    if (orient == POSITIVE_ORIENTATION)
	    	replace_curve_seg_by_bond(c,b,Bond_at_node(c,opor));
	    else
	    	replace_curve_seg_by_bond(c,Bond_at_node(c,opor),b);
	}
	DEBUG_LEAVE(rect_bdry_curve_redist)
}		/*end rect_bdry_curve_redist*/
}}}
src/intfc/iredist.c
{{{
EXPORT  void rect_bdry_redist2d(
	INTERFACE	*intfc,
	RECT_GRID	*rgr,
	int		iperm)
{
	CURVE		**c;
	double		tol[MAXD];
	int		i;
	ORIENTATION	orient;

	DEBUG_ENTER(rect_bdry_redist2d)
	for (i = 0; i < rgr->dim; ++i)
	    tol[i] = MIN_SC_SEP(intfc) * rgr->h[i];
	orient = (iperm % 2) ? POSITIVE_ORIENTATION : NEGATIVE_ORIENTATION;
	for (c = intfc->curves; c && *c; ++c) 
	{
	    if (!is_bdry(*c))
	        continue;

	    rect_bdry_curve_redist(*c,orient,rgr,tol);
	}
	DEBUG_LEAVE(rect_bdry_redist2d)
}		/*end rect_bdry_redist2d*/
}}}
src/front/fredist.c
{{{
/*
*			redistribute():
*
*	Controls high level dimensionally independent parts of
*	the redistribution of tracked waves.  See comments for
*	dimensionally specific parts for more information.
*
*	TODO:  At present this function is just a switch shell
*	implement a truly high level redistribution driver
*	to replace dimensionally dependent drivers.
*/

EXPORT int redistribute(
	Front		*fr,
	bool		do_redist,
	bool		restart_init)
{
	int		dim = fr->rect_grid->dim;
	int		status = BAD_REDISTRIBUTION;
	
	switch(dim)
	{
#if defined(ONED)
	case 1:
	    status = redistribute1d(fr);
	    break;
#endif /* defined(ONED) */
#if defined(TWOD)
	case 2:
	    status = redistribute2d(fr,do_redist,restart_init);
	    break;
#endif /* defined(TWOD) */
#if defined(THREED)
	case 3:
	    status = redistribute3d(fr,do_redist,restart_init);
	    //In this case scatter_front fails, 
	    //all procs will have the same value for status.
	    if(status == INCONSISTENT_RECONSTRUCTION)
	    	return status;
	    break;
#endif /* defined(THREED) */
	}


	if (fr->pp_grid && fr->pp_grid->nn > 1)
	{
	    long gs;

	    gs = (status == BAD_REDISTRIBUTION) ? 1 : 0;
#if defined(USE_OVERTURE)
#else /* if defined(USE_OVERTURE) */
            pp_global_lmax(&gs,1L);
#endif /* if defined(USE_OVERTURE) */

	    if (gs == 1)
		return BAD_REDISTRIBUTION;

	    gs = (status == MODIFY_TIME_STEP_REDISTRIBUTE) ? 1 : 0;
#if defined(USE_OVERTURE)
#else /* if defined(USE_OVERTURE) */
            pp_global_lmax(&gs,1L);
#endif /* if defined(USE_OVERTURE) */
	    if (gs == 1)
		return MODIFY_TIME_STEP_REDISTRIBUTE;
		
	    gs = (status == UNABLE_TO_UNTANGLE) ? 1 : 0;
#if defined(USE_OVERTURE)
#else /* if defined(USE_OVERTURE) */
            pp_global_lmax(&gs,1L);
#endif /* if defined(USE_OVERTURE) */

	    if (gs == 1)
		return UNABLE_TO_UNTANGLE; 

	    gs = (status == GOOD_REDISTRIBUTION) ? 0 : 1;
#if defined(USE_OVERTURE)
#else /* if defined(USE_OVERTURE) */
	    pp_global_lmax(&gs,1L);
#endif /* if defined(USE_OVERTURE) */

	    if (gs == 1)
		return BAD_REDISTRIBUTION; 
	}
	return status;
}		/*end redistribute*/
}}}
src/front/fredist2d.c
{{{
EXPORT int redistribute2d(
	Front		*fr,
	bool		do_redist,
	bool		restart_init)
{
	CROSS		*cross;
	INTERFACE	*intfc = fr->interf;
	INTERFACE	*save_intfc[2];
	O_NODE		*onode_list;
	float		*h = fr->rect_grid->h;
	float		hx = h[0], hy = h[1];
	float		dt, *dt_frac, min_dt_frac;
	int		status;
	bool		do_scatter = NO;
	int		small_loops_deleted;
	int		redist_status;
	bool		force_redistribute;
	bool		delete_small_loops_before_untangle;
	bool		istatus;
	bool		any_redist;
	int		num_untangles = 0;
	int		flag = NORMAL_ATTEMPT_TO_UNTANGLE;
	int		dim = fr->rect_grid->dim;
	static const int       MAX_NUM_UNTANGLES = 10;/*TOLERANCE*/
	static bool	first = YES;
	static float	dt_max, dt_min;
	DEBUG_ENTER(redistribute2d)

	if (first)
	{
	    first = NO;
	    dt_max = HUGE_VAL;
	    dt_min = 0.0;
	}

	if (fr->interf->curves == NULL)
	{
	    DEBUG_LEAVE(redistribute2d)
	    return GOOD_REDISTRIBUTION;
	}

	if (DEBUG)
	{
	    if (Frequency_of_redistribution(fr,GENERAL_WAVE) > 0)
	    {
	        (void) printf("Count redistribute(%d) %% "
	                      "general curve frequency redistribute(%d) = %d\n",
	    		      Redistribution_count(fr),
			      Frequency_of_redistribution(fr,GENERAL_WAVE),
			      Redistribution_count(fr) % 
	    		      Frequency_of_redistribution(fr,GENERAL_WAVE));
	    }
	    if (Frequency_of_redistribution(fr,VECTOR_WAVE) > 0)
	    {
	        (void) printf("Count redistribute(%d) %% "
	                      "uni_array curve frequency redistribute(%d) = %d\n",
	    		      Redistribution_count(fr),
			      Frequency_of_redistribution(fr,VECTOR_WAVE),
	    		      Redistribution_count(fr) %
	    		      Frequency_of_redistribution(fr,VECTOR_WAVE));
	    }
	    DEBUG_FRONT("at start of redistribute2d()",fr)
	    (void) printf("Interface before redistribute2d\n");
	    print_interface(intfc);
	}

	save_intfc[0] = make_save_intfc(intfc);
	save_intfc[1] = NULL;

	print_storage("before redistribute","REDIST_storage");
	start_clock("redistribute");

#if defined(USE_OVERTURE)
        if (!attach_sink_nodes(fr))
        {
            (void) printf("WARNING - in redistribute2d(), "
                          "attach_sink_nodes() failed for front[%d]\n",
                           fr->patch_number);
            (void) reset_interface_of_front(fr,save_intfc);
            prepare_to_leave_redistribute2d(save_intfc);
            DEBUG_LEAVE(redistribute2d)
            return BAD_REDISTRIBUTION;
        }
#else  /* if defined(USE_OVERTURE) */
        if (!pp_min_status(attach_sink_nodes(fr)))
        {
            (void) printf("WARNING - in redistribute2d(), "
                          "attach_sink_nodes() failed\n");
            (void) reset_interface_of_front(fr,save_intfc);
            prepare_to_leave_redistribute2d(save_intfc);
            DEBUG_LEAVE(redistribute2d)
            return BAD_REDISTRIBUTION;
        }
#endif /* if defined(USE_OVERTURE) */

	DEBUG_FRONT("after attach_sink_nodes",fr)

	    /* Redistribute Interface */

	Interface_redistributed(fr) = NO;
	small_loops_deleted = NO;
	force_redistribute = NO;
	delete_small_loops_before_untangle = NO;

redistribute_interface:

	if (do_redist)
	{
	    bool status;

	    status = (intfc->curves == NULL) ? YES :
	    		(Interface_redistributed(fr)) ? YES :
	    		Curve_redistribute(fr,&force_redistribute);

	    status = closed_curve_node_redistribute(intfc,status);

#if defined(USE_OVERTURE)
            if (!status)
            {
                (void) printf("WARNING in redistribute2d(), "
                              "redistribution failed\n");
                (void) reset_interface_of_front(fr,save_intfc);
                prepare_to_leave_redistribute2d(save_intfc);
                DEBUG_LEAVE(redistribute2d)
                return BAD_REDISTRIBUTION;
            }
#else /* if defined(USE_OVERTURE) */
            if (!pp_min_status(status))
            {
                (void) printf("WARNING in redistribute2d(), "
                              "redistribution failed\n");
                (void) reset_interface_of_front(fr,save_intfc);
                prepare_to_leave_redistribute2d(save_intfc);
                DEBUG_LEAVE(redistribute2d)
                return BAD_REDISTRIBUTION;
            }
#endif /* if defined(USE_OVERTURE) */
	}

#if defined(USE_OVERTURE)
        any_redist = Interface_redistributed(fr);
#else /* if defined(USE_OVERTURE) */
        any_redist = pp_max_status(Interface_redistributed(fr));
#endif /* if defined(USE_OVERTURE) */

	if (any_redist)
	{
	    /* redistribute or untangle may produce 2 and 3 bond loops */

	    delete_small_loops(fr);
	    if (!restart_init)
	    {
	    	print_storage("before copy/delete intfc",
	    		      "REDIST_storage");
	    	start_clock("copy/delete intfc");
	    	set_size_of_intfc_state(size_of_state(fr->interf));
	    	set_copy_intfc_states(YES); /* Ensure states copied */
	    	fr->interf = copy_interface(intfc);
	    	(void) delete_interface(intfc);
	    	intfc = fr->interf;
	    	set_copy_intfc_states(YES);
	    	stop_clock("copy/delete intfc");
	    	print_storage("after copy/delete intfc","REDIST_storage");
	    }
	    do_scatter = YES;
	}

	DEBUG_FRONT("before intersections check",fr)

	    	/* Check for Intersections in Front */
	if (DEBUG) (void) printf("Checking for intersections\n");
	istatus = check_for_intersections(intfc,&cross,YES);
	if (!istatus)
	{
	    if (debugging("pionfail"))
	    	print_interface(intfc);
	    (void) reset_interface_of_front(fr,save_intfc);
	    prepare_to_leave_redistribute2d(save_intfc);
	    DEBUG_LEAVE(redistribute2d)
	    return BAD_REDISTRIBUTION;
	}

	if (DEBUG) (void) printf("Intersections check completed\n");

	if (interface_is_tangled(cross))
	{
	    static const char *redist_mesg =   "redistributed hyp ";
	    static const char *unredist_mesg = "unredistributed hyp ";
	    int	              num_tangles;

	    ++num_untangles;
	    if (DEBUG)
	    {
	    	(void) printf("Entering untangle block, "
	    	              "attempt number %d.\n",num_untangles);
	    }

	    num_tangles = print_number_of_tangles(
	    	(Interface_redistributed(fr)==YES)?redist_mesg:unredist_mesg,
		fr->interf,cross);

	    if (num_untangles > MAX_NUM_UNTANGLES)
	    {
	    	(void) printf("WARNING in redistribute2d(), too many attempts "
			      "(%d)  to untangle without success.\n",
			      num_untangles);
	    	if (DEBUG && (cross != NULL))
	    	    print_intersections(cross,intfc);
	    	(void) reset_interface_of_front(fr,save_intfc);
	    	prepare_to_leave_redistribute2d(save_intfc);
	    	DEBUG_LEAVE(redistribute2d)
	    	return BAD_REDISTRIBUTION;
	    }

	    if ((save_intfc[0] != NULL) && any_redist &&
	        vector_wave_interaction(cross))
	    {
	    	CROSS	   *ur_cross = NULL;
		CROSS      *cr;
		HYPER_SURF *hs;
	    	int	   unredist_num_tangles;

	    	/* Check to see if redistribute created uni_array
	    	 * tangles.  We do not allow this, as the
	    	 * untangle code may not be able to handle the
	    	 * resulting (possibly unphysical) configuration. */

	    	if (DEBUG)
	    	    (void) printf("Second intersections check\n");
	    	istatus = check_for_intersections(save_intfc[0],&ur_cross,YES);
	    	if (!istatus)
	    	{
	    	    (void) printf("Second intersections check "
	    	                  "detects bad status.\n");
	    	    if (debugging("pionfail"))
	    	    {
	    	        (void) printf("Unredistributed Interface:\n\n");
	    	        print_interface(save_intfc[0]);
	    	        (void) printf("Redistributed Interface:\n\n");
	    	        print_interface(intfc);
	    	    }
	    	    (void) reset_interface_of_front(fr,save_intfc);
	    	    prepare_to_leave_redistribute2d(save_intfc);
	    	    DEBUG_LEAVE(redistribute2d)
	    	    return BAD_REDISTRIBUTION;
	    	}
	    	if (DEBUG)
	    	    (void) printf("Second intersections check completed\n");
	        if (!interface_is_tangled(ur_cross))
		{
		    /*
		     * The unredistributed interface is untangled
		     * Omit redistribution on this time step
		     */
	    	    (void) reset_interface_of_front(fr,save_intfc);
		    intfc = fr->interf;
	            save_intfc[0] = make_save_intfc(intfc);
	            any_redist = NO;
		    cross = NULL;
		}
		else
		{
		    bool repeat_redistribute = NO;
	    	    unredist_num_tangles = print_number_of_tangles(
	    			unredist_mesg,save_intfc[0],ur_cross);
	    	    if (unredist_num_tangles != num_tangles)
	    	    {
			repeat_redistribute = YES;
	    		(void) printf("WARNING in redistribute2d(), "
	    		              "redistribute causes vector tangle.\n");
		        for (cr = cross; cr != NULL; cr = cr->next)
		        {
			    if (wave_type(cr->c1) >=
				FIRST_VECTOR_PHYSICS_WAVE_TYPE)
			    {
				hs = Hyper_surf(cr->c1);
			        do_not_redistribute(hs) = YES;
				hs = correspond_hyper_surf(hs);
				if (hs != NULL)
			            do_not_redistribute(hs) = YES;
				else
				    repeat_redistribute = NO;
			    }
			    if (wave_type(cr->c2) >=
				FIRST_VECTOR_PHYSICS_WAVE_TYPE)
			    {
				hs = Hyper_surf(cr->c2);
			        do_not_redistribute(cr->c2) = YES;
				hs = correspond_hyper_surf(hs);
				if (hs != NULL)
			            do_not_redistribute(hs) = YES;
				else
				    repeat_redistribute = NO;
			    }
		        }
		    }
		
#if defined(USE_OVERTURE)
                    if (repeat_redistribute)
                    {
                        (void) reset_interface_of_front(fr,save_intfc);
                        prepare_to_leave_redistribute2d(save_intfc);
                        status = redistribute2d(fr,do_redist,restart_init);
                        printf("Patch front[%d] repeat_redistribute\n",
                                   fr->patch_number);
                        DEBUG_LEAVE(redistribute2d)
                        return status;
                    }
#else /* if defined(USE_OVERTURE) */
                    if (pp_max_status(repeat_redistribute))
                    {
                        (void) reset_interface_of_front(fr,save_intfc);
                        prepare_to_leave_redistribute2d(save_intfc);
                        status = redistribute2d(fr,do_redist,restart_init);
                        DEBUG_LEAVE(redistribute2d)
                        return status;
                    }
#endif /* if defined(USE_OVERTURE) */
	    	}
	    }
	}
	if (interface_is_tangled(cross))
	{
	    if (restart_init) 
	    {
	    	(void) printf("WARNING in redistribute2d(), "
	    	              "Restart interface tangled, cannot continue\n");
	    	(void) reset_interface_of_front(fr,save_intfc);
	    	prepare_to_leave_redistribute2d(save_intfc);
	    	DEBUG_LEAVE(redistribute2d)
	    	return BAD_REDISTRIBUTION;
	    }

	    set_force_tangle(NO);

	    if (too_many_tangled_points(cross,h,dim))
	    {
	        status = (*fr->grid_based_untangle)(fr,&cross);
	        status = synchronize_untangle_status(status);
		if (status != CURVES_UNTANGLED)
		{
	    	    (void) printf("WARNING in redistribute2d(), "
	    	              "grid based untangle failed\n");
	    	    redist_status = (do_redist &&
	    			(Interface_redistributed(fr))) ?
	    		     UNABLE_TO_UNTANGLE : BAD_REDISTRIBUTION;
	    	    (void) reset_interface_of_front(fr,save_intfc);
	    	    prepare_to_leave_redistribute2d(save_intfc);
	    	    DEBUG_LEAVE(redistribute2d)
	    	    return BAD_REDISTRIBUTION;
		}
	    }

	    if (DEBUG)
	    {
	    	(void) printf("Checking to delete small ");
	    	(void) printf("loops before untangle\n");
	    }

#if defined(USE_OVERTURE)
            if (delete_small_loops_before_untangle)
            {
                eliminate_small_loops(intfc,hx,hy,&cross);
                small_loops_deleted = YES;
            }
#else /* if defined(USE_OVERTURE) */
            if (pp_max_status(delete_small_loops_before_untangle))
            {
                eliminate_small_loops(intfc,hx,hy,&cross);
                small_loops_deleted = YES;
            }
#endif /* if defined(USE_OVERTURE) */

	    /* Make backup copy of interface in case untangle fails */

	    save_intfc[1] = make_save_intfc(intfc);


	    	/* Boundary untangle */

	    if (fr->fr_bdry_untangle)
	    {
	        if (DEBUG)
	    	    (void) printf("Calling boundary untangle\n");
	        status = (cross == NULL) ? CURVES_UNTANGLED :
	    			           (*fr->fr_bdry_untangle)(fr,&cross,
	    		                                           NULL,NULL,
								   flag);
#if !defined(USE_OVERTURE)
	        status = synchronize_untangle_status(status);
#endif /* if !defined(USE_OVERTURE) */

	        switch (status)
	        {
	        case CURVES_UNTANGLED:
	    	    break;
	        case MODIFY_TIME_STEP_TO_UNTANGLE:
	    	    (void) printf("WARNING in redistributed2d, "
	    	                  "bdry_untangle returns \n"
	    	                  "\t\tMODIFY_TIME_STEP_TO_UNTANGLE\n");
	    	    (void) reset_interface_of_front(fr,save_intfc);
	    	    prepare_to_leave_redistribute2d(save_intfc);
	    	    DEBUG_LEAVE(redistribute2d)
	    	    return MODIFY_TIME_STEP_REDISTRIBUTE;
	        case MODIFY_TIME_STEP_TO_UNTANGLE_BUT_FORCE_TANGLE:
	    	    (void) printf("WARNING in redistributed2d, "
	    	                  "bdry_untangle returns \n"
	    	                  "\t\tMODIFY_TIME_STEP_TO_"
	    	                  "UNTANGLE_BUT_FORCE_TANGLE\n");
	    	    dt_frac = fr->dt_frac;
	    	    set_force_tangle(YES);
	    	    dt_max = dt = fr->dt;
	    	    min_dt_frac = dt_min/dt;
	    	    if (*dt_frac < min_dt_frac)
	    		*dt_frac = 0.5*(min_dt_frac + 1.0);
	    	    (void) reset_interface_of_front(fr,save_intfc);
	    	    prepare_to_leave_redistribute2d(save_intfc);
	    	    DEBUG_LEAVE(redistribute2d)
	    	    return MODIFY_TIME_STEP_REDISTRIBUTE;
	        case ERROR_IN_UNTANGLE:
	        default:
	    	    if (do_redist && 
	    	        (Curve_redistribution_function(fr) != NULL) && 
	    	        (!Interface_redistributed(fr)))
	    	    {
	    	        (void) printf("WARNING in redistribute2d(), "
	    	                      "unable to untangle front and"
	    	                      " boundary on first attempt\n"
	    	                      "Redistributing and trying again\n");
	    	        force_redistribute = YES;
	    	        intfc = reset_interface_of_front(fr,save_intfc+1);
	    	        goto redistribute_interface;
	    	    }
	    	    else if (!small_loops_deleted) 
	    	    {
	    	        (void) printf("WARNING in redistribute2d(), "
	    	                      "unable to untangle front and "
	    	                      "boundary\n"
	    	                      "Deleting small loops and "
	    	                      "trying again\n");
	    	        intfc = reset_interface_of_front(fr,save_intfc+1);
	    	        delete_small_loops_before_untangle = YES;
	    	        goto redistribute_interface;
	    	    }
	    	    (void) printf("WARNING in redistribute2d(), "
	    	                  "unable to untangle front and bdry\n");
	    	    (void) reset_interface_of_front(fr,save_intfc);
	    	    redist_status = (do_redist &&
	    			Interface_redistributed(fr)) ?
	    		UNABLE_TO_UNTANGLE : BAD_REDISTRIBUTION;
	    	    prepare_to_leave_redistribute2d(save_intfc);
	    	    DEBUG_LEAVE(redistribute2d)
	    	    return redist_status;
	        }
	        DEBUG_FRONT("after boundary untangle:",fr)
	    }

	    if (debugging("intersect"))
	    {
	        (void) printf("After fr_bdry_untangle.\n");
	        if (cross)
	        {
	           (void) printf("Printing interior intersections only:\n");
	           print_intersections(cross,intfc);
	        }
	        else
	           (void) printf("No interior intersections\n");
	    }
	    debug_bond_cross(cross,fr)

	/* Interior untangle */

	    if (interface_is_tangled(cross))
	    {
	        if (DEBUG)
	    	    (void) printf("Calling untangle front\n");
	        status = (cross == NULL) ? CURVES_UNTANGLED :
	    		(fr->untangle_front) ?
	                        (*fr->untangle_front)(fr,&cross,flag) :
	                        ERROR_IN_UNTANGLE;

#if !defined(USE_OVERTURE)
	        status = synchronize_untangle_status(status);
#endif /* if !defined(USE_OVERTURE) */

	        switch (status)
	        {
	        case CURVES_UNTANGLED:
	            break;
	        case MODIFY_TIME_STEP_TO_UNTANGLE:
	    	    (void) printf("WARNING in redistributed2d, "
	    	                  "untangle returns "
	    	                  "MODIFY_TIME_STEP_TO_UNTANGLE\n");
	    	    (void) reset_interface_of_front(fr,save_intfc);
	            prepare_to_leave_redistribute2d(save_intfc);
	    	    DEBUG_LEAVE(redistribute2d)
	            return MODIFY_TIME_STEP_REDISTRIBUTE;
	        case MODIFY_TIME_STEP_TO_UNTANGLE_BUT_FORCE_TANGLE:
	    	    (void) printf("WARNING in redistributed2d, "
	    	                  "untangle returns "
	    	                  "MODIFY_TIME_STEP_TO_UNTANGLE_");
	    	    (void) printf("BUT_FORCE_TANGLE\n");
	    	    set_force_tangle(YES);
	    	    dt_frac = fr->dt_frac;
	    	    dt_max = dt = fr->dt;
	    	    min_dt_frac = dt_min/dt;
	    	    if (*dt_frac < min_dt_frac)
	    		*dt_frac = 0.5*(min_dt_frac + 1.0);
	    	    (void) reset_interface_of_front(fr,save_intfc);
	    	    prepare_to_leave_redistribute2d(save_intfc);
	    	    DEBUG_LEAVE(redistribute2d)
	    	    return MODIFY_TIME_STEP_REDISTRIBUTE;
	        case ERROR_IN_UNTANGLE:
	    	    if (do_redist && 
	    	        (Curve_redistribution_function(fr) != NULL) && 
	    	        (!Interface_redistributed(fr)))
	            {
	                (void) printf("WARNING in redistribute2d(), "
	                              "unable to untangle interior"
	                              " crosses on first attempt\n");
	                (void) printf("Redistributing and trying again\n");
	                force_redistribute = YES;
	                flag = DIFFICULT_ATTEMPT_TO_UNTANGLE;
	    	        intfc = reset_interface_of_front(fr,save_intfc+1);
	                goto redistribute_interface;
	            }
	            else if (!small_loops_deleted) 
	            {
	                (void) printf("WARNING in redistribute2d(), "
	                              "unable to untangle interior crosses\n");
	    	        (void) printf("Deleting small loops and ");
	                (void) printf("trying again\n");
	                flag = LAST_ATTEMPT_TO_UNTANGLE;
	    	        intfc = reset_interface_of_front(fr,save_intfc+1);
	                delete_small_loops_before_untangle = YES;
	                goto redistribute_interface;
	            }
	            (void) printf("WARNING in redistribute2d(), "
	                          "unable to unravel the interface\n");
	    	    (void) reset_interface_of_front(fr,save_intfc);
	    	    redist_status = (do_redist &&
	    			Interface_redistributed(fr)) ?
	    		UNABLE_TO_UNTANGLE : BAD_REDISTRIBUTION;
	    	    prepare_to_leave_redistribute2d(save_intfc);
	    	    DEBUG_LEAVE(redistribute2d)
	    	    return redist_status;
	        }
	    }
	    else
	    {
	    	(void) delete_interface(save_intfc[1]);
	    	save_intfc[1] = NULL;
	    }
	    dt_min = 0.0;	dt_max = HUGE_VAL;

	    /* Untangle may produce zero length bonds */

	    if (DEBUG)
	    	(void) printf("Deleting very short bonds\n");
	    intfc_delete_very_short_bonds(fr);

#if defined(USE_OVERTURE)
            if (!intfc_delete_fold_back_bonds(fr))
            {
                (void) printf("WARNING in redistribute2d(), "
                     "unable to delete fold back bonds for front[%d]\n",fr->patch_number);
                (void) reset_interface_of_front(fr,save_intfc);
                prepare_to_leave_redistribute2d(save_intfc);
                DEBUG_LEAVE(redistribute2d)
                return BAD_REDISTRIBUTION;
            }
#else /* if defined(USE_OVERTURE) */
	    if (!pp_min_status(intfc_delete_fold_back_bonds(fr)))
	    {
	    	(void) printf("WARNING in redistribute2d(), "
	    	              "unable to delete fold back bonds\n");
	    	(void) reset_interface_of_front(fr,save_intfc);
	    	prepare_to_leave_redistribute2d(save_intfc);
	    	DEBUG_LEAVE(redistribute2d)
	    	return BAD_REDISTRIBUTION;
	    }
#endif /* if defined(USE_OVERTURE) */

	    if (DEBUG)
	    	(void) printf("Calling scatter front\n");

#if !defined(USE_OVERTURE)
	    if (!pp_min_status(correct_for_exterior_curves(fr)))
	    {
	    	(void) printf("WARNING in redistribute2d(), "
	                  "unable to correct for exterior curves\n");
	    	(void) reset_interface_of_front(fr,save_intfc);
	    	prepare_to_leave_redistribute2d(save_intfc);
	    	DEBUG_LEAVE(redistribute2d)
	    	return BAD_REDISTRIBUTION;
	    }
	    if (!scatter_front(fr))
	    {
	    	(void) printf("WARNING in redistributed2d, "
	    	              "scatter_front() failed, "
	    	              "MODIFY_TIME_STEP_TO_UNTANGLE\n");
	    	(void) reset_interface_of_front(fr,save_intfc);
	    	prepare_to_leave_redistribute2d(save_intfc);
	    	dt_frac = fr->dt_frac;
	    	*dt_frac = Max_time_step_modification_factor(fr);
	    	DEBUG_LEAVE(redistribute2d)
	    	return MODIFY_TIME_STEP_REDISTRIBUTE;
	    }
#endif /* defined(USE_OVERTURE) */

	    do_scatter = NO;
	    DEBUG_FRONT("after interior untangle:",fr)
	    if (save_intfc[1] != NULL)
	    {
	    	delete_interface(save_intfc[1]);
		save_intfc[1] = NULL;
	    }
	    goto redistribute_interface;
	}
	else if (force_tangle() && fr->dt > 0.0)
	{
	    dt_frac = fr->dt_frac;
	    dt = fr->dt;
	    dt_min = dt;
	    min_dt_frac = 0.5*(dt_max + dt)/dt;
	    *dt_frac = max(*dt_frac,min_dt_frac);
	    (void) reset_interface_of_front(fr,save_intfc);
	    prepare_to_leave_redistribute2d(save_intfc);
	    DEBUG_LEAVE(redistribute2d)
	    return MODIFY_TIME_STEP_REDISTRIBUTE;
	}

#if defined(USE_OVERTURE)
        if (!correct_for_exterior_curves(fr))
        {
            (void) printf("WARNING in redistribute2d(), "
                          "unable to correct for exterior curves\n");
            (void) reset_interface_of_front(fr,save_intfc);
            prepare_to_leave_redistribute2d(save_intfc);
            DEBUG_LEAVE(redistribute2d)
            return BAD_REDISTRIBUTION;
        }
#else /* if defined(USE_OVERTURE) */
	if (!pp_min_status(correct_for_exterior_curves(fr)))
	{
	    (void) printf("WARNING in redistribute2d(), "
	                  "unable to correct for exterior curves\n");
	    (void) reset_interface_of_front(fr,save_intfc);
	    prepare_to_leave_redistribute2d(save_intfc);
	    DEBUG_LEAVE(redistribute2d)
	    return BAD_REDISTRIBUTION;
	}
#endif /* if defined(USE_OVERTURE) */

	DEBUG_FRONT("after correction for exterior curves",fr)
	if (fr->interf->modified)
	    do_scatter = YES;

#if defined(USE_OVERTURE)
        if (do_scatter)
#else /* if defined(USE_OVERTURE) */
        if (pp_max_status(do_scatter))
#endif /* if defined(USE_OVERTURE) */
	{

#if !defined(USE_OVERTURE)
	    if (!scatter_front(fr))
	    {
	    	(void) printf("WARNING in redistributed2d, "
	    	              "scatter_front() failed, "
	    	              "\t\tMODIFY_TIME_STEP_TO_UNTANGLE\n");
	    	(void) reset_interface_of_front(fr,save_intfc);
	    	prepare_to_leave_redistribute2d(save_intfc);
	    	dt_frac = fr->dt_frac;
	    	*dt_frac = Max_time_step_modification_factor(fr);
	    	DEBUG_LEAVE(redistribute2d)
	    	return MODIFY_TIME_STEP_REDISTRIBUTE;
	    }
#endif /* if !defined(USE_OVERTURE) */
	}

	DEBUG_FRONT("after redistribute:",fr)
	prepare_to_leave_redistribute2d(save_intfc);
	DEBUG_LEAVE(redistribute2d)
	return GOOD_REDISTRIBUTION;
}		/*end redistribute2d*/
}}}
src/front/fredist3d.c
{{{
EXPORT int redistribute3d(
	Front		*fr,
	bool		do_redist,
	bool		restart_init)
{
	CROSS		*cross;
	INTERFACE	*intfc;
	bool		status;
	bool		force_redistribute = YES;
	int		k, i;
	static int	cnt = 0;

	DEBUG_ENTER(redistribute3d)
	start_clock("redistribute");

	intfc = fr->interf;
	act_delete = NO;
	
	if(fr->step == -1)
	{
	    char  sn[30];
	    sprintf(sn, "pt_surface_bf%d", fr->step);
	    tecplot_interface_in_ball(sn, fr->interf);
	}

	
	if(fr->step > 0)
	{
	    SURFACE		**s;
	    CURVE		**c;

	    set_tol_for_smooth(fr);
	    //DEBUG_TMP check_print_intfc("Before surface detect", "de_and_rm_bf", 's', 
	              //DEBUG_TMP fr->interf, cnt, -1, NO);
	    cnt++;

	    for(i=0; i<2; i++)
	    {
		for (s = intfc->surfaces; s && *s; ++s)
		{
	    	    if(wave_type(*s) != FIRST_SCALAR_PHYSICS_WAVE_TYPE)
			continue;
	    
		    //DEBUG_TMP printf("#detect_and_move_points\n");
		    detect_and_move_points(*s);
		}
	
		if(NO)
		{
		    char  sn[30];
		    sprintf(sn, "pt_surface_bf%d_%d", fr->step, i);
		    tecplot_interface_in_ball(sn, fr->interf);
		}

		status = scatter_front(fr);
		//DEBUG_TMP printf("detect intfc modi %d\n", fr->interf->modified);

		if(!status)
		{
		    printf("ERROR in redistribute3d, scatter_front fails "
		    	   "after detect_and_move_points.\n");
		    clean_up(ERROR);
		}
	
		//DEBUG_TMP check_print_intfc("After surface detect", "de_and_rm_af", 's', 
				//DEBUG_TMP fr->interf, fr->step, -1, NO);
		//DEBUG_TMP printf("#detect finish %d\n\n", i);
	    }
	}

	if(fr->step == 0)
	    null_sides_are_consistent();
	//DEBUG_TMP if(fr->step%10 == 0)
		//DEBUG_TMP check_print_intfc("After surface detect", "contour", 's', 
	              //DEBUG_TMP fr->interf, fr->step, fr->step, NO);

	//if(fr->step == 1238)
	//{
	    //tecplot_interface_in_ball("sep_smo", fr->interf);
	    //clean_up(0);
	//}
	
	if ((do_redist && fr->step > 0) || pp_max_status(fr->redis_flag))
	{
	    int		num_iter=2;
	    
	    //DEBUG_TMP printf("#redist inside\n");
	    //DEBUG_TMP check_print_intfc("Before surface redist", "sur_redist", 's', 
		              //DEBUG_TMP fr->interf, fr->step, -1, NO);

	    //DEBUG_TMP remove_from_debug("act_delete");
	    if(fr->step%10 == 0 || pp_max_status(fr->redis_flag))
		//add_to_debug("act_delete");
		act_delete = NO;

	    for(i=0; i<num_iter; i++)
	    {
	        force_redistribute = YES;
	       
		//DEBUG_TMP if(fr->step == 1645 && i == -1)
		//DEBUG_TMP {
		    //add_to_debug("tst_redis");
		    //DEBUG_TMP add_to_debug("prt_que");
	            //DEBUG_TMP add_to_debug("pt_surface");
		    //DEBUG_TMP if(pp_mynode() == 7)
			//DEBUG_TMP set_shift_for_tecplot(-1.0, 0.0, 0.0);
		    //DEBUG_TMP else
			//DEBUG_TMP set_shift_for_tecplot(0.0, 0.0, 0.0);
		//DEBUG_TMP }

		status = (Interface_redistributed(fr) == YES) ?
		        FUNCTION_SUCCEEDED :
		        Surface_redistribute(fr,&force_redistribute);

		if(i != num_iter-1)
		    Interface_redistributed(fr) = NO;
		
		//There are two cases, 
		//    1. redistribute_surface fails for one proc, intfc is ok,
		//    2. the scatter_front in surface_redistribute fails, 
		//    intfc is changed and is not consistent.
	    	if (status == FUNCTION_FAILED)
		{
		    printf("WARNING in redistribute3d, Surface_redistribute "
		    	   "fails. %d  %d\n", fr->step, i);
		    
		    stop_clock("redistribute");
		    DEBUG_LEAVE(redistribute3d)
		    return BAD_REDISTRIBUTION;
		}

	    	//DEBUG_TMP check_print_intfc("After surface redist", "sur_redist_af", 'g', 
	        	      //DEBUG_TMP fr->interf, fr->step, -1, YES);
	
		//DEBUG_TMP printf("#redist finish %d\n\n", i);
	
		if(debugging("pt_surface"))
		    clean_up(0);
	    }

	    //DEBUG_TMP remove_from_debug("pt_surface");
	    //DEBUG_TMP if(debugging("pt_surface"))
		//DEBUG_TMP clean_up(0);
	    
	    //DEBUG_TMP if(fr->step == -1)
	    //DEBUG_TMP {
		//DEBUG_TMP tecplot_interface_in_ball("redis_fin", fr->interf);
	    //DEBUG_TMP }
		    
	    intfc = fr->interf;
	    fr->redis_flag = NO;
	}

	if (Tracking_algorithm(fr) == LOCALLY_GRID_BASED_TRACKING)
	{

	    if(fr->step == 0)
	        null_sides_are_consistent();
	    //DEBUG_TMP check_print_intfc("Before surface recon", "repair_bf", 'g', 
	        	//DEBUG_TMP fr->interf, fr->step, -1, YES);

	    if(recon_repeat() >= 1)
	    {
	    RECT_GRID	sav_c_gr, sav_t_gr, *sav_fr_gr;

	    sav_c_gr = Computational_grid(intfc);
	    sav_t_gr = topological_grid(intfc);
	    
	    //use a large grid, scatter_front will construct a large 
	    //buffer for intfc.
	    change_buffer_for_intfc(intfc);
	    
	    status = scatter_front(fr);
	
	    if(fr->step == 0)
	        null_sides_are_consistent();
	    //DEBUG_TMP check_print_intfc("Before surface recon in repeat", 
	    	//DEBUG_TMP "repair_bf", 'g', fr->interf, fr->step, -1, YES);
	
	    //add_to_debug("db_un");
	    //add_to_debug("box_intfc");
	
	    sav_fr_gr = fr->rect_grid;
	    fr->rect_grid = computational_grid(intfc);
   
	    //repair_intfc_at_crossings3d
	    status = repair_front_at_grid_crossing(fr);
	
	    //recover the previous grid.
	    fr->rect_grid = sav_fr_gr;
	    Computational_grid(intfc) = sav_c_gr;
	    topological_grid(intfc) = sav_t_gr;
	
	    Computational_grid(fr->interf) = sav_c_gr;
	    topological_grid(fr->interf) = sav_t_gr;
	    }
	    else
	    {
		status = repair_front_at_grid_crossing(fr);
	    }

	    if(fr->step == 0)
	        null_sides_are_consistent();
	    //DEBUG_TMP check_print_intfc("After surface recon", "repair_af", 'g', 
	        	//DEBUG_TMP fr->interf, fr->step, -1, NO);

	    if (!status)
                return UNABLE_TO_UNTANGLE;

	    //DEBUG_TMP if(fr->step == 458)
	    //DEBUG_TMP {
	        //add_to_debug("step_out");
    	        //add_to_debug("out_surf");
		//add_to_debug("err_stop");
	    //DEBUG_TMP }
	    
	    start_clock("scatter_front");
	    
	    //DEBUG_TMP add_to_debug("sep_for_open");
	    
	    status = scatter_front(fr);
	    
	    //DEBUG_TMP remove_from_debug("sep_for_open");
	    stop_clock("scatter_front");
	
	    //if(fr->step == 1615)
		//clean_up(0);
	    
	    if (!status)
	    {
		printf("WARNING, scatter_front fails after "
		       "locally reconstruction in redistribute3d.\n");
		
		stop_clock("redistribute");
		DEBUG_LEAVE(redistribute3d)
		return INCONSISTENT_RECONSTRUCTION;
	    }
	    
	    if(fr->step == 0)
	        null_sides_are_consistent();
	    //DEBUG_TMP check_print_intfc("After scat fr af repair", "repair_scat_af", 'g', 
	        	//DEBUG_TMP fr->interf, fr->step, -1, YES);

	    stop_clock("redistribute");
	    DEBUG_LEAVE(redistribute3d)
	    return GOOD_REDISTRIBUTION;
	}

	//for LGB belowing is never reached.

	if (debugging("gvrdst3d"))
	{
	    char s[120];

	    (void) sprintf(s,"before-intersect-ts%d",fr->step);
	    gview_plot_interface(s,fr->interf);
	}
	DEBUG_FRONT("before intersections check",fr)

		/* Check for Intersections in Front */

	  /* intersections does one of  the following:
	     1) returns NO if topology construction fails;
	     2) crashes if add_to_pointers() fails;
	     3) returns YES otherwise.
	  */

	if (pp_min_status(intersections(intfc,&cross,YES)) == FUNCTION_FAILED)
	{
	    stop_clock("redistribute");
	    (void) printf("WARNING in redistribute3d(), "
	                  "intersections() failed\n");
	    print_interface(intfc);
	    DEBUG_LEAVE(redistribute3d)
	    return BAD_REDISTRIBUTION;
	}

	if (debugging("gvrdst3d"))
	{
	    char s[120];

	    (void) sprintf(s,"before-untangle-ts%d",fr->step);
	    gview_plot_interface(s,fr->interf);
	}

	if (interface_is_tangled(cross))
	{
	    static const int Max_nattemps = 3;
	    int              nattemps;
	    (void) print_number_of_tangles("",intfc,cross);
	    start_clock("untangle");
	    if (restart_init) 
	    {
		stop_clock("untangle");
		stop_clock("redistribute");
		(void) printf("WARNING in redistribute(), "
		              "Restart interface tangled, cannot continue\n");
		DEBUG_LEAVE(redistribute3d)
		return BAD_REDISTRIBUTION;
	    }

	    nattemps = 0;
	    while (cross) 
	    {
		++nattemps;
		if (!scalar_unravel_3d(fr,&cross))
		{
		    stop_clock("untangle");
		    stop_clock("redistribute");
		    (void) printf("WARNING in redistribute3d(), "
		                  "scalar_unravel_3d() failed\n");
		    DEBUG_LEAVE(redistribute3d)
		    return UNABLE_TO_UNTANGLE;
		}
		force_redistribute = YES;
		if (!Surface_redistribute(fr,&force_redistribute))
		{
		    stop_clock("untangle");
		    stop_clock("redistribute");
		    (void) printf("WARNING in redistribute3d(), after "
		                  "untangling Surface_redistribute() failed\n");
		    DEBUG_LEAVE(redistribute3d)
		    return UNABLE_TO_UNTANGLE;
		}
		intfc = fr->interf;
		if (!pp_min_status(intersections(intfc,&cross,YES)))
		{
		    (void) printf("WARNING in redistribute3d(), "
		                  "After untangle, intersections() failed\n");
		    DEBUG_LEAVE(redistribute3d)
		    return UNABLE_TO_UNTANGLE;
		}
		if (interface_is_tangled(cross))
		{
		    if (nattemps>=Max_nattemps)
		    {
		        (void) printf("WARNING in redistribute3d(), "
				      "After untangle, intersections() finds "
				      "new tangle, too many attemps\n");
		        DEBUG_LEAVE(redistribute3d)
		        return UNABLE_TO_UNTANGLE;
		    }
		    else
		    {
		        (void) printf("WARNING in redistribute3d(), "
				      "After untangle, intersections() finds "
				      "new tangle, will attempt to untangle\n");
		    }
		}
		
	    }
	    stop_clock("untangle");
	}

	if (debugging("gvrdst3d"))
	{
	    char s[120];

	    (void) sprintf(s,"after-untangle-ts%d",fr->step);
	    gview_plot_interface(s,fr->interf);
	}

	stop_clock("redistribute");
	DEBUG_LEAVE(redistribute3d)
	return GOOD_REDISTRIBUTION;
}		/*end redistribute3d*/
}}}
src/front/fredist3d.c
{{{
LOCAL  bool redistribute_surface(
	SURFACE		*s,
	Front		*fr)
{
	INTERFACE *intfc;
	POINT	  *midp;
	POINTER_Q *insert_queue, *delete_queue;
	RECT_GRID *gr;
	TRI	  *tri, *oppt;
	bool      status;
	int       nside, nf, nl, ns, nt, i;
	int	  dim, wc;
	FILE	  *db_file;
	float	  coords[3];

	DEBUG_ENTER(redistribute_surface)

	set_pointer_queue_opts(PQ_BLOCK_SIZE,Num_pqs_in_block,PQ_ALLOC_TYPE,
		               "vmalloc",PQ_ALLOC_SIZE_FOR_POINTERS,
			       sizeof(TRI_SURF),0);

	intfc = s->interface;
	dim = intfc->dim;
	gr = fr->rect_grid;
	
	//set the tolerance for tri_status
	wc = wave_type(s)< FIRST_VECTOR_PHYSICS_WAVE_TYPE ?
				GENERAL_WAVE : VECTOR_WAVE;
	max_sqr_area = Max_tri_sqr_area(fr,wc);
	min_sqr_area = Min_tri_sqr_area(fr,wc);
	max_sqr_length = Max_scaled_tri_side_sqr_length(fr);
	aspect_tol2 = sqr(Aspect_ratio_tolerance(fr,wc));
	min_sqr_norm = Min_sqr_norm(gr);
	
	//DEBUG_TMP if(fr->step == -1)
	//DEBUG_TMP {
	    //DEBUG_TMP add_to_debug("pt_surface");
	    //DEBUG_TMP add_to_debug("prt_que");
	//DEBUG_TMP }
	    
	status = YES;
	insert_queue = delete_queue = NULL;
	nt = nf = nl = ns = 0;
	
	for (tri=first_tri(s); !at_end_of_tri_list(tri,s); tri=tri->next)
	{
	    nt++;
	    switch (tri_status(tri,gr))
	    {
	    case BAD_ANGLE:	
		++nf;
	    case LARGE:
		++nl;
		insert_queue = alloc_and_add_to_queue(tri,s,insert_queue,nside);
		break;
	    case SMALL:
		++ns;
		delete_queue = alloc_and_add_to_queue(tri,s,delete_queue,nside);
		break;
	    case GOOD_ANGLE:
	    default:
		Tri_workspace(tri) = NULL;
		break;
	    }
	}
	
	//DEBUG_TMP printf("#nfls %-8d   %5d %5d %5d %7d\n", fr->step, nf, nl, ns, nt);

	if(insert_queue==NULL && delete_queue==NULL)
	{
	    DEBUG_ENTER(redistribute_surface)
	    return YES;
	}

	if(debugging("prt_que"))
	{
	    char  ch[60];

	    sprintf(ch, "queue_tri%d_%d.plt", fr->step, pp_mynode());
	    db_file = fopen(ch, "w");
	    (void) fprintf(db_file,"TITLE = \"tecplot surface\"\n"
		   	"VARIABLES = \"x\", \"y\", \"z\"\n");
	    printf("#queue_tri open \n");

	    tecplot_tri_queue("insert", db_file, insert_queue);
	    tecplot_tri_queue("delete", db_file, delete_queue);
	    fclose(db_file);
	}

	sort_pointer_queue(insert_queue,intfc,LONGEST);
	if(debugging("pt_surface"))
	{
	    tecplot_surface_in_ball("in_bf", s);
	    //DEBUG_TMP check_print_intfc("In redist surf, before insert", "insert_bf", 'g', 
	        	      //DEBUG_TMP fr->interf, 1, -1, YES);
	}

	//DEBUG_TMP printf("#insert redist\n");
	while (insert_queue)
	{
	    insert_queue = head_of_pointer_queue(insert_queue);
	    tri = Tri_of_q(insert_queue);
	    
	    nside = find_scaled_extrem_edge(tri,gr,LONGEST);
	    insert_queue = dequeue(tri,insert_queue);
	    
	    if (is_side_bdry(tri,nside))
		continue;
	    
	    oppt = Tri_on_side(tri,nside);	    
	    if(is_tri_in_queue(oppt,insert_queue))
		insert_queue = dequeue(oppt,insert_queue);
	    if(is_tri_in_queue(oppt,delete_queue))
		delete_queue = dequeue(oppt,delete_queue);

	    if(skip_bdry_tri(oppt) || skip_bdry_tri(tri))
		continue;

	    // find and make tri side mid point
	    for(i = 0; i < dim; ++i)
		coords[i] = 0.5*(Coords(Point_of_tri(tri)[nside])[i] +
		                 Coords(Point_of_tri(tri)[Next_m3(nside)])[i]);
	    midp = Point(coords);

	    if (!insert_point_in_tri_side(midp,nside,tri,s))
	    {
		printf("WARNING redistribute_surface, "
		       "insert_point_in_tri_side fails.\n");
		status = NO;
	    }
	}
	    
	sort_pointer_queue(delete_queue,intfc,SHORTEST);
	if(debugging("pt_surface"))
	{
	    tecplot_surface_in_ball("de_bf", s);
	    //DEBUG_TMP check_print_intfc("In redist surf, before delete", "delete_bf", 'g', 
	        	      //DEBUG_TMP fr->interf, 1, -1, YES);
	    tri_queue_test("deletei_bf_test",  delete_queue);
	}

	//DEBUG_TMP printf("#delete redist\n");
	while (delete_queue)
	{
	    delete_queue = head_of_pointer_queue(delete_queue);
	    tri = Tri_of_q(delete_queue);

	    nside = find_scaled_extrem_edge(tri,gr,SHORTEST);
	    //add_to_debug("delete_dup");
		
	    delete_queue = dequeue(tri, delete_queue);
	    //if(!debugging("act_delete"))
	    if (act_delete)
		continue;

	    if(!delete_min_side_of_tri(tri,nside,s,&delete_queue,fr))
	    {
		printf("WARNING, redistribute_surface, "
		       "delete_min_side_of_tri fails.\n");
		status = NO;
	    }

	    //DEBUG_TMP remove_from_debug("delete_dup");
	}
	    
	//DEBUG_TMP if(debugging("pt_surface"))
	//DEBUG_TMP {
	    //DEBUG_TMP tecplot_surface_in_ball("de_af", s);
	    //DEBUG_TMP check_print_intfc("In redist surf, after delete", "delete_af", 'g', 
	        	      //DEBUG_TMP fr->interf, 1, -1, YES);
	//DEBUG_TMP }
	
	DEBUG_LEAVE(redistribute_surface)
	return status;
}		/*end redistribute_surface*/
}}}
src/front/fcorrspnd.c
{{{
EXPORT void remove_corresponds_to_deleted_interface(
	INTERFACE	*intfc)
{
	struct Table	*IT = interface_table_list();
	struct Table	*T;
	HYPER_SURF	**hs;
	HYPER_SURF_BDRY **hsb;

	for (T = IT; T != NULL; T = T->next)
	{
		if (T->interface == intfc) continue;
		for (hs = hyper_surf_list(T->interface); hs && *hs; ++hs)
		{
			if (!correspond_hyper_surf(*hs)) continue;
			if (correspond_hyper_surf(*hs)->interface == intfc)
				correspond_hyper_surf(*hs) = NULL;
		}
		for (hsb = hyper_surf_bdry_list(T->interface);
							hsb && *hsb; ++hsb)
		{
		    if (!correspond_hyper_surf_bdry(*hsb)) continue;
		    if (correspond_hyper_surf_bdry(*hsb)->interface == intfc)
			    correspond_hyper_surf_bdry(*hsb) = NULL;
		}
	}
}		/*end remove_corresponds_to_deleted_interface*/
}}}
src/front/fgb3d.c
{{{
/*
*		repair_intfc_at_crossings3d():
*/

EXPORT	bool	repair_intfc_at_crossings3d(
	Front     *front)
{
	INTERFACE *intfc = front->interf;
	bool      sav_intrp = interpolate_intfc_states(intfc);
	int 	  i, smin[3], smax[3];
	size_t	  sizest = front->sizest;
	RECT_GRID Dual_grid, *comp_grid = front->rect_grid;
	RECT_GRID gr_save = topological_grid(intfc);

	DEBUG_ENTER(repair_intfc_at_crossings3d)

	//printf("#front grid\n");
	//print_rectangular_grid(comp_grid);
	
	//printf("#intfc grid\n");
	//print_rectangular_grid(computational_grid(intfc));

	set_dual_grid(&Dual_grid,comp_grid);
	set_size_of_intfc_state(sizest);
	set_copy_intfc_states(YES);

	print_storage("Entering repair_intfc_at_crossings3d","crx_store");

	set_expanded_grid(&Dual_grid,&topological_grid(intfc));

	make_interface_topology_lists(intfc);
	set_crx_storage_for_reconstruction(intfc,NULL);

	/* set reconstruction boundary and tolerance */

	for (i = 0; i < 3; ++i)
	{
	    smin[i] = 0;
            smax[i] = topological_grid(intfc).gmax[i];
	}
	
	start_clock("insert_grid_crossings3d");
	interpolate_intfc_states(intfc) = YES;
	insert_grid_intfc_crossings(intfc);

	stop_clock("insert_grid_crossings3d");
	print_storage("After insert_grid_crossings3d","crx_store");

	start_clock("reconstruct_intfc3d_in_box");
	if (!repair_intfc3d_in_box(intfc,smin,smax,front))
	{
	    interpolate_intfc_states(intfc) = sav_intrp;
	    DEBUG_LEAVE(repair_intfc_at_crossings3d)
	    return NO;
	}
	stop_clock("reconstruct_intfc3d_in_box");
	print_storage("After reconstruct_intfc3d_in_box","crx_store");

	interpolate_intfc_states(intfc) = sav_intrp;

	//identify_detached_surface_curve_pair(intfc);

	reset_intfc_num_points(intfc);
	topological_grid(intfc) = gr_save;
        free_crx_storage(intfc);
	
	front->interf = copy_interface(intfc);
	
	delete_interface(intfc);
	print_storage("After copy_interface","crx_store");
	DEBUG_LEAVE(repair_intfc_at_crossings3d)
	return YES;
}	/*end repair_intfc_at_crossings3d*/
}}}
src/front/fgb3d.c
{{{
LOCAL	bool repair_intfc3d_in_box(
	INTERFACE  *intfc,
	int *smin,
	int *smax,
	Front *front)
{
	Table *T = table_of_interface(intfc);
	RECT_GRID gr = topological_grid(intfc);
	COMPONENT *comp = T->components;
	int i,n_reg_node;
	int *gmax = gr.gmax;
	bool status;

	if (debugging("set_component"))
	    (void) printf("Entering repair_intfc3d_in_box()\n");

	n_reg_node = (gmax[0]+1)*(gmax[1]+1)*(gmax[2]+1);
	for (i = 0; i < n_reg_node; ++i)
	    comp[i] = NO_COMP;

	status = track_comp_and_repair3d(smin,smax,gmax,intfc,front);
	
	if (status == FUNCTION_FAILED)
	{
	    screen("track_comp_and_repair3d() failed!\n");
	    clean_up(ERROR);
	    return status;
	}
	if (debugging("set_component"))
	    (void) printf("Leaving repair_intfc3d_in_box()\n");
	return status;
}	/* end repair_intfc3d_in_box */
}}}
src/intfc/iredist.c
{{{
/*
*			replace_curve_seg_by_bond():
*
*	Replaces the curve segment from the start of bond bs to the end
*	of bond be by a single bond. The resultant single bond has the
*	same pointer value as bs.
*/

LOCAL   void replace_curve_seg_by_bond(
	CURVE		*c,
	BOND		*bs,
	BOND		*be)
{
	BOND		*bnext;

	if ((bs == NULL) || (be == NULL))
	    return;
	if (bs == be)
	    return;
	bnext = be->next;
	while (bs->next != bnext)
		(void) delete_start_of_bond(bs->next,c);
}		/*end replace_curve_seg_by_bond*/
}}}
src/intfc/isub.c
{{{
EXPORT void reset_normal_on_intfc(
	INTERFACE	*intfc)
{
	SURFACE		**s;
	TRI		*t;


	switch (tri_storage_type)
	{
	case MIN_TRI_STORAGE:
	    break;
	case FULL_TRI_GEOMETRY:
	case TRI_PLUS_NORMAL:
	    for (s = intfc->surfaces; s && *s; ++s)
	        for (t = first_tri(*s); !at_end_of_tri_list(t,*s); t = t->next)
		    set_normal_of_tri(t);
	    break;
	default:
	    screen("ERROR in reset_normal_on_intfc(), unknown value %d\n",
		   tri_storage_type);
	    clean_up(ERROR);
	}
}		/*end reset_normal_on_intfc*/
}}}
example/example.c
{{{
/********************************************************************
 *	Sample (rotation) velocity function for the front    *
 ********************************************************************/

static int rotation_vel(
	POINTER params,
	Front *front,
	POINT *p,
	HYPER_SURF_ELEMENT *hse,
	HYPER_SURF *hs,
	float *vel)
{
	ROTATION_VEL_PARAMS *rv_params = (ROTATION_VEL_PARAMS*)params;
	float *coords = Coords(p);
	float V,xcomp,ycomp;
	float rad;
	float *cen = rv_params->cen;
	float omega_0 = rv_params->omega_0;
	float domega_dr = rv_params->domega_dr;
	float dx,dy;

	dx = coords[0] - cen[0]; 
	dy = coords[1] - cen[1];

	rad = sqrt(sqr(dx) + sqr(dy));
	if (rad == 0.0)
        {
            vel[0] = vel[1] = 0.0;
            return 1;
        }
	xcomp = fabs(coords[1]-cen[0])/rad;
        ycomp = fabs(coords[0]-cen[1])/rad;
        V = rad*(omega_0 + domega_dr*rad);
        if (coords[0]-cen[0] >= 0.0 && coords[1]-cen[1] >= 0.0) /*1st quadrant*/
        {
            vel[0] = -V*xcomp;
            vel[1] =  V*ycomp;
        }
        else if (coords[0]-cen[0] <= 0.0 && coords[1]-cen[1] >= 0.0) /*2nd quadrant*/
        {
            vel[0] = -V*xcomp;
            vel[1] = -V*ycomp;
        }
        else if (coords[0]-cen[0] <= 0.0 && coords[1]-cen[1] <= 0.0) /*3rd quadrant*/
        {
            vel[0] =  V*xcomp;
            vel[1] = -V*ycomp;
        }
        else if (coords[0]-cen[0] >= 0.0 && coords[1]-cen[1] <= 0.0) /*4th quadrant*/
        {
            vel[0] =  V*xcomp;
            vel[1] =  V*ycomp;
        }
	

}	/* end rotation_vel */

}}}
src/front/fcorrspnd.c
{{{
/*
*			rst_cor_after_delete_interface():
*
*	Removes the CORRESPOND structures containing intfc from
*	the list AND frees the storage used.
*/

EXPORT	void rst_cor_after_delete_interface(
	INTERFACE	*intfc)
{
	CORRESPOND	*crspd, *next_crspd = NULL;

	for (crspd = first_cor; crspd != NULL; crspd = next_crspd)
	{
		next_crspd = crspd->next;
		if ((intfc == crspd->oldintfc) || (intfc == crspd->newintfc))
		{
		    if (DEBUG)
		    {
			(void) printf("In rst_cor_after_delete_interface(),");
			(void) printf("\n\tintfc = %llu,",
				      interface_number(intfc));
			(void) printf(" deleting correspond = %p\n",
				      (POINTER)crspd);
		    }
		    delete_correspond_from_list(crspd);
		    free_correspondence_struct(crspd);
		}
	}
}		/*end rst_cor_after_delete_interface*/
}}}
src/intfc/isub.c
{{{
EXPORT	float scaled_bond_length(
	BOND		*b,
	float		*h,
	int		dim)
{
	float tmp, ans = 0.0;
	int   i;

	for (i = 0; i < dim; ++i) 
	{
	    tmp = (Coords(b->end)[i] - Coords(b->start)[i])/h[i];
	    ans += sqr(tmp);
	}
	return sqrt(ans);
}		/*end scaled_bond_length*/
}}}
src/front/fscatter.c
{{{
/*
*			scatter_front():
*	
*	This routine does three things:
*	1. cut large intfc according to the size of physical
*	   subdomain;
*	2. extend subdomain intfc and rect_grid up to buffer region;
*	3. fix boundary curves onto extended subdomain ----
*	   virtual domain.
*
*/


EXPORT bool scatter_front(
	Front		*front)
{
	COMPONENT	max_comp;
	INTERFACE	*intfc = front->interf;
	RECT_GRID	*gr = front->rect_grid;
	bool		status;
	bool		sav_copy = copy_intfc_states();
	bool		sav_intrp = interpolate_intfc_states(intfc);
	int		i, dim = gr->dim;
	DEBUG_ENTER(scatter_front)

	if ((dim == 3) && debugging("consistency"))
	{
	    (void) printf("Check consistency of interface "
	                  "before scatter_front()\n");
	    if (!consistent_interface(intfc))
	    {
		screen("ERROR in scatter_front(),  input interface is "
		       "inconsistent\n");
		clean_up(ERROR);
	    }
	    (void) printf("Interface into scatter_front is consistent\n");
	}
	if (dim == 2)
	{
	    for (i = 0; i < dim; ++i)
		if ((gr->lbuf[i] > 0) || (gr->ubuf[i] > 0))
		     break;
	    if (i == dim)
	    {
		DEBUG_LEAVE(scatter_front)
		status = FUNCTION_SUCCEEDED; /* No subdomains to process */
		return pp_min_status(status);
	    }
	}

	set_copy_intfc_states(YES);
	interpolate_intfc_states(intfc) = NO;

	status = form_subintfc_via_communication(front);
	
	if(dim == 3)
	    delete_outside_surface(front->interf);
	
	max_comp = max_component(intfc);
	pp_global_imax(&max_comp,1L);
	max_component(intfc) = max_comp;

	interpolate_intfc_states(intfc) = sav_intrp;
	set_copy_intfc_states(sav_copy);

	if ((status) && (dim == 3) && debugging("consistency"))
	{
	    (void) printf("Check consistency of interface ");
	    (void) printf("after scatter_front()\n");
	    if (!consistent_interface(intfc))
	    {
		screen("ERROR in scatter_front(),  output interface is "
		       "inconsistent\n");
		clean_up(ERROR);
	    }
	}

	DEBUG_LEAVE(scatter_front)
	return pp_min_status(status);
}		/*end scatter_front*/
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::setAdvectionDt()
{
	pp_global_max(&max_speed,1);
	if (max_speed != 0.0)
	    max_dt = hmin/max_speed;
	else
	    max_dt = HUGE;
	if (debugging("trace"))
	    printf("In setAdvectionDt: max_dt = %20.16f\n",max_dt);
}	/* end setAdvectionDt */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::setComponent(void)
{
	int i;
	double coords[MAXD];
	
	// cell center components
	for (i = 0; i < cell_center.size(); i++)
	{
	    cell_center[i].comp = 
	    		getComponent(cell_center[i].icoords);
	}
}
}}}
liquid/lcartsn.c
{{{
void C_CARTESIAN::setDomain()
{
	static bool first = YES;
	INTERFACE *grid_intfc;
	Table *T;
	static double *solute;
	int i;

	if (debugging("trace")) printf("Passed FrontMakeGridIntfc()\n");

	grid_intfc = front->grid_intfc;
	top_grid = &topological_grid(grid_intfc);
	lbuf = front->rect_grid->lbuf;
	ubuf = front->rect_grid->ubuf;
	top_gmax = top_grid->gmax;
	top_L = top_grid->L;
	top_U = top_grid->U;
	top_h = top_grid->h;
	dim = grid_intfc->dim;
	T = table_of_interface(grid_intfc);
	top_comp = T->components;
	eqn_params = (EQN_PARAMS*)front->extra;
	hmin = top_h[0];
	for (i = 1; i < dim; ++i)
	    if (hmin > top_h[i]) hmin = top_h[i];

	switch (dim)
	{
	case 1:
            if (first)
            {
                uni_array(&array,top_gmax[0]+1,FLOAT_NBYES);
                uni_array(&solute,top_gmax[0]+1,FLOAT_NBYES);
                first = NO;
            }	
	    imin = (lbuf[0] == 0) ? 1 : lbuf[0];
	    imax = (ubuf[0] == 0) ? top_gmax[0] - 1 : top_gmax[0] - ubuf[0];
	    eqn_params->solute = solute;
	    eqn_params = (EQN_PARAMS*)front->extra;
	    break;
	case 2:
	    if (first)
	    {
	    	uni_array(&array,(top_gmax[0]+1)*(top_gmax[1]+1),FLOAT_NBYES);
	    	uni_array(&solute,(top_gmax[0]+1)*(top_gmax[1]+1),FLOAT_NBYES);
	    	first = NO;
	    }
	    imin = (lbuf[0] == 0) ? 1 : lbuf[0];
	    jmin = (lbuf[1] == 0) ? 1 : lbuf[1];
	    imax = (ubuf[0] == 0) ? top_gmax[0] - 1 : top_gmax[0] - ubuf[0];
	    jmax = (ubuf[1] == 0) ? top_gmax[1] - 1 : top_gmax[1] - ubuf[1];
	    eqn_params->solute = solute;
	    break;
	case 3:
	    if (first)
	    {
	    	uni_array(&array,
			(top_gmax[0]+1)*(top_gmax[1]+1)*(top_gmax[2]+1),FLOAT_NBYES);
	    	uni_array(&solute,
			(top_gmax[0]+1)*(top_gmax[1]+1)*(top_gmax[2]+1),FLOAT_NBYES);
	    	first = NO;
	    }
	    imin = (lbuf[0] == 0) ? 1 : lbuf[0];
	    jmin = (lbuf[1] == 0) ? 1 : lbuf[1];
	    kmin = (lbuf[2] == 0) ? 1 : lbuf[2];
	    imax = (ubuf[0] == 0) ? top_gmax[0] - 1 : top_gmax[0] - ubuf[0];
	    jmax = (ubuf[1] == 0) ? top_gmax[1] - 1 : top_gmax[1] - ubuf[1];
	    kmax = (ubuf[2] == 0) ? top_gmax[2] - 1 : top_gmax[2] - ubuf[2];
	    eqn_params->solute = solute;
	    break;
	}
}	/* end setDomain */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::setGlobalIndex()
{
	int i,j,k,ic;
	int num_nodes = pp_numnodes();
	int myid = pp_mynode();
	static bool first = YES;

	if (first)
	{
	    first = NO;
	    uni_array(&n_dist,num_nodes,sizeof(int));
	}
	NLblocks = 0;
	switch (dim)
	{
	case 1:
	    for (i = imin; i <= imax; i++)
	    {
		ic = d_index1d(i,top_gmax);
		if (cell_center[ic].comp == SOLID_COMP) continue;
		NLblocks++;
	    }
	    break;
	case 2:
	    for (j = jmin; j <= jmax; j++)
	    for (i = imin; i <= imax; i++)
	    {
		ic = d_index2d(i,j,top_gmax);
		if (cell_center[ic].comp == SOLID_COMP) continue;
		NLblocks++;
	    }
	    break;
	case 3:
	    for (k = kmin; k <= kmax; k++)
	    for (j = jmin; j <= jmax; j++)
	    for (i = imin; i <= imax; i++)
	    {
		ic = d_index3d(i,j,k,top_gmax);
		if (cell_center[ic].comp == SOLID_COMP) continue;
		NLblocks++;
	    }
	    break;
	}

	for (i = 0; i < num_nodes; ++i) n_dist[i] = 0;
	n_dist[myid] = NLblocks;
	pp_global_imax(n_dist,num_nodes);
	ilower = 0;
        iupper = n_dist[0];

        for (i = 1; i <= myid; i++)
        {
            ilower += n_dist[i-1];
            iupper += n_dist[i];
        }	
}
}}}
liquid/lcartsn.c
{{{
// smooth discontinuous properties, such as the density, mu, force.
void L_CARTESIAN::setSmoothedProperties(void)
{
	switch (dim)
	{
	case 2:
	    return setSmoothedProperties2d();
	case 3:
	    return setSmoothedProperties3d();
	}
}	/* end setSmoothedProperties */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::setSmoothedProperties2d(void)
{
	int i,j,l; 
	int index, index_nb[4];
	int comp, c[4];
	double center[2], point[2], phi, H;
	bool is_near_intfc_pt;

	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index  = d_index2d(i,j,top_gmax);			
	    comp  = cell_center[index].comp;
	    if (!liquid_comp(comp)) continue;

	    index_nb[0] = d_index2d(i-1,j,top_gmax);			
	    index_nb[1] = d_index2d(i+1,j,top_gmax);			
	    index_nb[2] = d_index2d(i,j-1,top_gmax);			
	    index_nb[3] = d_index2d(i,j+1,top_gmax);			
	    for (l = 0; l < 4; ++l)
	    	c[l] = cell_center[index_nb[l]].comp;
			
	    is_near_intfc_pt = NO;
	    for (l = 0; l < 4; ++l)
	    {
	    	if (comp != c[l] && liquid_comp(c[l]))
		    is_near_intfc_pt = YES;
	    }
	    if (is_near_intfc_pt)
	    {
		getRectangleCenter(index, center);
		getNearestInterfacePoint(comp, center, point);	

		phi = getDistance(center,point);
		if (comp == m_comp[0])
		    phi *= -1;
			
		H = getSmoothingFunction(phi);
		cell_center[index].m_state.m_mu = m_mu[0]  + 
					(m_mu[1]-m_mu[0])*H;
		cell_center[index].m_state.m_rho = m_rho[0] + 
					(m_rho[1]-m_rho[0])*H; 
	    }
	    else
	    {
		switch (comp)
		{
		case LIQUID_COMP1:
		    cell_center[index].m_state.m_mu = m_mu[0];
		    cell_center[index].m_state.m_rho = m_rho[0];
		    break;
		case LIQUID_COMP2:
		    cell_center[index].m_state.m_mu = m_mu[1];
		    cell_center[index].m_state.m_rho = m_rho[1];
		    break;
		case SOLID_COMP:
		    cell_center[index].m_state.m_mu = 0.0;
		    cell_center[index].m_state.m_rho = 0.0;
		    break;
		}
	    }

	}
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{	
	    index  = d_index2d(i,j,top_gmax);
	    array[index] = cell_center[index].m_state.m_mu;
	}
	scatMeshArray();
	for (j = 0; j <= top_gmax[1]; j++)
	for (i = 0; i <= top_gmax[0]; i++)
	{	
	    index  = d_index2d(i,j,top_gmax);
	    cell_center[index].m_state.m_mu = array[index];
	}
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index  = d_index2d(i,j,top_gmax);
	    array[index] = cell_center[index].m_state.m_rho;
	}
	scatMeshArray();
	for (j = 0; j <= top_gmax[1]; j++)
	for (i = 0; i <= top_gmax[0]; i++)
	{
	    index  = d_index2d(i,j,top_gmax);
	    cell_center[index].m_state.m_rho = array[index];
	}
}	/* end setSmoothedProperties2d */
}}}
liquid/lcartsn.c
{{{
void L_CARTESIAN::setSmoothedProperties3d(void)
{
	int i,j,k,l; 
	int index, index_nb[6];
	COMPONENT comp, c[6];
	double center[MAXD],point[MAXD];
	double phi,H;
	bool is_near_intfc_pt;

	for (k = kmin; k <= kmax; k++)
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index  = d_index3d(i,j,k,top_gmax);			
	    comp  = cell_center[index].comp;
	    if (!liquid_comp(comp)) continue;

	    index_nb[0] = d_index3d(i-1,j,k,top_gmax);			
	    index_nb[1] = d_index3d(i+1,j,k,top_gmax);			
	    index_nb[2] = d_index3d(i,j-1,k,top_gmax);			
	    index_nb[3] = d_index3d(i,j+1,k,top_gmax);			
	    index_nb[4] = d_index3d(i,j,k-1,top_gmax);			
	    index_nb[5] = d_index3d(i,j,k+1,top_gmax);			
	    for (l = 0; l < 6; ++l)
	    	c[l] = cell_center[index_nb[l]].comp;
			
	    is_near_intfc_pt = NO;
	    for (l = 0; l < 6; ++l)
	    {
	    	if (comp != c[l] && liquid_comp(c[l]))
		    is_near_intfc_pt = YES;
	    }
	    if (is_near_intfc_pt)
	    {
		getRectangleCenter(index, center);
		getNearestInterfacePoint(comp, center, point);	

		phi = getDistance(center,point);
		if (comp == m_comp[0])
		    phi *= -1;
			
		H = getSmoothingFunction(phi);
		cell_center[index].m_state.m_mu = m_mu[0]  + 
					(m_mu[1]-m_mu[0])*H;
		cell_center[index].m_state.m_rho = m_rho[0] + 
					(m_rho[1]-m_rho[0])*H; 
	    }
	    else
	    {
		switch (comp)
		{
		case LIQUID_COMP1:
		    cell_center[index].m_state.m_mu = m_mu[0];
		    cell_center[index].m_state.m_rho = m_rho[0];
		    break;
		case LIQUID_COMP2:
		    cell_center[index].m_state.m_mu = m_mu[1];
		    cell_center[index].m_state.m_rho = m_rho[1];
		    break;
		case SOLID_COMP:
		    cell_center[index].m_state.m_mu = 0.0;
		    cell_center[index].m_state.m_rho = 0.0;
		    break;
		}
	    }
	}
	for (k = kmin; k <= kmax; k++)
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{	
	    index  = d_index3d(i,j,k,top_gmax);
	    array[index] = cell_center[index].m_state.m_mu;
	}
	scatMeshArray();
	for (k = 0; k <= top_gmax[2]; k++)
	for (j = 0; j <= top_gmax[1]; j++)
	for (i = 0; i <= top_gmax[0]; i++)
	{	
	    index  = d_index3d(i,j,k,top_gmax);
	    cell_center[index].m_state.m_mu = array[index];
	}
	for (k = kmin; k <= kmax; k++)
	for (j = jmin; j <= jmax; j++)
        for (i = imin; i <= imax; i++)
	{
	    index  = d_index3d(i,j,k,top_gmax);
	    array[index] = cell_center[index].m_state.m_rho;
	}
	scatMeshArray();
	for (k = 0; k <= top_gmax[2]; k++)
	for (j = 0; j <= top_gmax[1]; j++)
	for (i = 0; i <= top_gmax[0]; i++)
	{
	    index  = d_index3d(i,j,k,top_gmax);
	    cell_center[index].m_state.m_rho = array[index];
	}
}	/* end setSmoothedProperties3d */
}}}
src/front/fadv.c
{{{
EXPORT	void	set_advance_front(
	INIT_DATA	*init,
	Front		*front)
{
	int dim = front->rect_grid->dim;
	bool efss,mvfm;

	front->_EnforceFlowSpecifedStates = NULL;
	efss = ((init==NULL) || (enforce_flow_specified_states(init)==YES)) ?
		YES : NO;
	front->movingframe = ((init==NULL) || (movingframe(init)==YES)) 
				? YES : NO;
	switch (dim)
	{
	case 1:
	    front->_pre_advance_front = NULL;
	    front->_advance_front = advance_front1d;
	    if (efss == YES)
	        front->_EnforceFlowSpecifedStates = EnforceFlowSpecifedStates1d;
	    break;
	case 2:
#if defined(USE_OVERTURE)
            front->_normal_advance_front = normal_advance_front2d;
            front->_tangnt_advance_front = tangnt_advance_front2d;
            front->_redist_advance_front = redist_advance_front2d;
#else /* if defined(USE_OVERTURE) */
	    front->_advance_front = advance_front2d;
#endif /* if defined(USE_OVERTURE) */
	    front->_pre_advance_front = FrontPreAdvance;
	    if (efss == YES)
	        front->_EnforceFlowSpecifedStates = EnforceFlowSpecifedStates2d;
	    break;
	case 3:
	    front->_pre_advance_front = NULL;
	    front->_advance_front = advance_front3d_tracking_control;
	    if (efss == YES)
	        front->_EnforceFlowSpecifedStates = EnforceFlowSpecifedStates3d;
	    break;
	}
}		/*end set_advance_front*/
}}}
src/inftc/userhooks.c
{{{
EXPORT	bool set_boundary(
	INTERFACE	*intfc,
	RECT_GRID	*gr,
	COMPONENT	i_comp,
	double		eps)
{
	if (intfc == NULL)
	    return NO;
	return (*i_user_interface(intfc)._set_boundary)(intfc,gr,i_comp,eps);
}		/*end set_boundary*/
}}}
src/front/fsub.c
{{{
EXPORT  void set_default_front(
	F_INIT_DATA *Init,
	Front *front)
{
	set_front_hooks(init_data(Init));
	MaxFrontSpeed(front) = InitialMaxFrontSpeed(Init);
	Init_redistribution_function(front) = f_init_redistribute;
	set_front_pp_grid(init_data(Init),front);
	set_default_front_options(init_data(Init),front);
	f_set_default_front_parameters(init_data(Init),front);
	init_front(init_data(Init),front);
	front->resolution_level = 3;
}	/* end set_default_front */
}}}
src/front/finit.c
{{{
/*
*			set_default_front_options():
*
*	set default front options.
*
*/

EXPORT void set_default_front_options(
	INIT_DATA *init,
	Front     *front)
{
	char	s[Gets_BUF_SIZE];
	int	dim = front->rect_grid->dim;

	debug_print("init","Entered set_default_front_options()\n");

	InitialMaxFrontSpeed(init) =
	    alloc_MaxFrontSpeed(InitialMaxFrontSpeed(init),
	                        i_intfc(init),StateSize(init));

	if (restart_io_type(init) != NULL)
	    read_print_front_options(init,front);

	set_redistribution_defaults(init);

	    /* Choose Constant to Increase/Decrease Time-Steps */

	set_front_time_step_control_default(init);

	tangent_method(init) = LINEAR_SECANT;
	if (restart_io_type(init) != NULL)
	    tangent_method(init) = TANGENT_METHOD_FROM_RESTART;
	if (dim == 3)
	{
	    normal3d_method(init) = AREA_WEIGHTED_NORMAL;
	    if (restart_io_type(init) != NULL)
	        normal3d_method(init) = NORMAL_METHOD_FROM_RESTART;
	}

	if (dim == 2) /*Only 2D currently supports multiple tangent algorithms*/
	{
	    if (restart_io_type(init) != NULL)
	    {
	        F_USER_INTERFACE *fuh;
	        set_tangent_operator(tangent_method(init),dim);
		fuh = f_user_hook(dim);
		interface_tangent_function(restart_intfc(init)) =
		    fuh->_interface_tangent_function;
	    }
	}
	debug_print("init","Left set_default_front_options()\n");
}		/*end set_default_front_options*/
}}}
src/front/finit.c
{{{
EXPORT	void	set_front_hooks(
	INIT_DATA	*init)
{
	F_INIT_DATA	*f_init = f_init_data(init);

	f_init->_set_redistribution_defaults = f_set_redistribution_defaults;
	f_init->_set_front_time_step_control_default = 
	    f_set_front_time_step_control_default;
	f_init->_copy_redistribution_values = f_copy_redistribution_values;
	f_init->_prompt_for_redistribute = f_prompt_for_redistribute;
	f_init->_read_print_FlowSpecifiedRegion_data = 
	    f_read_print_FlowSpecifiedRegion_data;
	f_init->_prompt_for_front_options = f_prompt_for_front_options;
	f_init->_read_print_front_options = f_read_print_front_options;
}		/*end set_front_hooks*/
}}}
src/front/fscatter.c
{{{
EXPORT	void set_front_pp_grid(
	INIT_DATA	*init,
	Front		*front)
{
	RECT_GRID	*comp_glbgr = front->rect_grid;
	double		L[MAXD], U[MAXD], *GL, *GU;
	double		*h = comp_glbgr->h;
	int		lbuf[MAXD], ubuf[MAXD];
	int		gmax[MAXD];
	int		icoords[MAXD];
	int		i, dim = comp_glbgr->dim;
	int		myid = pp_mynode();
	static PP_GRID	Pp_grid;
	PP_GRID		*pp_grid = &Pp_grid;

	debug_print("init_pp_grid","Entered set_pp_grid():\n");

	front->pp_grid = pp_grid;
	copy_rect_grid(&pp_grid->Global_grid,comp_glbgr);

	pp_grid->nn = 1;
	for (i = 0; i < dim; ++i)
	{
	    int	Gmax, Pmax, k;
	    int	basic_slices, extra_slices;

	    pp_grid->buf[i] = buffer_zones(init)[i];
	    Pmax = pp_grid->gmax[i] = subdomains(init)[i];
	    pp_grid->nn *= Pmax;

	    uni_array(&pp_grid->dom[i],Pmax + 1,FLOAT);

	    pp_grid->dom[i][0]    = comp_glbgr->L[i];
	    pp_grid->dom[i][Pmax] = comp_glbgr->U[i];
	    Gmax = comp_glbgr->gmax[i];

	    basic_slices = Gmax / Pmax;
	    extra_slices = Gmax % Pmax;

	    for (k = 1; k < Pmax; ++k)
	    {
	    	if (k < extra_slices)
	            pp_grid->dom[i][k] = k*(basic_slices + 1)*h[i]
	        			 + pp_grid->dom[i][0];
	        else
	            pp_grid->dom[i][k] = (k*basic_slices + extra_slices)*h[i]
	        			 + pp_grid->dom[i][0];
	    }
	}

	/* Clip rectangular grid to subdomain */

	GL = pp_grid->Global_grid.L;    GU = pp_grid->Global_grid.U;
	find_Cartesian_coordinates(myid,pp_grid,icoords);
	for (i = 0; i < dim; ++i)
	{
	    L[i] = pp_grid->dom[i][icoords[i]];
	    U[i] = pp_grid->dom[i][icoords[i] + 1];
	    gmax[i] = irint((U[i] - L[i])/h[i]);
	    switch (dim) /* TODO Unify 2 and 3 D */
	    {
	    case 1:
	    case 2:
	    	lbuf[i] = (icoords[i] > 0) ? pp_grid->buf[i] : 0;
	    	ubuf[i] =  (icoords[i]<(pp_grid->gmax[i]-1))?pp_grid->buf[i]:0;
	    	break;
	    case 3:
	    	lbuf[i] = pp_grid->buf[i];
	    	ubuf[i] = pp_grid->buf[i];
	    	break;
	    }
	}
	set_rect_grid(L,U,GL,GU,lbuf,ubuf,gmax,dim,&comp_glbgr->Remap,
		      &pp_grid->Zoom_grid);

	if (debugging("set_pp_grid"))
	{
	    print_PP_GRID_structure(pp_grid);
	}

	debug_print("init_pp_grid","Left set_pp_grid():\n");
}		/*end set_front_pp_grid*/
}}}
src/intfc/isub.c
{{{
EXPORT	void set_normal_of_tri(
	TRI	*tri)
{
	float *p[3];
	float *n;
	float **s, s0, s1, s2;
	int   i;

	if (tri_storage_type == MIN_TRI_STORAGE)
	    return;

	p[0] = Coords(Point_of_tri(tri)[0]);
	p[1] = Coords(Point_of_tri(tri)[1]);
	p[2] = Coords(Point_of_tri(tri)[2]);

	if (tri_storage_type == FULL_TRI_GEOMETRY)
	{
	    s = fg_side_vector(tri);
	    for (i = 0; i < 3; ++i)
	    {
	        s[i] = fg_sv_store(tri)[i];
	        s[i][0] = s0 = p[Next_m3(i)][0] - p[i][0];
	        s[i][1] = s1 = p[Next_m3(i)][1] - p[i][1];
	        s[i][2] = s2 = p[Next_m3(i)][2] - p[i][2];
	        fg_length_side(tri)[i] = sqrt(s0*s0 + s1*s1 + s2*s2);
	    }
	}
	else
	{
	    static float **sstore;
	    if (sstore == NULL)
		bi_array(&sstore,3,3,FLOAT);
	    s = sstore;
	    for (i = 0; i < 3; ++i)
	    {
	        s[i][0] = p[Next_m3(i)][0] - p[i][0];
	        s[i][1] = p[Next_m3(i)][1] - p[i][1];
	        s[i][2] = p[Next_m3(i)][2] - p[i][2];
	    }
	}

	n = Tri_normal_vector(tri);
	n[0] = s[2][1]*s[0][2] - s[2][2]*s[0][1];
	n[1] = s[2][2]*s[0][0] - s[2][0]*s[0][2];
	n[2] = s[2][0]*s[0][1] - s[2][1]*s[0][0];
	sqr_normal_vector(tri) = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
}		/*end set_normal_of_tri*/
}}}
src/intfc/iscatter.c
{{{
EXPORT	PP_GRID *set_pp_grid(
	INIT_DATA	*init,
	RECT_GRID       *comp_glbgr)
{
	double		L[MAXD], U[MAXD], *GL, *GU;
	double		*h = comp_glbgr->h;
	int		lbuf[MAXD], ubuf[MAXD];
	int		gmax[MAXD];
	int		icoords[MAXD];
	int		i, dim = comp_glbgr->dim;
	int		myid = pp_mynode();
	static PP_GRID	Pp_grid;
	PP_GRID		*pp_grid = &Pp_grid;
	char		s[1028];

	debug_print("init_pp_grid","Entered set_pp_grid():\n");

	copy_rect_grid(&pp_grid->Global_grid,comp_glbgr);

	pp_grid->nn = 1;
	for (i = 0; i < dim; ++i)
	{
	    int	Gmax, Pmax, k;
	    int	basic_slices, extra_slices;

	    pp_grid->buf[i] = buffer_zones(init)[i];
	    Pmax = pp_grid->gmax[i] = subdomains(init)[i];
	    pp_grid->nn *= Pmax;

	    uni_array(&pp_grid->dom[i],Pmax + 1,FLOAT);

	    pp_grid->dom[i][0]    = comp_glbgr->L[i];
	    pp_grid->dom[i][Pmax] = comp_glbgr->U[i];
	    Gmax = comp_glbgr->gmax[i];

	    basic_slices = Gmax / Pmax;
	    extra_slices = Gmax % Pmax;

	    for (k = 1; k < Pmax; ++k)
	    {
	    	if (k < extra_slices)
	            pp_grid->dom[i][k] = k*(basic_slices + 1)*h[i]
	        			 + pp_grid->dom[i][0];
	        else
	            pp_grid->dom[i][k] = (k*basic_slices + extra_slices)*h[i]
	        			 + pp_grid->dom[i][0];
	    }
	}

	/* Clip rectangular grid to subdomain */

	GL = pp_grid->Global_grid.L;    GU = pp_grid->Global_grid.U;
	find_Cartesian_coordinates(myid,pp_grid,icoords);
	for (i = 0; i < dim; ++i)
	{
	    L[i] = pp_grid->dom[i][icoords[i]];
	    U[i] = pp_grid->dom[i][icoords[i] + 1];
	    gmax[i] = irint((U[i] - L[i])/h[i]);
	    switch (dim) /* TODO Unify 2 and 3 D */
	    {
	    case 1:
	    case 2:
	    	lbuf[i] = (icoords[i] > 0) ? pp_grid->buf[i] : 0;
	    	ubuf[i] =  (icoords[i]<(pp_grid->gmax[i]-1))?pp_grid->buf[i]:0;
	    	break;
	    case 3:
	    	lbuf[i] = pp_grid->buf[i];
	    	ubuf[i] = pp_grid->buf[i];
	    	break;
	    }
	}
	set_rect_grid(L,U,GL,GU,lbuf,ubuf,gmax,dim,&comp_glbgr->Remap,
		      &pp_grid->Zoom_grid);

	if (debugging("init_pp_grid"))
	{
	    (void) printf("pp_grid after set_pp_grid()\n");
	    (void) print_PP_GRID_structure(pp_grid);
	}
	debug_print("init_pp_grid","Left i_set_pp_grid():\n");
	return pp_grid;
}		/*end set_pp_grid*/
}}}
src/intfc/igrid.c
{{{
EXPORT void set_rect_grid(
	const double *L,
	const double *U,
	const double *GL,
	const double *GU,
	const int   *lbuf,
	const int   *ubuf,
	const int   *gmax,
	int	    dim,
	const REMAP *remap,
	RECT_GRID *rect_grid)
{
	int i;
	int nobuf[3] = {0, 0, 0};

	if (rect_grid == NULL)
	    return;

	rect_grid->Remap = *remap;
	rect_grid->dim = dim;
	if (lbuf == NULL)
	    lbuf = nobuf;
	if (ubuf == NULL)
	    ubuf = nobuf;
	for (i = 0; i < dim; ++i)
	{
	    rect_grid->L[i] = L[i];
	    rect_grid->U[i] = U[i];
	    rect_grid->GL[i] = GL[i];
	    rect_grid->GU[i] = GU[i];
	    rect_grid->lbuf[i] = lbuf[i];
	    rect_grid->ubuf[i] = ubuf[i];
	    rect_grid->gmax[i] = gmax[i];
	    rect_grid->h[i] = (gmax[i] > 0) ? (U[i] - L[i])/gmax[i] : 0;
	    rect_grid->VL[i] = rect_grid->L[i] - lbuf[i]*rect_grid->h[i];
	    rect_grid->VU[i] = rect_grid->U[i] + ubuf[i]*rect_grid->h[i];
	    rect_grid->edges[i] = NULL;
	    rect_grid->centers[i] = NULL;
	    rect_grid->dh[i] = NULL;
	    rect_grid->variable_mesh[i] = NO;
	}
	rect_grid->glstore = NULL;
	rect_grid->Remap.area = area_of_rect_grid(rect_grid);
}		/*end set_rect_grid*/
}}}
src/intfc/igrid.c
{{{
EXPORT	void	set_remap(
	int	        dim,
	GEOMETRY_REMAP	remap_type,
	REMAP           *remap)
{
	remap->remap = remap_type;
	switch (remap_type) 
	{
	case IDENTITY_REMAP:
	    remap->remap_name = "IDENTITY_REMAP";
	    remap->dnm[0] = "x";
	    remap->dnm[1] = "y";
	    remap->dnm[2] = "z";
	    remap->Dnm[0] = "X";
	    remap->Dnm[1] = "Y";
	    remap->Dnm[2] = "Z";
	    remap->dirs[0] = "x";
	    remap->dirs[1] = "x & y";
	    remap->dirs[2] = "x, y, & z";
	    switch (dim)
	    {
	    case 1:
	    	remap->Area = ident_Length;
	    	break;
	    case 2:
	    	remap->Area = ident_Area;
	    	break;
	    case 3:
	    	remap->Area = ident_Volume;
	    	break;
	    }
	    break;
	case CYLINDRICAL_REMAP:
	    remap->remap_name = "CYLINDRICAL_REMAP";
	    remap->dnm[0] = "radial";
	    remap->dnm[1] = "vertical";
	    remap->dnm[2] = "angular";
	    remap->Dnm[0] = "R";
	    remap->Dnm[1] = "Z";
	    remap->Dnm[2] = "theta";
	    remap->dirs[0] = "r";
	    remap->dirs[1] = "r & z";
	    remap->dirs[2] = "r, z, & theta";
	    switch (dim)
	    {
	    case 1:
	    	remap->Area = cylin_Area;
	    	break;
	    case 2:
	    	remap->Area = cylin_Volume;
	    	break;
	    }
	    break;
	case SPHERICAL_REMAP:
	    remap->remap_name = "SPHERICAL_REMAP";
	    remap->dnm[0] = "radial";
	    remap->dnm[1] = "longitudinal";
	    remap->dnm[2] = "latitudinal";
	    remap->Dnm[0] = "R";
	    remap->Dnm[1] = "theta";
	    remap->Dnm[2] = "phi";
	    remap->dirs[0] = "r";
	    remap->dirs[1] = "r & theta";
	    remap->dirs[2] = "r, theta, & phi";
	    remap->Area = spherical_Volume;
	    break;
	default:
	    remap->remap_name = "INVALID_REMAP";
	    screen("ERROR in set_remap(), "
	           "illegal or unavailable geometry\n");
	    clean_up(ERROR);
	}
}		/*end set_remap*/
}}}
src/intfc/igrid.c
{{{
EXPORT	void set_remap_and_rect_grid(
	double *L,
	double *U,
	int *gmax,
	GEOMETRY_REMAP geom_remap,
	RECT_GRID *r_grid)
{
	int		  i, dim = r_grid->dim;

	set_remap(dim,geom_remap,&Remap);

	for (i = 0; i < dim; ++i)
	{
	    r_grid->L[i] = L[i];
	    r_grid->U[i] = U[i];
	    r_grid->gmax[i] = gmax[i];
	    r_grid->h[i] = (U[i] - L[i]) / gmax[i];
	}

	/* Set Default values for subdomain specifications */
	/* correct for scalar runs */
	set_rect_grid(L,U,L,U,NOBUF,NOBUF,r_grid->gmax,dim,&Remap,r_grid);
	Remap.area = r_grid->Remap.area;
}		/*end i_init_remap_and_rect_grid*/
}}}
src/intfc/comp.c
{{{
/*
*			set_topological_grid():
*
*	Sets the underlying topological rectangular grid for an INTERFACE.
*	If grid is NULL, chooses  the smallest rectangle which
*	contains all POINTS in INTERFACE and then imposes a
*	regular DEFAULT_GMAX by DEFAULT_GMAX by DEFAULT_GMAX grid
*	on this rectangle.
*/


EXPORT void set_topological_grid(
	INTERFACE *intfc,
	RECT_GRID *input_grid)
{
	enum { DEFAULT_GMAX = 20 };
	HYPER_SURF	*hs;
	HYPER_SURF_ELEMENT *hse;
	POINT		*p;
	RECT_GRID	*top_grid = &topological_grid(intfc);
	double		*L, *U;
	int		dim = intfc->dim;
	int		i;
	static int	dgmax[3] = {DEFAULT_GMAX, DEFAULT_GMAX, DEFAULT_GMAX};

	if (DEBUG)
	    (void) printf("\n\nEntered set_topological_grid()\n");
	intfc->table->new_grid = YES;
	if (input_grid != NULL)
	{
	    copy_rect_grid(top_grid,input_grid);
	    intfc->table->fixed_grid = YES;
	    if (DEBUG)
		(void) printf("Left set_topological_grid()\n\n");
	    return;
	}
	else
	    intfc->table->fixed_grid = NO;

			/* Find Rectangle Containing INTERFACE: */
	L = top_grid->L;
	U = top_grid->U;
	for (i = 0; i < dim; ++i)
	{
	    L[i] = HUGE_VAL;
	    U[i] = -HUGE_VAL;
	}

	(void) next_point(intfc,NULL,NULL,NULL);
	while (next_point(intfc,&p,&hse,&hs))
	{
	    for (i = 0; i < dim; ++i)
	    {
	    	L[i] = min(L[i],Coords(p)[i]);
	    	U[i] = max(U[i],Coords(p)[i]);
	    }
	}


	if (DEBUG) 
	{
	    (void) printf("Rectsolid: ");
	    print_general_vector("L = ",L,dim,"");
	    print_general_vector("U = ",L,dim,"\n");
	}

	set_rect_grid(L,U,L,U,NOBUF,NOBUF,dgmax,dim,remap_info(),top_grid);

	if (DEBUG)
	    (void) printf("Left set_topological_grid()\n\n");
	return;
}		/*end set_toplogical_grid*/
}}}
src/front/fprint.c
{{{
EXPORT  void show_front_output(
        Front *front,
        char *out_name,
	bool print_in_binary) 
{   
        char dirname[256];
        int step = front->step; 
        int dim = front->rect_grid->dim;
	bool print_vtk = YES;
	char label[100];
	static bool first = YES;

        sprintf(dirname,"%s-vtk.ts%s",out_name,right_flush(step,7));
	if (pp_numnodes() > 1)
            sprintf(dirname,"%s-nd%s",dirname,right_flush(pp_mynode(),4));

        if (dim == 2)
        {
#if defined(__GD__)
	    FrontGDMovie(out_name,front);
#endif /* defined(__GD__) */
#if defined(USE_HDF)
	    hdf_plot_comp2d(front,out_name,first);
	    if (front->hdf_movie_var != NULL)
	    {
		HDF_MOVIE_VAR *hdf_movie_var = front->hdf_movie_var;
		int i,num_var = hdf_movie_var->num_var;
		for (i = 0; i < num_var; ++i)
		{
	    	    hdf_plot_var2d(front,out_name,hdf_movie_var->var_name[i],
				hdf_movie_var->top_var[i],
				hdf_movie_var->obstacle_comp[i],
				hdf_movie_var->get_state_var[i],first);
		}
	    }
	    print_vtk = NO;
#endif /* defined(USE_HDF) */
	    if (print_vtk)
        	vtk_interface_plot(dirname,front->interf,print_in_binary,
					front->time,front->step);
        }
	else if (dim == 3)
	{
#if defined(USE_HDF)
	    hdf_plot_comp3d(front,out_name,first);
	    if (front->hdf_movie_var != NULL)
	    {
		HDF_MOVIE_VAR *hdf_movie_var = front->hdf_movie_var;
		int i,num_var = hdf_movie_var->num_var;
		for (i = 0; i < num_var; ++i)
		{
	    	    hdf_plot_var3d(front,out_name,hdf_movie_var->var_name[i],
				hdf_movie_var->top_var[i],
				hdf_movie_var->obstacle_comp[i],
				hdf_movie_var->get_state_var[i],
				hdf_movie_var->idir[i],first);
		}
	    }
#endif /* defined(USE_HDF) */
            vtk_interface_plot(dirname,front->interf,print_in_binary,
					front->time,front->step);
	    if (front->print_sdl_file)
	    {
        	sprintf(dirname,"%s-sdl.ts%s",out_name,right_flush(step,7));
	    	sdl_interface_plot(dirname,front->interf);
	    }
	}
	first = NO;
}       /* end show_front_output */
}}}
[[An old version of FronTier source code Structure|http://frontier.ams.sunysb.edu/shock_hmpg/FTdoc/general/FTstructure.html]]
!!!front
----
Header file
[[front/fdecs.h]] Contains declarations of variables related to the front
[[front/frp.h]] Contains structures related to the solution of two dimensional Riemann problems.
[[front/fvelo.h]] Contains structures related to velocity functions
[[front/fuserint.h]]  User Supplied Operations
[[front/fprotos.h]]  Function prototype declarations for front directory
----
Source file

!!!intfc
----
Header file
[[intfc/int.h]] Defines the interface and related structures, such as [[POINT]], [[NODE]], [[BOND]]
[[intfc/geom.h]] This header file defines the dimension, remap type, [[RECT_GRID]] 
[[intfc/table.h]] Defines the [[TABLE]] structure used in [[INTERFACE]]
[[intfc/userint.h]] Defines User Supplied Operations, all kinds of function pointers
[[intfc/iprotos.h]] Defines function prototypes related to [[intfc]]
[[intfc/int_amr.h]] Defines [[PATCH_BDRY_FLAG]] structure
[[intfc/triangledefs.h]]  Include file for programs that call Triangle.    Accompanies Triangle Version 1.3   
[[intfc/array.h]] Defines the pointers queue
[[intfc/iloc.h]] Defines INTERFACE_ADDRESSES
[[intfc/ilocprotos.h]] Function Declarations Internal to Interface
----
Source file
----
[[testintfc.c]]
!!!util
[[util/cdecs.h]] Useful Extensions to C language
[[util/vmalloc]] Definitions for Storage Allocators
[[util/fnamedebug.h]] Defines some macros for debugging
[[util/uprotos.h]] Function prototypes for util libarary
[[util/navdecs.h]] Navigator code written by John D. Pinezich, 1999.
[[util/plotdecs.h]] MACRO DEFINITIONS FOR SIG, AN INTERMEDIATE PLOT LANGUAGE

src/front/fdecs.h
{{{
	void (*surface_propagate)(struct _Front*,struct _Front*,POINTER,
				float,float*);
}}}
src/front/fredist3d.c
{{{
/*
* 		surface_redistribute()
*
* 	The choice of name surface_redistribute() clashes in an obvious 
* 	way with the name redistribute_surface().  
*/


EXPORT bool surface_redistribute(
	Front		*fr,
	bool		*force_redist)
{
	SURFACE		**s;
	CURVE		**c;
	bool		status, min_status;
	bool		redist_non_vec_cur, redist_vec_cur;

	DEBUG_ENTER(surface_redistribute)

		// Check on redistribution conditions

	if (*force_redist)
	{
	    redist_non_vec_cur = redist_vec_cur = YES;
	    *force_redist = NO;
	}
	else if (Redistribution_count(fr) < 0)
	{
	    redist_non_vec_cur = redist_vec_cur = NO;
	}
	else
	{
	    redist_vec_cur = redist_needed(fr,VECTOR_WAVE);
	    redist_non_vec_cur = redist_needed(fr,GENERAL_WAVE);
	}
	++Redistribution_count(fr);

		// Redistribute vector surfaces
	
	set_size_of_intfc_state(size_of_state(fr->interf));
	set_copy_intfc_states(YES);
	set_current_interface(fr->interf);

	status = YES;
	if (redist_vec_cur == YES)
	{
	    for (s = fr->interf->surfaces; s && *s ; ++s) 
	    {
	    	if ((!omit_redistribution(*s)) &&
		    (wave_type(*s) >= FIRST_VECTOR_PHYSICS_WAVE_TYPE))
	    	    if (!redistribute_surface(*s,fr))
			status = NO;
	    }
	}
	
	//DEBUG_TMP check_print_intfc("Before redistribute_surface", "redist_sf_bf", 'g', 
			//DEBUG_TMP fr->interf, fr->step, -1, NO);
	make_interface_topology_lists(fr->interf);
	//DEBUG_TMP check_valid_intfc("before redistribute_surface", fr->interf);
	
	if (redist_non_vec_cur == YES)
	{
	    //printf("#redist curve3d bf\n");
	    //for (c = fr->interf->curves; c && *c; ++c)
	    //{
		//if (hsbdry_type(*c) != SUBDOMAIN_HSBDRY)
		//redistribute_curve3d(*c,fr);
	    //}

	    //DEBUG_TMP printf("#redist surface bf\n");
	    for (s = fr->interf->surfaces; s && *s ; ++s) 
	    {
	    	if ((!omit_redistribution(*s)) &&
	    	    (wave_type(*s) >= FIRST_PHYSICS_WAVE_TYPE) &&
	    	    (wave_type(*s) < FIRST_VECTOR_PHYSICS_WAVE_TYPE))
		{
		    start_clock("redistribute_surface");
		    if (!redistribute_surface(*s,fr))
			status = NO;
		    stop_clock("redistribute_surface");
		}
	    }
	}
	
	//DEBUG_TMP check_print_intfc("After redistribute_surface", "redist_sf_af", 'g', 
			//DEBUG_TMP fr->interf, fr->step, -1, NO);
	make_interface_topology_lists(fr->interf);
	//DEBUG_TMP check_valid_intfc("after redistribute_surface", fr->interf);

	//insert_point_in_tri_side fails or delete_min_side_of_tri fails.
	if(status == NO)
	{
	    printf("WARNING after #surface_redistribute, i"
	    	   "status is NO in step %d\n", fr->step);
	}
	min_status = pp_min_status(status);
	if (min_status == NO)
	{
	    (void) printf("WARNING in surface_redistribute(), "
		          "redistribute_surface(), failed\n");
	    DEBUG_LEAVE(surface_redistribute)
	    return min_status;
	}

	start_clock("scatter_front");
	status = scatter_front(fr);
	stop_clock("scatter_front");
	
	if (!status)
	{
	    (void) printf("WARNING in surface_redistribute(), "
	    	          "scatter_front() failed\n");
	    DEBUG_LEAVE(surface_redistribute)
	    return status;
	}

	set_current_interface(fr->interf);

	Interface_redistributed(fr) =
	    ((redist_vec_cur==YES) || (redist_non_vec_cur==YES)) ? YES : NO;

	DEBUG_LEAVE(surface_redistribute)
	return status;
}		/*end surface_redistribute*/
}}}
example3d/example.c
{{{
static int test_curvature_vel(
        POINTER params,
        Front *front,
        POINT *p,
        HYPER_SURF_ELEMENT *hse,
        HYPER_SURF *hs,
        double *vel)
{
	TEST_CURV_PARAMS *curv_params = (TEST_CURV_PARAMS*) params;
        int i;
        double coeff,epsilon,eps;
        double kappa;
        double nor[MAXD];

        coeff = curv_params->coeff;
        epsilon = curv_params->epsilon;

        normal(p,hse,hs,nor,front);
        kappa = fabs(mean_curvature_at_point(p,hse,hs,front));

        for (i = 0; i < curv_params->dim; ++i)
        {
            vel[i] = nor[i]*(coeff - epsilon*kappa);
        }
}
}}}
src/front/fgb3d.c
{{{
LOCAL	bool track_comp_and_repair3d(
	int		*smin,
	int		*smax,
        int		*gmax,
        INTERFACE	*intfc,
	Front		*fr)
{
	int		num_ip, i;
	RECT_BOX 	*boxes, *pb;
	static int 	**ips = NULL;

	DEBUG_ENTER(track_comp_and_repair3d)

	if(ips == NULL)
	    stat_matrix(&ips,MAX_NUM_UNPHY_IP,3,INT);

	// see function track_comp_through_crxings3d
	
	adjust_crossings(smin,smax,intfc);
	fill_physical_comps(smin,smax,gmax,intfc);

	//print_edge_crossings(smin, smax, intfc);
	
	fill_comp_with_component3d(smin,smax,gmax,intfc);

	//DEBUG_TMP if(fr->step == -1)
	//DEBUG_TMP {
	    //DEBUG_TMP int  tmin[3] = {12,10,41}, tmax[3] = {14,13,43};
	    //DEBUG_TMP if(pp_mynode() == 8)
	    //DEBUG_TMP {
		//DEBUG_TMP tmin[2] -= 40;
		//DEBUG_TMP tmax[2] -= 40;
	    //DEBUG_TMP }
	    //DEBUG_TMP printf("#check comp physical\n");
	    //DEBUG_TMP show_grid_components(tmin,tmax,0,intfc);
	    //DEBUG_TMP show_grid_components(tmin,tmax,1,intfc);
	    //DEBUG_TMP show_grid_components(tmin,tmax,2,intfc);
	    //DEBUG_TMP print_edge_crossings(smin, smax, intfc);
	//DEBUG_TMP }

	// record all unphysical ip's
	num_ip = record_unphysical_ips(smin,smax,intfc,ips);
	//DEBUG_TMP printf("#num_ip  %d\n", num_ip);

	// tst lgb
	if(num_ip == 0)
	{
	    DEBUG_LEAVE(track_comp_and_repair3d)
	    return FUNCTION_SUCCEEDED;
	}
	
	fr->redis_flag = YES;

	
	//DEBUG_TMP add_time_clear(1);
	//DEBUG_TMP add_time_start(1);

	//make the boxes for lgb reconstruction.
	if(!set_reconstruction_boxes(smin,smax,ips,num_ip,&boxes,intfc))
	{
	    DEBUG_LEAVE(track_comp_and_repair3d)
	    return FUNCTION_FAILED;
	}
	

	//remove crxs considering boxes and ips
	rm_bad_crxs_in_box(smin,smax,ips,num_ip,boxes,intfc);
	
	//DEBUG_TMP add_time_end(1);
	//DEBUG_TMP printf("#run time set_rec  %15.8f\n", add_time_get(1));

	// tst lgb
	//DEBUG_TMP print_int_vector("#smin=", smin, 3, "\n");
	//DEBUG_TMP print_int_vector("#smax=", smax, 3, "\n");

	//DEBUG_TMP if(NO)
	//DEBUG_TMP { // tst lgb part.
	//DEBUG_TMP if(!set_tst_recon_boxes(smin, smax, &boxes, intfc))
	//DEBUG_TMP {
	    //DEBUG_TMP DEBUG_LEAVE(track_comp_and_repair3d)
	    //DEBUG_TMP return FUNCTION_SUCCEEDED;
	//DEBUG_TMP }
	//DEBUG_TMP printf("#set_tst finish.\n");
	//DEBUG_TMP fflush(NULL);
	//DEBUG_TMP }

	set_current_interface(intfc);

	if (num_ip != 0 && NO)
	{
	    char	bname[50];
	    FILE	*fp;

	    sprintf(bname, "box_%d.plt", pp_mynode());
	    fp = fopen(bname, "w");
	    for (pb = boxes; pb != NULL; pb = pb->next)
	    	tecplot_show_box(bname, pb, fp);
	    fclose(fp);
	}

	//DEBUG_TMP printf("#list all boxes %d\n", fr->step);
	//DEBUG_TMP i = 0;
	//DEBUG_TMP for (pb = boxes; pb != NULL; pb = pb->next)
	//DEBUG_TMP {
	    //DEBUG_TMP i++;
	    //DEBUG_TMP printf("bmin = %-2d  %-2d  %-2d\n",pb->bmin[0],
	    	//DEBUG_TMP pb->bmin[1],pb->bmin[2]);
	    //DEBUG_TMP printf("bmax = %-2d  %-2d  %-2d\n",pb->bmax[0],
	    	//DEBUG_TMP pb->bmax[1],pb->bmax[2]);
	//DEBUG_TMP }
	//DEBUG_TMP printf("#total number of box(%d)=% d\n", fr->step, i);
	
	//DEBUG_TMP add_time_clear(2);
	//DEBUG_TMP add_time_start(2);
	box_index = 0;
	
	//DEBUG_TMP check_normal_on_intfc(intfc);
	for (pb = boxes; pb != NULL; pb = pb->next)
	{
	    if(NO)
	    {
		pb->bmin[0] = 24;
		pb->bmin[1] = 24;
		pb->bmin[2] = 42;
		pb->bmax[0] = 27;
		pb->bmax[1] = 27;
		pb->bmax[2] = 44;
	    }
    
	    //DEBUG_TMP printf("#untangle box_index = %d\n", box_index);
	    //DEBUG_TMP printf("bmin = %-2d  %-2d  %-2d\n",pb->bmin[0],
	    	//DEBUG_TMP pb->bmin[1],pb->bmin[2]);
	    //DEBUG_TMP printf("bmax = %-2d  %-2d  %-2d\n",pb->bmax[0],
	    	//DEBUG_TMP pb->bmax[1],pb->bmax[2]);

	    if (!grid_based_box_untangle(intfc,pb))
	    {
	    	printf("WARNING, track_comp_and_repair3d, "
		       "grid_based_box_untangle fails. \n");
		DEBUG_LEAVE(track_comp_and_repair3d)
		return FUNCTION_FAILED;
	    }
	    
	    
	    box_index++;
	}
	//DEBUG_TMP check_normal_on_intfc(intfc);
	
	//DEBUG_TMP add_time_end(2);
	//DEBUG_TMP printf("#run time grid_based  %15.8f\n", add_time_get(2));

	if (debugging("box_intfc"))
	{
	    if (consistent_interface(intfc))
	    {
	    	(void) printf("After untangle, interface is consistent!\n");
	    }
	}

	DEBUG_LEAVE(track_comp_and_repair3d)
	return FUNCTION_SUCCEEDED;

}	/* end track_comp_and_repair3d */
}}}
src/front/fredist3d.c
{{{
/*
*				tri_status():
*
*	Determines whether redistribution of a triangle is needed by
*	comparing the triangles normalized area with two tolerances.
*	In addition, this routine also checks the squared edge lengths and
*	determines their aspect ratios.
*	This routine has the following return values:
*
*	if (norm_area > max_sqr_area) return LARGE;
*	if (norm_area < min_sqr_area) return SMALL;
*	if (aspect ratio < aspect_tol) return BAD_ANGLE;
*	return GOOD_ANGLE;
*
*	The aspect ratio of a triangle is defined as A/(l0^2+l1^2+l2^2)
*	where A is the area of the triangle in the grid scaled metric
*	and the li are the lengths of the sides of the triangle in
*	grid scaled metric.
*/

LOCAL	TRI_STATUS tri_status(
	TRI *tri,
	RECT_GRID *gr)
{
	float	*p0 = Coords(Point_of_tri(tri)[0]);
	float	*p1 = Coords(Point_of_tri(tri)[1]);
	float	*p2 = Coords(Point_of_tri(tri)[2]);
	float	s00, s01, s02;
	float	s10, s11, s12;
	float	s20, s21, s22;
	float	N0, N1, N2;
	float	h0 = gr->h[0], h1 = gr->h[1], h2 = gr->h[2];
	float	sqr_area;
	float	a2,len[3],tri_area;
	const float *nor = Tri_normal(tri);

	sqr_area = 0.25*Dot3d(nor,nor); 
	if (sqr_area <= min_sqr_area)
	    return SMALL;

	s00 = (p1[0]-p0[0])/h0; s01 = (p1[1]-p0[1])/h1; s02 = (p1[2]-p0[2])/h2;
	s10 = (p2[0]-p1[0])/h0; s11 = (p2[1]-p1[1])/h1; s12 = (p2[2]-p1[2])/h2;
	s20 = (p0[0]-p2[0])/h0; s21 = (p0[1]-p2[1])/h1; s22 = (p0[2]-p2[2])/h2;
	QCross3d(s0,s2,N);

	tri_area = 0.5*sqrt(QDot3d(N,N));

			/* Check aspect ratio	*/
	len[0] = QDot3d(s0,s0);
	len[1] = QDot3d(s1,s1);
	len[2] = QDot3d(s2,s2);

	a2 = len[0]+len[1]+len[2];
	a2 = tri_area/sqr(a2);
	if (a2 < aspect_tol2)
	    return BAD_ANGLE;

	if ((len[0] > max_sqr_length) || (len[1] > max_sqr_length) ||
	    (len[2] > max_sqr_length))
	    return LARGE;

	if (sqr_area >= max_sqr_area)
	    return LARGE;
	return GOOD_ANGLE;
}		/*end tri_status*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	void user_fprint_curve(
	FILE		*file,
	CURVE		*c)
{
	if (c == NULL || c->interface == NULL)
	    return;
	(*i_user_interface(c->interface)._user_fprint_curve)(file,c);
}		/*end user_fprint_curve*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	void user_fprint_interface(
	FILE		*file,
	INTERFACE	*intfc)
{
	if (intfc == NULL)
	    return;
	(*i_user_interface(intfc)._user_fprint_interface)(file,intfc);
}		/*end user_fprint_interface*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	void user_fprint_surface(
	FILE		*file,
	SURFACE		*s)
{
	if (s == NULL || s->interface == NULL)
	    return;
	(*i_user_interface(s->interface)._user_fprint_surface)(file,s);
}		/*end user_fprint_surface*/
}}}
src/intfc/userhooks.c
{{{
EXPORT	void user_make_interface(
	INTERFACE	*intfc)
{
	if (intfc == NULL)
	    return;
	(*i_user_interface(intfc)._user_make_interface)(intfc);
}		/*end user_make_interface*/
}}}
include
|[[util/uprotos.h]]|[[util/fnamedebug.h]]|
Useful Extensions to C language
include 
|[[util/cdecs.h]]|[[util/navdecs.h]]|
Defines some macros for debugging
include 
|[[util/cdecs.h]]|
Navigator code written by John D. Pinezich, 1999.
include 
|[[util/cdecs.h]]|
MACRO DEFINITIONS FOR SIG, AN INTERMEDIATE PLOT LANGUAGE
include
|[[util/cdecs.h]]|
Function prototypes for util libarary
include
|[[util/cdecs.h]]|
Definitions for Storage Allocators
{{{
int  (*vfunc)(POINTER,struct _Front*,POINT*,HYPER_SURF_ELEMENT*,
				HYPER_SURF*,float*); /* analytical velo func */
}}}
src/intfc/igview.c
{{{
EXPORT void vtk_interface_plot(
	const char *dname,
	INTERFACE  *intfc,
	bool print_in_binary,
	double time,
	int step)
{
	double *BBL = topological_grid(intfc).GL;
	double *BBU = topological_grid(intfc).GU;

	if (create_directory(dname,YES) == FUNCTION_FAILED)
	{
	    (void) printf("WARNING in vtk_interface_plot(), directory "
			  "%s doesn't exist and can't be created\n",dname);
	    return;
	}

	if (intfc->dim == 2)
	vtk_plot_curves(intfc,BBL, BBU,dname,"2d-intfc", pRED, 10, print_in_binary,time,step);

	if (intfc->dim == 3)
	{
	vtk_plot_surfaces(intfc,BBL,BBU,NO,dname,"3d-intfc",NO,pRED,pRED,print_in_binary,time,step);
	vtk_print_box(dname,BBL,BBU,print_in_binary);
	}

}		/*end vtk_interface_plot*/
}}}
src/intfc/igview.c
{{{
LOCAL   void    vtk_plot_curves(
        INTERFACE     *intfc,
	const double   *BBL,
	const double   *BBU,
        const char    *dname,
        const char    *name,
	SURFACE_COLOR color,
	int	      width,
	bool  	      print_in_binary,
	double 	      time,
	int 	      step)
{
        FILE              *file;
        POINT             *ps, *pe;
        CURVE             **c;
        BOND              *b;
        static const char *indent = "    ";
        int               num_bonds,i,first,second;
	static char       *fname = NULL;
	static size_t     fname_len = 0;
	int		  tot_num_pnts,tot_num_bonds; 
	char str[100];
	int ivals[1];
	int length, length2;

	fname = get_vtk_file_name(fname,dname,name,&fname_len);

	tot_num_pnts = 0;
	for (c = intfc->curves; c && *c; ++c)
	{
            if (is_subdomain_boundary(Hyper_surf(*c)))continue;
            tot_num_pnts = tot_num_pnts+(*c)->num_points;
	}
	if(print_in_binary)
	{
	    if ((file = fopen(fname,"wb")) == NULL)
            {
                screen("WARNING in vtk_plot_curves(), "
                       "can't open %s\n",fname);
                return;
	    }
	    sprintf(str,"# vtk DataFile Version 3.0\n");
	    fwrite(str, sizeof(char), 27, file);
	    sprintf(str,"FronTier Interface\n");
	    fwrite(str, sizeof(char), 19, file);
	    sprintf(str,"BINARY\n");
	    fwrite(str, sizeof(char), 7, file);
	    sprintf(str, "DATASET POLYDATA\n");
    	    fwrite(str, sizeof(char), 17, file);

	    sprintf(str, "FIELD FieldData 2\n");
            fwrite(str, sizeof(char), 18, file);
	    sprintf(str, "TIME 1 1 float\n");
            fwrite(str, sizeof(char), 15, file);

	    float value1[1];
	    float tmp1 = time;
            if(hardware_is_little_endian())
	        value1[0] = endian_float_swap(tmp1);
            else
		value1[0] = tmp1;
	    fwrite(value1, sizeof(float), 1, file);

	    sprintf(str, "\n");
            fwrite(str, sizeof(char), 1, file);
	    sprintf(str, "CYCLE 1 1 int\n");
            fwrite(str, sizeof(char), 14, file);
	    #if defined(int)
            #undef int
            #define not_int
            #endif
	    int value2[1];
	    int tmp2 = step;
            if(hardware_is_little_endian())
	        value2[0] = endian_int_swap(tmp2);
            else
		value2[0] = tmp2;
	    fwrite(value2, sizeof(int), 1, file);
	    #if defined(not_int)
	    #define int double
     	    #undef not_int
	    #endif
	    sprintf(str, "\n");
            fwrite(str, sizeof(char), 1, file);

	    sprintf(str, "POINTS %d float\n",tot_num_pnts);
	    length = count_digits(tot_num_pnts);
	    fwrite(str, sizeof(char), 14 + length, file);

	    tot_num_bonds = 0;
            for (c = intfc->curves; c && *c; ++c)
            {
                if (is_subdomain_boundary(Hyper_surf(*c)))continue;
                tot_num_bonds = tot_num_bonds+(*c)->num_points - 1;
		
		for (b = (*c)->first; b; b = b->next)
                {
                    ps = b->start;
                    pe = b->end;
                    float vals[1];
 
		    if(hardware_is_little_endian())
		    	vals[0] = endian_float_swap(Coords(ps)[0]);
		    else
			vals[0] = Coords(ps)[0];
		    fwrite(vals, sizeof(float), 1, file);
		    if(hardware_is_little_endian())
			vals[0] = endian_float_swap(Coords(ps)[1]);
		    else
		        vals[0] = Coords(ps)[1];
                    fwrite(vals, sizeof(float), 1, file);
		    if(hardware_is_little_endian())
		        vals[0] = endian_float_swap(0.0);
		    else
			vals[0] = 0.0;
                    fwrite(vals, sizeof(float), 1, file);
                }
		
                float vals[1];

                if(hardware_is_little_endian())
 		    vals[0] = endian_float_swap(Coords(pe)[0]);
		else
		    vals[0] = Coords(pe)[0];
		fwrite(vals, sizeof(float), 1, file);
                if(hardware_is_little_endian())
                    vals[0] = endian_float_swap(Coords(pe)[1]);
                else
                    vals[0] = Coords(pe)[1];
                fwrite(vals, sizeof(float), 1, file);
                if(hardware_is_little_endian())
                    vals[0] = endian_float_swap(0.0);
                else
                    vals[0] = 0.0;
                fwrite(vals, sizeof(float), 1, file);	
	    }
	    sprintf(str, "\nLINES %i %i\n", tot_num_bonds,tot_num_bonds*3);
	    length = count_digits(tot_num_bonds);
	    length2 = count_digits(tot_num_bonds*3);
	    fwrite(str, sizeof(char), 9 + length + length2, file);
	 
	    first = 0;
            second = 1;
            for (c = intfc->curves; c && *c; ++c)
            {
                if (is_subdomain_boundary(Hyper_surf(*c)))continue;
                for (b = (*c)->first; b; b = b->next)
                {
		    if(hardware_is_little_endian())
		        ivals[0] = endian_int_swap(2);
		    else
			ivals[0] = 2;
		    fwrite(ivals, sizeof(int), 1, file);
		    if(hardware_is_little_endian())
                        ivals[0] = endian_int_swap(first);
                    else
                        ivals[0] = first;
                    fwrite(ivals, sizeof(int), 1, file);
                    if(hardware_is_little_endian())
                        ivals[0] = endian_int_swap(second);
                    else
                        ivals[0] = second;
                    fwrite(ivals, sizeof(int), 1, file);
			
                    first++;
                    second++;
                }
                first++;
                second++;
	    }	
        }
	else
	{	
	    if ((file = fopen(fname,"w")) == NULL)
            {
             	screen("WARNING in vtk_plot_curves(), "
                        "can't open %s\n",fname);
                return;
            }

	    (void) fprintf(file,"# vtk DataFile Version 3.0 \n"
		                "FronTier Interface \n"
		       	        "ASCII \n"
			        "DATASET POLYDATA \n");
	    (void) fprintf(file, "FIELD FieldData 2\n");
	    (void) fprintf(file, "TIME 1 1 float\n");
	    (void) fprintf(file, "%5.5e\n", time);
	    (void) fprintf(file, "CYCLE 1 1 int\n");
	    (void) fprintf(file, "%d\n", step);
	    (void) fprintf(file, "POINTS %d double\n",tot_num_pnts);
	
	    tot_num_bonds = 0;
            for (c = intfc->curves; c && *c; ++c)
            {
                if (is_subdomain_boundary(Hyper_surf(*c)))continue;
	        tot_num_bonds = tot_num_bonds+(*c)->num_points - 1;
                for (b = (*c)->first; b; b = b->next)
                {
                    ps = b->start;
                    pe = b->end;
                    (void) fprintf(file,"%-9g %-9g 0.0\n",
			       Coords(ps)[0], Coords(ps)[1]);
            	}
                (void) fprintf(file,"%-9g %-9g 0.0\n",
			       Coords(pe)[0],Coords(pe)[1]);
            }
	    fprintf(file,"LINES %i %i \n",tot_num_bonds,tot_num_bonds*3);
	    first=0;
	    second=1;
            for (c = intfc->curves; c && *c; ++c)
            {
                if (is_subdomain_boundary(Hyper_surf(*c)))continue;
                for (b = (*c)->first; b; b = b->next)
                {
                    (void) fprintf(file,"2 %i %i \n",first,second);
		    first++;
		    second++;
                }
	        first++;
	        second++;
            }
	}
        fclose(file);
}               /*end vtk_plot_curves*/
}}}
src/intfc/igview.c
{{{
LOCAL	void	vtk_plot_surfaces(
	INTERFACE     *intfc,
	const double   *BBL,
	const double   *BBU,
	bool          clip,
	const char    *dname,
	const char    *name,
	bool	      bdry,
	SURFACE_COLOR color1,
	SURFACE_COLOR color2,
	bool 	      print_in_binary,
	double 	      time,
	int 	      step)
{
	FILE	          *file;
	POINT             *p;
	SURFACE	          **s;
	TRI	          *tri;
	bool              plot_surf;
	double 	          D, intensity = .5;
	double             L[MAXD],U[MAXD],tol[MAXD];
	double	          *crds;
	int	          num_surfs, num_tris, i, j, k, l;
	int               npts, ntris;
	int		  length, length2;
	static const char *indent = "    ";
	static double      *pts = NULL;
	static int        *verts = NULL;
	static int        alloc_len_verts = 0, alloc_len_pts = 0;
	static char       *fname = NULL;
	char 		  str[100];
	static size_t     fname_len = 0;
	RECT_GRID *gr = &topological_grid(intfc);
	
	fname = get_vtk_file_name(fname,dname,name,&fname_len);

	for (num_tris = 0, s = intfc->surfaces; s && *s; ++s)
	{
	    num_tris += (*s)->num_tri;
	    for (tri=first_tri(*s); !at_end_of_tri_list(tri,*s); tri=tri->next)
	    {
	        for (k = 0; k < 3; ++k)
		    Index_of_point(Point_of_tri(tri)[k]) = -1;
	    }
	}
	
	if (alloc_len_pts < 3*intfc->num_points)
	{
	    if (pts != NULL)
		free(pts);
	    alloc_len_pts = 3*intfc->num_points;
	    uni_array(&pts,alloc_len_pts,FLOAT);
	}
	if (alloc_len_verts < 4*num_tris)
	{
	    if (verts != NULL)
		free(verts);
	    alloc_len_verts = 4*num_tris;
	    uni_array(&verts,alloc_len_verts,INT);
	}
	for (i = 0; i < 3; i++)
	{
	    L[i] = gr->L[i] - 0.5*gr->h[i]; 
	    U[i] = gr->U[i] + 0.5*gr->h[i];
	    tol[i] = 0.00001*gr->h[i];
	}

        for (npts=0, ntris=0, num_surfs=0, s = intfc->surfaces; s && *s; ++s)
	{
	    if (bdry == YES  &&  !Boundary(*s))
		continue; 
	    if (bdry == NO  &&  Boundary(*s))
		continue;
	    if (clip == YES)
	    {
		plot_surf = NO;
	        for (tri = first_tri(*s); !at_end_of_tri_list(tri,*s); 
		     tri = tri->next)
	        {
	            for (k = 0; k < 3; ++k)
		    {
			crds = Coords(Point_of_tri(tri)[k]);
	                for (l = 0; l < 3; ++l)
			    if ((crds[l] < L[l] - tol[l]) || 
			        (U[l] + tol[l] < crds[l]))
				break;
			if (l < 3)
			    break;
		    }
		    if (k == 3)
		    {
			plot_surf = YES;
			for (k = 0; k < 3; ++k)
			{
		            p = Point_of_tri(tri)[k];
			    if (Index_of_point(p) == -1)
			    {
			        crds = Coords(p);
	                        for (l = 0; l < 3; ++l)
				    pts[3*npts+l] = crds[l];
				Index_of_point(p) = npts++;
			    }
			    verts[4*ntris+k] = Index_of_point(p);
			}
			verts[4*ntris+3] = num_surfs;
			++ntris;
		    }
		}
		if (plot_surf == YES)
		    ++num_surfs;
	    }
	    else
	    {
	        for (tri = first_tri(*s); !at_end_of_tri_list(tri,*s); 
		     tri = tri->next)
	        {
	            for (k = 0; k < 3; ++k)
		    {
		        p = Point_of_tri(tri)[k];
			if (Index_of_point(p) == -1)
			{
			    crds = Coords(p);
	                    for (l = 0; l < 3; ++l)
				pts[3*npts+l] = crds[l];
			    Index_of_point(p) = npts++;
			}
			verts[4*ntris+k] = Index_of_point(p);
		    }
		    verts[4*ntris+3] = num_surfs;
		    ++ntris;
		}
		++num_surfs;
	    }
	}
	if (num_surfs == 0)
	    return;
         
	if ((file = fopen(fname,"w")) == NULL)
	{
	    (void) printf("WARNING in vtk_plot_surfaces(), "
	                  "can't open %s\n",fname);
	    return;
	}
	
	if(print_in_binary)
	{
	    if((file = fopen(fname, "wb")) == NULL)
	    {
 		(void) printf("WARNING in vtk_plot_surfaces(), "
	  	     	      "cant' open %s\n",fname);
	 	return;
	    }
	
	    sprintf(str,"# vtk DataFile Version 3.0\n");
	    fwrite(str, sizeof(char), 27, file);
	    sprintf(str,"FronTier Interface\n");
	    fwrite(str, sizeof(char), 19, file);
	    sprintf(str,"BINARY\n");
	    fwrite(str, sizeof(char), 7, file);
	    sprintf(str,"DATASET POLYDATA\n"); 
	    fwrite(str, sizeof(char), 17, file);

	    sprintf(str, "FIELD FieldData 2\n");
            fwrite(str, sizeof(char), 18, file);
	    sprintf(str, "TIME 1 1 float\n");
            fwrite(str, sizeof(char), 15, file);
	    float value1[1];
	    float tmp1 = time;
            if(hardware_is_little_endian())
	        value1[0] = endian_float_swap(tmp1);
            else
		value1[0] = tmp1;
	    fwrite(value1, sizeof(float), 1, file);

	    sprintf(str, "\n");
            fwrite(str, sizeof(char), 1, file);
	    sprintf(str, "CYCLE 1 1 int\n");
            fwrite(str, sizeof(char), 14, file);
	    #if defined(int)
            #undef int
            #define not_int
            #endif
	    int value2[1];
	    int tmp2 = step;
            if(hardware_is_little_endian())
	        value2[0] = endian_int_swap(tmp2);
            else
		value2[0] = tmp2;
	    fwrite(value2, sizeof(int), 1, file);
	    #if defined(not_int)
	    #define int double
     	    #undef not_int
	    #endif
	    sprintf(str, "\n");
            fwrite(str, sizeof(char), 1, file);

            sprintf(str,"POINTS %d float\n", npts);
	    length = count_digits(npts);
	    fwrite(str, sizeof(char), 14 + length, file);
	}
	else
	{
	    if ((file = fopen(fname,"w")) == NULL)
            {
                (void) printf("WARNING in vtk_plot_surfaces(), "
                              "can't open %s\n",fname);
                 return;
            }
 
	    (void) fprintf(file,"# vtk DataFile Version 3.0 \n"
		                "FronTier Interface \n"
		       	        "ASCII \n"
			        "DATASET POLYDATA \n");
	    (void) fprintf(file, "FIELD FieldData 2\n");
	    (void) fprintf(file, "TIME 1 1 float\n");
	    (void) fprintf(file, "%5.5e\n", time);
	    (void) fprintf(file, "CYCLE 1 1 int\n");
	    (void) fprintf(file, "%d\n", step);
	    (void) fprintf(file, "POINTS %d double\n",npts);
	}
	     
	for (i = 0; i < npts; ++i)
	{
	    if(print_in_binary)
	    {
		float vals[1];
		for(j = 0; j < 3; ++j)
		{
		    if(hardware_is_little_endian())
		        vals[0] = endian_float_swap(pts[3*i+j]);
		    else
			vals[0] = pts[3*i+j];
                    fwrite(vals, sizeof(float), 1, file);
		}    
	     }
	     else
	         (void) fprintf(file,"%-9g %-9g %-9g\n",
		       	        pts[3*i],pts[3*i+1],pts[3*i+2]);
	     
	}

	D = (num_surfs == 1) ? 1.0 : 1/(num_surfs - 1.0);
	if(print_in_binary)
	{
	    sprintf(str, "\nPOLYGONS %d %d\n", ntris, ntris*4);
	    length = count_digits(ntris);
	    length2 = count_digits(ntris*4);
	    fwrite(str, sizeof(char), 12 + length + length2, file);
	    for(j = 0; j < ntris; ++j)
	    {
		for(k = 0; k < 3; ++k)
		{
                    int vals[1];
		    if(k == 0)
		    {
		        if(hardware_is_little_endian())
		            vals[0] = endian_int_swap(3);
			else
			    vals[0] = 3;
			fwrite(vals, sizeof(int), 1, file);
		    }
		    if(hardware_is_little_endian())
                        vals[0] = endian_int_swap(verts[4*j+k]);
                    else
                        vals[0] = verts[4*j+k];
                    fwrite(vals, sizeof(int), 1, file);
		}
	    }
	}
	else
	{
	    fprintf(file,"POLYGONS %d %d \n",ntris,ntris*4); 
	    for (j = 0; j < ntris; ++j)
	    {
	        (void) fprintf(file,"%d %d %d %d \n",
			       3,verts[4*j],verts[4*j+1],verts[4*j+2]);
	    }
	} 
	(void) fclose(file);
	    
}	/*end vtk_plot_surfaces*/
}}}