本文整理汇总了C++中density函数的典型用法代码示例。如果您正苦于以下问题:C++ density函数的具体用法?C++ density怎么用?C++ density使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了density函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
FILE *planets,*results;
int i;
struct planet ss[9];
if((planets=fopen("planets.txt","r"))==NULL)
{
printf("Error loading planets.txt\n");
printf("Please press enter to continue");
getchar();
return(0);
}
if((results=fopen("results.txt","w"))==NULL)
{
printf("Error loading results.txt\n");
printf("Please press enter to continue");
getchar();
return(0);
}
for(i=0;i<9;i++)
{
fscanf(planets,"%s %lf %lf %lf",&ss[i].name,&ss[i].distance,&ss[i].mass,&ss[i].radius);
}
printf("Name Distance Mass Radius\n");
for(i=0;i<9;i++)
{
printf("%10s %g %g %g\n",ss[i].name,ss[i].distance,ss[i].mass,ss[i].radius);
}
for(i=0;i<9;i++)
{
fprintf(results,"%s %g %g\n",ss[i].name,ylength(&ss[i]),density(&ss[i]));
}
printf("Please press enter to continue");
getchar();
return(0);
}
示例2: density
doublereal WaterPropsIAPWS::psat(doublereal temperature, int waterState) {
doublereal densLiq = -1.0, densGas = -1.0, delGRT = 0.0;
doublereal dp, pcorr;
if (temperature >= T_c) {
densGas = density(temperature, P_c, WATER_SUPERCRIT);
setState_TR(temperature, densGas);
return P_c;
}
doublereal p = psat_est(temperature);
bool conv = false;
for (int i = 0; i < 30; i++) {
if (method == 1) {
corr(temperature, p, densLiq, densGas, delGRT);
doublereal delV = M_water * (1.0/densLiq - 1.0/densGas);
dp = - delGRT * Rgas * temperature / delV;
} else {
corr1(temperature, p, densLiq, densGas, pcorr);
dp = pcorr - p;
}
p += dp;
if ((method == 1) && delGRT < 1.0E-8) {
conv = true;
break;
} else {
if (fabs(dp/p) < 1.0E-9) {
conv = true;
break;
}
}
}
// Put the fluid in the desired end condition
if (waterState == WATER_LIQUID) {
setState_TR(temperature, densLiq);
} else if (waterState == WATER_GAS) {
setState_TR(temperature, densGas);
} else {
throw Cantera::CanteraError("WaterPropsIAPWS::psat",
"unknown water state input: " + Cantera::int2str(waterState));
}
return p;
}
示例3: inverseOpticalDepth
bool AtmosphericMedium::sampleDistance(PathSampleGenerator &sampler, const Ray &ray,
MediumState &state, MediumSample &sample) const
{
if (state.bounce > _maxBounce)
return false;
Vec3f p = (ray.pos() - _center);
float t0 = p.dot(ray.dir());
float h = (p - t0*ray.dir()).length();
float maxT = ray.farT() + t0;
if (_absorptionOnly) {
sample.t = ray.farT();
sample.weight = std::exp(-_sigmaT*densityIntegral(h, t0, maxT));
sample.pdf = 1.0f;
sample.exited = true;
} else {
int component = sampler.nextDiscrete(3);
float sigmaTc = _sigmaT[component];
float xi = 1.0f - sampler.next1D();
float t = inverseOpticalDepth(h, t0, sigmaTc, xi);
sample.t = min(t, maxT);
sample.weight = std::exp(-_sigmaT*densityIntegral(h, t0, sample.t));
sample.exited = (t >= maxT);
if (sample.exited) {
sample.pdf = sample.weight.avg();
} else {
float rho = density(h, sample.t);
sample.pdf = (rho*_sigmaT*sample.weight).avg();
sample.weight *= rho*_sigmaS;
}
sample.weight /= sample.pdf;
sample.t -= t0;
state.advance();
}
sample.p = ray.pos() + sample.t*ray.dir();
sample.phase = _phaseFunction.get();
return true;
}
示例4: l1Distance
double l1Distance(const Kernel &rhs, long nr = 1000)
{
double a,b,x;
a = min_ - 4.0*width_;
b = rhs.min_ - 4.0*rhs.width_;
double dm = (a < b ? a : b);
a = max_ + 4.0*width_;
b = rhs.max_ + 4.0*rhs.width_;
double dM = (a > b ? a : b);
double dD=(dM-dm)/(nr-1);
const function::Linear<double> lt(0, dm, nr-1, dM);
dM = 0.0;
for (long i=0; i<nr; ++i)
{
x = lt(i);
dM += fabs(density(x)-rhs.density(x))*dD;
}
return dM;
}
示例5: temperature
int MixtureFugacityTP::phaseState(bool checkState) const
{
int state = iState_;
if (checkState) {
double t = temperature();
double tcrit = critTemperature();
double rhocrit = critDensity();
if (t >= tcrit) {
return FLUID_SUPERCRIT;
}
double tmid = tcrit - 100.;
if (tmid < 0.0) {
tmid = tcrit / 2.0;
}
double pp = psatEst(tmid);
double mmw = meanMolecularWeight();
double molVolLiqTmid = liquidVolEst(tmid, pp);
double molVolGasTmid = GasConstant * tmid / (pp);
double densLiqTmid = mmw / molVolLiqTmid;
double densGasTmid = mmw / molVolGasTmid;
double densMidTmid = 0.5 * (densLiqTmid + densGasTmid);
doublereal rhoMid = rhocrit + (t - tcrit) * (rhocrit - densMidTmid) / (tcrit - tmid);
double rho = density();
int iStateGuess = FLUID_LIQUID_0;
if (rho < rhoMid) {
iStateGuess = FLUID_GAS;
}
double molarVol = mmw / rho;
double presCalc;
double dpdv = dpdVCalc(t, molarVol, presCalc);
if (dpdv < 0.0) {
state = iStateGuess;
} else {
state = FLUID_UNSTABLE;
}
}
return state;
}
示例6: evaluateFields
void XZHydrostatic_Omega<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
#ifndef ALBANY_KOKKOS_UNDER_DEVELOPMENT
for (int cell=0; cell < workset.numCells; ++cell) {
for (int qp=0; qp < numQPs; ++qp) {
for (int level=0; level < numLevels; ++level) {
ScalarT sum = -0.5*divpivelx(cell,qp,level) * E.delta(level);
for (int j=0; j<level; ++j) sum -= divpivelx(cell,qp,j) * E.delta(j);
for (int dim=0; dim < numDims; ++dim) sum += Velocity(cell,qp,level,dim)*gradp(cell,qp,level,dim);
omega(cell,qp,level) = sum/(Cpstar(cell,qp,level)*density(cell,qp,level));
}
}
}
#else
Kokkos::parallel_for(XZHydrostatic_Omega_Policy(0,workset.numCells),*this);
cudaCheckError();
#endif
}
示例7: result
result_type result(Args const &args) const
{
if (this->is_dirty)
{
this->is_dirty = false;
std::size_t cnt = count(args);
range_type histogram = density(args);
typename range_type::iterator it = histogram.begin();
while (this->sum < 0.5 * cnt)
{
this->sum += it->second * cnt;
++it;
}
--it;
float_type over = numeric::average(this->sum - 0.5 * cnt, it->second * cnt);
this->median = it->first * over + (it + 1)->first * (1. - over);
}
return this->median;
}
示例8: N_from_mu
double N_from_mu(Minimizer *min, Grid *potential, const Grid &constraint, double mu) {
Functional f = constrain(constraint, OfEffectivePotential(HS + IdealGas()
+ ChemicalPotential(mu)));
double Nnow = 0;
min->minimize(f, potential->description());
for (int i=0;i<numiters && min->improve_energy(false);i++) {
Grid density(potential->description(), EffectivePotentialToDensity()(1, potential->description(), *potential));
Nnow = density.sum()*potential->description().dvolume;
printf("Nnow is %g vs %g\n", Nnow, N);
fflush(stdout);
density.epsNativeSlice("papers/contact/figs/box.eps",
Cartesian(0,ymax+2,0), Cartesian(0,0,zmax+2),
Cartesian(0,-ymax/2-1,-zmax/2-1));
density.epsNativeSlice("papers/contact/figs/box-diagonal.eps",
Cartesian(xmax+2,0,zmax+2), Cartesian(0,ymax+2,0),
Cartesian(-xmax/2-1,-ymax/2-1,-zmax/2-1));
//sleep(3);
}
return Nnow;
}
示例9: cp_mole
doublereal SingleSpeciesTP::cv_mole() const
{
/*
* For single species, we go directory to the general Cp - Cv relation
*
* Cp = Cv + alpha**2 * V * T / beta
*
* where
* alpha = volume thermal expansion coefficient
* beta = isothermal compressibility
*/
doublereal cvbar = cp_mole();
doublereal alpha = thermalExpansionCoeff();
doublereal beta = isothermalCompressibility();
doublereal V = molecularWeight(0)/density();
doublereal T = temperature();
if (beta != 0.0) {
cvbar -= alpha * alpha * V * T / beta;
}
return cvbar;
}
示例10: pressure
void WaterSSTP::getEntropy_R_ref(doublereal* sr) const
{
doublereal p = pressure();
double T = temperature();
double dens = density();
int waterState = WATER_GAS;
double rc = m_sub.Rhocrit();
if (dens > rc) {
waterState = WATER_LIQUID;
}
doublereal dd = m_sub.density(T, OneAtm, waterState, dens);
if (dd <= 0.0) {
throw CanteraError("setPressure", "error");
}
m_sub.setState_TR(T, dd);
doublereal s = m_sub.entropy();
*sr = (s + SW_Offset)/ GasConstant;
dd = m_sub.density(T, p, waterState, dens);
}
示例11: density
void IonFlow::electricFieldMethod(const double* x, size_t j0, size_t j1)
{
for (size_t j = j0; j < j1; j++) {
double wtm = m_wtm[j];
double rho = density(j);
double dz = z(j+1) - z(j);
// mixture-average diffusion
double sum = 0.0;
for (size_t k = 0; k < m_nsp; k++) {
m_flux(k,j) = m_wt[k]*(rho*m_diff[k+m_nsp*j]/wtm);
m_flux(k,j) *= (X(x,k,j) - X(x,k,j+1))/dz;
sum -= m_flux(k,j);
}
// ambipolar diffusion
double E_ambi = E(x,j);
for (size_t k : m_kCharge) {
double Yav = 0.5 * (Y(x,k,j) + Y(x,k,j+1));
double drift = rho * Yav * E_ambi
* m_speciesCharge[k] * m_mobility[k+m_nsp*j];
m_flux(k,j) += drift;
}
// correction flux
double sum_flux = 0.0;
for (size_t k = 0; k < m_nsp; k++) {
sum_flux -= m_flux(k,j); // total net flux
}
double sum_ion = 0.0;
for (size_t k : m_kCharge) {
sum_ion += Y(x,k,j);
}
// The portion of correction for ions is taken off
for (size_t k : m_kNeutral) {
m_flux(k,j) += Y(x,k,j) / (1-sum_ion) * sum_flux;
}
}
}
示例12: density
// Calculate the modes of the density for the distribution
// and their associated errors
double
vpScale::MeanShift(vpColVector &error)
{
int n = error.getRows()/dimension;
vpColVector density(n);
vpColVector density_gradient(n);
vpColVector mean_shift(n);
int increment=1;
// choose smallest error as start point
int i=0;
while(error[i]<0 && error[i]<error[i+1])
i++;
// Do mean shift until no shift
while(increment >= 1 && i<n)
{
increment=0;
density[i] = KernelDensity(error, i);
density_gradient[i] = KernelDensityGradient(error, i);
mean_shift[i]=vpMath::sqr(bandwidth)*density_gradient[i]/((dimension+2)*density[i]);
double tmp_shift = mean_shift[i];
// Do mean shift
while(tmp_shift>0 && tmp_shift>error[i]-error[i+1])
{
i++;
increment++;
tmp_shift-=(error[i]-error[i-1]);
}
}
return error[i];
}
示例13: minPostings
ShardDefinition::ShardDefinition(std::istream& input)
{
CsvTsv::InputColumn<size_t>
minPostings("MinPostings",
"Minimum number of postings for any document in shard.");
CsvTsv::InputColumn<double>
density("Density",
"Target density for RowTables in the shard.");
CsvTsv::CsvTableParser parser(input);
CsvTsv::TableReader reader(parser);
reader.DefineColumn(minPostings);
reader.DefineColumn(density);
reader.ReadPrologue();
while (!reader.AtEOF())
{
reader.ReadDataRow();
AddShard(minPostings, density);
}
reader.ReadEpilogue();
}
示例14: switch
Real SodProblem::valueExact(Real t, const Point& p, int eq)
{
switch (eq) {
case 0:
return density(t, p);
break;
case 1:
return momentumX(t, p);
break;
case 2:
return momentumY(t, p);
break;
case 3:
return momentumZ(t, p);
case 4:
return energyTotal(t, p);
break;
default:
return 0.0;
mooseError("不可用的分量" << eq);
break;
}
}
示例15: evaluateFields
void XZHydrostatic_GeoPotential<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
const Eta<EvalT> &E = Eta<EvalT>::self();
ScalarT sum;
for (int cell=0; cell < workset.numCells; ++cell) {
for (int node=0; node < numNodes; ++node) {
for (int level=0; level < numLevels; ++level) {
sum =
PhiSurf(cell,node) +
0.5 * Pi(cell,node,level) * E.delta(level) / density(cell,node,level);
for (int j=level+1; j < numLevels; ++j) sum += Pi(cell,node,j) * E.delta(j) / density(cell,node,j);
Phi(cell,node,level) = sum;
//std::cout <<"Inside GeoP, cell, node, PhiSurf(cell,node)="<<cell<<
//", "<<node<<", "<<PhiSurf(cell,node) <<std::endl;
}
}
}
}