From 779467493e6bb2b70a0cbee7aa32b63b4c8c7214 Mon Sep 17 00:00:00 2001 From: Tobias WEBER Date: Sun, 19 Jul 2020 19:08:05 +0200 Subject: [PATCH] made my old ising code run again --- gfx/gil.h | 14 ++++-- phys/mag.h | 2 +- tools/misc/metrop.cpp | 6 +-- tools/misc/metrop_series_1d.cpp | 49 +++++++++++++++++++ ...metrop_series.cpp => metrop_series_2d.cpp} | 19 ++++--- 5 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 tools/misc/metrop_series_1d.cpp rename tools/misc/{metrop_series.cpp => metrop_series_2d.cpp} (68%) diff --git a/gfx/gil.h b/gfx/gil.h index 3a52237..b01d468 100644 --- a/gfx/gil.h +++ b/gfx/gil.h @@ -19,13 +19,19 @@ #ifndef int_p_NULL #define int_p_NULL reinterpret_cast(0) #endif -#include -#include +#include + +#include +#include + #ifndef NO_JPEG - #include + #include + #include #endif + #ifndef NO_TIFF - #include + #include + #include #endif diff --git a/phys/mag.h b/phys/mag.h index 0f96180..54cd64e 100644 --- a/phys/mag.h +++ b/phys/mag.h @@ -371,7 +371,7 @@ void metrop( *pS += (*(pDat+iElem) ? t_real(1) : t_real(-1)); // normalise - *pS /= std::pow(2., t_real(DIM)); // NN + *pS /= std::pow(2., t_real(DIM)); // NN for(std::size_t iDim=0; iDim diff --git a/tools/misc/metrop_series_1d.cpp b/tools/misc/metrop_series_1d.cpp new file mode 100644 index 0000000..d9d5527 --- /dev/null +++ b/tools/misc/metrop_series_1d.cpp @@ -0,0 +1,49 @@ +/** + * 1d metropolis test (without phase transition) + * @author Tobias Weber + * @date 8-oct-16 + * @license GPLv2 or GPLv3 + */ +// g++ -march=native -O2 -std=c++11 -o metrop_series_1d metrop_series_1d.cpp ../../log/log.cpp ../../math/rand.cpp + +#include "../../math/rand.h" +#include "../../phys/mag.h" +#include "../../phys/units.h" +#include "../../helper/array.h" +#include +#include + +using t_real = double; +static const tl::t_energy_si meV = tl::get_one_meV(); +static const tl::t_temperature_si kelvin = tl::get_one_kelvin(); +static const t_real k = t_real(tl::get_kB() / meV * kelvin); + + +int main() +{ + tl::init_rand(); + + std::size_t iIter = 1e7; + long iW = 256; + t_real J = 2.5; // meV + + boost::multi_array arr + = tl::rand_array({ iW }); + std::ofstream ofstrE("E1d.dat"); + + ofstrE << std::setw(16) << std::left << "#T" << " " + << std::setw(16) << std::left << "E_t" << " " + << std::setw(16) << std::left << "" << std::endl; + + for(t_real T=200.; T>=0.; T-=10.) + { + t_real Etot = 0., S = 0.; + tl::log_info("T = ", T, " K"); + tl::metrop({iW}, iIter, J, k, T, arr, &Etot, &S); + ofstrE << std::setw(16) << std::left << T << " " + << std::setw(16) << std::left << Etot << " " + << std::setw(16) << std::left << S << std::endl; + } + + return 0; +} diff --git a/tools/misc/metrop_series.cpp b/tools/misc/metrop_series_2d.cpp similarity index 68% rename from tools/misc/metrop_series.cpp rename to tools/misc/metrop_series_2d.cpp index 37facdc..59e7ef1 100644 --- a/tools/misc/metrop_series.cpp +++ b/tools/misc/metrop_series_2d.cpp @@ -1,14 +1,14 @@ /** - * metropolis test + * metropolis test (with phase transition) * @author Tobias Weber * @date 8-oct-16 * @license GPLv2 or GPLv3 */ -// gcc -march=native -O3 -std=c++11 -DNO_JPEG -DNO_TIFF -o metrop_series metrop_series.cpp ../../log/log.cpp ../../math/rand.cpp -lstdc++ -lm -lpng +// g++ -march=native -O2 -std=c++11 -DNO_JPEG -DNO_TIFF -o metrop_series_2d metrop_series_2d.cpp ../../log/log.cpp ../../math/rand.cpp -lpng -#include "../../math/mag.h" #include "../../math/rand.h" -#include "../../math/units.h" +#include "../../phys/mag.h" +#include "../../phys/units.h" #include "../../gfx/gil.h" #include "../../helper/array.h" #include @@ -19,6 +19,7 @@ static const tl::t_energy_si meV = tl::get_one_meV(); static const tl::t_temperature_si kelvin = tl::get_one_kelvin(); static const t_real k = t_real(tl::get_kB() / meV * kelvin); + int main() { tl::init_rand(); @@ -32,14 +33,20 @@ int main() boost::multi_array arr = tl::rand_array({iW, iH}); - std::ofstream ofstrE("E.dat"); + std::ofstream ofstrE("E2d.dat"); + + ofstrE << std::setw(16) << std::left << "#T" << " " + << std::setw(16) << std::left << "E_t" << " " + << std::setw(16) << std::left << "" << std::endl; for(t_real T=200.; T>=0.; T-=10.) { t_real Etot = 0., S = 0.; tl::log_info("T = ", T, " K"); tl::metrop({iW,iH}, iIter, J, k, T, arr, &Etot, &S); - ofstrE << T << "\t" << Etot << "\t" << S << std::endl; + ofstrE << std::setw(16) << std::left << T << " " + << std::setw(16) << std::left << Etot << " " + << std::setw(16) << std::left << S << std::endl; using t_view = tl::gil::gray8_view_t; using t_pix = typename t_view::value_type; -- GitLab