Beispiel #1
0
Moment Moment::operator-(const int val) const {
    if(this->date) {
        Date d(this->time);
        d.remove(val, Minute);
        return Moment(d.getTime(), true);
    }

    return Moment(this->time - val*60, false);
}
Beispiel #2
0
// **********************************************************************
double CPrecipPSD::SpecificSurfArea(double THAdens, double *dist, long *npts, double *x)
  {
  // Builtin functions
  double      pow_di(double , long );
  // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  //
  //     npts          number of points in discretization of psd
  //     x             midpoints of discretization
  //     Dist          number particle size distribution in 
  //     i             counter in do loop
  //     THAdens       hydrate density
  // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

  // Parameter adjustments
  //--x;
  //--dist;

  //double mdist[MaxPSDGridPts];
  //for (int i=0; i < *npts; i++)
  //  mdist[i]=dist[i];

  double mom2 = Moment(dist, 2, &m_GridPts.npts, m_GridPts.x) * 1e-12;  // calc 2nd moment
  double mom3 = Moment(dist, 3, &m_GridPts.npts, m_GridPts.x) * 1e-18;  // calc 3rd moment
  double surf = mom2 * 3.141592653589793;  // Surface area

  //Mass of alumina solids / kg slurry
  double rh = m_ModelParms.m_RhoH * 3.141592653589793 * mom3 / 6.0; // rh in tank
  double SSA=surf/(rh*1000);

  return SSA;
  //NumberToMass(mdist, npts, x);
  //
  //double TotMass=0.0;
  //double TotArea=0.0;
  //
  //for (i=0; i < *npts; i++)
  //  {
  //  double D=x[i]*1.0e-6;
  //  double SAMAtD=3.0/GTZ(500.*THAdens*D);
  //  TotMass+=mdist[i];
  //  TotArea+=SAMAtD*mdist[i];
  //  //dbgpln("%12.6f %12.6f %12.6f", x[i], mdist[i], SAMAtD);
  //  }
  //double dSAM=TotArea/GTZ(TotMass);
  ////dbgpln("%12s %12.6f %12.6f %12.6f", "", TotMass, TotArea, dSAM);
  //
  //return dSAM;
  } // Moment
Beispiel #3
0
Moment Moment::operator+(const Moment& m) const {
    if(this->isDate() && m.isDate()) {
        // date + date
        throw InvalidArgumentException("Can't add a date to a date");
    }

    if(!this->isDate() && !m.isDate()) {
        // délai + délai
        return Moment(this->time + m.time, false);
    }

    // date + delai
    Date d(this->date ? this->time : m.time);
    d.add(this->date ? m.time : this->time, Second);
    return Moment(d.getTime(), true);
}
Beispiel #4
0
Moment Moment::operator+(const int val) const {
    if(this->date) {
        Moment m(*this);
        m.setMinute(m.getMinute() + val);
        return m;
    }
    return Moment(this->time + val*60, false);
}
Beispiel #5
0
static void chanfunc_CalcStatistics (channelPtr chan)
{
    double mean, std_dev, variance, rms, moment, median, mode, min, max;
    int err, order, min_i, max_i, intervals;
    char newnote[256];

    Fmt (chanfunc.note, "");
    err = MaxMin1D (chan->readings, chan->pts, &max, &max_i, &min, &min_i);
    SetInputMode (chanfunc.p, STATISTICS_MIN, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_MIN, min);
    SetInputMode (chanfunc.p, STATISTICS_MAX, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_MAX, max);
    if (err == NoErr)
    {
        Fmt (chanfunc.note, "%s<Min: %f[e2p5]\n", min);
        Fmt (chanfunc.note, "%s[a]<Max: %f[e2p5]\n", max);
    }

    err = Mean (chan->readings, chan->pts, &mean);
    SetInputMode (chanfunc.p, STATISTICS_MEAN, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_MEAN, mean);
    if (err == NoErr) Fmt (chanfunc.note, "%s[a]<Mean: %f[e2p5]\n", mean);

    err = StdDev (chan->readings, chan->pts, &mean, &std_dev);
    SetInputMode (chanfunc.p, STATISTICS_STDDEV, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_STDDEV, std_dev);
    if (err == NoErr) Fmt (chanfunc.note, "%s[a]<StdDev: %f[e2p5]\n", std_dev);

    err = Variance (chan->readings, chan->pts, &mean, &variance);
    SetInputMode (chanfunc.p, STATISTICS_VAR, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_VAR, variance);
    if (err == NoErr) Fmt (chanfunc.note, "%s[a]<Variance: %f[e2p5]\n", variance);

    err = RMS (chan->readings, chan->pts, &rms);
    SetInputMode (chanfunc.p, STATISTICS_RMS, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_RMS, rms);
    if (err == NoErr) Fmt (chanfunc.note, "%s[a]<RMS: %f[e2p5]\n", rms);

    GetCtrlVal (chanfunc.p, STATISTICS_ORDER, &order);
    err = Moment (chan->readings, chan->pts, order, &moment);
    SetInputMode (chanfunc.p, STATISTICS_MOMENT, !err);
    SetInputMode (chanfunc.p, STATISTICS_ORDER, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_MOMENT, moment);
    if (err == NoErr) Fmt (chanfunc.note, "%s[a]<Moment: %f[e2p5] (order: %i)\n", moment, order);

    err = Median (chan->readings, chan->pts, &median);
    SetInputMode (chanfunc.p, STATISTICS_MEDIAN, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_MEDIAN, median);
    if (err == NoErr) Fmt (chanfunc.note, "%s[a]<Median: %f[e2p5]\n", median);

    GetCtrlVal (chanfunc.p, STATISTICS_INTERVAL, &intervals);
    err = Mode (chan->readings, chan->pts, min, max, intervals, &mode);
    SetInputMode (chanfunc.p, STATISTICS_INTERVAL, !err);
    SetInputMode (chanfunc.p, STATISTICS_MODE, !err);
    SetCtrlVal (chanfunc.p, STATISTICS_INTERVAL, intervals);
    SetCtrlVal (chanfunc.p, STATISTICS_MODE, mode);
    if (err == NoErr) Fmt (chanfunc.note, "%s[a]<Mode: %f[e2p5] (intervals: %i)\n", mode, intervals);
}
Beispiel #6
0
TEST_F(MomentTest, constructor) {
  cout << "moment: " << moment().format() << endl;
  EXPECT_EQ(Moment(1u).valueOf(), 1000);
  EXPECT_EQ(Moment(1u).unix(), 1);
  EXPECT_EQ(Moment(1u).format(), "1970-01-01 08:00:01.000");

  EXPECT_EQ(Moment(1ull).valueOf(), 1);
  EXPECT_EQ(Moment(1ull).unix(), 0);
  EXPECT_EQ(Moment(1000ull).unix(), 1);
  EXPECT_EQ(Moment(1ull).format(), "1970-01-01 08:00:00.001");

  EXPECT_EQ(Moment(1u, 1000000u).valueOf(), 1001);
  EXPECT_EQ(Moment(1u, 1000000u).format(), "1970-01-01 08:00:01.001");
}
double LegendreMomentShape::Evaluate(const double mKK, const double phi, const double ctheta_1, const double ctheta_2) const
{
	if(init) return 1;
	double result = 0;
	double mKK_mapped = (mKK - mKK_min) / (mKK_max - mKK_min)*2 - 1;
	if(std::abs(mKK_mapped) > 1) return 0; // I could print a warning here, but it gets tedious when you just want a mass projection with sensibly-sized bins that includes the threshold
	for(auto coeff : coeffs)
		result += coeff.val*Moment(coeff.l, coeff.i, coeff.k, coeff.j, mKK_mapped, phi, ctheta_1, ctheta_2);
	return result;
}
Beispiel #8
0
Moment Moment::operator-(const Moment& m) const {
    if(!this->date && m.date) {
        // délai - date
        throw InvalidArgumentException("You shouldn't remove a delay from a date");
    }

    if(!this->date && !m.date) {
        // délai - délai
        return Moment(this->time - m.time, false);
    }

    if(this->date && !m.date) {
        // date - délai
        Date d(this->time);
        d.remove(m.time, Second);
        return Moment(d.getTime(), true);
    }

    // date - date
    return Moment(Date(this->time) - Date(m.time), false);
}
Beispiel #9
0
int CPrecipPSD::NumberToMass(double *dist, long *npts, double *x)
  {
  long           i__1;
  double        d__1, d__2;

  double        const_;
  long           ii;
  double        mom3;

  // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  //
  //     npts          number of points in discretization of psd
  //     x             midpoints of discretization
  //     const         normalizing factor
  //     dist          particle size distribution
  //     ii            counter in do loop
  //     mom3          3rd moment of psd
  // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  //
  //    Functions Used
  //    Moment         Calculates moments from psd
  // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  //
  // Parameter adjustments
  --x;
  --dist;

  // Function Body
  mom3 = Moment(&dist[1], 3, npts, &x[1]);
  if(mom3 >= 1e-20)
    {
    const_ = 1. / mom3;
    }
  else
    {
    const_ = 0.;
    }

  i__1 = *npts;
  for(ii = 1; ii <= i__1; ++ii)
    {
    // Computing 3rd power
    d__1 = x[ii], d__2 = d__1;
    dist[ii] = const_ * (d__2 * (d__1 * d__1)) * dist[ii];
    if (dist[ii]<0)
      {
      int xxx=0;
      }
    }

  return 0;
  } // NumberToMass
Beispiel #10
0
int CPrecipPSD::DistSauter(double *psd, double *l32, long *npts, double *x)
  {
  long           i__1;

  // Builtin functions
  double            exp(double);

  long           i;
  double        mom0;

  // cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  //
  //     npts          number of points in discretization of psd
  //     x             midpoints of discretization
  //     i            counter in do loop
  //     L32          Sauter mean diameter
  //     mom0         0th moment
  //     psd          particle size distribution
  // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  //
  //    Functions Used
  //    Moment         Calculates moments from psd
  // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  //
  // Parameter adjustments
  --x;
  --psd;

  // Function Body
  i__1 = *npts;
  for(i = 1; i <= i__1; ++i)
    {
    psd[i] = x[i] * Exps(x[i] * -3. / *l32);

    // note interval prop to x
    }

  mom0 = Moment(&psd[1], 0, npts, &x[1]);
  i__1 = *npts;
  for(i = 1; i <= i__1; ++i)
    {
    psd[i] /= mom0;

    // normalize
    }

  return 0;
  } // DistSauter
Beispiel #11
0
/**
- FUNCIÓ: GetEllipse
- FUNCIONALITAT: Calculates bounding ellipse of external contour points
- PARÀMETRES:
	- 
- RESULTAT:
	- 
- RESTRICCIONS:
	- 
- AUTOR: rborras
- DATA DE CREACIÓ: 2008/05/06
- MODIFICACIÓ: Data. Autor. Descripció.
- NOTA: Calculation is made using second order moment aproximation
*/
CvBox2D CBlob::GetEllipse()
{
	// it is calculated?
	if( m_ellipse.size.width != -1 )
		return m_ellipse;
	
	double u00,u11,u01,u10,u20,u02, delta, num, den, temp;

	// central moments calculation
	u00 = Moment(0,0);

	// empty blob?
	if ( u00 <= 0 )
	{
		m_ellipse.size.width = 0;
		m_ellipse.size.height = 0;
		m_ellipse.center.x = 0;
		m_ellipse.center.y = 0;
		m_ellipse.angle = 0;
		return m_ellipse;
	}
	u10 = Moment(1,0) / u00;
	u01 = Moment(0,1) / u00;

	u11 = -(Moment(1,1) - Moment(1,0) * Moment(0,1) / u00 ) / u00;
	u20 = (Moment(2,0) - Moment(1,0) * Moment(1,0) / u00 ) / u00;
	u02 = (Moment(0,2) - Moment(0,1) * Moment(0,1) / u00 ) / u00;


	// elipse calculation
	delta = sqrt( 4*u11*u11 + (u20-u02)*(u20-u02) );
	m_ellipse.center.x = u10;
	m_ellipse.center.y = u01;
	
	temp = u20 + u02 + delta;
	if( temp > 0 )
	{
		m_ellipse.size.width = sqrt( 2*(u20 + u02 + delta ));
	}	
	else
	{
		m_ellipse.size.width = 0;
		return m_ellipse;
	}

	temp = u20 + u02 - delta;
	if( temp > 0 )
	{
		m_ellipse.size.height = sqrt( 2*(u20 + u02 - delta ) );
	}
	else
	{
		m_ellipse.size.height = 0;
		return m_ellipse;
	}

	// elipse orientation
	if (u20 > u02)
	{
		num = u02 - u20 + sqrt((u02 - u20)*(u02 - u20) + 4*u11*u11);
		den = 2*u11;
	}
    else
    {
		num = 2*u11;
		den = u20 - u02 + sqrt((u20 - u02)*(u20 - u02) + 4*u11*u11);
    }
	if( num != 0 && den  != 00 )
	{
		m_ellipse.angle = 180.0 + (180.0 / CV_PI) * atan( num / den );
	}
	else
	{
		m_ellipse.angle = 0;
	}
        
	return m_ellipse;

}
Beispiel #12
0
void LegendreMomentShape::Generate(IDataSet* dataSet, const PhaseSpaceBoundary* boundary, const std::string mKKname, const std::string phiname, const std::string ctheta_1name, const std::string ctheta_2name)
{
	double**** c    = newcoefficients();
	double**** c_sq = newcoefficients(); // Used in caclulating the error
	mKK_min = boundary->GetConstraint(mKKname)->GetMinimum();
	mKK_max = boundary->GetConstraint(mKKname)->GetMaximum();
	const double mK  = 0.493677; // TODO: read these from config somehow
	const double mBs  = 5.36677;
	const double mPhi= 1.019461;
	int numEvents = dataSet->GetDataNumber();
	// Calculate the coefficients by summing over the dataset
	std::cout << "Sum over " << numEvents << " events" << std::endl;
	for (int e = 0; e < numEvents; e++)
	{
		// Retrieve the data point
		DataPoint * event = dataSet->GetDataPoint(e);
		double phi        = event->GetObservable(phiname)->GetValue();
		double ctheta_1   = event->GetObservable(ctheta_1name)->GetValue();
		double ctheta_2   = event->GetObservable(ctheta_2name)->GetValue();
		double mKK        = event->GetObservable(mKKname)->GetValue();
		double mKK_mapped = (mKK - mKK_min)/(mKK_max-mKK_min)*2.+ (-1);
		// Calculate phase space element
		double p1_st = DPHelpers::daughterMomentum(mKK, mK, mK);
		double p3    = DPHelpers::daughterMomentum(mBs,mKK,mPhi);
		double val = p1_st*p3;
		for ( int l = 0; l < l_max; l++ )
			for ( int i = 0; i < i_max; i++ )
				for ( int k = 0; k < k_max; k++ )
					for ( int j = 0; j < j_max; j++ )
					{
						double coeff = ((2*l + 1)/2.)*((2*i + 1)/2.)*Moment(l, i, k, j, mKK_mapped, phi, ctheta_1, ctheta_2)/val;
						c[l][i][k][j] += coeff;
						c_sq[l][i][k][j] += coeff * coeff;
					}
	}
	// Accept or reject the coefficients
	double threshold = 4; // TODO: read from config
	std::cout << "Keeping coefficients more significant than " << threshold << "σ" << std::endl;
	for ( int l = 0; l < l_max; l++ )
		for ( int i = 0; i < i_max; i++ )
			for ( int k = 0; k < k_max; k++ )
				for ( int j = 0; j < j_max; j++ )
				{
					if(std::abs(c[l][i][k][j]) < 1e-12)
					{
						c[l][i][k][j] = 0.;
						continue;
					}
					double error = sqrt(1./numEvents/numEvents * ( c_sq[l][i][k][j] - c[l][i][k][j]*c[l][i][k][j]/numEvents) );
					double signif = std::abs(c[l][i][k][j]/numEvents)/error;
					if ( signif > threshold )
					{
						printf("c[%d][%d][%d][%d] = %f;// ± %f with significance %fσ\n", l, i, k, j, c[l][i][k][j]/numEvents, error, signif );
						c[l][i][k][j] /= numEvents;
					}
					else
						c[l][i][k][j] = 0.;
				}
	storecoefficients(c);
	deletecoefficients(c);
	deletecoefficients(c_sq);
	init = false;
}
Beispiel #13
0
int CPrecipPSD::EqnsToSolve
                    (
                      double  *y,
                      double  *yin,
                      double  *g,
                      double  *nuc,
                      double  *agg,
                      double  *res_time__,
                      double  *grow_coeff__,
                      double  *aggl_coeff__,
                      long     *q,
                      long     *npts,
                      double  *yp
                    )
  {
  long                   i;
  double                DotTmp[MaxPSDGridPts];
  double                PSDDotDiff[MaxPSDGridPts];

  // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  //
  //     rate of change of variables due to input/output to tank
  // Parameter adjustments
  CPSDStates &St  = *((CPSDStates*)y);
  CPSDStates &In  = *((CPSDStates*)yin);
  CPSDStates &Dot = *((CPSDStates*)yp);

  // Function Body
  for(i = 0; i < St.NStates(); ++i)
    {
    Dot[i] = -(St[i] - In[i]) / *res_time__;
    if (Dot[i]<0.0)
      { int xxx=0; }
    }

  // remember psd changes due to advection - CNM 
  for(i = 0; i < St.NPSD(); ++i)
    PSDDotDiff[i] = Dot.PSD(i);

  if (1)
    {
    //     rate of change of distribution due to growth and nucleation
    PureGrowth(St.PSD(), grow_coeff__, npts, DotTmp);

    for(i = 0; i < St.NPSD(); ++i)
      {
      Dot.PSD(i) += *g * 1e6 * DotTmp[i];
      if (Dot.PSD(i)<0.0)
        { int xxx=0; }
      }

    //     rate of change of distribution due to nucleation
    Dot.PSD(0) += *nuc;

    //     rate of change of distribution due to agglomeration
    if(*agg > 0.)
      {
      PureAgglom(St.PSD(), q, npts, aggl_coeff__, DotTmp);

      for(i = 0; i < St.NPSD(); ++i)
        {
        Dot.PSD(i) += *agg * DotTmp[i];
        if (Dot.PSD(i)<0.0)
          { int xxx=0; }
        }
      }
    }

  // Bound Soda
  Dot.rSoda()       -=m_DerivsPars.m_SodaRate;
  Dot.rBndSoda()    +=m_DerivsPars.m_SodaRate;
  Dot.rOrgSoda()    -=m_DerivsPars.m_OrgSodaRate;
  Dot.rBndOrgSoda() +=m_DerivsPars.m_OrgSodaRate;

  // Heat of Reaction
  if (m_DerivsPars.m_bWithHOR)
    {
    // calculate sum psd changes due to growth etc - CNM 
    for(i = 0; i < St.NPSD(); ++i)
      PSDDotDiff[i] = Dot.PSD(i) - PSDDotDiff[i];

    double mom3 = Moment(PSDDotDiff, 3, &m_GridPts.npts, m_GridPts.x) * 1e-18;  // calc 3rd moment
    //     convert basic variables to State2Conc variables
    double drh = m_ModelParms.m_RhoH * 3.141592653589793 * mom3 / 6.0; // rh in tank
 
    double dt=drh*m_DerivsPars.m_dTRate;
    Dot.Temp() += dt;
    m_DerivsPars.m_dReactionHeat = dt/3600.0*m_DerivsPars.m_totCp;
    }
  else
    m_DerivsPars.m_dReactionHeat=0;

  // ThermalLoss
  if (1)
    {
    double dt=3600.0*m_DerivsPars.m_dThermalConst*(m_DerivsPars.m_dAmbientTemp-St.Temp());
    Dot.Temp() += dt;
    m_DerivsPars.m_dThermalLoss = -dt/3600.0*m_DerivsPars.m_totCp;
    }
  else
    m_DerivsPars.m_dThermalLoss=0;
  return 0;
  } // EqnsToSolve
Beispiel #14
0
Moment Moment::now() {
    return Moment(Date().getTime(), true);
}
Beispiel #15
0
TEST_F(MomentTest, format) {
  EXPECT_EQ(Moment(1u).format("YYYY-MM-DD"), "1970-01-01");
  EXPECT_EQ(Moment(1u).format("HH:mm:ss.SSS"), "08:00:01.000");
  EXPECT_EQ(Moment(1u).format("YY"), "70");
}