Example #1
0
void playSounds(){

	char data[SOUNDBURSTWRITE+1];
	for (int i = 0; i < SOUNDBURSTWRITE; i++)
		data[i] = waveFunction();	
	writeSoundValue((char*)&data,SOUNDBURSTWRITE);
}
Example #2
0
double BerylliumTwo::localEnergy(const mat &r, VMCSolver *solver)
{
    double kineticEnergy, potentialEnergy;
    int nDimensions = solver->getNDimensions();
    double charge = solver->getCharge();
    int nParticles = solver->getNParticles();

    vec nucleusHalfDistance = zeros(nDimensions);
    nucleusHalfDistance(nDimensions - 1) = solver->trialFunction()->getNucleusDistance()/2.;


//    double r1p1 = norm(r.row(0) + nucleusHalfDistance.t());
//    double r1p2 = norm(r.row(0) - nucleusHalfDistance.t());
//    double r2p1 = norm(r.row(1) + nucleusHalfDistance.t());
//    double r2p2 = norm(r.row(1) - nucleusHalfDistance.t());

//    double r12 = norm(r.row(0) - r.row(1));



    if(m_analytical)
    {
    //Calculates the kinetic energy as the ratios of -1/2* ( d²/dx²|D| /|D| + 2 * (d/dx |D|/|D|)*d/dx Psi_C/Psi_C + d²/dx² Psi_C /Psi_C )
            kineticEnergy += solver->determinant()->laplacianSlaterDeterminant(r, solver);
        if(solver->getElectronInteration())
        {
            kineticEnergy += solver->derivatives()->analyticalCorrelationDoubleDerivative(r,solver);
//            cout << solver->derivatives()->analyticalCorrelationDoubleDerivative(r,solver) << endl;
//            kineticEnergy += 2*(dot(gradientSlater, gradientJastrow ));
        }

            kineticEnergy *= -1./2.;
    }
    else
        kineticEnergy =  solver->derivatives()->numericalDoubleDerivative(r, solver) / (2.*waveFunction(r, solver));


    //Time to calculate the potential energy, this is divided into three parts, potentialenergy between the nuclei,
    //potentialenergy between the particles and potentialenergy between the electrons and the nuclei

    //If we are setting the nuclei side by side we need to make sure that 1/|R| is not included. That is accounted for by other forces
    if(!m_zeroDistance)
        potentialEnergy += charge/solver->trialFunction()->getNucleusDistance();

    //Taking away the electron electron interaction, used for some tests with Hydrogenic wavesfunctions
    if(solver->getElectronInteration())
    {
        // Contribution from electron-electron potential
        double r12 = 0;
        for(int i = 0; i < nParticles; i++) {
            for(int j = i + 1; j < nParticles; j++) {
                r12 = 0;
                for(int k = 0; k < nDimensions; k++) {
                    r12 += (r(i,k) - r(j,k)) * (r(i,k) - r(j,k));
                }
                potentialEnergy += 1. / sqrt(r12);
            }
        }
    }

    //The interaction between the electrons and the nuclei
    for(int i = 0; i < nParticles; i ++)
    {
            double rip1 = norm(r.row(i) + nucleusHalfDistance.t());
            double rip2 = norm(r.row(i) - nucleusHalfDistance.t());

            potentialEnergy -= charge*( 1./rip1 + 1./rip2  );
    }






    return kineticEnergy + potentialEnergy;
}
void generateWaveBenchmarkTimeVariant(char *destinyFileName,char *folderName,void (*waveFunction)(structMatrix,structMatrix,structMatrix*,structMatrix*)) {
	/*
	 *	Initiating the mesh
	 */

	structMatrix mesh_hmatrix,mesh_vmatrix;
	structMatrix u_matrix_timeV[N_TIME_STEPS],v_matrix_timeV[N_TIME_STEPS];

	// Initiating mesh
	mesh_hmatrix = initMatrix(N_HNODES,N_VNODES);
	mesh_vmatrix = initMatrix(N_HNODES,N_VNODES);
	loadMesh(mesh_hmatrix,mesh_vmatrix);

	char path[N_TIME_STEPS][MAX_FILENAME_LENGTH];
	generateFileNames(path,destinyFileName,folderName);



	for(int i=0; i< N_TIME_STEPS; i++) {
		//printf("path[%d]: %s\n",i,path[i]);
		// Initializing u and v matrixes
		u_matrix_timeV[i] = initMatrix(N_HNODES,N_VNODES);
		v_matrix_timeV[i] = initMatrix(N_HNODES,N_VNODES);
	}


	// Calculations are handled via callback
	// This function must calculate for every time-step!
	waveFunction(mesh_hmatrix,mesh_vmatrix,u_matrix_timeV,v_matrix_timeV);


	// Printing matrixes to files
	for(int i=0; i< N_TIME_STEPS; i++) {
		char indexu[4],indexv[4],quiverexp[30];
		sprintf(indexu,"u%d",i);
		sprintf(indexv,"v%d",i);
		sprintf(quiverexp,"quiver(x,y,%s,%s)\n",indexu,indexv);
		printMatrixToFile(u_matrix_timeV[i],path[i],indexu);
		printMatrixToFile(v_matrix_timeV[i],path[i],indexv);
		printMatrixToFile(mesh_hmatrix,path[i],"x");
		printMatrixToFile(mesh_vmatrix,path[i],"y");
		// At the end, print the "quiver" function
		FILE *destinyFile = fopen(path[i],"a");
		fprintf(destinyFile,"%s",quiverexp);
		fclose(destinyFile);
	}

	// Memory freeing
	for(int i=0; i< N_TIME_STEPS; i++) {
		destroyMatrix(u_matrix_timeV[i]);
		destroyMatrix(v_matrix_timeV[i]);
	}
	destroyMatrix(mesh_hmatrix);
	destroyMatrix(mesh_vmatrix);

	// Generate the plotter script
	char plotterName[MAX_FILENAME_LENGTH];
	FILE *plotter;
	strcpy(plotterName,"../testbench/");
	strcat(plotterName,folderName);
	strcat(plotterName,"/");
	strcat(plotterName,destinyFileName);
	strcat(plotterName,"_plotter.m");
	plotter = fopen(plotterName,"w");

		for(int i=0; i< N_TIME_STEPS; i++ ) {
			fprintf(plotter,"%s_%d \nprint -djpg %s_%d.jpg\n",destinyFileName,i,destinyFileName,i);
		}

	fclose(plotter);
}