int main(int argc,const char **argv) { if ( argc < 2 ) { printf("Usage: blockchain (options) <dataDir>\n"); printf("\n"); printf("Options:\n"); printf("\n"); printf("-max_blocks <n> : Maximum number of blocks in the blockchain to analyze\n"); printf("-statistics : Whether or not to perform full statistics processing of every single address\n"); printf("-by_day : Accumulate breakdown of all bitcoin addresses by day\n"); printf("-by_month : Accumulate breakdown of all bitcoin addresses by month\n"); printf("-by_year : Accumulate breakdown of all bitcoin addresses by year\n"); printf("-zombie_days <n> : Number of days to consider a bitcoin address as a zombie, default value is 3 years.\n"); printf("-find_text <n> : Search for occurrences of ASCII text in the blockchain and output it to the log file. <n> is how many ASCII characters in a row to report text.\n"); } else { uint32_t zombieDays = 365*3; uint32_t maxBlocks = 10000000; const char *dataPath = "."; int i = 1; StatResolution resolution = SR_YEAR; bool processTransactions = false; uint32_t searchText = 0; while ( i < argc ) { const char *option = argv[i]; if ( *option == '-' ) { if ( strcmp(option,"-max_blocks") == 0 ) { i++; if ( i < argc ) { maxBlocks = atoi(argv[i]); if ( maxBlocks < 1 ) { printf("Invalid max_blocks value '%s'\n", argv[i] ); maxBlocks = 1000000; } else { printf("Maximum blocks set to %d\r\n", maxBlocks); } } else { printf("Error parsing option '-max_blocks', missing block number.\n"); } } else if ( strcmp(option,"-statistics") == 0 ) { processTransactions = true; printf("Enabling statistics processing\r\n"); } else if ( strcmp(option,"-by_day") == 0 ) { resolution = SR_DAY; processTransactions = true; printf("Gathering statistics by day\n"); } else if ( strcmp(option,"-by_month") == 0 ) { resolution = SR_MONTH; processTransactions = true; printf("Gathering statistics by month\n"); } else if ( strcmp(option,"-by_year") == 0 ) { resolution = SR_YEAR; processTransactions = true; printf("Gathering statistics by year\n"); } else if ( strcmp(option,"-find_text") == 0 ) { i++; if ( i < argc ) { searchText = atoi(argv[i]); printf("Searching for ASCII text in the blockchain using a character limit of %d\n", searchText ); } else { printf("Error parsing option '-find_text', missing character length.\n"); } } else if ( strcmp(option,"-zombie_days") == 0 ) { i++; if ( i < argc ) { zombieDays = atoi(argv[i]); printf("Zombie Days set to %d\n", zombieDays ); } else { printf("Error parsing option '-zombie_days', missing day count.\n"); } } else { printf("Unknown option '%s'\n", option ); } } else { if ( (i+1) == argc ) { printf("Using directory: %s to locate bitcoin data blocks.\n", option ); dataPath = option; } else { printf("%s not a valid option.\n", option ); } } i++; } BlockChainCommand bc(dataPath,maxBlocks,processTransactions,resolution,searchText,zombieDays); bc.setMaxBlocks(maxBlocks); while ( bc.process() ); } return 0; }
Int_t BToDstPi0Analysis::FitMES(){ //define cuts Float_t mesmin=BCPDGMass-.009; Float_t mesmax=BCPDGMass+.009; if(!OpenReducedNtuple())return 0; TH1F HmES("HmES","",40,5.20,5.30); ReducedNtuple->Draw("bmes>>HmES"); TH1F HmESN("HmESN","",40,5.20,5.30); ReducedNtuple->Draw("bmes>>HmESN","bcharge==-1"); TH1F HmESP("HmESP","",40,5.20,5.30); ReducedNtuple->Draw("bmes>>HmESP","bcharge==1"); filename=_OutputDir+"/MES.ps"; Canvas.Print(filename+"["); Canvas.Clear(); HmES.Draw("pe"); Canvas.Print(filename); Canvas.Clear(); HmESN.Draw("pe"); Canvas.Print(filename); Canvas.Clear(); HmESP.Draw("pe"); Canvas.Print(filename); mass.setRange(HmES.GetXaxis()->GetXmin(),HmES.GetXaxis()->GetXmax()); mass.setBins(HmES.GetXaxis()->GetNbins()); RooRealVar bm0("bm0","bm0",5.29); RooRealVar bc("bc","bc",-100,-10); RooRealVar bp("bp","bp",.1,1); RooArgusBG Bkg("Bkg","ArgusP",mass,bm0,bc,bp); ///-------------------------------Fit The RS RooDataHist dataset("dataset","dataset",RooArgList(mass),&HmES,1); RooDataHist datasetn("datasetn","datasetn",RooArgList(mass),&HmESN,1); RooDataHist datasetp("datasetp","datasetp",RooArgList(mass),&HmESP,1); //-------------------------------------------------------------------- //Fit RS data with Argus function //-------------------------------------------------------------------- Bkg.fitTo(dataset,"m"); RooPlot*plot=mass.frame(); dataset.plotOn(plot); Bkg.plotOn(plot); Canvas.Clear(); plot->Draw(); Canvas.Print(filename); delete plot; //-------------------------------------------------------------------- //Fit RS data Bkg + CBShape //-------------------------------------------------------------------- // RooHistPdf HBkg("HBkg","HBP",RooArgSet(mass),HB,0); // RooRealVar Bsl0("Bsl0","Bsl0",HmES.GetXaxis()->GetXmin()); // RooRealVar Bsl("Bsl","Bsl",-100,100); // RooGenericPdf BslP("BslP","BslP","1+Bsl*(mass-Bsl0)",RooArgList(Bsl0,Bsl,mass)); // RooProdPdf BkgProd("BkgProd","BkgProd",BslP,HBkg); RooRealVar sm0("sm0","sm0",5.2794); RooRealVar sigma("sigma","sigma",.003); RooRealVar alpha("alpha","alpha",3.); RooRealVar n("n","n",1,10);//1); //RooCBShape CBP("CBP","CBP",mass,sm0,sigma,alpha,n); RooGaussian CBP("CBP","CBP",mass,sm0,sigma); RooRealVar SYield("SYield","SYield",.01,.9); RooAddPdf FitPdf("FitPdf","FitPdf",RooArgList(CBP,Bkg),RooArgList(SYield)); mass.SetTitle("m_{ES}"); mass.setUnit("GeV^{2}/c^{4}"); ///Fit The Total FitPdf.fitTo(dataset,"m"); plot=mass.frame(); dataset.plotOn(plot,MarkerColor(0),LineColor(0)); FitPdf.plotOn(plot); FitPdf.plotOn(plot,Components(Bkg),LineColor(kRed)); Canvas.Clear(); plot->Draw(); HmES.SetLineColor(1);HmES.SetStats(0); HmES.Draw("same"); cutline.DrawLine(mesmin,0,mesmin,HmES.GetMaximum()); cutline.DrawLine(mesmax,0,mesmax,HmES.GetMaximum()); Canvas.Print(filename); delete plot; // //Calculate total signal yield // Int_t Syieldtot=(int)(SYield.getVal()*HmES.Integral()); // Int_t Syieldtote=(int)(SYield.getError()*HmES.Integral()); // Int_t Byieldtot=(int)((1-SYield.getVal())*HmES.Integral()); // Int_t Byieldtote=(int)((SYield.getError())*HmES.Integral()); //Calculate signal yield in cut mass.setRange("sigregion",mesmin,mesmax); RooArgSet nset(mass); RooAbsReal* sintegral=CBP.createIntegral(nset,nset,"sigregion"); Int_t syieldtot=(int)(HmES.Integral()*sintegral->getVal()*SYield.getVal()); RooAbsReal* bintegral=Bkg.createIntegral(nset,nset,"sigregion"); Int_t byieldtot=(int)(HmES.Integral()*bintegral->getVal()*(1-SYield.getVal())); cout<<"Yield Results in sig region TotSig="<<syieldtot<<endl; cout<<"Yield Results in sig region TotBkg="<<byieldtot<<endl; /* ///Now fix the shape parameters sm0.setConstant(1); sigma.setConstant(1); alpha.setConstant(1); n.setConstant(1); ////Fit the B0 FitPdf.fitTo(datasetn,"m"); RooPlot*plotn=mass.frame(); datasetn.plotOn(plotn,MarkerColor(0),LineColor(0)); //FitPdf.plotOn(plotn,LineStyle(1),LineColor(2)); FitPdf.plotOn(plotn,Components(BkgProd),LineColor(kBlack)); //Calculate total signal yield Int_t Syieldn=(int)(SYield.getVal()*HmESN.Integral()); Int_t Syieldne=(int)(SYield.getError()*HmESN.Integral()); Int_t Byieldn=(int)((1-SYield.getVal())*HmESN.Integral()); Int_t Byieldne=(int)((SYield.getError())*HmESN.Integral()); //Calculate signal yield in cut Int_t syieldn=(int)(HmESN.Integral()*sintegral->getVal()*SYield.getVal()); Int_t byieldn=(int)(HmESN.Integral()*bintegral->getVal()*(1-SYield.getVal())); ////Fit the B0bar FitPdf.fitTo(datasetp,"m"); RooPlot*plotp=mass.frame(); datasetp.plotOn(plotp,MarkerColor(0),LineColor(0)); //FitPdf.plotOn(plotp,LineStyle(1),LineColor(3)); FitPdf.plotOn(plotp,Components(BkgProd),LineColor(kBlack)); //Calculate total signal yield //Calculate total signal yield Int_t Syieldp=(int)(SYield.getVal()*HmESP.Integral()); Int_t Syieldpe=(int)(SYield.getError()*HmESP.Integral()); Int_t Byieldp=(int)((1-SYield.getVal())*HmESP.Integral()); Int_t Byieldpe=(int)((SYield.getError())*HmESP.Integral()); //Calculate signal yield in cut Int_t syieldp=(int)(HmESP.Integral()*sintegral->getVal()*SYield.getVal()); Int_t byieldp=(int)(HmESP.Integral()*bintegral->getVal()*(1-SYield.getVal())); Canvas.Clear(); plotn->Draw(); HmESN.SetLineColor(2);HmESN.SetStats(0); HmESN.Draw("same"); plotp->Draw("same"); HmESP.SetLineColor(3);HmESP.SetStats(0); HmESP.Draw("same"); Canvas.Print(filename); delete plotn; delete plotp; Float_t diff=Syieldn-Syieldp; Float_t diffe=sqrt((float)Syieldne*Syieldne+(float)Syieldpe*Syieldpe); Float_t asym=diff/Syieldtot; Float_t asyme=asym*sqrt(diffe*diffe/((float)diff*diff)+Syieldtote*Syieldtote/((float)Syieldtot*Syieldtot)); cout<<"Yield Results TotSig="<<Syieldtot<<"+-"<<Syieldtote <<", SigN="<<Syieldn<<"+-"<<Syieldne <<", SigP="<<Syieldp<<"+-"<<Syieldpe <<" Asym=(SigN-SigP)/(SigN+SigP)="<<asym<<"+-"<<asyme <<endl<<endl; cout<<"Yield Results TotBkg="<<Byieldtot<<"+-"<<Byieldtote<<", BkgN="<<Byieldn<<"+-"<<Byieldne<<", BkgP="<<Byieldp<<"+-"<<Byieldpe<<endl<<endl; cout<<"Yield Results in sig region TotSig="<<syieldtot<<", SigN="<<syieldn<<", SigP="<<syieldp<<endl; cout<<"Yield Results in sig region TotBkg="<<byieldtot<<", BkgN="<<byieldn<<", BkgP="<<byieldp<<endl; ///--------------------------------------------------------------- ////Plot Difference of the histograms: TH1F*HDiff=(TH1F*)HmESN.Clone(); HDiff->SetName("HDiff");HDiff->SetTitle("Difference"); HDiff->Sumw2(); HDiff->Add(&HmESP,-1); Canvas.Clear(); HDiff->SetStats(1); HDiff->SetLineColor(1); SetHistoXYLabels(HDiff,"m_{ES}","(GeV^{2}/c^{4})"); HDiff->Draw("pe"); Canvas.Update(); MoveStatsBox(HDiff,-1,1); cutline.DrawLine(HmESN.GetXaxis()->GetXmin(),0,HmESN.GetXaxis()->GetXmax(),0); Canvas.Update(); Canvas.Print(filename); cout<<" Asym="<<(float)(HDiff->Integral())/HmES.Integral(28,36)<<endl; delete HDiff; */ Canvas.Print(filename+"]"); return 1; }
/* * @test @(#)bug4117335.java 1.1 3/5/98 * * @bug 4117335 */ void DateFormatMiscTests::test4117335() { //UnicodeString bc = "\u7d00\u5143\u524d"; UChar bcC [] = { 0x7D00, 0x5143, 0x524D }; UnicodeString bc(bcC, 3, 3); //UnicodeString ad = "\u897f\u66a6"; UChar adC [] = { 0x897F, 0x66A6 }; UnicodeString ad(adC, 2, 2); //UnicodeString jstLong = "\u65e5\u672c\u6a19\u6e96\u6642"; UChar jstLongC [] = { 0x65e5, 0x672c, 0x6a19, 0x6e96, 0x6642 }; UnicodeString jstLong(jstLongC, 5, 5); UnicodeString jstShort = "JST"; UErrorCode status = U_ZERO_ERROR; DateFormatSymbols *symbols = new DateFormatSymbols(Locale::getJapan(), status); if(U_FAILURE(status)) { errln("Failure creating DateFormatSymbols, %s", u_errorName(status)); delete symbols; return; } failure(status, "new DateFormatSymbols"); int32_t eraCount = 0; const UnicodeString *eras = symbols->getEras(eraCount); logln(UnicodeString("BC = ") + eras[0]); if (eras[0] != bc) { errln("*** Should have been " + bc); //throw new Exception("Error in BC"); } logln(UnicodeString("AD = ") + eras[1]); if (eras[1] != ad) { errln("*** Should have been " + ad); //throw new Exception("Error in AD"); } int32_t rowCount, colCount; const UnicodeString **zones = symbols->getZoneStrings(rowCount, colCount); logln(UnicodeString("Long zone name = ") + zones[24][1]); if (zones[24][1] != jstLong) { errln("*** Should have been " + jstLong); //throw new Exception("Error in long TZ name"); } logln(UnicodeString("Short zone name = ") + zones[24][2]); if (zones[24][2] != jstShort) { errln("*** Should have been " + jstShort); //throw new Exception("Error in short TZ name"); } logln(UnicodeString("Long zone name = ") + zones[24][3]); if (zones[24][3] != jstLong) { errln("*** Should have been " + jstLong); //throw new Exception("Error in long TZ name"); } logln(UnicodeString("SHORT zone name = ") + zones[24][4]); if (zones[24][4] != jstShort) { errln("*** Should have been " + jstShort); //throw new Exception("Error in short TZ name"); } delete symbols; }
int main(int argc, char* argv[]) { // Define problem parameters: (x_loc, y_loc) is the center of the circular wave front, R_ZERO is the distance from the // wave front to the center of the circle, and alpha gives the steepness of the wave front. double alpha, x_loc, y_loc, r_zero; switch(PARAM) { case 0: alpha = 20; x_loc = -0.05; y_loc = -0.05; r_zero = 0.7; break; case 1: alpha = 1000; x_loc = -0.05; y_loc = -0.05; r_zero = 0.7; break; case 2: alpha = 1000; x_loc = 1.5; y_loc = 0.25; r_zero = 0.92; break; case 3: alpha = 50; x_loc = 0.5; y_loc = 0.5; r_zero = 0.25; break; default: // The same as 0. alpha = 20; x_loc = -0.05; y_loc = -0.05; r_zero = 0.7; break; } // Set adaptivity options according to the command line argument. int refinement_mode; if (argc != 2) refinement_mode = 0; else { refinement_mode = atoi(argv[1]); if (refinement_mode < 1 || refinement_mode > 12) throw Hermes::Exceptions::Exception("Invalid run case: %d (valid range is [1,12])", refinement_mode); } double threshold = 0.3; // strategy = 0 ... Refine elements until sqrt(threshold) times total error is processed. // If more elements have similar errors, refine all to keep the mesh symmetric. int strategy = 0; // strategy = 1 ... Refine all elements whose error is larger than threshold times max. element error. // Add also the norm of the residual to the error estimate of each element. bool use_residual_estimator = false; // Use energy norm for error estimate normalization and measuring of exact error. bool use_energy_norm_normalization = false; switch (refinement_mode) { case 1: case 2: case 3: case 4: case 5: case 6: { strategy = 0; break; } case 7 : case 8 : case 9 : case 10: case 11: case 12: { strategy = 1; break; } } switch (refinement_mode) { case 1: case 2: case 3: case 7: case 8: case 9: { threshold = 0.3; break; } case 4: case 5: case 6: case 10: case 11: case 12: { threshold = 0.3*0.3; break; } } switch (refinement_mode) { case 2: case 3: case 5: case 6: case 8: case 9: case 11: case 12: { use_residual_estimator = true; break; } } switch (refinement_mode) { case 3: case 6: case 9: case 12: { use_energy_norm_normalization = true; break; } } double setup_time = 0, assemble_time = 0, solve_time = 0, adapt_time = 0; // Time measurement. Hermes::Mixins::TimeMeasurable wall_clock; // Stop counting time for adaptation. wall_clock.tick(); // Load the mesh. Mesh mesh; MeshReaderH2D mloader; mloader.load("square_quad.mesh", &mesh); // Perform initial mesh refinement. for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // Stop counting time for adaptation. wall_clock.tick(); adapt_time += wall_clock.last(); // Set exact solution. CustomExactSolution exact(&mesh, alpha, x_loc, y_loc, r_zero); // Define right-hand side. CustomRightHandSide rhs(alpha, x_loc, y_loc, r_zero); // Initialize the weak formulation. CustomWeakForm wf(&rhs); // Equivalent, but slower: // DefaultWeakFormPoisson<double> wf(Hermes::HERMES_ANY, HERMES_ONE, &rhs); // Initialize boundary conditions. DefaultEssentialBCNonConst<double> bc("Bdy", &exact); EssentialBCs<double> bcs(&bc); // Create an H1 space with default shapeset. H1Space<double> space(&mesh, &bcs, P_INIT); // Initialize approximate solution. Solution<double> sln; // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(800, 0, 400, 400)); sview.show_mesh(false); sview.set_3d_mode(); sview.set_palette(Views::H2DV_PT_HUESCALE); sview.fix_scale_width(50); Views::OrderView oview("Mesh", new Views::WinGeom(0, 0, 800, 800)); oview.set_palette(Views::H2DV_PT_INVGRAYSCALE); // DOF and CPU convergence graphs. ConvergenceTable conv_table; conv_table.add_column(" cycle ", "%6d "); conv_table.add_column(" H1 error ", " %.4e "); conv_table.add_column(" ndof ", " %6d "); conv_table.add_column(" total time ", " %8.3f "); conv_table.add_column(" setup time ", " %8.3f "); conv_table.add_column(" assem time ", " %8.3f "); conv_table.add_column(" solve time ", " %8.3f "); conv_table.add_column(" adapt time ", " %8.3f "); wall_clock.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // Adaptivity loop: int as = 0; bool done = false; do { // Start counting setup time. wall_clock.tick(); // Assemble the discrete problem. DiscreteProblem<double> dp(&wf, &space); // Actual ndof. int ndof = space.get_num_dofs(); NewtonSolver<double> newton(&dp); newton.set_verbose_output(false); // Setup time continues in NewtonSolver::solve(). try { newton.solve(); } catch(Hermes::Exceptions::Exception e) { e.printMsg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; setup_time += newton.get_setup_time(); assemble_time += newton.get_assemble_time(); solve_time += newton.get_solve_time(); // Start counting time for adaptation. wall_clock.tick(); Solution<double>::vector_to_solution(newton.get_sln_vector(), &space, &sln); double err_exact = Global<double>::calc_abs_error(&sln, &exact, HERMES_H1_NORM); // Report results. Hermes::Mixins::Loggable::Static::info(" Cycle %d:", as); Hermes::Mixins::Loggable::Static::info(" Number of degrees of freedom: %d", ndof); Hermes::Mixins::Loggable::Static::info(" H1 error w.r.t. exact soln.: %g", err_exact); // Stop counting time for adaptation. wall_clock.tick(); double accum_time = wall_clock.accumulated(); adapt_time += wall_clock.last(); // View the approximate solution and polynomial orders. //sview.show(&sln); //oview.show(&space); //Views::View::wait(Views::HERMES_WAIT_KEYPRESS); conv_table.add_value(0, as); conv_table.add_value(1, err_exact); conv_table.add_value(2, ndof); conv_table.add_value(3, accum_time); conv_table.add_value(4, setup_time); conv_table.add_value(5, assemble_time); conv_table.add_value(6, solve_time); conv_table.add_value(7, adapt_time); // Start counting time for adaptation. wall_clock.tick(); if (err_exact < ERR_STOP) done = true; else { // Calculate element errors and total error estimate. Hermes::Hermes2D::BasicKellyAdapt<double> adaptivity(&space); unsigned int error_flags = HERMES_TOTAL_ERROR_ABS; if (use_energy_norm_normalization) { error_flags |= HERMES_ELEMENT_ERROR_REL; adaptivity.set_error_form(new EnergyErrorForm(&wf)); } else error_flags |= HERMES_ELEMENT_ERROR_ABS; if (use_residual_estimator) adaptivity.add_error_estimator_vol(new ResidualErrorForm(&rhs)); double err_est_rel = adaptivity.calc_err_est(&sln, error_flags); done = adaptivity.adapt(threshold, strategy, MESH_REGULARITY); // Stop counting time for adaptation. wall_clock.tick(); adapt_time += wall_clock.last(); } // Increase the counter of performed adaptivity steps. if (done == false) as++; else { Hermes::Mixins::Loggable::Static::info("Total running time: %g s", wall_clock.accumulated()); Hermes::Mixins::Loggable::Static::info(" Setup: %g s", setup_time); Hermes::Mixins::Loggable::Static::info(" Assemble: %g s", assemble_time); Hermes::Mixins::Loggable::Static::info(" Solve: %g s", solve_time); Hermes::Mixins::Loggable::Static::info(" Adapt: %g s", adapt_time); //sview.show(&sln); oview.show(&space); oview.save_screenshot(("final_mesh-"+itos(refinement_mode)+".bmp").c_str()); oview.close(); conv_table.save(("conv_table-"+itos(refinement_mode)+".dat").c_str()); } } while (done == false); // Wait for all views to be closed. //Views::View::wait(); return 0; }
INT main(INT argc, CHAR *argv[]) { /********** MAIN PROGRAM ********************************* * Solve Laplace equation using Jacobi iteration method * * *********************************************************/ INT m = M_DEFAULT, mp, k, p, below, above; long iter=MAXSTEPS; REAL TOL=EPS_DEFAULT, del, gdel,start,finish,time; CHAR line[80]; REAL ***v, ***vt, ***vnew; MPI_Init(&argc, &argv); /* starts MPI */ MPI_Comm_rank(MPI_COMM_WORLD, &k); /* get current process id */ MPI_Comm_size(MPI_COMM_WORLD, &p); /* get # procs from env or */ if(k == 0) { fprintf(OUTPUT," Number of args in command line, argc :\n"); fprintf(OUTPUT," argc = %d :\n", argc); if (argc >= 2) fprintf(OUTPUT," arg[1]= %s :\n", argv[1]); if (argc >= 3) fprintf(OUTPUT," arg[2]= %s :\n", argv[2]); if (argc >1){ m=atoi(argv[1]); } if (argc >2 ) { TOL= atof(argv[2]); } fprintf(OUTPUT,"Size of interior points, m :\n"); fprintf(OUTPUT,"m = %d\n",m); fprintf(OUTPUT,"Numerical accuracy, eps :\n"); fprintf(OUTPUT,"eps = %f\n",TOL); fprintf(OUTPUT,"Number of processes, p :\n"); fprintf(OUTPUT,"p = %d\n",p); start=-MPI_Wtime(); } MPI_Bcast(&m, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(&TOL, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); mp = m/p; v = allocate_3D(m, m, mp); /* allocate mem for 2D array */ vt = allocate_3D(mp, m, m); vnew = allocate_3D(mp, m, m); gdel = 1.0; iter = 0; bc(m, m, mp, v, k, p); /* initialize and define B.C. for v */ transpose(m, m, mp, v, vt); /* solve for vt */ /* driven by need of update_bc_2 */ replicate(mp, m, vt, vnew); /* vnew = vt */ neighbors(k, p, MPI_PROC_NULL, &below, &above); /* domain borders */ REAL ro = 1.0 - pow (PI / (2 * (m + 1)), 2); REAL w = 0; while (gdel > TOL) { /* iterate until error below threshold */ iter++; /* increment iteration counter */ if(iter > MAXSTEPS) { fprintf(OUTPUT,"Iteration terminated (exceeds %6d", MAXSTEPS); fprintf(OUTPUT," )\n"); return (0); /* nonconvergent solution */ } /* compute new solution according to the Jacobi scheme */ update_jacobi(mp, m, vt, vnew, &del); /* compute new vt */ /*update_sor(mp, m, vt, vnew, &del, w, 0 );*/ /*update_bc_2( mp, m, vt, k, below, above); [> update b.c. <]*/ /*update_sor(mp, m, vt, vnew, &del, w, 1);*/ /*update_bc_2( mp, m, vt, k, below, above); [> update b.c. <]*/ /*update_w(&w, ro);*/ if(iter%INCREMENT == 0) { gdel = 0; MPI_Allreduce( &del, &gdel, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); /* find global max error */ if( k == 0) { fprintf(OUTPUT,"iter,del,gdel: %6d, %lf %lf\n",iter,del,gdel); } } } if (k == 0) { finish=MPI_Wtime(); time=start+finish; fprintf(OUTPUT,"Stopped at iteration %d\n",iter); fprintf(OUTPUT,"The maximum error = %f\n",gdel); fprintf(OUTPUT,"Time = %f\n",time); } if (FILE_OUT) { /* write v to file for use in MATLAB plots */ transpose(mp, m, m, vt, v); write_file( m, m, mp, v, k, p ); MPI_Barrier(MPI_COMM_WORLD); } free(v); free(vt); free(vnew); /* release allocated arrays */ MPI_Finalize(); return (0); }
int16_t getInt16() { int16_t res = bc()->getInt16(bci_); bci_ += sizeof(int16_t); return res; }
// Alternative, FGL version: optimistic fine-grain locking. // Identifies the relevant edges and points, then locks // them in canonical order, then double-checks to make // sure nothing has changed. // void synchronized_reconsider(edge::Up self, const int seam, simple_queue<edge::Sp> *tentative_edges) { self->set_tentative(false, self); // Do this first, to avoid window where I turn it off // after somebody else has turned it on. point* a = self->get_points(0, self); point* b = self->get_points(1, self); edge::Up ac(self->get_neighbors(0, ccw, self)); edge::Up bc(self->get_neighbors(1, cw, self)); int aci = index_of(ac, a); int bci = index_of(bc, b); if (aci == -1 || bci == -1) { // inconsistent; somebody has already been here return; } point* c = ac->get_points(1-aci, ac); if (c != bc->get_points(1-bci, bc)) { // No triangle on the c side; we're an external edge return; } edge::Up ad(self->get_neighbors(0, cw, self)); edge::Up bd(self->get_neighbors(1, ccw, self)); int adi = index_of(ad, a); int bdi = index_of(bd, b); if (adi == -1 || bdi == -1) { // inconsistent; somebody has already been here return; } point* d = ad->get_points(1-adi, ad); if (d != bd->get_points(1-bdi, bd)) { // No triangle on the d side; we're an external edge return; } { point_set S; with_locked_points cs(S | a | b | c | d); if (!(edges->contains(self) && edges->contains(ac) && edges->contains(bc) && edges->contains(ad) && edges->contains(bd))) { // inconsistent; somebody has already been here return; } if (!(ac == self->get_neighbors(0, ccw, self) && bc == self->get_neighbors(1, cw, self) && ad == self->get_neighbors(0, cw, self) && bd == self->get_neighbors(1, ccw, self))) { // inconsistent; somebody has already been here return; } if (!(aci == index_of(ac, a) && bci == index_of(bc, b) && adi == index_of(ad, a) && bdi == index_of(bd, b))) { // inconsistent; somebody has already been here return; } if (!(c == ac->get_points(1-aci, ac) && c == bc->get_points(1-bci, bc) && d == ad->get_points(1-adi, ad) && d == bd->get_points(1-bdi, bd))) { // inconsistent; somebody has already been here return; } if (encircled(b, c, a, d, ccw) || encircled(a, d, b, c, ccw)) { // other diagonal is locally Delaunay; we're not destroy(self); // can't wait for delayed destructor edge::Sp dum; edge::create(c, d, bc, bd, cw, dum); ac->set_tentative(true, ac); tentative_edges->enqueue(ac, seam); ad->set_tentative(true, ad); tentative_edges->enqueue(ad, seam); bc->set_tentative(true, bc); tentative_edges->enqueue(bc, seam); bd->set_tentative(true, bd); tentative_edges->enqueue(bd, seam); } } }
int main(int argc, char *argv[]) { struct sched_param scp; scp.sched_priority = 60; sched_setscheduler(0, SCHED_FIFO, &scp); mlockall(MCL_FUTURE); allegro_init(); set_color_depth(24); set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 1024, 768, 0, 0); install_keyboard(); install_mouse(); font = load_font("font.fnt", NULL, NULL); BITMAP *wsbuffer = create_bitmap(1024, 768); Box workspace(0, 0, 1024, 768, COLOR_PLAYER, Box::TYPE_FLAT); BarCounter bc(902, 16); workspace.addChild(new Image(0, 0, 32, 768, "left.bmp")); workspace.addChild(new Image(992, 0, 32, 768, "right.bmp")); workspace.addChild(&bc); workspace.addChild(new PeakMeter(907, 50)); BITMAP *splash = load_bitmap("splash.bmp", 0); blit(splash, screen, 0, 0, 0, 0, 1024, 768); destroy_bitmap(splash); sound->init(162, &bc); // FIXME changing tempo. loader = new Loader(); for(int i = 0; i < NUMBER_PLAYERS; i++){ workspace.addChild(new Player(96 * i, COLOR_PLAYER)); sound->update(); } workspace.paint(); show_mouse(screen); bool mbdown = false; bool wsneedsredraw = false; int dragstart_x = 0; int dragstart_y = 0; int mickey_x = 0; int mickey_y = 0; bool taking_screenshot = false; while(!(key[KEY_LSHIFT] && key[KEY_LCONTROL] && key[KEY_ESC])){ sound->update(); bc.paintIfNeeded(); // Screenshot if(key[KEY_F12] && !taking_screenshot){ taking_screenshot = true; save_bitmap("shot.bmp", screen, 0); } else if(taking_screenshot){ taking_screenshot = false; } if(loader->needsDisplay()){ if(!wsneedsredraw){ scare_mouse(); blit(screen, wsbuffer, 0, 0, 0, 0, 1024, 768); unscare_mouse(); loader->paint(); wsneedsredraw = true; } if(key[KEY_ESC]) loader->cancelDisplay(); } else if(wsneedsredraw) { scare_mouse(); blit(wsbuffer, screen, 0, 0, 0, 0, 1024, 768); bc.paint(); workspace.paintIfNeeded(); unscare_mouse(); wsneedsredraw = false; } else { workspace.paintIfNeeded(); } if((mouse_b) && !mbdown) { if(loader->needsDisplay()) { loader->mouseEvent(mouse_x, mouse_y, mouse_b); } else { workspace.mouseEvent(mouse_x, mouse_y, mouse_b); } mbdown = true; dragstart_x = mouse_x; dragstart_y = mouse_y; show_mouse(0); get_mouse_mickeys(&mickey_x, &mickey_y); } else if (!mouse_b && mbdown) { mbdown = false; position_mouse(dragstart_x, dragstart_y); show_mouse(screen); } else if (mbdown) { // Trigger drag events get_mouse_mickeys(&mickey_x, &mickey_y); if(!loader->needsDisplay()){ if(mickey_x != 0 || mickey_y != 0) workspace.dragEvent(dragstart_x, dragstart_y, mickey_x, mickey_y); } } usleep(100); } // sound->system->release(); delete logg; set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); return 0; }
dtStatus dtTileCache::buildNavMeshTile(const dtCompressedTileRef ref, dtNavMesh* navmesh) { dtAssert(m_talloc); dtAssert(m_tcomp); unsigned int idx = decodeTileIdTile(ref); if (idx > (unsigned int)m_params.maxTiles) return DT_FAILURE | DT_INVALID_PARAM; const dtCompressedTile* tile = &m_tiles[idx]; unsigned int salt = decodeTileIdSalt(ref); if (tile->salt != salt) return DT_FAILURE | DT_INVALID_PARAM; m_talloc->reset(); BuildContext bc(m_talloc); const int walkableClimbVx = (int)(m_params.walkableClimb / m_params.ch); dtStatus status; // Decompress tile layer data. status = dtDecompressTileCacheLayer(m_talloc, m_tcomp, tile->data, tile->dataSize, &bc.layer); if (dtStatusFailed(status)) return status; #if 0 if (tile->header->tx != 1 || tile->header->ty != 0 || tile->header->tlayer < 1) return status; #endif // Rasterize obstacles. for (int i = 0; i < m_params.maxObstacles; ++i) { const dtTileCacheObstacle* ob = &m_obstacles[i]; if (ob->state == DT_OBSTACLE_EMPTY || ob->state == DT_OBSTACLE_REMOVING) continue; if (contains(ob->touched, ob->ntouched, ref)) { dtMarkCylinderArea(*bc.layer, tile->header->bmin, m_params.cs, m_params.ch, ob->pos, ob->radius, ob->height, 0); } } if (m_tmproc) { m_tmproc->markAreas(bc.layer, tile->header->bmin, m_params.cs, m_params.ch); } // Build navmesh if (m_params.regionPartitioning == DT_REGION_MONOTONE) { status = dtBuildTileCacheRegionsMonotone(m_talloc, m_params.minRegionArea, m_params.mergeRegionArea, *bc.layer); } else if (m_params.regionPartitioning == DT_REGION_WATERSHED) { bc.dfield = dtAllocTileCacheDistanceField(m_talloc); if (!bc.dfield) return status; status = dtBuildTileCacheDistanceField(m_talloc, *bc.layer, *bc.dfield); if (dtStatusFailed(status)) return status; status = dtBuildTileCacheRegions(m_talloc, m_params.minRegionArea, m_params.mergeRegionArea, *bc.layer, *bc.dfield); } else { status = dtBuildTileCacheRegionsChunky(m_talloc, m_params.minRegionArea, m_params.mergeRegionArea, *bc.layer, m_params.regionChunkSize); } if (dtStatusFailed(status)) return status; bc.lcset = dtAllocTileCacheContourSet(m_talloc); bc.lclusters = dtAllocTileCacheClusterSet(m_talloc); if (!bc.lcset || !bc.lclusters) return status; status = dtBuildTileCacheContours(m_talloc, *bc.layer, walkableClimbVx, m_params.maxSimplificationError, m_params.cs, m_params.ch, *bc.lcset, *bc.lclusters); if (dtStatusFailed(status)) return status; bc.lmesh = dtAllocTileCachePolyMesh(m_talloc); if (!bc.lmesh) return status; status = dtBuildTileCachePolyMesh(m_talloc, 0, *bc.lcset, *bc.lmesh); if (dtStatusFailed(status)) return status; // Early out if the mesh tile is empty. if (!bc.lmesh->npolys) return DT_SUCCESS; status = dtBuildTileCacheClusters(m_talloc, *bc.lclusters, *bc.lmesh); if (dtStatusFailed(status)) return status; dtNavMeshCreateParams params; memset(¶ms, 0, sizeof(params)); params.verts = bc.lmesh->verts; params.vertCount = bc.lmesh->nverts; params.polys = bc.lmesh->polys; params.polyAreas = bc.lmesh->areas; params.polyFlags = bc.lmesh->flags; params.polyCount = bc.lmesh->npolys; params.nvp = DT_VERTS_PER_POLYGON; params.walkableHeight = m_params.walkableHeight; params.walkableRadius = m_params.walkableRadius; params.walkableClimb = m_params.walkableClimb; params.tileX = tile->header->tx; params.tileY = tile->header->ty; params.tileLayer = tile->header->tlayer; params.cs = m_params.cs; params.ch = m_params.ch; params.buildBvTree = false; dtVcopy(params.bmin, tile->header->bmin); dtVcopy(params.bmax, tile->header->bmax); params.polyClusters = bc.lclusters->polyMap; params.clusterCount = (unsigned short)bc.lclusters->nclusters; if (m_tmproc) { m_tmproc->process(¶ms, bc.lmesh->areas, bc.lmesh->flags); } unsigned char* navData = 0; int navDataSize = 0; if (!dtCreateNavMeshData(¶ms, &navData, &navDataSize)) return DT_FAILURE; // Remove existing tile. navmesh->removeTile(navmesh->getTileRefAt(tile->header->tx,tile->header->ty,tile->header->tlayer),0,0); // Add new tile, or leave the location empty. if (navData) { // Let the navmesh own the data. status = navmesh->addTile(navData,navDataSize,DT_TILE_FREE_DATA,0,0); if (dtStatusFailed(status)) { dtFree(navData); return status; } } return DT_SUCCESS; }
/* * @test @(#)bug4117335.java 1.1 3/5/98 * * @bug 4117335 */ void DateFormatMiscTests::test4117335() { //UnicodeString bc = "\u7d00\u5143\u524d"; UChar bcC [] = { 0x7D00, 0x5143, 0x524D }; UnicodeString bc(bcC, 3, 3); //UnicodeString ad = "\u897f\u66a6"; UChar adC [] = { 0x897F, 0x66A6 }; UnicodeString ad(adC, 2, 2); //UnicodeString jstLong = "\u65e5\u672c\u6a19\u6e96\u6642"; UChar jstLongC [] = { 0x65e5, 0x672c, 0x6a19, 0x6e96, 0x6642 }; UChar jdtLongC [] = {0x65E5, 0x672C, 0x590F, 0x6642, 0x9593}; UnicodeString jstLong(jstLongC, 5, 5); // UnicodeString jstShort = "JST"; UnicodeString tzID = "Asia/Tokyo"; UnicodeString jdtLong(jdtLongC, 5, 5); // UnicodeString jdtShort = "JDT"; UErrorCode status = U_ZERO_ERROR; DateFormatSymbols *symbols = new DateFormatSymbols(Locale::getJapan(), status); if(U_FAILURE(status)) { dataerrln("Failure creating DateFormatSymbols, %s", u_errorName(status)); delete symbols; return; } failure(status, "new DateFormatSymbols"); int32_t eraCount = 0; const UnicodeString *eras = symbols->getEraNames(eraCount); logln(UnicodeString("BC = ") + eras[0]); if (eras[0] != bc) { errln("*** Should have been " + bc); //throw new Exception("Error in BC"); } logln(UnicodeString("AD = ") + eras[1]); if (eras[1] != ad) { errln("*** Should have been " + ad); //throw new Exception("Error in AD"); } int32_t rowCount, colCount; const UnicodeString **zones = symbols->getZoneStrings(rowCount, colCount); //don't hard code the index .. compute it. int32_t index = -1; for (int32_t i = 0; i < rowCount; ++i) { if (tzID == (zones[i][0])) { index = i; break; } } logln(UnicodeString("Long zone name = ") + zones[index][1]); if (zones[index][1] != jstLong) { errln("*** Should have been " + prettify(jstLong)+ " but it is: " + prettify(zones[index][1])); //throw new Exception("Error in long TZ name"); } // logln(UnicodeString("Short zone name = ") + zones[index][2]); // if (zones[index][2] != jstShort) { // errln("*** Should have been " + prettify(jstShort) + " but it is: " + prettify(zones[index][2])); // //throw new Exception("Error in short TZ name"); // } logln(UnicodeString("Long zone name = ") + zones[index][3]); if (zones[index][3] != jdtLong) { errln("*** Should have been " + prettify(jstLong) + " but it is: " + prettify(zones[index][3])); //throw new Exception("Error in long TZ name"); } // logln(UnicodeString("SHORT zone name = ") + zones[index][4]); // if (zones[index][4] != jdtShort) { // errln("*** Should have been " + prettify(jstShort)+ " but it is: " + prettify(zones[index][4])); // //throw new Exception("Error in short TZ name"); // } delete symbols; }
// 与えられた変換で曲線のトランスフォームを行いオブジェクトを生成する。 //General transformation of the curve. MGRSBRep MGRSBRep::operator* (const MGTransf& tr) const{ MGSPointSeq bc(m_surface.surface_bcoef()); bc.homogeneous_transform(tr); return MGRSBRep(bc,m_surface.knot_vector_u(),m_surface.knot_vector_v()); }
bool vc1::parse_sequence_header(const unsigned char *buf, int size, vc1::sequence_header_t &seqhdr) { try { static const struct { int n, d; } s_aspect_ratios[13] = { { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 }, { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 }, { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 }, { 160, 99 } }; static const int s_framerate_nr[5] = { 24, 25, 30, 50, 60 }; static const int s_framerate_dr[2] = { 1000, 1001 }; bit_reader_c bc(buf, size); vc1::sequence_header_t hdr; bc.skip_bits(32); // Marker hdr.profile = bc.get_bits(2); if (VC1_PROFILE_ADVANCED != hdr.profile) return false; hdr.level = bc.get_bits(3); hdr.chroma_format = bc.get_bits(2); hdr.frame_rtq_postproc = bc.get_bits(3); hdr.bit_rtq_postproc = bc.get_bits(5); hdr.postproc_flag = bc.get_bit(); hdr.pixel_width = (bc.get_bits(12) + 1) << 1; hdr.pixel_height = (bc.get_bits(12) + 1) << 1; hdr.pulldown_flag = bc.get_bit(); hdr.interlace_flag = bc.get_bit(); hdr.tf_counter_flag = bc.get_bit(); hdr.f_inter_p_flag = bc.get_bit(); bc.skip_bits(1); // reserved hdr.psf_mode_flag = bc.get_bit(); hdr.display_info_flag = bc.get_bit(); if (hdr.display_info_flag) { hdr.display_width = bc.get_bits(14) + 1; hdr.display_height = bc.get_bits(14) + 1; hdr.aspect_ratio_flag = bc.get_bit(); if (hdr.aspect_ratio_flag) { int aspect_ratio_idx = bc.get_bits(4); if ((0 < aspect_ratio_idx) && (14 > aspect_ratio_idx)) { hdr.aspect_ratio_width = s_aspect_ratios[aspect_ratio_idx - 1].n; hdr.aspect_ratio_height = s_aspect_ratios[aspect_ratio_idx - 1].d; } else if (15 == aspect_ratio_idx) { hdr.aspect_ratio_width = bc.get_bits(8); hdr.aspect_ratio_height = bc.get_bits(8); if ((0 == hdr.aspect_ratio_width) || (0 == hdr.aspect_ratio_height)) hdr.aspect_ratio_flag = false; } else hdr.aspect_ratio_flag = false; } hdr.framerate_flag = bc.get_bit(); if (hdr.framerate_flag) { if (bc.get_bit()) { hdr.framerate_num = 32; hdr.framerate_den = bc.get_bits(16) + 1; } else { int nr = bc.get_bits(8); int dr = bc.get_bits(4); if ((0 != nr) && (8 > nr) && (0 != dr) && (3 > dr)) { hdr.framerate_num = s_framerate_dr[dr - 1]; hdr.framerate_den = s_framerate_nr[nr - 1] * 1000; } else hdr.framerate_flag = false; } } if (bc.get_bit()) { hdr.color_prim = bc.get_bits(8); hdr.transfer_char = bc.get_bits(8); hdr.matrix_coef = bc.get_bits(8); } } hdr.hrd_param_flag = bc.get_bit(); if (hdr.hrd_param_flag) { hdr.hrd_num_leaky_buckets = bc.get_bits(5); bc.skip_bits(4 + 4); // bitrate exponent, buffer size exponent bc.skip_bits(hdr.hrd_num_leaky_buckets * (16 + 16)); // hrd_rate, hrd_buffer } memcpy(&seqhdr, &hdr, sizeof(vc1::sequence_header_t)); return true; } catch (...) { return false; } }
main() { int x_a[10] = {4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, }; int x_b =8888; int x_e[2] = {4444, 4444, }; int x_c[3] = {4444, 4444, 4444, }; for( x_b = 1 ; x_b <= 10 ; x_b ++) { x_a[(-1)*1+ bc("a", 4, 1, 10, x_b ) ] = 100 + x_b ; } for( x_b = 0 - 2 ; x_b >= 0 - 4 ; x_b --) { x_c[(-1)*-4+ bc("c", 8, -4, -2, x_b ) ] = 1000 - x_b ; } printf( "%s\n", "forward x: a" ); { int x_x ; int i; for(i=1; i<=10; i++) { x_x = x_a[i-(1)]; { int x_a =8888; x_a = 12 ; printf( "%d\n", x_x ); printf( "%d\n", x_a ); } } } printf( "%s\n", "forward x: c" ); { int x_x ; int i; for(i=-4; i<=-2; i++) { x_x = x_c[i-(-4)]; { int x_c[4] = {4444, 4444, 4444, 4444, }; printf( "%d\n", x_x ); printf( "%d\n", x_c[(-1)*22+ bc("c", 23, 22, 25, 24 ) ] ); { int x_x ; int i; for(i=22; i<=25; i++) { x_x = i; { x_c[(-1)*22+ bc("c", 25, 22, 25, x_x ) ] = 20000 + x_x ; } } } { int x_x ; int i; for(i=22; i<=25; i++) { x_x = x_c[i-(22)]; { printf( "%d\n", x_x ); } } } printf( "%d\n", x_x ); } } } printf( "%s\n", "bottom forward x: c" ); { int x_x ; int i; for(i=-4; i<=-2; i++) { x_x = x_c[i-(-4)]; { int x_c[4] = {4444, 4444, 4444, 4444, }; printf( "%d\n", x_x ); printf( "%d\n", x_c[(-1)*22+ bc("c", 37, 22, 25, 24 ) ] ); { int x_y ; int i; for(i=22; i<=25; i++) { x_y = i; { x_c[(-1)*22+ bc("c", 39, 22, 25, x_y ) ] = 20000 + x_y ; } } } { int x_y ; int i; for(i=22; i<=25; i++) { x_y = x_c[i-(22)]; { printf( "%d\n", x_y ); { int x_y ; int i; for(i=84; i<=85; i++) { x_y = i; { printf( "%d\n", x_y ); } } } } } } printf( "%d\n", x_x ); } } } }
int main(int argc, char **argv) { dest_x=0; dest_y=6000; v = 200; numberofobjects = 2; v1 = 100; ra[0][5] = 400; ra[1][5] = 400; ra[2][5] = 400; ra[3][5] = 400; //argv[1]="-rh"; //argv[2]="10.2.36.7"; //argc=3; BotConnector bc(argc, argv); if( bc.connect() ) { printf( "Connected to Robot\n" ); } else { printf( "Connection attempt to Robot failed, Sorry :(\n" ); return EXIT_SUCCESS; } argv[1]="-rrtp"; argv[2]="8102"; argc=3; BotConnector bc1(argc, argv); if( bc1.connect() ) { printf( "Connected to Robot1\n" ); } else { printf( "Connection attempt to Robot failed, Sorry :(\n" ); return EXIT_SUCCESS; } // bc.setRobotVelocity_idle(100,100); // initialising vr and vl bc.setRobotVelocity(100,100, 10000); bc.getAngles(0);// updating ra[][]. // omnicx = ra[0][1]+ra[0][5]*cos(ra[0][0]); // omnicy = ra[0][2]+ra[0][5]*sin(ra[0][0]); //bc1.moveRobot(0,90); //bc1.setRobotVelocity(100,100, 10000); bc1.moveRobot(6000,90); //bc1.setRobotVelocity(100,100, 30000); bc1.moveRobot(0,180); argv[1]="-rrtp"; argv[2]="8103"; argc=3; BotConnector bc2(argc, argv); if( bc2.connect() ) { printf( "Connected to Robot2\n" ); } else { printf( "Connection attempt to Robot failed, Sorry :(\n" ); return EXIT_SUCCESS; } bc2.moveRobot(2000,90); //bc2.setRobotVelocity(100,100, 20000); bc2.moveRobot(2000,-45); //bc2.setRobotVelocity(200,200, 25000); bc2.moveRobot(0,135); /* argv[1]="-rrtp"; argv[2]="8104"; argc=3; BotConnector bc3(argc, argv); if( bc3.connect() ) { printf( "Connected to Robot\n" ); } else { printf( "Connection attempt to Robot failed, Sorry :(\n" ); return EXIT_SUCCESS; } //bc.setVelocity1(-100,-100, 10000); bc3.moveRobot(0,90); bc3.setRobotVelocity(150,150, 30000); bc3.moveRobot(0,-125); bc3.setRobotVelocity(100,100, 20000); bc3.moveRobot(0,180);*/ /*argv[1]="-rrtp"; argv[2]="8105"; argc=3; BotConnector bc4(argc, argv); if( bc4.connect() ) { printf( "Connected to Robot\n" ); } else { printf( "Connection attempt to Robot failed, Sorry :(\n" ); return EXIT_SUCCESS; } //bc.setVelocity1(-100,-100, 10000); bc4.getAngles(4); bc4.moveRobot(0,90); bc4.setRobotVelocity(100,100, 40000); bc4.moveRobot(0,0); bc4.setRobotVelocity(200,200, 25000); bc4.moveRobot(0,180); argv[1]="-rrtp"; argv[2]="8106"; argc=3; BotConnector bc5(argc, argv); if( bc5.connect() ) { printf( "Connected to Robot\n" ); } else { printf( "Connection attempt to Robot failed, Sorry :(\n" ); return EXIT_SUCCESS; } //bc.setVelocity1(-100,-100, 10000); bc5.getAngles(5); bc5.moveRobot(0,90); bc5.setRobotVelocity(200,200, 25000); bc5.moveRobot(0,-80); bc5.setRobotVelocity(300,300, 15000); bc5.moveRobot(0,180);*/ bc.setRobotVelocity(-100,-100, 10000); bc.moveRobot(0,90); bc.getAngles(0); bc1.getAngles(1); bc2.getAngles(2); omnicx = ra[0][1]; omnicy = ra[0][2]+300; //bc3.getAngles(3); /*bc4.getAngles(4); bc5.getAngles(5);*/ ArUtil::sleep(5000); int f; for(f=0;f<200;f++) { float dest,dest1; int j; dest = tan_inv((dest_y-omnicy),(dest_x-omnicx)); j=update(dest); right_left(); // robot_motion(); bc.setRobotVelocity_idle(vright,vleft); bc1.setRobotVelocity_idle(100,100); bc2.setRobotVelocity_idle(100,100); // bc3.setRobotVelocity_idle(250,250); /*bc4.setRobotVelocity_idle(250,250); bc5.setRobotVelocity_idle(250,250);*/ ArUtil::sleep(300); bc.getAngles(0); bc1.getAngles(1); bc2.getAngles(2); //bc3.getAngles(3); omnicx = omnicx+ra[0][3]*0.3; omnicy = omnicy+ra[0][4]*0.3; /*bc.setRobotVelocity_idle(0,0); bc1.setRobotVelocity_idle(0,0); bc2.setRobotVelocity_idle(0,0); bc3.setRobotVelocity_idle(0,0);*/ // omnicx = ra[0][1]+ra[0][5]*cos(ra[0][0]); //omnicy = ra[0][2]+ra[0][5]*sin(ra[0][0]); printf("omnicx = %f, omnicy = %f\n",omnicx,omnicy); printf("x = %d",f); /* bc3.getAngles(3); bc4.getAngles(4); bc5.getAngles(5);*/ } return bc.disconnect(); }
int64_t getInt() { int64_t res = bc()->getInt64(bci_); bci_ += sizeof(int64_t); return res; }
main() { int x_a[] = {1, 10, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, }; int x_b =8888; int x_e =8888; int x_c[] = {-4, 3, 4444, 4444, 4444, 4444, }; for( x_b = 1 ; x_b <= 10 ; x_b ++) { printf("%d\n", x_b ); printf("%d\n", x_a[bc(x_a, 5, x_b , 'a')] ); } for( x_b = 0 - 4 ; x_b <= 0 - 2 ; x_b ++) { printf("%d\n", x_b ); printf("%d\n", x_c[bc(x_c, 10, x_b , 'c')] ); } for( x_b = 1 ; x_b <= 10 ; x_b ++) { x_a[bc(x_a, 14, x_b , 'a')] = 100 - x_b ; } for( x_b = 1 ; x_b <= 10 ; x_b ++) { printf("%d\n", x_b ); printf("%d\n", x_a[bc(x_a, 19, x_b , 'a')] ); } for( x_b = 1 ; x_b <= 9 ; x_b ++) { for( x_e = x_b + 1 ; x_e <= 11 ; x_e ++) { if( x_a[bc(x_a, 25, x_b , 'a')] > x_a[bc(x_a, 25, x_e , 'a')] ) { int x_t =8888; x_t = x_a[bc(x_a, 27, x_b , 'a')] ; x_a[bc(x_a, 28, x_b , 'a')] = x_a[bc(x_a, 28, x_e , 'a')] ; x_a[bc(x_a, 29, x_e , 'a')] = x_t ; } } } for( x_b = 1 ; x_b <= 10 ; x_b ++) { printf("%d\n", x_b ); printf("%d\n", x_a[bc(x_a, 36, x_b , 'a')] ); } }
uint16_t getUInt16() { uint16_t res = bc()->getUInt16(bci_); bci_ += sizeof(uint16_t); return res; }
void TriangleMesherInterface :: simplifyPSLG(Triangle_PSLG &coarse, const Triangle_PSLG &pslg, double limit, double minlen) { int segments = pslg.segment_a.giveSize(); int nodes = pslg.nx.giveSize(); // Calculate the inverted connection node->element std :: set< int > *connectivity = new std :: set< int > [ nodes ]; for ( int i = 0; i < segments; i++ ) { connectivity [ pslg.segment_a[i] - 1 ].insert(i + 1); connectivity [ pslg.segment_b[i] - 1 ].insert(i + 1); } // Some conservative error measure IntArray nodeRemoval(nodes); IntArray edgeRemoval(segments); edgeRemoval.zero(); IntArray seg_a = pslg.segment_a; IntArray seg_b = pslg.segment_b; nodeRemoval.zero(); FloatArray error_x(nodes), error_y(nodes), ab(2), ac(2), bc(2), err_vec(2); error_x.zero(); error_y.zero(); for ( int j = 0; j < 2; ++j ) { double allowed = j * limit / 2; for ( int i = 1; i <= nodes; i++ ) { std :: set< int > &elems = connectivity [ i - 1 ]; #if 1 if ( elems.size() < 2 ) { // Lone nodes or edges are removed. It is up for discussion whether or not this is a wanted. nodeRemoval.at(i) = true; if ( elems.size() == 1 ) { int e0 = * elems.begin(); edgeRemoval.at(e0) = true; // Find the other node and remove segment e0 from it; int n1 = seg_a.at(e0) == i ? seg_b.at(e0) : seg_a.at(e0); connectivity [ n1 - 1 ].erase(e0); elems.clear(); /*printf("Removing edge %d and node = %d\n", e0, n1); * while (connectivity[n1-1].size() < 2) { * nodeRemoval.at(n1) = true; * if (connectivity[n1-1].size() == 1) { * e0 = *connectivity[n1-1].begin(); * edgeRemoval.at(e0) = true; * connectivity[n1-1].clear(); * n1 = seg_a.at(e0) == i ? seg_b.at(e0) : seg_a.at(e0); * connectivity[n1-1].erase(e0); * } else { * OOFEM_WARNING("HAPPENS ONCE!"); * break; * } * }*/ } } else #endif if ( elems.size() == 2 ) { int e0 = * elems.begin(); int e1 = * ( ++elems.begin() ); if ( pslg.segment_marker.at(e0) == pslg.segment_marker.at(e1) ) { double abac, acac; int n0, n1, n2; n0 = seg_a.at(e0) == i ? seg_b.at(e0) : seg_a.at(e0); n1 = i; n2 = seg_a.at(e1) == i ? seg_b.at(e1) : seg_a.at(e1); ab[0] = pslg.nx.at(n1) - pslg.nx.at(n0); ab[1] = pslg.ny.at(n1) - pslg.ny.at(n0); ac[0] = pslg.nx.at(n2) - pslg.nx.at(n0); ac[1] = pslg.ny.at(n2) - pslg.ny.at(n0); abac = ab.dotProduct(ac); acac = ac.computeSquaredNorm(); // Find the error (how far the point would be moved to obtain the following line without it). if ( abac <= 0 || acac == 0 ) { // then -ab err_vec[0] = -ab[0]; err_vec[1] = -ab[1]; } else if ( abac >= acac ) { // then bc err_vec[0] = pslg.nx.at(n2) - pslg.nx.at(n1); err_vec[1] = pslg.ny.at(n2) - pslg.ny.at(n1); } else { err_vec = ac; err_vec.times(abac / acac); err_vec.subtract(ab); } double ev_norm = err_vec.computeNorm(); // Max of new or old error; double real_error = 0.0; if ( ev_norm == 0 ) { real_error = 0.0; } else { error_x.at(n1) += err_vec[0]; error_y.at(n1) += err_vec[1]; real_error = sqrt( error_x.at(n1) * error_x.at(n1) + error_y.at(n1) * error_y.at(n1) ); } if ( real_error <= allowed ) { // Mark node for removal, remove second edge, more first edge connection to next node; nodeRemoval.at(i) = true; edgeRemoval.at(e1) = true; connectivity [ n2 - 1 ].erase(e1); connectivity [ n2 - 1 ].insert(e0); if ( seg_a.at(e0) == n1 ) { // Doing the bothersome way to preserve direction of segments. seg_a.at(e0) = n2; } else { seg_b.at(e0) = n2; } elems.clear(); // Accumulate the error vector error_x.at(n0) += error_x.at(n1); error_y.at(n0) += error_y.at(n1); error_x.at(n2) += error_x.at(n1); error_y.at(n2) += error_y.at(n1); } } } } } // Deleting the elements which are too short. bool edgeRemoved = true; while ( edgeRemoved ) { edgeRemoved = false; for ( int i = 1; i <= nodes; i++ ) { std :: set< int > &elems = connectivity [ i - 1 ]; if ( elems.size() == 2 ) { int e0 = * elems.begin(); int e1 = * ( ++elems.begin() ); if ( pslg.segment_marker.at(e0) == pslg.segment_marker.at(e1) ) { int n0, n1, n2; n0 = seg_a.at(e0) == i ? seg_b.at(e0) : seg_a.at(e0); n1 = i; n2 = seg_a.at(e1) == i ? seg_b.at(e1) : seg_a.at(e1); ab[0] = pslg.nx.at(n1) - pslg.nx.at(n0); ab[1] = pslg.ny.at(n1) - pslg.ny.at(n0); bc[0] = pslg.nx.at(n2) - pslg.nx.at(n1); bc[1] = pslg.ny.at(n2) - pslg.ny.at(n1); if ( ab.computeSquaredNorm() < minlen * minlen || bc.computeSquaredNorm() < minlen * minlen ) { // Mark node for removal, remove second edge, more first edge connection to next node; nodeRemoval.at(i) = true; edgeRemoval.at(e1) = true; connectivity [ n2 - 1 ].erase(e1); connectivity [ n2 - 1 ].insert(e0); if ( seg_a.at(e0) == n1 ) { // Doing the bothersome way to preserve direction of segments. seg_a.at(e0) = n2; } else { seg_b.at(e0) = n2; } elems.clear(); edgeRemoved = true; } } } } } // Remove simple double-connections like o<--->o for ( int i = 1; i <= nodes; i++ ) { std :: set< int > &elems = connectivity [ i - 1 ]; if ( elems.size() == 2 ) { int e0 = * elems.begin(); int e1 = * ( ++elems.begin() ); int n0 = seg_a.at(e0) == i ? seg_b.at(e0) : seg_a.at(e0); int n1 = i; int n2 = seg_a.at(e1) == i ? seg_b.at(e1) : seg_a.at(e1); if ( n0 == n2 ) { // Then we have a simple double connection. We get rid of this node and the two edges. nodeRemoval.at(n1) = true; edgeRemoval.at(e0) = true; edgeRemoval.at(e1) = true; connectivity [ n1 - 1 ].erase(e0); connectivity [ n1 - 1 ].erase(e1); connectivity [ n2 - 1 ].erase(e0); connectivity [ n2 - 1 ].erase(e1); if ( connectivity [ n1 - 1 ].size() == 0 ) { nodeRemoval.at(n2) = true; } } } } delete[] connectivity; // Cleanup int newNodes = 0; IntArray newNumber(nodes); newNumber.zero(); coarse.nx.resize(nodes); coarse.ny.resize(nodes); for ( int i = 1; i <= nodes; i++ ) { if ( !nodeRemoval.at(i) ) { newNodes++; coarse.nx.at(newNodes) = pslg.nx.at(i); coarse.ny.at(newNodes) = pslg.ny.at(i); newNumber.at(i) = newNodes; } } coarse.nx.resize(newNodes); coarse.ny.resize(newNodes); int newSegments = 0; coarse.segment_a.resize(segments); coarse.segment_b.resize(segments); coarse.segment_marker.resize(segments); for ( int i = 1; i <= segments; i++ ) { if ( !edgeRemoval.at(i) ) { newSegments++; coarse.segment_a.at(newSegments) = newNumber.at( seg_a.at(i) ); coarse.segment_b.at(newSegments) = newNumber.at( seg_b.at(i) ); coarse.segment_marker.at(newSegments) = pslg.segment_marker.at(i); } } coarse.segment_a.resize(newSegments); coarse.segment_b.resize(newSegments); coarse.segment_marker.resize(newSegments); }
double getDouble() { double res = bc()->getDouble(bci_); bci_ += sizeof(double); return res; }
main() { int x_a[] = {1, 10, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, }; int x_b[] = {1, 10, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, }; int x_k =8888; { int x_x ; int indexx; for( indexx=( x_a [1]-1);indexx>=0;indexx--) { x_x = indexx+ x_a [0]; { x_a[bc(x_a, 4, x_x , 'a')] = 1000 - x_x ; } } } { int x_x ; int indexx; for( indexx=0;indexx< x_a [1];indexx++) { x_x = x_a [indexx+2]; { printf("%d\n", x_x ); x_a[bc(x_a, 9, 5 , 'a')] = 100 ; } } } { int x_x ; int indexx; for( indexx=( x_b [1]-1);indexx>=0;indexx--) { x_x = indexx+ x_b [0]; { x_b[bc(x_b, 13, x_x , 'b')] = 3000 - x_x ; } } } x_k = 0 ; { int x_x ; int indexx; for( indexx=0;indexx< x_b [1];indexx++) { x_x = x_b [indexx+2]; { x_k = x_k + 1 ; x_b[bc(x_b, 20, x_k , 'b')] = 9000 - x_k ; printf("%d\n", x_x ); } } } { int x_x ; int indexx; for( indexx=0;indexx< x_b [1];indexx++) { x_x = x_b [indexx+2]; { printf("%d\n", x_x ); } } } }
// can be instantiated with // <edge::Rp, edge::Wp> or <edge::Up, edge::Up>. bool reconsider(edgeWp self, const int seam, edge::Sp& e1, edge::Sp& e2, edge::Sp& e3, edge::Sp& e4) { e1 = edge::Sp(NULL); e2 = edge::Sp(NULL); e3 = edge::Sp(NULL); e4 = edge::Sp(NULL); self->set_tentative(false, self); point* a = self->get_points(0, self); assert (txnal<edgeRp>() || closest_seam(a) == seam); point* b = self->get_points(1, self); assert (txnal<edgeRp>() || closest_seam(b) == seam); edgeRp ac(self->get_neighbors(0, ccw, self)); edgeRp bc(self->get_neighbors(1, cw, self)); point* c = ac->get_points(1-index_of(ac, a), ac); // a and b are assumed to be closest to my seam. // I have to check c and d. if (!txnal<edgeRp>() && closest_seam(c) != seam) { // I can't safely consider this flip in this phase of // the algorithm. Defer to synchronized phase. self->set_tentative(true, self); return false; } if (c != bc->get_points(1-index_of(bc, b), bc)) { // No triangle on the c side; we're an external edge return true; } edgeRp ad(self->get_neighbors(0, cw, self)); edgeRp bd(self->get_neighbors(1, ccw, self)); point* d = ad->get_points(1-index_of(ad, a), ad); if (!txnal<edgeRp>() && closest_seam(d) != seam) { // I can't safely consider this flip in this phase of // the algorithm. Defer to synchronized phase. self->set_tentative(true, self); return false; } if (d != bd->get_points(1-index_of(bd, b), bd)) { // No triangle on the d side; we're an external edge return true; } if (encircled(b, c, a, d, ccw) || encircled(a, d, b, c, ccw)) { // other diagonal is locally Delaunay; we're not destroy(self); // can't wait for delayed destructor edgeWp ac_w(ac); edgeWp ad_w(ad); edgeWp bc_w(bc); edgeWp bd_w(bd); edge::Sp dum; edge::create(c, d, bc_w, bd_w, cw, dum); // Aliasing problem here: since edge constructor modifies // neighbors, I can't safely use ac, bc, ad, or bd after this // call. Must use writable versions instead. if (!ac_w->get_tentative(ac_w)) { ac_w->set_tentative(true, ac_w); e1 = ac_w; } if (!ad_w->get_tentative(ad_w)) { ad_w->set_tentative(true, ad_w); e2 = ad_w; } if (!bc_w->get_tentative(bc_w)) { bc_w->set_tentative(true, bc_w); e3 = bc_w; } if (!bd_w->get_tentative(bd_w)) { bd_w->set_tentative(true, bd_w); e4 = bd_w; } } return true; }
void BwCtrlWindow::updateBandwidth() { QTreeWidget *peerTreeWidget = bwTreeWidget; peerTreeWidget->clear(); RsConfigDataRates totalRates; std::map<RsPeerId, RsConfigDataRates> rateMap; std::map<RsPeerId, RsConfigDataRates>::iterator it; rsConfig->getTotalBandwidthRates(totalRates); rsConfig->getAllBandwidthRates(rateMap); /* insert */ QTreeWidgetItem *item = new QTreeWidgetItem(); peerTreeWidget->addTopLevelItem(item); peerTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); /* do Totals */ item -> setData(COLUMN_PEERID, Qt::DisplayRole, tr("TOTALS")); item -> setData(COLUMN_RSNAME, Qt::DisplayRole, tr("Totals")); item -> setData(COLUMN_IN_RATE, Qt::DisplayRole, totalRates.mRateIn); item -> setData(COLUMN_IN_MAX, Qt::DisplayRole,totalRates.mRateMaxIn); item -> setData(COLUMN_IN_QUEUE, Qt::DisplayRole, totalRates.mQueueIn); item -> setData(COLUMN_IN_ALLOC, Qt::DisplayRole, std::numeric_limits<float>::max()); item -> setData(COLUMN_IN_ALLOC_SENT, Qt::DisplayRole, std::numeric_limits<qint64>::max()); item -> setData(COLUMN_OUT_RATE, Qt::DisplayRole, totalRates.mRateOut); item -> setData(COLUMN_OUT_MAX, Qt::DisplayRole, totalRates.mRateMaxOut); item -> setData(COLUMN_OUT_QUEUE, Qt::DisplayRole, totalRates.mQueueOut); item -> setData(COLUMN_OUT_ALLOC, Qt::DisplayRole, std::numeric_limits<float>::max()); item -> setData(COLUMN_OUT_ALLOC_SENT, Qt::DisplayRole, std::numeric_limits<qint64>::max()); time_t now = time(NULL); for(it = rateMap.begin(); it != rateMap.end(); ++it) { /* find the entry */ QTreeWidgetItem *peer_item = NULL; #if 0 QString qpeerid = QString::fromStdString(*it); int itemCount = peerTreeWidget->topLevelItemCount(); for (int nIndex = 0; nIndex < itemCount; ++nIndex) { QTreeWidgetItem *tmp_item = peerTreeWidget->topLevelItem(nIndex); if (tmp_item->data(COLUMN_PEERID, Qt::DisplayRole).toString() == qpeerid) { peer_item = tmp_item; break; } } #endif if (!peer_item) { /* insert */ peer_item = new QTreeWidgetItem(); peerTreeWidget->addTopLevelItem(peer_item); } std::string name = rsPeers->getPeerName(it->first); peer_item -> setData(COLUMN_PEERID, Qt::DisplayRole, QString::fromStdString(it->first.toStdString())); peer_item -> setData(COLUMN_RSNAME, Qt::DisplayRole, QString::fromStdString(name)); peer_item -> setData(COLUMN_IN_RATE, Qt::DisplayRole, it->second.mRateIn); peer_item -> setData(COLUMN_IN_MAX, Qt::DisplayRole, it->second.mRateMaxIn); peer_item -> setData(COLUMN_IN_QUEUE, Qt::DisplayRole, it->second.mQueueIn); peer_item -> setData(COLUMN_IN_ALLOC, Qt::DisplayRole, it->second.mAllocIn); peer_item -> setData(COLUMN_IN_ALLOC_SENT, Qt::DisplayRole, qint64(now - it->second.mAllocTs)); peer_item -> setData(COLUMN_OUT_RATE, Qt::DisplayRole, it->second.mRateOut); peer_item -> setData(COLUMN_OUT_MAX, Qt::DisplayRole, it->second.mRateMaxOut); peer_item -> setData(COLUMN_OUT_QUEUE, Qt::DisplayRole, it->second.mQueueOut); if (it->second.mAllowedTs != 0) { peer_item -> setData(COLUMN_OUT_ALLOC, Qt::DisplayRole, it->second.mAllowedOut); peer_item -> setData(COLUMN_OUT_ALLOC_SENT, Qt::DisplayRole,qint64(now - it->second.mAllowedTs)); } else { peer_item -> setData(COLUMN_OUT_ALLOC, Qt::DisplayRole, std::numeric_limits<float>::max()); peer_item -> setData(COLUMN_OUT_ALLOC_SENT, Qt::DisplayRole, std::numeric_limits<qint64>::max()); } /* colour the columns */ if (it->second.mAllowedTs != 0) { if (it->second.mAllowedOut < it->second.mRateOut) { /* RED */ QColor bc("#ff4444"); // red peer_item -> setBackground(COLUMN_OUT_RATE,QBrush(bc)); } else if (it->second.mAllowedOut < it->second.mRateMaxOut) { /* YELLOW */ QColor bc("#ffff66"); // yellow peer_item -> setBackground(COLUMN_OUT_MAX,QBrush(bc)); } else { /* GREEN */ QColor bc("#44ff44");//bright green peer_item -> setBackground(COLUMN_OUT_ALLOC,QBrush(bc)); } } else { /* GRAY */ QColor bc("#444444");// gray peer_item -> setBackground(COLUMN_OUT_ALLOC,QBrush(bc)); peer_item -> setBackground(COLUMN_OUT_ALLOC_SENT,QBrush(bc)); } /* queueOut */ #define QUEUE_RED 10000 #define QUEUE_ORANGE 2000 #define QUEUE_YELLOW 500 if (it->second.mQueueOut > QUEUE_RED) { /* RED */ QColor bc("#ff4444"); // red peer_item -> setBackground(COLUMN_OUT_QUEUE,QBrush(bc)); } else if (it->second.mQueueOut > QUEUE_ORANGE) { /* ORANGE */ QColor bc("#ff9900"); //orange peer_item -> setBackground(COLUMN_OUT_QUEUE,QBrush(bc)); } else if (it->second.mQueueOut > QUEUE_YELLOW) { /* YELLOW */ QColor bc("#ffff66"); // yellow peer_item -> setBackground(COLUMN_OUT_QUEUE,QBrush(bc)); } else { /* GREEN */ QColor bc("#44ff44");//bright green peer_item -> setBackground(COLUMN_OUT_QUEUE,QBrush(bc)); } } }
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, std::vector<panzer::BC>& bcs) { // Physics block Teuchos::ParameterList& physics_block = ipb->sublist("test physics"); { Teuchos::ParameterList& p = physics_block.sublist("a"); p.set("Type","Energy"); p.set("Prefix",""); p.set("Model ID","solid"); p.set("Basis Type","HGrad"); p.set("Basis Order",2); } { Teuchos::ParameterList& p = physics_block.sublist("b"); p.set("Type","Energy"); p.set("Prefix","ION_"); p.set("Model ID","ion solid"); p.set("Basis Type","HGrad"); p.set("Basis Order",1); } { std::size_t bc_id = 0; panzer::BCType neumann = BCT_Dirichlet; std::string sideset_id = "left"; std::string element_block_id = "eblock-0_0"; std::string dof_name = "TEMPERATURE"; std::string strategy = "Constant"; double value = 5.0; Teuchos::ParameterList p; p.set("Value",value); panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, strategy, p); bcs.push_back(bc); } { std::size_t bc_id = 1; panzer::BCType neumann = BCT_Dirichlet; std::string sideset_id = "right"; std::string element_block_id = "eblock-1_0"; std::string dof_name = "TEMPERATURE"; std::string strategy = "Constant"; double value = 5.0; Teuchos::ParameterList p; p.set("Value",value); panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, strategy, p); bcs.push_back(bc); } { std::size_t bc_id = 2; panzer::BCType neumann = BCT_Dirichlet; std::string sideset_id = "top"; std::string element_block_id = "eblock-1_0"; std::string dof_name = "TEMPERATURE"; std::string strategy = "Constant"; double value = 5.0; Teuchos::ParameterList p; p.set("Value",value); panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, strategy, p); bcs.push_back(bc); } }
main() { int x_a[] = {1, 10, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, 4444, }; int x_b =8888; int x_x =8888; int x_c[] = {-4, 3, 4444, 4444, 4444, 4444, }; x_x = 12 ; for( x_b = 1 ; x_b <= 10 ; x_b ++) { x_a[bc(x_a, 6, x_b , 'a')] = 100 + x_b ; } for( x_b = 0 - 2 ; x_b >= 0 - 4 ; x_b --) { x_c[bc(x_c, 10, x_b , 'c')] = 1000 - x_b ; } printf( "%s\n", "element forward x: a" ); { int x_x ; int indexx; for( indexx=0; indexx< x_a [1]; indexx++) { x_x = x_a [indexx+2]; { printf("%d\n", x_x ); } } } printf("%d\n", x_x ); }
double snlCtrlPointNetSurface::calcFlatness ( int indexU, int indexV, int numPointsU, int numPointsV ) { // Calculate flatness of a rectangular section of control points. // -------------------------------------------------------------- // indexU: U index of starting position in control point net. // indexV: V index of starting position in control point net. // numPointsU: Number of points in U direction, including starting point, to test. // numPointsV: Number of points in V direction, including starting point, to test. // // Notes: // // Rectangle data orientation: // // V B--------D // | | // ^ | | // | | | // | A--------C // // -----> U // Locate rectangular array of points to process. int numPoints = numPointsU * numPointsV; snlCtrlPoint** ctrlPointPtrs = new snlCtrlPoint* [ numPoints ]; locatePoints ( indexU, indexV, numPointsU, numPointsV, ctrlPointPtrs ); // Pre-calculate vectors and normals. // 4 Corners. int indexB = numPointsV - 1; int indexC = numPoints - numPointsV; int indexD = numPoints - 1; snlCtrlPoint ptA = *(ctrlPointPtrs [ 0 ]); ptA.normalise(); snlCtrlPoint ptB = *(ctrlPointPtrs [ numPointsV - 1 ]); ptB.normalise(); snlCtrlPoint ptC = *(ctrlPointPtrs [ numPoints - numPointsV ]); ptC.normalise(); snlCtrlPoint ptD = *(ctrlPointPtrs [ numPoints - 1 ]); ptD.normalise(); // Side Vectors. snlVector ab ( ptA, ptB ); ab.unitise(); snlVector ba = ab * -1.0; snlVector ac ( ptA, ptC ); ac.unitise(); snlVector ca = ac * -1.0; snlVector bd ( ptB, ptD ); bd.unitise(); snlVector db = bd * -1.0; snlVector cd ( ptC, ptD ); cd.unitise(); snlVector dc = cd * -1.0; // Diagonal Vectors. snlVector bc ( ptB, ptC ); snlVector ad ( ptA, ptD ); // Normals. snlVector normA ( ac, ab ); snlVector normB ( ba, bd ); snlVector normC ( cd, ca ); snlVector normD ( db, dc ); // Project each point of the rectangle, not on the corners, onto the 4 base triangles. // If the projection does not lay on a triangle, it is not considered in any further flatness // calculations. If a point does not have any projections that lay on one of the four triangles // then the closest distance to one of the 6 vectors defining the 4 triangles is taken // as the flatness. double maxDistance = 0.0; // Maximum distance or "flatness". for ( int index = 0; index < indexD; index ++ ) { if ( ! index || index == indexB || index == indexC ) continue; // Don't process the corners. bool interiorFound = false; // True if at least one triangle contains projection. snlCtrlPoint t = *(ctrlPointPtrs [ index ]); t.normalise(); // Project point to and compare to triangle rooted at A. snlVector toProj ( ptA, t ); snlVector projVect = toProj.project ( normA ); snlPoint projPoint = t - projVect; double projDist = projVect.length(); bool isInterior = isInteriorToTriangle ( projPoint, ptA, ab, ac, ptB, ba, bc ); if ( isInterior ) interiorFound = true; if ( isInterior && maxDistance < projDist ) maxDistance = projDist; // Project point to and compare to triangle rooted at B. toProj.calc ( ptB, t ); projVect = toProj.project ( normB ); projPoint = t - projVect; projDist = projVect.length(); isInterior = isInteriorToTriangle ( projPoint, ptB, ba, bd, ptA, ab, ad ); if ( isInterior ) interiorFound = true; if ( isInterior && maxDistance < projDist ) maxDistance = projDist; // Project point to and compare to triangle rooted at C. toProj.calc ( ptC, t ); projVect = toProj.project ( normC ); projPoint = t - projVect; projDist = projVect.length(); isInterior = isInteriorToTriangle ( projPoint, ptC, ca, cd, ptA, ac, ad ); if ( isInterior ) interiorFound = true; if ( isInterior && maxDistance < projDist ) maxDistance = projDist; // Project point to and compare to triangle rooted at D. toProj.calc ( ptD, t ); projVect = toProj.project ( normD ); projPoint = t - projVect; projDist = projVect.length(); isInterior = isInteriorToTriangle ( projPoint, ptD, db, dc, ptB, bd, bc ); if ( isInterior ) interiorFound = true; if ( isInterior && maxDistance < projDist ) maxDistance = projDist; // If no triangle contains a projection then project to the six triangle outlines and take _smallest_ value if ( ! interiorFound ) { toProj.calc ( ptA, t ); double projMaxDistance = ab.projectDist ( toProj ); // A -> B. double projDist = ac.projectDist ( toProj ); // A -> C. if ( projDist < projMaxDistance ) projMaxDistance = projDist; projDist = ad.projectDist ( toProj ); // A -> D. if ( projDist < projMaxDistance ) projMaxDistance = projDist; toProj.calc ( ptD, t ); projDist = db.projectDist ( toProj ); // D -> B. if ( projDist < projMaxDistance ) projMaxDistance = projDist; projDist = dc.projectDist ( toProj ); // D -> C. if ( projDist < projMaxDistance ) projMaxDistance = projDist; toProj.calc ( ptB, t ); projDist = bc.projectDist ( toProj ); // B -> C. if ( projDist < projMaxDistance ) projMaxDistance = projDist; if ( maxDistance < projMaxDistance ) maxDistance = projMaxDistance; } } return maxDistance; }
void Cone::tesselate( int nTheta, int nHeight, std::vector< Vector4f >& positions, std::vector< Vector3f >& normals ) { positions.clear(); normals.clear(); positions.reserve( 6 * nTheta * nHeight ); normals.reserve( 6 * nTheta * nHeight ); float dt = MathUtils::TWO_PI / nTheta; float dh = height / nHeight; Vector4f bc( baseCenter, 0 ); for( int t = 0; t < nTheta; ++t ) { float t0 = t * dt; float t1 = t0 + dt; for( int h = 0; h < nHeight; ++h ) { float h0 = h * dh; float h1 = h0 + dh; float r0 = baseRadius * ( 1 - h0 / height ); float r1 = baseRadius * ( 1 - h1 / height ); float x00 = r0 * cosf( t0 ); float y00 = r0 * sinf( t0 ); float x10 = r0 * cosf( t1 ); float y10 = r0 * sinf( t1 ); float x01 = r1 * cosf( t0 ); float y01 = r1 * sinf( t0 ); float x11 = r1 * cosf( t1 ); float y11 = r1 * sinf( t1 ); Vector4f v00 = bc + Vector4f( x00, y00, h0, 1 ); Vector3f n00( x00, y00, r0 / sqrtf( r0 * r0 + h0 * h0 ) ); n00.normalize(); Vector4f v10 = bc + Vector4f( x10, y10, h0, 1 ); Vector3f n10( x10, y10, r0 / sqrtf( r0 * r0 + h0 * h0 ) ); n10.normalize(); Vector4f v01 = bc + Vector4f( x01, y01, h1, 1 ); Vector3f n01( x01, y01, r1 / sqrtf( r1 * r1 + h1 * h1 ) ); n01.normalize(); Vector4f v11 = bc + Vector4f( x11, y11, h1, 1 ); Vector3f n11( x11, y11, r1 / sqrtf( r1 * r1 + h1 * h1 ) ); n11.normalize(); positions.push_back( v00 ); normals.push_back( n00 ); positions.push_back( v10 ); normals.push_back( n10 ); positions.push_back( v01 ); normals.push_back( n01 ); positions.push_back( v01 ); normals.push_back( n01 ); positions.push_back( v10 ); normals.push_back( n10 ); positions.push_back( v11 ); normals.push_back( n11 ); } } }
return e1->eval(a, b, c, d) ^ e2->eval(a, b, c, d); } }; Expr* const ba() { return new A(); } Expr* const bb() { return new B(); } Expr* const bc() { return new C(); } Expr* const bd() { return new D(); } Expr* bnot(Expr* const e) { return new Not(e); } Expr* band(Expr* const e1, Expr* const e2) { return new And(e1, e2); } Expr* bor(Expr* const e1, Expr* const e2) { return new Or(e1, e2); } Expr* bxor(Expr* const e1, Expr* const e2) { return new Xor(e1, e2); } Expr* const knownXor4 = band( bor(bxor(ba(), bb()), bxor(bc(), bd())), bxor(bor(ba(), bb()), bor(bc(), bd()))); bool isXor4(Expr* const e) { return !e->eval(true, true, true, true) && !e->eval(false, true, true, true) && !e->eval(true, false, true, true) && !e->eval(false, false, true, true) && !e->eval(true, true, false, true) && !e->eval(false, true, false, true) && !e->eval(true, false, false, true) && e->eval(false, false, false, true) && !e->eval(true, true, true, false) && !e->eval(false, true, true, false) && !e->eval(true, false, true, false) && e->eval(false, false, true, false)
Instruction getInstruction() { return bc()->getInsn(bci_++); }
INT main(INT argc, CHAR *argv[]) { /********** MAIN PROGRAM ********************************* * Solve Laplace equation using Jacobi iteration method * * *********************************************************/ INT m = M_DEFAULT, mp, k, p, below, above; long iter=MAXSTEPS; REAL TOL=EPS_DEFAULT, del, gdel,start,finish,mytime; CHAR line[80]; REAL **v, **vt, **vnew; k = 0; p= 1; if(k == 0) { fprintf(OUTPUT," Number of args in command line, argc :\n"); fprintf(OUTPUT," argc = %d :\n", argc); if (argc >= 2) fprintf(OUTPUT," arg[1]= %s :\n", argv[1]); if (argc >= 3) fprintf(OUTPUT," arg[2]= %s :\n", argv[2]); if (argc >1){ m=atoi(argv[1]); m=MAX_M; } if (argc >2 ) { TOL= atof(argv[2]); TOL=EPS; } fprintf(OUTPUT,"Size of interior points, m :\n"); fprintf(OUTPUT,"m = %d\n",m); fprintf(OUTPUT,"Numerical accuracy, eps :\n"); fprintf(OUTPUT,"eps = %f\n",TOL); fprintf(OUTPUT,"Number of processes, p :\n"); fprintf(OUTPUT,"p = %d\n",p); start=-time(0); } mp = m/p; v = allocate_2D(m, mp); /* allocate mem for 2D array */ vt = allocate_2D(mp, m); vnew = allocate_2D(mp, m); gdel = 1.0; iter = 0; bc(m, mp, v, k, p); /* initialize and define B.C. for v */ transpose(m, mp, v, vt); /* solve for vt */ /* driven by need of update_bc_2 */ replicate(mp, m, vt, vnew); /* vnew = vt */ REAL ro = 1.0 - pow (PI / (2 * (m + 1)), 2); REAL w = 0; while (gdel > TOL) { /* iterate until error below threshold */ iter++; /* increment iteration counter */ if(iter > MAXSTEPS) { fprintf(OUTPUT,"Iteration terminated (exceeds %6d", MAXSTEPS); fprintf(OUTPUT," )\n"); return (0); /* nonconvergent solution */ } /* compute new solution according to the Jacobi scheme */ /*update_jacobi(mp, m, vt, vnew, &del); [> compute new vt <]*/ update_sor(mp, m, vt, vnew, &del, w); update_w(&w, ro); if (del > gdel) gdel = del; if( k == 0) { fprintf(OUTPUT,"iter,del,gdel: %6d, %lf %lf\n",iter,del,gdel); } update_bc_2( mp, m, vt, k, below, above); /* update b.c. */ } if (k == 0) { finish=time(0); mytime=start+finish; fprintf(OUTPUT,"Stopped at iteration %d\n",iter); fprintf(OUTPUT,"The maximum error = %f\n",gdel); fprintf(OUTPUT,"Time = %f\n",mytime); } if (FILE_OUT) { /* write v to file for use in MATLAB plots */ transpose(mp, m, vt, v); write_file( m, mp, v, k, p ); } free(v); free(vt); free(vnew); /* release allocated arrays */ return (0); }
void drawTree(FastVoxelView &vv,Pos3D base,float h) { Pos3D p1(0,0,0),p2(0,0,0),p3(0,0,0); Color c(0x99,0x69,0); Color bc(0,0xAA,0); p1=base; p2=base+Pos3D(0,1,0)*h*0.25; p3=base+Pos3D(0,1,0)*h*0.5; cdebug(p1<<p2<<p3); Trunk t(p1,p2,p3,7,5); std::list<Trunk> tlist,nlist; tlist.push_back(t); int rw=h/4; float angle=M_PI/1.5; // 30 degrees int last=5; for(int i=0;i<=last;i++) { std::cout<<"_______________"<<std::endl; std::list<Trunk>::iterator k=tlist.begin(); for(;k!=tlist.end();k++) { Pos3D dir=k->p3 - k->p2; int count=4; std::list<Pos3D> l=splitDir(dir,count,angle,M_PI/count/8.0,0);//M_PI/count,angle/3); std::list<Pos3D>::iterator j=l.begin(); for(;j!=l.end();j++) { Pos3D r=*j; r=r*rw; int mi=i+1; // c=Color(mi&1,(mi>>1)&1,(mi>>2)&1); /* drawBall(vv,k->p1,4,c); drawBall(vv,k->p2,3,c); drawBall(vv,k->p3,2,c);*/ draw3Line(vv,k->p1,k->p2,k->p3,c,40,k->w1,k->w2); if(i==last) draw3Line(vv,k->p1,k->p2,k->p2,bc,4,2,1); float start=0.6; start+=getRandEq()*0.3; Pos3D sp=bezier(start, k->p1,k->p2,k->p3); // Pos3D np(k->p3*2-k->p2+Pos3D(rx,ry,rz)); Pos3D np(k->p3*2-k->p2+r); Trunk nt(sp, sp*0.5+np*0.5+getRandPos(rw), np, k->w2,k->w2-1); nlist.push_back(nt); } } rw*=0.9; tlist.clear(); cdebug(nlist.size()); tlist=nlist; nlist.clear(); } // roots std::list<Pos3D> l=splitDir(Pos3D(0,-1,0),4,M_PI/4,0,0); std::list<Pos3D>::iterator j=l.begin(); for(;j!=l.end();j++) { Pos3D n=*j * 10 + base; draw3Line(vv,base,base*0.5+n*0.5,n,c,40,t.w1,t.w2); } }