Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added examples #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enable_language(CXX)

project(mythical VERSION "0.0.0")

set(SOVERSION 0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down
11 changes: 6 additions & 5 deletions CoarseGrainSites/include/mythical/version.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include <string>

namespace mythical {
const std::string PROJECT_NAME = "@PROJECT_NAME@";
const std::string PROJECT_VER = "@PROJECT_VERSION@";
const int PROJECT_VER_MAJOR = @PROJECT_VERSION_MAJOR@;
const int PROJECT_VER_MINOR = @PROJECT_VERSION_MINOR@;
const int PROJECT_VER_PATCH = @PROJECT_VERSION_PATCH@;
const std::string mythical_NAME = "@PROJECT_NAME@";
const std::string mythical_VER = "@PROJECT_VERSION@";
const std::string mythnical_SOVERSION = "@SOVERSION@";
const int mythical_VER_MAJOR = @PROJECT_VERSION_MAJOR@;
const int mythical_VER_MINOR = @PROJECT_VERSION_MINOR@;
const int mythical_VER_PATCH = @PROJECT_VERSION_PATCH@;
}
#endif // MYTHICAL_VERSION_HPP
3 changes: 3 additions & 0 deletions cmake/MythiCaLInstall.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

set_target_properties(mythical PROPERTIES VERSION ${mythical_VERSION} SOVERSION ${SOVERSION})

target_include_directories(mythical PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/libmythical>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/mythical>
Expand Down
Binary file added examples/1D_hopping/1D_example
Binary file not shown.
64 changes: 64 additions & 0 deletions examples/1D_hopping/1D_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <mythical/coarsegrainsystem.hpp>
#include <mythical/walker.hpp>

#include <unordered_map>
#include <vector>
#include <iostream>
#include <fstream>

using namespace std;

namespace my = mythical;

typedef std::pair<int,shared_ptr<my::Walker>> walker_t;

unordered_map<int,unordered_map<int, double>>
generateRates(const int number_of_sites) {
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;
}
return rates;
}

int main(){

int number_of_sites = 20;

unordered_map<int,unordered_map<int, double>> rates = generateRates(number_of_sites);

my::CoarseGrainSystem CGsystem;
CGsystem.setTimeResolution(3.0);
CGsystem.initializeSystem(rates);

class Charge : public my::Walker {};

int charge_id;
vector<walker_t> charges;
charges.emplace_back(charge_id, std::shared_ptr<my::Walker>( new Charge));
charges.back().second->occupySite(1);
CGsystem.initializeWalkers(charges);

const int iterations = 50;

ofstream traj_file;
traj_file.open("Trajectory.txt");
traj_file << "Number of Sites: " << number_of_sites << endl;
traj_file << "Number of iterations: " << iterations << endl;
traj_file << endl;
traj_file << "Site Dwell Time" << std::endl;

for(int iteration = 0; iteration<iterations;++iteration){
CGsystem.hop(charges.at(0));
const int site_id = charges.at(0).second->getIdOfSiteCurrentlyOccupying();
const double dwell_time = charges.at(0).second->getDwellTime();
cout << "Charge occupying site: " << site_id << " dwell time " << dwell_time << endl;
traj_file << site_id << " " << dwell_time << endl;
}

CGsystem.removeWalkerFromSystem(charges.at(0));
traj_file.close();

return 0;
}
9 changes: 9 additions & 0 deletions examples/1D_hopping/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.12)
project(1D_example)

enable_language(CXX)

find_package(MythiCaL REQUIRED)
add_executable(1D_example 1D_example.cpp)

target_link_libraries(1D_example PUBLIC mythical::mythical)
44 changes: 44 additions & 0 deletions examples/1D_hopping/scripts/create_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as pat

site=[]
dwell_Time=[]

with open("Trajectory.txt") as fid:

line = fid.readline()
words = line.split()
num_sites = int(words[3])

line = fid.readline()
words = line.split()
iterations = int(words[3])

line = fid.readline()
line = fid.readline()


for line in fid:
site.append(int(line.split()[0]))
dwell_Time.append(float(line.split()[1]))

sites = np.asarray(site)

for i in range(0,iterations):
fig = plt.figure(figsize = (num_sites+1,5))
ax = plt.gca()
for j in range(1,num_sites+1):
draw_circ = plt.Circle((j,0),0.4, color='r')
ax.add_artist(draw_circ)

draw_circ = plt.Circle((sites[i],0),0.4, color='b')
ax.add_artist(draw_circ)

ax.set_xlim(0, num_sites+1)
ax.set_ylim(-2,2)
ax.set_aspect('equal')
plt.xlabel("x axis")
plt.savefig("hop_" + str(i) + ".png")

plt.close()
1 change: 1 addition & 0 deletions examples/1D_hopping/scripts/create_movie.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ffmpeg.exe -r 4 -i hop_%d.png -vcodec libx264 -pix_fmt yuv420p output.mp4
56 changes: 56 additions & 0 deletions examples/ToF/scripts/plot_current_transient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

import numpy as np
import matplotlib.pyplot as plt

moving_avg = 5

with open("transient_current.txt",'r') as tc:
tc.readline() # Ignore header
num_pts = int(tc.readline())
time = np.zeros(num_pts)
current = np.zeros(num_pts)
current_moving_avg = np.zeros(num_pts)
charges = np.zeros(num_pts)

lines = tc.readlines()
count = 0
# Strips the newline character
for line in lines:
words = line.split()
time[count] = float(words[0])
current[count] = float(words[1])
charges[count] = int(words[2])
count = count + 1

value = 0.0
for ind in range(0,num_pts):
value = value + current[ind]
if ind < moving_avg:
current_moving_avg[ind] = value/float(ind+1)
elif ind > num_pts - moving_avg:
value = value - current[ind-moving_avg]
current_moving_avg[ind] = value/float(num_pts - ind)
else:
value = value - current[ind-moving_avg]
current_moving_avg[ind] = value/float(moving_avg)

xlim_val = 2E-9
plt.plot(time,current)
plt.plot(time,current_moving_avg)
params = {'mathtext.default': 'regular' }
plt.rcParams.update(params)
plt.xlabel("Time $[s]$")
plt.ylabel("Displacement Current $[A / cm^2]$")
plt.yscale('log')
plt.xscale('log')
plt.savefig("DisplacementCurrentLogLog.png")
plt.xscale('linear')
plt.yscale('linear')
ax = plt.gca()
plt.xlim(0,xlim_val)
# plt.ylim(0,20000)
ax2 = ax.twinx()
ax2.plot(time,charges,color='g')
ax2.set_ylabel("Number of Charges Remaining")
plt.ylim(0,210)
plt.savefig("DisplacementCurrent.png")