Skip to content

Commit

Permalink
dockerfile and json support
Browse files Browse the repository at this point in the history
  • Loading branch information
jwdeitch committed Oct 14, 2018
1 parent d1022e3 commit 62c80db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
20 changes: 13 additions & 7 deletions Algorithm/MonteCarlo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@

#include "MonteCarlo.hpp"
#include "../Model/Model.hpp"
#include <nlohmann/json.hpp>

using json = nlohmann::json;

void MonteCarlo::simulate(int nitr, Model *model_ptr) {
std::ofstream output;
output.open("output.json");

json output_json = {
{"type", "common_origin"}, {"data", {} }
};

model_ptr->create_initial_spin_configuration();

output << R"({"type": "common_origin", "data": [)";



int accepted_counter = 0;
output << model_ptr->save_spin_configuration(accepted_counter).str();
output_json["data"].push_back(model_ptr->save_spin_configuration(accepted_counter).str());

for (int i = 0; i < nitr; i++) {
uword random_index = randi<umat>(1, 1, distr_param(0, (model_ptr->system_size) - 1))(0);
Expand All @@ -22,13 +29,12 @@ void MonteCarlo::simulate(int nitr, Model *model_ptr) {
double change_eng = model_ptr->energy_change(random_index, new_s);

if (change_eng < 0.0) {
output << ", ";
model_ptr->update_spin_configuration(random_index, new_s);
accepted_counter++;
output << model_ptr->save_spin_configuration(accepted_counter).str();
output_json["data"].push_back(model_ptr->save_spin_configuration(accepted_counter).str());
}
}

output << "]}";
output << output_json.dump();
output.close();
}
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.10)
project(Simulation)
project(MCSM)

set(CMAKE_CXX_STANDARD 11)

find_library(Simulation libarmadillo)
find_library(MCSM libarmadillo)

add_executable(Simulation main.cpp Model/Model.hpp Model/Heisenberg.cpp Algorithm/MonteCarlo.cpp Lattice/Lattice.hpp Model/Heisenberg.hpp Algorithm/MonteCarlo.hpp Algorithm/Algorithm.hpp)
add_executable(MCSM main.cpp Model/Model.hpp Model/Heisenberg.cpp Algorithm/MonteCarlo.cpp Lattice/Lattice.hpp Model/Heisenberg.hpp Algorithm/MonteCarlo.hpp Algorithm/Algorithm.hpp)

target_link_libraries(Simulation armadillo)
target_link_libraries(MCSM armadillo)
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
FROM ubuntu:18.10
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y g++ git cmake
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y g++ git cmake nlohmann-json-dev libarmadillo-dev

COPY . /usr/local
WORKDIR /usr/local/cmake-build-debug

WORKDIR /usr/local/

RUN cmake . && make

CMD ./MCSM ## docker build -t mcsm . && docker run mcsm

0 comments on commit 62c80db

Please sign in to comment.