TEST(testTrackToFaceBasic, trackFirstFace) { Mesh *mesh = readMesh("mesh"); vector<Particle> particles = readParticles("particles", mesh); // Find Particle with label 1 Particle *particle; for(int i=0; i<particles.size(); i++) { if(particles[i].getLabel() == 1) { particle = &particles[i]; break; } } vector<pair<float, float> > trajectory(particle->getTrajectory()); float lambda; ASSERT_EQ(1, particle->trackToFaceBasic(0, -1, trajectory[0].first, trajectory[0].second, trajectory[1].first, trajectory[1].second, &lambda) ); ASSERT_TRUE(lambda >= 0); ASSERT_TRUE(lambda <= 1); }
void parse__Variable(Model *model, const std::string &basePath, xml::Node *var) { size_t index = -1; size_t start = -1; size_t end = -1; size_t patch = -1; size_t numParticles = 0; std::string variable; std::string filename; std::string varType = var->getProp("type"); for (int i=0;i<var->child.size();i++) { xml::Node *n = var->child[i]; if (n->name == "index") { index = atoi(n->content.c_str()); } else if (n->name == "variable") { variable = n->content; } else if (n->name == "numParticles") { numParticles = atol(n->content.c_str()); } else if (n->name == "patch") { patch = atol(n->content.c_str()); } else if (n->name == "filename") { filename = n->content; } else if (n->name == "start") { start = atol(n->content.c_str()); } else if (n->name == "end") { end = atol(n->content.c_str()); } } if (numParticles > 0 && variable == "p.x" /* && index == .... */ ) { readParticles(model,numParticles,basePath+"/"+filename,start,end); } else if (numParticles > 0 && varType == "ParticleVariable<double>" ) { readDoubleAttributes(model,variable,numParticles,basePath+"/"+filename,start,end); } else if (numParticles > 0 && varType == "ParticleVariable<float>" ) { readFloatAttributes(model,variable,numParticles,basePath+"/"+filename,start,end); } }
// Particle stays in the same cell TEST(testTrackToFaceBasic, trackSame) { Mesh *mesh = readMesh("mesh"); vector<Particle> particles = readParticles("particles", mesh); Particle *particle; for(int i=0; i<particles.size(); i++) { if(particles[i].getLabel() == 1) { particle = &particles[i]; break; } } vector<pair<float, float> > trajectory(particle->getTrajectory()); float lambda; ASSERT_EQ(-1, particle->trackToFaceBasic(1, -1, 1.5, 3, 2.5, 1.5, &lambda) ); }
TEST(testTrackToFaceBasic, anotherTrackingTest) { Mesh *mesh = readMesh("mesh"); vector<Particle> particles = readParticles("particles", mesh); Particle *particle; for(int i=0; i<particles.size(); i++) { if(particles[i].getLabel() == 1) { particle = &particles[i]; break; } } vector<pair<float, float> > trajectory(particle->getTrajectory()); float lambda; ASSERT_EQ(2, particle->trackToFaceBasic(0, -1, 3.4, 1.79, 3, 3, &lambda)); ASSERT_TRUE(lambda >= 0); ASSERT_TRUE(lambda <= 1); }
TEST(testTrackToFaceBasic, trackCase2) { Mesh *mesh = readMesh("mesh"); vector<Particle> particles = readParticles("particles", mesh); Particle *particle; for(int i=0; i<particles.size(); i++) { if(particles[i].getLabel() == 2) { particle = &particles[i]; break; } } vector<pair<float, float> > trajectory(particle->getTrajectory()); float lambda; int faceHit = particle->trackToFaceBasic (1, 1, 3.23239, 1.11972, 3.4, 1, &lambda); ASSERT_EQ(-1, faceHit); ASSERT_TRUE(lambda >= 0); ASSERT_TRUE(lambda <= 1); }
TEST(TestParticleTracker, testTrackParticle2) { Mesh *mesh = readMesh("mesh"); vector<Particle> particles = readParticles("particles", mesh); Particle *particle; for(int i=0; i<particles.size(); i++) { if(particles[i].getLabel() == 2) { particle = &particles[i]; break; } } vector<pair<float, float> > trajectory(particle->getTrajectory()); particle->trackParticle(); vector<pair<int, float> > cellFraction(particle->getCellFraction()); vector<int> stepCells(particle->getStepCells()); ASSERT_TRUE(stepCells.size() == 3); ASSERT_EQ(6, cellFraction.size()); ASSERT_EQ(2, cellFraction[cellFraction.size()-1].first); }
int main(int argc, char ** argv){ //MPI Initialization MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); clOptions options; if(getCla(argc, argv, &options)){ //NOTHING TO WORRY ABOUT }else{ printf("command line options failure\n"); return 1; } MPI_Status status_ignore; //MPI Particle Initialization //MPI_Datatype MPI_particle; create_MPI_struct(&MPI_particle); MPI_Type_commit(&MPI_particle); //Deprecated and dangerous as superseded by options structure //char * readFName =NULL; //char * writeFName = NULL; //char * defaultFName = "default.dat"; //int writeData = 0; //int compareData = 0; //change to allow command line arguments //Setup if(options.timing >=1){ clock_start(); } char * initTypeTimingTag = "undefined_tag"; int nParticles = options.nParticles; int nEachMax = pieceSize(nParticles, size, 0); double diff; particle * buffers[4]; particle * spare_particle_pointer; buffers[0] = calloc(sizeof(particle), nEachMax); buffers[1] = calloc(sizeof(particle), nEachMax); buffers[2] = calloc(sizeof(particle), nEachMax); buffers[3] = calloc(sizeof(particle), nEachMax); int buf_index[3] = {rank, rank, rank}; int nEach[3]; nEach[0] = pieceSize(nParticles, size, rank); nEach[1] = pieceSize(nParticles, size, rank); nEach[2] = pieceSize(nParticles, size, rank); //diff =compareMultipleParticles(buffers[0], buffers[1], nEachMax); //Read or Randomize and print if(options.readInput == 1){ if(options.verbosity>=2){ printf("reading particles\n"); } initTypeTimingTag = "init_read"; readParticles(options.readFName, buffers[3], nParticles, size, rank); }else if(options.genFunction == 2){ if(options.verbosity>=2){ printf("generating particles\n"); } initTypeTimingTag = "init_gen2"; initialize_2(buffers[3], nEachMax); //fprintParticles(stdout, buffers[3], nEachMax); }else{ //no input printf("error: no initial data specified\n"); MPI_Finalize(); } if(options.verbosity>=2){ printf("should have particles now\n"); } int i; for(i=0;i<nEachMax;i++){ buffers[0][i] = buffers[3][i]; buffers[0][i].dvx = 0; buffers[0][i].dvy = 0; buffers[0][i].dvz = 0; buffers[1][i] = buffers[0][i]; buffers[2][i] = buffers[0][i]; } if(options.verbosity>=3){ printf("rank %d printing particles set 0 \n", rank); fprintParticles(stdout, buffers[0], nEachMax); printf("rank %d printing particles set 1 \n", rank); fprintParticles(stdout, buffers[1], nEachMax); printf("rank %d printing particles set 2 \n", rank); fprintParticles(stdout, buffers[2], nEachMax); printf("rank %d printing particles set 3 \n", rank); fprintParticles(stdout, buffers[3], nEachMax); } //diff =compareMultipleParticles(buffers[0], buffers[3], nEachMax); //printf("rank %d diff = %g \t\t expected different \n", rank, diff); //Loop //Pass //Calculate //Collect if(options.timing == 2){ clock_stop(argv[0], options, initTypeTimingTag); } if(options.timing >=1){ clock_start(); } int j; int passTimes; int passingBuffer = 0; for(passTimes = size; passTimes >0;passTimes -=3){ for(i=0;i<passTimes;i++){ MPI_pass(buffers, passingBuffer, nEachMax, 1, buf_index); nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]); printf("pass:%d:\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]); func(buffers, nEach, buf_index); } if(passTimes ==3){passTimes+=1;} passingBuffer == (passingBuffer+1)%3; } //Passing to rank that should have particle buffer if(options.verbosity>=0){ printf("old:%d\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]); } int dist; passingBuffer =0; dist = (rank *2 - buf_index[passingBuffer])%size; MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index); nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]); passingBuffer =1; dist = (rank *2 - buf_index[passingBuffer])%size; MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index); nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]); passingBuffer =2; dist = (rank *2 - buf_index[passingBuffer])%size; MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index); nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]); if(options.verbosity>=0){ printf("new:%d\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]); } if(options.verbosity>=3){ printf("combining results\n"); } if(options.verbosity>=3){ printf("rank %d printing particles set 0 \n", rank); fprintParticles(stdout, buffers[0], nEachMax); printf("rank %d printing particles set 1 \n", rank); fprintParticles(stdout, buffers[1], nEachMax); printf("rank %d printing particles set 2 \n", rank); fprintParticles(stdout, buffers[2], nEachMax); printf("rank %d printing particles set 3 \n", rank); fprintParticles(stdout, buffers[3], nEachMax); } //Combine results for(i=0;i<nEach[0];i++){ buffers[0][i].dvx += buffers[1][i].dvx+buffers[2][i].dvx; //buffers[0][i].dvx /= 6; buffers[1][i].dvx = buffers[0][i].dvx; buffers[2][i].dvx = buffers[0][i].dvx; buffers[0][i].dvy += buffers[1][i].dvy+buffers[2][i].dvy; //buffers[0][i].dvy /= 6; buffers[1][i].dvy = buffers[0][i].dvy; buffers[2][i].dvy = buffers[0][i].dvy; buffers[0][i].dvz += buffers[1][i].dvz+buffers[2][i].dvz; //buffers[0][i].dvz /= 6; buffers[1][i].dvz = buffers[0][i].dvz; buffers[2][i].dvz = buffers[0][i].dvz; } if(options.timing >= 1){ clock_stop(argv[0], options, "no_duplicates"); } if(rank == 0){ //fprintParticles(stdout, buffers[3], nEachMax); //fprintParticles(stdout, buffers[0], nEachMax); } //Check results //use buffers[3] if(options.compareResults == 1){ if(options.verbosity>=2){ printf("comparing results"); } if(options.timing == 2){ clock_start(); } diff =compareMultipleParticles(buffers[0], buffers[3], nEach[0]); if(options.timing == 2){ clock_stop(argv[0], options, "comparison"); } printf("rank %d diff = %g\n", rank, diff); } if(options.writeOutput == 1){ if(options.timing == 2){ clock_start(); } writeParticles(options.writeFName, buffers[0], nParticles, size, rank); if(options.timing == 2){ clock_stop(argv[0], options, "writing"); } } //freeing and finalization free(buffers[0]); free(buffers[1]); free(buffers[2]); free(buffers[3]); //MPI Finalization MPI_Type_free(&MPI_particle); MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); }
int pp6day3_muonanalysis() { std::string muonFile; //int resultCode(0); // Obtain filename from user std::cout << "Enter filename to analyse: "; muonFile = getString(); // Create EventArrays of muons/antimuons in input file std::string runID("run4.dat"); double muonMass = 0.105658366; // GeV EventArray* p = readParticles(muonFile, "mu-", muonMass, runID); EventArray* q = readParticles(muonFile, "mu+", muonMass, runID); // Create an array of suffcient size to hold the invariant masses // formed between each muon/antimuon pair, plus an array // to hold the flattened indices int combinations = p->size * q->size; double *invMasses = new double[combinations]; int *indices = new int[combinations]; for (size_t i(0); i < q->size; ++i) { for (size_t j(0); j < p->size; ++j) { int flatIndex = i * p->size + j; indices[flatIndex] = flatIndex; invMasses[flatIndex] = calculate_invariant_mass(q->particles[i], p->particles[j]); } } // Sort the invariant masses using an associative sort over the indices associative_sort(invMasses, indices, combinations); //-------------------------------------------------------------------- // - Present results // std::cout << "Results:" << std::endl; std::cout << "========" << std::endl; std::cout << "Analysed File : " << muonFile << std::endl; std::cout << "Number of Muons = " << p->size << std::endl; std::cout << "Number of AntiMuons = " << q->size << std::endl; std::cout << "----------------------------" << std::endl; for (int i(0); i < 10; ++i) { int muonIndex(indices[i] % p->size); int antimuonIndex((indices[i] - muonIndex) / p->size); std::cout << "{InvariantMass : " << invMasses[indices[i]] << ",\n\t" << "{Muon : " << "Event = " << p->ids[muonIndex] << ", " << "(E, P) = (" << (p->particles[muonIndex]).getFourMomentum() << ")}\n\t" << "{AntiMuon : " << "Event = " << q->ids[antimuonIndex] << ", " << "(E, P) = (" << (q->particles[antimuonIndex]).getFourMomentum() << ")}\n" << "}" << std::endl; } destroyEventArray(p); destroyEventArray(q); delete [] invMasses; delete [] indices; return 0; }
void Application::compute(void *) { int fd, numt, skip, ret, i, n; char buf[500]; // read input parameters and data object name Covise::get_browser_param("path", &dataPath); Covise::get_scalar_param("numt", &numt); Covise::get_scalar_param("skip", &skip); Covise::get_choice_param("format", &i); if (i == 1) readDouble = 1; else readDouble = 0; pfactor = 1; Covise::get_scalar_param("pfactor", &pfactor); coDistributedObject **grids; coDistributedObject **DOSveloc; coDistributedObject **DOSpress; coDistributedObject **DOSrho; coDistributedObject **DOSvol; coDistributedObject **DOStemperature; coDistributedObject **DOSamu; coDistributedObject **DOStke; coDistributedObject **DOSeps; coDistributedObject **DOSparticles; coDistributedObject **DOSpveloc; coDistributedObject **DOSptemperature; grids = new coDistributedObject *[numt + 1]; DOSveloc = new coDistributedObject *[numt + 1]; DOSpress = new coDistributedObject *[numt + 1]; DOSrho = new coDistributedObject *[numt + 1]; DOSvol = new coDistributedObject *[numt + 1]; DOStemperature = new coDistributedObject *[numt + 1]; DOSamu = new coDistributedObject *[numt + 1]; DOStke = new coDistributedObject *[numt + 1]; DOSeps = new coDistributedObject *[numt + 1]; DOSparticles = new coDistributedObject *[numt + 1]; DOSpveloc = new coDistributedObject *[numt + 1]; DOSptemperature = new coDistributedObject *[numt + 1]; for (i = 0; i < numt + 1; i++) { grids[i] = NULL; DOSveloc[i] = NULL; DOSpress[i] = NULL; DOSrho[i] = NULL; DOSvol[i] = NULL; DOStemperature[i] = NULL; DOSamu[i] = NULL; DOStke[i] = NULL; DOSeps[i] = NULL; DOSparticles[i] = NULL; DOSpveloc[i] = NULL; DOSptemperature[i] = NULL; } Mesh = Covise::get_object_name("mesh"); Veloc = Covise::get_object_name("velocity"); Press = Covise::get_object_name("pressure"); rho_name = Covise::get_object_name("rho"); vol_name = Covise::get_object_name("vol"); temp_name = Covise::get_object_name("temperature"); amu_name = Covise::get_object_name("amu"); tke_name = Covise::get_object_name("tke"); eps_name = Covise::get_object_name("eps"); p_name = Covise::get_object_name("particles"); pv_name = Covise::get_object_name("pvelocity"); pt_name = Covise::get_object_name("ptemperature"); if ((fd = Covise::open(dataPath, O_RDONLY)) < 0) { strcpy(buf, "ERROR: Can't open file >> "); strcat(buf, dataPath); Covise::sendError(buf); return; } for (n = 0; n < numt; n++) { ret = readHeader(fd); if (ret < 0) { close(fd); break; } sprintf(buf, "%s_%d", Mesh, n); mesh = new coDoUnstructuredGrid(buf, header.numElem, header.numElem * 8, header.numCoords, 1); if (!mesh->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", Veloc, n); DOveloc = new coDoVec3(buf, header.numCoords); if (!DOveloc->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", Press, n); DOpress = new coDoFloat(buf, header.numElem); if (!DOpress->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", rho_name, n); DOrho = new coDoFloat(buf, header.numElem); if (!DOrho->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", vol_name, n); DOvol = new coDoFloat(buf, header.numElem); if (!DOvol->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", temp_name, n); DOtemperature = new coDoFloat(buf, header.numElem); if (!DOtemperature->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", amu_name, n); DOamu = new coDoFloat(buf, header.numElem); if (!DOamu->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", tke_name, n); DOtke = new coDoFloat(buf, header.numElem); if (!DOtke->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", eps_name, n); DOeps = new coDoFloat(buf, header.numElem); if (!DOeps->objectOk()) { Covise::sendError("could not create output object:"); break; } if (header.np > 0) { sprintf(buf, "%s_%d", p_name, n); DOparticles = new coDoPoints(buf, header.np / pfactor); if (!DOeps->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", pv_name, n); DOpveloc = new coDoVec3(buf, header.np / pfactor); if (!DOeps->objectOk()) { Covise::sendError("could not create output object:"); break; } sprintf(buf, "%s_%d", pt_name, n); DOptemperature = new coDoFloat(buf, header.np / pfactor); if (!DOeps->objectOk()) { Covise::sendError("could not create output object:"); break; } } mesh->getAddresses(&el, &vl, &x_coord, &y_coord, &z_coord); mesh->getTypeList(&tl); DOveloc->getAddresses(&u, &v, &w); DOpress->getAddress(&p); DOrho->getAddress(&rho); DOvol->getAddress(&vol); DOtemperature->getAddress(&temp); DOamu->getAddress(&amu); DOtke->getAddress(&tke); DOeps->getAddress(&eps); if (header.np > 0) { DOparticles->getAddresses(&px, &py, &pz); DOpveloc->getAddresses(&pu, &pv, &pw); DOptemperature->getAddress(&ptemp); } if (readData(fd) < 0) { close(fd); break; } skipBlocks(fd, 1); if (readConn(fd) < 0) { close(fd); break; } if (header.iper > 0) skipBlocks(fd, 1); if (header.np > 0) readParticles(fd); grids[n] = mesh; DOSveloc[n] = DOveloc; DOSpress[n] = DOpress; DOSrho[n] = DOrho; DOSvol[n] = DOvol; DOStemperature[n] = DOtemperature; DOSamu[n] = DOamu; DOStke[n] = DOtke; DOSeps[n] = DOeps; if (header.np > 0) { DOSparticles[n] = DOparticles; DOSpveloc[n] = DOpveloc; DOSptemperature[n] = DOptemperature; } if (header.iper > 0) { if (header.np > 0) skipBlocks(fd, skip * 5); else skipBlocks(fd, skip * 4); } else if (header.np > 0) skipBlocks(fd, skip * 4); else skipBlocks(fd, skip * 3); } coDoSet *set = new coDoSet(Mesh, grids); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(Veloc, DOSveloc); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(Press, DOSpress); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(rho_name, DOSrho); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(vol_name, DOSvol); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(temp_name, DOStemperature); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(amu_name, DOSamu); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(tke_name, DOStke); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(eps_name, DOSeps); set->addAttribute("TIMESTEP", "1 1000"); delete set; if (header.np > 0) { set = new coDoSet(p_name, DOSparticles); set->addAttribute("TIMESTEP", "1 1000"); delete set; set = new coDoSet(pv_name, DOSpveloc); delete set; set = new coDoSet(pt_name, DOSptemperature); delete set; } for (i = 0; i < n; i++) { delete grids[i]; delete DOSveloc[i]; delete DOSpress[i]; delete DOSrho[i]; delete DOSvol[i]; delete DOStemperature[i]; delete DOSamu[i]; delete DOStke[i]; delete DOSeps[i]; delete DOSparticles[i]; delete DOSpveloc[i]; delete DOSptemperature[i]; } delete[] grids; delete[] DOSveloc; delete[] DOSpress; delete[] DOSrho; delete[] DOSvol; delete[] DOStemperature; delete[] DOSamu; delete[] DOStke; delete[] DOSeps; delete[] DOSparticles; delete[] DOSpveloc; delete[] DOSptemperature; close(fd); }
TEST(TestParticleTracker, testDotProd) { Mesh *mesh = readMesh("mesh"); vector<Particle> particles = readParticles("particles", mesh); ASSERT_FLOAT_EQ(17, particles[0].dotProd(3, 2, 1, 7)); }