Beispiel #1
0
double  initQCD(double MZalphaS, double McMc, double MbMb, double MtP)
{ 
  double Mq,Mq_;

  lambda[5]= findLambda(5,MZalphaS, 91.187);

  MtPole=MtP;

  if(MtP< poleQmass(91.187,MZalphaS, 6)) return -1;  
  
  for(Mq=MtP,Mq_=0;fabs(Mq_-Mq)>0.00001*Mq;)
  { double alpha=alpha3(Mq, lambda[5], 5);
    Mq_=Mq; 
    Mq*=MtP/poleQmass(Mq, alpha, 6);
  }

  qMass[6]= Mq;

  lambda[6]= findLambda(6,alpha3(qMass[6],lambda[5], 5),qMass[6]);
  notInitialized=0;
  
  qMass[5]=0; qMass[4]=0;
  if(MbMb<=lambda[5]) { qMin=lambda[5]; return qMin;}
  
  qMass[5]=MbMb;
  MbPole=poleQmass(MbMb, alpha3(MbMb,lambda[5] ,5),5);

  lambda[4]= findLambda(4,alpha3(qMass[5],lambda[5],5),qMass[5]);

  if(McMc<=lambda[4]) {qMin=lambda[4]; return qMin;}
  qMass[4]=McMc;
  lambda[3]=findLambda(3,alpha3(qMass[4],lambda[4],4),qMass[4]);
                       qMin=lambda[3]; return qMin;
  nfMax=6;
}
Beispiel #2
0
static void init_alpha(void)
{
  double lambda,al; 
  int nf=alphaNF;

  if(nf==6) nf--;
  
  lambda=findLambda(nf,alphaOrder,alphaMZ,91.187);

  if(alphaNF>6) alphaNF=6; if(alphaNF<3) alphaNF=3;
  if(alphaOrder>3)alphaOrder=3; if(alphaOrder<1)alphaOrder=1;

  nf5=nf; L5=lambda;
  if(nf5==5) 
  {  if(MbMb<1.5*L5) {L4=L5;nf4=nf5;} else 
     { al=alpha(5,alphaOrder,L5,MbMb  );
       if(alphaOrder==3) al*=(1.+(11./72.)*pow(al/M_PI,2.));
       L4=findLambda(4,alphaOrder,al,MbMb);nf4=4; ;
     }
  } else {nf4=nf;L4=lambda;}
  if(nf4==4) 
  { if(MCHARM<1.5*L4) {L3=L4;nf3=nf4;} else
    { al=alpha(4,alphaOrder,L4,MCHARM);
      if(alphaOrder==3) al*=(1.+(11./72.)*pow(al/M_PI,2.));
      L3=findLambda(3,alphaOrder,al,MCHARM);nf3=3;
    }
  } else {nf3=nf; L3=lambda;}

  if(alphaNF==6)
  {  nf6=6;
     al=alpha(5,alphaOrder,L5,Mtp);
     if(alphaOrder==3) al*=(1.-(11./72.)*pow(al/M_PI,2.));
     L6=findLambda(6,alphaOrder,al,Mtp);
  }
  else {nf6=nf5; L6=L5;}
}
Beispiel #3
0
int writeAlpha(FILE*f,int nf,int ordr,double lambda,int nfMx,
               double Mc,double Mb,double Mt,int N, double *q)
{
    int    nf3,nf4,nf5,nf6;
    double  L3, L4, L5, L6;
    double al;
    int i,j;

    nf5=nf;
    L5=lambda;
    if(nf5==5)
    {   nf4=4;
        al=alpha(5, ordr,L5, Mb );
        if(ordr==3) al*=(1.+(11./72.)*pow(al/M_PI,2.));
        L4=findLambda(4,ordr, al ,Mb);
    }
    else {
        nf4=nf5;
        L4=lambda;
    }
    if(nf4==4)
    {   nf3=3;
        al=alpha(4, ordr,L4, Mc );
        if(ordr==3) al*=(1.+(11./72.)*pow(al/M_PI,2.));
        L3=findLambda(3,ordr,al ,Mc);
    }
    else {
        nf3=nf4;
        L3=lambda;
    }

    if(nfMx>=6)
    {   nf6=6;
        al=alpha(5, ordr,L5, Mt);
        if(ordr==3) al*=(1.-(11./72.)*pow(al/M_PI,2.));
        L6=findLambda(6,ordr, al ,Mt);
    }
    else {
        nf6=nf;
        L6=lambda;
    }


    fprintf(stderr,"L3=%f L4=%f L5=%f L6=%f\n",L3,L4,L5,L6);

    fprintf(f,"\n#Alpha\n");
    for(i=0,j=1; i<N; i++,j++)
    {   double al;
        double Q=q[i];
        if(Q<1.4)  al=alpha(nf3, ordr, L3, Q);
        else  if(Q<4.5)  al=alpha(nf4, ordr, L4, Q);
        else  if(Q<175.) al=alpha(nf5, ordr, L5, Q);
        else             al=alpha(nf6, ordr, L6, Q);
        fprintf(f," %.5E",al);
        if(j==10) {
            fprintf(f,"\n");
            j=0;
        }
    }
    fprintf(f,"\n");
}
Beispiel #4
0
/*****************************************************************
* Create the amorphous part of the model
****************************************************************/
void makeAmorphous() {
	int g,p,iatom,ix,iy,iz,ic,atomCount = 0,amorphSites,amorphAtoms;
	static double *axCell,*byCell,*czCell=NULL;
	static double **Mm = NULL;
	double rCellx,rCelly,rCellz;
	double d,r;
	atom *amorphCell;
	// atom newAtom;
	// double xpos,ypos,zpos;
	int nx,ny,nz;
	int *randArray,randCount;


	if (Mm == NULL) {
		Mm = double2D(3,3,"Mm");
		axCell=Mm[0]; byCell=Mm[1]; czCell=Mm[2];
	}

	for (g=0;g<nGrains;g++) {
		/********************************************************
		* if this grain is an amorphous one ... 
		*/
		if (grains[g].amorphFlag == AMORPHOUS) {
			r = grains[g].rmin/grains[g].rFactor;
			/* create an hexagonally closed packed unit cell for initial amorphous structure 
			* The length of each vector is now 1 
			*/
			axCell[0] = r;     axCell[1] = 0;               axCell[2] = 0;
			byCell[0] = 0.5*r; byCell[1] = 0.5*sqrt(3.0)*r; byCell[2] = 0;
			czCell[0] = 0.5*r; czCell[1] = 0.5/sqrt(3.0)*r; czCell[2] = sqrt(5.0)/6*r;      
			/* size of rectangular cell containing 4 atoms: */
			rCellx = r; rCelly = sqrt(3.0)*r; rCellz = (sqrt(5.0)*r)/3.0;

			/* determine number of unit cells in super cell */
			nx = (int)(superCell.ax/rCellx);
			ny = (int)(superCell.by/rCelly);
			nz = (int)(superCell.cz/rCellz);
			amorphSites = 4*nx*ny*nz;
			amorphCell = (atom *)malloc((amorphSites+1)*sizeof(atom));

			atomCount = 0;
			for (ix=0;ix<=nx;ix++) {
				for (iy=0;iy<=ny;iy++) {
					for (iz=0;iz<=nz;iz++) {
						for (ic=0;ic<4;ic++) {
							/* check if this atom and any of the 4 atoms per rect. unit cell lie within the super cell 
							*/
							amorphCell[atomCount].x  = ix*rCellx-(ic==3)*axCell[0]+(ic % 2)*byCell[0]+(ic>1)*czCell[0]; 
							amorphCell[atomCount].y  = iy*rCelly-(ic==3)*axCell[1]+(ic % 2)*byCell[1]+(ic>1)*czCell[1]; 
							amorphCell[atomCount].z  = iz*rCellz-(ic==3)*axCell[2]+(ic % 2)*byCell[2]+(ic>1)*czCell[2]; 
							if ((amorphCell[atomCount].x >= 0) && 
								(amorphCell[atomCount].x < superCell.ax) &&
								(amorphCell[atomCount].y >= 0) && 
								(amorphCell[atomCount].y < superCell.by) &&
								(amorphCell[atomCount].z >= 0) && 
								(amorphCell[atomCount].z < superCell.cz)) {
									for (p=0;p<grains[g].nplanes;p++) {
										d = findLambda(grains[g].planes+p,&(amorphCell[atomCount].z),-1);
										if (d < 0)
											break;
									}
									/* if all the previous test have been successful, this atom is IN */
									if (p == grains[g].nplanes) atomCount++;
							}
						} /* ic ... */
					} /* iz ... */
				} /* iy ... */
			} /* ix ... */
			amorphSites = atomCount;
			/****************************************************************************************
			* Now we have all the sites within the bounding planes on which we can put atoms
			*/
			/* the true number of amorphous atoms is # of sites / rFactor^3 */
			amorphAtoms = (int)floor((double)amorphSites/pow(grains[g].rFactor,3.0));
			if (amorphAtoms > amorphSites) amorphAtoms = amorphSites;
			randCount = amorphSites;
			atomCount = superCell.natoms;


			superCell.atoms = (atom *)realloc(superCell.atoms,(atomCount+amorphAtoms+1)*sizeof(atom));
			if (superCell.atoms == NULL) {
				printf("makeAmorphous: Could not allocate memory for additional atoms!\n");
				exit(0);
			}

			randArray = (int *)malloc(amorphSites*sizeof(int));
			for (ix=0;ix<amorphSites;ix++) randArray[ix] = ix;
			/*
			printf("memory allocation: sC.atoms: %d .. %d, rArray: %d .. %d\n",
			(int)superCell.atoms,(int)superCell.atoms+(atomCount+amorphAtoms+1)*sizeof(atom),
			(int)randArray,(int)randArray+amorphSites*sizeof(int));
			*/

			for (ix=amorphAtoms;ix>0;ix--) {
				do {
					iy = (int)((double)rand()*(double)(randCount-1)/(double)(RAND_MAX));
					if (iy >= randCount) iy = randCount-1;
					if (iy < 0) iy = 0;
					//	printf("%5d, iy: %d, sites: %d, atoms: %d  ",ix,iy,randCount,amorphAtoms);
					iz = randArray[iy];
					if (iz > amorphSites) {
						printf("%5d, iy: %d, sites: %d, atoms: %d  ",ix,iy,randCount,amorphAtoms);
						printf("iz: %d (%d)\n",iz,(int)superCell.atoms[atomCount].z);
						printf("makeAmorphous: Error because of overlapping memory areas!\n");
						for (iz=0;iz<=amorphAtoms;iz++)
							printf("iz=%d: %d\n",iz,randArray[iz]);
						exit(0);
					}
				} while (iz > amorphSites);

				/* replace already choosen sites with unused ones, so that we don't occupy
				* any site twice 
				*/
				if (iy == randCount-1)  randCount--;	
				else 
					randArray[iy] = randArray[--randCount];


				iatom = ix % grains[g].natoms;
				superCell.atoms[atomCount].q = grains[g].unitCell[iatom].q;
				superCell.atoms[atomCount].dw = grains[g].unitCell[iatom].dw;
				superCell.atoms[atomCount].occ = grains[g].unitCell[iatom].occ;
				superCell.atoms[atomCount].Znum = grains[g].unitCell[iatom].Znum;
				superCell.atoms[atomCount].x = amorphCell[iz].x;
				superCell.atoms[atomCount].y = amorphCell[iz].y;
				superCell.atoms[atomCount].z = amorphCell[iz].z;
				atomCount++;
			} 
			superCell.natoms = atomCount;
			free(randArray);
			free(amorphCell);
		} /* end of if amorph,i.e. crystalline */
	} /* g=0..nGrains .. */

}
Beispiel #5
0
/********************************************************************
* This function adds only the crystalline atoms to the superCell
* the amorphous ones are handled by makeAmorphous,  and makeSpecial
********************************************************************/
void makeSuperCell() {
	int g,p,iatom,ix,iy,iz,atomCount = 0;
	// atom *atomPtr;
	// atomPtr = (atom *)malloc(sizeof(atom));
	static double *axCell,*byCell,*czCell=NULL;
	static double **Mm = NULL, **Mminv = NULL, **Mrot = NULL,**Mr=NULL,**Mr2=NULL;
	static double **a = NULL,**b= NULL;
	double maxLength,dx,dy,dz,d,dxs,dys,dzs;
	atom newAtom;
	// double xpos,ypos,zpos;
	int nxmin,nxmax,nymin,nymax,nzmin,nzmax;

	/* claculate maximum length in supercell box, which is naturally 
	* the room diagonal:
	*/
	maxLength = vectLength(&(superCell.ax));
	/*	 maxLength = sqrt(superCell.ax*superCell.ax+
	superCell.by*superCell.by+
	superCell.cz*superCell.cz);
	*/

	if (Mm == NULL) {
		Mm = double2D(3,3,"Mm");
		Mminv = double2D(3,3,"Mminv");
		Mrot = double2D(3,3,"Mrot");
		Mr	 = double2D(3,3,"Mr");
		Mr2   = double2D(3,3,"Mr");
		axCell=Mm[0]; byCell=Mm[1]; czCell=Mm[2];
		a = double2D(1,3,"a");
		b = double2D(1,3,"b");
	}

	atomCount = superCell.natoms;
	for (g=0;g<nGrains;g++) {
		/********************************************************
		* if this grain is a crystalline one ... 
		*/
		if (grains[g].amorphFlag == 0) {
			dx = grains[g].shiftx/superCell.ax; 
			dy = grains[g].shifty/superCell.by; 
			dz = grains[g].shiftz/superCell.cz;
			/* find the rotated unit cell vectors .. */
			makeCellVect(grains+g, axCell, byCell, czCell);
			// showMatrix(Mm,3,3,"M");
			///////////////////////////////////////////////////////////////////

			memset(Mrot[0],0,3*3*sizeof(double));
			Mrot[0][0] = 1.0; Mrot[1][1] = 1.0; Mrot[2][2] = 1.0; 
			memcpy(Mr2[0],Mrot[0],3*3*sizeof(double));


			memset(Mr[0],0,3*3*sizeof(double));
			Mr[0][0] = 1.0; Mr[1][1] = cos(grains[g].tiltx); Mr[1][2] = sin(grains[g].tiltx); 
			Mr[2][1] = -sin(grains[g].tiltx); Mr[2][2] = cos(grains[g].tiltx);
			matrixProduct(Mrot,3,3,Mr,3,3,Mr2);
			memcpy(Mrot[0],Mr2[0],3*3*sizeof(double));
			// showMatrix(Mrot,3,3,"Mrotx");

			memset(Mr[0],0,3*3*sizeof(double));
			Mr[1][1] = 1.0; Mr[0][0] = cos(grains[g].tilty); Mr[0][2] = -sin(grains[g].tilty); 
			Mr[2][0] = sin(grains[g].tilty); Mr[2][2] = cos(grains[g].tilty);
			matrixProduct(Mrot,3,3,Mr,3,3,Mr2);
			memcpy(Mrot[0],Mr2[0],3*3*sizeof(double));
			// showMatrix(Mrot,3,3,"Mrotxy");

			memset(Mr[0],0,3*3*sizeof(double));
			Mr[2][2] = 1.0; Mr[0][0] = cos(grains[g].tiltz); Mr[0][1] = sin(grains[g].tiltz); 
			Mr[1][0] = -sin(grains[g].tiltz); Mr[1][1] = cos(grains[g].tiltz);
			matrixProduct(Mrot,3,3,Mr,3,3,Mr2);
			memcpy(Mrot[0],Mr2[0],3*3*sizeof(double));		
			// showMatrix(Mrot,3,3,"Mrotxyz");

			///////////////////////////////////////////////////////////////////
			/*
			rotateVect(axCell,axCell,grains[g].tiltx,grains[g].tilty,grains[g].tiltz);
			rotateVect(byCell,byCell,grains[g].tiltx,grains[g].tilty,grains[g].tiltz);
			rotateVect(czCell,czCell,grains[g].tiltx,grains[g].tilty,grains[g].tiltz);
			*/
			inverse_3x3(Mminv[0],Mm[0]);
			matrixProduct(Mm,3,3,Mrot,3,3,Mr2);
			memcpy(Mm[0],Mr2[0],3*3*sizeof(double));
			// showMatrix(Mm,3,3,"M");
			inverse_3x3(Mr2[0],Mm[0]);

			/* find out how far we will have to go in units of unit cell vectors.
			* when creating the supercell by checking the number of unit cell vectors 
			* necessary to reach every corner of the supercell box.
			*/
			memset(a[0],0,3*sizeof(double));
			matrixProduct(a,1,3,Mr2,3,3,b);
			// showMatrix(Mm,3,3,"M");
			// showMatrix(Mminv,3,3,"M");
			nxmin = nxmax = (int)floor(b[0][0]-dx); 
			nymin = nymax = (int)floor(b[0][1]-dy); 
			nzmin = nzmax = (int)floor(b[0][2]-dz);
			for (ix=0;ix<=1;ix++) for (iy=0;iy<=1;iy++) for (iz=0;iz<=1;iz++) {
				a[0][0]=ix*superCell.ax; a[0][1]=iy*superCell.by; a[0][2]=iz*superCell.cz;

				matrixProduct(a,1,3,Mr2,3,3,b);
				// showMatrix(b,1,3,"b");
				if (nxmin > (int)floor(b[0][0]-dx)) nxmin=(int)floor(b[0][0]-dx);
				if (nxmax < (int)ceil( b[0][0]-dx)) nxmax=(int)ceil( b[0][0]-dx);
				if (nymin > (int)floor(b[0][1]-dy)) nymin=(int)floor(b[0][1]-dy);
				if (nymax < (int)ceil( b[0][1]-dy)) nymax=(int)ceil( b[0][1]-dy);
				if (nzmin > (int)floor(b[0][2]-dz)) nzmin=(int)floor(b[0][2]-dz);
				if (nzmax < (int)ceil( b[0][2]-dz)) nzmax=(int)ceil( b[0][2]-dz);	  
			}
			// nxmin--;nxmax++;nymin--;nymax++;nzmin--;nzmax++;
			superCell.atoms = (atom *)realloc(superCell.atoms,(superCell.natoms+1+
				(nxmax-nxmin)*(nymax-nymin)*
				(nzmax-nzmin)*grains[g].natoms)*
				sizeof(atom));
			// showMatrix(Mm,3,3,"Mm");
			// showMatrix(Mminv,3,3,"Mminv");
			printf("Grain %d: range: (%d..%d, %d..%d, %d..%d)\n",
				g,nxmin,nxmax,nymin,nymax,nzmin,nzmax);

			dx = grains[g].shiftx; 
			dy = grains[g].shifty; 
			dz = grains[g].shiftz;
			for (iatom=0;iatom<grains[g].natoms;iatom++) {
				memcpy(&newAtom,&(grains[g].unitCell[iatom]),sizeof(atom));
				// We need to convert the cartesian coordinates of this atom
				// to fractional ones:
				b[0][0] = newAtom.x;
				b[0][1] = newAtom.y;
				b[0][2] = newAtom.z;
				matrixProduct(b,1,3,Mminv,3,3,a);
				newAtom.x = a[0][0]; newAtom.y = a[0][1]; newAtom.z = a[0][2];
				//printf("%2d: %d (%g,%g,%g) (%g,%g,%g)\n",iatom,newAtom.Znum,
				//		 b[0][0],b[0][1],b[0][2],a[0][0],a[0][1],a[0][2]);
				for (ix=nxmin;ix<=nxmax;ix++) {
					for (iy=nymin;iy<=nymax;iy++) {
						for (iz=nzmin;iz<=nzmax;iz++) {
							/* atom position in reduced coordinates: */
							// a[0][0] = ix+newAtom.x; a[0][1] = iy+newAtom.y; a[0][2] = iz+newAtom.z;		 
							a[0][0] = newAtom.x+ix; a[0][1] = newAtom.y+iy; a[0][2] = newAtom.z+iz;
							matrixProduct(a,1,3,Mm,3,3,b);

							/*	  
							b[0][0] = a[0][0]*Mm[0][0]+a[0][1]*Mm[0][1]+a[0][2]*Mm[0][2];
							b[0][1] = a[0][0]*Mm[1][0]+a[0][1]*Mm[1][1]+a[0][2]*Mm[1][2];
							b[0][2] = a[0][0]*Mm[2][0]+a[0][1]*Mm[2][1]+a[0][2]*Mm[2][2];
							*/
							/* // same as matrixProduct: 
							b[0][0] = a[0][0]*Mm[0][0]+a[0][1]*Mm[1][0]+a[0][2]*Mm[2][0];
							b[0][1] = a[0][0]*Mm[0][1]+a[0][1]*Mm[1][1]+a[0][2]*Mm[2][1];
							b[0][2] = a[0][0]*Mm[0][2]+a[0][1]*Mm[1][2]+a[0][2]*Mm[2][2];
							*/
							superCell.atoms[atomCount].x  = b[0][0]+dx; 
							superCell.atoms[atomCount].y  = b[0][1]+dy; 
							superCell.atoms[atomCount].z  = b[0][2]+dz; 
							if ((superCell.atoms[atomCount].x >= 0) && 
								(superCell.atoms[atomCount].x < superCell.ax) &&
								(superCell.atoms[atomCount].y >= 0) && 
								(superCell.atoms[atomCount].y < superCell.by) &&
								(superCell.atoms[atomCount].z >= 0) && 
								(superCell.atoms[atomCount].z < superCell.cz)) {
									// If this is a sphere:
									if (grains[g].sphereRadius > 0) {
										dxs = superCell.atoms[atomCount].x - grains[g].sphereX;
										dys = superCell.atoms[atomCount].y - grains[g].sphereY;
										dzs = superCell.atoms[atomCount].z - grains[g].sphereZ;
										if (dxs*dxs+dys*dys+dzs*dzs < grains[g].sphereRadius*grains[g].sphereRadius) { 
											superCell.atoms[atomCount].dw = newAtom.dw;
											superCell.atoms[atomCount].occ = newAtom.occ;
											superCell.atoms[atomCount].q = newAtom.q;
											superCell.atoms[atomCount].Znum = newAtom.Znum;
											atomCount++;
										}
									}
									// If this is a straight-edged grain
									else {
										for (p=0;p<grains[g].nplanes;p++) {
											/*
											printf("hello %d (%g %g %g)\n",g,
											superCell.atoms[atomCount].x,superCell.atoms[atomCount].y,
											superCell.atoms[atomCount].z);
											*/
											d = findLambda(grains[g].planes+p,&(superCell.atoms[atomCount].z),-1);

											/*
											printf("%3d lambda: %g (%g %g %g), (%g %g %g), %d\n",atomCount,d,
											newAtom.x,newAtom.y,newAtom.z,
											superCell.atoms[atomCount].x,superCell.atoms[atomCount].y,
											superCell.atoms[atomCount].z,grains[g].nplanes);
											*/		
											if (d < 0)
												break;
										}
										/* if all the previous test have been successful, this atom is IN,
										* which means that we also need to copy the other data elements
										* for this atom. 
										*/
										if (p == grains[g].nplanes) {
											superCell.atoms[atomCount].q = newAtom.q;
											superCell.atoms[atomCount].dw = newAtom.dw;
											superCell.atoms[atomCount].occ = newAtom.occ;
											superCell.atoms[atomCount].Znum = newAtom.Znum;
											atomCount++;
										}
									} // if this is a sphere or not ...
							}
						} /* iz ... */
					} /* iy ... */
				} /* ix ... */
			} /* iatom ... */
			superCell.natoms = atomCount;
		} /* end of if !amorph,i.e. crystalline */
	} /* g=0..nGrains .. */
	/*
	atomPtr->x = 0.5; atomPtr->y = 0.2; atomPtr->z = 0.7;
	findLambda(grains[0].planes,&(atomPtr->z),1);
	*/ 

}
Beispiel #6
0
void makeSpecial(int distPlotFlag) {
	int p,g,iatom,atomCount = 0,amorphAtoms;
	double d,r,x,y,z,dist,volume;
	int i,j,Znum,count;
	long seed;
	float pos[3],center[3],grainBound[6];
	int trials = 0,type;
	char *ptr;

	seed = -(long)(time(NULL));  // initialize random number generator.

	for (g=0;g<nGrains;g++) {
		/********************************************************
		* if this grain is a special one ... 
		*/
		if (grains[g].amorphFlag == SPECIAL_GRAIN) {
			//  type = atoi(grains[g].name);
			ptr = grains[g].name;
			while (*ptr != ' ') ptr++;
			type = atoi(ptr+1);
			*ptr = 0;
			// printf("Distribution type: %d \n",type);
			printf("%s: distribution type: %d (%s)\n",grains[g].name,type,
				(type == 2) ? "double gaussian" : (type == 1 ? "single gaussian" : "random"));
			/**************************************************************
			* We would like to calculate the Volume of this grain.  
			* We do this by brute force, by simply checking, if randomly
			* distributed points are within the grain, or not.
			*************************************************************/
			grainBound[0] = superCell.ax;  grainBound[1] = 0;
			grainBound[2] = superCell.by;  grainBound[3] = 0;
			grainBound[4] = superCell.cz;  grainBound[5] = 0;
			for (count=0, i=0; i<TRIAL_COUNT;i++) {
				// remember that we have to create a vector with
				// z,y,x, because that is the way the atom struct is 
				pos[2] = superCell.ax*ran(&seed);
				pos[1] = superCell.by*ran(&seed);
				pos[0] = superCell.cz*ran(&seed);
				for (p=0;p<grains[g].nplanes;p++) {
					d = findLambda(grains[g].planes+p,pos,-1);
					if (d < 0) break;
				}
				// if all the previous tests have been successful, this atom is IN 
				if (p == grains[g].nplanes) {
					count++;
					// center of this grain
					center[0] += pos[2]; center[1] += pos[1]; center[2] += pos[0]; 
					// boundaries in X-direction of this grain
					if (grainBound[0] > pos[2]) grainBound[0] = pos[2]; // xmin
					if (grainBound[1] < pos[2]) grainBound[1] = pos[2]; // xmax
					if (grainBound[2] > pos[1]) grainBound[2] = pos[1]; // ymin
					if (grainBound[3] < pos[1]) grainBound[3] = pos[1]; // ymax
					if (grainBound[4] > pos[0]) grainBound[4] = pos[0]; // zmin
					if (grainBound[5] < pos[0]) grainBound[5] = pos[0]; // zmax
				}
			}
			center[0] /= (double)count;
			center[1] /= (double)count;
			center[2] /= (double)count;
			volume = superCell.ax*superCell.by*superCell.cz*(double)count/(double)TRIAL_COUNT;
			printf("Volume: %gA^3, %g %%\n",volume,(double)(100*count)/(double)TRIAL_COUNT);
			printf("boundaries: x: %g..%g, y: %g..%g, z: %g..%g\n",
				grainBound[0],grainBound[1],grainBound[2], 
				grainBound[3],grainBound[4],grainBound[5]); 

			// First we need to find out how much memory we need to reserve for this grain
			amorphAtoms = 0;
			for (iatom=0;iatom<grains[g].natoms;iatom++) {
				if (grains[g].unitCell[iatom].y < 1.0) {  // if this is a concentration, and no count
					grains[g].unitCell[iatom].y *= volume;  // then convert it to number of atoms
				}
				amorphAtoms += (int)(grains[g].unitCell[iatom].y);
			}

			superCell.atoms = (atom *)realloc(superCell.atoms,(amorphAtoms+superCell.natoms+1)*
				sizeof(atom));
			if (superCell.atoms == NULL) {
				printf("makeAmorphous: Could not allocate memory for additional atoms!\n");
				exit(0);
			}
			atomCount = superCell.natoms;  // start adding amorphous atoms, where we left off.

			// Now we can loop through and add these atoms randomly to the grain
			for (iatom=0;iatom<grains[g].natoms;iatom++) {
				r = grains[g].unitCell[iatom].z;             // radius of this atom
				count = (int)(grains[g].unitCell[iatom].y);  // number of atoms of this kind
				Znum = grains[g].unitCell[iatom].Znum;
				covRad[Znum-1] = r;                          // set radius of other atoms also
				for (j=0;j<count;j++) {
					do { // make it lie within the grain bounding planes
						do { // make the atoms not touch eachother
							// z = superCell.cz*ran(&seed);
							// y = superCell.by*ran(&seed);
							z = grainBound[4]+ran(&seed)*(grainBound[5]-grainBound[4]);	    
							y = grainBound[2]+ran(&seed)*(grainBound[3]-grainBound[2]);	    
							if (fabs(superCell.cz-z) < 2e-5) z = 0.0;
							if (fabs(superCell.by-y) < 2e-5) y = 0.0;
							if (iatom > 0) {
								x = grainBound[0]+ran(&seed)*(grainBound[1]-grainBound[0]);	    
							}
							else {
								switch (type) {
		case 0:
			x = grainBound[0]+ran(&seed)*(grainBound[1]-grainBound[0]);	    
			break;
		case 1:
			x = xDistrFun1(center[0],0.08*(grainBound[1]-grainBound[0]));	    
			break;
		case 2:
			x = xDistrFun2(center[0],0.80*(grainBound[1]-grainBound[0]),
				0.08*(grainBound[1]-grainBound[0]));
			break;
		default:
			x = grainBound[0]+ran(&seed)*(grainBound[1]-grainBound[0]);	    
								}
							}
							if (fabs(superCell.ax-x) < 2e-5) x = 0.0;
							// Now we must check, whether atoms overlap
							for (i=0;i<atomCount;i++) {
								for (p=-1;p<=1;p++) {
									dist = sqrt(SQR(x-superCell.atoms[i].x)+
										SQR(y-superCell.atoms[i].y+p*superCell.by)+
										SQR(z-superCell.atoms[i].z));		  
									if (dist < r+covRad[superCell.atoms[i].Znum-1]) break;		
								}	    
								if (p < 2) break;
							}
							trials++;
							if (trials % amorphAtoms == 0)
								printf("Average trials per atom: %d times, success: %g %%\n",
								trials/amorphAtoms,100.0*(atomCount-superCell.natoms)/
								(double)amorphAtoms);
						} while (i < atomCount);  
						// try until we find one that does not touch any other

						// superCell.atoms[atomCount].dw = 0.0;
						superCell.atoms[atomCount].dw = 0.45*28.0/(double)(2.0*Znum);

						superCell.atoms[atomCount].occ  = 1.0;
						superCell.atoms[atomCount].q    = 0;
						superCell.atoms[atomCount].Znum = Znum;
						superCell.atoms[atomCount].x    = x;
						superCell.atoms[atomCount].y    = y;
						superCell.atoms[atomCount].z    = z;

						for (p=0;p<grains[g].nplanes;p++) {
							d = findLambda(grains[g].planes+p,&(superCell.atoms[atomCount].z),-1);
							if (d < 0) break;
						}
						// if all the previous tests have been successful, this atom is IN 
					} while(p < grains[g].nplanes);
					atomCount++;
				} // for j=0..count
				printf("%d (%d): %d \n",iatom,Znum,count);
			} // for iatom = 0..natoms
			printf("\n%d amorphous atoms, volume: %gA^3 (%g%%), center: %g, width: %g\n",
				atomCount-superCell.natoms,
				volume,100.0*volume/(superCell.ax*superCell.by*superCell.cz),center[0],
				grainBound[1]-grainBound[0]);
			switch (type) {
	  case 2:
		  xDistrFun2(0.0,0.0,0.0);
		  break;
	  case 1:
		  xDistrFun1(0.0,0.0);
		  break;
			}
			superCell.natoms = atomCount;
		} // if special_grain 
	} // g=0..nGrains ..
	/*******************************************************************
	* Now we must produce distribution plots of the different atom kinds
	*/
	if (distPlotFlag) makeDistrPlot(superCell.atoms,superCell.natoms,superCell.ax);
}
Beispiel #7
0
int  main(int npar, char ** parch)
{
  int i,j;
  int NfMx=5;
  double q[NQ]= { 1.25,1.5,2.,2.5,3.2,4.,5.,6.4,8.,10.,12.,18.,
                  26.,40.,64.,100.,160.,240.,400.,640.,1e3,1800.,3200.,5600.,1e4,
                  1.8e4,3.2e4,5.6e4,1e5,1.8e5,3.2e5,5.6e5,1e6,1.8e6,3.2e6,5.6e6,1e7};
  double x[NX]={ 1e-5,2e-5,4e-5,6e-5,8e-5,1e-4,2e-4,4e-4,6e-4,
                 8e-4,.001,.002,.004,.006,.008,.01,.014,.02,.03,.04,.06,.08,.1,
                 .125,.15,.175,.2,.225,.25,.275,.3,.325,.35,.375,.4,.425,.45,.475,
                 .5,.525,.55,.575,.6,.65,.7,.75,.8,.9,1. };

  char * version;
  double Mc=sqrt(2.045);
  double Mb=sqrt(18.5);
  double Mt=175;
  
  char names[4][10]={"(6 -6)", "(5 -5)", "(4 -4)", "(3 -3)"};
  double f1[49*37],f2[49*37],f3[49*37],f4[49*37], f5[49*37],f6[49*37],f7[49*37],f8[49*37];

  if( npar!=2 && npar!=5 ) 
  { fprintf(stderr,"This routine needs 1 parameters: identifier of the set, or 4 parameters:\n"
                   "1. the identifier; 2. nf; 3. order (lo, nlo,nnlo); 4. alpha_QCD(MZ)\n");  
    return 1;
  }
  
  version=parch[1];
  
  printf("#distribution \"%s(proton)\"  2212 =>    ",version);
  for(i= 6-NfMx; i<4;i++) printf(" %s",names[i]);
  printf(" -1 -2 21 2 1 \n");

  printf("#distribution \"%s(anti-proton)\" -2212 => ",version);
  for(i=6-NfMx; i<4;i++) printf(" %s",names[i]);
  printf(" 1 2 21 -2 -1\n");

  printf("\n#Q_grid\n"); 
  for(i=0;i<NQ;i++) q[i]=sqrt(q[i]); 
  for(i=0,j=1;i<NQ;i++,j++) 
  {  printf(" %.9E",q[i]); 
     if(j==10) {printf("\n"); j=0;}
  }

  if(npar==5)
  {
     int ordr, nf, nfMx;
     double lambda, alphMZ;

     if(sscanf(parch[2],"%d",  &nf)!=1 || nf>6 || nf<4)
     { fprintf(stderr,"Second parameter should be a hole number between 4 and 6\n");
       exit(1);
     }
          if(strcmp(parch[3],"lo")==0)    ordr=1;
     else if(strcmp(parch[3],"nlo")==0)   ordr=2;
     else if(strcmp(parch[3],"nnlo")==0)  ordr=3;
     else 
     { fprintf(stderr,"Third parameter should be 'lo', 'nlo', or 'nnlo' \n");
       exit(1);
     }        
     if(sscanf(parch[4],"%lf", &alphMZ)!=1 || alphMZ<0.09 || alphMZ>0.15)
     { fprintf(stderr,"Fourth parameter should be a  number between 0.09 and 0.15\n");
       exit(1);
     } 
     if(nf==6){nf=5;nfMx=6;} else nfMx=nf;
     lambda=findLambda(nf,ordr,alphMZ,91.187);
     writeAlpha(stdout,nf,ordr,lambda,nfMx,Mc,Mb,Mt,NQ,q);
  }  

  printf("\n#X_grid\n");
  for(i=0,j=1;i<NX;i++,j++) 
  {
     printf(" %.5E",x[i]); 
     if(j==10) {printf("\n"); j=0;}
  }     
  printf("\n");

  printf("\n#Interpolation MRST2001\n"); 

  for(i=0; i<NX-1; ++i) for(j=0; j<NQ;++j) 
  {  int k=i+j*NX;
     scanf("%lf %lf %lf %lf %lf %lf %lf %lf",f1+k,f2+k,f3+k,f4+k,f5+k,f7+k,f6+k,f8+k);
  }
 

   /* notation: 1=uval 2=val 3=glue 4=usea 5=chm 6=str 7=btm 8=dsea */

/*(b,B) (c,C) (s,S) D U G u d */
           
    printf("\n#q_threshold %.7E\n",Mb);
    printf("\n#1-parton\n");
    for(j=0;j<NQ;j++)
    { for(i=0;i<NX-1;i++)  printf(" %.8E",f7[j*NX+i]/x[i]);
      printf(" 0.\n");
    }

    printf("\n#q_threshold %.7E\n",Mc);
    printf("\n#2-parton\n");
    for(j=0;j<NQ;j++)
    { for(i=0;i<NX-1;i++)  printf(" %.6E",f5[j*NX+i]/x[i]);
      printf(" 0.\n");
    }

    printf("\n#q_threshold 0\n");
    printf("\n#3-parton\n");
    for(j=0;j<NQ;j++)
    { for(i=0;i<NX-1;i++)  printf(" %.6E",f6[j*NX+i]/x[i]);
      printf(" 0.\n");
    }

    printf("\n#4-parton\n");
    for(j=0;j<NQ;j++)
    { for(i=0;i<NX-1;i++)  printf(" %.6E",f8[j*NX+i]/x[i]);
      printf(" 0.\n");
    }

    printf("\n#5-parton\n");
    for(j=0;j<NQ;j++)
    { for(i=0;i<NX-1;i++)  printf(" %.6E",f4[j*NX+i]/x[i]);
      printf(" 0.\n");
    }

    printf("\n#6-parton\n");
    for(j=0;j<NQ;j++)
    { for(i=0;i<NX-1;i++)  printf(" %.6E",f3[j*NX+i]/x[i]);
      printf(" 0.\n");
    }

    printf("\n#7-parton\n");
    for(j=0;j<NQ;j++)
    { for(i=0;i<NX-1;i++)  printf(" %.6E",(f1[j*NX+i]+f4[j*NX+i])/x[i]);
      printf(" 0.\n");
    }

    printf("\n#8-parton\n");
    for(j=0;j<NQ;j++)
    { for(i=0;i<NX-1;i++)  printf(" %.6E",(f2[j*NX+i]+f8[j*NX+i])/x[i]);
      printf(" 0.\n");
    }
    return 0;
}