void calc_dist(int col, int row) { int lv, lv2; /* loop variables */ int d; /* current distance being checked */ int max; /* maximum finite distance found so far */ int f; /* temporary variable (returned value from do_step */ /* initiate all positions to be infinite distance away */ for (lv = 0; lv < ncol; lv++) for (lv2 = 0; lv2 < nrow; lv2++) dist[lv][lv2][0] = dist[lv][lv2][1] = MAXN; /* starting location is zero w/o king, kdist[col][row] with king */ dist[col][row][0] = 0; max = dist[col][row][1] = kdist[col][row]; for (d = 0; d <= max; d++) { /* for each distance away */ for (lv = 0; lv < ncol; lv++) for (lv2 = 0; lv2 < nrow; lv2++) { /* for each position that distance away */ if (dist[lv][lv2][0] == d) { /* update with moves through this square */ f = do_step(lv, lv2, 0); if (d + f > max) /* update max if necessary */ max = d + f; } if (dist[lv][lv2][1] == d) { /* same as above, except this time knight has king */ f = do_step(lv, lv2, 1); if (d + f > max) max = d + f; } } } }
int main(){ mtsl_init(); #ifndef __SIMULATION_MODE__ pthread_t th0, th1; pthread_mutex_init( &mutex_lock, NULL ); pthread_create( &th0, NULL, (void*)th_advert, NULL ); sleep( ADVERT_BASE_PERIOD ); pthread_create( &th1, NULL, (void*)th_recv, NULL ); #endif while(1){ // this is the main thread led3_toggle(); #ifdef __SIMULATION_MODE__ do_step(); report(); #else if( my_info.level < MTSL_LEVEL3 ) continue; pthread_mutex_lock( &mutex_lock ); mtsl_ranging(); mtsl_dist_filtering(); fill_anchor(); self_pos(); report(); pthread_mutex_unlock( &mutex_lock ); #endif sleep( RANGING_BASE_PERIOD ); } return 0; }
void System::solve(double MaxTime, double dt, state_t ini) { double time = 0; vars.swap(ini); while (time < MaxTime) { switch(stepper_kind){ case STEPPER_RK4: rk4_stepper.do_step(rhs_implicit_active, vars, time, dt); break; case STEPPER_RK_FEHLBERG78: rk_fehlberg_stepper.do_step(rhs_implicit_active, vars, time, dt); break; case STEPPER_ROSENBROCK4: rosenbrock4_stepper.do_step(ode_explicit_pair, vars, time, dt); break; case STEPPER_RK_CK54: rk_ck54_stepper.do_step(rhs_implicit_active, vars, time, dt); break; case STEPPER_RK4_OWN: do_step(dt,time); break; } for (auto &a : analyzers) { a->addPoint(vars, time); } time += dt; } }
static ERL_NIF_TERM evaluate_command(esqlite_command *cmd, esqlite_connection *conn) { switch(cmd->type) { case cmd_open: return do_open(cmd->env, conn, cmd->arg); case cmd_exec: return do_exec(cmd->env, conn, cmd->arg); case cmd_changes: return do_changes(cmd->env, conn, cmd->arg); case cmd_prepare: return do_prepare(cmd->env, conn, cmd->arg); case cmd_step: return do_step(cmd->env, conn->db, cmd->stmt); case cmd_reset: return do_reset(cmd->env, conn->db, cmd->stmt); case cmd_bind: return do_bind(cmd->env, conn->db, cmd->stmt, cmd->arg); case cmd_column_names: return do_column_names(cmd->env, cmd->stmt); case cmd_close: return do_close(cmd->env, conn, cmd->arg); case cmd_insert: return do_insert(cmd->env, conn, cmd->arg); default: return make_error_tuple(cmd->env, "invalid_command"); } }
static int tilib_ctl(device_t dev_base, device_ctl_t op) { struct tilib_device *dev = (struct tilib_device *)dev_base; switch (op) { case DEVICE_CTL_RESET: if (dev->MSP430_Reset(RST_RESET, 0, 0) < 0) { report_error(dev, "MSP430_Reset"); return -1; } return 0; case DEVICE_CTL_RUN: if (refresh_bps(dev) < 0) return -1; if (dev->MSP430_Run(RUN_TO_BREAKPOINT, 0) < 0) { report_error(dev, "MSP430_Run"); return -1; } break; case DEVICE_CTL_HALT: return do_halt(dev); case DEVICE_CTL_STEP: return do_step(dev); } return 0; }
int main(int argc, char **argv) { pid_t pid; if(argc < 2) { fprintf(stderr, "USAGE: %s PROGRAM ARGS...\n", argv[0]); exit(1); } if((pid = fork()) < 0) { perror("fork"); exit(1); } else if(pid == 0) { char *env[] = { NULL }; if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) { perror("ptrace"); exit(1); } if(execve(argv[1], argv+1, env) < 0) { perror("execve"); exit(1); } } /* Parent. */ do_step(pid); return 0; }
int main(int argc,char* argv[]) { SDL_Surface* screen=SDL_SetVideoMode(SIZE,SIZE,32,SDL_DOUBLEBUF); if(screen==NULL)return 1; init_terrain(); while(!SDL_GetKeyState(NULL)[SDLK_SPACE]) { SDL_PumpEvents(); draw_terrain(screen); do_step(); SDL_Flip(screen); int x,y; for(y=0;y<SIZE;y++) for(x=0;x<SIZE;x++) { float val=terrain[x][y].height; write(STDOUT_FILENO,&val,sizeof(float)); val=terrain[x][y].water.depth; write(STDOUT_FILENO,&val,sizeof(float)); } } return 0; }
void do_step( DynamicalSystem &system , container_type &x , time_type t , time_type dt ) { system( x , m_dxdt , t ); do_step( system , x , m_dxdt , t , dt ); }
void his_step() { chip damka; if (HisColor == White) damka = WDamka; else damka = BDamka; click_x = hishod[3 + 2*hishod_part] - 65; click_y = hishod[4 + 2*hishod_part] - 49; hishod_part++; if (board[click_y][click_x] == None) { byte step_status = do_step(click_x, click_y, HisColor); if (step_status > 0) { apply_select(selected_x, selected_y, 0); chip old_chip = board[selected_y][selected_x]; board[selected_y][selected_x] = None; apply_color(selected_x, selected_y); board[click_y][click_x] = old_chip; if (step_status == 2 && can_eat(click_x, click_y, HisColor)) { // 2 - возможен повторный ход, т.к. предыдущий был рубкой. apply_color(click_x, click_y); apply_select(click_x, click_y, 1); if ((HisColor == White && click_y == 7) || (HisColor == Black && click_y == 0)) futureDamka = 1; if (hishod_part < hishod_len) { his_step(); } else { debug_print("his_step error4", 15, 6); error(); } } else { if (futureDamka || (HisColor == White && click_y == 7) || (HisColor == Black && click_y == 0)) board[click_y][click_x] = damka; apply_color(click_x, click_y); forbidden_direction = DNone; if (hishod_part == hishod_len) { if (game_over()) { ggs = GGNEW; } else { if (HisColor == White) ggs = GGStartStepBlack; else ggs = GGStartStepWhite; } Mouse_Clc_Restart(); } else { debug_print("his_step error3", 15, 6); error(); } } } else { debug_print("his_step error2", 15, 6); error(); } } else { debug_print("his_step error1", 15, 6); error(); } }
int main(int argc, char **argv) { int c, i, j, tapA, tapB; int *scratch; int tapAcoords[1], tapBcoords[1]; FILE *fpA, *fpB, *fpAt, *fpBt; srandom(time(NULL)); PHYSMOD = calloc(1, sizeof(physmod_t)); init(PHYSMOD); fpA = fopen("outA.dat", "wb"); fpB = fopen("outB.dat", "wb"); fpAt = fopen("outA.txt", "w"); fpBt = fopen("outB.txt", "w"); /* The "taps" (locations where we record the output of our simulation) are the one place we still use a hardcoded number of dimensions. This must be fixed. */ tapAcoords[0] = PHYSMOD->dimsize[0]/4; tapAcoords[1] = PHYSMOD->dimsize[1]/4; tapAcoords[2] = PHYSMOD->dimsize[2]/4; tapAcoords[3] = PHYSMOD->dimsize[3]/4; tapA = combine_coords(PHYSMOD, tapAcoords); tapBcoords[0] = 3*PHYSMOD->dimsize[0]/4; tapBcoords[1] = 3*PHYSMOD->dimsize[1]/4; tapBcoords[2] = 3*PHYSMOD->dimsize[2]/4; tapBcoords[3] = 3*PHYSMOD->dimsize[3]/4; tapB = combine_coords(PHYSMOD, tapBcoords); /* dynamically allocate scratch space for all threads */ scratch = calloc(2 * PHYSMOD->dimcount * omp_get_max_threads(), sizeof(int)); printf("max threads: %d\n", omp_get_max_threads()); for (j=0 ; j<16; j++) { for (i=0 ; i<1024*64; i++) { do_step(PHYSMOD, scratch); fwrite( PHYSMOD->position + tapA, sizeof(MYFLT), 1, fpA); fprintf(fpAt, "%f\n", (PHYSMOD->position)[tapA]); fwrite( PHYSMOD->position + tapB, sizeof(MYFLT), 1, fpB); fprintf(fpBt, "%f\n", (PHYSMOD->position)[tapB]); } fflush(NULL); printf("%6d samples written\n", (j+1)*1024*64); } fclose(fpA); fclose(fpB); }
void path_slicert::operator()( const abstract_functionst &abstract_functions, abstract_counterexamplet &abstract_counterexample) { #ifdef DEBUG std::cout << "Path slicer START" << std::endl; #endif // build function map for(abstract_functionst::function_mapt::const_iterator f_it=abstract_functions.function_map.begin(); f_it!=abstract_functions.function_map.end(); f_it++) { for(abstract_programt::const_targett i_it=f_it->second.body.instructions.begin(); i_it!=f_it->second.body.instructions.end(); i_it++) function_map[i_it]=f_it; } string_sett dependencies; { // last one must be assertion assert(!abstract_counterexample.steps.empty()); assert(abstract_counterexample.steps.back().has_pc); // get concrete statement const goto_programt::instructiont &instruction= *abstract_counterexample.steps.back().pc->code.concrete_pc; assert(instruction.is_assert()); // fill up dependencies add_dependencies(instruction.guard, dependencies); } #ifdef DEBUG std::cout << "***********\n"; std::cout << dependencies; std::cout << "***********\n"; #endif // go backwards for(abstract_counterexamplet::stepst::reverse_iterator it=abstract_counterexample.steps.rbegin(); it!=abstract_counterexample.steps.rend(); it++) do_step(abstract_functions, dependencies, *it); }
double MonteCarlo::do_optimize(unsigned int max_steps) { IMP_OBJECT_LOG; IMP_CHECK_OBJECT(this); if (get_number_of_movers() == 0) { IMP_THROW("Running MonteCarlo without providing any" << " movers isn't very useful.", ValueException); } ParticleIndexes movable = get_movable_particles(); // provide a way of feeding in this value last_energy_ = do_evaluate(movable); if (return_best_) { best_ = new Configuration(get_model()); best_energy_ = last_energy_; } reset_statistics(); update_states(); IMP_LOG_TERSE("MC Initial energy is " << last_energy_ << std::endl); for (unsigned int i = 0; i < max_steps; ++i) { if (get_stop_on_good_score() && get_scoring_function()->get_had_good_score()) { break; } do_step(); if (best_energy_ < get_score_threshold()) break; } IMP_LOG_TERSE("MC Final energy is " << last_energy_ << std::endl); if (return_best_) { // std::cout << "Final score is " << get_model()->evaluate(false) //<< std::endl; best_->swap_configuration(); IMP_LOG_TERSE("MC Returning energy " << best_energy_ << std::endl); IMP_IF_CHECK(USAGE) { IMP_LOG_TERSE("MC Got " << do_evaluate(get_movable_particles()) << std::endl); /*IMP_INTERNAL_CHECK((e >= std::numeric_limits<double>::max() && best_energy_ >= std::numeric_limits<double>::max()) || std::abs(best_energy_ - e) < .01+.1* std::abs(best_energy_ +e), "Energies do not match " << best_energy_ << " vs " << e << std::endl);*/ } return do_evaluate(movable); } else { return last_energy_;
static void handle_sync_message (GstBus * bus, GstMessage * message, gpointer data) { GstElement *bin; bin = GST_ELEMENT_CAST (data); switch (message->type) { case GST_MESSAGE_STEP_DONE: do_step (bin); break; default: break; } }
int main (int argc, char *argv[]) { GstElement *bin; GstBus *bus; gst_init (&argc, &argv); if (argc < 2) { g_print ("usage: %s <uri>\n", argv[0]); return -1; } /* create a new bin to hold the elements */ bin = gst_element_factory_make ("playbin", "bin"); g_assert (bin); g_object_set (bin, "uri", argv[1], NULL); bus = gst_pipeline_get_bus (GST_PIPELINE (bin)); gst_bus_add_signal_watch (bus); gst_bus_enable_sync_message_emission (bus); g_signal_connect (bus, "message", (GCallback) handle_message, bin); g_signal_connect (bus, "sync-message", (GCallback) handle_sync_message, bin); /* go to the PAUSED state and wait for preroll */ g_message ("prerolling first frame"); gst_element_set_state (bin, GST_STATE_PAUSED); gst_element_get_state (bin, NULL, NULL, -1); /* queue step */ do_step (bin); gst_element_set_state (bin, GST_STATE_PLAYING); loop = g_main_loop_new (NULL, TRUE); g_main_loop_run (loop); g_message ("finished"); /* stop the bin */ gst_element_set_state (bin, GST_STATE_NULL); g_main_loop_unref (loop); gst_object_unref (bus); exit (0); }
int main(int argc, char** argv) { if (argc > 1) { if (strcmp(argv[1], "step") == 0) { do_step(); exit(0); } } printf("connect port=%d\n", PORTNO); do_default(); return 0; }
double Simulator::do_simulate(double time) { IMP_FUNCTION_LOG; set_was_used(true); ParticleIndexes ps = get_simulation_particle_indexes(); setup(ps); double target = current_time_ + time; boost::scoped_ptr<boost::progress_display> pgs; if (get_log_level() == PROGRESS) { pgs.reset(new boost::progress_display(time / max_time_step_)); } while (current_time_ < target) { last_time_step_ = do_step(ps, max_time_step_); current_time_ += last_time_step_; update_states(); if (get_log_level() == PROGRESS) { ++(*pgs); } } return Optimizer::get_scoring_function()->evaluate(false); }
void step(chip color) { chip damka; if (color == White) damka = WDamka; else damka = BDamka; if (mc == MCBoard) { if (board[click_y][click_x] == None) { byte step_status = do_step(click_x, click_y, color); if (step_status > 0) { write_hod(click_x, click_y); apply_select(selected_x, selected_y, 0); chip old_chip = board[selected_y][selected_x]; board[selected_y][selected_x] = None; apply_color(selected_x, selected_y); board[click_y][click_x] = old_chip; if (step_status == 2 && can_eat(click_x, click_y, color)) { // 2 - возможен повторный ход, т.к. предыдущий был рубкой. apply_color(click_x, click_y); apply_select(click_x, click_y, 1); if ((color == White && click_y == 7) || (color == Black && click_y == 0)) futureDamka = 1; } else { if (futureDamka || (color == White && click_y == 7) || (color == Black && click_y == 0)) board[click_y][click_x] = damka; apply_color(click_x, click_y); formalize_hod(); debug_print(myhod, 3 + 2*myhod_len, Dmy); send_str(myhod, 3 + 2*myhod_len); forbidden_direction = DNone; if (game_over()) { ggs = GGNEW; } else { if (color == White) ggs = GGStartStepBlack; else ggs = GGStartStepWhite; } } } } } }
t_dmap *compute_dmap(const int x, const int y, const int seed) { const int size = ODDIFY(pow_two(MAX(x, y))); int nb_iter; t_dmap *dmap; dmap = new_dmap(size); if (dmap == NULL) return (NULL); nb_iter = 1; srand(seed); dmap->map[0][0] = (rand() % RAND_RANGE); dmap->map[size - 1][0] = (rand() % RAND_RANGE); dmap->map[size - 1][size - 1] = (rand() % RAND_RANGE); dmap->map[0][size - 1] = (rand() % RAND_RANGE); while (dmap->step > 1) { do_step(nb_iter, dmap, size); dmap->step /= 2; nb_iter *= 2; } return (dmap); }
void do_step_v1( System system , StateInOut & x , time_type t , time_type dt ) { typedef typename odeint::unwrap_reference< StateInOut >::type state_in_type; typedef typename odeint::unwrap_reference< typename state_in_type::first_type >::type coor_in_type; typedef typename odeint::unwrap_reference< typename state_in_type::second_type >::type momentum_in_type; typedef typename boost::remove_reference< coor_in_type >::type xyz_type; state_in_type & statein = x; coor_in_type & qinout = statein.first; momentum_in_type & pinout = statein.second; // alloc a if( m_resizer.adjust_size( qinout , detail::bind( &velocity_verlet::template resize_impl< xyz_type > , detail::ref( *this ) , detail::_1 ) ) || m_first_call ) { initialize_acc( system , qinout , pinout , t ); } // check first do_step( system , qinout , pinout , get_current_acc() , qinout , pinout , get_old_acc() , t , dt ); toggle_current_acc(); }
void do_step( System system , const StateInOut &x , const time_type &t , const time_type &dt ) { do_step( system , x , t , x , dt ); }
void do_step( System system , const StateInOut &x , StateIn const & pred , time_type t , time_type dt , const ABBuf &buf ) { do_step( system , x , pred , t , x , dt , buf ); }
GLOBAL Int UMF_solve ( Int sys, const Int Ap [ ], const Int Ai [ ], const double Ax [ ], double Xx [ ], const double Bx [ ], #ifdef COMPLEX const double Az [ ], double Xz [ ], const double Bz [ ], #endif NumericType *Numeric, Int irstep, double Info [UMFPACK_INFO], Int Pattern [ ], /* size n */ double SolveWork [ ] /* if irstep>0 real: size 5*n. complex:10*n */ /* otherwise real: size n. complex: 4*n */ ) { /* ---------------------------------------------------------------------- */ /* local variables */ /* ---------------------------------------------------------------------- */ Entry axx, wi, xj, zi, xi, aij, bi ; double omega [3], d, z2i, yi, flops ; Entry *W, *Z, *S, *X ; double *Z2, *Y, *B2, *Rs ; Int *Rperm, *Cperm, i, n, p, step, j, nz, status, p2, do_scale ; #ifdef COMPLEX Int AXsplit ; Int Bsplit ; #endif #ifndef NRECIPROCAL Int do_recip = Numeric->do_recip ; #endif /* ---------------------------------------------------------------------- */ /* initializations */ /* ---------------------------------------------------------------------- */ #ifndef NDEBUG UMF_dump_lu (Numeric) ; ASSERT (Numeric && Xx && Bx && Pattern && SolveWork && Info) ; #endif nz = 0 ; omega [0] = 0. ; omega [1] = 0. ; omega [2] = 0. ; Rperm = Numeric->Rperm ; Cperm = Numeric->Cperm ; Rs = Numeric->Rs ; /* row scale factors */ do_scale = (Rs != (double *) NULL) ; flops = 0 ; Info [UMFPACK_SOLVE_FLOPS] = 0 ; Info [UMFPACK_IR_TAKEN] = 0 ; Info [UMFPACK_IR_ATTEMPTED] = 0 ; /* UMFPACK_solve does not call this routine if A is rectangular */ ASSERT (Numeric->n_row == Numeric->n_col) ; n = Numeric->n_row ; if (Numeric->nnzpiv < n || SCALAR_IS_ZERO (Numeric->rcond) || SCALAR_IS_NAN (Numeric->rcond)) { /* Note that systems involving just L return UMFPACK_OK, even if */ /* A is singular (L is always has a unit diagonal). */ DEBUGm4 (("Note, matrix is singular in umf_solve\n")) ; status = UMFPACK_WARNING_singular_matrix ; irstep = 0 ; } else { status = UMFPACK_OK ; } irstep = MAX (0, irstep) ; /* make sure irstep is >= 0 */ W = (Entry *) SolveWork ; /* Entry W [0..n-1] */ Z = (Entry *) NULL ; /* unused if no iterative refinement */ S = (Entry *) NULL ; Y = (double *) NULL ; Z2 = (double *) NULL ; B2 = (double *) NULL ; #ifdef COMPLEX if (irstep > 0) { if (!Ap || !Ai || !Ax) { return (UMFPACK_ERROR_argument_missing) ; } /* A, B, and X in split format if Az, Bz, and Xz present */ AXsplit = SPLIT (Az) || SPLIT(Xz); Z = (Entry *) (SolveWork + 4*n) ; /* Entry Z [0..n-1] */ S = (Entry *) (SolveWork + 6*n) ; /* Entry S [0..n-1] */ Y = (double *) (SolveWork + 8*n) ; /* double Y [0..n-1] */ B2 = (double *) (SolveWork + 9*n) ; /* double B2 [0..n-1] */ Z2 = (double *) Z ; /* double Z2 [0..n-1], equiv. to Z */ } else { /* A is ignored, only look at X for split/packed cases */ AXsplit = SPLIT(Xz); } Bsplit = SPLIT (Bz); if (AXsplit) { X = (Entry *) (SolveWork + 2*n) ; /* Entry X [0..n-1] */ } else { X = (Entry *) Xx ; /* Entry X [0..n-1] */ } #else X = (Entry *) Xx ; /* Entry X [0..n-1] */ if (irstep > 0) { if (!Ap || !Ai || !Ax) { return (UMFPACK_ERROR_argument_missing) ; } Z = (Entry *) (SolveWork + n) ; /* Entry Z [0..n-1] */ S = (Entry *) (SolveWork + 2*n) ; /* Entry S [0..n-1] */ Y = (double *) (SolveWork + 3*n) ; /* double Y [0..n-1] */ B2 = (double *) (SolveWork + 4*n) ; /* double B2 [0..n-1] */ Z2 = (double *) Z ; /* double Z2 [0..n-1], equiv. to Z */ } #endif /* ---------------------------------------------------------------------- */ /* determine which system to solve */ /* ---------------------------------------------------------------------- */ if (sys == UMFPACK_A) { /* ------------------------------------------------------------------ */ /* solve A x = b with optional iterative refinement */ /* ------------------------------------------------------------------ */ if (irstep > 0) { /* -------------------------------------------------------------- */ /* using iterative refinement: compute Y and B2 */ /* -------------------------------------------------------------- */ nz = Ap [n] ; Info [UMFPACK_NZ] = nz ; /* A is stored by column */ /* Y (i) = ||R A_i||, 1-norm of row i of R A */ for (i = 0 ; i < n ; i++) { Y [i] = 0. ; } flops += (ABS_FLOPS + 1) * nz ; p2 = Ap [n] ; for (p = 0 ; p < p2 ; p++) { /* Y [Ai [p]] += ABS (Ax [p]) ; */ ASSIGN (aij, Ax, Az, p, AXsplit) ; ABS (d, aij) ; Y [Ai [p]] += d ; } /* B2 = abs (B) */ flops += ABS_FLOPS * n ; for (i = 0 ; i < n ; i++) { /* B2 [i] = ABS (B [i]) ; */ ASSIGN (bi, Bx, Bz, i, Bsplit) ; ABS (B2 [i], bi) ; } /* scale Y and B2. */ if (do_scale) { /* Y = R Y */ /* B2 = R B2 */ #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { Y [i] *= Rs [i] ; B2 [i] *= Rs [i] ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { Y [i] /= Rs [i] ; B2 [i] /= Rs [i] ; } } flops += 2 * n ; } } for (step = 0 ; step <= irstep ; step++) { /* -------------------------------------------------------------- */ /* Solve A x = b (step 0): */ /* x = Q (U \ (L \ (P R b))) */ /* and then perform iterative refinement (step > 0): */ /* x = x + Q (U \ (L \ (P R (b - A x)))) */ /* -------------------------------------------------------------- */ if (step == 0) { if (do_scale) { /* W = P R b, using X as workspace, since Z is not * allocated if irstep = 0. */ #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { ASSIGN (X [i], Bx, Bz, i, Bsplit) ; SCALE (X [i], Rs [i]) ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { ASSIGN (X [i], Bx, Bz, i, Bsplit) ; SCALE_DIV (X [i], Rs [i]) ; } } flops += SCALE_FLOPS * n ; for (i = 0 ; i < n ; i++) { W [i] = X [Rperm [i]] ; } } else { /* W = P b, since the row scaling R = I */ for (i = 0 ; i < n ; i++) { /* W [i] = B [Rperm [i]] ; */ ASSIGN (W [i], Bx, Bz, Rperm [i], Bsplit) ; } } } else { for (i = 0 ; i < n ; i++) { /* Z [i] = B [i] ; */ ASSIGN (Z [i], Bx, Bz, i, Bsplit) ; } flops += MULTSUB_FLOPS * nz ; for (i = 0 ; i < n ; i++) { xi = X [i] ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* Z [Ai [p]] -= Ax [p] * xi ; */ ASSIGN (aij, Ax, Az, p, AXsplit) ; MULT_SUB (Z [Ai [p]], aij, xi) ; } } /* scale, Z = R Z */ if (do_scale) { #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE (Z [i], Rs [i]) ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE_DIV (Z [i], Rs [i]) ; } } flops += SCALE_FLOPS * n ; } for (i = 0 ; i < n ; i++) { W [i] = Z [Rperm [i]] ; } } flops += UMF_lsolve (Numeric, W, Pattern) ; flops += UMF_usolve (Numeric, W, Pattern) ; if (step == 0) { for (i = 0 ; i < n ; i++) { X [Cperm [i]] = W [i] ; } } else { flops += ASSEMBLE_FLOPS * n ; for (i = 0 ; i < n ; i++) { /* X [Cperm [i]] += W [i] ; */ ASSEMBLE (X [Cperm [i]], W [i]) ; } } /* -------------------------------------------------------------- */ /* sparse backward error estimate */ /* -------------------------------------------------------------- */ if (irstep > 0) { /* ---------------------------------------------------------- */ /* A is stored by column */ /* W (i) = R (b - A x)_i, residual */ /* Z2 (i) = R (|A||x|)_i */ /* ---------------------------------------------------------- */ for (i = 0 ; i < n ; i++) { /* W [i] = B [i] ; */ ASSIGN (W [i], Bx, Bz, i, Bsplit) ; Z2 [i] = 0. ; } flops += (MULT_FLOPS + DECREMENT_FLOPS + ABS_FLOPS + 1) * nz ; for (j = 0 ; j < n ; j++) { xj = X [j] ; p2 = Ap [j+1] ; for (p = Ap [j] ; p < p2 ; p++) { i = Ai [p] ; /* axx = Ax [p] * xj ; */ ASSIGN (aij, Ax, Az, p, AXsplit) ; MULT (axx, aij, xj) ; /* W [i] -= axx ; */ DECREMENT (W [i], axx) ; /* Z2 [i] += ABS (axx) ; */ ABS (d, axx) ; Z2 [i] += d ; } } /* scale W and Z2 */ if (do_scale) { /* Z2 = R Z2 */ /* W = R W */ #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE (W [i], Rs [i]) ; Z2 [i] *= Rs [i] ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE_DIV (W [i], Rs [i]) ; Z2 [i] /= Rs [i] ; } } flops += (SCALE_FLOPS + 1) * n ; } flops += (2*ABS_FLOPS + 5) * n ; if (do_step (omega, step, B2, X, W, Y, Z2, S, n, Info)) { /* iterative refinement is done */ break ; } } } } else if (sys == UMFPACK_At) { /* ------------------------------------------------------------------ */ /* solve A' x = b with optional iterative refinement */ /* ------------------------------------------------------------------ */ /* A' is the complex conjugate transpose */ if (irstep > 0) { /* -------------------------------------------------------------- */ /* using iterative refinement: compute Y */ /* -------------------------------------------------------------- */ nz = Ap [n] ; Info [UMFPACK_NZ] = nz ; /* A' is stored by row */ /* Y (i) = ||(A' R)_i||, 1-norm of row i of A' R */ if (do_scale) { flops += (ABS_FLOPS + 2) * nz ; #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { yi = 0. ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* yi += ABS (Ax [p]) * Rs [Ai [p]] ; */ /* note that abs (aij) is the same as * abs (conj (aij)) */ ASSIGN (aij, Ax, Az, p, AXsplit) ; ABS (d, aij) ; yi += (d * Rs [Ai [p]]) ; } Y [i] = yi ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { yi = 0. ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* yi += ABS (Ax [p]) / Rs [Ai [p]] ; */ /* note that abs (aij) is the same as * abs (conj (aij)) */ ASSIGN (aij, Ax, Az, p, AXsplit) ; ABS (d, aij) ; yi += (d / Rs [Ai [p]]) ; } Y [i] = yi ; } } } else { /* no scaling */ flops += (ABS_FLOPS + 1) * nz ; for (i = 0 ; i < n ; i++) { yi = 0. ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* yi += ABS (Ax [p]) ; */ /* note that abs (aij) is the same as * abs (conj (aij)) */ ASSIGN (aij, Ax, Az, p, AXsplit) ; ABS (d, aij) ; yi += d ; } Y [i] = yi ; } } /* B2 = abs (B) */ for (i = 0 ; i < n ; i++) { /* B2 [i] = ABS (B [i]) ; */ ASSIGN (bi, Bx, Bz, i, Bsplit) ; ABS (B2 [i], bi) ; } } for (step = 0 ; step <= irstep ; step++) { /* -------------------------------------------------------------- */ /* Solve A' x = b (step 0): */ /* x = R P' (L' \ (U' \ (Q' b))) */ /* and then perform iterative refinement (step > 0): */ /* x = x + R P' (L' \ (U' \ (Q' (b - A' x)))) */ /* -------------------------------------------------------------- */ if (step == 0) { /* W = Q' b */ for (i = 0 ; i < n ; i++) { /* W [i] = B [Cperm [i]] ; */ ASSIGN (W [i], Bx, Bz, Cperm [i], Bsplit) ; } } else { /* Z = b - A' x */ for (i = 0 ; i < n ; i++) { /* Z [i] = B [i] ; */ ASSIGN (Z [i], Bx, Bz, i, Bsplit) ; } flops += MULTSUB_FLOPS * nz ; for (i = 0 ; i < n ; i++) { zi = Z [i] ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* zi -= conjugate (Ax [p]) * X [Ai [p]] ; */ ASSIGN (aij, Ax, Az, p, Bsplit) ; MULT_SUB_CONJ (zi, X [Ai [p]], aij) ; } Z [i] = zi ; } /* W = Q' Z */ for (i = 0 ; i < n ; i++) { W [i] = Z [Cperm [i]] ; } } flops += UMF_uhsolve (Numeric, W, Pattern) ; flops += UMF_lhsolve (Numeric, W, Pattern) ; if (step == 0) { /* X = R P' W */ /* do not use Z, since it isn't allocated if irstep = 0 */ /* X = P' W */ for (i = 0 ; i < n ; i++) { X [Rperm [i]] = W [i] ; } if (do_scale) { /* X = R X */ #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE (X [i], Rs [i]) ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE_DIV (X [i], Rs [i]) ; } } flops += SCALE_FLOPS * n ; } } else { /* Z = P' W */ for (i = 0 ; i < n ; i++) { Z [Rperm [i]] = W [i] ; } if (do_scale) { /* Z = R Z */ #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE (Z [i], Rs [i]) ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE_DIV (Z [i], Rs [i]) ; } } flops += SCALE_FLOPS * n ; } flops += ASSEMBLE_FLOPS * n ; /* X += Z */ for (i = 0 ; i < n ; i++) { /* X [i] += Z [i] ; was +=W[i] in v4.3, which is wrong */ ASSEMBLE (X [i], Z [i]) ; /* bug fix, v4.3.1 */ } } /* -------------------------------------------------------------- */ /* sparse backward error estimate */ /* -------------------------------------------------------------- */ if (irstep > 0) { /* ---------------------------------------------------------- */ /* A' is stored by row */ /* W (i) = (b - A' x)_i, residual */ /* Z2 (i) = (|A'||x|)_i */ /* ---------------------------------------------------------- */ flops += (MULT_FLOPS + DECREMENT_FLOPS + ABS_FLOPS + 1) * nz ; for (i = 0 ; i < n ; i++) { /* wi = B [i] ; */ ASSIGN (wi, Bx, Bz, i, Bsplit) ; z2i = 0. ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* axx = conjugate (Ax [p]) * X [Ai [p]] ; */ ASSIGN (aij, Ax, Az, p, AXsplit) ; MULT_CONJ (axx, X [Ai [p]], aij) ; /* wi -= axx ; */ DECREMENT (wi, axx) ; /* z2i += ABS (axx) ; */ ABS (d, axx) ; z2i += d ; } W [i] = wi ; Z2 [i] = z2i ; } flops += (2*ABS_FLOPS + 5) * n ; if (do_step (omega, step, B2, X, W, Y, Z2, S, n, Info)) { /* iterative refinement is done */ break ; } } } } else if (sys == UMFPACK_Aat) { /* ------------------------------------------------------------------ */ /* solve A.' x = b with optional iterative refinement */ /* ------------------------------------------------------------------ */ /* A' is the array transpose */ if (irstep > 0) { /* -------------------------------------------------------------- */ /* using iterative refinement: compute Y */ /* -------------------------------------------------------------- */ nz = Ap [n] ; Info [UMFPACK_NZ] = nz ; /* A.' is stored by row */ /* Y (i) = ||(A.' R)_i||, 1-norm of row i of A.' R */ if (do_scale) { flops += (ABS_FLOPS + 2) * nz ; #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { yi = 0. ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* yi += ABS (Ax [p]) * Rs [Ai [p]] ; */ /* note that A.' is the array transpose, * so no conjugate */ ASSIGN (aij, Ax, Az, p, AXsplit) ; ABS (d, aij) ; yi += (d * Rs [Ai [p]]) ; } Y [i] = yi ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { yi = 0. ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* yi += ABS (Ax [p]) / Rs [Ai [p]] ; */ /* note that A.' is the array transpose, * so no conjugate */ ASSIGN (aij, Ax, Az, p, AXsplit) ; ABS (d, aij) ; yi += (d / Rs [Ai [p]]) ; } Y [i] = yi ; } } } else { /* no scaling */ flops += (ABS_FLOPS + 1) * nz ; for (i = 0 ; i < n ; i++) { yi = 0. ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* yi += ABS (Ax [p]) */ /* note that A.' is the array transpose, * so no conjugate */ ASSIGN (aij, Ax, Az, p, AXsplit) ; ABS (d, aij) ; yi += d ; } Y [i] = yi ; } } /* B2 = abs (B) */ for (i = 0 ; i < n ; i++) { /* B2 [i] = ABS (B [i]) ; */ ASSIGN (bi, Bx, Bz, i, Bsplit) ; ABS (B2 [i], bi) ; } } for (step = 0 ; step <= irstep ; step++) { /* -------------------------------------------------------------- */ /* Solve A.' x = b (step 0): */ /* x = R P' (L.' \ (U.' \ (Q' b))) */ /* and then perform iterative refinement (step > 0): */ /* x = x + R P' (L.' \ (U.' \ (Q' (b - A.' x)))) */ /* -------------------------------------------------------------- */ if (step == 0) { /* W = Q' b */ for (i = 0 ; i < n ; i++) { /* W [i] = B [Cperm [i]] ; */ ASSIGN (W [i], Bx, Bz, Cperm [i], Bsplit) ; } } else { /* Z = b - A.' x */ for (i = 0 ; i < n ; i++) { /* Z [i] = B [i] ; */ ASSIGN (Z [i], Bx, Bz, i, Bsplit) ; } flops += MULTSUB_FLOPS * nz ; for (i = 0 ; i < n ; i++) { zi = Z [i] ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* zi -= Ax [p] * X [Ai [p]] ; */ ASSIGN (aij, Ax, Az, p, AXsplit) ; MULT_SUB (zi, aij, X [Ai [p]]) ; } Z [i] = zi ; } /* W = Q' Z */ for (i = 0 ; i < n ; i++) { W [i] = Z [Cperm [i]] ; } } flops += UMF_utsolve (Numeric, W, Pattern) ; flops += UMF_ltsolve (Numeric, W, Pattern) ; if (step == 0) { /* X = R P' W */ /* do not use Z, since it isn't allocated if irstep = 0 */ /* X = P' W */ for (i = 0 ; i < n ; i++) { X [Rperm [i]] = W [i] ; } if (do_scale) { /* X = R X */ #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE (X [i], Rs [i]) ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE_DIV (X [i], Rs [i]) ; } } flops += SCALE_FLOPS * n ; } } else { /* Z = P' W */ for (i = 0 ; i < n ; i++) { Z [Rperm [i]] = W [i] ; } if (do_scale) { /* Z = R Z */ #ifndef NRECIPROCAL if (do_recip) { /* multiply by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE (Z [i], Rs [i]) ; } } else #endif { /* divide by the scale factors */ for (i = 0 ; i < n ; i++) { SCALE_DIV (Z [i], Rs [i]) ; } } flops += SCALE_FLOPS * n ; } flops += ASSEMBLE_FLOPS * n ; /* X += Z */ for (i = 0 ; i < n ; i++) { /* X [i] += Z [i] ; was +=W[i] in v4.3, which is wrong */ ASSEMBLE (X [i], Z [i]) ; /* bug fix, v4.3.1 */ } } /* -------------------------------------------------------------- */ /* sparse backward error estimate */ /* -------------------------------------------------------------- */ if (irstep > 0) { /* ---------------------------------------------------------- */ /* A.' is stored by row */ /* W (i) = (b - A.' x)_i, residual */ /* Z (i) = (|A.'||x|)_i */ /* ---------------------------------------------------------- */ flops += (MULT_FLOPS + DECREMENT_FLOPS + ABS_FLOPS + 1) * nz ; for (i = 0 ; i < n ; i++) { /* wi = B [i] ; */ ASSIGN (wi, Bx, Bz, i, Bsplit) ; z2i = 0. ; p2 = Ap [i+1] ; for (p = Ap [i] ; p < p2 ; p++) { /* axx = Ax [p] * X [Ai [p]] ; */ ASSIGN (aij, Ax, Az, p, AXsplit) ; MULT (axx, aij, X [Ai [p]]) ; /* wi -= axx ; */ DECREMENT (wi, axx) ; /* z2i += ABS (axx) ; */ ABS (d, axx) ; z2i += d ; } W [i] = wi ; Z2 [i] = z2i ; } flops += (2*ABS_FLOPS + 5) * n ; if (do_step (omega, step, B2, X, W, Y, Z2, S, n, Info)) { /* iterative refinement is done */ break ; } } } } else if (sys == UMFPACK_Pt_L) { /* ------------------------------------------------------------------ */ /* Solve P'Lx=b: x = L \ Pb */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [Rperm [i]] ; */ ASSIGN (X [i], Bx, Bz, Rperm [i], Bsplit) ; } flops = UMF_lsolve (Numeric, X, Pattern) ; status = UMFPACK_OK ; } else if (sys == UMFPACK_L) { /* ------------------------------------------------------------------ */ /* Solve Lx=b: x = L \ b */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [i] ; */ ASSIGN (X [i], Bx, Bz, i, Bsplit) ; } flops = UMF_lsolve (Numeric, X, Pattern) ; status = UMFPACK_OK ; } else if (sys == UMFPACK_Lt_P) { /* ------------------------------------------------------------------ */ /* Solve L'Px=b: x = P' (L' \ b) */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* W [i] = B [i] ; */ ASSIGN (W [i], Bx, Bz, i, Bsplit) ; } flops = UMF_lhsolve (Numeric, W, Pattern) ; for (i = 0 ; i < n ; i++) { X [Rperm [i]] = W [i] ; } status = UMFPACK_OK ; } else if (sys == UMFPACK_Lat_P) { /* ------------------------------------------------------------------ */ /* Solve L.'Px=b: x = P' (L.' \ b) */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* W [i] = B [i] ; */ ASSIGN (W [i], Bx, Bz, i, Bsplit) ; } flops = UMF_ltsolve (Numeric, W, Pattern) ; for (i = 0 ; i < n ; i++) { X [Rperm [i]] = W [i] ; } status = UMFPACK_OK ; } else if (sys == UMFPACK_Lt) { /* ------------------------------------------------------------------ */ /* Solve L'x=b: x = L' \ b */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [i] ; */ ASSIGN (X [i], Bx, Bz, i, Bsplit) ; } flops = UMF_lhsolve (Numeric, X, Pattern) ; status = UMFPACK_OK ; } else if (sys == UMFPACK_Lat) { /* ------------------------------------------------------------------ */ /* Solve L.'x=b: x = L.' \ b */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [i] ; */ ASSIGN (X [i], Bx, Bz, i, Bsplit) ; } flops = UMF_ltsolve (Numeric, X, Pattern) ; status = UMFPACK_OK ; } else if (sys == UMFPACK_U_Qt) { /* ------------------------------------------------------------------ */ /* Solve UQ'x=b: x = Q (U \ b) */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* W [i] = B [i] ; */ ASSIGN (W [i], Bx, Bz, i, Bsplit) ; } flops = UMF_usolve (Numeric, W, Pattern) ; for (i = 0 ; i < n ; i++) { X [Cperm [i]] = W [i] ; } } else if (sys == UMFPACK_U) { /* ------------------------------------------------------------------ */ /* Solve Ux=b: x = U \ b */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [i] ; */ ASSIGN (X [i], Bx, Bz, i, Bsplit) ; } flops = UMF_usolve (Numeric, X, Pattern) ; } else if (sys == UMFPACK_Q_Ut) { /* ------------------------------------------------------------------ */ /* Solve QU'x=b: x = U' \ Q'b */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [Cperm [i]] ; */ ASSIGN (X [i], Bx, Bz, Cperm [i], Bsplit) ; } flops = UMF_uhsolve (Numeric, X, Pattern) ; } else if (sys == UMFPACK_Q_Uat) { /* ------------------------------------------------------------------ */ /* Solve QU.'x=b: x = U.' \ Q'b */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [Cperm [i]] ; */ ASSIGN (X [i], Bx, Bz, Cperm [i], Bsplit) ; } flops = UMF_utsolve (Numeric, X, Pattern) ; } else if (sys == UMFPACK_Ut) { /* ------------------------------------------------------------------ */ /* Solve U'x=b: x = U' \ b */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [i] ; */ ASSIGN (X [i], Bx, Bz, i, Bsplit) ; } flops = UMF_uhsolve (Numeric, X, Pattern) ; } else if (sys == UMFPACK_Uat) { /* ------------------------------------------------------------------ */ /* Solve U'x=b: x = U' \ b */ /* ------------------------------------------------------------------ */ for (i = 0 ; i < n ; i++) { /* X [i] = B [i] ; */ ASSIGN (X [i], Bx, Bz, i, Bsplit) ; } flops = UMF_utsolve (Numeric, X, Pattern) ; } else { return (UMFPACK_ERROR_invalid_system) ; } #ifdef COMPLEX /* copy the solution back, from Entry X [ ] to double Xx [ ] and Xz [ ] */ if (AXsplit) { for (i = 0 ; i < n ; i++) { Xx [i] = REAL_COMPONENT (X [i]) ; Xz [i] = IMAG_COMPONENT (X [i]) ; } } #endif /* return UMFPACK_OK, or UMFPACK_WARNING_singular_matrix */ /* Note that systems involving just L will return UMFPACK_OK */ Info [UMFPACK_SOLVE_FLOPS] = flops ; return (status) ; }
void do_step( System system , StateInOut &in , time_type t , time_type dt , const ABBuf &buf ) { do_step( system , in , t , in , dt , buf ); }
void do_step( System system , const StateInOut &in , const time_type &t , const time_type &dt , const ABBuf &buf ) { do_step( system , in , t , in , dt , buf ); }
/* * The function "mon()" is the dialog user interface, called * from the simulation just after program start. */ void mon(void) { register int eoj = 1; static char cmd[LENCMD]; tcgetattr(0, &old_term); if (x_flag) { if (do_getfile(xfn) == 0) do_go(); } while (eoj) { next: printf(">>> "); fflush(stdout); if (fgets(cmd, LENCMD, stdin) == NULL) { putchar('\n'); goto next; } switch (*cmd) { case '\n': do_step(); break; case 't': do_trace(cmd + 1); break; case 'g': do_go(); break; case 'd': do_dump(cmd + 1); break; case 'l': do_list(cmd + 1); break; case 'm': do_modify(cmd + 1); break; case 'f': do_fill(cmd + 1); break; case 'v': do_move(cmd + 1); break; case 'x': do_reg(cmd + 1); break; case 'p': do_port(cmd + 1); break; case 'b': do_break(cmd + 1); break; case 'h': do_hist(cmd + 1); break; case 'z': do_count(cmd + 1); break; case 'c': do_clock(); break; case 's': do_show(); break; case '?': do_help(); break; case 'r': do_getfile(cmd + 1); break; case '!': do_unix(cmd + 1); break; case 'q': eoj = 0; break; default: puts("what??"); break; } } }
void do_step( System system , const StateInOut &x , time_type t , time_type dt ) { do_step( system , x , t , x , dt ); }
void do_step( System system , state_type &x , time_type t , time_type dt ) { m_x_err_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_x_err<state_type> , detail::ref( *this ) , detail::_1 ) ); do_step( system , x , t , dt , m_x_err.m_v ); }
void do_step( System system , state_type &x , time_type t , time_type dt , state_type &xerr ) { do_step( system , x , t , x , dt , xerr ); }
double Simulator::do_simulate_wave(double time, double max_time_step_factor, double base) { IMP_FUNCTION_LOG; set_was_used(true); ParticleIndexes ps = get_simulation_particle_indexes(); setup(ps); double target = current_time_ + time; IMP_USAGE_CHECK(max_time_step_factor > 1.0, "simulate wave time step factor must be >1.0"); // build wave into cur_ts double wave_max_ts = max_time_step_factor * max_time_step_; std::vector<double> ts_seq; { int n_half = 2; // subwave length bool max_reached = false; double raw_wave_time = 0.0; do { double cur_ts = max_time_step_; // go up for (int i = 0; i < n_half; i++) { ts_seq.push_back(cur_ts); raw_wave_time += cur_ts; cur_ts *= base; if (cur_ts > wave_max_ts) { max_reached = true; break; } } // go down for (int i = 0; i < n_half; i++) { cur_ts /= base; ts_seq.push_back(cur_ts); raw_wave_time += cur_ts; if (cur_ts < max_time_step_) { break; } } n_half++; } while (!max_reached && raw_wave_time < time); // adjust to fit into time precisely unsigned int n = (unsigned int)std::ceil(time / raw_wave_time); double wave_time = time / n; double adjust = wave_time / raw_wave_time; IMP_LOG(PROGRESS, "Wave time step seq: "); for (unsigned int i = 0; i < ts_seq.size(); i++) { ts_seq[i] *= adjust; IMP_LOG(PROGRESS, ts_seq[i] << ", "); } IMP_LOG(PROGRESS, std::endl); } unsigned int i = 0; unsigned int k = ts_seq.size(); // n waves of k frames int orig_nf_left = (int)(time / max_time_step_); while (current_time_ < target) { last_time_step_ = do_step(ps, ts_seq[i++ % k]); current_time_ += last_time_step_; // emulate state updating by frames for the origin max_time_step // (for periodic optimizers) int nf_left = (int)((target - current_time_) / max_time_step_); while (orig_nf_left >= nf_left) { IMP_LOG(PROGRESS, "Updating states: " << orig_nf_left << "," << nf_left << " target time " << target << " current time " << current_time_ << std::endl); update_states(); // needs to move orig_nf_left--; } } IMP_LOG(PROGRESS, "Simulated for " << i << " actual frames with waves of " << k << " frames each" << std::endl); IMP_USAGE_CHECK(current_time_ >= target - 0.001 * max_time_step_, "simulations did not advance to target time for some reason"); return Optimizer::get_scoring_function()->evaluate(false); }
void do_step( System system , const CoorInOut &q , const MomentumInOut &p , const time_type &t , const time_type &dt ) { do_step( system , std::make_pair( detail::ref( q ) , detail::ref( p ) ) , t , dt ); }