コード例 #1
0
bool EinsplineSetBuilder::ReadGvectors_ESHDF()
{
  update_token(__FILE__,__LINE__,"ReadGvectors_ESHDF");
  bool root=myComm->rank() ==0;
  //this is always ugly
  MeshSize = 0;
  int hasPsig=1;
#if defined(__bgp__)||(__bgq__)
  if(root)
  {
    hid_t gid=H5Dopen(H5FileID,"/electrons/kpoint_0/spin_0/state_0/psi_g");
    if(gid<0)
      hasPsig=0;
    H5Dclose(gid);
  }
  myComm->bcast(hasPsig);
#else
  if(root)
  {
    HDFAttribIO<TinyVector<int,3> > h_mesh(MeshSize);
    h_mesh.read (H5FileID, "/electrons/psi_r_mesh");
    h_mesh.read (H5FileID, "/electrons/mesh");
  }
  myComm->bcast(MeshSize);
  hasPsig = (MeshSize[0] == 0);
#endif
  if(hasPsig)
  {
    int nallowed=257;
    int allowed[] =
    {
      72,75,80,81,90,96,100,108,120,125,
      128,135,144,150,160,162,180,192,200,216,
      225,240,243,250,256,270,288,300,320,324,
      360,375,384,400,405,432,450,480,486,500,
      512,540,576,600,625,640,648,675,720,729,
      750,768,800,810,864,900,960,972,1000,1024,
      1080,1125,1152,1200,1215,1250,1280,1296,1350,1440,
      1458,1500,1536,1600,1620,1728,1800,1875,1920,1944,
      2000,2025,2048,2160,2187,2250,2304,2400,2430,2500,
      2560,2592,2700,2880,2916,3000,3072,3125,3200,3240,
      3375,3456,3600,3645,3750,3840,3888,4000,4050,4096,
      4320,4374,4500,4608,4800,4860,5000,5120,5184,5400,
      5625,5760,5832,6000,6075,6144,6250,6400,6480,6561,
      6750,6912,7200,7290,7500,7680,7776,8000,8100,8192,
      8640,8748,9000,9216,9375,9600,9720,10000,10125,10240,
      10368,10800,10935,11250,11520,11664,12000,12150,12288,12500,
      12800,12960,13122,13500,13824,14400,14580,15000,15360,15552,
      15625,16000,16200,16384,16875,17280,17496,18000,18225,18432,
      18750,19200,19440,19683,20000,20250,20480,20736,21600,21870,
      22500,23040,23328,24000,24300,24576,25000,25600,25920,26244,
      27000,27648,28125,28800,29160,30000,30375,30720,31104,31250,
      32000,32400,32768,32805,33750,34560,34992,36000,36450,36864,
      37500,38400,38880,39366,40000,40500,40960,41472,43200,43740,
      45000,46080,46656,46875,48000,48600,49152,50000,50625,51200,
      51840,52488,54000,54675,55296,56250,57600,58320,59049,60000,
      60750,61440,62208,62500,64000,64800,65536
    };
    int numk=0;
    MaxNumGvecs=0;
    //    std::set<TinyVector<int,3> > Gset;
    // Read k-points for all G-vectors and take the union
    TinyVector<int,3> maxIndex(0,0,0);
    Gvecs.resize(NumTwists);
    {
      int numg=0;
      if(root)
      {
        ostringstream Gpath;
        Gpath    << "/electrons/kpoint_0/gvectors";
        HDFAttribIO<vector<TinyVector<int,3> > > h_Gvecs(Gvecs[0]);
        h_Gvecs.read (H5FileID, Gpath.str().c_str());
        numg=Gvecs[0].size();
      }
      myComm->bcast(numg);
      if(!root)
        Gvecs[0].resize(numg);
      myComm->bcast(Gvecs[0]);
      MaxNumGvecs=Gvecs[0].size();
      for (int ig=0; ig<Gvecs[0].size(); ig++)
      {
        maxIndex[0] = std::max(maxIndex[0], std::abs(Gvecs[0][ig][0]));
        maxIndex[1] = std::max(maxIndex[1], std::abs(Gvecs[0][ig][1]));
        maxIndex[2] = std::max(maxIndex[2], std::abs(Gvecs[0][ig][2]));
      }
      // for (int ig=0; ig<Gvecs.size(); ig++)
      // 	if (Gset.find(Gvecs[ig]) == Gset.end())
      // 	  Gset.insert(Gvecs[ig]);
    } //done with kpoint_0
    MeshSize[0] = (int)std::ceil(4.0*MeshFactor*maxIndex[0]);
    MeshSize[1] = (int)std::ceil(4.0*MeshFactor*maxIndex[1]);
    MeshSize[2] = (int)std::ceil(4.0*MeshFactor*maxIndex[2]);
    //only use 2^a 3^b 5^c where a>=2  up to 65536
    int *ix=lower_bound(allowed,allowed+nallowed,MeshSize[0]);
    int *iy=lower_bound(allowed,allowed+nallowed,MeshSize[1]);
    int *iz=lower_bound(allowed,allowed+nallowed,MeshSize[2]);
    MeshSize[0]=(MeshSize[0]>128)? *ix:(MeshSize[0]+MeshSize[0]%2);
    MeshSize[1]=(MeshSize[1]>128)? *iy:(MeshSize[1]+MeshSize[1]%2);
    MeshSize[2]=(MeshSize[2]>128)? *iz:(MeshSize[2]+MeshSize[2]%2);
    if(Version[0]<2)
    {
      //get the map for each twist, but use the MeshSize from kpoint_0
      app_log() << "  ESHDF::Version " << Version << endl;
      app_log() << "  Assumes distinct Gvecs set for different twists. Regenerate orbital files using updated QE." << endl;
      for(int k=0; k<DistinctTwists.size(); ++k)
      {
        int ik=DistinctTwists[k];
        if(ik==0)
          continue; //already done
        int numg=0;
        if(root)
        {
          ostringstream Gpath;
          Gpath    << "/electrons/kpoint_" << ik << "/gvectors";
          HDFAttribIO<vector<TinyVector<int,3> > > h_Gvecs(Gvecs[ik]);
          h_Gvecs.read (H5FileID, Gpath.str().c_str());
          numg=Gvecs[ik].size();
        }
        myComm->bcast(numg);
        if(numg==0)
        {
          //copy kpoint_0, default
          Gvecs[ik]=Gvecs[0];
        }
        else
        {
          if(numg !=  MaxNumGvecs)
          {
            ostringstream o;
            o<< "Twist " << ik << ": The number of Gvecs is different from kpoint_0."
             << " This is not supported anymore. Rerun pw2qmcpack.x or equivalent";
            APP_ABORT(o.str());
          }
          if(!root)
            Gvecs[ik].resize(numg);
          myComm->bcast(Gvecs[ik]);
        }
      }
    }
  }
  app_log() << "B-spline mesh factor is " << MeshFactor << endl;
  app_log() << "B-spline mesh size is (" << MeshSize[0] << ", " << MeshSize[1] << ", " << MeshSize[2] << ")\n";
  app_log() << "Maxmimum number of Gvecs " << MaxNumGvecs << endl;
  app_log().flush();
  return hasPsig;
}
コード例 #2
0
InnerNode::InnerNode(InnerNode* P, Btree* T) : Node(0,P,T)
{
    item = new Item[maxIndex()+1];
    if( item == 0 )
        ClassLib_error( __ENOMEMIA );
}
コード例 #3
0
ファイル: grid2.cpp プロジェクト: ZaneYang/VoxelHashing
template <class T> const T& Grid2<T>::maxValue() const
{
	std::pair<size_t, size_t> index = maxIndex();
	return m_data[index.first * m_dimY + index.second];
}
コード例 #4
0
void InnerNode::append( Sortable* D, Node* N )
{
    // never called from anywhere where it might fill up THIS
    PRECONDITION( last < maxIndex() );
    setItem( ++last, D, N );
}
コード例 #5
0
void InnerNode::append( Item& itm )
{
    PRECONDITION( last < maxIndex() );
    setItem( ++last, itm );
}
コード例 #6
0
ファイル: psize.c プロジェクト: RashmiKumari/g_mmpbsa
int psize (t_topology *top, atom_id *index, int isize, rvec *x, t_PolKey *param, gmx_bool bCG, gmx_bool bFocus)	{
	int i,j;
	rvec minlen, maxlen;
	rvec olen, clen, flen, cen;
	ivec n, np, tn, nsmall;
	real nsmem, gmem, zofac;
	real r, np_float;

	minlen[XX] = 9999; minlen[YY] = 9999; minlen[ZZ] = 9999;
	maxlen[XX] = -9999; maxlen[YY] = -9999; maxlen[ZZ] = -9999;

	for (i=0;i<isize;i++)	{
		r = top->atoms.pdbinfo[index[i]].bfac;
		for(j=0;j<DIM;j++)	{
			if((x[index[i]][j]*10)-r < minlen[j])
				minlen[j] = (x[index[i]][j]*10) - r;

			if((x[index[i]][j]*10)+r > maxlen[j])
				maxlen[j] = (x[index[i]][j]*10) + r;

		}
	}

	for (i=0;i<DIM;i++)		{
		olen[i] = maxlen[i] - minlen[i];
		clen[i] = param->cfac * olen[i];
		flen[i] = param->fadd + olen[i];
		if(flen[i]>clen[i])
			flen[i] = clen[i];
		cen[i] = (maxlen[i] + minlen[i])/2;

		tn[i] = (int) flen[i]/param->gridspace + 0.5;
		n[i] = 32*((int)((tn[i] - 1) / 32.0 + 0.5)) + 1;
		nsmall[i] = 32*((int)((tn[i] - 1) / 32.0 + 0.5)) + 1;

		if (nsmall[i] < 33)
			nsmall[i] = 33;
	}

	//To Check the available memory
	gmem = 200.0 * n[XX] * n[YY] * n[ZZ] / 1024 / 1024;
	while(1)	{
		nsmem = 200.0 * nsmall[XX] * nsmall[YY] * nsmall[ZZ] / 1024 / 1024;
		if(nsmem<param->gmemceil)
			break;
		else	{
			i = maxIndex(nsmall);
			nsmall[i] = 32 * ((nsmall[i] - 1)/32 - 1) + 1;
			if (nsmall <= 0)	{
				gmx_fatal(FARGS, "You picked a memory ceiling that is too small\n");
			}


		}
	}

	// Calculating pdime => np
	if (gmem >= param->gmemceil)	{
		zofac = 1 + 2 * param->ofrac;
		for (i=0;i<DIM;i++)	{
			np_float = n[i]/(float)nsmall[i];
			if (np_float > 1)
				np[i] = (int)(zofac*n[1]/nsmall[i] + 1.0);
		}
	}


	if(gmem >= param->gmemceil)
		param->mg_type = mg_para;
	else
		param->mg_type = mg_auto;

	if (bCG)	{
		copy_rvec(clen,param->cglen);
		copy_rvec(cen,param->cgcent);
	}

	if(!bFocus)	{
		copy_rvec(flen,param->fglen);
		copy_rvec(cen,param->fgcent);
	}
	copy_ivec(nsmall,param->dime);

	if(param->mg_type == mg_para)
		copy_ivec(np, param->pdime);

	return 0;
}
コード例 #7
0
void planarCNBGraph(Graph &G, int n, int m,	int b)	
{
	G.clear();
	if (b <= 0) b = 1;
	if (n <= 0) n = 1;
	if ((m <= 0) || (m > 3*n-6)) m = 3*n-6;
	
	node cutv;
	G.newNode();
	
	for (int nB=1; nB<=b; nB++){
		cutv = G.chooseNode();
		// set number of nodes for the current created block
		int actN = randomNumber(1, n);
		
		node v1 = G.newNode();
		
		if (actN <= 1){
			G.newEdge(v1, cutv);
		}
		else
			if (actN == 2){
				node v2 = G.newNode();
				G.newEdge(v1, v2);
				
				int rnd = randomNumber(1, 2);
				edge newE;
				int rnd2 = randomNumber(1, 2);
				if (rnd == 1){
					newE = G.newEdge(v1, cutv);
				}
				else{
					newE = G.newEdge(v2, cutv);
				}
				if (rnd2 == 1){
					G.contract(newE);
				}
			}
			else{
				// set number of edges for the current created block
				int actM;
				if (m > 3*actN-6)
					actM = randomNumber(1, 3*actN-6);
				else
					actM = randomNumber(1, m);
				if (actM < actN)
					actM = actN;
				
				int ke = actN-3, kf = actM-actN;
				
				Array<node> nodes(actN);
				Array<edge> edges(actM);
				Array<face> bigFaces(actM);
					
				// we start with a triangle
				node v2 = G.newNode(), v3 = G.newNode();
				nodes[0] = v1;
				nodes[1] = v2;
				nodes[2] = v3;
				edges[0] = G.newEdge(v1,v2);
				edges[1] = G.newEdge(v2,v3);
				edges[2] = G.newEdge(v3,v1);
				
				int actInsertedNodes = 3;
				
				CombinatorialEmbedding E(G);
				FaceArray<int> posBigFaces(E);
				int nBigFaces = 0, nEdges = 3;
				
				while(ke+kf > 0) {
					int p = randomNumber(1,ke+kf);
			
					if (nBigFaces == 0 || p <= ke) {
						int eNr = randomNumber(0,nEdges-1);
						edge e  = edges[eNr];
						face f  = E.rightFace(e->adjSource());
						face fr = E.rightFace(e->adjTarget());
						
						node u = e->source();
						node v = e->target();
						
						edges[nEdges++] = E.split(e);
						
						if (e->source() != v && e->source() != u)
							nodes[actInsertedNodes++] = e->source();
						else
							nodes[actInsertedNodes++] = e->target();

						if (f->size() == 4) {
							posBigFaces[f] = nBigFaces;
							bigFaces[nBigFaces++] = f;
						}
						if (fr->size() == 4) {
							posBigFaces[fr] = nBigFaces;
							bigFaces[nBigFaces++] = fr;
						}
			
						ke--;
					}
					else {						
						int pos = randomNumber(0,nBigFaces-1);
						face f = bigFaces[pos];
						int df = f->size();
						int i = randomNumber(0,df-1), j = randomNumber(2,df-2);
			
						adjEntry adj1;
						for (adj1 = f->firstAdj(); i > 0; adj1 = adj1->faceCycleSucc())
							i--;
			
						adjEntry adj2;
						for (adj2 = adj1; j > 0; adj2 = adj2->faceCycleSucc())
							j--;
			
						edge e = E.splitFace(adj1,adj2);
						edges[nEdges++] = e;
						
						face f1 = E.rightFace(e->adjSource());
						face f2 = E.rightFace(e->adjTarget());
			
						bigFaces[pos] = f1;
						posBigFaces[f1] = pos;
						if (f2->size() >= 4) {
							posBigFaces[f2] = nBigFaces;
							bigFaces[nBigFaces++] = f2;
						}
						if (f1->size() == 3) {
							bigFaces[pos] = bigFaces[--nBigFaces];
						}
						
						kf--;
					}
				}
						
				// delete multi edges
				SListPure<edge> allEdges;
				EdgeArray<int> minIndex(G), maxIndex(G);
		
				parallelFreeSortUndirected(G,allEdges,minIndex,maxIndex);
		
				SListConstIterator<edge> it = allEdges.begin();
				edge ePrev = *it, e;
				for(it = ++it; it.valid(); ++it, ePrev = e) {
					e = *it;
					if (minIndex[ePrev] == minIndex[e] &&
						maxIndex[ePrev] == maxIndex[e])
					{
						G.move(e,
							e->adjTarget()->faceCycleSucc()->twin(), ogdf::before,
							e->adjSource()->faceCycleSucc()->twin(), ogdf::before);
					}
				}
				
				node cutv2 = nodes[randomNumber(0,actN-1)];
				
				int rnd = randomNumber(1,2);
				edge newE = G.newEdge(cutv2, cutv);
				if (rnd == 1){
					G.contract(newE);
				}
			}
	}
};
コード例 #8
0
void planarBiconnectedGraph(Graph &G, int n, int m, bool multiEdges)
{
	if (n < 3) n = 3;
	if (m < n) m = n;
	if (m > 3*n-6) m = 3*n-6;

	int ke = n-3, kf = m-n;

	G.clear();
	
	Array<edge> edges(m);
	Array<face> bigFaces(m);
	//random_source S;

	// we start with a triangle
	node v1 = G.newNode(), v2 = G.newNode(), v3 = G.newNode();
	edges[0] = G.newEdge(v1,v2);
	edges[1] = G.newEdge(v2,v3);
	edges[2] = G.newEdge(v3,v1);

	CombinatorialEmbedding E(G);
	FaceArray<int> posBigFaces(E);
	int nBigFaces = 0, nEdges = 3;

	while(ke+kf > 0) {
		int p = randomNumber(1,ke+kf);

		if (nBigFaces == 0 || p <= ke) {
			edge e  = edges[randomNumber(0,nEdges-1)];
			face f  = E.rightFace(e->adjSource());
			face fr = E.rightFace(e->adjTarget());

			edges[nEdges++] = E.split(e);

			if (f->size() == 4) {
				posBigFaces[f] = nBigFaces;
				bigFaces[nBigFaces++] = f;
			}
			if (fr->size() == 4) {
				posBigFaces[fr] = nBigFaces;
				bigFaces[nBigFaces++] = fr;
			}

			ke--;

		} else {
			int pos = randomNumber(0,nBigFaces-1);
			face f = bigFaces[pos];
			int df = f->size();
			int i = randomNumber(0,df-1), j = randomNumber(2,df-2);

			adjEntry adj1;
			for (adj1 = f->firstAdj(); i > 0; adj1 = adj1->faceCycleSucc())
				i--;

			adjEntry adj2;
			for (adj2 = adj1; j > 0; adj2 = adj2->faceCycleSucc())
				j--;

			edge e = E.splitFace(adj1,adj2);
			edges[nEdges++] = e;

			face f1 = E.rightFace(e->adjSource());
			face f2 = E.rightFace(e->adjTarget());

			bigFaces[pos] = f1;
			posBigFaces[f1] = pos;
			if (f2->size() >= 4) {
				posBigFaces[f2] = nBigFaces;
				bigFaces[nBigFaces++] = f2;
			}
			if (f1->size() == 3) {
				bigFaces[pos] = bigFaces[--nBigFaces];
			}

			kf--;
		}
	}

	if (multiEdges == false) {
		SListPure<edge> allEdges;
		EdgeArray<int> minIndex(G), maxIndex(G);

		parallelFreeSortUndirected(G,allEdges,minIndex,maxIndex);

		SListConstIterator<edge> it = allEdges.begin();
		edge ePrev = *it, e;
		for(it = ++it; it.valid(); ++it, ePrev = e) {
			e = *it;
			if (minIndex[ePrev] == minIndex[e] &&
				maxIndex[ePrev] == maxIndex[e])
			{
				G.move(e,
					e->adjTarget()->faceCycleSucc()->twin(), ogdf::before,
					e->adjSource()->faceCycleSucc()->twin(), ogdf::before);
			}
		}

	}
}
コード例 #9
0
void KPrMatrixWipeStrategy::setup( const KPrPageEffect::Data &data, QTimeLine &timeLine )
{
    timeLine.setFrameRange( 0, (m_smooth ? framesPerSquare : 1) * maxIndex(m_squaresPerRow, m_squaresPerCol) );
}
コード例 #10
0
int fitPeak(double xCenter,double yCenter,double distance,double energy,
        double pixelLength,double pixelHeight,double alpha,double beta,double rotation,
        double * sliceQ,double * sliceVal,int numValues,
        double qLower,double qUpper,double chi,double allowedStddevRatio,double *x,double *y,double * qFit,double * deviationFit) {

    double avgVal,maxVal;
    int index;
    double p[4];
    int status;
    double cos_beta,sin_beta,cos_alpha,sin_alpha,cos_rotation,sin_rotation;
    double stddev,sum;
    int i,num;
    //double chiSquare,fit;

    double heightFit,bgFit;
    double covar[4][4];

    int VERBOSE;

    VERBOSE = 0;

    // can't fit unless you have several values
    if (numValues < 10) 
        return 0;

    avgVal = average(sliceVal,numValues);
    index = maxIndex(sliceVal,numValues);
    maxVal = sliceVal[index];

    // 'real' parameters
    p[0]=maxVal-avgVal;
    p[1]=sliceQ[index];
    p[2]= (qUpper-qLower)/15.0;
    p[3]= avgVal;

    status=dlevmar_dif(gaussian, p, sliceVal, 4, numValues, 
            1000,NULL, NULL, NULL,*covar,(void *)sliceQ);

    // check to see if fit is good.
    // if not, return 0 to tell the code that no fit was found

    if (status <= 0) // for successful operation status > 0
        return 0;

    heightFit = p[0];
    *qFit = p[1];
    *deviationFit = p[2]; // pass pack to caller
    bgFit = p[3];
    sum = 0;
    num = 0;

    /*
    if (sqrt(covar[0][0]) > heightFit) {
        if (VERBOSE) printf("Uncertanty in height large compared to height.\n");
        return 0;
    }
    */

    /*
    if (sqrt(covar[1][1]) > *deviationFit) {
        if (VERBOSE) printf("Uncertanty in postion large compared to width of peak.\n");
        return 0;
    }
    */


    // I am not sure this is a good thing to test, b/c there could be a good fit even with a weird b/g
    /*
    if (sqrt(covar[3][3]) > .3*heightFit) {
        if (VERBOSE) printf("Uncertanty in backgound too much\n");
        return 0;
    }
    */
        

    // peak must be signifigantly larger then background
    /*
    if (heightFit < 0.05*bgFit) {
        if (VERBOSE) printf("Peak is not tall enough to count\n");
        return 0;
    }
    */
    
    // make sure fit does not fall too far off the data
    if (*qFit-2* (*deviationFit) < qLower || *qFit+2* (*deviationFit) > qUpper) {
        if (VERBOSE) printf("Fit is too far off the data.\n");
        return 0;
    }

    stddev = 0;
    sum = 0;
    num = 0;

    // calculate variation of background outsize 2 sigma of fit
    for (i=0;i<numValues;i++) {
        if (sliceQ[i] > *qFit+2* (*deviationFit) || sliceQ[i] < *qFit-2* (*deviationFit) ) {
            sum+=(sliceVal[i]-bgFit)*(sliceVal[i]-bgFit);
            num+=1;
        }
    }
    stddev = sqrt(sum*1.0/num);

    // make sure height is bigger then deviation of background by user specified ratio
    if (heightFit < allowedStddevRatio*stddev) {
        if (VERBOSE) printf("Background stddev is too large.\n");
        return 0;
    }

    // good fit, calc x,y cordinates of it.
    cos_beta  = cos(beta*PI/180.0);
    sin_beta  = sin(beta*PI/180.0);
    cos_alpha = cos(alpha*PI/180.0);
    sin_alpha = sin(alpha*PI/180.0);
    cos_rotation = cos(rotation*PI/180.0);
    sin_rotation = sin(rotation*PI/180.0);

    // get physical pixel cordinates
    getXY(xCenter,yCenter,distance,energy,*qFit,chi,
        pixelLength,pixelHeight,rotation,cos_beta,sin_beta,
        cos_alpha,sin_alpha,cos_rotation,sin_rotation,x,y);

    return 1; // success!
}