コード例 #1
0
ファイル: gspsphere.c プロジェクト: jasminegrosso/zeno
void gspsphere(void)
{
    real gamma0, mcut, r, sig2, eint = 0.0;
    static real *sig2tab = NULL;
    bodyptr bp;

    nbody = getiparam("nbody");
    assert(nbody > 0);
    gamma0 = getdparam("gamma");
    mcut = getdparam("mcut");
    assert(0.0 < mcut && mcut <= 1.0);
    if (sig2tab == NULL)
        sig2tab = calc_sig2_gsp(gsp, ggsp, 0.0);
    if (btab == NULL)
        btab = (bodyptr) allocate(nbody * SizeofBody);
    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
        Mass(bp) = gsp->mtot / nbody;
        r = r_mass_gsp(gsp, xrandom(0.0, mcut * gsp->mtot));
	pickshell(Pos(bp), NDIM, r);
	CLRV(Vel(bp));
	Rho(bp) = rho_gsp(gsp, r);
	sig2 = sig2_gsp(gsp, ggsp, 0.0, sig2tab, r);
        EntFunc(bp) = sig2 / rpow(Rho(bp), gamma0 - 1);
	Uintern(bp) = sig2 / (gamma0 - 1);
	eint += Mass(bp) * Uintern(bp);
    }
    eprintf("[%s: thermal energy = %f]\n", getargv0(), eint);
}
コード例 #2
0
ファイル: kin.c プロジェクト: jorgenem/oslo-method-software
void Absorbator()
{
   int Z=14, A=28, Zi=2, Ai=3;
   long nstep=1000;
   float Ti=45., hmax=19.0;
   char list='n', inbuf[130];
   float Ek, h, I, c, Mir;
   
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   printf(" Give Z for the absorbating medium (%3d): ",Z);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Z);

   printf(" Give A for the absorbating medium (%3d): ",A);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&A);

   printf(" Give Z for the projectile (%3d): ",Zi);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Zi);

   printf(" Give A for the projectile (%3d): ",Ai);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Ai);

   printf(" Give the thickness (micrometer) (%4.1f): ",hmax);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&hmax);

   printf(" Give # integration step (%ld): ",nstep);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%ld",&nstep);

   printf(" Do you want energies for each integration step (y/n) (%c): ",list);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%c",&list);
   list=tolower(list);

   if(Rho(Z)*Mass(Ai)<0.0001) return;
   h   = hmax/(float)nstep*1.e-4;
   I   = 9.1*Z*(1+1.9*pow(Z,(-2./3.)))*1.e-6;
   c   = 0.30707*Rho(Z)*Z/(float)A*Zi*Zi;
   Mir = (Mass(Ai)-Zi*0.000549)*931.5016;

   printf(" Give energy of the projectile (-1 = stop) (%3.1f): ",Ti);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&Ti);

   while (Ti!=-1)
   {
   Ek = Ti;
   Ek = Rk4(Ek, c, Mir, I, h, nstep, list);
   printf("\n The final energy is %7.3f MeV with energy loss of %7.3f MeV",
   Ek, Ti-Ek);
   printf("\n\n Give energy of the projectile (-1 = stop) (%3.1f): ",Ti);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&Ti);
   }
}
コード例 #3
0
ファイル: kin.c プロジェクト: jorgenem/oslo-method-software
void Density()
{
   char inbuf[130];
   int Z = 13;
   
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   printf(" Give atomic mass number Z (%d): ",Z);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Z);

   if(Rho(Z)<0.00001)return;
   printf(" Density is:  %5.2f g/cm**3",Rho(Z));
   return;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: chrisb2244/cfd-solver
int main()
{
    MeshScalingType cnst = MeshScalingType::Constant;

    MeshDimension x(10, 0, 1);
    MeshDimension y(10, 0, 1);
    auto meshPtr = std::make_shared<Mesh<2>>(cnst, x, y);
    const Mesh<2>& mesh = *meshPtr;

    vectorField<2> U(meshPtr, "U");
    scalarField<2> Rho(meshPtr, "Rho");

    Rho.setFixed(1);

    double d = 1.0;
    constexpr double pi = 3.141592653589793238463;
//    for (size_t i=0; i<mesh.xCells(); i++) {
//        for (size_t j=0; j<mesh.yCells(); j++) {
//            double r = std::pow(std::pow(mesh.x(i)+0.25,2) +
//                                std::pow(mesh.y(j),2),0.5);
//            Rho(i,j) = r <= 12.25 ? std::exp((std::pow(r,2)*-1)/d) : 0;
//            U.x(i,j) =  0.01 * pi * mesh.y(j);
//            U.y(i,j) = -0.01 * pi * mesh.x(i);
//        }
//    }

}
コード例 #5
0
void assign_closest_serial(It begin, It end, int K, leveldb::DB* work_db,
                           const std::vector<GDELTMini>& centroids,
                           vuad& totals, vuai& cluster_sizes) {
  GDELTMini current_row;
  for (auto itit = begin; itit != end; ++itit) {
    auto& range = *itit;
    for (range.reset(); range.should_continue(); range.it->Next()) {
      read(range.it->value(), current_row);
      int min = -1;
      double min_dist = std::numeric_limits<double>::infinity();
      for (int i = 0; i < K; ++i) {
        double d = Rho(current_row, centroids[i]);
        if (d < min_dist) {
          min = i;
          min_dist = d;
        }
      }
      CHECK(min >= 0);
      add_atomic_double(totals[min].get(), min_dist);
      auto i = cluster_sizes[min]->fetch_add(1) + 1;
      int prev = get_centroid(work_db, range.it->key(), K);
      set_centroid(work_db, range.it->key(), prev, min, K);
    }
  }
}
コード例 #6
0
ファイル: kin.c プロジェクト: jorgenem/oslo-method-software
 void Meter()
{
   char inbuf[130];
   float tmg = 2.2;
   int Z = 13;
   
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   printf(" Give thickness in mg/cm**2 (%3.1f): ",tmg);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&tmg);

   printf(" Give atomic mass number Z (%d): ",Z);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Z);

   if(Rho(Z)<0.00001)return;
   printf("\n Thickness in micrometer is:  %5.2f",tmg*10./Rho(Z));
   return;
}
コード例 #7
0
ファイル: kin.c プロジェクト: jorgenem/oslo-method-software
void Gram()
{
   char inbuf[130];
   float tmicro = 19.;
   int Z = 13;

   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   printf(" Give thickness in micrometer (%3.1f): ",tmicro);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&tmicro);

   printf(" Give atomic mass number Z (%d): ",Z);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Z);

   if(Rho(Z)<0.00001)return;
   printf(" Thickness in mg/cm**2 is:  %5.2f",tmicro*Rho(Z)/10.);
   return;
}
コード例 #8
0
SimplePropertySet<string, double> propertylist() 
{

	SimplePropertySet<string, double> result;

	result.add (Property<string, double> ("Option Value", Price() ) );
	result.add (Property<string, double> ("Delta",Delta() ) );
	result.add (Property<string, double> ("Gamma",Gamma() ) );
	result.add (Property<string, double> ("Vega",Vega() ) );
	result.add (Property<string, double> ("Vega",Theta() ) );
	result.add (Property<string, double> ("Rho",Rho() ) );
	result.add (Property<string, double> ("Cost of Carry",Coc() ) );										// Cost of carry
	
	cout << "counbt " << result.Count();
	return result;

}
コード例 #9
0
ファイル: RhoToolsTest.C プロジェクト: freekang/rhoframework
void RhoToolsTest(Int_t nTimes=1)
{
#ifdef __CINT__
    gROOT.Macro("$RHO/RhoMacros/LoadLibs.C");
#endif
    
    TRho Rho("RhoTools test");
    //cout << Rho; // Not possible until ROOT uses ANSI streams
    
    TStopwatch timer;					    // Measure the execution time
    timer.Start();
    for (int i=0;i<nTimes;i++) Sputnik revival;
    timer.Stop();
    
    cout<<" ----- Realtime:   "<<timer.RealTime()<<"sec"<<endl;
    cout<<" ----- Cputime:    "<<timer.CpuTime()<<"sec"<<endl;
}
コード例 #10
0
void update_medoids_serial(int idx, std::vector<IterRange>& its,
                           std::vector<IterRange>& jts,
                           std::vector<KV>& thread_best,
                           std::vector<double> thread_best_dist,
                           leveldb::DB* db) {
  auto& i = its[idx];
  auto& j = jts[idx];
  GDELTMini current, other;
  for (i.reset(); i.should_continue(); i.it->Next()) {
    lookup(db, i.it->value(), current);
    double tot = 0;
    for (j.reset(); j.should_continue(); j.it->Next()) {
      lookup(db, j.it->value(), other);
        tot += Rho(current, other);
    }
    if (tot < thread_best_dist[idx]) {
      thread_best_dist[idx] = tot;
      thread_best[idx] = std::make_pair(i.it->value().ToString(), current);
    }
  }
}
コード例 #11
0
Vector<double> graph( string& sensitivity_type,  string& property,
					 Vector<double> parameter_range)
{
		curr = &T;		// Default x axis is time T

		if (property == "r")
			curr = &r;
		if (property == "sig")
			curr = &sig;
		if (property == "K")
			curr = &K;
		if (property == "T")
			curr = &T;
		if (property == "U")
			curr = &U;
		if (property == "b")
			curr = &b;

		// Save the value in the 'current' property 
		double memento = (*curr)();


		Vector<double> result (parameter_range.Size(), parameter_range.MinIndex());

		if (sensitivity_type == "Price")
		{
			for (int i = parameter_range.MinIndex(); i <= parameter_range.MaxIndex(); i++)
			{
				(*curr)(parameter_range[i]);
				result[i] = Price();
			}
		}

	

		if (sensitivity_type == "Delta")
		{
			for (int i = parameter_range.MinIndex(); i <= parameter_range.MaxIndex(); i++)
			{
				(*curr)(parameter_range[i]);
				result[i] = Delta();
			}
		}


		if (sensitivity_type == "Gamma")
		{
			for (int i = parameter_range.MinIndex(); i <= parameter_range.MaxIndex(); i++)
			{
				(*curr)(parameter_range[i]);
				result[i] = Gamma();
			}
		}

		if (sensitivity_type == "Vega")
		{
			for (int i = parameter_range.MinIndex(); i <= parameter_range.MaxIndex(); i++)
			{
				(*curr)(parameter_range[i]);
				result[i] = Vega();
			}
		}

	
		if (sensitivity_type == "Theta")
		{
			for (int i = parameter_range.MinIndex(); i <= parameter_range.MaxIndex(); i++)
			{
				(*curr)(parameter_range[i]);
				result[i] = Theta();
			}
		}

		if (sensitivity_type == "Rho")
		{
			for (int i = parameter_range.MinIndex(); i <= parameter_range.MaxIndex(); i++)
			{
				(*curr)(parameter_range[i]);
				result[i] = Rho();
			}
		}

		if (sensitivity_type == "Coc")
		{
			for (int i = parameter_range.MinIndex(); i <= parameter_range.MaxIndex(); i++)
			{
				(*curr)(parameter_range[i]);
				result[i] = Coc();
			}
		}

		// Now restore the old value of the property
		(*curr)(memento);

		return result;

}
コード例 #12
0
ファイル: snaplist.c プロジェクト: jasminegrosso/zeno
void print_data(bodyptr btab, int nbody, real tnow, string *fields,
		string ifmt, string rfmt)
{
    bodyptr bp;

    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	if (set_member(fields, TimeTag))
	    printf(rfmt, tnow);
	if (set_member(fields, MassTag))
	    printf(rfmt, Mass(bp));
	if (set_member(fields, PosTag)) {
	    printf(rfmt, Pos(bp)[0]);
	    printf(rfmt, Pos(bp)[1]);
	    printf(rfmt, Pos(bp)[2]);
	}
	if (set_member(fields, VelTag)) {
	    printf(rfmt, Vel(bp)[0]);
	    printf(rfmt, Vel(bp)[1]);
	    printf(rfmt, Vel(bp)[2]);
	}
	if (set_member(fields, AccTag)) {
	    printf(rfmt, Acc(bp)[0]);
	    printf(rfmt, Acc(bp)[1]);
	    printf(rfmt, Acc(bp)[2]);
	}
	if (set_member(fields, PhiTag))
	    printf(rfmt, Phi(bp));
	if (set_member(fields, SmoothTag))
	    printf(rfmt, Smooth(bp));
	if (set_member(fields, RhoTag))
	    printf(rfmt, Rho(bp));
	if (set_member(fields, EntFuncTag))
	    printf(rfmt, EntFunc(bp));
	if (set_member(fields, UinternTag))
	    printf(rfmt, Uintern(bp));
	if (set_member(fields, UdotIntTag))
	    printf(rfmt, UdotInt(bp));
        if (set_member(fields, UdotRadTag))
	    printf(rfmt, UdotRad(bp));
        if (set_member(fields, UdotVisTag))
	    printf(rfmt, UdotVis(bp));
	if (set_member(fields, TauTag))
	    printf(rfmt, Tau(bp));
	if (set_member(fields, BirthTag))
	    printf(rfmt, Birth(bp));
	if (set_member(fields, DeathTag))
	    printf(rfmt, Death(bp));
	if (set_member(fields, TypeTag))
	  printf(ifmt, (int) Type(bp));
	if (set_member(fields, KeyTag))
	    printf(ifmt, Key(bp));
	if (set_member(fields, AuxTag))
	    printf(rfmt, Aux(bp));
	if (set_member(fields, AuxVecTag)) {
	    printf(rfmt, AuxVec(bp)[0]);
	    printf(rfmt, AuxVec(bp)[1]);
	    printf(rfmt, AuxVec(bp)[2]);
	}
	printf("\n");
    }
}
コード例 #13
0
ファイル: kin.c プロジェクト: jorgenem/oslo-method-software
void Straggling()
{
   int Z=70, A=173, Zi=2, Ai=3, Zf=2, Af=4, Zr, Ar;
   long nstep =1000;
   float Ti=45., d=2., Q=15., Ex=0., theta=45., thetar;
   float I, c, Mi, Mf, Mr, Mir, Mfr;
   float d1, d2, E1s, E2s, h1, h2, dh1, dh2;
   float Ek1, Ek2, Ekf, dE;
   char inbuf[130];
   
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   printf(" Give Z for the absorbating medium (%3d): ",Z);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Z);

   printf(" Give A for the absorbating medium (%3d): ",A);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&A);

   printf(" Give Z for the projectile (%3d): ",Zi);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Zi);

   printf(" Give A for the projectile (%3d): ",Ai);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Ai);

   printf(" Give Z for the light-product (%3d): ",Zf);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Zf);

   printf(" Give A for the light-product (%3d): ",Af);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%d",&Af);

   printf(" Give energy of the projectile (%3.1f): ",Ti);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&Ti);

   printf(" Give the thickness of target (mg/cm**2) (%3.1f): ",d);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&d);

   printf(" Give Q-value for the reaction (%3.1f): ",Q);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&Q);

   printf(" Give exitation-energy for the nucleus (%3.1f): ",Ex);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&Ex);
   if(Rho(Z)*Mass(Ai)*Mass(Af)<0.0001) return;
   I = 9.1*Z*(1.+1.9*pow(Z,(-2./3.)))*1e-6;
   c  = 0.30707*Rho(Z)*Z/(float)A*Zi*Zi;
   Zr = Z + Zi - Zf;
   Ar = A + Ai - Af;
   Mi = Mass(Ai) - Zi*0.000549;
   Mf = Mass(Af) - Zf*0.000549;
   Mr = Mass(Ar) - Zr*0.000549;
   Mir = Mi*931.5016;
   Mfr = Mf*931.5016;

   printf(" Give angle in degree (-1 = stop) (%3.1f): ",theta);
   fgets_ignore(inbuf,sizeof(inbuf),stdin);
   sscanf(inbuf,"%f",&theta);
   while(theta!=-1)
   {
      thetar = 2*3.14159*theta/360.;
      d1  = d;
      d2  = d/cos(thetar);
      E1s = 18.*Zi*sqrt(d1);
      E2s = 18.*Zf*sqrt(d2);
      h1  = d1/Rho(Z)*1.e-5;
      h2  = d2/Rho(Z)*1.e-5;
      dh1 = h1/(float)nstep*100.;
      dh2 = h2/(float)nstep*100.;

      Ek1 = Ti;
      Ek2 = Ti;
      Ek1 = Rk4(Ek1,c,Mir,I,dh1,nstep,'n');
      Ek1 = Relkin(Mi,Mf,Mr,Ek1,Q,thetar);
      Ek2 = Relkin(Mi,Mf,Mr,Ek2,Q,thetar);
      Ek2 = Rk4(Ek2-Ex,c,Mfr,I,dh2,nstep,'n');
      Ekf = sqrt(.5*((Ek1-Ex)*(Ek1-Ex)+Ek2*Ek2));
      dE  = sqrt(((Ek1-Ex-Ek2)*1000.)*((Ek1-Ex-Ek2)*1000.) + 0.5*(E1s*E1s+E2s*E2s));
      printf("\n The final energy is %6.3f MeV  with FWHM %5.1f keV",Ekf,dE);
      printf(" \n\n Give angle in degree (-1 = stop) (%3.1f): ",theta);
      fgets_ignore(inbuf,sizeof(inbuf),stdin);
      sscanf(inbuf,"%f",&theta);
   }
}
コード例 #14
0
float GLGPUDataset::Rho(int i, int j, int k, int slot) const
{
  int idx[3] = {i, j, k};
  NodeIdType nid = Idx2Nid(idx);
  return Rho(nid, slot);
}
コード例 #15
0
void SpeciesInfo::augmentDensitySpherical(const QuantumNumber& qnum, const diagMatrix& Fq, const matrix& VdagCq)
{	static StopWatch watch("augmentDensitySpherical"); watch.start(); 
	augmentDensity_COMMON_INIT
	int nProj = MnlAll.nRows();
	const GridInfo &gInfo = e->gInfo;
	complex* nAugData = nAug.data();
	
	//Loop over atoms:
	for(unsigned atom=0; atom<atpos.size(); atom++)
	{	//Get projections and calculate density matrix at this atom:
		matrix atomVdagC = VdagCq(atom*nProj,(atom+1)*nProj, 0,VdagCq.nCols());
		matrix RhoAll = atomVdagC * Fq * dagger(atomVdagC); //density matrix in projector basis on this atom
		if(isRelativistic()) RhoAll = fljAll * RhoAll * fljAll; //transformation for relativistic pseudopotential
		std::vector<matrix> Rho(e->eInfo.nDensities); //RhoAll split by spin(-density-matrix) components
		if(e->eInfo.isNoncollinear())
		{	matrix RhoUp = RhoAll(0,2,nProj, 0,2,nProj);
			matrix RhoDn = RhoAll(1,2,nProj, 1,2,nProj);
			if(Rho.size()==1)
				Rho[0] = RhoUp + RhoDn; //unpolarized noncollinear mode
			else
			{	matrix RhoUpDn = RhoAll(0,2,nProj, 1,2,nProj);
				matrix RhoDnUp = RhoAll(1,2,nProj, 0,2,nProj);
				Rho[0] = RhoUp;
				Rho[1] = RhoDn;
				Rho[2] = (RhoUpDn + RhoDnUp) * 0.5; //'real part' of UpDn
				Rho[3] = (RhoUpDn - RhoDnUp) * complex(0,-0.5); //'imaginary part' of UpDn
			}
		}
		else std::swap(Rho[qnum.index()], RhoAll); //in this case each qnum contributes to a specific spin component
		
		//Calculate spherical function contributions from density matrix:
		for(size_t s=0; s<Rho.size(); s++) if(Rho[s])
		{	int atomOffs = Nlm*(atom + s*atpos.size());
			//Triple loop over first projector:
			int i1 = 0;
			for(int l1=0; l1<int(VnlRadial.size()); l1++)
			for(int p1=0; p1<int(VnlRadial[l1].size()); p1++)
			for(int m1=-l1; m1<=l1; m1++)
			{	//Triple loop over second projector:
				int i2 = 0;
				for(int l2=0; l2<int(VnlRadial.size()); l2++)
				for(int p2=0; p2<int(VnlRadial[l2].size()); p2++)
				for(int m2=-l2; m2<=l2; m2++)
				{	if(i2<=i1) //rest handled by i1<->i2 symmetry
					{	std::vector<YlmProdTerm> terms = expandYlmProd(l1,m1, l2,m2);
						double prefac = qnum.weight * ((i1==i2 ? 1 : 2)/gInfo.detR)
									* (Rho[s].data()[Rho[s].index(i2,i1)] * cis(0.5*M_PI*(l2-l1))).real();
						for(const YlmProdTerm& term: terms)
						{	QijIndex qIndex = { l1, p1, l2, p2, term.l };
							auto Qijl = Qradial.find(qIndex);
							if(Qijl==Qradial.end()) continue; //no entry at this l
							nAugData[nAug.index(Qijl->first.index, atomOffs + term.l*(term.l+1) + term.m)] += term.coeff * prefac;
						}
					}
					i2++;
				}
				i1++;
			}
		}
	}
	watch.stop();
}