LIB_LOCAL COMPONENT component1d( float *coords, INTERFACE *intfc) { float x = coords[0]; POINT **p; int ix; int k; struct Table *T = intfc->table; /* Check for no points in the interface (interior only) */ if (intfc->points == NULL) return MIN_INTERIOR_COMP; if (intfc->modified || T->new_grid) { if (make_point_comp_lists(intfc) == FUNCTION_FAILED) { (void) printf("WARNING in component1d(), " "make_point_comp_lists failed\n"); return NO_COMP; } } if (rect_in_which(coords,&ix,&T->rect_grid) == FUNCTION_FAILED) return exterior_component(intfc); /* Point Outside */ if (T->compon1d[ix] != ONFRONT) /* Off Front */ return T->compon1d[ix]; else /* On Front: */ { for (k=0, p=T->pts_in_zone[ix]; k < T->num_of_points[ix]; ++k, ++p) { if (x <= Coords(*p)[0]) return negative_component(*p); } p--; return positive_component(*p); } } /*end component1d*/
LIB_LOCAL bool nearest_interface_point1d( float *coords, COMPONENT comp, INTERFACE *intfc, USE_BOUNDARIES bdry, HYPER_SURF *hs, float *ans, float *t, HYPER_SURF_ELEMENT **phse, HYPER_SURF **phs) { const COMPONENT *eq_comps; int n_eq; POINT **p; POINT *p_closest; int ix; /* Grid square containing x */ int icoords[MAXD]; int ix1,ix2; int k; struct Table *T = intfc->table; if (intfc->modified || T->new_grid) { if (make_point_comp_lists(intfc) == FUNCTION_FAILED) { static bool first = YES; (void) printf("WARNING in nearest_interface_point1d(), " "make_point_comp_lists() failed\n" "coords = (%g), comp = %d, bdry = %d, hs = %p\n", coords[0],comp,bdry,hs); (void) printf("Topological grid of interface\n"); print_rectangular_grid(&topological_grid(intfc)); if (first == YES) { (void) printf("Interface into "); (void) printf("nearest_interface_point1d()\n"); print_interface(intfc); } first = NO; return NO; } } if ((!rect_in_which(coords,icoords,&T->rect_grid)) || (T->compon1d[icoords[0]] != ONFRONT)) /* Off Front: */ return long_nearest_interface_point1d(coords,comp,intfc, bdry,hs,ans,t,phse,phs); /* On Front: */ /* Find Closest Point on Front: */ eq_comps = equivalent_components_list(comp,&n_eq,intfc); if (hs) { p_closest = Point_of_hs(hs); } else { float distance; /* Distance from (x) to a Point */ float min_distance; /* Distance to the nearest Point */ ix = icoords[0]; min_distance = HUGE_VAL; p_closest = NULL; p = T->pts_in_zone[ix]; /* Check center block first for existence of allowed */ /* closest point */ for (k = 0; k < T->num_of_points[ix]; ++k,++p) { if (!comp_is_on_point(*p,eq_comps,n_eq)) continue; if (skip_boundary_hs(Hyper_surf(*p),bdry)) continue; distance = sqr(coords[0] - Coords(*p)[0]); if (distance < min_distance) { min_distance = distance; p_closest = *p; } } if (p_closest == NULL) return long_nearest_interface_point1d(coords,comp,intfc,bdry, hs,ans,t,phse,phs); ix1 = ix-1; if (ix1 < 0) ix1=ix; ix2 = ix+1; if (ix2 == T->rect_grid.gmax[0]) ix2 = ix; for(ix = ix1; ix <= ix2; ++ix) { if ((ix == icoords[0]) || (T->compon1d[ix] != ONFRONT)) continue; p = T->pts_in_zone[ix]; for (k = 0; k < T->num_of_points[ix]; ++k,++p) { if (!comp_is_on_point(*p,eq_comps,n_eq)) continue; if (skip_boundary_hs(Hyper_surf(*p),bdry)) continue; distance = sqr(coords[0] - Coords(*p)[0]); if (distance < min_distance) { min_distance = distance; p_closest = *p; } } } if (p_closest == NULL) return long_nearest_interface_point1d(coords,comp, intfc,bdry,hs,ans,t,phse,phs); } *phs = Hyper_surf(p_closest); *phse = Hyper_surf_element(p_closest); ans[0] = Coords(p_closest)[0]; t[0] = 0.0; return YES; } /*end nearest_interface_point1d*/
/*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*/