void Network::stepRK3_SSP(double dt) { for(int j=0; j<Nedges; j++) { for(int i=0; i<channels[j]->N*2; i++) { channels[j]->qhat[i] = channels[j]->q0[i]; } for (int i=0; i<channels[j]->N; i++) { channels[j]->Clhat[i] = channels[j]->Cl0[i]; } } EulerStep(dt); EulerStep(dt); for(int j=0; j<Nedges; j++) { channels[j]->n++; for(int i = 0; i<channels[j]->N; i++) { for (int k=0; k<2; k++) { channels[j]->q[channels[j]->idx(k,i)] = 0.75*channels[j]->qhat[channels[j]->idx(k,i)] +.25*channels[j]->q[channels[j]->idx(k,i)]; channels[j]->q0[channels[j]->idx(k,i)] = channels[j]->q[channels[j]->idx(k,i)]; } channels[j]->Cl[i] = 0.75*channels[j]->Clhat[i] +.25*channels[j]->Cl[i]; channels[j]->Cl0[i] = channels[j]->Cl[i]; } } EulerStep(dt); for(int j=0; j<Nedges; j++) { for(int i = 0; i<channels[j]->N; i++) { for (int k=0; k<2; k++) { channels[j]->q[channels[j]->idx(k,i)] = 1./3.*channels[j]->qhat[channels[j]->idx(k,i)] +2./3.*channels[j]->q[channels[j]->idx(k,i)]; channels[j]->q0[channels[j]->idx(k,i)] = channels[j]->q[channels[j]->idx(k,i)]; channels[j]->q_hist[channels[j]->idx_t(k,i+1,nn)] = channels[j]->q[channels[j]->idx(k,i)]; } channels[j]->Cl[i] = 1./3.*channels[j]->Clhat[i]+2./3.*channels[j]->Cl[i]; channels[j]->Cl0[i] = channels[j]->Cl[i]; channels[j]->Cl_hist[nn*(channels[j]->N+2)+i+1] = channels[j]->Cl[i]; channels[j]->p_hist[channels[j]->pj_t(i+1,nn)] = channels[j]->P[i+1]; } } }
/* Parametrized simulation driver */ EXP long M_DECL ParamDriverC(double t0, double dt, long npts, double *ic, double *p, double *out, char *errbuf, long internal) { double u[NINP],y[NOUT],w[1+2*NEQ+NPAR+NDFA+NEVT]; long i,j; SolverStruct S; /* Setup */ for(i=0; i<npts*(NOUT+1); i++) out[i]=*dsn_undef; S.w=w; if(internal==0) S.err=0; else S.err=-1; S.buf=errbuf; SolverSetup(t0,ic,u,p,y,dt,&S); /* Output */ out[0]=t0; for(j=0; j<NOUT; j++) out[j+1]=y[j]; /* Integration loop */ for(i=1; i<npts; i++) { /* Take a step with states */ EulerStep(u,&S); if( S.err>0 ) break; /* Output */ SolverOutputs(y,&S); out[i*(NOUT+1)]=S.w[0]; for(j=0; j<NOUT; j++) out[i*(NOUT+1)+j+1]=y[j]; } return(i); }
void LevelSetOperator::IntegrateEuler(float dt) { // Create grid used to store next time step LevelSetGrid grid; EulerStep(grid,dt); /* // Iterate over grid and compute the grid values for the next timestep LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand(); LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand(); while (iter != iend) { unsigned int i = iter.GetI(); unsigned int j = iter.GetJ(); unsigned int k = iter.GetK(); // Compute rate of change float ddt = Evaluate(i,j,k); // Compute the next time step and store it in the grid grid.SetValue(i,j,k, GetGrid().GetValue(i,j,k) + ddt*dt); iter++; }*/ // Update the grid with the next time step GetGrid() = grid; std::cerr << "Euler Integration Complete" << std::endl; }
void LevelSetOperator::IntegrateRungeKutta(float dt) { // Create grid used to store next time step const LevelSetGrid gridN0 = GetGrid(); LevelSetGrid gridN1; LevelSetGrid gridN2; LevelSetGrid gridNHalf; LevelSetGrid gridNOneAndHalf; std::cerr << "RK Integration Begin timestep:" << dt << std::endl; EulerStep(gridN1,dt); std::cerr << "RK Integration Euler Step 1" << std::endl; //grid N1 = RK 1 GetGrid() = gridN1; EulerStep(gridN2,dt); std::cerr << "RK Integration Euler Step 2" << std::endl; //GridLerp(gridN0,gridN2,0.5f,GetGrid()); GridLerp(gridN0,gridN2,0.75f,gridNHalf); std::cerr << "RK Integration Lerp 1" << std::endl; GetGrid() = gridNHalf; EulerStep(gridNOneAndHalf,dt); std::cerr << "RK Integration Euler Step 3" << std::endl; GridLerp(gridN0,gridNOneAndHalf,1.0f/3.0f,gridN1); std::cerr << "RK Integration Lerp 2" << std::endl; //grid N1 == RK 3 GetGrid() = gridN1; std::cerr << "RK Integration Complete" << std::endl; }
void CSheetSimulator::Simulate( float dt, int steps ) { ComputeControlPoints(); // Initialize positions if necessary dt /= steps; for (int i = 0; i < steps; ++i) { // Each step, we want to re-select the best collision planes to constrain // the movement by DetermineBestCollisionPlane(); EulerStep(dt); } }
void Sim::step(double* out, double* u) /* u: control signal */ { for (int k = 0; k < NOUT; k++) out[k] = *dsn_undef; // clear values to nan /* Integration loop */ /* Take a step with states */ EulerStep(u, &S); if (S.err <= 0) { /* Output */ SolverOutputs(y, &S); out[0] = S.w[0]; for(long j = 0; j < NOUT; j++) out[j + 1] = y[j]; } }
void CSheetSimulator::Simulate( float dt ) { // Initialize positions if necessary EulerStep(dt); }