// delete the specified key from the Btree
RC deleteKey(BTreeHandle *tree, Value *key) {

	Btree* leaf      = NULL;
	// get the desired leaf
	leaf = find_leaf(tree, key);

	// get the left node
	Btree* childLeft = NULL;
	childLeft = leaf->prev;

	// get the tree stastistics data
	Btree_stat *info = NULL;
	info = tree->mgmtData;

	if (leaf != NULL) {

		if (childLeft == NULL) {

			// no child
			// delete the entry and adjust the tree if needed
			delete_entry(tree, leaf, key);

			// done
			return RC_OK;
		}

		if (key->v.intV == leaf->keys[0]) {

			// the key exists in this leaf node
			// delete it
			delete_entry(tree, leaf, key);

			// check if there is underflow in the node capacity
			if (leaf->num_keys == 0) {

				// merge with the left sibling
				childLeft->next = leaf->next;

				// check if we need to propagate this change up the tree
				delete_parent_nodes_inital(info, leaf, key);

				// done
				return RC_OK;
			}

			// update the prent node
			updateFirst(leaf, key);

			return RC_OK;

		} else {

			delete_entry(tree, leaf, key);

			if (leaf) {

				// see of there is underflow
				if (checkUnderflow(info, leaf)) {

					// if yes, merge with left sibling
					if (childLeft) {

						// check the number of keys even after splitting
						if (childLeft->num_keys > splitNode(info->order)
						&&  childLeft->num_keys != info->order) {

							// we need to redistribute the keys
							// to balance out
							redistribute(info, childLeft, leaf);

						} else {
							// just merge
							merge_nodes(info, childLeft, leaf);
						}
					}
				}
			}

			return RC_OK;
		}
	}

	// all ok
	return RC_OK;
}
示例#2
0
static  void test_propagate(
        Front *front)
{
        int ip,im,status,count;
        Front *newfront;
        float dt,dt_frac,CFL;
        bool is_print_time, is_movie_time, time_limit_reached;
        char s[10];
        float fcrds[MAXD];
        int  dim = front->rect_grid->dim;

	front->max_time = 2.0;
	front->max_step = 400;
	front->print_time_interval = 1.0;
	front->movie_frame_interval = 0.02;

        CFL = Time_step_factor(front);
	Frequency_of_redistribution(front,GENERAL_WAVE) = 2;

        printf("dim = %d\n", dim);
	printf("CFL = %f\n",CFL);
	printf("Frequency_of_redistribution(front,GENERAL_WAVE) = %d\n",
		Frequency_of_redistribution(front,GENERAL_WAVE));

	if (!RestartRun)
	{
            redistribute(front,YES,NO);

            front->time = 0.0;
            front->dt = 0.0;
            front->step = 0;

	    // Always output the initial interface.
	    FrontPrintOut(front,out_name);
            FrontMovieFrame(front,out_name,binary);
            ip = im = 1;

	    // This is a virtual propagation to get maximum front 
	    // speed to determine the first time step.

            status = FrontAdvance(front->dt,&dt_frac,front,&newfront,
                                (POINTER)NULL);
            front->dt = CFL*FrontHypTimeStep(front); 
	}
	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);

        for (;;)
        {
	    /* Propagating interface for time step dt */

            status = FrontAdvance(front->dt,&dt_frac,front,&newfront,
                                (POINTER)NULL);
            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*FrontHypTimeStep(front); 

	    /* 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)
                print_front_output(front,out_name);
            if (is_movie_time || time_limit_reached)
                show_front_output(front,out_name,binary);

            if (time_limit_reached)
                    break;

	    front->dt = FrontOutputTimeControl(front,
			&is_movie_time,
			&is_print_time,
			&time_limit_reached,
			&im,&ip);
        }
        (void) delete_interface(front->interf);
}       /* end test_propagate */
示例#3
0
文件: fadv.c 项目: antdvid/FronTier
/*ARGSUSED*/
LOCAL int advance_front1d(
	double		dt,
	double		*dt_frac,
	Front		*front,
	Front		**newfront,
	POINTER		wave)
{
	POINT              *oldp, *newp;
	HYPER_SURF_ELEMENT *oldhse, *newhse;
	HYPER_SURF         *oldhs, *newhs;
	INTERFACE          *intfc_old, *intfc_new;
	int		   status;
	double              V[MAXD];
	boolean		   has_tracked_points;
	static const char	   *fname = "advance_front1d";

	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;

	has_tracked_points = (front->interf->points != NULL) ? YES : NO;
	if (pp_max_status(has_tracked_points) == 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("propagate");

		/* Initialize Newfront */

	start_clock("init_new_front");
	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);
	if ((*newfront)->interf == NULL)
	{
	    (void) printf("ERROR in advance_front1d(), "
			  "unable to copy interface\n");
	    return return_advance_front(front,newfront,ERROR_IN_STEP,fname);
	}
	stop_clock("init_new_front");

		/* Propagate the points */

	set_propagation_limits(front,*newfront);
	set_copy_intfc_states(YES);
	intfc_old = front->interf;
	intfc_new = (*newfront)->interf;

	(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);
	}
	copy_hypersurface_flags(intfc_new);
	debug_front("pt_front","after point propagate",*newfront);

	switch (redistribute(*newfront,YES,NO)) 
	{
	case	GOOD_REDISTRIBUTION:
	    status = GOOD_STEP;
	    break;
	
	case	MODIFY_TIME_STEP_REDISTRIBUTE:
	    (void) printf("WARNING in advance_front1d(), redistribution "
			  "of front failed, reducing time step\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = max(Min_time_step_modification_factor(front),*dt_frac);
	    status = MODIFY_TIME_STEP;
	    break;

	case	UNABLE_TO_UNTANGLE:
	case	BAD_REDISTRIBUTION:
	default:
	    (void) printf("WARNING in advance_front1d(), "
	                  "redistribution of front failed\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = ERROR_IN_STEP;
	    break;
	}
	debug_front("redist_front","after redistribute",*newfront);
	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);
	if (!scatter_front(*newfront))
	{
	    (void) printf("WARNING in advance_front1d(), "
	    	          "scatter_front() failed for "
	    	          "normally propagated front\n");
	    return return_advance_front(front,newfront,ERROR_IN_STEP,fname);
	}

	(*newfront)->step = front->step + 1;
	(*newfront)->time = front->time + dt;
	interpolate_intfc_states(intfc_new) = YES;
	set_size_of_intfc_state(size_of_state(intfc_new));

	if (intfc_new->modified)
	    (void) make_point_comp_lists(intfc_new);

	stop_clock("propagate");
	debug_front("new_front","from advance front",*newfront);
	return return_advance_front(front,newfront,status,fname);
}		/*end advance_front1d*/
示例#4
0
文件: fadv.c 项目: antdvid/FronTier
LOCAL int advance_front2d(
	double    dt,
	double    *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;
	boolean	   scatter_normally_propagated_front = YES;
	boolean	   scatter_tangentially_propagated_front = YES;
	boolean	   stat;
	boolean       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->intfc_propagate != NULL)
	{
	    start_clock("intfc_propagate");
	    intfc_propagate(front,wave,front->interf,(*newfront)->interf,dt);
	    debug_front("cp_front","after intfc prop",*newfront);
	    stop_clock("curve_propagate");
	}
	else 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)
	    {
	        oldc = *c;
	        if (((newc = correspond_curve(oldc)) != NULL) &&
	    	     (correspond_curve(newc) != NULL))
	        {
	    	    if (debugging("propagate"))
	                (void) printf("\t\tpropagating curve %llu\n",
		                      (long long unsigned int)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);
	}
	if (*front->max_scaled_propagation > 0.5)
	{
	    (void) printf("WARNING in advance_front2d(), "
	                  "front->max_scaled_propagation = %f\n",
			  *(front->max_scaled_propagation));
	    *dt_frac = 0.4/(*front->max_scaled_propagation);
	    status = MODIFY_TIME_STEP;
	    goto sync_prop_stat2;
	}

	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);
	    print_storage("after snd_copy_interface","ADV_storage");
	    stop_clock("snd_copy_interface");
	}
	interpolate_intfc_states((*newfront)->interf) = YES;

	/* 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);
	intfc_delete_fold_back_bonds(*newfront);
	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*/
示例#5
0
EXPORT int redist_advance_front2d(
	float    dt,
	float    *dt_frac,
	Front    *front,
	Front    **newfront,
	POINTER  wave)
{
	int        status, do_redist = YES;
	const char *fname = "redist_advance_front2d()";
	
	switch (redistribute(*newfront,do_redist,NO)) 
	{
	case	GOOD_REDISTRIBUTION:
	    status = GOOD_STEP;
	    break;
	
	case	UNABLE_TO_UNTANGLE:
	    (void) printf("WARNING in redist_advance_front2d(), "
	                  "redistribution of front failed\n"
	                  "Restarting redist_advance_front2d()\n");
	    (void) delete_interface((*newfront)->interf);
	    (*newfront)->interf = NULL;
	    do_redist = NO;
	    status = ERROR_IN_STEP;
	    break;

	case	MODIFY_TIME_STEP_REDISTRIBUTE:
	    (void) printf("WARNING in redist_advance_front2d(), "
	                  "redistribute returns\n"
	                  "\t\tMODIFY_TIME_STEP_REDISTRIBUTE\n");
	    status = MODIFY_TIME_STEP;
	    break;
		
	case	BAD_REDISTRIBUTION:
	default:
	    (void) printf("WARNING in redist_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 (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);

	/* Delete non-boundary curves that lie  */
	/* fully on or exterior to the boundary */
	delete_exterior_curves(*newfront,front->interf);
    
        if(delete_phys_remn_on_bdry(*newfront) == NO)
        {
            (void) printf("WARNING in redist_advance_front2d(), "
                          "delete_phys_remn_on_bdry() detected error\n");
            debug_front("ERROR_front","after error",*newfront);
            status = MODIFY_TIME_STEP;
            return return_advance_front(front,newfront,status,fname);
        }  

	delete_small_loops(*newfront);

	measure_front(*newfront);

	test_for_mono_comp_curves((*newfront)->interf);

        /* 
        if((*newfront)->step > 5111) 
        {
            printf("LEAVING redist_advance_front2d, front[%d], level[%d]\n",
             (*newfront)->patch_number, (*newfront)->patch_level);
            for(CURVE **c = (*newfront)->interf->curves; c && *c; c++)
            {
                if(wave_type(*c) < FIRST_PHYSICS_WAVE_TYPE)
                    continue;
                print_curve(*c);
            }        
        }
        */ 
	return return_advance_front(front,newfront,GOOD_STEP,fname);
}		/*end redist_advance_front2d*/