Пример #1
0
void mindist_trajectory(float* coords, float* box, int* groups1, int* groups2, int gn1, int gn2, int na, int nf, int pbc, float* dist) {
    float mindist;
    int a,b,g1,g2,n1,n2,g1atm,g2atm,f;
    float coo1[3], coo2[3];
    int nf3 = nf*3; // Precalculate 3 * nframes for the coordinate lookup macro
    int groupprod = gn1*gn2;

    // Iterate over all frames
    for (f=0; f < nf; f++){
        // Iterate over the two group sets
        for (g1=0; g1 < gn1; g1++){
            for (g2=0; g2 < gn2; g2++){
                mindist = -1;
                // Iterate over atoms in the two groups
                for (a = 0; a < na; a++) {
                    g1atm = groups1[g1 * na + a];
                    if (g1atm == -1) break;
                    //get_coords(coords, g1atm, f, nf, coo1);
                    //const float* coo1 = &coords[g1atm*dim];

                    for (b=0; b < na; b++) {
                        g2atm = groups2[g2 * na + b];
                        if (g2atm == -1) break;
                        //get_coords(coords, g2atm, f, nf, coo2);
                        //const float* coo2 = &coords[g2atm*dim];

                        float d[3];
                        d[0] = coords[Xf(g1atm,f,nf,nf3)]-coords[Xf(g2atm,f,nf,nf3)];
                        d[1] = coords[Yf(g1atm,f,nf,nf3)]-coords[Yf(g2atm,f,nf,nf3)];
                        d[2] = coords[Zf(g1atm,f,nf,nf3)]-coords[Zf(g2atm,f,nf,nf3)];

                        if (pbc){
                            d[0] = d[0] - box[0] * round(d[0] / box[0]);
                            d[1] = d[1] - box[1] * round(d[1] / box[1]);
                            d[2] = d[2] - box[2] * round(d[2] / box[2]);
                        }
                        //printf("coor: %f %f %f / %f %f %f\n", coo1[0], coo1[1], coo1[2], coo2[0], coo2[1], coo2[2]);

                        float D = d[0]*d[0]+d[1]*d[1]+d[2]*d[2];
                        //printf("index: %d/%d dist: %f\n", g1atm, g2atm, sqrt(D));

                        if (D < mindist || mindist < 0) {
                            mindist = D;
                        }
                    }
                }
                //printf("%d %d %d %d: %f\n", g1, gn2, g2, g1*gn2+g2, sqrt(mindist));
                dist[g1*gn2+g2+(f*groupprod)] = sqrt(mindist);  // Add here the f
            }
        }
    }
}
Пример #2
0
int main(int argc, char* argv [])
{
	// check for verbosity flag:
	bool verbose = false;
	if( argc >= 2 )
	{
		for(int i=1; i < argc; i++)
		{
			std::string flag(argv[i]);
			if(flag == "--verbose")
				verbose = true;
		}
	}

	bool pass = true;

	// Do some output
	std::cout << "========== Test Suite 2 ==========" << std::endl;
	std::cout << "   Testing plot generators  " << std::endl;

	// create a model to use for the test:
	std::string fname("SRIM/Hydrogen in Aluminum.txt");
	//StopPow::StopPow_SRIM s(fname);
	std::vector<double> mf(2);
	mf[0] = 1.0;
	mf[1] = 1/1800.;
	std::vector<double> Zf(2);
	Zf[0] = 1.0;
	Zf[1] = -1.;
	std::vector<double> Tf(2);
	Tf[0] = 1.0;
	Tf[1] = 1.0;
	std::vector<double> nf(2);
	nf[0] = 1e24;
	nf[1] = 1e24;
	nf[0] = 1e24; nf[1] = 1e24;
	StopPow::StopPow_LP s(1,1,mf,Zf,Tf,nf);


	std::vector< std::vector<double> > dEdx_plot;
	bool ret = StopPow::get_dEdx_vs_E( s , dEdx_plot );
	if(ret)
		std::cout << "dE/dx plot generated successfully" << std::endl;
	else
		std::cout << "ERROR: could not generate dE/dx plot" << std::endl;
	pass &= ret;

	std::vector< std::vector<double> > Range_plot;
	ret = StopPow::get_Range_vs_E( s , Range_plot );
	if(ret)
		std::cout << "Range plot generated successfully" << std::endl;
	else
		std::cout << "ERROR: could not generate Range plot" << std::endl;
	pass &= ret;

	double thickness = 100; // um
	std::vector< std::vector<double> > Eout_plot_1;
	ret = StopPow::get_Eout_vs_Ein( s , thickness , Eout_plot_1 );
	if(ret)
		std::cout << "Eout vs Ein plot generated successfully" << std::endl;
	else
		std::cout << "ERROR: could not generate Eout vs Ein plot" << std::endl;
	pass &= ret;

	double Ein = 15; // MeV
	std::vector< std::vector<double> > Eout_plot_2;
	ret = StopPow::get_Eout_vs_Thickness( s , Ein , Eout_plot_2 );
	if(ret)
		std::cout << "Eout vs Thickness plot generated successfully" << std::endl;
	else
		std::cout << "ERROR: could not generate Eout vs Thickness plot" << std::endl;
	pass &= ret;

	thickness = 100; // um
	std::vector< std::vector<double> > Ein_plot_1;
	ret = StopPow::get_Ein_vs_Eout( s , thickness , Ein_plot_1 );
	if(ret)
		std::cout << "Ein vs Eout plot generated successfully" << std::endl;
	else
		std::cout << "ERROR: could not generate Ein vs Eout plot" << std::endl;
	pass &= ret;

	double Eout = 15; // MeV
	std::vector< std::vector<double> > Ein_plot_2;
	ret = StopPow::get_Ein_vs_Thickness( s , Eout , Ein_plot_2 );
	if(ret)
		std::cout << "Ein vs Thickness plot generated successfully" << std::endl;
	else
		std::cout << "ERROR: could not generate Ein vs Thickness plot" << std::endl;
	pass &= ret;

	Ein = 15;
	std::vector< std::vector<double> > Thickness_plot_1;
	ret = StopPow::get_Thickness_vs_Eout( s , Ein , Thickness_plot_1 );
	if(ret)
		std::cout << "Thickness vs Eout plot generated successfully" << std::endl;
	else
		std::cout << "ERROR: could not generate Thickness vs Eout plot" << std::endl;
	pass &= ret;

	Eout = 5;
	std::vector< std::vector<double> > Thickness_plot_2;
	ret = StopPow::get_Thickness_vs_Ein( s , Eout , Thickness_plot_2 );
	if(ret)
		std::cout << "Thickness vs Ein plot generated successfully" << std::endl;
	else
		std::cout << "ERROR: could not generate Thickness vs Ein plot" << std::endl;
	pass &= ret;

	// print if requested
	if( verbose) 
	{
		std::cout << "E (MeV) , dE/dx" << std::endl;
		for(int j=0; j<dEdx_plot[0].size(); j++)
		{
			std::cout << dEdx_plot[0][j] << "," << dEdx_plot[1][j] << std::endl;
		}
		std::cout << "--------------------------------" << std::endl;


		std::cout << "E (MeV) , Range" << std::endl;
		for(int j=0; j<Range_plot[0].size(); j++)
		{
			std::cout << Range_plot[0][j] << "," << Range_plot[1][j] << std::endl;
		}
		std::cout << "--------------------------------" << std::endl;

		std::cout << "Ein (MeV) , Eout (MeV)" << std::endl;
		for(int j=0; j<Eout_plot_1[0].size(); j++)
		{
			std::cout << Eout_plot_1[0][j] << "," << Eout_plot_1[1][j] << std::endl;
		}
		std::cout << "--------------------------------" << std::endl;

		std::cout << "Thickness , Eout (MeV)" << std::endl;
		for(int j=0; j<Eout_plot_2[0].size(); j++)
		{
			std::cout << Eout_plot_2[0][j] << "," << Eout_plot_2[1][j] << std::endl;
		}
		std::cout << "--------------------------------" << std::endl;

		std::cout << "Eout (MeV) , Ein (MeV)" << std::endl;
		for(int j=0; j<Ein_plot_1[0].size(); j++)
		{
			std::cout << Ein_plot_1[0][j] << "," << Ein_plot_1[1][j] << std::endl;
		}
		std::cout << "--------------------------------" << std::endl;

		std::cout << "Thickness , Ein (MeV)" << std::endl;
		for(int j=0; j<Ein_plot_2[0].size(); j++)
		{
			std::cout << Ein_plot_2[0][j] << "," << Ein_plot_2[1][j] << std::endl;
		}
		std::cout << "--------------------------------" << std::endl;

		std::cout << "Eout (MeV) , Thickness" << std::endl;
		for(int j=0; j<Thickness_plot_1[0].size(); j++)
		{
			std::cout << Thickness_plot_1[0][j] << "," << Thickness_plot_1[1][j] << std::endl;
		}
		std::cout << "--------------------------------" << std::endl;

		std::cout << "Ein (MeV) , Thickness" << std::endl;
		for(int j=0; j<Thickness_plot_2[0].size(); j++)
		{
			std::cout << Thickness_plot_2[0][j] << "," << Thickness_plot_2[1][j] << std::endl;
		}
		std::cout << "--------------------------------" << std::endl;

	}

	// ---------------------------------------
	//				Speed tests
	// ---------------------------------------
	std::cout << "Speed tests (ms / generation):" << std::endl;
	int n = 10;

	std::clock_t start;
	double duration;
	start = std::clock();
	for(int i=0; i<n; i++)
		ret = StopPow::get_dEdx_vs_E( s , dEdx_plot );
	// duration per call in ms:
	duration = (1000./n)*(std::clock()-start) / (double) CLOCKS_PER_SEC;
	std::cout << "dE/dx vs E = " << duration << " ms" << std::endl;

	start = std::clock();
	for(int i=0; i<n; i++)
		ret = StopPow::get_Range_vs_E( s , Range_plot );
	// duration per call in ms:
	duration = (1000./n)*(std::clock()-start) / (double) CLOCKS_PER_SEC;
	std::cout << "Range vs E = " << duration << " ms" << std::endl;

	start = std::clock();
	for(int i=0; i<n; i++)
		ret = StopPow::get_Eout_vs_Ein( s , thickness , Eout_plot_1 );
	// duration per call in ms:
	duration = (1000./n)*(std::clock()-start) / (double) CLOCKS_PER_SEC;
	std::cout << "Eout vs Ein = " << duration << " ms" << std::endl;

	start = std::clock();
	for(int i=0; i<n; i++)
		ret = StopPow::get_Eout_vs_Thickness( s , Ein , Eout_plot_2 );
	// duration per call in ms:
	duration = (1000./n)*(std::clock()-start) / (double) CLOCKS_PER_SEC;
	std::cout << "Eout vs Thickness = " << duration << " ms" << std::endl;

	start = std::clock();
	for(int i=0; i<n; i++)
		ret = StopPow::get_Ein_vs_Eout( s , thickness , Ein_plot_1 );
	// duration per call in ms:
	duration = (1000./n)*(std::clock()-start) / (double) CLOCKS_PER_SEC;
	std::cout << "Ein vs Eout = " << duration << " ms" << std::endl;

	start = std::clock();
	for(int i=0; i<n; i++)
		ret = StopPow::get_Ein_vs_Thickness( s , Eout , Ein_plot_2 );
	// duration per call in ms:
	duration = (1000./n)*(std::clock()-start) / (double) CLOCKS_PER_SEC;
	std::cout << "Ein vs Thickness = " << duration << " ms" << std::endl;

	start = std::clock();
	for(int i=0; i<n; i++)
		ret = StopPow::get_Thickness_vs_Eout( s , Ein , Thickness_plot_1 );
	// duration per call in ms:
	duration = (1000./n)*(std::clock()-start) / (double) CLOCKS_PER_SEC;
	std::cout << "Thickness vs Eout = " << duration << " ms" << std::endl;

	start = std::clock();
	for(int i=0; i<n; i++)
		ret = StopPow::get_Thickness_vs_Ein( s , Eout , Thickness_plot_2 );
	// duration per call in ms:
	duration = (1000./n)*(std::clock()-start) / (double) CLOCKS_PER_SEC;
	std::cout << "Thickness vs Ein = " << duration << " ms" << std::endl;
	
	if(pass)
	{
		std::cout << "PASS" << std::endl;
		return 0;
	}
	std::cout << "FAIL!" << std::endl;
	return 1;
}