// If there has been significant progress, display it. void PrintStatus(unsigned current_value) { if (current_value >= m_next_threshold) { m_next_threshold += m_percent_interval; PrintPercent(current_value / static_cast<double>(m_max_value) * 100.); } if (current_value + 1 == m_max_value) std::cout << " 100%" << std::endl; }
void TVolumeSource::FindPotentialMinimum(){ cout << "Sampling phase space "; const int N = 100000; int percent = 0; for (int i = 0; i < N; i++){ PrintPercent((double)i/N, percent); double t = fmc->UniformDist(0, fActiveTime); // dice start time int polarisation = fmc->DicePolarisation(fParticleName); // dice polarisation double x, y, z; RandomPointInSourceVolume(x, y, z); // dice point in source volume TParticle *p = TParticleSource::CreateParticle(t, x, y, z, 0, 0, 0, polarisation); // create dummy particle with Ekin = 0 double V = p->Hstart(); // potential at particle position equals its total energy if (V < MinPot) MinPot = V; // remember minimal potential delete p; ParticleCounter--; } cout << " minimal potential = " << MinPot << "eV\n"; }
void TabField3::ReadTabFile(const char *tabfile, std::vector<double> &BxTab, std::vector<double> &ByTab, std::vector<double> &BzTab, std::vector<double> &VTab){ std::ifstream FIN(tabfile, std::ifstream::in); if (!FIN.is_open()){ printf("\nCould not open %s!\n",tabfile); exit(-1); } printf("\nReading %s ",tabfile); std::string line; FIN >> xl >> yl >> zl; getline(FIN,line); getline(FIN,line); getline(FIN,line); getline(FIN,line); getline(FIN,line); if (line.find("BX") != std::string::npos){ BxTab.resize(xl*yl*zl); getline(FIN,line); } if (line.find("BY") != std::string::npos){ ByTab.resize(xl*yl*zl); getline(FIN,line); } if (line.find("BZ") != std::string::npos){ BzTab.resize(xl*yl*zl); getline(FIN,line); } if (line.find("V") != std::string::npos){ // file contains potential? VTab.resize(xl*yl*zl); getline(FIN,line); } if (!FIN || line.substr(0,2) != " 0"){ printf("%s not found or corrupt! Exiting...\n",tabfile); exit(-1); } std::vector<double> xind(xl), yind(yl), zind(zl); int xi = 0, yi = 0, zi = -1, perc = 0; double x, y, z, val; while (FIN.good()){ FIN >> x; FIN >> y; FIN >> z; if (!FIN) break; x *= lengthconv; y *= lengthconv; z *= lengthconv; if (zi >= 0 && z < zind[zi]){ if (yi >= 0 && y < yind[yi]){ xi++; yi = 0; } else yi++; zi = 0; } else zi++; int i3 = INDEX_3D(xi, yi, zi, xl, yl, zl); // status if read is displayed PrintPercent((float)i3/(xl*yl*zl), perc); xind[xi] = x; yind[yi] = y; zind[zi] = z; if (BxTab.size() > 0){ FIN >> val; BxTab[i3] = val*Bconv; } if (ByTab.size() > 0){ FIN >> val; ByTab[i3] = val*Bconv; }