Exemple #1
7
int main()
{
  read_pars("input");
  read_ensemble_pars(base_path,T,ibeta,nmass,mass,iml_un,nlights,data_list_file);
  TH=L=T/2;
  
  init_latpars();
  
  int ncombo=nmass*nmass;
  
  //load all the corrs
  double *buf=new double[4*ncombo*T*(njack+1)];
  FILE *fin=open_file(combine("%s/%s",base_path,corr_name).c_str(),"r");
  int stat=fread(buf,sizeof(double),4*ncombo*(njack+1)*T,fin);
  if(stat!=4*ncombo*(njack+1)*T)
    {
      cerr<<"Error loading data!"<<endl;
      exit(1);
    }
  
  jvec M(ncombo,njack);
  jvec Z2(ncombo,njack);
  
  //define minuit staff
  TMinuit minu(2);
  minu.SetPrintLevel(-1);
  minu.SetFCN(chi2);
  corr_fit=new double[TH+1];
  corr_err=new double[TH+1];
  
  //fit each combo
  int ic=0;
  for(int ims=0;ims<nmass;ims++)
    for(int imc=ims;imc<nmass;imc++)
      {
	//take into account corr
	jvec corr1(T,njack),corr2(T,njack),corr;
	int ic1=0+2*(ims+nmass*(0+2*imc));
	int ic2=1+2*(ims+nmass*(1+2*imc));
	cout<<ims<<" "<<imc<<" "<<ic1<<" "<<ic2<<endl;
	corr1.put(buf+ic1*T*(njack+1));
	corr2.put(buf+ic2*T*(njack+1));
	corr=(corr1+corr2)/2;
	cout<<corr1[0]<<" "<<corr2[0]<<endl;
	
	//choose the index of the fitting interval
	if(ims>=nlights) ifit_int=2;
	else
	  if(imc>=nlights) ifit_int=1;
	  else ifit_int=0;
	
	//simmetrize
	corr=corr.simmetrized(parity);
	int ttmin=tmin[ifit_int];
	int ttmax=tmax[ifit_int];
	jvec Mcor=effective_mass(corr),Z2cor(TH+1,njack);
	jack Meff=constant_fit(Mcor,ttmin,ttmax);
	for(int t=0;t<=TH;t++)
	  for(int ijack=0;ijack<=njack;ijack++)
	    Z2cor[t].data[ijack]=corr[t].data[ijack]/fun_fit(1,Meff[ijack],t);
	jack Z2eff=constant_fit(Z2cor,ttmin,ttmax);
	
	if(!isnan(Z2eff[0])) minu.DefineParameter(0,"Z2",Z2eff[0],Z2eff.err(),0,2*Z2eff[0]);
	if(!isnan(Meff[0])) minu.DefineParameter(1,"M",Meff[0],Meff.err(),0,2*Meff[0]);
	for(int t=tmin[ifit_int];t<=tmax[ifit_int];t++) corr_err[t]=corr.data[t].err();
	
	//jacknife analysis
	for(int ijack=0;ijack<njack+1;ijack++)
	  {
	    //copy data so that glob function may access it
	    for(int t=tmin[ifit_int];t<=tmax[ifit_int];t++) corr_fit[t]=corr.data[t].data[ijack];
	  
	    //fit
	    double dum;
	    minu.Migrad();	    
	    minu.GetParameter(0,Z2.data[ic].data[ijack],dum);
	    minu.GetParameter(1,M.data[ic].data[ijack],dum);
	  }
	
	//if((ims==iml_un||ims==nlights-1||ims==nlights||ims==nmass-1)&&
	//(imc==iml_un||imc==nlights-1||imc==nlights||imc==nmass-1))
	  {
	    //plot eff mass
	    {
	      ofstream out(combine("eff_mass_plot_%02d_%02d.xmg",ims,imc).c_str());
	      out<<"@type xydy"<<endl;
	      out<<"@s0 line type 0"<<endl;
	      out<<Mcor<<endl;
	      out<<"&"<<endl;
	      out<<"@type xy"<<endl;
	      double av_mass=M[ic].med();
	      double er_mass=M[ic].err();
	      out<<tmin[ifit_int]<<" "<<av_mass-er_mass<<endl;
	      out<<tmax[ifit_int]<<" "<<av_mass-er_mass<<endl;
	      out<<tmax[ifit_int]<<" "<<av_mass+er_mass<<endl;
	      out<<tmin[ifit_int]<<" "<<av_mass+er_mass<<endl;
	      out<<tmin[ifit_int]<<" "<<av_mass-er_mass<<endl;
	    }
	    //plot fun
	    {
	      ofstream out(combine("fun_plot_%02d_%02d.xmg",ims,imc).c_str());
	      out<<"@type xydy"<<endl;
	      out<<"@s0 line type 0"<<endl;
	      out<<corr<<endl;
	      out<<"&"<<endl;
	      out<<"@type xy"<<endl;
	      for(int t=tmin[ifit_int];t<tmax[ifit_int];t++)
		out<<t<<" "<<fun_fit(Z2[ic][njack],M[ic][njack],t)<<endl;
	    }
	  }
	
	  cout<<mass[ims]<<" "<<mass[imc]<<"  "<<M[ic]<<" "<<Z2[ic]<<" f:"<<sqrt(Z2[ic])/(sinh(M[ic])*M[ic])*(mass[ims]+mass[imc])<<" fV:"<<Za_med[ibeta]*sqrt(Z2[ic])/M[ic]/lat[ibeta].med()<<endl;
	  ic++;
      }
  
  ofstream out("fitted_mass.xmg");
  out<<"@type xydy"<<endl;
  for(int ims=0;ims<nmass;ims++)
    {
      //out<<"s0 line type 0"<<endl;
      for(int imc=0;imc<nmass;imc++) out<<mass[imc]<<" "<<M[icombo(ims,imc,nmass,nlights,0)]<<endl;
      out<<"&"<<endl;
    }

  M.write_to_binfile(out_file);
  Z2.append_to_binfile(out_file);
  
  return 0;
}
Exemple #2
0
INLINE P YgooSmathYPfsinh(P x) {
  INTFLO iz, ix; ix.i = (PINT)x; 
  iz.f = (float)sinh((double)ix.f);
  return (P)iz.i;
}
Exemple #3
0
float
sinhf (float x)
{
  return (float) sinh ((double) x);
}
inline double _sinh(double arg)            { return  sinh(arg); }
Exemple #5
0
void c_qd_sinh(const double *a, double *b) {
  qd_real bb;
  bb = sinh(qd_real(a));
  TO_DOUBLE_PTR(bb, b);
}
double Formulaeditor::factor(qint32& nPosition, QString& strCharacter)
{
    qreal f = 0.0;
    qint32 wI = 0, wL = 0, wBeginn = 0, wError = 0;

    if	(strCharacter == str_char(0)) return 0.0;
    // read digit and save as float in f
    if (((strCharacter >= "0") && (strCharacter <= "9")) || (strCharacter == "."))
    {
        wBeginn = nPosition;

        do
        {
            char_n(nPosition, strCharacter);
        }
        while ((((strCharacter >= "0") && (strCharacter <= "9")) || (strCharacter == ".")));

        if (strCharacter == ".")
        {
            do
            {
                char_n(nPosition, strCharacter);
            }
            while (!(((qint8)strCharacter.at(0).digitValue() >= 0) && ((qint8)strCharacter.at(0).digitValue() <=  9))  || (strCharacter.at(0) == '.'));
        }

        QString g_strF = m_strFunction.mid(wBeginn - 1, nPosition - wBeginn);
        f = g_strF.toFloat();
    }
    else
    {
        QString strCharacterUpper = strCharacter.toUpper();
        if (strCharacter == "(")
        {
            char_n(nPosition, strCharacter);
            f = expression(nPosition, strCharacter);
            if (strCharacter == ")")
                char_n(nPosition, strCharacter);
        }
        else if (strCharacterUpper == "X")
        {
            char_n(nPosition, strCharacter);
            f = m_dFktValue;
        }
        else
        {
            bool gefunden = false;
            qint32 AnzStdFunctions = m_strStandardFunction.length() - 1;
            for (wI = 1; wI <= AnzStdFunctions; wI++)
            {
                wL = m_strStandardFunction.at(wI).length();
                QString strFunktionUpper = m_strFunction.mid(nPosition - 1, wL);
                strFunktionUpper = strFunktionUpper.toUpper();
                QString strDummy(m_strStandardFunction.at(wI));
                strDummy = strDummy.toUpper();
                if (strFunktionUpper == strDummy)
                {
                    gefunden = true;
                    nPosition = nPosition + wL - 1;
                    char_n(nPosition, strCharacter);
                    // ! recursion !!!!!!!!!!!!!!!!!!!!!!
                    f = factor(nPosition, strCharacter);
                    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    if (strFunktionUpper == "ABS")
                        f = fabs(f);
                    else if (strFunktionUpper == "SQRT")
                        if (f >= 0)
                            f = sqrt(f);
                        else
                            wError = -1;
                    else if (strFunktionUpper == "SINH")
                        f = sinh(f);
                    else if (strFunktionUpper == "COSH")
                        f = cosh(f);
                    else if (strFunktionUpper == "TANH")
                        f = tanh(f);
                    else if (strFunktionUpper == "ARCTAN")
                        f = atan(f);
                    else if (strFunktionUpper == "LN")
                    {
                        if (f >= 0)
                            f = log(f);
                        else
                            wError = -1;
                    }
                    else if (strFunktionUpper == "LOG")
                    {
                        if (f >= 0)
                            f = log10(f);
                        else
                            wError = -1;
                    }
                    else if (strFunktionUpper == "EXP")
                    {
                        //if (f <= 41)
                            f = exp(f);
                        //else
                            //wError = -1;
                    }
                    else if (strFunktionUpper == "SIN")
                        f = sin(f);
                    else if (strFunktionUpper == "COS")
                        f = cos(f);
                    else if (strFunktionUpper == "COT")
                        f = cot(f);
                    else if (strFunktionUpper == "TAN")
                    {
                        if (cos(f) != 0)
                            f = tan(f);
                        else
                            wError = -1;
                    }
                    else if (strFunktionUpper == "ARCSIN")
                    {
                        if (fabs(f) < 1)
                            f = asin(f);
                        else
                            wError = -1;
                    }
                    else if (strFunktionUpper == "ARCCOS")
                    {
                        if (fabs(f) <= 1)
                            f = acos(f);
                        else
                            wError = -1;
                    }
                    else if (strFunktionUpper == "SIGN")
                        f = signl(f);                    
                    else if (strFunktionUpper == "RAD")
                        f = RAD(f);
                    else if (strFunktionUpper == "DEG")
                        f = DEG(f);
                    else if (strFunktionUpper == "ARSINH")
                        f = ArSinh(f);                   
                    else if (strFunktionUpper == "ARCOSH")
                    {
                        if (fabs(f) >= 1)
                            f = ArCosh(f);
                        else
                            wError = -1;
                    }
                    else if (strFunktionUpper == "ARTANH")
                    {
                        if (fabs(f) <= 1)
                            f = ArTanh(f);
                        else
                            wError = -1;
                    }
                    break;
                }
            }
            if (!gefunden)
            {
                char_n(nPosition, strCharacter);
                if (strCharacterUpper == "A")
                    f = m_dFunctionConstant[0];
                else if (strCharacterUpper == "B")
                    f = m_dFunctionConstant[1];
                else if (strCharacterUpper == "C")
                    f = m_dFunctionConstant[2];
                else if (strCharacterUpper == "D")
                    f = m_dFunctionConstant[3];
                else if (strCharacterUpper == "E")
                    f = m_dFunctionConstant[4];
                else if (strCharacterUpper == "F")
                    f = m_dFunctionConstant[5];
                else if (strCharacterUpper == "G")
                    f = m_dFunctionConstant[6];
                else if (strCharacterUpper == "H")
                    f = m_dFunctionConstant[7];
            }
        }
    }

    if (wError == -1)           errorText = QString("General Parser Error blocked!");

    return f;
}
Exemple #7
0
static int math_sinh (lua_State *L) {
  lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
  return 1;
}
Exemple #8
0
Fichier : math.c Projet : 217/ruby
static VALUE
math_sinh(VALUE obj, VALUE x)
{
    Need_Float(x);
    return DBL2NUM(sinh(RFLOAT_VALUE(x)));
}
Exemple #9
0
//function to fit
double fun_fit(double Z2,double M,int t)
{
  if(parity==1) return Z2*exp(-M*TH)*cosh(M*(TH-t))/sinh(M);
  else return Z2*exp(-M*TH)*sin(M*(TH-t))/sinh(M);
}
Exemple #10
0
int StringFragmentation::decayStringIntoParticles( TLorentzVector *vArr, double fictionRhoPt )
{
    if ( !fRand )
    {
        printf("StringFragmentation: fRand is not set!!!\n" );
        return 0;
    }
    //    double yStringSize = fabs( fRand->Gaus(1,0.2) ) + fabs( fRand->Gaus(0,fYmax-fYmin) );
    //    double yStringShift = fRand->Gaus(0,fStringShiftSigma);

    //    double yStringSize = fabs( fRand->Gaus(4,0.4) ) + 2*fabs( fRand->Gaus(0,2) );
    //    double yStringSize = fabs( fRand->Gaus(4,0.2) ) + 2*fabs( fRand->Gaus(0,4) );
    //WAS USED FOR PROCEEDING...    double yStringSize = 10;//fRand->Uniform(2,10);
    double yStringSize = fYmax-fYmin;//fRand->Uniform(2,10);
    //    double yStringSize = fabs( fRand->Gaus(fYmax-fYmin,0.2) ) + 2*fabs( fRand->Gaus(0,0.5) );
    //    double yStringSize = fYmax-fYmin;//fabs( fRand->Gaus(3.6,0.2) ) + 2*fabs( fRand->Gaus(0,5) );
    //    double yStringShift = fRand->Uniform(-fStringShiftSigma,fStringShiftSigma) + fRand->Gaus(0,fStringShiftSigma);
    double yStringShift = (fYmax+fYmin)/2;//fRand->Gaus(0,fStringShiftSigma);
    //    double yStringShift = fRand->Gaus(0,2);
    //    double yStringSize = fabs( fRand->Gaus(3.6,0.2) ) + 2*fabs( fRand->Gaus(0,5) );
    //    double yStringSize = fabs( fRand->Gaus(3.6,0.2) ) + 2*fabs( fRand->Gaus(0,5) );
    //        double yStringSize = fabs( fRand->Gaus(3.6,0.2) ) + 2*fabs( fRand->Gaus(0,5) );
    //    double yStringSize = fRand->Uniform(0., fYmax-fYmin);
    //        double yStringSize = fabs( fRand->Gaus(2.,0.001) ) + 2*fabs( fRand->Gaus(0,0.2) );



    //    funcStringDecay->SetParameter( 0, yStringSize );
    //    funcStringDecay->SetParameter( 1, 1 );

    //    cout << nParticlesInString << endl;
    if(0)if ( fRand->Uniform() > 0.25) //ministrings
    {
        //        yStringSize = TMath::Max(4., fabs(fRand->Gaus(0,2)) );
        yStringSize = fabs( fRand->Gaus(2,0.2) ) + 2*fabs( fRand->Gaus(0,1) );
        //        yStringSize = TMath::Max(0.5, fabs(fRand->Gaus(0,1)) );
        //TMath::Max( 0.5, fabs( fRand->Gaus(1.5,0.3) ) + 2*fabs( fRand->Gaus(0,0.2) ) );
    }

    //    int nParticlesInString = 0.72 /*coeffToTuneMult*/ * TMath::Max(1,TMath::Nint( fRand->Gaus(yStringSize,yStringSize/10) )); // /2270*1550;
    //    nParticlesInString *= 1.14; //for energy-dependence! (30.01.2015, tuning basing on STAR)

    int nParticlesInString = TMath::Max(1,TMath::Nint( fRand->Gaus(yStringSize,yStringSize/10) )); // /2270*1550;
    //    nParticlesInString *= 1.25; //arbitrary factor to increase multiplicity
    nParticlesInString *= 1.25*0.7; //arbitrary factor to tune multiplicity IN CASE OF ALL PARTICLES - RHOS

    //nParticlesInString; // to take into account two pions from single rho!!!!!!!
    //    int nParticlesInString = TMath::Max(1,TMath::Nint( fRand->Gaus(yStringSize,yStringSize/5) ));
    //WAS USED FOR PROCEEDING...    int nParticlesInString = TMath::Max(2,TMath::Nint( fRand->Gaus(1.2,0.5) ));

    int nCutPoints = nParticlesInString + 1;
    for ( int iBreak = 0; iBreak < nCutPoints; iBreak++ )
    {
        //        double y = fRand->Uniform( fRand->Gaus(fYmin,0.2)+yStringShift, fRand->Gaus(fYmax,0.2)+yStringShift );
        //        double y = fRand->Uniform( fYmin+yStringShift, fYmax+yStringShift );
        //        double y = funcStringDecay->GetRandom();
        double y = fRand->Uniform( -yStringSize/2 + yStringShift, yStringSize/2+yStringShift );
        //        double y = fRand->Gaus( 0, fRand->Gaus(fYmin,0.2) ) + yStringShift;
        //y += yStringShift; //fRand->Gaus(0,2);
        yBreakPoints[iBreak] = y;
    }

    //sort cut points
    TMath::Sort<double, int>( nCutPoints, yBreakPoints, indecesCutsSorted, kFALSE );

    //fill array with sorted y of the string cuts
    for ( int iBreak = 0; iBreak < nCutPoints; iBreak++ )
        yBreakPointsSorted[iBreak] = yBreakPoints[ indecesCutsSorted[iBreak] ];

    //    double particleMass = mRho;
    //        double particleMass = mPion;
    // possible LOGICAL ERROR HERE!!! (if use the mass in cut point calculations)



    //double factorToPtExp = ( particleMass == mPion ? 2.5 : 1.57 );
    //make pTs at string cuts
    for ( int iBreak = 0; iBreak < nCutPoints; iBreak++ )
    {

        /*
            https://arxiv.org/pdf/1101.2599v1.pdf :

            page 86:
            The transverse dimensions of the tube are of typical hadronic sizes, roughly 1 fm.

            From hadron mass spectroscopy the string constant k, i.e. the amount of energy per unit length, is known to
            be k ≈ 1 GeV/fm ≈ 0.2 GeV2.

            page 87:
            ...The expression “massless” relativistic string is somewhat of a misnomer:
            k effectively corresponds to a “mass density” along the string.

            Typically, a break occurs when the q and the qbar
            ends of a colour singlet system are 1–5 fm apart in the qqbar rest frame,
            but note that the higher-momentum particles at the outskirts of the system are
            appreciably Lorentz contracted.

            At the end of the process, the string has broken by the creation of a set
            of new qiqbari pairs, with i running from 1 to n − 1 for a system that fragments
            into n primary hadrons (i.e. hadrons before secondary decays). Each hadron
            is formed by the quark from one break (or an endpoint) and the antiquark
            from an adjacent break: qqbar1, q1qbar2, q2qbar3, . . . , qn−1qbar.

            page 90:
            The factorization of the transverse-momentum and the mass terms leads
            to a flavour-independent Gaussian spectrum for the q'qbar' pairs.
             Since the
            string is assumed to have no transverse excitations, this p⊥ is locally compensated
            between the quark and the antiquark of the pair, and <pT_q^2> = sigma^2 = κ/π ≈ (250 MeV)2.

             Experimentally a number closer to σ2 ≈ (350 MeV)2 is required,
             which could be explained as the additional effect of soft-gluon
            radiation below the shower cutoff scale. That radiation would have a nonGaussian
            shape but, when combined with the ordinary fragmentation p⊥, the
            overall shape is close to Gaussian, and is parameterized correspondingly in
            the program. Hadrons receive p⊥ contributions from two q'qbar' pairs and have
            <pT_hadron^2> = sigma^2 2σ^2.

            The formula also implies a suppression of heavy quark production,
            u : d : s : c ≈ 1 : 1 : 0.3 : 10−11.

            The simplest scheme for baryon production is that, in addition to quark–
            antiquark pairs, also antidiquark–diquark pairs are occasionally produced in
            the field, in a triplet–antitriplet representation.

             */


        // !!! use some numerical factor to MATCH MEAN PT when later merge two quarks of string fragments
        //        if ( particleMass == mPion )
        //            breakPointPt[iBreak] = fRand->Exp( 0.25 ); //0.3); //funcPt->GetRandom();//fRand->Exp(pTtau);
        //        else //rho
        //        breakPointPt[iBreak] = fRand->Exp( 0.25 ); //0.75 );//fictionRhoPt ); //0.3); //funcPt->GetRandom();//fRand->Exp(pTtau);
        //            breakPointPt[iBreak] = fRand->Exp( 0.25 ); //0.75 );//fictionRhoPt ); //0.3); //funcPt->GetRandom();//fRand->Exp(pTtau);
        // GOOD: breakPointPt[iBreak] = fabs(fRand->Gaus( 0, 0.35 )); //0.75 );//fictionRhoPt ); //0.3); //funcPt->GetRandom();//fRand->Exp(pTtau);
        //        breakPointPt[iBreak] = funcPt->GetRandom( /*fictionRhoPt*/ ); //0.3); //funcPt->GetRandom();//fRand->Exp(pTtau);



        //        const double kPtFor_u_d_quarks = 0.35;

        // ##### July 2016: NEW STRING DECAY INTO QUARKS:
        bool flagFineQuarkConfig = false;

        while ( !flagFineQuarkConfig )
        {
            double probQuarkType = fRand->Uniform( 0, 2.3); // u:d:s = 1:1:0.3 from Generators overview paper
            if ( probQuarkType < 0.01 ) // Sept 2017: ASSUME SOME PROBABILITY TO DECAY INTO C-QUARK!
            {
                breakPointType[iBreak] = 3; // c - quark
                breakPointPt[iBreak] = fabs(fRand->Exp( 0.35 ));

            }
            else if ( probQuarkType < 0.2 )
            {
                breakPointType[iBreak] = 1; // s - quark
//                breakPointPt[iBreak] = fabs(fRand->Gaus( 0, 0.47 )); //0.45 ));
//                breakPointPt[iBreak] = fabs(fRand->Gaus( 0.1, 0.35 )); //0.45 ));
                breakPointPt[iBreak] = fabs(fRand->Exp( 0.35 )); //0.45 ));
            }
            else //if ( probQuarkType < 0.05 )
            {
                double probQuarkDiquark = fRand->Uniform( 0, 1 );
                if ( probQuarkDiquark < 0.04 )
                {
                    breakPointType[iBreak] = 2; // diquark
//                    breakPointPt[iBreak] = fabs(fRand->Gaus( 0, 0.56 )); //0.55 ));
//                    breakPointPt[iBreak] = fabs(fRand->Gaus( 0.3, 0.35 )); //0.55 ));
                    breakPointPt[iBreak] = fabs(fRand->Exp( 0.48 ));
                }
                else
                {
                    breakPointType[iBreak] = 0; // u and d quarks
//                    breakPointPt[iBreak] = fabs(fRand->Gaus( 0, 0.28 ) ); //0.28 ));// 0.35 ));
                    breakPointPt[iBreak] = fabs(fRand->Exp( 0.2 )); //0.45 ));
                }
            }
            if ( iBreak == 0 ) // first break: always allowed
                flagFineQuarkConfig = true;
            else
            {
                if ( breakPointType[iBreak-1] == 2 && breakPointType[iBreak] == 2 ) // NOT ALLOWED CONFIG! ("pentaquark? :) )
                    continue;
                else
                    flagFineQuarkConfig = true;
            }
        }

        //                ...

        //        if ( fictionRhoPt == 0 )
        //            breakPointPt[iBreak] = 0;
        //        else
        //            breakPointPt[iBreak] = fRand->Gaus(fictionRhoPt,0.01); //funcPt->GetRandom();//fRand->Exp(pTtau);

        //        breakPointPt[iBreak] = fRand->Uniform( 0.1, 0.5 );
        breakPointPhi[iBreak] = fRand->Uniform( 0, 2*TMath::Pi() );
    }

    //calc kinematic params of "particles"=string fragments
    for ( int iBreak = 0; iBreak < nParticlesInString; iBreak++ )
    {
        double pT1 = breakPointPt[iBreak];
        double pT2 = breakPointPt[iBreak+1];
        double phi1 = breakPointPhi[iBreak];
        double phi2 = breakPointPhi[iBreak+1];
        phi2 += TMath::Pi();
        FixAngleInTwoPi(phi2);

        double ptX = pT1*cos( phi1 ) + pT2*cos( phi2 );
        double ptY = pT1*sin( phi1 ) + pT2*sin( phi2 );
        double ptParticle = sqrt( ptX*ptX+ptY*ptY );
        //        double ptParticle = fRand->Exp(0.9);
        if ( ptParticle < 0.01 )
            ptParticle = 0.01;


        // FOR TESTS!!!
        if(0)
        {
            if ( fictionRhoPt == 0 )
                ptParticle = 0.01;
            else
                ptParticle = fRand->Exp(fictionRhoPt);
            //            ptParticle = fRand->Gaus(fictionRhoPt,0.01); //funcPt->GetRandom();//fRand->Exp(pTtau);
        }
        // FOR TESTS!!!
        if(0)
            ptParticle = fRand->Exp(0.75);


        // !!! RANDOMIZE PT for generated particles:
        //        fParticles[iBreak].pt  = funcPt->GetRandom();
        //        cout << fParticles[iP].pt << endl;

        double phiVectorSum = asin( ptY/ptParticle );
        if ( ptX < 0 )
            phiVectorSum = TMath::Pi()-phiVectorSum;
        FixAngleInTwoPi(phiVectorSum);
        FixAngleInTwoPi(phiVectorSum);

        //        histPhi->Fill(phiVectorSum);
        //        histPtRho->Fill(ptParticle );
        //        histPtRhoWithWeight->Fill(ptParticle, 1./2/TMath::Pi()/ptParticle );

        double phiParticle = phiVectorSum;
        if(0)
            phiParticle = fRand->Uniform( 0, 2*TMath::Pi() );//phiVectorSum;

        double yParticle = (yBreakPointsSorted[iBreak] + yBreakPointsSorted[iBreak+1])/2;

        if(0)
            yParticle = fRand->Uniform( -yStringSize/2, yStringSize/2 );
        //            yParticle = fRand->Uniform( fYmin+yStringShift, fYmax+yStringShift ); //use it to "shuffle" particles in y!
        //        yParticle += fRand->Gaus(0,1);
        //        yParticle = fRand->Uniform( -yStringSize/2, yStringSize/2 );
        yParticle = fRand->Uniform( -yStringSize/2+yStringShift, yStringSize/2+yStringShift );



        // to get pions = 0.8 when half of them goes from rho decays:
        // probabilities for rho, pions, kaons+protons should be 0.25, 0.5, 0.25
        //        k=1 //ratio of pions from rho-s to pions from string
        //        a=0.8 //ratio of final state pions to all charged
        //        x=(a*k)/(2*k+2-a*k)
        //        y=(a*k)/(2*k+2-a*k)*2/k
        //        z=1-x-y
        //        check: (2*x+y)/(2*x+y+z)

        // TMP: just assign mass for particle. Todo?: separate mechanisms for mesons and proton (?)
        double particleMass = mPion;
        // ##### tune particle ratios!
        if (0) // only rho mesons!!!
        {
            while ( fabs(particleMass-mRho) > mRhoWidth/2 )
                particleMass = fRand->Gaus(mRho,mRhoWidth/2);//( fRand->Uniform(0,1) > 0.5 ? fRand->Gaus(mRho,mRhoWidth/2) : mPion );
        }
        //        else //if (0)
        //        {
        //            double probPID = fRand->Uniform(0,1);
        //            if ( probPID < 0.0 )
        //                particleMass = fRand->Gaus(mRho,mRhoWidth/2);//( fRand->Uniform(0,1) > 0.5 ? fRand->Gaus(mRho,mRhoWidth/2) : mPion );
        //            else if ( probPID < 0.75 )
        //                particleMass = mPion;
        //            else //kaon or proton (13% and 4%)
        //            {
        //                if ( fRand->Uniform(0,1) < 13./(13+4) )
        //                    particleMass = mKaon;
        //                else
        //                    particleMass = mProton;
        //            }
        //        }
        else
        {
            short q1 = breakPointType[iBreak];
            short q2 = breakPointType[iBreak+1];
            if ( q1 == 0 && q2 == 0 ) // u/d quarks => pions
                particleMass = mPion;
            else if ( (q1 == 0 && q2 == 1)
                      || (q1 == 1 && q2 == 0) ) // u/d and s quarks => kaons
                particleMass = mKaon;
            else if ( q1 == 1 && q2 == 1 ) // two s quarks => phi
                particleMass = mPhi;
            else if ( (q1 == 0 && q2 == 2)
                      || (q1 == 2 && q2 == 0) ) // u/d quarks and diquark  => protons/neutrons (!!! also neutrons!)
                particleMass = mProton;
            else if ( (q1 == 1 && q2 == 2)
                      || (q1 == 2 && q2 == 1) ) // s quark and diquark  => Lambda
                particleMass = mLambda;
            else if ( q1 == 3 || q2 == 3 ) // KOSTYL': if at least one of the two string ends is a c-quark
                //(q1 == 0 && q2 == 3)
//                      || (q1 == 3 && q2 == 0) ) // u/d quarks and c quark  => D-meson
                particleMass = mD0;
            else
            {
                cout << "breakPointTypes: impossible configuration! "
                     << q1 << " and " <<  q2 << endl;
                particleMass = mLambda;
            }
        }



        //        cout << particleMass << endl;

        //        ptParticle = fRand->Exp(0.45);

        // prepare lorentz vector
        if (1) //use direct sampling of pt "boltzman" distr
        {
            if ( fabs( particleMass-mPion) < 0.001 )
                ptParticle = funcPtBoltzmanLikePion->GetRandom();
            else if ( fabs( particleMass-mKaon) < 0.001 )
                ptParticle = funcPtBoltzmanLikeKaon->GetRandom();
            else if ( fabs( particleMass-mProton) < 0.001 )
                ptParticle = funcPtBoltzmanLikeProton->GetRandom();
            else if ( fabs( particleMass-mD0) < 0.001 )
                ptParticle = funcPtBoltzmanLikeDmeson->GetRandom();
        }
        if (0)
            phiParticle = fRand->Uniform( 0, TMath::TwoPi() );

        double mT = sqrt( ptParticle*ptParticle + particleMass*particleMass );
        double pX = ptParticle * cos(phiParticle);
        double pY = ptParticle * sin(phiParticle);
        double pZ = mT*sinh(yParticle);
        vArr[iBreak].SetXYZM( pX, pY, pZ, particleMass );

    }

    return nParticlesInString;

}
double HHVM_FUNCTION(sinh, double arg) { return sinh(arg); }
Exemple #12
0
Constante& Rationnel::sinush()const
{
    Reel* res = new Reel(sinh((float)num/den));
    return *res;
}
Exemple #13
0
#include <stdio.h>
#include <math.h>

printf("%f\n", sin(0.12));
printf("%f\n", cos(0.12));
printf("%f\n", tan(0.12));
printf("%f\n", asin(0.12));
printf("%f\n", acos(0.12));
printf("%f\n", atan(0.12));
printf("%f\n", sinh(0.12));
printf("%f\n", cosh(0.12));
printf("%f\n", tanh(0.12));
printf("%f\n", exp(0.12));
printf("%f\n", fabs(-0.12));
printf("%f\n", log(0.12));
printf("%f\n", log10(0.12));
printf("%f\n", pow(0.12, 0.12));
printf("%f\n", sqrt(0.12));
printf("%f\n", round(12.34));
printf("%f\n", ceil(12.34));
printf("%f\n", floor(12.34));

void main() {}
Exemple #14
0
double r_sinh(real *x)
#endif
{
return( sinh(*x) );
}
Exemple #15
0
  //! RHS: x->z  (x'=z).
  inline void operator()(double t,double x[],double z[]) const
  {
    // references to clarify (?) the code:
    const double& nConIntraK =x[0];
    const double& nConIntraNa =x[1];
    const double& nConIntraCa =x[2];
    const double& nConIntraCl =x[3];
    const double& nConIntraglu =x[4];
    const double& aConIntraK =x[5];
    const double& aConIntraNa =x[6];
    const double& aConIntraCa =x[7];
    const double& aConIntraCl =x[8];
    const double& aConIntraglu =x[9];
    const double& ConExtraK =x[10];
    const double& ConExtraNa =x[11];
    const double& ConExtraCa =x[12];
    const double& ConExtraCl =x[13];
    const double& ConExtraglu =x[14];
    const double& nVm =x[15];
    const double& aVm =x[16];
    const double& nPropVol =x[17];
    const double& aPropVol =x[18];
    //------------Compute------------------
    double depol=fdepol(t,x[20]);
    // calcul des potentiels d'équilibre par la loi de Nernst 
  
    double  nEK = (RTF)*log(ConExtraK/nConIntraK);
    //double nECa = ((RT)/(2*F))*log(ConExtraCa/nConIntraCa); 
    double nENa = (RTF)*log(ConExtraNa/nConIntraNa); 
    double nEglu = (-RTF)*log(ConExtraglu/nConIntraglu);
    double nECl = (-RTF)*log(ConExtraCl/nConIntraCl);

    double aEK = (RTF)*log(ConExtraK/aConIntraK);
    //double aECa = ((RT)/(2*F))*log(ConExtraCa/aConIntraCa); 
    double aENa = (RTF)*log(ConExtraNa/aConIntraNa); 
    double aEglu = (-RTF)*log(ConExtraglu/aConIntraglu); 
    double aECl = (-RTF)*log(ConExtraCl/aConIntraCl); 


    //courant du canal potassique KDR
	
    double  nmeqKDR = (0.0047*(nVm - 8)/(1 - exp(-(nVm - 8)/12))) / 
      (0.0047*( nVm - 8)/(1 - exp(-(nVm - 8)/12.0)) + exp(-(nVm + 127)/30.0)); 
    double nheqKDR = 1/(1 + exp((nVm + 25)/4.0)); 
    double nIKDR = 1.e-3 * ngKDR * nmeqKDR*nmeqKDR * nheqKDR *(nVm - nEK); 
         
    double ameqKDR = (0.0047*(aVm - 8)/(1 - exp(-(aVm - 8)/12))) /
      (0.0047*( aVm - 8)/(1 - exp(-(aVm - 8)/12)) + exp(-(aVm + 127)/30)); 
    double aheqKDR = 1/(1 + exp((aVm + 25)/4)); 
    double aIKDR = 1.e-3 * agKDR * ameqKDR* ameqKDR * aheqKDR *(aVm - aEK); 
    //courant du canal potassique BK  
	
    double nmeqBK = 250*nConIntraCa*exp(nVm/24)/(250*nConIntraCa*exp(nVm/24) +
  						 0.1*exp(-nVm/24)); 
    double nIBK = 1.e-3 * ngBK * nmeqBK *(nVm - nEK); 
          
    double ameqBK = 250*aConIntraCa*exp(aVm/24)/(250*aConIntraCa*exp(aVm/24) +
  						 0.1*exp(-aVm/24)); 
    double aIBK = 1.e-3 * agBK * ameqBK * (aVm - aEK);  

    //courant du canal potassiques Kir  
	
    double ameqKir = 1/(2+exp(1.62*(FRT)*(aVm-aEK))); 
    double aIKir =  1.e-3  * agKir * ameqKir * (ConExtraK/(ConExtraK+13))*
      (aVm - aEK);                 

    //courant du canal calcique CaHVA
          
    double nCurlyPhi= FRT*nVm; 
    double nA1 = (nConIntraCa*exp(2*nCurlyPhi)-ConExtraCa) / 
      (exp(2*nCurlyPhi) - 1); 
              
    double  namCaHVA = 8.5/(1 + exp(-(nVm - 8)/12.5)); 
    double  nbmCaHVA = 35/(1 + exp((nVm + 74)/14.5)); 
    double  nmeqCaHVA = namCaHVA/(namCaHVA  + nbmCaHVA) ; 
    double  nahCaHVA =  0.0015/(1 + exp((nVm + 29)/8)); 
    double  nbhCaHVA = 0.0055/(1 + exp(-(nVm + 23)/8)); 
    double  nheqCaHVA = nahCaHVA/(nahCaHVA  + nbhCaHVA) ; 
    double  nICaHVA = 10 * F * npHVA * ngCaHVA * 4 * nCurlyPhi * 
      nmeqCaHVA * nheqCaHVA * nA1 ; 
    //nICaHVA*=bCaHVA;
                   
    double  aCurlyPhi= FRT*aVm; 
    double  aA1 = (aConIntraCa*exp(2*aCurlyPhi)-ConExtraCa) / 
      (exp(2*aCurlyPhi) - 1); 
    
    double  aamCaHVA = 8.5/(1 + exp(-(aVm - 8)/12.5)); 
    double  abmCaHVA = 35/(1 + exp((aVm + 74)/14.5)); 
    double  ameqCaHVA = aamCaHVA/(aamCaHVA  + abmCaHVA) ; 
    double  aahCaHVA =  0.0015/(1 + exp((aVm + 29)/8)); 
    double  abhCaHVA = 0.0055/(1 + exp(-(aVm + 23)/8)); 
    double  aheqCaHVA = aahCaHVA/(aahCaHVA  + abhCaHVA) ; 
    double  aICaHVA = 10 * F * apHVA * agCaHVA * 4 * aCurlyPhi *
      ameqCaHVA * aheqCaHVA * aA1 ; 
    //aICaHVA*=bCaHVA;

  //courant du canal sodique NaP
    double  namNaP =200/(1 + exp(-(nVm - 18)/16)); 
    double  nbmNaP = 25/(1 + exp((nVm + 58)/8)); 
    double  nmeqNaP = namNaP/(namNaP  + nbmNaP) ; 
    double  nINaP = (1.e-3 * ngNaP * nmeqNaP * (nVm - nENa));// *bNap;
          
    double aamNaP =200/(1 + exp(-(aVm - 18)/16)); 
    double abmNaP = 25/(1 + exp((aVm + 58)/8)); 
    double ameqNaP = aamNaP/(aamNaP  + abmNaP) ; 
    double aINaP = (1.e-3 * agNaP * ameqNaP * (aVm - aENa));//*bNap;

    //courants dus au récepteur NMDA et AMPA
	
    double nConGLU=ConExtraglu;
          
    double nA2 = 72*nConGLU/(72*nConGLU + 6.6) ; 
    double nB2 = 1/(1 + 0.028*exp(-0.062*nVm)) ;
          
    double  nCK = ((nConIntraK/ConExtraK)*exp(nCurlyPhi)- 1)/
      (exp(nCurlyPhi)- 1);
    double ngKNMDA = ((nPK*F*F)/(RT))*ConExtraK ; 
    double nIKNMDA = 1.e-3 * ngKNMDA * nA2 * nB2 * nCK * nVm; 
              
    double nCNa = ((nConIntraNa/ConExtraNa)*exp(nCurlyPhi)- 1)/
      (exp(nCurlyPhi)- 1);
    double ngNaNMDA = ((nPK*F*F)/(RT))*ConExtraNa; 
    double nINaNMDA = 1.e-3 * ngNaNMDA * nA2 * nB2 * nCNa * nVm; 
          
    double nCCa = ((nConIntraCa/ConExtraCa)*exp(2*nCurlyPhi)- 1)/
      (exp(2*nCurlyPhi)- 1);
    double ngCaNMDA = ((4*6*nPK*F*F)/(RT))*ConExtraCa; 
    double nICaNMDA = 1.e-3 * ngCaNMDA * nA2 * nB2 * nCCa * nVm; 
    //nIKNMDA*=bNMDA;
    //nINaNMDA*=bNMDA;
    //nICaNMDA*=bNMDA;
     
    double aConGLU=ConExtraglu;
          
    double aA2 = 1100*aConGLU/(1100*aConGLU + 190) ; 
    double aCK = ((aConIntraK/ConExtraK)*exp(aCurlyPhi)- 1)/
      (exp(aCurlyPhi)- 1);

    double agKAMPA = ((aPK*F*F)/(RT))*ConExtraK ; 
    double aIKAMPA = 1.e-3 * agKAMPA * aA2 * aCK * aVm; 
              
    double aCNa = ((aConIntraNa/ConExtraNa)*exp(aCurlyPhi)- 1)/
      (exp(aCurlyPhi)- 1);
    double agNaAMPA = ((aPK*F*F)/(RT))*ConExtraNa; 
    double aINaAMPA = 1.e-3 * agNaAMPA * aA2 * aCNa * aVm; 
    //aIKAMPA*=bAMPA;
    //aINaAMPA*= bAMPA;
    //courants de la pompe Na+/K+  
          
    double nCapitalPhi = FRT*(nVm + 176.5); 
    double nA3 = pow(ConExtraK/(ConExtraK + 3.7),2) ; 
    double nB3 = pow(nConIntraNa/(nConIntraNa + 0.6),3) ; 
    double nC3 = (0.052*sinh(nCapitalPhi))/(0.026*exp(nCapitalPhi) + 
  					  22.5*exp(-nCapitalPhi)); 
    double nIKpompeKNa = -0.01 * nrNaK * depol * nA3 * nB3 * nC3 ; 
          
    //double nINapompeKNa = (3/2)*(-10)^(-2) * nrNaK * depol * nA3 * nB3 * nC3; 
    double nINapompeKNa = (1.5)*0.01 * nrNaK * depol * nA3 * nB3 * nC3;

    double aCapitalPhi = FRT*(aVm + 176.5); 
    double aA3 = pow(ConExtraK/(ConExtraK + 3.7),2) ; 
    double aB3 = pow(aConIntraNa/(aConIntraNa + 0.6),3) ; 
    double aC3 = (0.052*sinh(aCapitalPhi))/(0.026*exp(aCapitalPhi) +
  					    22.5*exp(-aCapitalPhi)); 
    double aIKpompeKNa = -0.01 * arNaK * depol * aA3 * aB3 * aC3 ; 
  
    double aINapompeKNa = (1.5)*0.01  * arNaK * depol * aA3 * aB3 * aC3; 

    //courant de la pompe Ca2+
          
    double nICapompe = depol*ngCapompe*0.01*nConIntraCa/(nConIntraCa+0.0002);
    double aICapompe = depol*agCapompe*0.01*aConIntraCa/(aConIntraCa+0.0002);

    //courant de la pompe Cl-
           
    double nIClpompe=-0.01 * depol *ngClpompe * nConIntraCl/(nConIntraCl+25);
    double aIClpompe=-0.01 * depol *agClpompe * aConIntraCl/(aConIntraCl+25);  


    //courants de l'antiport Na+/Ca2+   
          
    double aa=F/(2*RT);
 
    double nA4 = pow(nConIntraNa,3)*ConExtraCa*exp(aa*nVm)
      - pow(ConExtraNa,3)*nConIntraCa*exp(-aa*nVm); 
    double nB4 = 1 + 0.0001*(pow(ConExtraNa,3)*nConIntraCa 
  			     + pow(nConIntraNa,3)*ConExtraCa); 

    double nICaantiport = -0.01*(nrNaCa/20736.0) * nA4/nB4; 
                
    double nINaantiport = (1.5)* 0.01*(nrNaCa/20736.0) * nA4/nB4; 
          
    double aA4 = pow(aConIntraNa,3)*ConExtraCa*exp(aa*aVm)
      - pow(ConExtraNa,3)*aConIntraCa*exp(-aa*aVm); 
    double aB4 = 1 + 0.0001*(pow(ConExtraNa,3)*aConIntraCa 
  			     + pow(aConIntraNa,3)*ConExtraCa);         
    double aICaantiport = -0.01*  (arNaCa/20736.0) * aA4/aB4; 
                
    double aINaantiport = (1.5)* 0.01*(arNaCa/20736.0) * aA4/aB4;   

    //nICaantiport*=bNaCa;  nINaantiport*=bNaCa;
    //aICaantiport*=bNaCa;  aINaantiport*=bNaCa;
    //courants du transporteur du glutamate
          
    double nEtransp = (RT/F)*log(
  				 pow(ConExtraNa/nConIntraNa,3)*
  				 (nConIntraK/ConExtraK)*
  				 (ConExtraglu/nConIntraglu)
  				 );
 
    //double nIglu = -0.001 * ngtransp * (nVm - nEtransp);
          
    double nINatransporteur = 3*0.001 * ngtransp * (nVm - nEtransp); 
    double nIKtransporteur = -0.001 * ngtransp * (nVm - nEtransp); 
    double nIglutransporteur = -0.001 * ngtransp * (nVm - nEtransp);   
          
          
    double aEtransp = (RT/F)*log(
  				 pow(ConExtraNa/aConIntraNa,3)*
  				 (aConIntraK/ConExtraK)*
  				 (ConExtraglu/aConIntraglu)
  				 );


    //double aIglu = -0.001 * agtransp * (aVm - aEtransp);
          
    double aINatransporteur = 3*0.001 * agtransp * (aVm - aEtransp); 
    double aIKtransporteur = -0.001 * agtransp * (aVm - aEtransp); 
    double aIglutransporteur = -0.001 * agtransp * (aVm - aEtransp); 
 
    // nINatransporteur*=bGLU; nIKtransporteur*=bGLU;
    // nIglutransporteur*=bGLU;aINatransporteur*=bGLU;
    // aIKtransporteur*=bGLU; aIglutransporteur*=bGLU;   
    // courants du transporteur Na/K/Cl
          
    double aEinvNaKCl = -2*aECl + aEK + aENa;

    double aINacotransp = -0.001*arNaKCl * aEinvNaKCl;
         
    double aIKcotransp = -0.001*arNaKCl * aEinvNaKCl;
    
    double aIClcotransp = 2*0.001*arNaKCl * aEinvNaKCl;

    // aINacotransp*=bNaKCl;
    // aIKcotransp*=bNaKCl;
    // aIClcotransp*=bNaKCl;
    //courants de glutamate
          
    double nIgludiff = 0.001 * ngglu * (nVm - nEglu); 
    double aIgludiff = 0.001 * agglu * (aVm - aEglu); 
          
    //courant du canal Cl-
          
    double  nEinvKCl = nECl - nEK;
    double  nIClglob = -0.001 * ngClglob *  nEinvKCl;
    double  nIKglob = 0.001 * ngClglob *  nEinvKCl;
    double aEinvKCl = aECl - aEK;
    double aIClglob = -0.001 * agClglob *  aEinvKCl;
    double aIKglob = 0.001 * agClglob *  aEinvKCl;

    //courants stretch pour le Cl

    double nIstre = - ngstre * 
      (nPropVol0 + 50 * (nPropVol - nPropVol0))/nPropVol0;
          
    double aIstre = - agstre * 
      (aPropVol0 + 50 * (aPropVol - aPropVol0))/aPropVol0;
                   
    // courants Cl
          
    double nICl = 0.001 * ngCl*(nVm-nECl);
    double aICl = 0.001 * agCl*(aVm-aECl); 
           
    //somme des courants

  
    double  nSommeCourantsK = nIKDR + nIBK + nIKNMDA + nIKpompeKNa +
      nIKtransporteur + nIKglob; 
                  
    double  nSommeCourantsCa  = nICaHVA + nICaNMDA + nICaantiport + nICapompe; 
                  
    double nSommeCourantsNa   = nINaP + nINaNMDA + nINapompeKNa + 
      nINaantiport + nINatransporteur ; 
         
    double  nSommeCourantsglu  = nIglutransporteur + nIgludiff ; 
         
    double  nSommeCourantsCl = nICl + nIClglob + nIClpompe + nIstre; 
                 
    // double  nSommeCourantsCat  = nSommeCourantsNa + nSommeCourantsK +
    //   nSommeCourantsCa ;
        
    // double  ncourants  = nSommeCourantsCat + nSommeCourantsCl +
    //   nSommeCourantsglu ;
        
         
    double aSommeCourantsK = aIKDR + aIKir + aIBK + aIKAMPA + aIKpompeKNa +
      aIKtransporteur + aIKcotransp + aIKglob; 
                  
    double aSommeCourantsCa  = aICaHVA + aICaantiport +
      aICapompe; 
                  
    double  aSommeCourantsNa   = aINaP + aINaAMPA + aINapompeKNa +
      aINaantiport + aINatransporteur + aINacotransp ; 
         
    double  aSommeCourantsglu   = aIglutransporteur + aIgludiff ; 
         
    double  aSommeCourantsCl = aICl + aIClglob + aIClpompe + aIClcotransp +
    aIstre;
               
    // double  aSommeCourantsCat  = aSommeCourantsNa + aSommeCourantsK +
    //   aSommeCourantsCa ;
    
  
    // double acourants  = aSommeCourantsCat + aSommeCourantsCl +
    //   aSommeCourantsglu ;
         
    //------ F:------------------------------------------
    double snfv=1000*n1*nsurf/(F*v);

    z[0]=-snfv*nSommeCourantsK;
    z[1]=-snfv*nSommeCourantsNa;
    z[2]=-snfv*nSommeCourantsCa/2.0;
    z[3]= snfv*nSommeCourantsCl;
    z[4]= snfv*nSommeCourantsglu;

    const double safv=1000*n2*asurf/(F*v);
    z[5]=-safv*aSommeCourantsK;
    z[6]=-safv*aSommeCourantsNa;
    z[7]=-safv*aSommeCourantsCa/2.0;
    z[8]= safv*aSommeCourantsCl;
    z[9]=safv*aSommeCourantsglu;

    z[10]=snfv*nSommeCourantsK+safv*aSommeCourantsK;
    z[11]=snfv*nSommeCourantsNa+safv*aSommeCourantsNa;
    z[12]=snfv*nSommeCourantsCa/2.0+safv*aSommeCourantsCa/2.0;
    z[13]=-snfv*nSommeCourantsCl-safv*aSommeCourantsCl;
    z[14]=-snfv*nSommeCourantsglu-safv*aSommeCourantsglu;

    //---Vmn et Vma:

    z[15]=-1000.0*(nsurf/ncap)*(nSommeCourantsNa+nSommeCourantsK+
  				nSommeCourantsCa+
  				nSommeCourantsCl+nSommeCourantsglu);

    z[16]= -1000.0*(asurf/acap)*(aSommeCourantsNa+
  				 aSommeCourantsK+aSommeCourantsCa+
  				 aSommeCourantsCl+aSommeCourantsglu);

  //
    double Cn=nConIntraK+nConIntraNa+nConIntraCa+nConIntraCl+nConIntraglu;
    double Ca=aConIntraK+aConIntraNa+aConIntraCa+aConIntraCl+aConIntraglu;
    double Ce=ConExtraK+ConExtraNa+ConExtraCa+ConExtraCl+ConExtraglu;


    //---fn:
  
    z[17]=alpha_n*(Cn+nnP0/(v*nPropVol)-Ce);
		
		
    //---fa:
    z[18]=alpha_a*(Ca+anP0/(v*aPropVol)-Ce);


    //---transformation pour utiliser les variables "primales":
    for(int i=0;i<5;i++)
      z[i]=(z[i]-x[i]*z[17])/nPropVol;
    for(int i=5;i<10;i++)
      z[i]=(z[i]-x[i]*z[18])/aPropVol;
    for(int i=10;i<15;i++)
      z[i]=(z[i]+x[i]*(z[17]+z[18]))/(1.0-aPropVol-nPropVol);

    //---recuperation:
    recup(x,z[19],z[20]);
  }
Exemple #16
0
void ctss_calculate_biquad_coeff(CTSS_DSPNode *node,
                                 CTSS_BiquadType type,
                                 float freq,
                                 float dbGain,
                                 float bandwidth) {
  CTSS_BiquadState *state = node->state;
  float a0, a1, a2, b0, b1, b2;

  float A     = powf(10.0f, dbGain / 40.0f);
  float omega = HZ_TO_RAD(freq);
  float sn    = sinf(omega);
  float cs    = cosf(omega);
  float alpha = sn * sinh(CT_LN2 / 2.0f * bandwidth * omega / sn);
  float beta  = sqrtf(A + A);

  switch (type) {
    case LPF:
    default:
      b0 = (1.0f - cs) / 2.0f;
      b1 = 1.0f - cs;
      b2 = (1.0f - cs) / 2.0f;
      a0 = 1.0f + alpha;
      a1 = -2.0f * cs;
      a2 = 1.0f - alpha;
      break;
    case HPF:
      b0 = (1.0f + cs) / 2.0f;
      b1 = -(1.0f + cs);
      b2 = (1.0f + cs) / 2.0f;
      a0 = 1.0f + alpha;
      a1 = -2.0f * cs;
      a2 = 1.0f - alpha;
      break;
    case BPF:
      b0 = alpha;
      b1 = 0;
      b2 = -alpha;
      a0 = 1.0f + alpha;
      a1 = -2.0f * cs;
      a2 = 1.0f - alpha;
      break;
    case NOTCH:
      b0 = 1.0f;
      b1 = -2.0f * cs;
      b2 = 1.0f;
      a0 = 1.0f + alpha;
      a1 = -2.0f * cs;
      a2 = 1.0f - alpha;
      break;
    case PEQ:
      b0 = 1.0f + (alpha * A);
      b1 = -2.0f * cs;
      b2 = 1.0f - (alpha * A);
      a0 = 1.0f + (alpha / A);
      a1 = -2.0f * cs;
      a2 = 1.0f - (alpha / A);
      break;
    case LSH:
      b0 = A * ((A + 1.0f) - (A - 1.0f) * cs + beta * sn);
      b1 = 2.0f * A * ((A - 1.0f) - (A + 1.0f) * cs);
      b2 = A * ((A + 1.0f) - (A - 1.0f) * cs - beta * sn);
      a0 = (A + 1.0f) + (A - 1.0f) * cs + beta * sn;
      a1 = -2.0f * ((A - 1.0f) + (A + 1.0f) * cs);
      a2 = (A + 1.0f) + (A - 1.0f) * cs - beta * sn;
      break;
    case HSH:
      b0 = A * ((A + 1.0f) + (A - 1.0f) * cs + beta * sn);
      b1 = -2.0f * A * ((A - 1.0f) + (A + 1.0f) * cs);
      b2 = A * ((A + 1.0f) + (A - 1.0f) * cs - beta * sn);
      a0 = (A + 1.0f) - (A - 1.0f) * cs + beta * sn;
      a1 = 2.0f * ((A - 1.0f) - (A + 1.0f) * cs);
      a2 = (A + 1.0f) - (A - 1.0f) * cs - beta * sn;
      break;
  }

  a0 = 1.0f / a0;

  state->f[0] = b0 * a0;
  state->f[1] = b1 * a0;
  state->f[2] = b2 * a0;
  state->f[3] = a1 * a0;
  state->f[4] = a2 * a0;

  state->f[5] = state->f[6] = state->f[7] = state->f[8] = 0.0f;
}
Exemple #17
0
void MathSinh(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
    ReturnValue->Val->FP = sinh(Param[0]->Val->FP);
}
Exemple #18
0
void bessjy(double  x, double xnu, double *rj, double *ry)
{
    void beschb(double x, double *gam1, double *gam2, double *gampl, double
*gammi);

int i,isign,l,nl;
double a,b,br,bi,c,cr,ci,d,del,del1,den,di,dlr,dli,dr,e,f,fact,fact2,
              fact3,ff,gam,gam1,gam2,gammi,gampl,h,p,pimu,pimu2,q,r,rjl,
              rjl1,rjmu,rjp1,rjpl,rjtemp,ry1,rymu,rymup,rytemp,sum,sum1,
              temp,w,x2,xi,xi2,xmu,xmu2;
if (x <= 0.0 || xnu<0.0) nrerror("bad argumnets in bessjy");
nl=(x < XMIN ? (int)(xnu+0.5) : IMAX(0,(int)(xnu+1.5))); 
xmu=xnu-nl;
xmu2=xmu*xmu;
xi=1.0/x;
xi2=2.0*xi;
w=xi2/M_PI;
isign=1;
h=xnu*xi;
if(h<FPMIN) h=FPMIN;
b=xi2*xnu;
d=0.0;
c=h;
for (i=1;i<=MAXIT;i++)
{
 b+=xi2;
 d=b-d;
 if(fabs(d)< FPMIN) d=FPMIN;
 c=b-1.0/c;
 if(fabs(c)<FPMIN) c=FPMIN;
 d=1.0/d;
 del=c*d;
 h=del*h;
 if(d<0.0)  isign=-isign;
 if(fabs(del-1.0)<EPS) break;
}
if(i>MAXIT) nrerror("x too large in bessjy; try asymptotic expansion");
rjl=isign*FPMIN;
rjpl=h*rjl;
rjl1=rjl;
rjp1=rjpl;
fact=xnu*xi;
for (l=nl;l>=1;l--){
rjtemp=fact*rjl+rjpl;
fact-=xi;
rjpl=fact*rjtemp-rjl;
rjl=rjtemp;
}
if(rjl ==0.0) rjl=EPS;
f=rjpl/rjl;
if (x<XMIN) {
x2=0.5*x;
pimu=M_PI*xmu;
fact=(fabs(pimu)<EPS ? 1.0 : pimu/sin(pimu));
d=-log(x2);
e=xmu*d;
fact2=(fabs(e)< EPS ? 1.0 : sinh(e)/e);
beschb(xmu,&gam1,&gam2,&gampl,&gammi);
ff=2.0/M_PI*fact*(gam1*cosh(e)+gam2*fact2*d);
e=exp(e);
p=e/(gampl*M_PI);
q=1.0/(e*M_PI*gammi);
pimu2=0.5*pimu;
fact3=(fabs(pimu2) <EPS ? 1.0 : sin(pimu2)/pimu2);
r=M_PI*pimu2*fact3*fact3;
c=1.0;
d=-x2*x2;
sum=ff+r*q;
sum1=p;
for (i=1;i<=MAXIT;i++)
{ff=(i*ff+p+q)/(i*i-xmu2);
c *=(d/i);
p/= (i-xmu);
q/=(i+xmu);
del=c*(ff+r*q);
sum+=del;
del1=c*p-i*del;
sum1 +=del1;
if(fabs(del) < (1.0+fabs(sum))*EPS) break;
}
if(i > MAXIT) nrerror("bessy series failed to converge");
rymu=-sum;
ry1=-sum1*xi2;
rymup=xmu*xi*rymu-ry1;
rjmu=w/(rymup-f*rymu);
} else {
a=0.25-xmu2;
p=-0.5*xi;
q=1.0;
br=2.0*x;
bi=2.0;
fact=a*xi/(p*p+q*q);
cr=br+q*fact;
ci=bi+p*fact;
den=br*br+bi*bi;
dr=br/den;
di=-bi/den;
dlr=cr*dr-ci*di;
dli=cr*di+ci*dr;
temp=p*dlr-q*dli;
q=p*dli+q*dlr;
p=temp;
for(i=2;i<=MAXIT;i++)
{a+=2*(i-1);
bi +=2.0;
dr=a*dr+br;
di=a*di+bi;
if (fabs(dr)+fabs(di) < FPMIN) dr=FPMIN;
fact=a/(cr*cr+ci*ci);
cr=br+cr*fact;
ci=bi-ci*fact;
if(fabs(cr)+fabs(ci)<FPMIN) cr=FPMIN;
den=dr*dr+di*di;
dr/=den;
di /=-den;
dlr=cr*dr-ci*di;
dli=cr*di+ci*dr;
temp=p*dlr-q*dli;
q=p*dli+q*dlr;
p=temp;
if (fabs(dlr-1.0)+fabs(dli) < EPS) break;
}
if(i>MAXIT) nrerror("cf2 failed in bessjy");
gam=(p-f)/q;
rjmu=sqrt(w/((p-f)*gam+q));
rjmu=SIGN(rjmu,rjl);
rymu=rjmu*gam;
rymup=rymu*(p+q/gam);
ry1=xmu*xi*rymu-rymup;
}
fact=rjmu/rjl;
*rj=rjl1*fact;
for(i=1;i<=nl;i++)
{rytemp=(xmu+i)*xi2*ry1-rymu;
rymu=ry1;
ry1=rytemp;
}
*ry=rymu;
}
Exemple #19
0
Fichier : math.c Projet : 217/ruby
double
tanh(double x)
{
    return sinh(x) / cosh(x);
}
Exemple #20
0
int decode_function(char *ptr,int argnum,double *argptr,
                    double *value,void *data) {


  int i; 
 
  for (i=0;fnlist[i] !=0;i++) if (strcmp(ptr,fnlist[i])==0) break;

  switch(i) {
    case 0:
      *value=fabs(argptr[0]);
      break;
    case 1: 
      *value=acos(argptr[0]);
      break;
    case 2: 
      *value=acosh(argptr[0]);
      break;
    case 3: 
      *value=asin(argptr[0]);
      break;
    case 4: 
      *value=asinh(argptr[0]);
      break;
    case 5: 
      *value=atan(argptr[0]);
      break;
    case 6: 
      *value=atan2(argptr[0],argptr[1]);
      break;
    case 7: 
      *value=atanh(argptr[0]);
      break;
   case 8: 
      *value=ceil(argptr[0]);
      break;
   case 9: 
      *value=cos(argptr[0]);
      break;
  case 10: 
      *value=cosh(argptr[0]);
      break;
  case 11: 
      *value=exp(argptr[0]);
      break;
  case 12: 
      *value=floor(argptr[0]);
      break;
  case 13: 
      *value=(int) argptr[0];
      break;
  case 14: 
      *value=log(argptr[0]);
      break;
  case 15: 
      *value=log10(argptr[0]);
      break;
  case 16: 
      *value=sin(argptr[0]);
      break;
  case 17: 
      *value=sinh(argptr[0]);
      break;
  case 18: 
      *value=sqrt(argptr[0]);
      break;
  case 19: 
      *value=tan(argptr[0]);
      break;
  case 20: 
      *value=tanh(argptr[0]);
      break;
      
  }
  return 0;
}
void test_extra(T)
{
   T t = 1;
   t = abs(t);
   t = abs(t*t);

   t = fabs(t);
   t = fabs(t*t);

   t = sqrt(t);
   t = sqrt(t*t);

   t = floor(t);
   t = floor(t*t);

   t = ceil(t);
   t = ceil(t*t);

   t = trunc(t);
   t = trunc(t*t);

   t = round(t);
   t = round(t*t);

   t = exp(t);
   t = exp(t*t);

   t = log(t);
   t = log(t*t);

   t = log10(t);
   t = log10(t*t);

   t = cos(t);
   t = cos(t*t);

   t = sin(t);
   t = sin(t*t);

   t = tan(t);
   t = tan(t*t);

   t = asin(t);
   t = asin(t*t);

   t = atan(t);
   t = atan(t*t);

   t = acos(t);
   t = acos(t*t);

   t = cosh(t);
   t = cosh(t*t);

   t = sinh(t);
   t = sinh(t*t);

   t = tanh(t);
   t = tanh(t*t);

   double dval = 2;
   t = pow(t, t);
   t = pow(t, t*t);
   t = pow(t, dval);
   t = pow(t*t, t);
   t = pow(t*t, t*t);
   t = pow(t*t, dval);
   t = pow(dval, t);
   t = pow(dval, t*t);

   t = atan2(t, t);
   t = atan2(t, t*t);
   t = atan2(t, dval);
   t = atan2(t*t, t);
   t = atan2(t*t, t*t);
   t = atan2(t*t, dval);
   t = atan2(dval, t);
   t = atan2(dval, t*t);

   t = fmod(t, t);
   t = fmod(t, t*t);
   t = fmod(t, dval);
   t = fmod(t*t, t);
   t = fmod(t*t, t*t);
   t = fmod(t*t, dval);
   t = fmod(dval, t);
   t = fmod(dval, t*t);

   typedef typename T::backend_type backend_type;
   typedef typename backend_type::exponent_type exp_type;
   exp_type e = 0;
   int i = 0;

   t = ldexp(t, i);
   t = ldexp(t*t, i);
   t = ldexp(t, e);
   t = ldexp(t*t, e);

   t = frexp(t, &i);
   t = frexp(t*t, &i);
   t = frexp(t, &e);
   t = frexp(t*t, &e);
}
Exemple #22
0
npy_double npy_sinh(npy_double x)
{
    return sinh(x);
}
Exemple #23
0
void eval_sinh(Expr *expr)
{
	expr->l->fn(expr->l);
	expr->v.x = sinh(expr->l->v.x);
}
Exemple #24
0
void Parser::optimise_call(ExprNode *node)
{
    DBL result = 0.0;
    bool have_result = true;;

    if(node->op != OP_CALL)
        return;
    if(node->child == NULL)
        return;
    if(node->child->op != OP_CONSTANT)
        return;

    switch(node->call.token)
    {
        case SIN_TOKEN:
            result = sin(node->child->number);
            break;
        case COS_TOKEN:
            result = cos(node->child->number);
            break;
        case TAN_TOKEN:
            result = tan(node->child->number);
            break;
        case ASIN_TOKEN:
            result = asin(node->child->number);
            break;
        case ACOS_TOKEN:
            result = acos(node->child->number);
            break;
        case ATAN_TOKEN:
            result = atan(node->child->number);
            break;
        case SINH_TOKEN:
            result = sinh(node->child->number);
            break;
        case COSH_TOKEN:
            result = cosh(node->child->number);
            break;
        case TANH_TOKEN:
            result = tanh(node->child->number);
            break;
        case ASINH_TOKEN:
            result = asinh(node->child->number);
            break;
        case ACOSH_TOKEN:
            result = acosh(node->child->number);
            break;
        case ATANH_TOKEN:
            result = atanh(node->child->number);
            break;
        case ABS_TOKEN:
            result = fabs(node->child->number);
            break;
        case RADIANS_TOKEN:
            result = node->child->number * M_PI / 180.0;
            break;
        case DEGREES_TOKEN:
            result = node->child->number * 180.0 / M_PI;
            break;
        case FLOOR_TOKEN:
            result = floor(node->child->number);
            break;
        case INT_TOKEN:
            result = (int)(node->child->number);
            break;
        case CEIL_TOKEN:
            result = ceil(node->child->number);
            break;
        case SQRT_TOKEN:
            result = sqrt(node->child->number);
            break;
        case EXP_TOKEN:
            result = exp(node->child->number);
            break;
        case LN_TOKEN:
            if(node->child->number > 0.0)
                result = log(node->child->number);
            else
                Error("Domain error in 'ln'.");
            break;
        case LOG_TOKEN:
            if(node->child->number > 0.0)
                result = log10(node->child->number);
            else
                Error("Domain error in 'log'.");
            break;
        case MIN_TOKEN:
            have_result = false;
            break;
        case MAX_TOKEN:
            have_result = false;
            break;
        case ATAN2_TOKEN:
            have_result = false;
            break;
        case POW_TOKEN:
            have_result = false;
            break;
        case MOD_TOKEN:
            have_result = false;
            break;
        case SELECT_TOKEN:
            have_result = false;
            break;
        case FUNCT_ID_TOKEN:
            have_result = false;
            break;
        case VECTFUNCT_ID_TOKEN:
            have_result = false;
            break;
        default:
            have_result = false;
            break;
    }

    if(have_result == true)
    {
        POV_FREE(node->call.name);
        node->number = result;
        node->op = OP_CONSTANT;
        POV_FREE(node->child);
        node->child = NULL;
    }
}
inline double _d0_cosh(double arg)         { return (sinh(arg)); }
Exemple #26
0
double complex
ccosh(double complex z)
{
	double x, y, h;
	int32_t hx, hy, ix, iy, lx, ly;

	x = creal(z);
	y = cimag(z);

	EXTRACT_WORDS(hx, lx, x);
	EXTRACT_WORDS(hy, ly, y);

	ix = 0x7fffffff & hx;
	iy = 0x7fffffff & hy;

	/* Handle the nearly-non-exceptional cases where x and y are finite. */
	if (ix < 0x7ff00000 && iy < 0x7ff00000) {
		if ((iy | ly) == 0)
			return (cpack(cosh(x), x * y));
		if (ix < 0x40360000)	/* small x: normal case */
			return (cpack(cosh(x) * cos(y), sinh(x) * sin(y)));

		/* |x| >= 22, so cosh(x) ~= exp(|x|) */
		if (ix < 0x40862e42) {
			/* x < 710: exp(|x|) won't overflow */
			h = exp(fabs(x)) * 0.5;
			return (cpack(h * cos(y), copysign(h, x) * sin(y)));
		} else if (ix < 0x4096bbaa) {
			/* x < 1455: scale to avoid overflow */
			z = __ldexp_cexp(cpack(fabs(x), y), -1);
			return (cpack(creal(z), cimag(z) * copysign(1, x)));
		} else {
			/* x >= 1455: the result always overflows */
			h = huge * x;
			return (cpack(h * h * cos(y), h * sin(y)));
		}
	}

	/*
	 * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0.
	 * The sign of 0 in the result is unspecified.  Choice = normally
	 * the same as dNaN.  Raise the invalid floating-point exception.
	 *
	 * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0.
	 * The sign of 0 in the result is unspecified.  Choice = normally
	 * the same as d(NaN).
	 */
	if ((ix | lx) == 0 && iy >= 0x7ff00000)
		return (cpack(y - y, copysign(0, x * (y - y))));

	/*
	 * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0.
	 *
	 * cosh(NaN +- I 0)   = d(NaN) + I sign(d(NaN, +-0))0.
	 * The sign of 0 in the result is unspecified.
	 */
	if ((iy | ly) == 0 && ix >= 0x7ff00000) {
		if (((hx & 0xfffff) | lx) == 0)
			return (cpack(x * x, copysign(0, x) * y));
		return (cpack(x * x, copysign(0, (x + x) * y)));
	}

	/*
	 * cosh(x +- I Inf) = dNaN + I dNaN.
	 * Raise the invalid floating-point exception for finite nonzero x.
	 *
	 * cosh(x + I NaN) = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception for finite
	 * nonzero x.  Choice = don't raise (except for signaling NaNs).
	 */
	if (ix < 0x7ff00000 && iy >= 0x7ff00000)
		return (cpack(y - y, x * (y - y)));

	/*
	 * cosh(+-Inf + I NaN)  = +Inf + I d(NaN).
	 *
	 * cosh(+-Inf +- I Inf) = +Inf + I dNaN.
	 * The sign of Inf in the result is unspecified.  Choice = always +.
	 * Raise the invalid floating-point exception.
	 *
	 * cosh(+-Inf + I y)   = +Inf cos(y) +- I Inf sin(y)
	 */
	if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) {
		if (iy >= 0x7ff00000)
			return (cpack(x * x, x * (y - y)));
		return (cpack((x * x) * cos(y), x * sin(y)));
	}

	/*
	 * cosh(NaN + I NaN)  = d(NaN) + I d(NaN).
	 *
	 * cosh(NaN +- I Inf) = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception.
	 * Choice = raise.
	 *
	 * cosh(NaN + I y)    = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception for finite
	 * nonzero y.  Choice = don't raise (except for signaling NaNs).
	 */
	return (cpack((x * x) * (y - y), (x + x) * (y - y)));
}
Exemple #27
0
double
d_sinh(double *x)
{
	return( sinh(*x) );
}
Exemple #28
0
//------------------------Sampling the transition probability (v(0)=X_t, v(1)=int_0^t X_s ds) 
//-------------------------dX_t = kappa(theta-X_t)dt + sigma sqrt(X_t)dW_t
//-------------------------------------In the case of the troncation serie
static void Sample_C(  PnlVect* v,double t, double kappa, double sigma, double theta ,int generator)
{
  //----------Declaration of variable
  double gamma, lambda;
  double tmp;
  double tmp2;
  int j,pss;
  int order_tr; // Default value is equal to 20
  //----------Initialization of parammter
  tmp=0.;
  j=0;
  gamma = 4.*kappa/(sigma*sigma*(1.-exp(-kappa*t)));
  lambda = pnl_vect_get(v,0)*gamma*exp(-kappa*t);
  order_tr = 20;
  //----------Begin operations
  //----generate vt --> tmp
  pss = pnl_rand_poisson(lambda*0.5,generator);
  
  for(j=1;j<= pss;j++)
    tmp = tmp + pnl_rand_gamma(1.,2., generator);
  
  tmp = tmp +pnl_rand_gamma(2.*kappa*theta/(sigma*sigma),2.,generator);
  tmp = tmp/gamma;
  //----generate the variable Z

  tmp2 =0.;
  j=0;
  pss = pnl_rand_bessel(2.*theta*kappa/(sigma*sigma)-1.,2.*kappa*sqrt(pnl_vect_get(v,0)*tmp)/(sigma*sigma*sinh(kappa*t*0.5)),generator);

  for(j=1;j<=pss;j++)
    {
      tmp2=tmp2+X_3_sample(  order_tr,  t,  kappa,  sigma,  generator);
    }
  //----generate int_0^t vs = X1 +X2 +X3 --> lambda

  lambda=tmp2+X_2_sample(  order_tr,  t,  kappa,  sigma,  theta ,  generator)+X_1_sample(  order_tr,  t,  kappa,  sigma,  pnl_vect_get(v,0),  tmp,  generator);
  
  //----set the new value 
  pnl_vect_set(v,0,tmp);
  pnl_vect_set(v,1,lambda);
}
Exemple #29
0
static double kepler( const double ecc, double mean_anom)
{
   double curr, err, thresh, offset = 0.;
   double delta_curr = 1.;
   bool is_negative = false;
   unsigned n_iter = 0;

   if( !mean_anom)
      return( 0.);

   if( ecc < 1.)
      {
      if( mean_anom < -PI || mean_anom > PI)
         {
         double tmod = fmod( mean_anom, PI * 2.);

         if( tmod > PI)             /* bring mean anom within -pi to +pi */
            tmod -= 2. * PI;
         else if( tmod < -PI)
            tmod += 2. * PI;
         offset = mean_anom - tmod;
         mean_anom = tmod;
         }

      if( ecc < .9)     /* low-eccentricity formula from Meeus,  p. 195 */
         {
         curr = atan2( sin( mean_anom), cos( mean_anom) - ecc);
         do
            {
            err = (curr - ecc * sin( curr) - mean_anom) / (1. - ecc * cos( curr));
            curr -= err;
            }
            while( fabs( err) > THRESH);
         return( curr + offset);
         }
      }


   if( mean_anom < 0.)
      {
      mean_anom = -mean_anom;
      is_negative = true;
      }

   curr = mean_anom;
   thresh = THRESH * fabs( 1. - ecc);
               /* Due to roundoff error,  there's no way we can hope to */
               /* get below a certain minimum threshhold anyway:        */
   if( thresh < MIN_THRESH)
      thresh = MIN_THRESH;
   if( (ecc > .8 && mean_anom < PI / 3.) || ecc > 1.)    /* up to 60 degrees */
      {
      double trial = mean_anom / fabs( 1. - ecc);

      if( trial * trial > 6. * fabs(1. - ecc))   /* cubic term is dominant */
         {
         if( mean_anom < PI)
            trial = CUBE_ROOT( 6. * mean_anom);
         else        /* hyperbolic w/ 5th & higher-order terms predominant */
            trial = asinh( mean_anom / ecc);
         }
      curr = trial;
      if( thresh > THRESH)       /* happens if e > 2. */
         thresh = THRESH;
      }

   if( ecc < 1.)
      while( fabs( delta_curr) > thresh)
         {
         if( n_iter++ > MAX_ITERATIONS)
            err = near_parabolic( curr, ecc) - mean_anom;
         else
            err = curr - ecc * sin( curr) - mean_anom;
         delta_curr = -err / (1. - ecc * cos( curr));
         curr += delta_curr;
         }
   else
      while( fabs( delta_curr) > thresh)
         {
         if( n_iter++ > MAX_ITERATIONS)
            err = -near_parabolic( curr, ecc) - mean_anom;
         else
            err = ecc * sinh( curr) - curr - mean_anom;
         delta_curr = -err / (ecc * cosh( curr) - 1.);
         curr += delta_curr;
         }
   return( is_negative ? offset - curr : offset + curr);
}
Exemple #30
0
void
iterate (control_point *cp,
         int            n,
         int            fuse,
         point         *points)
{
  int    i, j, count_large = 0, count_nan = 0;
  int    xform_distrib[CHOOSE_XFORM_GRAIN];
  double p[3], t, r, dr;
  p[0] = points[0][0];
  p[1] = points[0][1];
  p[2] = points[0][2];

  /*
   * first, set up xform, which is an array that converts a uniform random
   * variable into one with the distribution dictated by the density
   * fields
   */
  dr = 0.0;
  for (i = 0; i < NXFORMS; i++)
    dr += cp->xform[i].density;
  dr = dr / CHOOSE_XFORM_GRAIN;

  j = 0;
  t = cp->xform[0].density;
  r = 0.0;
  for (i = 0; i < CHOOSE_XFORM_GRAIN; i++)
    {
      while (r >= t)
        {
          j++;
          t += cp->xform[j].density;
        }
      xform_distrib[i] = j;
      r += dr;
    }

  for (i = -fuse; i < n; i++)
    {
      /* FIXME: the following is supported only by gcc and c99 */
      int fn = xform_distrib[g_random_int_range (0, CHOOSE_XFORM_GRAIN)];
      double tx, ty, v;

      if (p[0] > 100.0 || p[0] < -100.0 ||
        p[1] > 100.0 || p[1] < -100.0)
      count_large++;
      if (p[0] != p[0])
        count_nan++;

#define coef   cp->xform[fn].c
#define vari   cp->xform[fn].var

      /* first compute the color coord */
      p[2] = (p[2] + cp->xform[fn].color) / 2.0;

      /* then apply the affine part of the function */
      tx = coef[0][0] * p[0] + coef[1][0] * p[1] + coef[2][0];
      ty = coef[0][1] * p[0] + coef[1][1] * p[1] + coef[2][1];

      p[0] = p[1] = 0.0;
      /* then add in proportional amounts of each of the variations */
      v = vari[0];
      if (v > 0.0)
        {
          /* linear */
          double nx, ny;
          nx = tx;
          ny = ty;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[1];
      if (v > 0.0)
        {
          /* sinusoidal */
          double nx, ny;
          nx = sin (tx);
          ny = sin (ty);
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[2];
      if (v > 0.0)
        {
          /* spherical */
          double nx, ny;
          double r2 = tx * tx + ty * ty + 1e-6;
          nx = tx / r2;
          ny = ty / r2;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[3];
      if (v > 0.0)
        {
          /* swirl */
          double r2 = tx * tx + ty * ty;  /* /k here is fun */
          double c1 = sin (r2);
          double c2 = cos (r2);
          double nx = c1 * tx - c2 * ty;
          double ny = c2 * tx + c1 * ty;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[4];
      if (v > 0.0)
        {
          /* horseshoe */
          double a, c1, c2, nx, ny;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            a = atan2(tx, ty);  /* times k here is fun */
          else
            a = 0.0;
          c1 = sin (a);
          c2 = cos (a);
          nx = c1 * tx - c2 * ty;
          ny = c2 * tx + c1 * ty;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[5];
      if (v > 0.0)
        {
          /* polar */
          double nx, ny;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            nx = atan2 (tx, ty) / G_PI;
          else
            nx = 0.0;

          ny = sqrt (tx * tx + ty * ty) - 1.0;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[6];
      if (v > 0.0)
        {
          /* bent */
          double nx, ny;
          nx = tx;
          ny = ty;
          if (nx < 0.0) nx = nx * 2.0;
          if (ny < 0.0) ny = ny / 2.0;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[7];
      if (v > 0.0)
        {
          /* folded handkerchief */
          double theta, r2, nx, ny;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2( tx, ty );
          else
            theta = 0.0;
          r2 = sqrt (tx * tx + ty * ty);
          nx = sin (theta + r2) * r2;
          ny = cos (theta - r2) * r2;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[8];
      if (v > 0.0)
        {
          /* heart */
          double theta, r2, nx, ny;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2( tx, ty );
          else
            theta = 0.0;
          r2 = sqrt (tx * tx + ty * ty);
          theta *= r2;
          nx = sin (theta) * r2;
          ny = cos (theta) * -r2;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[9];
      if (v > 0.0)
        {
          /* disc */
          double theta, r2, nx, ny;
          if ( tx < -EPS || tx > EPS ||
               ty < - EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0.0;
          nx = tx * G_PI;
          ny = ty * G_PI;
          r2 = sqrt (nx * nx * ny * ny);
          p[0] += v * sin(r2) * theta / G_PI;
          p[1] += v * cos(r2) * theta / G_PI;
        }

      v = vari[10];
      if (v > 0.0)
        {
          /* spiral */
          double theta, r2;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2( tx, ty );
          else
            theta = 0.0;
          r2 = sqrt (tx * tx + ty * ty) + 1e-6;
          p[0] += v * (cos (theta) + sin (r2)) / r2;
          p[1] += v * (cos (theta) + cos (r2)) / r2;
        }

      v = vari[11];
      if (v > 0.0)
        {
          /* hyperbolic */
          double theta, r2;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0.0;
          r2 = sqrt (tx * tx + ty * ty) + 1e-6;
          p[0] += v * sin (theta) / r2;
          p[1] += v * cos (theta) * r2;
        }

      v = vari[12];
      if (v > 0.0 )
        {
          double theta, r2;
          /* diamond */
          if ( tx < -EPS || tx > EPS ||
               ty < -EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0.0;
          r2 = sqrt( tx * tx + ty * ty );
          p[0] += v * sin (theta) * cos (r2);
          p[1] += v * cos (theta) * sin (r2);
        }

      v = vari[13];
      if (v > 0.0)
        {
          /* ex */
          double theta, r2, n0, n1, m0, m1;
          if ( tx < -EPS || tx > EPS ||
               ty < -EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0.0;
          r2 = sqrt( tx * tx + ty * ty );
          n0 = sin(theta + r2);
          n1 = cos(theta - r2);
          m0 = n0 * n0 * n0 * r2;
          m1 = n1 * n1 * n1 * r2;
          p[0] += v * (m0 + m1);
          p[1] += v * (m0 - m1);
        }

      v = vari[14];
      if ( v > 0.0)
        {
          double theta, r2, nx, ny;
          /* julia */
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0.0;
          if (flam3_random_bit ())
            theta += G_PI;
          r2 = pow (tx * tx + ty * ty, 0.25);
          nx = r2 * cos (theta);
          ny = r2 * sin (theta);
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[15];
      if (v > 0.0)
        {
          /* waves */
          double dx, dy, nx, ny;
          dx = coef[2][0];
          dy = coef[2][1];
          nx = tx + coef[1][0] * sin (ty / ((dx * dx) + EPS));
          ny = ty + coef[1][1] * sin (tx / ((dy * dy) + EPS));
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[16];
      if (v > 0.0)
        {
          /* fisheye */
          double theta, r2, nx, ny;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0.0;
          r2 = sqrt (tx * tx + ty * ty);
          r2 = 2 * r2 / (r2 + 1);
          nx = r2 * cos (theta);
          ny = r2 * sin (theta);
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[17];
      if (v > 0.0)
        {
          /* popcorn */
          double dx, dy, nx, ny;
          dx = tan (3 * ty);
          dy = tan (3 * tx);
          nx = tx + coef[2][0] * sin (dx);
          ny = ty + coef[2][1] * sin (dy);
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[18];
      if (v > 0.0)
        {
          /* exponential */
          double dx, dy, nx, ny;
          dx = exp (tx - 1.0);
          dy = G_PI * ty;
          nx = cos (dy) * dx;
          ny = sin (dy) * dx;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[19];
      if (v > 0.0)
        {
          /* power */
          double theta, r2, tsin, tcos, nx, ny;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0.0;
          tsin = sin (theta);
          tcos = cos (theta);
          r2 = sqrt (tx * tx + ty * ty);
          r2 = pow (r2, tsin);
          nx = r2 * tcos;;
          ny = r2 * tsin;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[20];
      if (v > 0.0)
        {
          /* cosine */
          double nx, ny;
          nx =  cos (tx * G_PI) * cosh (ty);
          ny = -sin (tx * G_PI) * sinh (ty);
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[21];
      if (v > 0.0)
        {
          /* rings */
          double theta, r2, dx, nx, ny;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0;
          dx = coef[2][0];
          dx = dx * dx + EPS;
          r2 = sqrt (tx * tx + ty * ty);
          r2 = fmod (r2 + dx, 2 * dx) - dx + r2 * (1 - dx);
          nx = cos (theta) * r2;
          ny = sin (theta) * r2;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[22];
      if (v > 0.0)
        {
          /* fan */
          double theta, r2, dx, dy, dx2, nx, ny;
          if (tx < -EPS || tx > EPS ||
              ty < -EPS || ty > EPS)
            theta = atan2 (tx, ty);
          else
            theta = 0.0;
          dx = coef[2][0];
          dy = coef[2][1];
          dx = G_PI * (dx * dx + EPS);
          dx2 = dx / 2;
          r2 = sqrt (tx * tx + ty * ty );
          theta += (fmod (theta + dy, dx) > dx2) ? -dx2: dx2;
          nx = cos (theta) * r2;
          ny = sin (theta) * r2;
          p[0] += v * nx;
          p[1] += v * ny;
        }

      v = vari[23];
      if (v > 0.0)
        {
          /* eyefish */
          double r2;
          r2 = 2.0 * v / (sqrt(tx * tx + ty * ty) + 1.0);
          p[0] += r2 * tx;
          p[1] += r2 * ty;
        }

      v = vari[24];
      if (v > 0.0)
        {
          /* bubble */
          double r2;
          r2 = v / ((tx * tx + ty * ty) / 4 + 1);
          p[0] += r2 * tx;
          p[1] += r2 * ty;
        }

      v = vari[25];
      if (v > 0.0)
        {
          /* cylinder */
          double nx;
          nx = sin (tx);
          p[0] += v * nx;
          p[1] += v * ty;
        }

      v = vari[26];
      if (v > 0.0)
        {
          /* noise */
          double rx, sinr, cosr, nois;
          rx = flam3_random01 () * 2 * G_PI;
          sinr = sin (rx);
          cosr = cos (rx);
          nois = flam3_random01 ();
          p[0] += v * nois * tx * cosr;
          p[1] += v * nois * ty * sinr;
        }

      v = vari[27];
      if (v > 0.0)
        {
          /* blur */
          double rx, sinr, cosr, nois;
          rx = flam3_random01 () * 2 * G_PI;
          sinr = sin (rx);
          cosr = cos (rx);
          nois = flam3_random01 ();
          p[0] += v * nois * cosr;
          p[1] += v * nois * sinr;
        }

      v = vari[28];
      if (v > 0.0)
        {
          /* gaussian */
          double ang, sina, cosa, r2;
          ang = flam3_random01 () * 2 * G_PI;
          sina = sin (ang);
          cosa = cos (ang);
          r2 = v * (flam3_random01 () + flam3_random01 () + flam3_random01 () +
                    flam3_random01 () - 2.0);
          p[0] += r2 * cosa;
          p[1] += r2 * sina;
        }

      /* if fuse over, store it */
      if (i >= 0)
        {
          points[i][0] = p[0];
          points[i][1] = p[1];
          points[i][2] = p[2];
        }
    }
}