Commit e659b2b6 authored by Manuel Schrauth's avatar Manuel Schrauth
Browse files

Merge remote-tracking branch 'origin' into 170-tidy-up-marqovdemo

parents 41abaaee 0ac88107
Pipeline #11967 failed with stages
in 22 minutes and 46 seconds
......@@ -32,13 +32,15 @@
class GraphFromCSV
{
public:
int npoints;
int npoints, ncoords;
std::vector<std::vector<int>> neighbours;
std::vector<std::vector<double>> grid;
GraphFromCSV(std::string filename)
{
npoints = import_geometry(filename, neighbours);
ncoords = import_geometry_ncoords(filename);
npoints = import_geometry(filename, grid, neighbours, ncoords);
}
std::vector<int> nbrs(const int a, const int i) const
......@@ -46,31 +48,6 @@ class GraphFromCSV
return neighbours[i];
}
std::size_t size() const {return npoints;}
};
/* Read graph with coordinates from csv file.
* @note for format specifications see general documentation
*/
class GraphFromCSVwithCoords
{
public:
int npoints;
std::vector<std::vector<int>> neighbours;
std::vector<std::vector<double>> grid;
GraphFromCSVwithCoords(std::string filename, int ncoords)
{
npoints = import_geometry(filename, grid, neighbours, ncoords, false);
}
std::vector<int> nbrs(const int a, const int i) const
{
return neighbours[i];
}
std::vector<double> crds(const int i) const
{
return grid[i];
......@@ -78,4 +55,5 @@ class GraphFromCSVwithCoords
std::size_t size() const {return npoints;}
};
#endif
......@@ -22,6 +22,8 @@
#include <string>
#include <fstream>
/**
* export coordinates and neighbour relations
*
......@@ -53,34 +55,19 @@ void save_geometry(Grid& grid, const std::string path)
/**
* export coordinates, neighbour relations and bond strengths
* @brief Import header line of CSV graph which contains only a single number (the number of coordinates)
*
* @tparam Grid the type of the lattice
* @param grid the lattice
* @param path directory in which the geometry is to be stored
* @param path filename including full path
*
* @return return the number of coordinates as an integer (can be zero)
*/
template <class Grid>
void save_geometry_deluxe(Grid& grid, const std::string path)
int import_geometry_ncoords(std::string path)
{
std::ofstream os;
os.open(path.c_str());
os << std::fixed << std::setprecision(16);
for (int i=0; i<grid.size(); i++)
{
auto nbrs = grid.nbrs(0,i);
auto crds = grid.crds(i);
auto bnds = grid.getbnds(0,i);
os << nbrs.size() + crds.size() + bnds.size();
for (int j=0; j<crds.size(); j++) os << "\t" << crds[j];
for (int j=0; j<nbrs.size(); j++) os << "\t" << nbrs[j];
for (int j=0; j<bnds.size(); j++) os << "\t" << bnds[j];
os << std::endl;
}
std::ifstream in(NULL);
in.open(path.c_str());
std::string row;
std::getline(in, row);
return std::stoi(row);
}
......@@ -104,7 +91,11 @@ int import_geometry(const std::string path, std::vector<std::vector<double>>& gr
in.open(path.c_str());
std::string row;
// loop over lines
// jump over header (two lines)
std::getline(in, row);
std::getline(in, row);
// loop over lines containing the geometry
while (!in.eof())
{
std::getline(in, row);
......@@ -134,49 +125,4 @@ int import_geometry(const std::string path, std::vector<std::vector<double>>& gr
return nbrs.size();
}
/**
* @brief Import neighbour relations from CSV file
*
* @param path filename including full path
* @param grid here the coordinates will be stored
* @param minusone set false if indices in CSV file are counted from zero (default), set true if they are counted from one
*
* @return the number of vertices
*
* @note for format specifications see general documentation-
*/
int import_geometry(const std::string path, std::vector<std::vector<int>>& nbrs, bool minusone=false)
{
int reduce = 0;
if (minusone) reduce = -1;
std::ifstream in(NULL);
in.open(path.c_str());
std::string row;
while (!in.eof())
{
std::getline(in, row);
if (in.bad() || in.fail())
{
break;
}
std::istringstream ss(row);
std::string substr;
std::vector<int> n;
while(std::getline(ss, substr, '\t'))
{
n.push_back(std::stoi(substr)+reduce);
}
nbrs.push_back(n);
}
return nbrs.size();
}
#endif
......@@ -58,6 +58,9 @@ static int instantiatesim(const std::string& path, Lattice& mylatt, const HamPar
return 0;
}
/** Create a single instance of the Ising Model
*
* @see Ising.h
......@@ -70,41 +73,47 @@ static int instantiatesim(const std::string& path, Lattice& mylatt, const HamPar
*/
int pyIsing(std::string path, int dim, int len, double beta, double J)
{
RegularHypercubic mylatt(len, dim); //nD len x len lattice
// A section for setting our Hamiltonian parameters, J, and the inverse temperature beta
// Construct hypercubic regular lattice of linear length len and dimension dim
RegularHypercubic mylatt(len, dim);
// Set Hamiltonian parameters, the coupling J, and the inverse temperature beta
auto hp = make_tuple(beta, J);
// Create and run a single simulation
return instantiatesim<RegularHypercubic, Ising<double>>(path, mylatt, hp);
}
/*
int pyIsingGraph(std::string outpath, std::string graphpath, double beta, double J)
{
GraphFromCSV graph(graphpath);//load lattice from a graph specification
// A section for setting our Hamiltonian parameters, J, and the inverse temperature beta
// Load lattice from a graph specification
GraphFromCSV graph(graphpath);
// Set Hamiltonian parameters, the coupling J, and the inverse temperature beta
auto hp = make_tuple(beta, J);
// Create and run a single simulation
return instantiatesim<GraphFromCSV, Ising<double>>(outpath, graph, hp);
}*/
}
int pyHeisenberg(std::string path, int dim, int len, double beta, double J)
{
RegularHypercubic mylatt(len, dim); //nD len x len lattice
// A section for setting our Hamiltonian parameters, J, and the inverse temperature beta
RegularHypercubic mylatt(len, dim);
auto hp = make_tuple(beta, J);
return instantiatesim<RegularHypercubic, Heisenberg<double, double> >(path, mylatt, hp);
}
int pyHeisenbergGraph(std::string outpath, std::string graphpath, double beta, double J)
{
GraphFromCSV graph(graphpath);//load lattice from a graph specification
// A section for setting our Hamiltonian parameters, J, and the inverse temperature beta
GraphFromCSV graph(graphpath);
auto hp = make_tuple(beta, J);
return instantiatesim<GraphFromCSV, Heisenberg<double, double>>(outpath, graph, hp);
}
int pyPhi4(std::string path, int dim, int len, double beta, double lambda, double mass)
{
RegularHypercubic mylatt(len, dim); //nD len x len lattice
// A section for setting our Hamiltonian parameters, J, and the inverse temperature beta
RegularHypercubic mylatt(len, dim);
auto hp = make_tuple(beta, beta, lambda, mass);
return instantiatesim<RegularHypercubic, Phi4<double, double> >(path, mylatt, hp);
......@@ -112,44 +121,40 @@ int pyPhi4(std::string path, int dim, int len, double beta, double lambda, doubl
int pyAshkinTeller(std::string path, int dim, int len, double beta, double J, double K)
{
RegularHypercubic mylatt(len, dim); //nD len x len lattice
// A section for setting our Hamiltonian parameters, and beta
RegularHypercubic mylatt(len, dim);
auto hp = make_tuple(beta, J, K);
return instantiatesim<RegularHypercubic, AshkinTeller >(path, mylatt, hp);
}
int pyAshkinTellerGraph(std::string outpath, std::string graphpath, double beta, double J, double K)
{
GraphFromCSV graph(graphpath);//load lattice from a graph specification
// A section for setting our Hamiltonian parameters, and beta
GraphFromCSV graph(graphpath);
auto hp = make_tuple(beta, J, K);
return instantiatesim<GraphFromCSV, AshkinTeller >(outpath, graph, hp);
}
int pyBlumeCapel(std::string path, int dim, int len, double beta, double J, double D)
{
RegularHypercubic mylatt(len, dim); //nD len x len lattice
// A section for setting our Hamiltonian parameters, and beta
RegularHypercubic mylatt(len, dim);
auto hp = make_tuple(beta, J, D);
return instantiatesim<RegularHypercubic, BlumeCapel<int> >(path, mylatt, hp);
}
int pyBlumeCapelGraph(std::string outpath, std::string graphpath, double beta, double J, double D)
{
GraphFromCSV graph(graphpath);//load lattice from a graph specification
// A section for setting our Hamiltonian parameters, and beta
GraphFromCSV graph(graphpath);
auto hp = make_tuple(beta, J, D);
return instantiatesim<GraphFromCSV, BlumeCapel<int> >(outpath, graph, hp);
}
int pyBEG(std::string path, int dim, int len, double beta, double J, double D, double K)
{
RegularHypercubic mylatt(len, dim); //nD len x len lattice
// A section for setting our Hamiltonian parameters, and beta
RegularHypercubic mylatt(len, dim);
auto hp = make_tuple(beta, J, D, K);
return instantiatesim<RegularHypercubic, BlumeEmeryGriffiths<int> >(path, mylatt, hp);
}
template <class Lattice, class HamParms>
static int instantiatePotts(int q, const std::string& path, Lattice&& mylatt, const HamParms& hp)
{
......@@ -185,9 +190,7 @@ static int instantiatePotts(int q, const std::string& path, Lattice&& mylatt, co
int pyPotts(int q, std::string path, int dim, int len, double beta, double J)
{
RegularHypercubic mylatt(len, dim); //nD len x len lattice
// A section for setting our Hamiltonian parameters, and beta
RegularHypercubic mylatt(len, dim);
auto hp = make_tuple(beta, J);
return instantiatePotts(q, path, mylatt, hp);
}
......@@ -5,6 +5,7 @@
#include <string>
int pyIsing(std::string path, int dim, int len, double beta, double J);
int pyIsingGraph(std::string outpath, std::string graphpath, double beta, double J);
int pyHeisenberg(std::string path, int dim, int len, double beta, double J);
int pyHeisenbergGraph(std::string outpath, std::string graphpath, double beta, double J);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment