Repository navigation
2. I.b Tutorial CTS Implementation
Here we have created a 20 site system. Each site is connected to it's two nearest neighbors with the exception of the two end sites.

A charge is created which inherits from the random walker class. A single charge is created from the Charge class and is given an id of 0 and initially placed on site 1. The charge is then allowed to hop between the sites using the built in KMC engine by calling the hop function. The charges dwell time and the site it occupies is updated each time the hop() function is called. The rates have been setup so that it is much more favorable to hop towards the neighboring site with the largest id.
// test.cpp
#include <kmccoarsegrain/kmc_coarsegrainsystem.hpp>
#include <kmccoarsegrain/kmc_walker.hpp>
#include <unordered_map>
#include <vector>
#include <iostream>
using namespace std;
using namespace kmccoarsegrain;
int main(){
int number_of_sites = 20;
unordered_map<int,unordered_map<int, double>> rates;
for(int i=1 ; i<number_of_sites; ++i){
rates[i][i+1]=3.0;
rates[i+1][i]=1.0;
}
KMC_CoarseGrainSystem CGsystem;
CGsystem.setTimeResolution(3.0);
CGsystem.initializeSystem(rates);
class Charge : public KMC_Walker {};
vector<pair<int,KMC_Walker>> charges;
Charge charge;
charge.occupySite(1);
charges.push_back(pair<int,KMC_Walker>(0,charge));
CGsystem.initializeWalkers(charges);
int iterations = 20;
for(int iteration = 0; iteration<iterations;++iteration){
CGsystem.hop(charges.at(0));
int site_id = charges.at(0).second.getIdOfSiteCurrentlyOccupying();
double dwell_time = charges.at(0).second.getDwellTime();
cout << "Charge occupying site: " << site_id << " dwell time " << dwell_time << endl;
}
CGsystem.removeWalkerFromSystem(charges.at(0));
return 0;
}
gcc test.cpp -o test -lstdc++ -I/usr/local/include/kmccoarsegrain -L/usr/local/lib/kmccoarsegrain -lkmccoarsegrain
Notice that the dwell time varies during each hop even though the rates are the same off each site. This is because though the sites will have a time constant that is the same the dwell time is calculated from the dwell time using a random number X with the equation:

The random number
is a value between 0 and 1 and changes each time the hop function is called.
export LD_LIBRARY_PATH=/usr/local/lib/kmccoarsegrain
./test
Charge occupying site: 2 dwell time 0.422175
Charge occupying site: 1 dwell time 0.358142
Charge occupying site: 2 dwell time 0.346855
Charge occupying site: 3 dwell time 0.123077
Charge occupying site: 4 dwell time 0.173075
Charge occupying site: 5 dwell time 0.413991
Charge occupying site: 4 dwell time 0.335752
Charge occupying site: 5 dwell time 0.0259773
Charge occupying site: 6 dwell time 0.0222147
Charge occupying site: 7 dwell time 0.0545392
Charge occupying site: 8 dwell time 0.214363
Charge occupying site: 9 dwell time 0.0853959
Charge occupying site: 10 dwell time 0.513267
Charge occupying site: 11 dwell time 0.131025
Charge occupying site: 12 dwell time 1.20267
Charge occupying site: 13 dwell time 0.00404967
Charge occupying site: 12 dwell time 0.26887
Charge occupying site: 13 dwell time 0.119876
Charge occupying site: 14 dwell time 0.436987
Charge occupying site: 15 dwell time 0.0513455