void ExcitedStates::updateMoPlot(int const index) { clearTransitionLines(); QList<Data::Amplitude> amplitudes(m_excitedStates.data().amplitudes(index)); qDebug() << "Number of amplitudes" << amplitudes.size(); QPen pen; QColor color; pen.setStyle(Qt::SolidLine); pen.setWidth(3); double dx(-0.2); QList<Data::Amplitude>::const_iterator iter; for (iter = amplitudes.begin(); iter != amplitudes.end(); ++iter) { color.setHsv(280, 255*std::abs((*iter).m_amplitude), 255); pen.setColor(color); QCPItemLine* line(new QCPItemLine(m_moPlot)); line->setSelectable(true); m_transitionLines.append(line); double x( ((*iter).m_spin == Data::Alpha) ? 0.75 : 2.5 ); line->position("start")->setCoords(x+dx, (*iter).m_ei); line->position("end")->setCoords(x+dx, (*iter).m_ea); dx += 0.1; line->setPen(pen); line->setSelectedPen(m_selectedPen); line->setHead(QCPLineEnding::esSpikeArrow); } m_moPlot->replot(); }
VCRDecoder() { FileStream inputStream = File("U:\\c2.raw", true).openRead(); //FileStream inputStream = File("U:\\captured.bin", true).openRead(); int nn = inputStream.size(); FileStream h = File("U:\\vcr_decoded.bin", true).openWrite(); int samplesPerFrame = 1824*253; Array<Byte> input(samplesPerFrame); _fftData.allocate(2048); _chromaData.allocate(2048); _burstData.allocate(91); _forward = fftwf_plan_dft_1d(2048, reinterpret_cast<fftwf_complex*>(&_fftData[0]), reinterpret_cast<fftwf_complex*>(&_fftData[0]), -1, FFTW_MEASURE); _backward = fftwf_plan_dft_1d(2048, reinterpret_cast<fftwf_complex*>(&_fftData[0]), reinterpret_cast<fftwf_complex*>(&_fftData[0]), 1, FFTW_MEASURE); _chromaForward = fftwf_plan_dft_1d(2048, reinterpret_cast<fftwf_complex*>(&_chromaData[0]), reinterpret_cast<fftwf_complex*>(&_chromaData[0]), -1, FFTW_MEASURE); _chromaBackward = fftwf_plan_dft_1d(2048, reinterpret_cast<fftwf_complex*>(&_chromaData[0]), reinterpret_cast<fftwf_complex*>(&_chromaData[0]), 1, FFTW_MEASURE); Complex<float> localOscillatorFrequency = unit(4.4f*11/315); Complex<float> chromaOscillatorFrequency = unit(2.0f/91); // 0.629 == 315/11 / 2 / 4 * 16 / 91 0.629f*11/315 == 16/8/91 //static const float cutoff = 3.0f*2048*11/315; // 3.3f //static const int cutoff = 208; static const int cutoff = static_cast<int>(2.2f*2048*11/315); static const int chromaCutoff = static_cast<int>(2048.0*2.0/91)*0.75; // *0.5; _outputb0.allocate(2048); _outputb1.allocate(2048); Array<Complex<float>> amplitudes(253); for (int y = 0; y < 253; ++y) amplitudes[y] = 0; Array<Vector3<float>> frameCache(3*2048*253); for (int i = 0; i < 3*2048*253; ++i) frameCache[i] = Vector3<float>(0, 0, 0); int frame = 0; Complex<float> burstAcc = 0; Complex<float> framePhase = unit((90 - 33)/360.0f); }
int main(int argc, char *argv[]) { try { StandardException exc; if(argc < 3) { std::string exceptionString = "Need to specify the spline type (linear or cubic) and the number of (internal) knots."; exc.set(exceptionString); throw exc; } bool isLinear = true; if(argv[1][0] == 'c') isLinear = false; const int nKnots = std::atoi(argv[2]); if(nKnots < 0 || nKnots > 100) { std::stringstream exceptionStr; exceptionStr << "The number of knots " << nKnots << " is invalid. Needs to be positive and not larger than 100."; exc.set(exceptionStr.str()); throw exc; } bool varyNEff = false; bool varySumMNu = false; for(int i = 3; i < argc; ++i) { if(std::string(argv[i]) == "neff") varyNEff = true; if(std::string(argv[i]) == "sum_mnu") varySumMNu = true; } int nPar = 4 + 2 * (nKnots + 2) - 2; if(varyNEff) { ++nPar; output_screen("Varying N_eff!" << std::endl); } else { output_screen("N_eff not being varied. To vary it give \"neff\" as an extra argument." << std::endl); } if(varySumMNu) { ++nPar; output_screen("Varying sum_mnu!" << std::endl); } else { output_screen("sum_mnu not being varied. To vary it give \"sum_mnu\" as an extra argument." << std::endl); } // for A_planck ++nPar; const double kMin = 0.8e-6; const double kMax = 1.2; const double aMin = -2; const double aMax = 4; std::vector<double> kVals(nKnots + 2); std::vector<double> amplitudes(nKnots + 2, 2e-9); kVals[0] = kMin; kVals.back() = kMax; const double deltaLogK = (std::log(kMax) - std::log(kMin)) / (nKnots + 1); for(int i = 1; i < kVals.size() - 1; ++i) kVals[i] = std::exp(std::log(kMin) + i * deltaLogK); SplineWithDegenerateNeutrinosParams params(isLinear, 0.022, 0.12, 0.7, 0.1, kVals, amplitudes, 3.046, 0, 0, varyNEff, varySumMNu); #ifdef COSMO_PLANCK_15 PlanckLikelihood planckLike(true, true, true, false, true, false, false, false, 100); #else ERROR NOT IMPLEMENTED; #endif planckLike.setModelCosmoParams(¶ms); std::stringstream root; root << "knotted_"; if(isLinear) root << "linear_"; else root << "cubic_"; root << nKnots; if(varyNEff) root << "_neff"; if(varySumMNu) root << "_summnu"; PolyChord pc(nPar, planckLike, 300, root.str(), 3 * (4 + (varyNEff ? 1 : 0) + (varySumMNu ? 1 : 0))); int paramIndex = 0; pc.setParam(paramIndex++, "ombh2", 0.02, 0.025, 1); pc.setParam(paramIndex++, "omch2", 0.1, 0.2, 1); pc.setParam(paramIndex++, "h", 0.55, 0.85, 1); pc.setParam(paramIndex++, "tau", 0.02, 0.20, 1); if(varyNEff) pc.setParam(paramIndex++, "n_eff", 2.0, 5.0, 1); if(varySumMNu) pc.setParam(paramIndex++, "sum_mnu", 0.001, 3.0, 1); for(int i = 1; i < kVals.size() - 1; ++i) { std::stringstream paramName; paramName << "k_" << i; pc.setParamSortedUniform(paramIndex++, paramName.str(), std::log(kMin), std::log(kMax), 0, 2); } for(int i = 0; i < amplitudes.size(); ++i) { std::stringstream paramName; paramName << "a_" << i; pc.setParam(paramIndex++, paramName.str(), aMin, aMax, 2); } #ifdef COSMO_PLANCK_15 pc.setParamGauss(paramIndex++, "A_planck", 1, 0.0025, 3); #else ERROR NOT IMPLEMENTED; #endif check(paramIndex == nPar, ""); const std::vector<double> fracs{0.7, 0.25, 0.05}; pc.setParameterHierarchy(fracs); pc.run(true); } catch (std::exception& e) { output_screen("EXCEPTION CAUGHT!!! " << std::endl << e.what() << std::endl); output_screen("Terminating!" << std::endl); return 1; } return 0; }
int main(int argc, char *argv[]) { std::string file_name = argv[1]; bool isLinear = true; if(argv[2][0] == 'c') isLinear = false; const int nKnots = std::atoi(argv[3]); bool varyNEff = false; bool varySumMNu = false; for(int i = 4; i < argc; ++i) { if(std::string(argv[i]) == "neff") varyNEff = true; if(std::string(argv[i]) == "sum_mnu") varySumMNu = true; } int nPar = 4 + 2 * (nKnots + 2) - 2; if(varyNEff) ++nPar; if(varySumMNu) ++nPar; // Starting values for cosmological parameters // From Planck 2015 (http://arxiv.org/abs/1502.01589), Table 3, Column 4 const double h = 0.6727; const double omBH2 = 0.02225; const double omCH2 = 0.1198; const double tau = 0.079; const double ns = 0.9645; const double as = 3.094; // ln(10^10*as) const double pivot = 0.05; const double kMin = 0.8e-6; const double kMax = 1.2; const double aMin = -2; const double aMax = 4; std::vector<double> kVals(nKnots + 2); std::vector<double> amplitudes(nKnots + 2); kVals[0] = kMin; kVals.back() = kMax; const double deltaLogK = (std::log(kMax) - std::log(kMin)) / (nKnots + 1); for(int i = 1; i < kVals.size() - 1; ++i) kVals[i] = std::exp(std::log(kMin) + i * deltaLogK); for(int i = 0; i < amplitudes.size(); ++i) amplitudes[i] = (std::exp(as)/1e10) * pow(kVals[i]/pivot, ns - 1.0); int nMassive = (varySumMNu ? 1 : 0); double nEff = 3.046; double sumMNu = 0.0; SplineWithDegenerateNeutrinosParams params(isLinear, omBH2, omCH2, h, tau, kVals, amplitudes, nEff, nMassive, sumMNu, varyNEff, varySumMNu); Cosmo cosmo; cosmo.preInitialize(3500, false, true, false); std::ifstream datafile(file_name); std::ofstream outfile(file_name.substr(0, file_name.size()-4) + "sigma8.txt"); std::string line; while(getline(datafile, line)) { std::istringstream iss(line); std::vector<double> vec; double dummy; while(iss >> dummy) vec.push_back(dummy); std::vector<double> v(&vec[2], &vec[vec.size()-1]); params.setAllParameters(v); cosmo.initialize(params, true, true, true, true, 1.0); for(int i = 0; i < vec.size(); ++i) outfile << vec[i] << ' '; outfile << cosmo.sigma8() << std::endl; } outfile.close(); datafile.close(); return 0; }
int main(int argc, char* argv[]) { int nang, N; float dx, dz; int nx, nz; float ox, oz; int gnx, gnz; float gdx, gdz, gox, goz; struct point length; int inter; float TETAMAX, alpha2; FILE *outfile; int ii; int rays, wfront, gap; int lomx, first; int nr, nrmax, nt; int prcube, pr, ste; int ns, nou; float DSmax, dt, T, freq; float *vel; float ds, os, goox; float xmin, xmax, zmin, zmax; float depth; struct point *pos; struct heptagon *cube; struct grid *out; sf_file inp, ampl, time; sf_init(argc,argv); inp = sf_input("in"); /* GET MODEL PARAMETERS */ if (!sf_histint(inp,"n1",&nz)) sf_error("No n1= in input"); if (!sf_histint(inp,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(inp,"d1",&dz)) sf_error("No d1= in input"); if (!sf_histfloat(inp,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(inp,"o1",&oz)) sf_error("No o1= in input"); if (!sf_histfloat(inp,"o2",&ox)) sf_error("No o2= in input"); /* GET TRACING PARAMETERS */ if(!sf_getint("nang",&nang)) nang = 10; /* Number of take-off angles */ if(!sf_getint("rays",&rays)) rays = 0; /* If draw rays */ if(!sf_getint("wfront",&wfront)) wfront = 0; /* If draw wavefronts */ if(!sf_getint("gap",&gap)) gap = 1; /* Draw wavefronts every gap intervals */ if(!sf_getint("inter",&inter)) inter = 1; /* If use linear interpolation */ if(!sf_getfloat("DSmax",&DSmax)) DSmax = 5; /* Maximum distance between contiguos points of a wavefront */ if(!sf_getfloat("dt",&dt)) dt = 0.0005; /* time step */ if(!sf_getint("nt",&nt)) nt = 5; /* Number of time steps between wavefronts */ if(!sf_getint("nrmax",&nrmax)) nrmax = 2000; /* Maximum number of points that define a wavefront */ if(!sf_getint("lomx",&lomx)) lomx = 1; /* Use Lomax's waveray method */ if(!sf_getint("first",&first)) first = 1; /* Obtain first arrivals only */ if(!sf_getint("nou",&nou)) nou = 6; /* GET GRIDDING PARAMETERS */ if(!sf_getint("gnx",&gnx)) gnx = nx; /* Coordinates of output grid */ if(!sf_getint("gnz",&gnz)) gnz = nz; if(!sf_getfloat("gdx",&gdx)) gdx = dx; if(!sf_getfloat("gdz",&gdz)) gdz = dz; if(!sf_getfloat("gox",&goox)) goox = ox; if(!sf_getfloat("goz",&goz)) goz = oz; /* GET LOMAX SPECIFIC PARAMETERS */ if(!sf_getint("N",&N)) N = 3; /* Number of control points */ if(!sf_getfloat("TETAMAX",&TETAMAX)) TETAMAX = 1.5; /* Truncation parameter */ if(!sf_getfloat("alpha2",&alpha2)) alpha2 = 4.0; /* Width of gaussian weighting function */ if(!sf_getfloat("freq",&freq)) freq = 100.; /* Pseudo-frequency of waverays */ /* GET DEBUGGING INFO */ if(!sf_getint("prcube",&prcube)) prcube=0; /* For debugging porpouses */ if(!sf_getint("pr",&pr)) pr=0; /* For debugging porpouses */ /* GET SOURCE LOCATIONS */ if(!sf_getint("ns",&ns) || ns==0) ns=1; /* Number of source locations */ if(!sf_getfloat("ds",&ds)) ds=1.; /* interval between sources */ if(!sf_getfloat("os",&os)) os=0.; /* first source location */ if(!sf_getfloat("depth",&depth)) depth=dz; /* Depth location of sources */ pos = (struct point *) sf_alloc (ns,sizeof(struct point)); for(ii=0;ii<ns;ii++) { pos[ii] = makepoint(ii*ds + os, depth); } /* PREPARE OUTPUT */ ampl = sf_output("ampl"); sf_putint(ampl,"n1",gnz); sf_putint(ampl,"n2",gnx); sf_putint(ampl,"n3",ns); sf_putfloat(ampl,"d1",gdz); sf_putfloat(ampl,"d2",gdx); sf_putfloat(ampl,"d3",ds); sf_putfloat(ampl,"o1",goz); sf_putfloat(ampl,"o2",goox); sf_putfloat(ampl,"o3",os); time = sf_output("time"); sf_putint(time,"n1",gnz); sf_putint(time,"n2",gnx); sf_putint(time,"n3",ns); sf_putfloat(time,"d1",gdz); sf_putfloat(time,"d2",gdx); sf_putfloat(time,"d3",ds); sf_putfloat(time,"o1",goz); sf_putfloat(time,"o2",goox); sf_putfloat(time,"o3",os); /* READ VELOCITY MODEL */ vel = sf_floatalloc(nx*nz+2); sf_floatread(vel,nx*nz,inp); /* ALLOCATE MEMORY FOR OUTPUT */ out = (struct grid *) sf_alloc (1,sizeof(struct grid)); out->time = sf_floatalloc (gnx*gnz); out->ampl = sf_floatalloc (gnx*gnz); out->flag = sf_intalloc (gnx*gnz); T = 1. / freq; length = makepoint((nx-1)*dx,(nz-1)*dz); cube = (struct heptagon *) sf_alloc (nrmax,sizeof(struct heptagon)); /* FOR DEBUGGING PORPOUSES, PRINT TO FILE */ if(pr||prcube) { outfile = fopen("junk","w"); } else { outfile = NULL; } /* SET DISPLAY IN ORDER TO SHOW RAYS ON SCREEN */ /* NOTE: THIS PROGRAM USES DIRECT CALLS TO LIB_VPLOT * TO DRAW THE RAYS AND THE WAVEFRONTS */ if(rays || wfront) { setgraphics(ox, oz, length.x, length.z); /* vp_color(BLUE); for(ii=0;ii<gnx;ii++) { vp_umove(ii*gdx+gox, goz); vp_udraw(ii*gdx+gox, (gnz-1)*gdz+goz); } for(ii=0;ii<gnz;ii++) { vp_umove(gox, ii*gdz+goz); vp_udraw((gnx-1)*gdx+gox, ii*gdz+goz); } */ } norsar_init(gnx,gnz, TETAMAX,N,alpha2,inter, nx,nz,ox,oz,dx,dz,length); /* ALGORITHM: * For every source: */ for(ii=0;ii<ns;ii++) { ste = 0; gox = goox + pos[ii].x; sf_warning("\nSource #%d\n", ii); /* 1.- Construct the inital wavefront */ nr = nang; initial (pos[ii], cube, vel, dt, nt, T, lomx, nr, out); gridding_init(gnx,gnz, gdx,gdz,gox,goz, outfile); /* run while the wavefront is not too small */ while (nr > 4) { ste++; /* 2.- Propagate wavefront */ wavefront (cube, nr, vel, dt, nt, T, lomx); if(prcube || pr) { fprintf(outfile,"\n\nwavefront"); printcube(cube, nr, outfile); } /* 3.- Get rid of caustics */ if(first) { if(ste%2==1) { caustics_up (cube, 0, nr); } else { caustics_down (cube, nr-1, nr); } if(prcube || pr) { fprintf(outfile,"\n\ncaustics"); printcube(cube, nr, outfile); } } /* 4.- Eliminate rays that cross boundaries, defined by xmin, xmax, zmin, zmax. Note that the computational grid is a little bigger than the ouput grid. */ xmin = gox-nou*gdx; xmax = 2*pos[ii].x-gox+nou*gdx; zmin = oz-nou*gdz; zmax = length.z+oz+nou*gdz; mark_pts_outofbounds (cube, nr, xmin, xmax, zmin, zmax); if(prcube) { fprintf(outfile, "\n\nboundaries"); printcube(cube, nr, outfile); } /* 5.- Rearrange cube */ makeup(cube, &nr); if(nr<4) break; if(prcube || pr) { fprintf(outfile, "\n\nmakeup"); printcube(cube, nr, outfile); } /* 6.- Calculate amplitudes for new wavefront */ amplitudes (cube, nr); if(prcube) { fprintf(outfile, "\n\namplitudes"); printcube(cube, nr, outfile); } /* 7.- Draw rays */ if(rays) draw_rays (cube, nr); /* 8.- Draw wavefront */ if(wfront && (ste%gap==0)) draw_wavefronts (cube, nr, DSmax); /* 9.- Parameter estimation at receivers */ gridding (cube, nr, out, DSmax, (ste-1)*nt*dt, vel, first); /* pos[ii]); */ /* 10.- Interpolate new points of wavefront */ interpolation (cube, &nr, nrmax, DSmax); /* 0); */ if(prcube) { fprintf(outfile,"\n\ninterpolation"); printcube(cube, nr, outfile); } /* 11.- Prepare to trace new wavefront */ movwavf (cube, nr); if(prcube) { fprintf(outfile,"\n\nmovwavf"); printcube(cube, nr, outfile); } if((wfront || rays) && (ste%gap==0)) vp_erase(); } /* Finally interpolate amplitude and traveltime values to receivers that has not being covered. */ TwoD_interp (out, gnx, gnz); sf_floatwrite(out->time, gnx * gnz, time); sf_floatwrite(out->ampl, gnx * gnz, ampl); } if(pr||prcube) fclose(outfile); exit(0); }