frame_builder::frame_builder(const config& cfg,const shared_string& frame_string) : image_(), image_diagonal_(), image_mod_(""), halo_(""), halo_x_(""), halo_y_(""), halo_mod_(""), sound_(""), text_(""), text_color_(0), duration_(1), blend_with_(0), blend_ratio_(""), highlight_ratio_(""), offset_(""), submerge_(""), x_(""), y_(""), drawing_layer_("") { image(image::locator(cfg[frame_string+"image"]),cfg[frame_string+"image_mod"]); image_diagonal(image::locator(cfg[frame_string+"image_diagonal"]),cfg[frame_string+"image_mod"]); sound(cfg[frame_string+"sound"]); std::vector<shared_string> tmp_string_vect=utils::split_shared(cfg[frame_string+"text_color"]); if(tmp_string_vect.size() ==3) { text(cfg[frame_string+"text"], display::rgb(atoi(tmp_string_vect[0].c_str()),atoi(tmp_string_vect[1].c_str()),atoi(tmp_string_vect[2].c_str()))); } else { text(cfg[frame_string+"text"],0); } if(!cfg[frame_string+"duration"].empty()) { duration(atoi(cfg[frame_string+"duration"].c_str())); } else { duration(atoi(cfg[frame_string+"end"].c_str()) - atoi(cfg[frame_string+"begin"].c_str())); } halo(cfg[frame_string+"halo"],cfg[frame_string+"halo_x"],cfg[frame_string+"halo_y"],cfg[frame_string+"halo_mod"]); tmp_string_vect=utils::split_shared(cfg[frame_string+"blend_color"]); if(tmp_string_vect.size() ==3) { blend(cfg[frame_string+"blend_ratio"],display::rgb(atoi(tmp_string_vect[0].c_str()),atoi(tmp_string_vect[1].c_str()),atoi(tmp_string_vect[2].c_str()))); } else { blend(cfg[frame_string+"blend_ratio"],0); } highlight(cfg[frame_string+"alpha"]); offset(cfg[frame_string+"offset"]); submerge(cfg[frame_string+"submerge"]); x(cfg[frame_string+"x"]); y(cfg[frame_string+"y"]); drawing_layer(cfg[frame_string+"layer"]); }
void *Sethalo(void *argument) { int SETHALO, TPNHALO; int operatorID; int streamID1, streamID2; int nrecs, nvars; int tsID, recID, varID, levelID; int gridsize, gridsize2; int vlistID1, vlistID2; int gridID1 = -1, gridID2; int index, ngrids, gridtype; int nmiss; int *vars; int i; int lhalo = 0, rhalo = 0; int ndiffgrids; double missval; double *array1 = NULL, *array2 = NULL; int taxisID1, taxisID2; cdoInitialize(argument); SETHALO = cdoOperatorAdd("sethalo", 0, 0, NULL); TPNHALO = cdoOperatorAdd("tpnhalo", 0, 0, NULL); operatorID = cdoOperatorID(); streamID1 = streamOpenRead(cdoStreamName(0)); vlistID1 = streamInqVlist(streamID1); ngrids = vlistNgrids(vlistID1); ndiffgrids = 0; for ( index = 1; index < ngrids; index++ ) if ( vlistGrid(vlistID1, 0) != vlistGrid(vlistID1, index)) ndiffgrids++; for ( index = 0; index < ngrids; index++ ) { gridID1 = vlistGrid(vlistID1, index); gridtype = gridInqType(gridID1); if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN ) break; if ( gridtype == GRID_CURVILINEAR ) break; if ( gridtype == GRID_GENERIC && gridInqXsize(gridID1) > 0 && gridInqYsize(gridID1) > 0 ) break; } if ( gridInqType(gridID1) == GRID_GAUSSIAN_REDUCED ) cdoAbort("Gaussian reduced grid found. Use option -R to convert it to a regular grid!"); if ( index == ngrids ) cdoAbort("No regular grid found!"); if ( ndiffgrids > 0 ) cdoAbort("Too many different grids!"); if ( operatorID == SETHALO ) { operatorInputArg("left and right halo"); gridID2 = genindexgrid(gridID1, &lhalo, &rhalo); } else { gridID2 = gentpngrid(gridID1); } vlistID2 = vlistDuplicate(vlistID1); taxisID1 = vlistInqTaxis(vlistID1); taxisID2 = taxisDuplicate(taxisID1); vlistDefTaxis(vlistID2, taxisID2); ngrids = vlistNgrids(vlistID1); for ( index = 0; index < ngrids; index++ ) { if ( gridID1 == vlistGrid(vlistID1, index) ) { vlistChangeGridIndex(vlistID2, index, gridID2); break; } } nvars = vlistNvars(vlistID1); vars = (int*) malloc(nvars*sizeof(int)); for ( varID = 0; varID < nvars; varID++ ) { if ( gridID1 == vlistInqVarGrid(vlistID1, varID) ) vars[varID] = TRUE; else vars[varID] = FALSE; } streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype()); streamDefVlist(streamID2, vlistID2); gridsize = gridInqSize(gridID1); array1 = (double*) malloc(gridsize*sizeof(double)); gridsize2 = gridInqSize(gridID2); array2 = (double*) malloc(gridsize2*sizeof(double)); tsID = 0; while ( (nrecs = streamInqTimestep(streamID1, tsID)) ) { taxisCopyTimestep(taxisID2, taxisID1); streamDefTimestep(streamID2, tsID); for ( recID = 0; recID < nrecs; recID++ ) { streamInqRecord(streamID1, &varID, &levelID); if ( vars[varID] ) { streamReadRecord(streamID1, array1, &nmiss); if ( operatorID == SETHALO ) halo(array1, gridID1, array2, lhalo, rhalo); else tpnhalo(array1, gridID1, array2); if ( nmiss ) { nmiss = 0; missval = vlistInqVarMissval(vlistID1, varID); for ( i = 0; i < gridsize2; i++ ) if ( DBL_IS_EQUAL(array2[i], missval) ) nmiss++; } streamDefRecord(streamID2, varID, levelID); streamWriteRecord(streamID2, array2, nmiss); } } tsID++; } streamClose(streamID2); streamClose(streamID1); if ( vars ) free(vars); if ( array2 ) free(array2); if ( array1 ) free(array1); cdoFinish(); return (0); }
main() { /******************************************************************************/ /* BUILDING DISK POSITION DISTRIBUTION */ /******************************************************************************/ std::cout << "Building disk\n"; // printing disk parameters std::cout << " Mdisk = " << Md << "\n"; std::cout << " Ndisk = " << Ndisk << "\n"; std::cout << " Radial Scale Length h = " << h << "\n"; std::cout << " Vertical Scale Length z0 = " << z0 << "\n"; std::cout << " Radial Cutoff = " << diskcut << "\n"; std::cout << " Vertical Cutoff = " << thickcut << "\n"; std::vector<Vector> disk(Ndisk, Vector(3)); // array of disk positions min = 0.0, max = diskcut; // setting max and min radii topbound = findtopbound(surfacedist, min, max); // finding topbound for (int i = 0; i < Ndisk; i++) // for each particle in disk { r = rejectionsample(surfacedist, min, max, topbound); // choose // random radius disk[i][0] = r; // assigning as such disk[i][1] = randomreal(0.0, 2.0*PI); // randomize azimuthal angle } min = -thickcut; // setting min and max max = thickcut; // heights topbound = findtopbound(diskthick, min, max); // finding topbound for (int i = 0; i < Ndisk; i++) // for each disk particle { disk[i][2] = rejectionsample(diskthick, min, max, topbound); // // choosing height randomly bodies[i].mass = Md / ((double)Ndisk); // assigning masses such that // total mass is correct bodies[i].pos = cyltocart(disk[i]); // transforming to cartesian coords bodies[i].id = i; // assigning particle id bodies[i].DM = false; // these are not dark } /******************************************************************************/ /* BUILDING HALO POSITION DISTRIBUTION */ /******************************************************************************/ std::cout << "Building Halo\n"; // printing parameters std::cout << " Mhalo = " << Mh << "\n"; std::cout << " Nhalo = " << Nhalo << "\n"; std::cout << " Scale Length rc = " << rc << "\n"; std::cout << " Scale Length gamma = " << g << "\n"; std::cout << " Cutoff Radius = " << halocut << "\n"; std::vector<Vector> halo(Nhalo, Vector(3)); // array of halo positions min = 0.0, max = halocut; // max and min for distribution topbound = findtopbound(hernquisthalo, min, max); // finding topbound for (int i = 0; i < Nhalo; i++) // for each bulge particle { r = rejectionsample(hernquisthalo, min, max, topbound); // select r from // distribution bodies[Ndisk + i].pos = randomsphere(r); // randomize position // on sphere bodies[Ndisk + i].mass = Mh / ((double)Nhalo); // normalizing mass bodies[Ndisk + i].id = Ndisk + i; // setting appropriate ID bodies[Ndisk + i].DM = true; // these are dark halo[i] = carttosphere(bodies[Ndisk + i].pos); // saving copy in // spherical coords for later } /******************************************************************************/ /* BUILDING BULGE POSITION DISTRIBUTION */ /******************************************************************************/ std::cout << "Building Bulge\n"; std::cout << " Mbulge = " << Mb << "\n"; std::cout << " Nbulge = " << Nbulge << "\n"; std::cout << " Scale Length a = " << a << "\n"; std::cout << " Cutoff Radius = " << bulgecut << "\n"; std::vector<Vector> bulge(Nbulge, Vector(3)); // array of bulge positions min = 0.0; max = bulgecut; // distribution max and min topbound = findtopbound(bulgedist, min, max); // finding topbound for (int i = 0; i < Nbulge; i++) // for each particle { r = rejectionsample(bulgedist, min, max, topbound); // select r from // distribution bodies[Ndisk + Nhalo + i].pos = randomsphere(r); // randomize sphere // position bodies[Ndisk + Nhalo + i].mass = Mb / (double)Nbulge; // setting mass bodies[Ndisk + Nhalo + i].id = Ndisk + Nhalo + i; // setting IDs bulge[i] = carttosphere(bodies[Ndisk + Nhalo + i].pos); // saving copy // in spherical coordinates } /******************************************************************************/ /* Approximating Cumulative Mass Distribution M(r) */ /******************************************************************************/ dr = halocut / ((double) massbins); // setting separation between mass // bins std::cout << "Approximating Cumulative Mass Distribution M(r)\n"; std::cout << " Number of bins = " << massbins << "\n"; std::cout << " dr = " << dr << "\n"; std::vector <Vector> Massatr(massbins, Vector(2)); // Array to hold // radius and value of cumulative // mass distribution for (int i = 0; i < massbins; i++) // for each mass bin { Massatr[i][1] = ((double)(i+1))*dr; // setting radius Massatr[i][0] = 0.0; // clearing total mass for (int j = 0; j < Ndisk; j++) // for each disk mass { r = sqrt(disk[j][0]*disk[j][0] + disk[j][2]*disk[j][2]); // radius // in spherical coordinates if((r < (double)(i+1)*dr)) // if radius less than bin radius { Massatr[i][0] += Md / (double)Ndisk; // add mass } } for (int j = 0; j < Nhalo; j++) // for each halo mass { r = halo[j][0]; // radius if((r < (double)(i+1)*dr)) // if radius less than bin radius { Massatr[i][0] += Mh / (double)Nhalo; // add mass } } for (int j = 0; j < Nbulge; j++) // for each bulge mass { r = bulge[j][0]; // radius if((r < (double)(i+1)*dr)) // if radius less than bin radius { Massatr[i][0] += Mb / (double)Nbulge; // add mass } } } /******************************************************************************/ /* Setting Halo Velocities */ /******************************************************************************/ std::cout << "Setting Halo Velocities\n"; double v; // variable to hold speed double vesc; // variable to hold escape speed std::vector<Vector> halovels(Nhalo, Vector(3)); // Vector to hold halo // velocities for (int i = 0; i < Nhalo; i++) // for each halo mass { r = halo[i][0]; // radius startbin = floor(r/dr); // starting index is floor of r/dr vesc = sqrt(2.0*Massatr[startbin][0]/r); // escape velocity vr2 = 0.0; // clearing radial dispersion for (int j = startbin; j < massbins; j++) // for each mass bin { vr2 += hernquisthalo(Massatr[j][1])*dr*Massatr[j][0]; // add } // contribution vr2 /= (hernquisthalo(r)/(r*r)); // dividing by halo density at r min = 0.0; // distribution min max = 0.95*vesc; // distribution max is 0.95 of // escape velocity topbound = vr2 / 2.71828; // topbound is vr^2 / e v = rejectionsample(halospeeddist, min, max, topbound); // selecting // absolute speed halovels[i] = randomsphere(v); // randomizing cartesian velocities // on a sphere of radius v bodies[Ndisk + i].vel = halovels[i];// assigning velocities as such } /******************************************************************************/ /* Setting Bulge Velocities */ /******************************************************************************/ std::cout << "Setting Bulge Velocities\n"; std::vector<Vector> bulgevels(Nbulge, Vector(3)); // Vector to hold bulge // velocities for (int i = 0; i < Nbulge; i++) // for each particle { r = bulge[i][0]; // radius startbin = floor(r / dr); // starting index vesc = sqrt(2.0*Massatr[startbin][0]/r); // escape velocity vr2 = 0.0; // clearing radial dispersion for (int j = startbin; j < massbins; j++) // for each mass bin { vr2 += bulgedist(Massatr[j][1])*dr*Massatr[j][0]; // add // contribution } vr2 /= bulgedist(r)/(r*r); // dividing by halo density at r min = 0.0; // distribution min max = 0.95*vesc; // max is 0.95 of escape velocity topbound = vr2 / 2.71828; // topbound is vr^2 /e v = rejectionsample(bulgedist, min, max, topbound); // selecting absolute // absolute speed bulgevels[i] = randomsphere(v); // randomizing constrained cartesian // velocities bodies[Ndisk + Nhalo + i].vel = bulgevels[i]; // assining data as such } /******************************************************************************/ /* Setting Disk Velocities */ /******************************************************************************/ std::cout << "Setting Disk Velocities\n"; std::cout << " Q = " << Q << "\n"; std::cout << " Reference radius = " << rref << "\n"; std::vector<Vector> diskvels(Ndisk, Vector(3)); // Vector to hold disk // velocities double vz2; // vertical dispersion double vc; // circular speed double ar; // radial acceleration double k; // epicyclic frequency double sigmaz2; // azimuthal velocity dispersion double sigmaavg; // average dispersion double Omega; // angular frequency double A; // radial dispersion constant int count; // count variable for averaging Vector acc(3); // vector to store acceleration double as = 0.25*h; maketree(bodies, Ntot, root); // making tree // NORMALIZING RADIAL DISPERSION std::cout << " Normalizing Radial Distribution\n"; dr = diskcut / 1000.0; // width of annulus in which // to average dispersion sigmaavg = 0.0; // zeroing average for (int i = 0; i < Ndisk; i++) // for each disk particle { r = disk[i][0]; // radius if (fabs(r - rref) < dr) // if radius in annulus { // calculate epicylclic frequency k = epicyclicfrequency(bodies, Ntot, i, root, eps, theta, 0.05*dr); sigmaavg += 3.36*Sigma(r)/k; // calculate dispersion and add to // average count += 1; // up count } } sigmaavg /= (double)count; // divide total by count sigmaavg *= Q; // adjust by Q A = sigmaavg*sigmaavg / Sigma(rref); // setting norm constant // ASSIGNING VELOCITIES std::cout << " Setting particle velocities\n"; for (int i = 0; i < Ndisk; i++) // for every particle { r = disk[i][0]; // radius vz2 = PI*z0*Sigma(sqrt(r*r + 2.0*as*as)); // vertical dispersion diskvels[i][2] = gaussianrandom(sqrt(vz2)); // randomizing vertical // with this dispersion vr2 = A*Sigma(sqrt(r*r + 2.0*as*as)); // assigning radial dispersion diskvels[i][0] = gaussianrandom(sqrt(vr2)); // randomizing radial // dispersion acc = treeforce(&bodies[i], root, eps, theta); // acceleration ar = (acc[0]*bodies[i].pos[0] + acc[1]*bodies[i].pos[1])/r; // // radial acceleration Omega = sqrt(fabs(ar)/r); // angular frequency k = epicyclicfrequency(bodies, Ntot, i, root, eps, theta, dr); // // epicyclic frequency vc = Omega*r; // circular speed v = sqrt(fabs(vc*vc + vr2*(1.0 - (k*k)/(4.0*Omega*Omega) - 2.0*r/h))); // // azimuthal streaming velocity sigmaz2 = vr2*k*k/(4.0*Omega*Omega);// azimuthal dispersion v += gaussianrandom(sqrt(sigmaz2)); // adding random azimuthal component diskvels[i][1] = v; // assigning azimuthal velocity // transforming to cartesian coords bodies[i].vel[0] = diskvels[i][0]*cos(disk[i][1]) - diskvels[i][1]*sin(disk[i][1]); bodies[i].vel[1] = diskvels[i][0]*sin(disk[i][1]) + diskvels[i][1]*cos(disk[i][1]); bodies[i].vel[2] = diskvels[i][2]; } /******************************************************************************/ /* Reporting Average Disk Speed */ /******************************************************************************/ v = 0.0; for (int i = 0; i < Ndisk; i++) { v += bodies[i].vel.norm(); } v /= (double)Ndisk; std::cout << "Average Disk Particle Speed: " << v << "\n"; std::cout << "Disk Size: " << diskcut << "\n"; std::cout << "Disk Crossing Time: " << diskcut / v << "\n"; writeinitfile(Ntot, Nhalo, bodies, "data/initfile.txt"); }
void SliderThumb::paintEvent(QPaintEvent *event) { QPainter painter(this); // Halo QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(_haloColor); painter.setBrush(brush); painter.setPen(Qt::NoPen); painter.setRenderHint(QPainter::Antialiasing); QPointF disp = Qt::Horizontal == slider->orientation() ? QPointF(SLIDER_MARGIN + slider->thumbOffset(), slider->height()/2) : QPointF(slider->width()/2, SLIDER_MARGIN + slider->thumbOffset()); QRectF halo((slider->pos() - QPointF(_haloSize, _haloSize)/2) + disp, QSizeF(_haloSize, _haloSize)); painter.drawEllipse(halo); // Knob brush.setColor(slider->value() > slider->minimum() ? (slider->isEnabled() ? _fillColor : Style::instance().themeColor("disabled")) : _minFillColor); painter.setBrush(brush); if (_borderWidth > 0) { QPen pen; pen.setColor(Style::instance().themeColor("accent3")); pen.setWidthF(_borderWidth); painter.setPen(pen); } else { painter.setPen(Qt::NoPen); } QRectF geometry = Qt::Horizontal == slider->orientation() ? QRectF(slider->thumbOffset(), slider->height()/2 - SLIDER_MARGIN, SLIDER_MARGIN*2, SLIDER_MARGIN*2).translated(slider->pos()) : QRectF(slider->width()/2 - SLIDER_MARGIN, slider->thumbOffset(), SLIDER_MARGIN*2, SLIDER_MARGIN*2).translated(slider->pos()); QRectF thumb(0, 0, _diameter, _diameter); thumb.moveCenter(geometry.center()); painter.drawEllipse(thumb); #ifdef DEBUG_LAYOUT QPen pen; pen.setColor(Qt::red); pen.setWidth(2); painter.setPen(pen); painter.setBrush(Qt::NoBrush); painter.drawRect(geometry); painter.drawRect(rect().adjusted(0, 0, -2, -2)); #endif QWidget::paintEvent(event); }