bool analys(char* fileName, intgrtOutData& ode_res) { if (fileName == NULL) return false; //获取结果 bool bRes = integrate(fileName, final_time, max_step, ode_res); if (bRes == EXIT_FAILURE) { cout << "integrate error" << endl; return false; } else return true; }
int main() { const unsigned int bins = 5; const double a(0.0), b(M_PI); const double lambda = 2.2; sin_lambda_x func(lambda); std::cout.precision(15); std::cout << "I = " << integrate(a,b,bins,func) << std::endl; return 0; }
static inline void assemble(boost::shared_ptr<Mesh<Simplex<Dim>>>& mesh, double* vec) { boost::timer time; //HeapProfilerStart("FunctionSpace"); auto Vh = FunctionSpace<Mesh<Simplex<Dim>>, bases<Lagrange<Order, Type>>>::New(_mesh = mesh); //HeapProfilerDump("dump"); //HeapProfilerStop(); vec[2] = time.elapsed(); Environment::logMemoryUsage( "Assemble Elasticity Memory Usage: FunctionSpace" ); vec[1] = Vh->nDof(); auto E = 1e+8; auto nu = 0.25; auto mu = E / (2 * (1 + nu)); auto lambda = E * nu / ((1 + nu) * (1 - 2 * nu)); time.restart(); auto v = Vh->element(); auto f = backend()->newVector(Vh); auto l = form1(_test = Vh, _vector = f); l = integrate(_range = elements(mesh), _expr = -1e+3 * trans(oneY()) * id(v)); vec[4] = time.elapsed(); Environment::logMemoryUsage( "Assemble Elasticity Memory Usage: Form1" ); time.restart(); auto u = Vh->element(); auto A = backend()->newMatrix(Vh, Vh); vec[5] = time.elapsed(); Environment::logMemoryUsage( "Assemble Elasticity Memory Usage: Matrix" ); time.restart(); auto a = form2(_trial = Vh, _test = Vh, _matrix = A); a = integrate(_range = elements(mesh), _expr = lambda * divt(u) * div(v) + 2 * mu * trace(trans(sym(gradt(u))) * sym(grad(u)))); a += on(_range = markedfaces(mesh, "Dirichlet"), _rhs = l, _element = u, _expr = zero<Dim, 1>()); vec[3] = time.elapsed(); auto mem = Environment::logMemoryUsage( "Assemble Elasticity Memory Usage: Form2" ); v[6] = mem.memory_usage/1e9; cleanup(); }
int QuantitativeInvisibilityF1D::operator()(Interface1D &inter) { ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter); if (ve) { result = ve->qi(); return 0; } FEdge *fe = dynamic_cast<FEdge *>(&inter); if (fe) { result = fe->qi(); return 0; } result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); return 0; }
void inductor::calcTR (nr_double_t) { nr_double_t l = getPropertyDouble ("L"); nr_double_t r, v; nr_double_t i = real (getJ (VSRC_1)); /* apply initial condition if requested */ if (getMode () == MODE_INIT && isPropertyGiven ("I")) { i = getPropertyDouble ("I"); } setState (fState, i * l); integrate (fState, l, r, v); setD (VSRC_1, VSRC_1, -r); setE (VSRC_1, v); }
void Integrate2DQuad(int maxOrder, int numNodes1D, NuTo::eIntegrationMethod method) { NuTo::IntegrationTypeTensorProduct<2> intType(numNodes1D, method); for (int n = 0; n <= maxOrder; n++) { for (int i = 0; i < n + 1; i++) { auto f = [n, i](Eigen::VectorXd x) { return (std::pow(x[0], i) * std::pow(x[1], n - i)); }; double computedResult = integrate(f, intType); double expectedResult = 1. / (i + 1) / (n - i + 1) * ((1. - std::pow(-1, i + 1)) * (1. - std::pow(-1, n - i + 1))); BOOST_CHECK_SMALL(computedResult - expectedResult, 1.e-13); } } }
/* thread calls */ void * calc(void * data){ int rc; tdata * portion = (tdata *)data; portion->result = integrate(portion->fun, portion->l_bound, portion->u_bound, portion->precision); /* update val and strips */ rc = pthread_mutex_lock(&lock); if (rc) { printf("thread acquire failed!\n"); exit(-1); } integral_val += portion->result.value; integral_strips += portion->result.strips; rc = pthread_mutex_unlock(&lock); return NULL; }
int cannon_integ_aero( CANNON_AERO* C) { int ipass; /* GET SHORTHAND NOTATION FOR DATA STRUCTURES */ CANNON_AERO_OUT *CAO = &(C->out) ; /* LOAD THE POSITION AND VELOCITY STATES */ load_state( &CAO->position[0] , &CAO->position[1] , &CAO->position[2] , &CAO->velocity[0] , &CAO->velocity[1] , &CAO->velocity[2] , NULL ); /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */ load_deriv( &CAO->velocity[0] , &CAO->velocity[1] , &CAO->velocity[2] , &CAO->acceleration[0] , &CAO->acceleration[1] , &CAO->acceleration[2] , NULL ); /* CALL THE TRICK INTEGRATION SERVICE */ ipass = integrate(); /* UNLOAD THE NEW POSITION AND VELOCITY STATES */ unload_state( &CAO->position[0] , &CAO->position[1] , &CAO->position[2] , &CAO->velocity[0] , &CAO->velocity[1] , &CAO->velocity[2] , NULL ); /* RETURN */ return( ipass ); }
Eigen::VectorXd TrapezoidalInt::integrate(const unsigned long long &ts, const int &num_joints, const double samples[]) { if (first_pass && !size_set) { setSize(num_joints); first_pass = false; std::cout << "Size of TrapezoidalInt was not set, but automatically adjusted to the first received vector size of: " << num_joints << "\n"; } Eigen::VectorXd to_int(num_joints); for (int i=0;i<num_joints;i++) { to_int(i) = samples[i]; } return integrate(ts, to_int); }
void Tournament::update_states(ns_t ns) { if (!ready) { return; } ns_t shot = IntegrateMaxTimeStep; while (ns) { if (ns <= IntegrateMaxTimeStep) { shot = ns; ns = 0; } else { ns -= IntegrateMaxTimeStep; } integrate(shot); } }
double EmpiricalDistribution::deviation( double a, double b ) const { if ( a > b ) std::swap( a, b ); a = a > min ? a : min; b = b < max ? b : max; auto moment2 = [&]( double t ) { return t * t * density_func( t ); }; double ex = expectation( a, b ); double prob = this->operator()( b ) - this->operator()( a ); double m2 = integrate( moment2, a, b ); return m2 - ex * ex * prob; }
void RobotStabilizeEffect::reset() { for(int i = 0; i < STABILIZE_PARTICLE_COUNT; i++) { GLParticleDummy * p = getParticle(i); GLfloat angle = 2.0f * M_PI * frand(); GLfloat radius = 30.0f + frand() * 5.0f; p->moveTo(mPos.x + radius * cos(angle), mPos.y + radius * sin(angle)); p->setVelocity2f(2.0f * frand(), 2.0f * frand()); } GLvector2f backup = mPos; for(int i = 0; i < STABILIZE_PARTICLE_COUNT; i++) { //mPos += GLvector2f(0.05f, 0.05f); integrate(0.1f); } mPos = backup; }
void MenuOrbital::move( float dt ) { if( !isActive ) { activationDelay -= dt; if( activationDelay <= 0 ) isActive = true; } stateTime = time; stateAngle = angle; state( integrate(state(), dt, maxSpeed) ); time = stateTime; angle = stateAngle; }
static void calculateIntegrals(const AstronomyParameters* ap, const IntegralArea* ias, const StreamConstants* sc, const StreamGauss sg, EvaluationState* es, const CLRequest* clr, GPUInfo* ci, int useImages) { const IntegralArea* ia; double t1, t2; int rc; #if SEPARATION_CAL if (separationLoadKernel(ci, ap, sc) != CAL_RESULT_OK) fail("Failed to load integral kernel"); #endif /* SEPARATION_OPENCL */ for (; es->currentCut < es->numberCuts; es->currentCut++) { es->cut = &es->cuts[es->currentCut]; ia = &ias[es->currentCut]; es->current_calc_probs = completedIntegralProgress(ias, es); t1 = mwGetTime(); #if SEPARATION_OPENCL rc = integrateCL(ap, ia, sc, sg, es, clr, ci, (cl_bool) useImages); #elif SEPARATION_CAL rc = integrateCAL(ap, ia, sg, es, clr, ci); #else rc = integrate(ap, ia, sc, sg, es, clr); #endif /* SEPARATION_OPENCL */ t2 = mwGetTime(); warn("Integral %u time = %f s\n", es->currentCut, t2 - t1); if (rc || isnan(es->cut->bgIntegral)) fail("Failed to calculate integral %u\n", es->currentCut); cleanStreamIntegrals(es->cut->streamIntegrals, sc, ap->number_streams); clearEvaluationStateTmpSums(es); } #if SEPARATION_CAL mwUnloadKernel(ci); #endif /* SEPARATION_CAL */ }
static double integral_t0_g_minus(double t, void *data) { struct para *P = data; double res; if (P->st0 == 0) { res = integral_z_g_minus(t, P); } else { struct function F = { integral_z_g_minus, P }; res = integrate(&F, t - .5*P->st0, t + .5*P->st0, TUNE_INT_T0) / P->st0; } return res; }
/** Compute a first approximation for the RELEASE waypoint from wind and expected airspeed and altitude */ unit_t nav_drop_compute_approach( uint8_t wp_target, uint8_t wp_start, float nav_drop_radius ) { waypoints[WP_RELEASE].a = waypoints[wp_start].a; nav_drop_z = waypoints[WP_RELEASE].a - waypoints[wp_target].a; nav_drop_x = 0.; nav_drop_y = 0.; /* We approximate vx and vy, taking into account that RELEASE is next to TARGET */ float x_0 = waypoints[wp_target].x - waypoints[wp_start].x; float y_0 = waypoints[wp_target].y - waypoints[wp_start].y; /* Unit vector from START to TARGET */ float d = sqrt(x_0*x_0+y_0*y_0); float x1 = x_0 / d; float y_1 = y_0 / d; waypoints[WP_BASELEG].x = waypoints[wp_start].x + y_1 * nav_drop_radius; waypoints[WP_BASELEG].y = waypoints[wp_start].y - x1 * nav_drop_radius; waypoints[WP_BASELEG].a = waypoints[wp_start].a; nav_drop_start_qdr = M_PI - atan2(-y_1, -x1); if (nav_drop_radius < 0) nav_drop_start_qdr += M_PI; // wind in NED frame if (stateIsAirspeedValid()) { nav_drop_vx = x1 * *stateGetAirspeed_f() + stateGetHorizontalWindspeed_f()->y; nav_drop_vy = y_1 * *stateGetAirspeed_f() + stateGetHorizontalWindspeed_f()->x; } else { // use approximate airspeed, initially set to AIRSPEED_AT_RELEASE nav_drop_vx = x1 * airspeed + stateGetHorizontalWindspeed_f()->y; nav_drop_vy = y_1 * airspeed + stateGetHorizontalWindspeed_f()->x; } nav_drop_vz = 0.; float vx0 = nav_drop_vx; float vy0 = nav_drop_vy; integrate(wp_target); waypoints[WP_CLIMB].x = waypoints[WP_RELEASE].x + (CLIMB_TIME + CARROT) * vx0; waypoints[WP_CLIMB].y = waypoints[WP_RELEASE].y + (CLIMB_TIME + CARROT) * vy0; waypoints[WP_CLIMB].a = waypoints[WP_RELEASE].a + SAFE_CLIMB; return 0; }
int main(int argc, char *argv[]) { int i; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-help") == 0) { fprintf(stderr, "options: none\n"); exit(0); } } SET_BINARY_MODE integrate(); return 0; }
void tbook::ref_at(twindow& window) { tscroll_label& content = find_widget<tscroll_label>(&window, "content", false); tlabel* label = dynamic_cast<tlabel*>(content.find("_label", true)); tintegrate integrate(current_topic_->text.parsed_text(), label->get_width(), -1, label->config()->text_font_size, font::NORMAL_COLOR); int mousex, mousey; SDL_GetMouseState(&mousex,&mousey); const std::string ref = integrate.ref_at(mousex - label->get_x(), mousey - label->get_y()); if (!ref.empty()) { const help::topic* t = find_topic(toplevel, ref); tree_->set_select_item(cookie_rfind_node(t)); switch_to_topic(*window_, *t); } }
void last_shot(int flag) { int i; double *x; x = &MyData[0]; MyStart = 1; get_ic(2, x); STORFLAG = flag; MyTime = T0; if (flag) { storage[0][0] = (float)T0; extra(x, T0, NODE, NEQ); for (i = 0; i < NEQ; i++) storage[1 + i][0] = (float)x[i]; storind = 1; } integrate(&MyTime, x, TEND, DELTA_T, 1, NJMP, &MyStart); }
int cannon_integ_aero( CANNON_AERO* C) { int ipass; /* LOAD THE POSITION AND VELOCITY STATES */ load_state( &C->pos[0] , &C->pos[1] , &C->pos[2] , &C->vel[0] , &C->vel[1] , &C->vel[2] , NULL ); /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */ load_deriv( &C->vel[0] , &C->vel[1] , &C->vel[2] , &C->acc[0] , &C->acc[1] , &C->acc[2] , NULL ); /* CALL THE TRICK INTEGRATION SERVICE */ ipass = integrate(); /* UNLOAD THE NEW POSITION AND VELOCITY STATES */ unload_state( &C->pos[0] , &C->pos[1] , &C->pos[2] , &C->vel[0] , &C->vel[1] , &C->vel[2] , NULL ); /* RETURN */ return( ipass ); }
void World::integrate (float dt) { if (dt < nextCollission) { setNewKinematics(dt); nextCollission = nextCollission - dt; } else { setNewKinematics(nextCollission); collissionHandler(); dt = dt - nextCollission; nextCollission = findNextCollission(); integrate(dt); } }
returnValue Integrator::integrate( const Grid &t_, double *x0, double *xa, double *p , double *u , double *w ){ if( rhs == 0 ) return ACADOERROR( RET_TRIVIAL_RHS ); Vector components = rhs->getDifferentialStateComponents(); Vector tmpX ( components.getDim(), x0 ); Vector tmpXA( rhs->getNXA() , xa ); Vector tmpP ( rhs->getNP () , p ); Vector tmpU ( rhs->getNU () , u ); Vector tmpW ( rhs->getNW () , w ); return integrate( t_, tmpX, tmpXA, tmpP, tmpU, tmpW ); }
int main() { if (signal(SIGINT, signal_handler) == SIG_ERR) { printf("\nCan't catch SIGINT\n"); } create_and_initialize_system(); validate_system(); int num_steps = 1000; int num_cycles = 1000; integrate(num_cycles, num_steps); update_simulation_run_status("complete"); free_and_delete_system(); return 0; }
void CudaSystem::update() { // emit particles emitParticles(); reinitCells(grid); storeParticles(grid,m_dPos[1],particles.size()); searchNeighbooring(m_dPos[1],m_dInteractionRadius, grid, 1, voisines, particles.size()); // evaluate forces evaluateForcesExt(); // integrate integrate(); // Collision collide(); }
void UIRuntimeMiniToolBar::setIntegrationMode(IntegrationMode integrationMode) { /* Make sure integration-mode really changed: */ if (m_integrationMode == integrationMode) return; /* Update integration-mode: */ m_integrationMode = integrationMode; /* Re-integrate: */ integrate(); /* Re-initialize: */ adjustGeometry(); /* Propagate to child to update shape: */ m_pToolbar->setIntegrationMode(m_integrationMode); }
void physics_simulate() { PfxPerfCounter pc; for(int i=1;i<numRigidBodies;i++) { pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep); } perf_push_marker("broadphase"); pc.countBegin("broadphase"); broadphase(); pc.countEnd(); perf_pop_marker(); perf_push_marker("collision"); pc.countBegin("collision"); collision(); pc.countEnd(); perf_pop_marker(); perf_push_marker("solver"); pc.countBegin("solver"); constraintSolver(); pc.countEnd(); perf_pop_marker(); perf_push_marker("integrate"); pc.countBegin("integrate"); integrate(); pc.countEnd(); perf_pop_marker(); frame++; if(frame%100 == 0) { float broadphaseTime = pc.getCountTime(0); float collisionTime = pc.getCountTime(2); float solverTime = pc.getCountTime(4); float integrateTime = pc.getCountTime(6); SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f integrate %.2f | total %.2f\n",frame, broadphaseTime,collisionTime,solverTime,integrateTime, broadphaseTime+collisionTime+solverTime+integrateTime); } }
void compute_powerspectrum( const std::vector<double>& k, std::vector<double>& Pk, double z ) { double D0 = Dplus(1.0); double Dz = Dplus(1.0/(1.0+z))/D0; //.. compute normalization first .. double sigma0; { std::vector<double> scale(1,0.0); scale[0] = 8.0; double intt(0.0), dint(1.0), dx(2.0*M_PI/scale[0]), atmp(0.0); for(;;){ dint = integrate( &dsigma, scale, atmp, atmp+dx ); atmp+=dx; intt+=dint; if( dint/intt < REL_PRECISION ) break; } sigma0 = sqrt(4.0*M_PI*intt); } //... compute normalized power spectrum Pk.clear(); static double nspect = g_nspect; #if TRANSFERF_TYPE==0 static TransferFunction_BBKS TF(false); #elif TRANSFERF_TYPE==1 static TransferFunction_BBKS TF(true); #elif TRANSFERF_TYPE==2 static TransferFunction_Eisenstein TF; #else #error "Undefined Transfer Function Type." #endif for(unsigned i=0; i<k.size(); ++i ){ double tfk = TF.compute(k[i]); Pk.push_back( Dz*Dz*pow(k[i],nspect)*tfk*tfk /sigma0/sigma0*g_sigma_8*g_sigma_8 ); } }
int VehicleOne::state_integ() { int integration_step; load_state( &heading, &headingRate, &position[0], &position[1], &velocity[0], &velocity[1], (double*)0 ); load_deriv( &headingRate, &headingAccel, &velocity[0], &velocity[1], &acceleration[0], &acceleration[1], (double*)0 ); integration_step = integrate(); unload_state( &heading, &headingRate, &position[0], &position[1], &velocity[0], &velocity[1], (double*)0 ); if (!integration_step) { if (heading < -PI) heading += 2*PI; if (heading > PI) heading += -2*PI; } return(integration_step); }
vector<double> projectQ(TH2F* hst, double Q, double Elevel){ // Q units in [MeV] double Qlo = Q - 0.5; double Qhi = Q + 0.5; int qlo = hst->GetYaxis()->FindBin(Qlo); int qhi = hst->GetYaxis()->FindBin(Qhi); TH1F* hst_proj = (TH1F*)hst->ProjectionX("_px", qlo, qhi, ""); // primary gamma energy double Egam_lo = Qlo - Elevel; double Egam_hi = Qhi - Elevel; Egam_lo *= 1e3; Egam_hi *= 1e3; hst_proj->Draw(); TLine *line0 = new TLine(Egam_lo, 1, Egam_lo, 100); TLine *line1 = new TLine(Egam_hi, 1, Egam_hi, 100); line0->SetLineColor(2); line1->SetLineColor(2); line0->Draw("SAME"); line1->Draw("SAME"); double counts = integrate(hst_proj, Egam_lo, Egam_hi); //cout << "Integrating from: " << Egam_lo << " to: " << Egam_hi << endl; //cout << "Feeding to " << Elevel << " is: " << counts << " counts." << endl; double Eavg = 0.5*(Egam_hi + Egam_lo);// really this is the efficiency-corrected average of the primary spectrum vector<double> vec; vec.push_back(counts); vec.push_back(Eavg); return vec; }
void b3CpuRigidBodyPipeline::stepSimulation(float deltaTime) { //update world space aabb's updateAabbWorldSpace(); //compute overlapping pairs computeOverlappingPairs(); //compute contacts computeContactPoints(); //solve contacts //update transforms integrate(deltaTime); }