当前位置: 首页>>代码示例>>C++>>正文


C++ Particles::reserve方法代码示例

本文整理汇总了C++中Particles::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ Particles::reserve方法的具体用法?C++ Particles::reserve怎么用?C++ Particles::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Particles的用法示例。


在下文中一共展示了Particles::reserve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char ** argv)
{
	invalid_argument er(
		"Bond angle correlation function\n"
#ifdef use_periodic
		"Syntax : periodic_g6 [path]filename NbOfBins Nb dx dy dz [mode=0 [l=6]]\n"
#else
		"Syntax : g6 [path]filename radius NbOfBins range [mode=0 [l=6 [zmin zmax]]]\n"
		" range is in diameter unit\n"
#endif
		" mode\t0 raw boo\n"
		"     \t1 coarse grained boo\n"
		);

    try
    {

		if(argc<3) throw er;

		const string filename(argv[1]);
		const string inputPath = filename.substr(0,filename.find_last_of("."));

		vector<size_t> inside;

		//construct the particle container out of the datafile
#ifdef use_periodic
		if(argc<7) throw er;
		const size_t Nbins = atoi(argv[2]);
		const size_t Nb = atoi(argv[3]);
		double nbDiameterCutOff =atof(argv[4]);
		BoundingBox b;
		for(size_t d=0;d<3;++d)
		{
			b.edges[d].first=0.0;
			b.edges[d].second = atof(argv[4+d]);
			if(nbDiameterCutOff>b.edges[d].second)
                nbDiameterCutOff=b.edges[d].second;
		}
		nbDiameterCutOff /=4.0;
		const bool mode = (argc<8)?0:atoi(argv[7]);
		const size_t l = (argc<9)?6:atoi(argv[8]);
		PeriodicParticles Centers(Nb,b,filename,1.0);
		cout << "With periodic boundary conditions"<<endl;
#else
        const double radius = atof(argv[2]),
				nbDiameterCutOff = atof(argv[4]);
        const size_t Nbins = atoi(argv[3]);
        const bool mode = (argc<6)?0:atoi(argv[5]);
        const size_t l = (argc<7)?6:atoi(argv[6]);
		Particles Centers(filename,radius);
#endif
		cout << Centers.size() << " particles ... ";

		//read q6m
		vector<BooData> rawBoo, allBoo;
		Centers.load_qlm(inputPath+".qlm", rawBoo);
		if(mode)
		{
		    Centers.makeNgbList(loadBonds(inputPath+".bonds"));
		    //select all particles who's all neighbours' qlms are not null
		    vector<size_t> second_inside;
		    second_inside.reserve(Centers.size());
		    for(size_t p=0; p<Centers.getNgbList().size(); ++p)
		    {
		        bool hasNullNgb = false;
		        for(size_t n=0; n<Centers.getNgbList()[p].size(); ++n)
                    hasNullNgb = (hasNullNgb || rawBoo[Centers.getNgbList()[p][n]].isnull());
                if(!hasNullNgb)
                    second_inside.push_back(p);
		    }
		    cout<< second_inside.size()<< " have coarse grained qlms ... ";
		    Centers.getCgBOOs(second_inside, rawBoo, allBoo);
		}
		else
            allBoo=rawBoo;

#ifndef use_periodic
        vector<size_t> slab;
        slab.reserve(Centers.size());
        //Case where we ask to discard all points out of the interval [zmin, zmax]
        if(argc>8)
        {
            const double zmin = atof(argv[7]),
                        zmax = atof(argv[8]);
            //look for the particles that are in the slab and have non null qlm
            for(size_t p=0; p<Centers.size(); ++p)
                if(Centers[p][2]>zmin && Centers[p][2]<zmax && !allBoo[p].isnull())
                    slab.push_back(p);
        }
        else
            for(size_t p=0; p<Centers.size(); ++p)
                if(!allBoo[p].isnull())
                    slab.push_back(p);

        //reduce the centers list
        Particles cen;
        cen.radius = Centers.radius;
        cen.reserve(slab.size());
        for(size_t p=0; p<slab.size(); ++p)
            cen.push_back(Centers[slab[p]]);
//.........这里部分代码省略.........
开发者ID:MathieuLeocmach,项目名称:colloids,代码行数:101,代码来源:g6.cpp


注:本文中的Particles::reserve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。