void Foam::twoPhaseMixtureThermo::correct()
{
    psi_ = alpha1()*thermo1_->psi() + alpha2()*thermo2_->psi();
    mu_ = alpha1()*thermo1_->mu() + alpha2()*thermo2_->mu();
    alpha_ = alpha1()*thermo1_->alpha() + alpha2()*thermo2_->alpha();

    interfaceProperties::correct();
}
void Foam::twoPhaseMixtureThermo::correct()
{
    thermo1_->he() = thermo1_->he(p_, T_);
    thermo1_->correct();

    thermo2_->he() = thermo2_->he(p_, T_);
    thermo2_->correct();

    psi_ = alpha1()*thermo1_->psi() + alpha2()*thermo2_->psi();
    mu_ = alpha1()*thermo1_->mu() + alpha2()*thermo2_->mu();
    alpha_ = alpha1()*thermo1_->alpha() + alpha2()*thermo2_->alpha();
}
Пример #3
0
Dart EmbeddedGMap3::cutEdge(Dart d)
{
    Dart nd = GMap3::cutEdge(d);

    if(isOrbitEmbedded<EDGE>())
    {
        // embed the new darts created in the cut edge
        unsigned int eEmb = getEmbedding<EDGE>(d) ;
        Dart e = d ;
        do
        {
            setDartEmbedding<EDGE>(beta0(e), eEmb) ;
            e = alpha2(e) ;
        } while(e != d) ;

        // embed a new cell for the new edge and copy the attributes' line (c) Lionel
        setOrbitEmbeddingOnNewCell<EDGE>(phi1(d)) ;
        copyCell<EDGE>(phi1(d), d) ;
    }

    if(isOrbitEmbedded<FACE>())
    {
        Dart f = d;
        do
        {
            unsigned int fEmb = getEmbedding<FACE>(f) ;
            setDartEmbedding<FACE>(beta0(f), fEmb);
            setDartEmbedding<FACE>(phi1(f), fEmb);
            setDartEmbedding<FACE>(phi3(f), fEmb);
            setDartEmbedding<FACE>(beta1(phi3(f)), fEmb);
            f = alpha2(f);
        } while(f != d);
    }

    if(isOrbitEmbedded<VOLUME>())
    {
        Dart f = d;
        do
        {
            unsigned int vEmb = getEmbedding<VOLUME>(f) ;
            setDartEmbedding<VOLUME>(beta0(f), vEmb);
            setDartEmbedding<VOLUME>(phi1(f), vEmb);
            setDartEmbedding<VOLUME>(phi2(f), vEmb);
            setDartEmbedding<VOLUME>(beta1(phi2(f)), vEmb);
            f = alpha2(f);
        } while(f != d);
    }

    return nd ;
}
Пример #4
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::GidaspowErgunWenYu::K
(
    const volScalarField& Ur
) const
{
    volScalarField alpha2(max(scalar(1) - alpha1_, scalar(1.0e-6)));
    volScalarField d(phase1_.d());
    volScalarField bp(pow(alpha2, -2.65));
    volScalarField Re(max(Ur*d/phase2_.nu(), scalar(1.0e-3)));

    volScalarField Cds
    (
        neg(Re - 1000)*(24.0*(1.0 + 0.15*pow(Re, 0.687))/Re)
      + pos(Re - 1000)*0.44
    );

    // Wen and Yu (1966)
    return
    (
        pos(alpha2 - 0.8)
       *(0.75*Cds*phase2_.rho()*Ur*bp/d)
      + neg(alpha2 - 0.8)
       *(
           150.0*alpha1_*phase2_.nu()*phase2_.rho()/(sqr(alpha2*d))
         + 1.75*phase2_.rho()*Ur/(alpha2*d)
        )
    );
}
Пример #5
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::SyamlalOBrien::CdRe() const
{
    volScalarField alpha2
    (
        max(scalar(1) - pair_.dispersed(), pair_.continuous().residualAlpha())
    );

    volScalarField A(pow(alpha2, 4.14));
    volScalarField B
    (
        neg(alpha2 - 0.85)*(0.8*pow(alpha2, 1.28))
      + pos0(alpha2 - 0.85)*(pow(alpha2, 2.65))
    );
    volScalarField Re(pair_.Re());
    volScalarField Vr
    (
        0.5
       *(
            A - 0.06*Re + sqrt(sqr(0.06*Re) + 0.12*Re*(2.0*B - A) + sqr(A))
        )
    );
    volScalarField CdsRe(sqr(0.63*sqrt(Re) + 4.8*sqrt(Vr)));

    return
        CdsRe
       *max(pair_.continuous(), pair_.continuous().residualAlpha())
       /sqr(Vr);
}
Пример #6
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::Tenneti::CdRe() const
{
    volScalarField alpha1
    (
        max(pair_.dispersed(), pair_.continuous().residualAlpha())
    );

    volScalarField alpha2
    (
        max(scalar(1) - pair_.dispersed(), pair_.continuous().residualAlpha())
    );

    volScalarField F0
    (
        5.81*alpha1/pow3(alpha2) + 0.48*pow(alpha1, 1.0/3.0)/pow4(alpha2)
    );

    volScalarField F1
    (
        pow(alpha1, 3)*max(pair_.Re(), residualRe_)
       *(0.95 + 0.61*pow3(alpha1)/sqr(alpha2))
    );

    // Tenneti et al. correlation includes the mean pressure drag.
    // This was removed here by multiplying F by alpha2 for consistency with
    // the formulation used in OpenFOAM
    return
        SchillerNaumann_->CdRe()/(alpha2*max(pair_.Re(), residualRe_)) +
        24.0*sqr(alpha2)*(F0 + F1);
}
Пример #7
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::SyamlalOBrien::K
(
    const volScalarField& Ur
) const
{
    volScalarField alpha2(max(phase2_, scalar(1.0e-6)));
    volScalarField A(pow(alpha2, 4.14));
    volScalarField B
    (
        neg(alpha2 - 0.85)*(0.8*pow(alpha2, 1.28))
      + pos(alpha2 - 0.85)*(pow(alpha2, 2.65))
    );

    volScalarField Re(max(Ur*phase1_.d()/phase2_.nu(), scalar(1.0e-3)));

    volScalarField Vr
    (
        0.5*
        (
            A - 0.06*Re + sqrt(sqr(0.06*Re) + 0.12*Re*(2.0*B - A) + sqr(A))
        )
    );

    volScalarField Cds(sqr(0.63 + 4.8*sqrt(Vr/Re)));

    return 0.75*Cds*phase2_.rho()*Ur/(phase1_.d()*sqr(Vr));
}
Пример #8
0
void CPengRobinson::SetTDState_rhoT (su2double rho, su2double T) {
	su2double fv, e, atanh;

  atanh = (log(1.0+( rho * b * sqrt(2.0)/(1 + rho*b))) - log(1.0-( rho * b * sqrt(2.0)/(1 + rho*b))))/2.0;
	fv = atanh;
	e = T*Gas_Constant/Gamma_Minus_One - a*(k+1)*sqrt( alpha2(T) ) / ( b*sqrt(2.0) ) * fv;
	SetTDState_rhoe(rho, e);
}
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureThermo::he
(
    const volScalarField& p,
    const volScalarField& T
) const
{
    return alpha1()*thermo1_->he(p, T) + alpha2()*thermo2_->he(p, T);
}
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureThermo::kappa
(
    const label patchi
) const
{
    return
        alpha1().boundaryField()[patchi]*thermo1_->kappa(patchi)
      + alpha2().boundaryField()[patchi]*thermo2_->kappa(patchi);
}
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureThermo::alphaEff
(
    const volScalarField& alphat
) const
{
    return
        alpha1()*thermo1_->alphaEff(alphat)
      + alpha2()*thermo2_->alphaEff(alphat);
}
Пример #12
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::Gibilaro::CdRe() const
{
    volScalarField alpha2(max(scalar(1) - pair_.dispersed(), residualAlpha_));

    return
        (4/3)
       *(17.3/alpha2 + 0.336*pair_.Re())
       *max(pair_.continuous(), residualAlpha_)
       *pow(alpha2, -2.8);
}
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureThermo::he
(
    const scalarField& p,
    const scalarField& T,
    const labelList& cells
) const
{
    return
        scalarField(alpha1(), cells)*thermo1_->he(p, T, cells)
      + scalarField(alpha2(), cells)*thermo2_->he(p, T, cells);
}
Пример #14
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::Gibilaro::K
(
    const volScalarField& Ur
) const
{
    volScalarField alpha2(max(phase2_, scalar(1.0e-6)));
    volScalarField bp(pow(alpha2, -2.8));
    volScalarField Re(max(alpha2*Ur*phase1_.d()/phase2_.nu(), scalar(1.0e-3)));

    return (17.3/Re + scalar(0.336))*phase2_.rho()*Ur*bp/phase1_.d();
}
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureThermo::alphaEff
(
    const scalarField& alphat,
    const label patchi
) const
{
    return
        alpha1().boundaryField()[patchi]*thermo1_->alphaEff(alphat, patchi)
      + alpha2().boundaryField()[patchi]*thermo2_->alphaEff(alphat, patchi)
    ;
}
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureThermo::CpByCpv
(
    const scalarField& p,
    const scalarField& T,
    const label patchi
) const
{
    return
        alpha1().boundaryField()[patchi]*thermo1_->CpByCpv(p, T, patchi)
      + alpha2().boundaryField()[patchi]*thermo2_->CpByCpv(p, T, patchi);
}
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureThermo::nu
(
    const label patchi
) const
{
    return
        mu(patchi)
       /(
            alpha1().boundaryField()[patchi]*thermo1_->rho(patchi)
          + alpha2().boundaryField()[patchi]*thermo2_->rho(patchi)
        );
}
Пример #18
0
void CPengRobinson::SetTDState_PT (su2double P, su2double T ) {
	su2double toll= 1e-6;
	su2double A, B, Z, DZ=1.0, F, F1, atanh;
	su2double rho, fv, e;
	su2double sqrt2=sqrt(2.0);
	unsigned short nmax = 20, count=0;

	A= a*alpha2(T)*P/(T*Gas_Constant)/(T*Gas_Constant);
	B= b*P/(T*Gas_Constant);

  if (Zed > 0.1) Z = min(Zed, 0.99);
		else Z=0.99;
  
	do {
		F = Z*Z*Z + Z*Z*(B - 1.0) + Z*(A - 2*B - 3*B*B)  + (B*B*B + B*B - A*B);
		F1 = 3*Z*Z + 2*Z*(B - 1.0) + (A - 2*B - 3*B*B);
		DZ = F/F1;
		Z-= DZ;
	} while(abs(DZ)>toll && count < nmax);

	if (count == nmax) {
		cout << "Warning Newton-Raphson exceed number of max iteration in PT"<< endl;
		cout << "Compressibility factor  "<< Z << " would be substituted with "<< Zed<< endl;
	}
	// check if the solution is physical otherwise uses previous point  solution
	if (Z <= 1.0001 && Z >= 0.05 && count < nmax)
	    Zed = Z;


	rho= P/(Zed*Gas_Constant*T);
  
  atanh = (log(1.0+( rho * b * sqrt2/(1 + rho*b))) - log(1.0-( rho * b * sqrt2/(1 + rho*b))))/2.0;
  
	fv = atanh;

  e = T*Gas_Constant/Gamma_Minus_One - a*(k+1)*sqrt( alpha2(T) )*fv / (b*sqrt2);

	SetTDState_rhoe(rho, e);
}
Пример #19
0
void CPengRobinson::SetTDState_rhoe (su2double rho, su2double e ) {

    su2double DpDd_T, DpDT_d, DeDd_T, Cv;
    su2double A, B, C, sqrt2, fv, a2T, rho2, atanh;

    Density = rho;
    StaticEnergy = e;

    rho2 = rho*rho;
    sqrt2=sqrt(2.0);

    atanh = (log(1.0+( rho * b * sqrt2/(1 + rho*b))) - log(1.0-( rho * b * sqrt2/(1 + rho*b))))/2.0;
  
    fv = atanh;
    
    A = Gas_Constant / Gamma_Minus_One;
    B = a*k*(k+1)*fv/(b*sqrt2*sqrt(TstarCrit));
    C = a*(k+1)*(k+1)*fv/(b*sqrt2) + e;

    Temperature = ( -B + sqrt(B*B + 4*A*C) ) / (2*A); /// Only positive root considered
    Temperature *= Temperature;

    a2T = alpha2(Temperature);

    A = (1/rho2 + 2*b/rho - b*b);
    B = 1/rho-b;

    Pressure = Temperature*Gas_Constant / B - a*a2T / A;

    Entropy = Gas_Constant / Gamma_Minus_One*log(Temperature) + Gas_Constant*log(B) - a*sqrt(a2T) *k*fv/(b*sqrt2*sqrt(Temperature*TstarCrit));

    DpDd_T =  ( Temperature*Gas_Constant /(B*B    ) - 2*a*a2T*(1/rho + b) /( A*A ) ) /(rho2);

    DpDT_d = Gas_Constant /B + a*k / A * sqrt( a2T/(Temperature*TstarCrit) );

    Cv = Gas_Constant/Gamma_Minus_One + ( a*k*(k+1)*fv ) / ( 2*b*sqrt(2*Temperature*TstarCrit) );

    dPde_rho = DpDT_d/Cv;

    DeDd_T = - a*(1+k) * sqrt( a2T ) / A / (rho2);

    dPdrho_e = DpDd_T - dPde_rho*DeDd_T;

    SoundSpeed2 = dPdrho_e + Pressure/(rho2)*dPde_rho;

    dTde_rho = 1/Cv;

    Zed = Pressure/(Gas_Constant*Temperature*Density);


}
Пример #20
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::WenYu::CdRe() const
{
    volScalarField alpha2(max(scalar(1) - pair_.dispersed(), residualAlpha_));
    volScalarField Re(pair_.Re());
    volScalarField CdsRe
    (
        neg(Re - 1000)*24.0*(1.0 + 0.15*pow(Re, 0.687))
      + pos(Re - 1000)*0.44*max(Re, residualRe_)
    );

    return
        CdsRe
       *pow(alpha2, -2.65)
       *max(pair_.continuous(), residualAlpha_);
}
Foam::tmp<Foam::volScalarField> Foam::dragModels::GidaspowSchillerNaumann::K
(
    const volScalarField& Ur
) const
{
    volScalarField alpha2(max(phase2_, scalar(1e-6)));
    volScalarField bp(pow(alpha2, -2.65));

    volScalarField Re(max(alpha2*Ur*phase1_.d()/phase2_.nu(), scalar(1.0e-3)));
    volScalarField Cds
    (
        neg(Re - 1000)*(24.0*(1.0 + 0.15*pow(Re, 0.687))/Re)
      + pos0(Re - 1000)*0.44
    );

    return 0.75*Cds*phase2_.rho()*Ur*bp/phase1_.d();
}
Пример #22
0
void EmbeddedGMap3::splitVolume(std::vector<Dart>& vd)
{
    GMap3::splitVolume(vd);

    // follow the edge path a second time to embed the vertex, edge and volume orbits
    for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
    {
        Dart dit = *it;

        // embed the vertex embedded from the origin volume to the new darts
        if(isOrbitEmbedded<VERTEX>())
        {
            unsigned int vEmb = getEmbedding<VERTEX>(dit) ;
            setDartEmbedding<VERTEX>(beta2(dit), vEmb);
            setDartEmbedding<VERTEX>(beta3(beta2(dit)), vEmb);
            setDartEmbedding<VERTEX>(beta1(beta2(dit)), vEmb);
            setDartEmbedding<VERTEX>(beta3(beta1(beta2(dit))), vEmb);
        }

        // embed the edge embedded from the origin volume to the new darts
        if(isOrbitEmbedded<EDGE>())
        {
            unsigned int eEmb = getEmbedding<EDGE>(dit) ;
            setDartEmbedding<EDGE>(beta2(dit), eEmb);
            setDartEmbedding<EDGE>(beta3(beta2(dit)), eEmb);
            setDartEmbedding<EDGE>(beta0(beta2(dit)), eEmb);
            setDartEmbedding<EDGE>(beta0(beta3(beta2(dit))), eEmb);
        }

        // embed the volume embedded from the origin volume to the new darts
        if(isOrbitEmbedded<VOLUME>())
        {
            unsigned int vEmb = getEmbedding<VOLUME>(dit) ;
            setDartEmbedding<VOLUME>(beta2(dit), vEmb);
            setDartEmbedding<VOLUME>(beta0(beta2(dit)), vEmb);
        }
    }

    if(isOrbitEmbedded<VOLUME>())
    {
        Dart v = vd.front() ;
        Dart v23 = alpha2(v) ;
        setOrbitEmbeddingOnNewCell<VOLUME>(v23) ;
        copyCell<VOLUME>(v23, v) ;
    }
}
Пример #23
0
float calVelUpdateStepLen(const FwiParams &params,
    const float *wlt,
    const float *dobs,
    const float *derr,
    float epsil,
    const EnquistAbc2d &fmMethod,
    const ShotPosition &allSrcPos,
    const ShotPosition &allGeoPos
    )
{
  int nt = params.nt;
  int nz = params.nz;
  int nx = params.nx;
  int ng = params.ng;
  int ns = params.ns;

  std::vector<float> dcal(ng, 0); /* calculated/synthetic seismic data */
  std::vector<float> sp0(nz * nx); /* source wavefield p0 */
  std::vector<float> sp1(nz * nx); /* source wavefield p1 */
  std::vector<float> sp2(nz * nx); /* source wavefield p2 */

  std::vector<float> alpha1(ng, 0); /* numerator of alpha, length=ng */
  std::vector<float> alpha2(ng, 0); /* denominator of alpha, length=ng */

  for (int is = 0; is < ns; is++) {
    std::fill(sp0.begin(), sp0.end(), 0);
    std::fill(sp1.begin(), sp1.end(), 0);
    ShotPosition currSrcPos = allSrcPos.clip(is);

    for (int it = 0; it < nt; it++) {
      fmMethod.addSource(&sp1[0], &wlt[it], currSrcPos);
      fmMethod.stepForward(&sp0[0], &sp1[0], &sp2[0]);

      cycleSwap(sp0, sp1, sp2);

      fmMethod.recordSeis(&dcal[0], &sp0[0], allGeoPos);

      sum_alpha12(&alpha1[0], &alpha2[0], &dcal[0], &dobs[is * nt * ng + it * ng], &derr[is * ng * nt + it * ng], ng);
    }
  }

  float alpha = cal_alpha(&alpha1[0], &alpha2[0], epsil, ng);

  return alpha;
}
Пример #24
0
void SVM_SVMType_SVR::solve(
    const SVM_Problem & prob,
    const SVM_Parameter & param,
    std::vector<double> & alpha,
    SVM_SolutionInfo & si,
    double Cp,
    double Cn
) const {
    int l = prob.dimension;
    std::vector<double> alpha2(2 * l, 0);
    std::vector<double> linear_term(2 * l, param.p);
    std::vector<schar> y(2 * l, 1);
    int i;

    if (Cp < Cn) {
        // ugly hack to avoid unused variable warning
    }

    for (i = 0; i < l; i++) {
        linear_term[i]     -= prob.labels[i];
        linear_term[i + l] += prob.labels[i];
        y[i + l] = -1;
    }

    SVM_Solver s;
    SVM_SVMType * svmtype = new SVM_SVMType_SVR(prob, param);
    s.solve(2 * l, svmtype, linear_term, y,
        alpha2, param.C, param.C, param.eps, si, param.shrinking);
    delete svmtype;

    double sum_alpha = 0, a;
    for (i = 0; i < l; i++) {
        a = alpha2[i] - alpha2[i + l];
        sum_alpha += fabs(a);
        alpha.push_back(a);
    }
    //std::cout << "nu = " << (sum_alpha / (param.C * l)) << "\n";

    alpha2.clear();
    linear_term.clear();
    y.clear();
}
Пример #25
0
Foam::tmp<Foam::volScalarField>
Foam::dragModels::GidaspowSchillerNaumann::CdRe() const
{
    volScalarField alpha2
    (
        max(scalar(1) - pair_.dispersed(), pair_.continuous().residualAlpha())
    );

    volScalarField Re(alpha2*pair_.Re());

    volScalarField CdsRe
    (
        neg(Re - 1000)*24.0*(1.0 + 0.15*pow(Re, 0.687))/alpha2
      + pos(Re - 1000)*0.44*max(Re, residualRe_)
    );

    return
        CdsRe
       *pow(alpha2, -2.65)
       *max(pair_.continuous(), pair_.continuous().residualAlpha());
}
/****
* This routine computes <LeftVector | \hat P_\pm (\D+B(1-(1/\rho)\D))^-1 P_\pm | RightVector>
* All factors are already included.
*/
bool AnalyzerObservablePsiBarPhiPsiCondensateBase::calcMatrixElementProjectorHatMinverseProjector(Complex& result, double* phiField, Complex* LeftVector, Complex* RightVector, double TOL, int projMode) {
  int L0 = fermiOps->get1DSizeL0();
  int L1 = fermiOps->get1DSizeL1();
  int L2 = fermiOps->get1DSizeL2();
  int L3 = fermiOps->get1DSizeL3();
  bool success = true;  
  double rho, r;
  fermiOps->getDiracParameters(rho, r);
  double fac = -1.0 / (2.0*rho);
  if (projMode != 0) fac *= 0.25;  //Missing factor 0.5 in projector \hat P_\pm and P_\pm compensated with this factor 0.25. 

  //Berechne daggered Projector \hat P_\pm angewendet auf LeftVector  ==> Faktor 0.5 fehlt
  if (projMode != 0) {
    fermiOps->executeGamma5(LeftVector, SolutionVector);
    fermiOps->executeDiracDaggerMatrixMultiplication(SolutionVector, HelperVector, false);
    Complex alpha1(-1.0/rho, 0);
    SSE_ComplexVectorAddition(L0, L1, L2, L3, xtraSize1, xtraSize2, xtraSize3, alpha1, HelperVector, SolutionVector);
    Complex alpha2(projMode, 0);
    SSE_ComplexVectorAddition(L0, L1, L2, L3, xtraSize1, xtraSize2, xtraSize3, alpha2, SolutionVector, LeftVector);	
  }
    
  //Apply inverse M^dagger  
  int neededIter = 0;
  bool b = fermiOps->executeFermionMatrixDaggerInverseMatrixMultiplication(LeftVector, SolutionVector, phiField, TOL, false, -1, neededIter);
  if (!b) success = false;

  //Apply P_\pm^dagger  ==> Faktor 0.5 fehlt
  if (projMode != 0) {
    bool projPlus = true;
    if (projMode<0) projPlus = false;
    fermiOps->executeProjectorMultiplication(SolutionVector, SolutionVector, projPlus); //OHNE Faktor 0.5
  }

  Complex scalar(0,0);     
	  
  SSE_ComplexScalarProduct(L0, L1, L2, L3, xtraSize1, xtraSize2, xtraSize3, SolutionVector, RightVector, scalar);
  result = fac*scalar;

  return success;
}
Пример #27
0
void CPengRobinson::SetEnergy_Prho (su2double P, su2double rho) {

    su2double ad;
    su2double A, B, C, T, vb1, vb2, atanh;
    vb1 = (1/rho -b);
    vb2 = (1/rho/rho + 2*b/rho - b*b);

    A =   Gas_Constant/vb1 - a*k*k/TstarCrit/vb2;

    B =   2*a*k*(k+1)/sqrt(TstarCrit)/vb2;

    C = - P - a*(1+k)*(1+k)/vb2;

    T = ( -B + sqrt(B*B - 4*A*C) ) / (2*A);
    T *= T;

    atanh = (log(1.0+( rho * b * sqrt(2.0)/(1 + rho*b) )) - log(1.0-( rho * b * sqrt(2.0)/(1 + rho*b) )))/2.0;
    ad = a*(k+1)*sqrt( alpha2(T) ) / ( b*sqrt(2.0) ) * atanh ;

    StaticEnergy = T * Gas_Constant / Gamma_Minus_One - ad;

}
Пример #28
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::Tenneti::CdRe() const
{
    volScalarField alpha1
    (
        max(pair_.dispersed(), pair_.continuous().residualAlpha())
    );

    volScalarField alpha2
    (
        max(pair_.continuous(), pair_.continuous().residualAlpha())
    );

    volScalarField Res(alpha2*pair_.Re());

    volScalarField CdReIsolated
    (
        neg(Res - 1000)*24*(1 + 0.15*pow(Res, 0.687))
      + pos0(Res - 1000)*0.44*max(Res, residualRe_)
    );

    volScalarField F0
    (
        5.81*alpha1/pow3(alpha2) + 0.48*pow(alpha1, 1.0/3.0)/pow4(alpha2)
    );

    volScalarField F1
    (
        pow3(alpha1)*Res*(0.95 + 0.61*pow3(alpha1)/sqr(alpha2))
    );

    // Tenneti et al. correlation includes the mean pressure drag.
    // This was removed here by multiplying F by alpha2 for consistency with
    // the formulation used in OpenFOAM
    return
        CdReIsolated + 24*sqr(alpha2)*(F0 + F1);
}
Пример #29
0
void BDT_cuts_norm(){
    
    
    gROOT->ProcessLine(".L ~/cern/project/lhcbStyle.C");
    lhcbStyle();
    
    const std::string filename("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/normalisation_samples/Lb2JpsipK_2011_2012_signal_withbdt.root");
    const std::string treename = "withbdt";
    
    const std::string filenameMC("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/normalisation_samples/Lb2JpsipK_MC_2011_2012_norm_withbdt.root");
    
    TFile* file = TFile::Open( filename.c_str() );
    if( !file ) std::cout << "file " << filename << " does not exist" << std::endl;
    TTree* tree = (TTree*)file->Get( treename.c_str() );
    if( !tree ) std::cout << "tree " << treename << " does not exist" << std::endl;
    
    TFile* fileMC = TFile::Open( filenameMC.c_str() );
    if( !fileMC ) std::cout << "file " << filenameMC << " does not exist" << std::endl;
    TTree* treeMC = (TTree*)fileMC->Get( treename.c_str() );
    if( !treeMC ) std::cout << "tree " << treename << " does not exist" << std::endl;
    
    
    // -- signal, mass shape
    RooRealVar Lambda_b0_DTF_MASS_constr1("Lambda_b0_DTF_MASS_constr1","m(J/#psi pK^{-})", 5550., 5700., "MeV/c^{2}"); 
    RooRealVar Jpsi_M("Jpsi_M","m(#mu#mu)", 3000., 3200., "MeV/c^{2}"); 
    RooRealVar chi_c_M("chi_c_M","m(J/#psi#gamma)", 3400., 3700., "MeV/c^{2}"); 
    RooRealVar mean("mean","mean", 5630., 5610., 5650.);
    RooRealVar sigma1("sigma1","sigma1", 10., 1., 100.);
    RooRealVar sigma2("sigma2","sigma2", 30.0, 5.0, 300.0);
    RooRealVar alpha1("alpha1","alpha1", 1.0, 0.5, 5.0);
    RooRealVar n1("n1","n1", 1.8, 0.2, 15.0);
    RooRealVar alpha2("alpha2","alpha2", -0.5, -5.5, 0.0);
    RooRealVar n2("n2","n2", 0.7, 0.2, 10.0);
    //RooRealVar bkgcat_chic("bkgcat_chic","bkgcat_chic", 0, 100);
    RooRealVar bdtg3("bdtg3", "bdtg3", -1.0, 1.0);
    RooRealVar frac2("frac2","frac2", 0.3, 0., 1.);
    
    RooGaussian gauss1("gauss1","gauss1", Lambda_b0_DTF_MASS_constr1, mean, sigma1);
    RooGaussian gauss2("gauss2","gauss2", Lambda_b0_DTF_MASS_constr1, mean, sigma2);
    RooCBShape cb1("cb1","cb1", Lambda_b0_DTF_MASS_constr1, mean, sigma1, alpha1, n1); 
    RooCBShape cb2("cb2","cb2", Lambda_b0_DTF_MASS_constr1, mean, sigma2, alpha2, n2); 
    RooAddPdf sig("sig", "sig", RooArgList(cb1, cb2), RooArgList( frac2 ));
    RooRealVar cbRatio("cbRatio","cb Ratio", 0.8, 0.1, 1.0);
    RooRealVar sigYield("sigYield","sig Yield", 4e2, 1e0, 1e6);
    RooRealVar bgYield("bgYield","bg Yield", 1e4, 1e0, 1e6);
    
    
    
    //put in values from fit_MC here <<--- DON'T FORGET TO CHANGE THESE IF THE FIT CHANGES!!!
    /*
    EXT PARAMETER                                INTERNAL      INTERNAL
  NO.   NAME      VALUE            ERROR       STEP SIZE       VALUE
   1  alpha1       2.18020e+00   2.85078e-02   1.38432e-04  -2.56034e-01
   2  alpha2      -2.79102e+00   6.74385e-02   1.51818e-04  -1.49177e-02
   3  cbRatio      3.07172e-01   1.49204e-02   1.72642e-04  -5.69984e-01
   4  mean         5.61985e+03   9.58397e-03   5.56682e-05  -9.66293e-02
   5  n1           1.49358e+00   8.14447e-02   2.09300e-04  -9.70542e-01
   6  n2           1.45276e+00   1.09864e-01   2.59028e-04  -8.39538e-01
   7  sigma1       8.46303e+00   1.32851e-01   2.86985e-05  -1.01453e+00
   8  sigma2       4.93976e+00   3.42842e-02   5.03572e-06  -1.44512e+00
    */
    alpha1.setVal( 2.18020e+00 );
    alpha2.setVal( -2.79102e+00 );
    n1.setVal( 1.49358e+00 );
    n2.setVal( 1.45276e+00 );
    frac2.setVal( 3.07172e-01 );
    sigma1.setVal( 8.46303e+00 );
    sigma2.setVal( 4.93976e+00 );
    
    alpha1.setConstant( true );
    alpha2.setConstant( true );
    frac2.setConstant( true );
    n1.setConstant( true );
    n2.setConstant( true );
    sigma1.setConstant( true );
    sigma2.setConstant( true );
    
    // -- bg, mass shape
    RooRealVar a1("a1","a1", -0.1, -0.5, 0.5);
    RooChebychev comb("comb","comb", Lambda_b0_DTF_MASS_constr1, a1);
    RooRealVar mean3("mean3","mean3", 5560., 5500., 5600.);
    RooRealVar sigma3("sigma3","sigma3", 5., 1., 10.);
    RooRealVar frac3("frac3","frac", 0.2, 0.0, 0.3);
    RooGaussian gauss3("gauss3","gauss3", Lambda_b0_DTF_MASS_constr1, mean3, sigma3);
    //RooAddPdf bg("bg","bg", RooArgList(comb), RooArgList(frac3));
    
    // -- add signal & bg
    RooAddPdf pdf("pdf", "pdf", RooArgList(sig, comb), RooArgList( sigYield, bgYield));  
    
    
    double efficiencies1[40];
    double efficiencies1_error[40];
    double bdt_cuts[40];
    double efficiencies2[40];
    double efficiencies2_error[40];
    double sideband_bg_val[40];
    
    double MC_pre = treeMC->GetEntries();
    
    double effvals[40];
    
    
    //loop starting here
    for(int i=0; i < 40; i=i+1) {
        double cut_val = -1.0 + i*0.05;
        //double cut_val = -1.0; // testing
        bdt_cuts[i] = cut_val;
        
        std::stringstream c;
        c << "bdtg3" << " >= " << cut_val;
        const std::string cut = c.str();
        
        //std::cout << cut;
    
        RooArgSet obs;
        obs.add(Lambda_b0_DTF_MASS_constr1);
        //obs.add(chi_c_Mp);
        //obs.add(mass_pK);
        obs.add(Jpsi_M);
        obs.add(chi_c_M);
        obs.add(bdtg3); 
    
        RooDataSet ds("ds","ds", obs, RooFit::Import(*tree), RooFit::Cut(cut.c_str())); 
    
        RooPlot* plot = Lambda_b0_DTF_MASS_constr1.frame();
    
        RooFitResult * result = pdf.fitTo( ds, RooFit::Extended() );
        
        double sig_val = sigYield.getVal();
        double bg_val = bgYield.getVal();
        double sig_error = sigYield.getError();
        double bg_error = bgYield.getError();
        
        double efficiency1 = (sig_val)/(sqrt(sig_val + bg_val));
        efficiencies1[i] = efficiency1;
        
        double efficiency1_error_sq = (pow(sig_error,2)/(sig_val+bg_val) + (pow(sig_val,2)*(pow(sig_error,2)+pow(bg_error,2))/(4*pow((sig_val+bg_val),3))));
        
        double efficiency1_error = sqrt(efficiency1_error_sq);
        efficiencies1_error[i] = efficiency1_error;
        
        /*
        double MC_post = treeMC->GetEntries(cut.c_str());
        
        double eff_val = MC_post/MC_pre; 
        
        //something here to get the sideband background count
        
        
        Lambda_b0_DTF_MASS_constr1.setRange("R", 5650., 5700.);
        RooFitResult * sideband = bg.fitTo( ds, RooFit::Range("R") );
        sideband->Print();
        
        Lambda_b0_DTF_MASS_constr1.setRange("R", 5650., 5700.);
        RooAbsReal* integral = pdf.createIntegral(Lambda_b0_DTF_MASS_constr1, RooFit::Range("R"));
        //std::cout << integral->getVal() << std::endl;
        //std::cout << integral->getError() << std::endl;
        //Double_t sideband_bg_val = integral->getVal();
        //double sideband_bg_error = integral->getError();
        
        std::stringstream r;
        r << "bdtg3" << " >= " << cut_val << " && Lambda_b0_DTF_MASS_constr1 >= 5650 && Lambda_b0_DTF_MASS_constr1 <= 5700";
        const std::string cut2 = r.str();
        
        double integ = tree->GetEntries(cut2.c_str());
        //double integ = integral->getVal();
        
        double efficiency2 = eff_val/(5./2. + sqrt(integ));
        efficiencies2[i] = efficiency2;
        
        effvals[i]=eff_val;
        
        
        std::cout << "\n" << integ << std::endl;
        std::cout << "\n" << eff_val << std::endl;
        std::cout << "\n" << efficiency2 << std::endl;
        */
        
        //double efficiency2_error = efficiency2*sqrt(pow(eff_error/eff_val,2)+(1/(4*sideband_bg_val))*pow(sideband_bg_error/(5/2+sideband_bg_val),2));
        
        //std::cout << "\n\n" << "BDT cut value = " << cut_val << "\n" ;
        //std::cout << "S = " << sig_val << " +/- " << sig_error << "\n" ;
        //std::cout << "B = " << bg_val << " +/- " << bg_error << "\n" ;
        //std::cout << "S/sqrt(S+B) = " << efficiency << " +/- " << efficiency_error << "\n\n" ;
        
        //ds.plotOn( plot );
        //pdf.plotOn( plot );
        
        //RooPlot* plotPullMass = mass.frame();
        
        //plotPullMass->addPlotable( plot->pullHist() );
        //plotPullMass->SetMinimum();
        //plotPullMass->SetMaximum();
        
        //std::cout << cut_val;
    }
    
    
    TCanvas *c1 = new TCanvas(); 
    
    //double zeros[20];
    //for (i=0, i<20, i++) zeros[i]=0.0;
    
    TGraphErrors* graph = new TGraphErrors(40, bdt_cuts, efficiencies1, 0, efficiencies1_error);
    
    graph->SetTitle("S/sqrt(S+B) vs BDTG3 cut");
    //graph->SetMarkerColor(4);
    //graph->SetMarkerStyle(20);
    //graph->SetMarkerSize(1.0);
    graph->GetXaxis()->SetTitle("BDTG3 cut (>)");
    graph->GetXaxis()->SetRangeUser(-1.0,1.0);
    graph->GetYaxis()->SetTitle("S/sqrt(S+B)");
    //graph->Fit("pol5"); 
    graph->Draw("AP");
    c1->SaveAs("~/cern/plots/bdt_cuts_norm/Lb2JpsipK_2011_2012_BDTG3_cuts_S_sqrtS+B.pdf");
    //return c1;
    
    //std::cout << efficiencies1_error[5] << std::endl;
    
    //gStyle->SetOptFit(1011);
    /*TCanvas *c2 = new TCanvas();
    
    TGraph* graph2 = new TGraph(40, bdt_cuts, efficiencies2);
    
    graph2->SetTitle("eff/[5/2+sqrt(B)] vs BDTG3 cut");
    graph2->SetMarkerColor(4);
    graph2->SetMarkerStyle(20);
    graph2->SetMarkerSize(1.0);
    graph2->GetXaxis()->SetTitle("BDTG3 cut (>)");
    graph2->GetXaxis()->SetRangeUser(-1.0,1.0);
    graph2->GetYaxis()->SetTitle("eff/[5/2+sqrt(B)]");
    //graph2->Fit("pol7"); 
    graph2->Draw("AP");
    c2->SaveAs("~/cern/plots/bdt_cuts_norm/Lb2JpsipK_2011_2012_BDTG3_cuts_Punzi.png");
    //return c2;
    */
    
    
    
    /*
    TCanvas* c = new TCanvas();
    
    TPad* pad1 = new TPad("pad1","pad1", 0, 0.3, 1, 1.0);
    pad1->SetBottomMargin(0.1);
    pad1->SetTopMargin(0.1);
    pad1->Draw();
    c->cd();
    TPad* pad2 = new TPad("pad2","pad2", 0, 0, 1, 0.3);
    pad2->SetBottomMargin(0.1);
    pad2->SetTopMargin(0.0);
    pad2->Draw();
    
    
    //pdf.plotOn( plot, RooFit::Components( DfbPdf ), RooFit::LineColor( kRed ), RooFit::LineStyle(kDashed) );
    //pdf.plotOn( plot, RooFit::Components( promptPdf ), RooFit::LineColor( kBlue ), RooFit::LineStyle(kDotted) );
    //pdf.plotOn( plot, RooFit::Components( bgPdf ), RooFit::LineColor( kOrange ), RooFit::LineStyle(kDashDotted) );
    
    pad1->cd();
    plot->Draw();
    
    pad2->cd();
    plotPullMass->Draw("AP");
    
    c->SaveAs(out_file_mass);
    
    RooStats::SPlot* sData = new RooStats::SPlot("sData","An SPlot",
            ds, &pdf, RooArgList(sigYield, bgYield) );
    
    
    RooDataSet * dataw_z = new RooDataSet(ds.GetName(),ds.GetTitle(),&ds,*(ds.get()),0,"sigYield_sw") ;
    */
    /*   
    TCanvas* d = new TCanvas();
    RooPlot* w_mass_chicp = mass_chicp.frame();
    dataw_z->plotOn(w_mass_chicp, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ;
    w_mass_chicp->Draw();
    d->SaveAs("m_chicp_sweighted.png");
    
    TCanvas* e = new TCanvas();
    RooPlot* w_mass_pK = mass_pK.frame();
    dataw_z->plotOn(w_mass_pK, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ;
    w_mass_pK->Draw();
    e->SaveAs("m_pK_sweighted.png");
    */
    /*
    TCanvas* f = new TCanvas();
    RooPlot* w_mass_Jpsi = mass_Jpsi.frame();
    dataw_z->plotOn(w_mass_Jpsi, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ;
    w_mass_Jpsi->Draw();
    f->SaveAs("m_Jpsi_sweighted.png");
    
    TCanvas* g = new TCanvas();
    RooPlot* w_mass_Chic = mass_Chic.frame();
    dataw_z->plotOn(w_mass_Chic, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ;
    w_mass_Chic->Draw();
    g->SaveAs("m_Chic_sweighted.png");
    */
    
    
}
Пример #30
0
void fitGraphs( const ZGConfig& cfg, const std::vector<float> masses, const std::string& width, const std::string& outdir, TFile* outfile, const std::string& name, const std::string& sel ) {


  std::cout << "+++ STARTING: " << name << std::endl;

  TString name_tstr(name);

  std::string plotdir = outdir + "/plots";
  system( Form("mkdir -p %s", plotdir.c_str() ) );

  TGraphErrors* gr_mean   = new TGraphErrors(0);
  TGraphErrors* gr_sigma  = new TGraphErrors(0);
  TGraphErrors* gr_width  = new TGraphErrors(0);
  TGraphErrors* gr_alpha1 = new TGraphErrors(0);
  TGraphErrors* gr_n1     = new TGraphErrors(0);
  TGraphErrors* gr_alpha2 = new TGraphErrors(0);
  TGraphErrors* gr_n2     = new TGraphErrors(0);

  gr_mean  ->SetName(Form("mean_w%s_%s"  , width.c_str(), name.c_str()));
  gr_sigma ->SetName(Form("sigma_w%s_%s" , width.c_str(), name.c_str()));
  gr_width ->SetName(Form("width_w%s_%s" , width.c_str(), name.c_str()));
  gr_alpha1->SetName(Form("alpha1_w%s_%s", width.c_str(), name.c_str()));
  gr_n1    ->SetName(Form("n1_w%s_%s"    , width.c_str(), name.c_str()));
  gr_alpha2->SetName(Form("alpha2_w%s_%s", width.c_str(), name.c_str()));
  gr_n2    ->SetName(Form("n2_w%s_%s"    , width.c_str(), name.c_str()));




  TFile* file  = TFile::Open( Form("%s/trees.root", cfg.getEventYieldDir().c_str()) );

  outfile->cd();

  int iPoint = 0;

  for( unsigned i=0; i<masses.size(); ++i ) {


    float thisMass = masses[i];
    if( thisMass==1250. && name=="mm" && width=="0p014" ) continue;

    std::cout << "-> Starting mass: " << thisMass << std::endl;

    std::string signalName;
    if( thisMass <= 500. ) {
      signalName = std::string(Form("XZg_Spin0ToZG_ZToLL_W_%s_M_%.0f", width.c_str(), thisMass ));
    } else {
      signalName = std::string(Form("GluGluSpin0ToZG_ZToLL_W%s_M%.0f", width.c_str(), thisMass ));
    }
    TTree* tree0 = (TTree*)file->Get( signalName.c_str() );
    if( tree0 == 0 ) continue;
    TTree* tree;
    if( sel=="" ) {
      tree = tree0;
    } else {
      tree = tree0->CopyTree(sel.c_str());
    }

    float maxMassFact = (thisMass>1000. || width=="5p6" ) ? 1.5 : 1.3;
    RooRealVar x("boss_mass", "boss_mass", thisMass, 0.5*thisMass, maxMassFact*thisMass );

    // Crystal-Ball
    RooRealVar mean( "mean", "mean", thisMass, 0.9*thisMass, 1.1*thisMass );
    float sigmaResolution = ( width=="5p6" ) ? 0.03 : 0.015;
    RooRealVar sigma( "sigma", "sigma", sigmaResolution*thisMass, 0., 0.07*thisMass );
    float alpha1_init = (width=="5p6" && thisMass<1000. ) ? 0.8 : 1.2;
    if( width=="5p6" && thisMass==1500.) alpha1_init=1.4;
    RooRealVar alpha1( "alpha1", "alpha1", alpha1_init, 0., 2.5 );
    RooRealVar n1( "n1", "n1", 3., 0., 5. );
    RooRealVar alpha2( "alpha2", "alpha2", 1.2, 0., 2.5 );
    RooRealVar n2( "n2", "n2", 3.5, 0., 10. );
    RooDoubleCBShape cb( "cb", "cb", x, mean, sigma, alpha1, n1, alpha2, n2 );


    RooDataSet* data = new RooDataSet( "data", "data", RooArgSet(x), RooFit::Import(*tree) );

    cb.fitTo( *data, RooFit::Strategy(2) );

    RooPlot* frame = x.frame();
    data->plotOn(frame);
    cb.plotOn(frame);

    TCanvas* c1 = new TCanvas("c1", "", 600, 600);
    c1->cd();

    frame->Draw();

    c1->SaveAs( Form("%s/fit_%s_m%.0f_w%s.eps", plotdir.c_str(), name.c_str(), thisMass, width.c_str()) );
    c1->SaveAs( Form("%s/fit_%s_m%.0f_w%s.pdf", plotdir.c_str(), name.c_str(), thisMass, width.c_str()) );

    c1->SetLogy();

    c1->SaveAs( Form("%s/fit_%s_m%.0f_w%s_log.eps", plotdir.c_str(), name.c_str(), thisMass, width.c_str()) );
    c1->SaveAs( Form("%s/fit_%s_m%.0f_w%s_log.pdf", plotdir.c_str(), name.c_str(), thisMass, width.c_str()) );

    delete c1;

    gr_mean  ->SetPoint( iPoint, thisMass, mean.getVal() );
    gr_sigma ->SetPoint( iPoint, thisMass, sigma.getVal() );
    gr_width ->SetPoint( iPoint, thisMass, sigma.getVal()/mean.getVal() );
    gr_alpha1->SetPoint( iPoint, thisMass, alpha1.getVal() );
    gr_n1    ->SetPoint( iPoint, thisMass, n1.getVal() );
    gr_alpha2->SetPoint( iPoint, thisMass, alpha2.getVal() );
    gr_n2    ->SetPoint( iPoint, thisMass, n2.getVal() );

    gr_mean  ->SetPointError( iPoint, 0., mean.getError() );
    gr_sigma ->SetPointError( iPoint, 0., sigma.getError() );
    gr_width ->SetPointError( iPoint, 0., sigma.getError()/mean.getVal() ); // random
    gr_alpha1->SetPointError( iPoint, 0., alpha1.getError() );
    gr_n1    ->SetPointError( iPoint, 0., n1.getError() );
    gr_alpha2->SetPointError( iPoint, 0., alpha2.getError() );
    gr_n2    ->SetPointError( iPoint, 0., n2.getError() );
    //gr_width->SetPointError( iPoint, 0., sqrt( sigma.getError()*sigma.getError()/(mean.getVal()*mean.getVal()) + sigma.getVal()*sigma.getVal()*mean.getError()*mean.getError()/(mean.getError()*mean.getError()*mean.getError()*mean.getError()) ) );

    iPoint++;

    delete tree;
    delete data;

  } // for i


  TF1* f1_mean   = fitGraph(plotdir, gr_mean  , "Gaussian Mean [GeV]");
  TF1* f1_sigma  = fitGraph(plotdir, gr_sigma , "Gaussian Sigma [GeV]");
  TF1* f1_width  = fitGraph(plotdir, gr_width , "Gaussian #sigma/#mu");
  TF1* f1_alpha1 = fitGraph(plotdir, gr_alpha1, "CB left #alpha");
  TF1* f1_n1     = fitGraph(plotdir, gr_n1    , "CB left N");
  TF1* f1_alpha2 = fitGraph(plotdir, gr_alpha2, "CB right #alpha");
  TF1* f1_n2     = fitGraph(plotdir, gr_n2    , "CB right N");

  f1_mean  ->Write();
  f1_sigma ->Write();
  f1_width ->Write();
  f1_alpha1->Write();
  f1_n1    ->Write();
  f1_alpha2->Write();
  f1_n2    ->Write();

  gr_mean  ->Write();
  gr_sigma ->Write();
  gr_width ->Write();
  gr_alpha1->Write();
  gr_n1    ->Write();
  gr_alpha2->Write();
  gr_n2    ->Write();

}