Ejemplo n.º 1
0
void System::removeTotalMomentum()
{
    StatisticsSampler sampler;
    vector<double> momentum = sampler.calculateTotalMomentum(shared_from_this());

    if(numberOfAtoms() > 0) {
        momentum[0] /= numberOfAtoms();
        momentum[1] /= numberOfAtoms();
        momentum[2] /= numberOfAtoms();
    }

    atomManager().atoms().iterate([&](Atom &atom) {
        atom.velocity[0] -= momentum[0]*atom.type()->massInverse();
        atom.velocity[1] -= momentum[1]*atom.type()->massInverse();
        atom.velocity[2] -= momentum[2]*atom.type()->massInverse();
    });
}
Ejemplo n.º 2
0
std::ostream& operator<<(std::ostream &stream, System &system) {
    StatisticsSampler sampler;

    stream << "System information:" << endl;
    stream << "Length [Å]: " << UnitConverter::lengthToAngstroms(system.systemLength()) << endl;
    stream << "Number of atoms: " << system.numberOfAtoms() << endl;
    stream << "Number of ghost atoms: " << system.numberOfGhostAtoms() << endl;
    stream << "Potentials (" << system.potentials().size() << "): " << endl;
    for(Potential *potential : system.potentials()) {
        stream << "   " << potential->name() << endl;
    }
    std::shared_ptr<System> system_ptr(&system);

    vector<double> momentum = sampler.calculateTotalMomentum(system_ptr);
    stream << "Total momentum: (" << momentum.at(0) << "," << momentum.at(1) << "," << momentum.at(2) << ")";
    return stream;
}
Ejemplo n.º 3
0
int main() {
    double dt = UnitConverter::timeFromSI(1e-14);

    System system;
    VelocityVerlet *integrator = new VelocityVerlet();
    //EulerCromer *integrator = new EulerCromer();
    system.setIntegrator(integrator);
    system.createFCCLattice(5, UnitConverter::lengthFromAngstroms(5.26), 700.0);
    system.removeMomentum();
    LennardJones *potential = new LennardJones(3.405, 1.);
    system.setPotential(potential);
    StatisticsSampler statisticsSampler;
    Thermostat thermostat(&statisticsSampler, &system);
    thermostat.setThermostat(false);
    Neighbourlists neighbourlist(&system);

    IO *output = new IO();
    output->open((char *)"output.dat");
    IO *movie = new IO();
    movie->open((char *)"movie.xyz");
    movie->saveState(system);
    for(int timestep=0; timestep<1000; timestep++) {
        system.step(dt, thermostat, neighbourlist);
        statisticsSampler.sample(system);
        movie->saveState(system);
        //if(timestep % 10 == 0) {
            output->saveOutput(system, statisticsSampler);
        //}
        if(timestep % 100 == 0) {
            cout << timestep << endl;
        }
    }
    statisticsSampler.getEnergyVariance();
    cout << "The standard deviation of the energy is:" << statisticsSampler.energyTotalVariance << endl;
    movie->close();
    output->close();

    return 0;
}
Ejemplo n.º 4
0
int main(int numberOfArguments, char **argumentList)
{
    omp_set_num_threads(8);  // initialize OpenMP

    //DEFAULT PARAMETERS:
    int numberOfUnitCells = 5;
    double initialTemperature = UnitConverter::temperatureFromSI(1500.0); // measured in Kelvin
    double latticeConstant = UnitConverter::lengthFromAngstroms(5.26);   // measured in angstroms
    double dt = UnitConverter::timeFromSI(1e-15);                        // measured in seconds

    // USER DEFINED PARAMETERS:
    if(numberOfArguments > 1) numberOfUnitCells = atoi(argumentList[1]);
    if(numberOfArguments > 2) initialTemperature = UnitConverter::temperatureFromSI(atof(argumentList[2]));
    if(numberOfArguments > 3) latticeConstant = UnitConverter::lengthFromAngstroms(atof(argumentList[3]));
    if(numberOfArguments > 4) dt = UnitConverter::timeFromSI(atof(argumentList[4]));

    // PRINT DIMENSION SCALING FACTORS:
    cout << "One unit of length is " << UnitConverter::lengthToSI(1.0) << " meters" << endl;
    cout << "One unit of velocity is " << UnitConverter::velocityToSI(1.0) << " meters/second" << endl;
    cout << "One unit of time is " << UnitConverter::timeToSI(1.0) << " seconds" << endl;
    cout << "One unit of mass is " << UnitConverter::massToSI(1.0) << " kg" << endl;
    cout << "One unit of temperature is " << UnitConverter::temperatureToSI(1.0) << " K" << endl;
    for(double T =  UnitConverter::temperatureFromSI(100.0); T < UnitConverter::temperatureFromSI(3000.0); T +=  UnitConverter::temperatureFromSI(100.0)){
    // CREATE AND INITIALIZE THE LATTICE:
    System system;
    bool NoBoundaries = 0;      // flag to tigger boundary conditions
    system.createFCCLattice(numberOfUnitCells, latticeConstant, T);
    system.setPotential(new LennardJones(UnitConverter::lengthFromAngstroms(3.405),
                                         UnitConverter::temperatureFromSI(119.8)));
    system.setIntegrator(new VelocityVerlet());
    system.removeTotalMomentum();

    StatisticsSampler statisticsSampler;
    /*
    IO movie, data;
    movie.open("movie.xyz", 1);
    data.open("data.txt", 0);
    movie.saveState(&system);
    cout << "Timestep Time Temperature KineticEnergy PotentialEnergy TotalEnergy" << endl;
    for(int timestep=0; timestep<20000; timestep++) {
        if(NoBoundaries) system.stepNoBoundaries(dt);
        else system.step(dt);
        statisticsSampler.sample(system);
        data.saveStatistcalData(&system, &statisticsSampler);
        if( !(timestep % 100) ) {
            cout << system.steps() << "      "
                 << UnitConverter::timeToSI(system.time()) << "      "
                 << UnitConverter::temperatureToSI(statisticsSampler.temperature()) << "      "
                 << statisticsSampler.kineticEnergy() << "      "
                 << statisticsSampler.potentialEnergy() << "      "
                 << statisticsSampler.totalEnergy()<< "      "
                 << statisticsSampler.diffusionConstant()<< "      "
                 << statisticsSampler.pressure()<< "      "
                 << statisticsSampler.momentum()
                 << endl;
            movie.saveState(&system);
        }
    }

    movie.close(1);
    data.close(0);

    */
    double N = 3000;
    for(int timestep=0; timestep<N; timestep++) {
        system.step(dt);
    }
    double D = 0.0;
    double D2 = 0.0;
    for(int timestep=0; timestep<N; timestep++) {
        system.step(dt);
        statisticsSampler.sample(system);
        D+=statisticsSampler.diffusionConstant();
        D2+=statisticsSampler.diffusionConstant()*statisticsSampler.diffusionConstant();
    }
    D2 = sqrt(D2/N - D/N*D/N);
    printf("%.f,    %.15f,    %.15f\n", UnitConverter::temperatureToSI(statisticsSampler.temperature()),
                                        UnitConverter::diffusionToSI(D/N),
                                        UnitConverter::diffusionToSI(D2));
    }

    return 0;
}
Ejemplo n.º 5
0
int main(int numberOfArguments, char **argumentList)
{
    //omp_set_num_threads(8);  // initialize OpenMP

    //DEFAULT PARAMETERS:
    int numberOfUnitCells = 10;
    double initialTemperature = UnitConverter::temperatureFromSI(300.0); // measured in Kelvin
    double latticeConstant = UnitConverter::lengthFromAngstroms(5.26);   // measured in angstroms
    double dt = UnitConverter::timeFromSI(1e-15);                        // measured in seconds

    // USER DEFINED PARAMETERS:
    if(numberOfArguments > 1) numberOfUnitCells = atoi(argumentList[1]);
    if(numberOfArguments > 2) initialTemperature = UnitConverter::temperatureFromSI(atof(argumentList[2]));
    if(numberOfArguments > 3) latticeConstant = UnitConverter::lengthFromAngstroms(atof(argumentList[3]));
    if(numberOfArguments > 4) dt = UnitConverter::timeFromSI(atof(argumentList[4]));

    // PRINT DIMENSION SCALING FACTORS:
    cout << "One unit of length is " << UnitConverter::lengthToSI(1.0) << " meters" << endl;
    cout << "One unit of velocity is " << UnitConverter::velocityToSI(1.0) << " meters/second" << endl;
    cout << "One unit of time is " << UnitConverter::timeToSI(1.0) << " seconds" << endl;
    cout << "One unit of mass is " << UnitConverter::massToSI(1.0) << " kg" << endl;
    cout << "One unit of temperature is " << UnitConverter::temperatureToSI(1.0) << " K" << endl;

    // CREATE AND INITIALIZE THE LATTICE:
    System system;
    system.createFCCLattice(numberOfUnitCells, latticeConstant, initialTemperature);
    double sigma = UnitConverter::lengthFromAngstroms(3.405);
    double epsilon = UnitConverter::temperatureFromSI(119.8);
    system.setPotential(new LennardJones(sigma, epsilon));
    system.potential()->rCut = 2.5*sigma;
    system.potential()->rShell = 0.3*sigma;
    system.setIntegrator(new VelocityVerlet());
    system.setThermostat(new Thermostat(UnitConverter::timeFromSI(1e-13),
                                        UnitConverter::temperatureFromSI(300.0)));
    system.removeTotalMomentum();
    system.thermostat()->setOff();

    int numberOfTimesteps = 2000;

    StatisticsSampler statisticsSampler;
    IO movie, data;
    movie.open("movie.xyz", 1);
    data.open("data.txt", 0);
    movie.saveState(&system);
    cout << "Timestep   Time  Temperature   KineticEnergy  PotentialEnergy"
         << "TotalEnergy   DiffusionK   Pressure    Momentum" << endl;


    for(int timestep=0; timestep<numberOfTimesteps; timestep++) {
            system.step(dt);
            statisticsSampler.sample(system);
            data.saveStatistcalData(&system, &statisticsSampler);
            if( !(timestep % 100) ) {
                cout << system.steps() << "      "
                     << UnitConverter::timeToSI(system.time()) << "      "
                     << UnitConverter::temperatureToSI(statisticsSampler.temperature()) << "      "
                     << statisticsSampler.kineticEnergy() << "      "
                     << statisticsSampler.potentialEnergy() << "      "
                     << statisticsSampler.totalEnergy()<< "      "
                     << statisticsSampler.diffusionConstant()<< "      "
                     << UnitConverter::pressureToSI(statisticsSampler.pressure())<< "      "
                     << statisticsSampler.momentum()
                     << endl;
                movie.saveState(&system);
            }
        }

        movie.close(1);
        data.close(0);
    return 0;
}
Ejemplo n.º 6
0
int main(int numberOfArguments, char **argumentList)
{
    clock_t executionTimeStart, executionTimeFinish;
    executionTimeStart = clock();

    int numberOfUnitCells = 5;
    double initialTemperature = UnitConverter::temperatureFromSI(2000.0); // measured in Kelvin
    double latticeConstant = UnitConverter::lengthFromAngstroms(5.26); // measured in angstroms
    double dt = UnitConverter::timeFromSI(5e-15); // Measured in seconds
    int integratorNumber = 2; //initially set to Velocity Verlet, 1 is Euler-Cromer
    int numberOfTimesteps = 1000;

    // If a first argument is provided, it is the number of unit cells
    if(numberOfArguments > 1) numberOfUnitCells = atoi(argumentList[1]);
    // If a second argument is provided, it is the initial temperature (measured in MD units)
    if(numberOfArguments > 2) initialTemperature = atof(argumentList[2]);
    // If a third argument is provided, it is the lattice constant determining the density (measured in MD units)
    if(numberOfArguments > 3) latticeConstant = atof(argumentList[3]);
    // If a fourth argument is provided, it is the time step length dt (measured in MD units)
    if(numberOfArguments > 4) dt = atof(argumentList[4]);
    // If a fifth argument is provided, it is the integrator number
    if(numberOfArguments > 5) integratorNumber = atoi(argumentList[5]);
    // If a sixth argument is provided, it is the number of timesteps
    if(numberOfArguments > 6) numberOfTimesteps = atoi(argumentList[6]);

    /* // Possible to print the MD units used in the simulation
    cout << "One unit of length is " << UnitConverter::lengthToSI(1.0) << " meters" << endl;
    cout << "One unit of velocity is " << UnitConverter::velocityToSI(1.0) << " meters/second" << endl;
    cout << "One unit of time is " << UnitConverter::timeToSI(1.0) << " seconds" << endl;
    cout << "One unit of mass is " << UnitConverter::massToSI(1.0) << " kg" << endl;
    cout << "One unit of temperature is " << UnitConverter::temperatureToSI(1.0) << " K" << endl;
    */

    System system;

    system.createFCCLattice(numberOfUnitCells, latticeConstant, initialTemperature);
    system.setPotential(new LennardJones(3.405, 1.0));

    if(integratorNumber == 1) system.setIntegrator(new EulerCromer());
    else if(integratorNumber == 2) system.setIntegrator(new VelocityVerlet());

    system.removeTotalMomentum();

    StatisticsSampler statisticsSampler;
    IO statisticsFile; // To write statistics to file for plotting
    IO movie; // To write the state to file to look at in Ovito

    if(numberOfArguments > 5){ // making unique filenames for plotting with python
        string filenameStatistics = "run_plot_python_output/statistics_file_NrOfCells" + to_string(numberOfUnitCells) + "_T" + to_string(int(initialTemperature*1000)) + "_b" + to_string(int(latticeConstant*1000)) + "_dt" + to_string(int(dt*10000)) + "_int" + to_string(integratorNumber) + ".txt";
        statisticsFile.open(filenameStatistics.c_str());
        string filenameMovie = "run_plot_python_output/movie_NrOfCells" + to_string(numberOfUnitCells) + "_T" + to_string(int(initialTemperature*1000)) + "_b" + to_string(int(latticeConstant*1000)) + "_dt" + to_string(int(dt*10000)) + "_int" + to_string(integratorNumber) + ".xyz";
        movie.open(filenameMovie.c_str());
    }
    else{
        statisticsFile.open("statistics_file.txt");
        movie.open("movie.xyz");
    }

    cout << "Timestep Time Temperature KineticEnergy PotentialEnergy TotalEnergy DiffusionConstant MeanSquareDisplacement" << endl;
    for(int timestep=0; timestep<numberOfTimesteps; timestep++) {
        //movie.saveState(&system); //including also the starting position in the movie, uncomment to write to movie file

        system.step(dt); //moving the particle one step

        statisticsSampler.sample(system);
        statisticsFile.saveStatistics(&system, &statisticsSampler, 0); //output done here

        if( !(timestep % 100) ) {
            // Print the timestep every 100 timesteps
            cout << system.steps() << "      " << system.time() << "      " << statisticsSampler.temperature() << "      " << statisticsSampler.kineticEnergy() << "      " << statisticsSampler.potentialEnergy() << "      " << statisticsSampler.totalEnergy() << "      " << statisticsSampler.diffusionConstant() << "      " << statisticsSampler.meanSquareDisplacement() << endl;
        }
    }

    movie.close();

    executionTimeFinish = clock();
    double totalExecutionTime = (( executionTimeFinish - executionTimeStart )/double(CLOCKS_PER_SEC ));
    cout << "Execution time: " << totalExecutionTime << endl;

    statisticsFile.saveStatistics(&system, &statisticsSampler, totalExecutionTime);
    statisticsFile.close();

    return 0;
}