Commit 9ed6f9f0 authored by Hylke Donker's avatar Hylke Donker
Browse files

Forgot what changed!

parent 56191c31
......@@ -2,21 +2,21 @@ cmake_minimum_required( VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
set( CMAKE_VERBOSE_MAKEFILE on )
project(pyspin)
add_library(pyspin SHARED projection.cpp psi.cpp pyspin.cpp hamiltonian.cpp spin_system.cpp hamiltonian_heisenberg.cpp hamiltonian_kagome.cpp hamiltonian_flower.cpp heisenberg_nnn.cpp ladder.cpp)
add_library(pyspin SHARED projection.cpp psi.cpp pyspin.cpp hamiltonian.cpp spin_system.cpp hamiltonian_heisenberg.cpp hamiltonian_kagome.cpp hamiltonian_flower.cpp heisenberg_nnn.cpp hamiltonian_lieb_mattis.cpp ladder.cpp )
set_target_properties(pyspin PROPERTIES PREFIX "")
find_package(Boost 1.46 COMPONENTS python REQUIRED)
find_package( PythonLibs 2.7 REQUIRED)
#find_package( LAPACK REQUIRED)
find_package( LAPACK REQUIRED)
set(MKL_USE_STATIC_LIBS ON)
find_package(MKL)
if (MKL_FOUND)
include_directories(${MKL_INCLUDE_DIRS})
link_directories(${MKL_LIBRARY_DIRS})
target_link_libraries(pyspin ${MKL_LIBRARIES})
else()
find_package(LAPACK REQUIRED)
target_link_libraries(pyspin ${LAPACK_LIBRARIES})
endif()
#find_package(MKL)
#if (MKL_FOUND)
# include_directories(${MKL_INCLUDE_DIRS})
# link_directories(${MKL_LIBRARY_DIRS})
# target_link_libraries(pyspin ${MKL_LIBRARIES})
#else()
# find_package(LAPACK REQUIRED)
# target_link_libraries(pyspin ${LAPACK_LIBRARIES})
#endif()
#set_property(TARGET pyspin PROPERTY CXX_STANDARD 11)
#set_property(TARGET pyspin PROPERTY CXX_STANDARD_REQUIRED ON)
if(CMAKE_COMPILER_IS_GNUCXX)
......@@ -26,5 +26,5 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif(CMAKE_COMPILER_IS_GNUCXX)
INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
#TARGET_LINK_LIBRARIES ( pyspin ${Boost_LIBRARIES} ${LAPACK_LIBRARIES})
TARGET_LINK_LIBRARIES (pyspin ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES ( pyspin ${Boost_LIBRARIES} ${LAPACK_LIBRARIES})
#TARGET_LINK_LIBRARIES (pyspin ${Boost_LIBRARIES})
from numpy import testing
from numpy import *
import bits
import sys
import ctypes
def calc_S2(psi):
N = psi.get_size()
S2=N*0.75
for l in range(N):
for k in range(l+1, N):
Slk =pyspin.correlation(psi, l,k)
S2 += 2*sum(Slk)
return S2
flags = sys.getdlopenflags()
sys.setdlopenflags(flags|ctypes.RTLD_GLOBAL)
import pyspin
sys.setdlopenflags(flags)
lmsys = pyspin.lieb_mattis_system(4)
lmsys.initialize()
psi0 = array(lmsys.groundstate().get())
hhsys = pyspin.heisenberg_system(4, True)
hhsys.initialize()
psi0p = array(hhsys.groundstate().get())
testing.assert_almost_equal(absolute(dot(psi0, psi0p)), 1.0)
# TODO:
# Do some more unit testing to check that ground state is indeed singlet, etc.
lmsys2 = pyspin.lieb_mattis_system(6)
lmsys2.initialize()
testing.assert_almost_equal(calc_S2(lmsys2.groundstate()), 0)
......@@ -188,7 +188,9 @@ int heisenberg_local_field_system::initialize()
throw std::out_of_range("Minimum number of spins is 2.");
build();
diagonalize_real(); // Only magnetic field along z-direction, Hamiltonian is purely real!
//diagonalize_real(); // Only magnetic field along z-direction, Hamiltonian is purely real!
build_subsp();
blockwise_diagonalise();
_initialized = true;
return 0;
......
......@@ -28,7 +28,7 @@ public:
int build();
};
class heisenberg_hamiltonian_local_field : public hamiltonian , public heisenberg_parameters //, public hamiltonian_functions
class heisenberg_hamiltonian_local_field : public hamiltonian_subsp , public heisenberg_parameters //, public hamiltonian_functions
{
public:
heisenberg_hamiltonian_local_field(int num_spin, bool periodic = true, double Jx = 1.0, double Jy = 1.0, double Jz = 1.0);
......
#include "hamiltonian_lieb_mattis.h"
lieb_mattis_hamiltonian::lieb_mattis_hamiltonian(int num_spin, double Jx, double Jy, double Jz) : J_x(Jx), J_y(Jy), J_z(Jz)
{
if(num_spin % 2 != 0)
throw std::range_error("Number of spins must be even in Lieb-Mattis Hamiltonian.");
N = num_spin;
dim = pow(2,N);
}
int lieb_mattis_hamiltonian::build()
{
// Allocate memory for matrix
_matrix.resize(dim*dim);
// loop through matrix elements
for(unsigned int k = 0; k < dim; k++)
{
// Loop through sublattice A; even sites: 2i
for(unsigned int i = 0; i < N/2; i++)
{
// Loop through sublattice B; odd-sites 2j+1
for(unsigned int j = 0; j < N/2; j++)
{
// Calculate first diagonal elements
_matrix[k+dim*k] += J_z * S_zS_z(2*i, 2*j+1, k);
// Calculate also off-diagonal elements
for (unsigned int l = 0; l < dim; l++)
{
_matrix[k*dim+l] += J_x*S_xS_x(2*i, 2*j+1, k, l);
_matrix[k*dim+l] += J_y*S_yS_y(2*i, 2*j+1, k, l);
}
}
}
}
_hamiltonian_constructed = true;
return EXIT_SUCCESS;
}
lieb_mattis_system::lieb_mattis_system(int num_spin, double Jx, double Jy, double Jz) : lieb_mattis_hamiltonian(num_spin, Jx, Jy, Jz)
{
_initialized = false;
}
int lieb_mattis_system::initialize()
{
if(N < 2 || dim < 4)
throw std::out_of_range("Minimum number of spins is 2.");
build();
build_subsp();
blockwise_diagonalise();
_initialized = true;
return 0;
}
#ifndef HAMILTONIAN_LIEB_MATTIS
#define HAMILTONIAN_LIEB_MATTIS
#include "spin_system.h"
#include "hamiltonian.h"
class lieb_mattis_hamiltonian : public hamiltonian_subsp
{
public:
lieb_mattis_hamiltonian(int num_spin = -1, double Jx = 1.0, double Jy = 1.0, double Jz = 1.0);
int build();
private:
double J_x, J_y, J_z;
};
class lieb_mattis_system : public lieb_mattis_hamiltonian, public spin_system // So far no spin_system dependence
{
public:
lieb_mattis_system(int num_spin, double Jx = 1.0, double Jy = 1.0, double Jz = 1.0);
//~lieb_mattis_system();
int initialize();
};
#endif
......@@ -5,6 +5,7 @@
#include "hamiltonian_kagome.h"
#include "hamiltonian_flower.h"
#include "heisenberg_nnn.h"
#include "hamiltonian_lieb_mattis.h"
// psi0 = To apply time evolution
// dim = dimension of system (2^N)
......@@ -115,6 +116,11 @@ BOOST_PYTHON_MODULE(pyspin)
.def("get_initialized", &flower_system::get_initialized)
;
class_<lieb_mattis_system, bases<hamiltonian>>("lieb_mattis_system", init<int, optional<double, double, double> >())
.def("initialize", &lieb_mattis_system::initialize)
.def("get_initialized", &lieb_mattis_system::get_initialized)
;
class_<heisenberg_local_field_system, bases<hamiltonian>>("heisenberg_local_field_system", init<int, bpy::list, optional<bool, double, double, double> >())
.def("initialize", &heisenberg_local_field_system::initialize)
......@@ -130,6 +136,7 @@ BOOST_PYTHON_MODULE(pyspin)
def("time_evolution", time_evolution<kagome_system_subsp>);
def("time_evolution", time_evolution<kagome_system>);
def("time_evolution", time_evolution<flower_system>);
def("time_evolution", time_evolution<lieb_mattis_system>);
def("time_evolution", time_evolution<heisenberg_system_nnn_subsp>);
def("vneumann_projection", vneumann_projection);
}
......
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