void manage_errors() { if (g_XGV_num_errors == 0) { g_num_errors = 0; print_interface(); } else { g_num_errors = g_XGV_num_errors; // get_errors_descriptions(); print_interface(); } }
static void print_configuration(openusb_devid_t devid, int cfgidx, struct usb_config_desc *cfg) { int i; int ret; printf(" Config: %d\n", cfgidx); printf(" wTotalLength: %d\n", cfg->wTotalLength); printf(" bNumInterfaces: %d\n", cfg->bNumInterfaces); printf(" bConfigurationValue: %d\n", cfg->bConfigurationValue); printf(" iConfiguration: %d\n", cfg->iConfiguration); printf(" bmAttributes: %02xh\n", cfg->bmAttributes); printf(" MaxPower: %d\n", cfg->bMaxPower); printf("\n"); for (i = 0; i < cfg->bNumInterfaces; i++) { struct usb_interface_desc intf; int j; for (j = 0;; j++) { /* no clue of how many altsettings here */ ret = openusb_parse_interface_desc(libhandle, devid, NULL, 0, cfgidx, i, j, &intf); if(ret != 0) { break; } print_interface(devid, cfgidx, i, j, &intf); } } }
LIB_LOCAL void i_print_intersections1d( CROSS *cross, INTERFACE *intfc) { int i, num; CROSS *cr; if (cross == NULL) { (void) printf("NO INTERSECTIONS \n"); return; } (void) output(); (void) printf("INTERSECTIONS:\n\n"); print_interface(intfc); (void) printf("Here are the intersections:\n\n"); for (num = 1, cr = cross; cr; ++num, cr = cr->next) { (void) printf("Intersection %d, ",num); (void) printf("Cross %p next %p prev %p\n", (POINTER)cr,(POINTER)cr->next,(POINTER)cr->prev); (void) printf("Crossing points\n"); (void) printf("cr->npt = %d\n",cr->npt); for (i = 0; i < cr->npt; ++i) print_point(cr->pt[i]); } } /*end i_print_intersections1d*/
void read_stats(const char *name) { if(name) { print_interface(name); return; } /* scan for interface names */ glob_t g; char tmp[32]; sprintf(tmp, "%snd*", DEV_DIR); g.gl_offs = 256; g.gl_offs = 256; if(glob(tmp, 0, 0, &g)) { perror("glob for interface failed"); return; } int i; for(i=0;i<g.gl_pathc;i++) print_interface((char *)basename(g.gl_pathv[i])); }
void print_configuration(struct usb_config_descriptor *config) { int i; printf(" wTotalLength: %d\n", config->wTotalLength); printf(" bNumInterfaces: %d\n", config->bNumInterfaces); printf(" bConfigurationValue: %d\n", config->bConfigurationValue); printf(" iConfiguration: %d\n", config->iConfiguration); printf(" bmAttributes: %02xh\n", config->bmAttributes); printf(" MaxPower: %d\n", config->MaxPower); for (i = 0; i < config->bNumInterfaces; i++) print_interface(&config->interface[i]); }
void KlassHierarchy::print_class(outputStream* st, KlassInfoEntry* cie, bool print_interfaces) { ResourceMark rm; InstanceKlass* klass = (InstanceKlass*)cie->klass(); int indent = 0; // Print indentation with proper indicators of superclass. Klass* super = klass->super(); while (super != NULL) { super = super->super(); indent++; } print_indent(st, indent); if (indent != 0) st->print("--"); // Print the class name, its unique ClassLoader identifer, and if it is an interface. print_classname(st, klass); if (klass->is_interface()) { st->print(" (intf)"); } st->print("\n"); // Print any interfaces the class has. if (print_interfaces) { Array<Klass*>* local_intfs = klass->local_interfaces(); Array<Klass*>* trans_intfs = klass->transitive_interfaces(); for (int i = 0; i < local_intfs->length(); i++) { print_interface(st, local_intfs->at(i), "declared", indent); } for (int i = 0; i < trans_intfs->length(); i++) { Klass* trans_interface = trans_intfs->at(i); // Only print transitive interfaces if they are not also declared. if (!local_intfs->contains(trans_interface)) { print_interface(st, trans_interface, "inherited", indent); } } } }
TEST_PYLIBUSB_API print_config( struct usb_config_descriptor* cfg ) { int i; printf("usb_config_descriptor at %p\n",cfg); printf(" bLength: %d\n",cfg->bLength); printf(" bDescriptorType: %d\n",cfg->bDescriptorType); printf(" wTotalLength: %d\n",cfg->wTotalLength); printf(" bNumInterfaces: %d\n",cfg->bNumInterfaces); printf(" bConfigurationValue: %d\n",cfg->bConfigurationValue); printf(" iConfiguration: %d\n",cfg->iConfiguration); printf(" bmAttributes: %d\n",cfg->bmAttributes); printf(" MaxPower: %d\n",cfg->MaxPower); for (i=0;i<cfg->bNumInterfaces;i++) { print_interface(&((cfg->interface)[i])); } }
void print_ClassFile(ClassFile* class_file_ptr){ printf("\n\nMagic: %.8x\n\n", class_file_ptr->magic); printf("Minor Version: %.4x\n", class_file_ptr->minor_version); printf("Major Version: %.4x\n\n", class_file_ptr->major_version); printConstantPoolTable(class_file_ptr->constant_pool_count, class_file_ptr->constant_pool); print_interface(class_file_ptr->interfaces, class_file_ptr->interfaces_count, class_file_ptr->constant_pool); printField(class_file_ptr->constant_pool, class_file_ptr->fields, class_file_ptr->fields_count); print_Methods(class_file_ptr, class_file_ptr->constant_pool); print_attributes(class_file_ptr->attributes, class_file_ptr->attributes_count, class_file_ptr->constant_pool); }
LOCAL bool i_consistent_interface3d( INTERFACE *intfc) { HYPER_SURF_ELEMENT *hse; HYPER_SURF *hs; CURVE **c; NODE **n; POINT *p; SURFACE **ss, *s; TRI *tri; bool status = YES; const char *warn = "WARNING in i_consistent_interface(), "; /* Check Nodes */ for (n = intfc->nodes; n && *n; ++n) { if ((*n)->interface != intfc) { (void) printf("%s n = %llu n->interface (%llu) != intfc (%llu)\n", warn,node_number(*n), interface_number((*n)->interface), interface_number(intfc)); status = NO; } for (c = (*n)->in_curves; c && *c; ++c) { if ((*c)->end != *n) { (void) printf("%s inconsistent node (%llu) " "curve (%llu) pair, " "curve->end != n\n", warn,node_number(*n),curve_number(*c)); status = NO; } } for (c = (*n)->out_curves; c && *c; ++c) { if ((*c)->start != *n) { (void) printf("%s inconsistent node (%llu) " "curve (%llu) pair, " "curve->start != n\n", warn,node_number(*n),curve_number(*c)); status = NO; } } } /* Check Curves */ for (c = intfc->curves; c && *c; c++) { if (!check_curve3d(*c,intfc)) { (void) printf("%s inconsistency in curve (%llu) found\n", warn,curve_number(*c)); status = NO; } } for (ss = intfc->surfaces; ss && *ss; ++ss) { if (!check_consistency_of_tris_on_surface(*ss)) { (void) printf("%s inconsistency in surface (%llu) found\n", warn,surface_number(*ss)); status = NO; } } (void) next_point(intfc,NULL,NULL,NULL); while (next_point(intfc,&p,&hse,&hs)) { BOND *b = NULL, *bb; BOND_TRI **bts; CURVE **c; TRI **tris; int i, ntris; int v, pside, nside; tri = Tri_of_hse(hse); s = Surface_of_hs(hs); if ((v = Vertex_of_point(tri,p)) == ERROR) { (void) printf("%s point not on tri, s = %llu\n", warn,surface_number(s)); (void) printf("p(%llu) - (%g, %g, %g), ", point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); status = NO; } if (!Boundary_point(p)) { ntris = set_tri_list_around_point(p,tri,&tris,intfc); if ((tri != tris[0]) || (tri != Prev_tri_at_vertex(tris[ntris-1],p))) { bool consistent_tri_list = NO; if (allow_null_sides) { if ((Next_tri_at_vertex(tris[0],p) == NULL) && (Prev_tri_at_vertex(tris[ntris-1],p) == NULL)) consistent_tri_list = YES; } if (!consistent_tri_list) { (void) printf("\n%s Corrupt tri list s (%llu) " "p(%llu) - (%g, %g, %g)\n", warn,surface_number(s), point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); (void) printf("%d tris about point\n",ntris); for (i = 0; i < ntris; ++i) { (void) printf("tris[%d] - ",i); print_tri(tris[i],hs->interface); } (void) printf("End printout of " "Corrupt tri list s (%llu) " "p(%llu) - (%g, %g, %g)\n\n", surface_number(s),point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); status = NO; } } continue; } nside = v; pside = Prev_m3(v); if (is_side_bdry(tri,nside)) b = Bond_on_side(tri,nside); else if (is_side_bdry(tri,pside)) b = Bond_on_side(tri,pside); else //#bjet2 { ntris = set_tri_list_around_point(p,tri,&tris,intfc); v = Vertex_of_point(tris[0],p); nside = v; pside = Prev_m3(v); if (is_side_bdry(tris[0],nside)) b = Bond_on_side(tris[0],nside); else if (is_side_bdry(tris[0],pside)) b = Bond_on_side(tris[0],pside); else { int i; (void) printf("%s Boundary_point has no adjacent " "tri with a bond\n",warn); (void) printf("p(%llu) - (%g, %g, %g), ", point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); for (i = 0; i < ntris; ++i) { (void) printf("tris[%d] - ",i); print_tri(tris[i],hs->interface); } status = NO; } tri = tris[0]; } for (bts = Btris(b); bts && *bts; ++bts) if ((*bts)->tri == tri) break; if ((bts == NULL) || (*bts == NULL)) { (void) printf("%s bond tri for tri not found\n",warn); (void) printf("p(%llu) - (%g, %g, %g), ",point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); print_bond(b); status = NO; } else { if ((*bts)->bond != b) { (void) printf("%s (*bts)->bond != b\n",warn); (void) printf("p(%llu) - (%g, %g, %g), ",point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); print_bond(b); status = NO; } if ((*bts)->surface != s) { (void) printf("%s inconsistent surfaces at bond tri\n", warn); (void) printf("p(%llu) - (%g, %g, %g), ",point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); print_bond(b); status = NO; } if (orientation_of_bond_at_tri(b,tri) != (*bts)->orient) { (void) printf("%s inconsistent orientation at bond tri\n", warn); (void) printf("p(%llu) - (%g, %g, %g), ",point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); print_bond(b); status = NO; } switch ((*bts)->orient) { case POSITIVE_ORIENTATION: for (c = s->pos_curves; c && *c; c++) if ((*c) == (*bts)->curve) break; break; case NEGATIVE_ORIENTATION: for (c = s->neg_curves; c && *c; c++) if ((*c) == (*bts)->curve) break; break; case ORIENTATION_NOT_SET: c = NULL; (void) printf("%s undetermined orientation at " "bond on tri\n",warn); (void) printf("p(%llu) - (%g, %g, %g), ",point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); print_bond(b); status = NO; break; } if ((c == NULL) || (*c == NULL)) { (void) printf("%s curve with bond on tri not found\n",warn); (void) printf("p(%llu) - (%g, %g, %g), ",point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); print_bond(b); status = NO; } else { for (bb = (*c)->first; bb != NULL; bb = bb->next) if (bb == b) break; if (bb == NULL) { (void) printf("%s bond not on curve\n",warn); (void) printf("p(%llu) - (%g, %g, %g), ",point_number(p), Coords(p)[0],Coords(p)[1],Coords(p)[2]); print_tri(tri,hs->interface); print_bond(b); print_curve(*c); status = NO; } } } } if (status == NO) { (void) printf("WARNING in i_consistent_interface(), " "Inconsistent interface found\n"); print_interface(intfc); } allow_null_sides = NO; return status; } /*end i_consistent_interface*/
void user_interface(OjCmpt XGV_CCU) { struct termios newTermio; struct termios storedTermio; int running = 1; char choice[8] = {0}; int count = 0; // Prepare terminal for receiving key commands tcgetattr(0, &storedTermio); memcpy(&newTermio, &storedTermio, sizeof(struct termios)); newTermio.c_lflag &= (~ICANON); newTermio.c_lflag &= (~ECHO); newTermio.c_cc[VTIME] = 0; newTermio.c_cc[VMIN] = 1; tcsetattr(0, TCSANOW, &newTermio); // Start up Curses window initscr(); //cbreak(); //noecho(); //nodelay(stdscr, 1); // Don't wait at the getch() function if the user hasn't hit a key keypad(stdscr, 1); // Allow Function key input and arrow key input while (running) { print_interface(); memset(choice, 0, 8); count = read(0, &choice, 8); if (count == 1) { switch (choice[0]) { case 27: // ESC printf("Shutting Down XGV_CCU...\n"); running = 0; break; case 'W': case 'w': change_control_mode_to_wrench_efforts(XGV_CCU); break; case 'M': case 'm': change_control_mode_to_motion_profiles(XGV_CCU); break; case ' ': g_brakes_command = MAX_BRAKES; g_throttle_command = MIN_THROTTLE; g_steering_command = (MAX_STEERING - MIN_STEERING) / 2.0 + MIN_STEERING; g_velocity_command = (MAX_VELOCITY - MIN_VELOCITY) / 2.0 + MIN_VELOCITY; g_acceleration_command = 1.0; g_atan_curvature_command = (MAX_ARCTAN_DESIRED_CURVATURE - MIN_ARCTAN_DESIRED_CURVATURE) / 2.0 + MIN_ARCTAN_DESIRED_CURVATURE; g_rate_change_curvature_command = 0.06; break; case 'a': g_gear_command = 1; // Low send_set_discrete_devices_message(XGV_CCU); break; case 's': g_gear_command = 2; // Drive send_set_discrete_devices_message(XGV_CCU); break; case 'd': g_gear_command = 128; // Neutral send_set_discrete_devices_message(XGV_CCU); break; case 'f': g_gear_command = 129; // Reverse send_set_discrete_devices_message(XGV_CCU); break; case 'z': g_engine_command = 1; // Turn engine On send_set_engine_message(XGV_CCU, g_engine_command); break; case 'x': g_engine_command = 0; // Turn engine Off send_set_engine_message(XGV_CCU, g_engine_command); break; case '1': g_turn_signal_command = 0; send_set_signals_message(XGV_CCU); break; case '2': g_turn_signal_command = 1; send_set_signals_message(XGV_CCU); break; case '3': g_turn_signal_command = 2; send_set_signals_message(XGV_CCU); break; case '4': g_turn_signal_command = 3; send_set_signals_message(XGV_CCU); break; case '5': if (g_horn_status_command == 0) g_horn_status_command = 1; else if (g_horn_status_command == 1) g_horn_status_command = 0; send_set_signals_message(XGV_CCU); break; case '6': g_headlights_status_command = 0; send_set_signals_message(XGV_CCU); break; case '7': g_headlights_status_command = 1; send_set_signals_message(XGV_CCU); break; case '8': g_headlights_status_command = 2; send_set_signals_message(XGV_CCU); break; case '9': if ((g_headlights_status_command & 7) == 2) g_headlights_status_command ^= 8; send_set_signals_message(XGV_CCU); break; case '0': if ((g_headlights_status_command & 7) == 2) g_headlights_status_command ^= 0x10; send_set_signals_message(XGV_CCU); break; default: break; } } else { switch (choice[2]) { case 65: // Up g_throttle_command += (MAX_THROTTLE - MIN_THROTTLE) / 100.0; if (g_throttle_command > MAX_THROTTLE) g_throttle_command = MAX_THROTTLE; g_brakes_command = 0.0; g_velocity_command += (MAX_VELOCITY - MIN_VELOCITY) / 100.0; if (g_velocity_command > MAX_VELOCITY) g_velocity_command = MAX_VELOCITY; break; case 66: // Down g_throttle_command -= (MAX_THROTTLE - MIN_THROTTLE) / 100.0; if (g_throttle_command < MIN_THROTTLE) { g_throttle_command = MIN_THROTTLE; g_brakes_command += (MAX_BRAKES - MIN_BRAKES) / 100.0; if (g_brakes_command > MAX_BRAKES) g_brakes_command = MAX_BRAKES; } g_velocity_command -= (MAX_VELOCITY - MIN_VELOCITY) / 100.0; if (g_velocity_command < MIN_VELOCITY) g_velocity_command = MIN_VELOCITY; break; case 67: // Right g_steering_command += (MAX_STEERING - MIN_STEERING) / 100.0; if (g_steering_command > MAX_STEERING) g_steering_command = MAX_STEERING; g_atan_curvature_command += (MAX_ARCTAN_DESIRED_CURVATURE - MIN_ARCTAN_DESIRED_CURVATURE) / 100.0; if (g_atan_curvature_command > MAX_ARCTAN_DESIRED_CURVATURE) g_atan_curvature_command = MAX_ARCTAN_DESIRED_CURVATURE; break; case 68: // Left g_steering_command -= (MAX_STEERING - MIN_STEERING) / 100.0; if (g_steering_command < MIN_STEERING) g_steering_command = MIN_STEERING; g_atan_curvature_command -= (MAX_ARCTAN_DESIRED_CURVATURE - MIN_ARCTAN_DESIRED_CURVATURE) / 100.0; if (g_atan_curvature_command < MIN_ARCTAN_DESIRED_CURVATURE) g_atan_curvature_command = MIN_ARCTAN_DESIRED_CURVATURE; break; default: break; } } } endwin(); tcsetattr(0, TCSANOW, &storedTermio); }
static int list_devices(bool parsable) { char bus_type[] = "usb"; char busid[SYSFS_BUS_ID_SIZE]; char product_name[128]; struct sysfs_bus *ubus; struct sysfs_device *dev; struct sysfs_device *intf; struct sysfs_attribute *idVendor; struct sysfs_attribute *idProduct; struct sysfs_attribute *bConfValue; struct sysfs_attribute *bNumIntfs; struct dlist *devlist; int i; int ret = -1; ubus = sysfs_open_bus(bus_type); if (!ubus) { err("could not open %s bus: %s", bus_type, strerror(errno)); return -1; } devlist = sysfs_get_bus_devices(ubus); if (!devlist) { err("could not get %s bus devices: %s", bus_type, strerror(errno)); goto err_out; } /* remove interfaces and root hubs from device list */ dlist_filter_sort(devlist, is_device, devcmp); if (!parsable) { printf("Local USB devices\n"); printf("=================\n"); } dlist_for_each_data(devlist, dev, struct sysfs_device) { idVendor = sysfs_get_device_attr(dev, "idVendor"); idProduct = sysfs_get_device_attr(dev, "idProduct"); bConfValue = sysfs_get_device_attr(dev, "bConfigurationValue"); bNumIntfs = sysfs_get_device_attr(dev, "bNumInterfaces"); if (!idVendor || !idProduct || !bConfValue || !bNumIntfs) { err("problem getting device attributes: %s", strerror(errno)); goto err_out; } /* get product name */ usbip_names_get_product(product_name, sizeof(product_name), strtol(idVendor->value, NULL, 16), strtol(idProduct->value, NULL, 16)); print_device(dev->bus_id, idVendor->value, idProduct->value, parsable); print_product_name(product_name, parsable); for (i = 0; i < atoi(bNumIntfs->value); i++) { snprintf(busid, sizeof(busid), "%s:%.1s.%d", dev->bus_id, bConfValue->value, i); intf = sysfs_open_device(bus_type, busid); if (!intf) { err("could not open device interface: %s", strerror(errno)); goto err_out; } print_interface(busid, intf->driver_name, parsable); sysfs_close_device(intf); } printf("\n"); }
EXPORT int normal_advance_front2d( float dt, float *dt_frac, Front *front, Front **newfront, POINTER wave) { CURVE *oldc,*newc; CURVE **c; NODE *oldn,*newn; RPROBLEM *rp,*rp1; int status, node_stat; NODE_FLAG flag; const char *fname = "normal_advance_front2d()"; 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; if(front->interf->nodes == NULL) { bool sav_copy; INTERFACE *sav_intfc; sav_intfc = current_interface(); sav_copy = copy_intfc_states(); set_size_of_intfc_state(size_of_state(front->interf)); set_copy_intfc_states(YES); (*newfront)->interf = copy_interface(front->interf); set_current_interface(sav_intfc); set_copy_intfc_states(sav_copy); return return_advance_front(front,newfront,GOOD_STEP,fname); } 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); /* If USE_OVERTURE, can not syncronize_time_step at here (*newfront)->interf = pp_copy_interface(front->interf); */ (*newfront)->interf = 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 (status != GOOD_STEP) { (void) printf("ERROR in normal_advance_front2d(), " "unable to copy interface\n"); print_storage("after init_new_front","ADV_storage"); clean_up(ERROR); } 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++) { oldc = *c; if (((newc = correspond_curve(oldc)) != NULL) && (correspond_curve(newc) != NULL)) { if (debugging("propagate")) (void) printf("\t\tpropagating curve %lu\n", curve_number(oldc)); curve_propagate(front,wave,oldc,newc,dt); } } 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); if(DEBUG) { /* printf("IN normal_advance_front2d\n"); printf("node propagate\n"); print_node(oldn); print_node(newn); printf("oldnode is virtual fixed = %s\n", is_virtual_fixed_node(oldn) == YES ? "YES" : "NO"); printf("newnode is virtual fixed = %s\n", is_virtual_fixed_node(newn) == YES ? "YES" : "NO"); printf("End of print new and old nodes\n"); */ } status = (newn != NULL) ? (*front->node_propagate)(front,wave,oldn,newn,&rp, dt,dt_frac,flag,NULL) : GOOD_NODE; if (is_bad_status(status) && (point_in_buffer(Coords(oldn->posn),front->rect_grid) == YES)) { (void) printf("WARNING in normal_advance_front2d(), " "node_propagation returns "); print_node_status("WARNING in normal_advance_front2d(), " "node_propagation returns ",status,"\n"); /* print_node_status(status); */ (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: (void) printf("WARNING in normal_advance_front2d(), "); (void) printf("node_propagate failed, "); print_node_status("WARNING in normal_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"); } *dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf); free_rp_list(&rp); status = MODIFY_TIME_STEP; goto sync_prop_stat1; case MODIFY_TIME_STEP_NODE: (void) printf("WARNING in normal_advance_front2d(), " "node_propagate returns " "MODIFY_TIME_STEP_NODE\n"); free_rp_list(&rp); status = MODIFY_TIME_STEP; goto sync_prop_stat1; case REPEAT_TIME_STEP_NODE: (void) printf("WARNING in normal_advance_front2d(), " "node_propagate returns " "REPEAT_TIME_STEP_NODE\n"); free_rp_list(&rp); status = REPEAT_TIME_STEP; goto sync_prop_stat1; case NO_CROSS_NODE: (void) printf("WARNING in normal_advance_front2d(), "); (void) printf("node_propagate failed, "); print_node_status("WARNING in normal_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"); } *dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf); free_rp_list(&rp); status = MODIFY_TIME_STEP; goto sync_prop_stat1; case ERROR_NODE: default: (void) printf("WARNING in normal_advance_front2d(), "); (void) printf("node_propagate failed, "); print_node_status("WARNING in normal_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); } *dt_frac = Min_time_step_modification_factor(front); free_rp_list(&rp); status = MODIFY_TIME_STEP; 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 normal_advance_front2d(), "); (void) printf("CROSS code needed\n"); status = ERROR_IN_STEP; } } /* 061003 closed, since the correspondence is reset. * The second node prop. is done in tangential step now. node_stat = second_node_propagate2d(dt,dt_frac,front,newfront,wave); if(GOOD_STEP != node_stat) { (void) printf("WARNING in normal_advance_front2d(), " "second node_propagation returns stat= %d", node_stat); clean_up(ERROR); } */ sync_prop_stat1: return return_advance_front(front,newfront,GOOD_STEP,fname); } /*end normal_advance_front2d*/
LOCAL void rt_add_to_state( float *coords, Locstate state, /* assumed to be TGAS_STATE */ COMP_TYPE *ct, INIT_DATA *init) { #if defined(float) static const float ACC = 1.0e-14; /*TOLERANCE*/ #else /* defined(float) */ static const float ACC = 1.0e-7; /*TOLERANCE*/ #endif /* defined(float) */ int i, j, k0, k1, dim, layer_label, num_modes, nstep; float rho, csq, rho_prime, a_z, b_z, k_dot_r, sig, phase; float tmp, ub, lb, z0, z1, a0, a1, b0, b1, z, h_z, g_z; const float *grav; _RT_PERTURBED *rtp = Rt_perturbed(ct); NORMAL_MODE *n_m; dim = ct->params->dim; layer_label = rtp->layer_label; nstep = rtp->lin_pert_intvl; num_modes = rtp->num_modes; if (num_modes <= 0) return; z0 = lb = get_surf_height(coords, rtp->lower_surf); z1 = ub = get_surf_height(coords, rtp->upper_surf); h_z = (ub-lb)/nstep; z = coords[dim-1]; grav = gravity(coords,initial_time(init)); g_z = grav[dim-1]; /* find out which interval z belongs */ if (ub < lb) { screen("\nERROR in rt_add_to_state(), "); screen("Interfaces are already tangled.\n"); (void) printf("ub = %g, lb = %g\n",ub,lb); print_interface(current_interface()); clean_up(ERROR); } if (z >= ub) k0 = k1 = nstep; else if (z <= lb) k0 = k1 = 0; else { k0 = 0, k1 = nstep; for (;;) { tmp = (z0+z1)/2.0; if (z >= tmp) k0 = (k0+k1)/2, z0 = tmp; else k1 = (k0+k1)/2, z1 = tmp; if (k1-k0 == 1) break; } } z0 = lb+k0*h_z; z1 = lb+k1*h_z; rho = Dens(state); csq = sound_speed_squared(state); rho_prime = get_rho_prime(state,ct,g_z); /* sum over all the normal modes */ for (i = 0; i < num_modes; ++i) { n_m = rtp->normal_mode[i]; if (k0 == k1) { a_z = n_m->a[layer_label][k1]; b_z = n_m->b[layer_label][k1]; } else { a0 = n_m->a[layer_label][k0]; a1 = n_m->a[layer_label][k1]; a_z = ((a1-a0)*z+(a0*z1-a1*z0))/h_z; b0 = n_m->b[layer_label][k0]; b1 = n_m->b[layer_label][k1]; b_z = ((b1-b0)*z+(b0*z1-b1*z0))/h_z; } if ((fabs(a_z) < ACC) && (fabs(b_z) < ACC)) continue; sig = n_m->sigma_r; phase = n_m->phase; k_dot_r = 0.0; for (j = 0; j <= dim-2; ++j) k_dot_r += n_m->wv_num[j]*coords[j]; phase += k_dot_r; Dens(state) += ((g_z*rho/csq-rho_prime)*a_z+b_z/csq)/sig*sin(phase); Press(state) += b_z/sig*sin(phase); Vel(state)[dim-1] += a_z*sin(phase); set_type_of_state(state,TGAS_STATE); phase += 3.0*PI/2; for (j = 0; j <= dim-2; ++j) Vel(state)[j] += sin(phase)*n_m->wv_num[j]*b_z/(rho*sig*sig); reset_gamma(state); } } /*end rt_add_to_state*/
EXPORT NODE *reorder_node_loop( NODE *oldn, NODE *newn) { INTERFACE *intfc; NODE *next, *prev; NODE *next_old_node; if (oldn != NULL) { intfc = oldn->interface; next = next_node(oldn); if (next == NULL) { screen("ERROR in reorder_node_loop(), " "next_node(oldn) == NULL\n"); print_node(oldn); (void) printf("Old interface information\n"); print_linked_node_list(intfc); print_interface(intfc); if (newn != NULL) { intfc = newn->interface; (void) printf("New interface information\n"); print_linked_node_list(intfc); print_interface(intfc); } clean_up(ERROR); } prev = prev_node(oldn); prev_node(next) = prev; if (prev != NULL) next_node(prev) = next; else first_node(intfc) = next; next_node(last_node(intfc)) = oldn; next_node(oldn) = NULL; prev_node(oldn) = last_node(intfc); last_node(intfc) = oldn; next_old_node = next; } else next_old_node = NULL; if (newn != NULL) { intfc = newn->interface; next = next_node(newn); if (next == NULL) { screen("ERROR in reorder_node_loop(), " "next_node(newn) == NULL\n"); print_node(newn); if (oldn != NULL) { (void) printf("Old interface information\n"); print_linked_node_list(intfc); print_interface(intfc); } intfc = newn->interface; (void) printf("New interface information\n"); print_linked_node_list(intfc); print_interface(intfc); clean_up(ERROR); } prev = prev_node(newn); prev_node(next) = prev; if (prev != NULL) next_node(prev) = next; else first_node(intfc) = next; next_node(last_node(intfc)) = newn; next_node(newn) = NULL; prev_node(newn) = last_node(intfc); last_node(intfc) = newn; } return next_old_node; } /*end reorder_node_loop*/
/////////////////////////////////// /// Main function. /////////////////////////////////// int main(int argc, char** argv) { unsigned long game_start_time; //the game start time. unsigned long current_time; //current time. unsigned long test_start_time; // the test start time. unsigned long correct_order=0; //the correct order. unsigned long input_order=0; //the order inputed by player. int correct_count=0,wrong_count=0; int read_count=0; int test_num=1; char buffer[MAX_LENGTH]; //initialize the array to store numbers. int i=0; for (i=0;i<10;i++){ numbers[i]=-1; } printf("This is a memory-test game.\n"); sleep(1000); printf("There are 10 tests.\n"); sleep(1000); printf("In each test, some random numbers flash on the screan. You need to remember the order and rewrite them.\n"); sleep(3000); printf("At the end of this game, you can see the report of your performance.\n\n\n"); sleep(1000); printf("When you are ready, type \"y\"to begin the game. Type other letter to exit the game.\n"); read_count=read(STDIN_FILENO,buffer,MAX_LENGTH-1); if(!((buffer[0]=='y' || buffer[0] == 'Y') && read_count ==2)){ return 0; } game_start_time=time(); while(1){ while(test_num<=10){ //There are 10 tests. printf("test: %d\n",test_num); sleep(2000); //print the flashing numbers. print_interface(test_num); printf("\nPlease type the order of numbers(for example: 38257): "); test_start_time = time(); read_count = read(STDIN_FILENO,buffer,MAX_LENGTH-1); current_time = time(); buffer[read_count-1]=0; input_order = 0; for (i=0;i<10;i++){ if(buffer[i]==0) break; // Caculate the input order. input_order = input_order*10 + (int)buffer[i]-(int)'0'; } //printf("%lu\n",input_order); printf("Time spend: %lu.%lus\n",(current_time-test_start_time)/1000,(current_time-test_start_time)%1000/100); for(i=0;i<10;i++){ if(numbers[i]<0) break; //printf("numbers %d %d %lu\n",i,numbers[i],correct_order); //Caculate the correct order. correct_order = correct_order*10+numbers[i]; } printf("Correct order is: %lu\n",correct_order); //Chech if the input is correct. if(input_order==correct_order){ printf("Correct order.\n"); correct_count++; } else { printf("Oh on, wrong order.\n"); wrong_count++; } //clear up the numbers. for (i=0;i<10;i++){ numbers[i]=-1; } sleep(2000); correct_order=0; test_num++; } report_performance(correct_count,wrong_count); printf("\nPress 'y' to try again. Press others to exit."); read_count=read(STDIN_FILENO,buffer,MAX_LENGTH-1); if(!((buffer[0]=='y' || buffer[0] == 'Y') && read_count ==2)){ return 0; } test_num=1; } return 0; }
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*/ LIB_LOCAL bool long_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; /* Find Closest Point on Front: */ if (hs) { p_closest = Point_of_hs(hs); } else { float distance; /* Distance from (x) to a point */ float min_distance; /* Distance to Nearest point */ eq_comps = equivalent_components_list(comp,&n_eq,intfc); min_distance = HUGE_VAL; p_closest = NULL; for (p = intfc->points; p && (*p); ++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) { static int first = YES; (void) printf("WARNING in long_nearest_interface_point1d(), " "p_closest == NULL\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 " "long_nearest_interface_point1d()\n"); print_interface(intfc); } first = NO; return NO; } } *phs = Hyper_surf(p_closest); *phse = Hyper_surf_element(p_closest); ans[0] = Coords(p_closest)[0]; t[0] = 0.0; return YES; } /*end long_nearest_interface_point1d*/
int main_game_interface() { //int lolx=0, loly=0; //int city=-1; // sanity checks, do take care to see that they are always used whenever unit count changes int unitcount, citycount; int oldx, oldy; bool done = false; while (!done) { unitcount = count_units(); citycount = count_cities(); SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses /// BUG: Cursor goes off grid /// BUG: Cursor behaves strangely in relation to viewscreen around edges case SDL_KEYDOWN: { if (event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_KP4) { if (gs.selected_type == SELECTED_UNIT && gs.selected_thing >= 0) { oldx = gs.units[gs.selected_thing].x; gs.units[gs.selected_thing].x--; if (!sanitize_unit_coords(gs.selected_thing) && gs.units[gs.selected_thing].curmove > 0 && is_unit_allowed_there(gs.selected_thing)) { gs.units[gs.selected_thing].curmove--; gs.curx = gs.units[gs.selected_thing].x-5; gs.cury = gs.units[gs.selected_thing].y-3; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; // combat here detect_and_do_combat(gs.selected_thing); } else { gs.units[gs.selected_thing].x = oldx; } } else { gs.curx--; gs.selx--; } sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_RIGHT || event.key.keysym.sym == SDLK_KP6) { if (gs.selected_type == SELECTED_UNIT && gs.selected_thing >= 0) { oldx = gs.units[gs.selected_thing].x; gs.units[gs.selected_thing].x++; if (!sanitize_unit_coords(gs.selected_thing) && gs.units[gs.selected_thing].curmove > 0 && is_unit_allowed_there(gs.selected_thing)) { gs.units[gs.selected_thing].curmove--; gs.curx = gs.units[gs.selected_thing].x-5; gs.cury = gs.units[gs.selected_thing].y-3; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; // combat here detect_and_do_combat(gs.selected_thing); } else { gs.units[gs.selected_thing].x = oldx; } } else { gs.curx++; gs.selx++; } sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_KP8) { if (gs.selected_type == SELECTED_UNIT && gs.selected_thing >= 0) { oldy = gs.units[gs.selected_thing].y; gs.units[gs.selected_thing].y--; if (!sanitize_unit_coords(gs.selected_thing) && gs.units[gs.selected_thing].curmove > 0 && is_unit_allowed_there(gs.selected_thing)) { gs.units[gs.selected_thing].curmove--; gs.curx = gs.units[gs.selected_thing].x-5; gs.cury = gs.units[gs.selected_thing].y-3; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; // combat here detect_and_do_combat(gs.selected_thing); } else { gs.units[gs.selected_thing].y = oldy; } } else { gs.cury--; gs.sely--; } sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_DOWN || event.key.keysym.sym == SDLK_KP2) { if (gs.selected_type == SELECTED_UNIT && gs.selected_thing >= 0) { oldy = gs.units[gs.selected_thing].y; gs.units[gs.selected_thing].y++; if (!sanitize_unit_coords(gs.selected_thing) && gs.units[gs.selected_thing].curmove > 0 && is_unit_allowed_there(gs.selected_thing)) { gs.units[gs.selected_thing].curmove--; gs.curx = gs.units[gs.selected_thing].x-5; gs.cury = gs.units[gs.selected_thing].y-3; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; // combat here detect_and_do_combat(gs.selected_thing); } else { gs.units[gs.selected_thing].y = oldy; } } else { gs.cury++; gs.sely++; } sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_KP7) { // up-left if (gs.selected_type == SELECTED_UNIT && gs.selected_thing >= 0) { oldx = gs.units[gs.selected_thing].x; oldy = gs.units[gs.selected_thing].y; gs.units[gs.selected_thing].x--; gs.units[gs.selected_thing].y--; if (!sanitize_unit_coords(gs.selected_thing) && gs.units[gs.selected_thing].curmove > 0 && is_unit_allowed_there(gs.selected_thing)) { gs.units[gs.selected_thing].curmove--; gs.curx = gs.units[gs.selected_thing].x-5; gs.cury = gs.units[gs.selected_thing].y-3; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; // combat here detect_and_do_combat(gs.selected_thing); } else { gs.units[gs.selected_thing].x = oldx; gs.units[gs.selected_thing].y = oldy; } } else { gs.curx--; gs.cury--; gs.selx--; gs.sely--; } sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_KP9) { // up-right if (gs.selected_type == SELECTED_UNIT && gs.selected_thing >= 0) { oldx = gs.units[gs.selected_thing].x; oldy = gs.units[gs.selected_thing].y; gs.units[gs.selected_thing].x++; gs.units[gs.selected_thing].y--; if (!sanitize_unit_coords(gs.selected_thing) && gs.units[gs.selected_thing].curmove > 0 && is_unit_allowed_there(gs.selected_thing)) { gs.units[gs.selected_thing].curmove--; gs.curx = gs.units[gs.selected_thing].x-5; gs.cury = gs.units[gs.selected_thing].y-3; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; // combat here detect_and_do_combat(gs.selected_thing); } else { gs.units[gs.selected_thing].x = oldx; gs.units[gs.selected_thing].y = oldy; } } else { gs.curx++; gs.cury--; gs.selx++; gs.sely--; } sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_KP1) { // down-left if (gs.selected_type == SELECTED_UNIT && gs.selected_thing >= 0) { oldx = gs.units[gs.selected_thing].x; oldy = gs.units[gs.selected_thing].y; gs.units[gs.selected_thing].x--; gs.units[gs.selected_thing].y++; if (!sanitize_unit_coords(gs.selected_thing) && gs.units[gs.selected_thing].curmove > 0 && is_unit_allowed_there(gs.selected_thing)) { gs.units[gs.selected_thing].curmove--; gs.curx = gs.units[gs.selected_thing].x-5; gs.cury = gs.units[gs.selected_thing].y-3; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; // combat here detect_and_do_combat(gs.selected_thing); } else { gs.units[gs.selected_thing].x = oldx; gs.units[gs.selected_thing].y = oldy; } } else { gs.curx--; gs.cury++; gs.selx--; gs.sely++; } sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_KP3) { // down-right if (gs.selected_type == SELECTED_UNIT && gs.selected_thing >= 0) { oldx = gs.units[gs.selected_thing].x; oldy = gs.units[gs.selected_thing].y; gs.units[gs.selected_thing].x++; gs.units[gs.selected_thing].y++; if (!sanitize_unit_coords(gs.selected_thing) && gs.units[gs.selected_thing].curmove > 0 && is_unit_allowed_there(gs.selected_thing)) { gs.units[gs.selected_thing].curmove--; gs.curx = gs.units[gs.selected_thing].x-5; gs.cury = gs.units[gs.selected_thing].y-3; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; // combat here detect_and_do_combat(gs.selected_thing); } else { gs.units[gs.selected_thing].x = oldx; gs.units[gs.selected_thing].y = oldy; } } else { gs.curx++; gs.cury++; gs.selx++; gs.sely++; } sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_c) { // cycle city // find the next extant city // sanity check for now, redo later if (gs.selected_type == SELECTED_UNIT || gs.selected_type == -1 || gs.selected_thing == -1) { gs.selected_type = SELECTED_CITY; gs.selected_thing = -1; } if (citycount == 0) break; do { gs.selected_thing++; if (gs.selected_thing >= MAX_CITIES) gs.selected_thing = 0; gs.curx = gs.cities[gs.selected_thing].x; gs.cury = gs.cities[gs.selected_thing].y; gs.selx = gs.cities[gs.selected_thing].x; gs.sely = gs.cities[gs.selected_thing].y; } while (gs.cities[gs.selected_thing].size < 1 || gs.cities[gs.selected_thing].faction_id != gs.player_faction); gs.curx -= 5; gs.cury -= 3; sanitize_coords(); print_map(gs.curx,gs.cury); break; } if (event.key.keysym.sym == SDLK_u) { // cycle unit // find the next extant unit // sanity check for now, redo later if (gs.selected_type == SELECTED_CITY || gs.selected_type == -1 || gs.selected_thing == -1) { gs.selected_type = SELECTED_UNIT; gs.selected_thing = -1; } if (unitcount == 0) break; // no active units, go away // finds the closest active unit and centers on it do { gs.selected_thing++; if (gs.selected_thing >= MAX_UNITS) gs.selected_thing = 0; gs.curx = gs.units[gs.selected_thing].x; gs.cury = gs.units[gs.selected_thing].y; gs.selx = gs.units[gs.selected_thing].x; gs.sely = gs.units[gs.selected_thing].y; } while (gs.units[gs.selected_thing].active == UNIT_INACTIVE); gs.curx -= 5; gs.cury -= 3; sanitize_coords(); print_map(gs.curx,gs.cury); break; } // Build city command! if (event.key.keysym.sym == SDLK_b) { // make sure a unit is actually selected and can build if (gs.selected_type != SELECTED_UNIT) break; // no unit selected if (gs.selected_thing == -1) break; // nothing selected if ((gs.units[gs.selected_thing].flags&UNIT_FLAG_SETTLER) == 0) break; // unit can't build /// TODO: Checks for if there is a city too close gs.units[gs.selected_thing].hp = 0; // kill the unit // build the city build_new_city(gs.units[gs.selected_thing].x,gs.units[gs.selected_thing].y,gs.units[gs.selected_thing].faction_id); break; } if (event.key.keysym.sym == SDLK_p) { // production if (gs.selected_type != SELECTED_CITY) break; // no city selected if (gs.selected_thing == -1) break; // nothing selected // placeholder code until I can think of something better // toggles production of random unit if (gs.cities[gs.selected_thing].production_order == CITY_NO_PRODUCTION) { gs.cities[gs.selected_thing].production_order = rand()%65536; // fix this later, should be a parameter or something gs.cities[gs.selected_thing].production_type = rand()%3+1; // random type } else { gs.cities[gs.selected_thing].production_order = CITY_NO_PRODUCTION; } } if (event.key.keysym.sym == SDLK_s) { // save return CODE_SAVE_GAME; } if (event.key.keysym.sym == SDLK_ESCAPE) { // quit return CODE_MAIN_MENU; } if (event.key.keysym.sym == SDLK_BACKSPACE) { // turn // end turn hack do_turn(); break; } } } // end switch } // end of message processing print_map(gs.curx,gs.cury); print_interface(); SDL_Flip(MAIN_SCREEN); SDL_Delay(100); } return 0; }
/*ARGSUSED*/ EXPORT void get_state_1d_overlay( float *coords, Locstate s, COMP_TYPE *ct, HYPER_SURF *hs, INTERFACE *intfc, INIT_DATA *init, int stype) { ONED_OVERLAY *olay = (ONED_OVERLAY*)ct->extra; INPUT_SOLN **is = olay->is; RECT_GRID *gr = &is[0]->grid; INTERFACE *intfc1d = olay->intfc1d; float x, coords1d[3], m, sp; float dcoords[3]; float c0[3], c1[3]; float alpha; int i0[3], i1[3], i, dim = ct->params->dim; int nvars = olay->prt->n_restart_vars; static Locstate s0 = 0, s1 = 0; debug_print("init_states","Entered get_state_1d_overlay()\n"); if (s0 == NULL) { (*ct->params->_alloc_state)(&s0,ct->params->sizest); (*ct->params->_alloc_state)(&s1,ct->params->sizest); } for (i = 0; i < dim; ++i) dcoords[i] = coords[i] - olay->origin[i]; switch (olay->overlay_type) { case RADIAL_OVERLAY: x = mag_vector(dcoords,dim); break; case CYLINDRICAL_OVERLAY: sp = scalar_product(dcoords,olay->direction,dim); for (i = 0; i < dim; ++i) dcoords[i] -= sp*olay->direction[i]; x = mag_vector(dcoords,dim); break; case RECTANGULAR_OVERLAY: x = scalar_product(dcoords,olay->direction,dim); break; case OVERLAY_TYPE_UNSET: default: x = -HUGE_VAL; screen("ERROR in get_state_1d_overlay(), unset overlay type\n"); clean_up(ERROR); break; } if (x > gr->U[0]) x = gr->U[0]; if (x < gr->L[0]) x = gr->L[0]; coords1d[0] = x; if (rect_in_which(coords1d,i0,gr) == FUNCTION_FAILED) { screen("ERROR in get_state_1d_overlay(), rect_in_which() failed\n"); print_general_vector("dcoords = ",dcoords,dim,"\n"); (void) printf("overlay type = %d, x = %g\n",olay->overlay_type,x); (void) printf("rectangular grid gr\n"); print_rectangular_grid(gr); (void) printf("One dimensional interface\n"); print_interface(intfc1d); clean_up(ERROR); } c0[0] = cell_center(i0[0],0,gr); if (x < c0[0]) { i1[0] = i0[0]; i0[0]--; if (i0[0] < 0) i0[0] = 0; c1[0] = c0[0]; c0[0] = cell_center(i0[0],0,gr); } else { i1[0] = i0[0] + 1; if (i1[0] >= gr->gmax[0]) i1[0] = i0[0]; c1[0] = cell_center(i1[0],0,gr); } if (component(c0,intfc1d) != ct->comp) { set_oned_state_from_interface(c0,s0,ct,olay); } else { g_restart_initializer(i0,nvars,ct->comp,is,s0,init); Init_params(s0,ct->params); } if (component(c1,intfc1d) != ct->comp) { set_oned_state_from_interface(c1,s1,ct,olay); } else { g_restart_initializer(i1,nvars,ct->comp,is,s1,init); Init_params(s1,ct->params); } alpha = (c1[0] > c0[0]) ? (x - c0[0])/(c1[0] - c0[0]) : 0.5; ct->params->dim = 1; interpolate_states(olay->front,1.0-alpha,alpha,c0,s0,c1,s1,s); ct->params->dim = dim; m = Mom(s)[0]; switch (olay->overlay_type) { case RADIAL_OVERLAY: case CYLINDRICAL_OVERLAY: if (x > 0.0) { for (i = 0; i < dim; ++i) Mom(s)[i] = m*dcoords[i]/x; } else { for (i = 0; i < dim; ++i) Mom(s)[i] = 0.0; } break; case RECTANGULAR_OVERLAY: for (i = 0; i < dim; ++i) Mom(s)[i] = m*olay->direction[i]; break; case OVERLAY_TYPE_UNSET: default: screen("ERROR in get_state_1d_overlay(), unset overlay type\n"); clean_up(ERROR); break; } set_state(s,stype,s); } /*end get_state_1d_overlay*/
EXPORT int collect_pcs_in_mesh2d(TRI_GRID *ntg) { int xmax; int ymax; struct Table *T; P_LINK *hash_table; Locstate *states; COMPONENT *comp; TG_PT *node_pts; BLK_EL0 *blk_el0; BOND ****by; BOND ***byx; CURVE ****cy,***cyx; POINT_COMP_ST *pcs; int ix, iy, l; int **nby, *nbyx; int *offset = ntg->offset; int num_pcs = 0; int h_size; #if defined(DEBUG_TRI_GRID) debug_print("collect_pcs_in_mesh2d", "make_bond_comp_list"); #endif /* defined(DEBUG_TRI_GRID) */ set_dual_interface_topology(ntg); ntg->_locate_on_trigrid = tg_build; #if defined(DEBUG_TRI_GRID) debug_print("collect_pcs_in_mesh2d", "to count_num_pcs2d"); #endif /* defined(DEBUG_TRI_GRID) */ ntg->n_pcs = count_num_pcs2d(ntg); VECTOR(ntg,pcs,ntg->n_pcs,sizeof(POINT_COMP_ST)); T = table_of_interface(ntg->grid_intfc); xmax = ntg->rect_grid.gmax[0]; ymax = ntg->rect_grid.gmax[1]; /* Allocate space for hashing table */ /*P_LINK (int.h) pair of left and right states */ h_size = (ntg->grid_intfc->num_points)*4+1; uni_array(&hash_table,h_size,sizeof(P_LINK)); #if defined(DEBUG_TRI_GRID) debug_print("collect_pcs_in_mesh2d", "to copy_tg_pts_from_intfc"); #endif /* defined(DEBUG_TRI_GRID) */ copy_tg_pts_from_intfc(ntg,hash_table,h_size); /* set the pcs's */ comp = T->components; states = ntg->states; node_pts = ntg->node_points; blk_el0 = ntg->blk_els0; #if defined(DEBUG_TRI_GRID) debug_print("collect_pcs_in_mesh2d", "to set the pcs's"); #endif /* defined(DEBUG_TRI_GRID) */ for (iy = 0, nby = T->num_of_bonds, by = T->bonds, cy = T->curves; iy < ymax; ++iy, ++nby, ++by, ++cy) { for (ix = 0, nbyx = *nby, byx = *by, cyx = *cy; ix < xmax; ++ix, ++nbyx, ++byx, ++cyx) { pcs = blk_el0_pcs_els(blk_el0) = &(ntg->pcs[num_pcs]); if (*nbyx != 0) { for (l = 0; l < 4; ++l) { pcs[l].p = node_pts + offset[l]; pcs[l].comp[0] = comp[offset[l]]; pcs[l].s[0] = states[offset[l]]; pcs[l].comp[1] = NO_COMP; pcs[l].s[1] = NULL; } num_pcs_els_in_blk(blk_el0) = 4; add_intfc_blk_pcs2d(*nbyx,*byx,*cyx,blk_el0, hash_table,h_size); num_pcs += num_pcs_els_in_blk(blk_el0); } else { set_bilinear_blk_el0(blk_el0); pcs[0].p = node_pts; pcs[0].comp[0] = comp[0]; pcs[0].s[0] = states[0]; pcs[0].comp[1] = NO_COMP; pcs[0].s[1] = NULL; ++num_pcs; } ++node_pts; ++states; ++comp; ++blk_el0; } ++node_pts; ++states; ++comp; /* if (iy < ymax -1) { node_pts += xmax+1; states += xmax+1; comp += xmax+1; } */ } free(hash_table); #if defined(DEBUG_TRI_GRID) if (debugging("collect_pcs_in_mesh2d")) { int i; int icoords[MAXD]; float *coords; (void) printf("\t\t PRINTING PCS:\n"); for (i=0;i<ntg->n_pcs ;++i) { coords = (float*)(ntg->pcs[i].p); if (rect_in_which(coords,icoords,&(ntg->rect_grid))) { (void) printf("%d: icoords[%d,%d] ", i,icoords[0],icoords[1]); (void) printf("comp[0] = %d, comp[1] = %d \n", ntg->pcs[i].comp[0],ntg->pcs[i].comp[1]); } else { (void) printf("rect_in_which failed for this pcs\n"); (void) printf("%d: comp[0] = %d, comp[1] = %d \n", i,ntg->pcs[i].comp[0],ntg->pcs[i].comp[1]); } (void) printf("(%g,%g)\n", coords[0],coords[1]); } (void) printf("\t\n\n PRINTING BLK_EL0:\n"); for (icoords[0] = 0; icoords[0] < ntg->rect_grid.gmax[0]; ++icoords[0]) { for (icoords[1] = 0; icoords[1] < ntg->rect_grid.gmax[1]; ++icoords[1]) { blk_el0 = &Blk_el0(icoords,ntg); (void) printf("blk_el0[%d,%d] = %llu\n", icoords[0],icoords[1], ptr2ull(blk_el0)); (void) printf("num_pcs_els_in_blk = %d\n", num_pcs_els_in_blk(blk_el0)); for (i = 0; i < num_pcs_els_in_blk(blk_el0); ++i) { (void) printf("%d: (%g, %g)\n",i, Coords(blk_el0_pcs_els(blk_el0)[i].p)[0], Coords(blk_el0_pcs_els(blk_el0)[i].p)[1]); } } } } if (debugging("tri_grid")) { (void) printf("Grid interface AFTER collect_pcs_in_mesh2d()\n"); print_interface(ntg->grid_intfc); } #endif /* defined(DEBUG_TRI_GRID) */ return GOOD_STEP; } /*end collect_pcs_in_mesh2d*/
/*ARGSUSED*/ EXPORT INTERFACE *i_zoom_interface( INTERFACE *given_intfc, RECT_GRID *gr, double *L, double *U, double **Q) { INTERFACE *cur_intfc; INTERFACE *zoom_intfc; RECT_GRID *t_gr; int dim = given_intfc->dim; int i, j; double **Qi = NULL; static double **pc = NULL; debug_print("zoom","Entered zoom_interface()\n"); cur_intfc = current_interface(); if ((zoom_intfc = copy_interface(given_intfc)) == NULL) { Error(ERROR,"Unable to copy interface."); clean_up(ERROR); } if (debugging("zoom")) { (void) output(); (void) printf("INTERFACE before zoom:\n\n"); print_interface(zoom_intfc); } if (Q != NULL) { static double** M = NULL; if (M == NULL) bi_array(&M,MAXD,MAXD,FLOAT); Qi = M; for (i = 0; i < dim; i++) for (j = 0; j < dim; j++) Qi[i][j] = Q[j][i]; } if (pc == NULL) bi_array(&pc,MAXNCORNERS,MAXD,FLOAT); calculate_box(L,U,pc,Q,Qi,dim); /* Shrink topological grid to cutting boundary */ t_gr = &topological_grid(zoom_intfc); rotate_and_zoom_rect_grid(t_gr,L,U,Q); switch(dim) { case 1: /* TODO */ return NULL; case 2: insert_cuts_and_bdry2d(zoom_intfc,pc); clip_interface2d(zoom_intfc); break; case 3: /* TODO */ return NULL; } rotate_interface(zoom_intfc,pc[0],Qi); if (set_boundary(zoom_intfc,t_gr,component(pc[0],given_intfc), grid_tolerance(gr) != FUNCTION_SUCCEEDED)) { screen("ERROR in i_zoom_interface(), set_boundary failed\n"); clean_up(ERROR); } set_current_interface(cur_intfc); if (debugging("zoom")) { (void) printf("INTERFACE after zoom:\n\n"); print_interface(zoom_intfc); } debug_print("zoom","Leaving zoom_interface()\n"); return zoom_intfc; } /*end i_zoom_interface*/
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*/
EXPORT int check_comps_at_nodes( INTERFACE *intfc, O_NODE **onode_list) { NODE **n; O_NODE O_node; O_NODE *onode, *on; COMPONENT compi, compj; int i, j; int num_inconsistent = 0; debug_print("ccn","Entered check_comps_at_nodes()\n"); O_node.prev = O_node.next = NULL; on = &O_node; if (intfc->dim != 2) return 0; for (n = intfc->nodes; n && *n; ++n) { onode = make_onode(*n); for (i = 0; i < onode->num_c; ++i) { j = (i + 1) % onode->num_c; if (onode->orient[i] == POSITIVE_ORIENTATION) compi = negative_component(onode->nc[i]); else compi = positive_component(onode->nc[i]); if (onode->orient[j] == POSITIVE_ORIENTATION) compj = positive_component(onode->nc[j]); else compj = negative_component(onode->nc[j]); if (compi != compj) { if (debugging("inconsis")) { char xname[100]; double radius = 3.0*topological_grid(intfc).h[0]; int ii,jj; print_node(*n); sprintf(xname,"inconsis_comp-%d-%d",pp_mynode(), num_inconsistent); xgraph_2d_intfc_within_range(xname,intfc, Coords((*n)->posn),radius,NO); for (ii = 0; ii < onode->num_c; ++ii) { jj = (ii + 1) % onode->num_c; if (onode->orient[ii] == POSITIVE_ORIENTATION) compi = negative_component(onode->nc[ii]); else compi = positive_component(onode->nc[ii]); if (onode->orient[jj] == POSITIVE_ORIENTATION) compj = positive_component(onode->nc[jj]); else compj = negative_component(onode->nc[jj]); printf("compi = %d\n",compi); printf("compj = %d\n",compj); print_curve(onode->nc[jj]); } } ++num_inconsistent; on->next = onode; onode->prev = on; on = onode; break; } } } if (onode_list!= NULL) { *onode_list = O_node.next; if (*onode_list) (*onode_list)->prev = NULL; } if ((num_inconsistent > 0) && debugging("ccn")) { (void) printf("Inconsistent components found at nodes\n"); for (onode = *onode_list; onode != NULL; onode = onode->next) print_onode(onode); print_interface(intfc); } debug_print("ccn","Left check_comps_at_nodes(), num_inconsistent = %d\n", num_inconsistent); return num_inconsistent; } /*end check_comps_at_node*/
EXPORT int redistribute1d( Front *fr) { CROSS *cross; INTERFACE *intfc = fr->interf; boolean istatus; int flag = NORMAL_ATTEMPT_TO_UNTANGLE; int status; debug_print("redist1d","Entered redistribute1d()\n"); istatus = intersections(intfc,&cross,YES); if (istatus == FUNCTION_FAILED) { (void) printf("WARNING in redistribute1d(), " "intersections() failed\n"); } if (pp_min_status(istatus) == FUNCTION_FAILED) { if (istatus == FUNCTION_SUCCEEDED) { (void) printf("WARNING in redistribute1d(), " "intersections() failed on remote node\n"); } if (debugging("redist1d")) { (void) printf("WARNING in redistribute1d(), " "intersections() failed\n"); } debug_print("redist1d","Left redistribute1d()\n"); return BAD_REDISTRIBUTION; } if (interface_is_tangled(cross) == NO) { debug_print("redist1d","Left redistribute1d()\n"); return GOOD_REDISTRIBUTION; } (void) print_number_of_tangles("",intfc,cross); if (fr->fr_bdry_untangle) { if (debugging("redist1d")) (void) printf("Attempting to untangle boundary interactions\n"); status = (cross == NULL) ? CURVES_UNTANGLED : (*fr->fr_bdry_untangle)(fr,&cross, NULL,NULL,flag); status = synchronize_untangle_status(status); if (status != CURVES_UNTANGLED) { (void) printf("WARNING in redistribute1d(), " "unable to untangle boundary tangles\n"); debug_print("redist1d","Left redistribute1d()\n"); return BAD_REDISTRIBUTION; } } if (interface_is_tangled(cross) == NO) { debug_print("redist1d","Left redistribute1d()\n"); return GOOD_REDISTRIBUTION; } if (fr->untangle_front) { if (debugging("redist1d")) (void) printf("Attempting to untangle interior interactions\n"); status = (cross==NULL) ? CURVES_UNTANGLED : (*fr->untangle_front)(fr,&cross,flag); status = synchronize_untangle_status(status); switch (status) { case CURVES_UNTANGLED: break; case MODIFY_TIME_STEP_TO_UNTANGLE: (void) printf("WARNING in redistributed1d, " "fr->untangle_front returns \n" "\t\tMODIFY_TIME_STEP_TO_UNTANGLE\n"); debug_print("redist1d","Left redistribute1d()\n"); return MODIFY_TIME_STEP_REDISTRIBUTE; default: (void) printf("WARNING in redistribute1d(), " "unable to untangle interior tangles\n"); debug_print("redist1d","Left redistribute1d()\n"); return BAD_REDISTRIBUTION; } } if (interface_is_tangled(cross) == YES) { (void) printf("WARNING in redistribute1d(), " "unable to untangle interface\n"); print_intersections(cross,intfc); debug_print("redist1d","Left redistribute1d()\n"); return BAD_REDISTRIBUTION; } if (consistent_components1d(intfc) == NO) { screen("ERROR in redistribute1d(), " "inconsistent components\n"); print_interface(intfc); clean_up(ERROR); debug_print("redist1d","Left redistribute1d()\n"); return BAD_REDISTRIBUTION; } if (debugging("redist1d")) { (void) printf("Untangled interface\n"); print_interface(fr->interf); } debug_print("redist1d","Left redistribute1d()\n"); return GOOD_REDISTRIBUTION; } /*end redistribute1d*/