Introduction
The c++ (cpp) ubvector example is extracted from the most popular open source projects, you can refer to the following example for usage.
Programming language: C++ (Cpp)
Class/type: ubvector
Example#1File:
pinside.cppProject:
kwrobert/ResearchCode
int pinside::inside(double x, double y, const ubvector &xa,
const ubvector &ya) {
int N=xa.size(), ix;
point t, *p=new point[N+1];
t.x=x;
t.y=y;
// We have to copy the vectors so we can rearrange them because
// they are const
ubvector xb(N), yb(N);
vector_copy(N,xa,xb);
vector_copy(N,ya,yb);
// Ensure that (yb[0],ya[0]) is the point with the smallest x
// coordinate among all the points with the smallest y coordinate
double xmin=xb[0];
double ymin=yb[0];
ix=0;
for(int i=0;i<N;i++) {
if (yb[i]<ymin) {
ymin=yb[i];
ix=i;
}
}
for(int i=0;i<N;i++) {
if (yb[i]==ymin && xb[i]<xmin) {
xmin=xb[i];
ix=i;
}
}
vector_rotate<ubvector,double>(N,xb,ix);
vector_rotate<ubvector,double>(N,yb,ix);
// Copy to p[]
for(int i=0;i<N;i++) {
p[i+1].x=xb[i];
p[i+1].y=yb[i];
}
int ret=inside(t,p,N);
delete[] p;
return ret;
}
Example#2File:
bamr_class.cppProject:
awsteiner/bamr
int bamr_class::fill(const ubvector &pars, double weight,
std::vector<double> &line, model_data &dat) {
model &m=*this->mod;
size_t n_params=pars.size();
double nbmax2=0.0, emax=0.0, pmax=0.0, nbmax=0.0, mmax=0.0, rmax=0.0;
if (m.has_eos) {
// The central energy density in the maximum mass configuration
emax=dat.mvsr.max("ed");
// The central pressure in the maximum mass configuration
pmax=dat.mvsr.max("pr");
// The maximum mass
mmax=dat.mvsr.get_constant("m_max");
// The radius of the maximum mass star
rmax=dat.mvsr.get_constant("r_max");
if (set->baryon_density) {
// The highest baryon density in the EOS table
nbmax2=dat.eos.max("nb");
// The central baryon density in the maximum mass configuration
nbmax=dat.mvsr.get_constant("nb_max");
}
} else {
// Need to set mmax for no EOS models to figure out how
// high up we should go for the radius grid
mmax=3.0;
}
for(size_t i=0;i<nsd->n_sources;i++) {
line.push_back(dat.wgts[i]);
}
for(size_t i=0;i<nsd->n_sources;i++) {
line.push_back(dat.rad[i]);
}
for(size_t i=0;i<nsd->n_sources;i++) {
line.push_back(dat.mass[i]);
}
if (m.has_eos) {
for(int i=0;i<set->grid_size;i++) {
double eval=m.e_grid[i];
// Make sure the energy density from the grid
// isn't beyond the table limit
double emax2=dat.eos.max("ed");
if (eval<emax2) {
double pres_temp=dat.eos.interp("ed",eval,"pr");
//if (pres_temp<pmax) {
line.push_back(pres_temp);
//} else {
//line.push_back(0.0);
//}
} else {
line.push_back(0.0);
}
}
}
// It is important here that all of these columns which store values
// over a grid are either always positive or always negative,
// because the code reports zero in the fill_line() function for
// values beyond the end of the EOS or the M-R curve.
for(int i=0;i<set->grid_size;i++) {
double mval=m.m_grid[i];
if (mval<mmax) {
line.push_back(dat.mvsr.interp("gm",mval,"r"));
if (m.has_eos) {
line.push_back(dat.mvsr.interp("gm",mval,"pr"));
}
} else {
line.push_back(0.0);
if (m.has_eos) {
line.push_back(0.0);
}
}
}
if (m.has_eos) {
if (set->baryon_density) {
for(int i=0;i<set->grid_size;i++) {
double nbval=m.nb_grid[i];
if (nbval<nbmax2) {
double pres_temp=dat.eos.interp("nb",nbval,"pr");
if (pres_temp<pmax) {
line.push_back(pres_temp);
} else {
line.push_back(0.0);
}
double eval2=dat.eos.interp("nb",nbval,"ed");
double eoa_val2=eval2/nbval-939.0/o2scl_const::hc_mev_fm;
line.push_back(eoa_val2);
} else {
line.push_back(0.0);
line.push_back(0.0);
}
}
}
if (m.has_esym) {
line.push_back(dat.eos.get_constant("S"));
line.push_back(dat.eos.get_constant("L"));
}
line.push_back(rmax);
line.push_back(mmax);
line.push_back(pmax);
line.push_back(emax);
if (set->baryon_density) line.push_back(nbmax);
for(size_t i=0;i<nsd->n_sources;i++) {
double val=dat.mvsr.interp
("gm",pars[n_params-nsd->n_sources+i],"ed");
line.push_back(val);
}
if (set->baryon_density) {
for(size_t i=0;i<nsd->n_sources;i++) {
double val2=dat.mvsr.interp
("gm",pars[n_params-nsd->n_sources+i],"nb");
line.push_back(val2);
}
}
}
if (set->baryon_density) {
line.push_back(dat.mvsr.get_constant("gm_nb1"));
line.push_back(dat.mvsr.get_constant("r_nb1"));
line.push_back(dat.mvsr.get_constant("gm_nb2"));
line.push_back(dat.mvsr.get_constant("r_nb2"));
line.push_back(dat.mvsr.get_constant("gm_nb3"));
line.push_back(dat.mvsr.get_constant("r_nb3"));
line.push_back(dat.mvsr.get_constant("gm_nb4"));
line.push_back(dat.mvsr.get_constant("r_nb4"));
line.push_back(dat.mvsr.get_constant("gm_nb5"));
line.push_back(dat.mvsr.get_constant("r_nb5"));
}
if (set->compute_cthick) {
line.push_back(dat.eos.get_constant("nt"));
line.push_back(dat.eos.get_constant("prt"));
for(int i=0;i<set->grid_size;i++) {
double mval=m.m_grid[i];
if (mval<mmax) {
double rval=dat.mvsr.interp("gm",mval,"r");
line.push_back(rval-dat.mvsr.interp("gm",mval,"r0"));
} else {
line.push_back(0.0);
}
}
}
if (set->addl_quants) {
cout << "1: " << mmax << " " << dat.mvsr.get_constant("m_max") << endl;
exit(-1);
mmax=dat.mvsr.get_constant("m_max");
for(int i=0;i<set->grid_size;i++) {
double mval=m.m_grid[i];
if (mval<mmax) {
// Baryonic mass
double bm=dat.mvsr.interp("gm",mval,"bm");
line.push_back(bm);
// Binding energy
line.push_back(bm-mval);
// Moment of inertia
double rad=dat.mvsr.interp("gm",mval,"r");
// rjw is km^4, so dividing by km/Msun gives Msun*km^2
double I=dat.mvsr.interp("gm",mval,"rjw")/3.0/schwarz_km;
line.push_back(I);
// To compute I_bar, divide by G^2*M^3
double I_bar=I*4.0/schwarz_km/schwarz_km/mval/mval/mval;
line.push_back(I_bar);
/*
// Relation for lambda given I from Kent Yagi based
// on Yagi and Yunes, Science, (2014)
double a0=-210.327;
double a1=481.472;
double a2=-464.271;
double a3=241.564;
double a4=-70.6449;
double a5=10.9775;
double a6=-0.707066;
*/
// Jim's fit from Steiner, Lattimer, and Brown (2016)
double b0=-30.5395;
double b1=38.3931;
double b2=-16.3071;
double b3=3.36972;
double b4=-0.26105;
double li=log(I_bar);
double li2=li*li;
double li3=li*li2;
double li4=li*li3;
double Lambda_bar=exp(b0+b1*li+b2*li2+b3*li3+b4*li4);
line.push_back(Lambda_bar);
} else {
line.push_back(0.0);
line.push_back(0.0);
line.push_back(0.0);
line.push_back(0.0);
line.push_back(0.0);
}
}
}
if (nsd->source_fnames_alt.size()>0) {
for(size_t i=0;i<nsd->n_sources;i++) {
// Compute alternate probability from an insignificant bit
// in the mass
double alt=dat.mass[i]*1.0e8-((double)((int)(dat.mass[i]*1.0e8)));
if (alt<2.0/3.0) {
line.push_back(0.0);
} else {
line.push_back(1.0);
}
}
}
return o2scl::success;
}