Skip to content

Commit 65abe06

Browse files
committed
Add code file.
1 parent 81cd3cf commit 65abe06

19 files changed

+1443
-0
lines changed

cpp/a.exe

1.77 MB
Binary file not shown.

cpp/ising.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "ising.hpp"
2+
#include <time.h>
3+
#include <math.h>
4+
#include <stdlib.h>
5+
#include <iostream>
6+
7+
typedef unsigned int uint;
8+
9+
double calculate_energy(int * spin[], int L, double H)
10+
{
11+
double energy = 0;
12+
int s_nr, s_nb;
13+
for (int i = 0; i < L; i++)
14+
{
15+
for (int j = 0; j < L; j++)
16+
{
17+
s_nr = j < L - 1 ? spin[i][j + 1] : 0;
18+
s_nb = i < L - 1 ? spin[i + 1][j] : 0;
19+
energy += -spin[i][j] * (s_nr + s_nb + H);
20+
}
21+
}
22+
return energy;
23+
}
24+
25+
double ising2(double H, double T, int L, int N)
26+
{
27+
int x, y, s_nr, s_nb, s_nt, s_nl;
28+
int **spin = new int*[L];
29+
double delta_energy;
30+
srand((uint)time(NULL));
31+
for (int i = 0; i < L; i++)
32+
{
33+
spin[i] = new int[L];
34+
for (int j = 0; j < L; j++)
35+
{
36+
spin[i][j] = (rand()%2)*2-1;
37+
}
38+
}
39+
for (int i = 0; i < N; i++)
40+
{
41+
for (int j = 0; j < 1e4; j++)
42+
{
43+
44+
x = rand() % L; //row
45+
y = rand() % L; //col
46+
s_nr = y < L - 1 ? spin[x][y + 1] : 0;
47+
s_nl = y > 0 ? spin[x][y - 1] : 0;
48+
s_nb = x < L - 1 ? spin[x + 1][y] : 0;
49+
s_nt = x > 0 ? spin[x - 1][y] : 0;
50+
delta_energy = 2 * spin[x][y] * (s_nb + s_nl + s_nr + s_nt + H);
51+
if (delta_energy < 0 || (double)(rand() % 100) / 100 < exp(-delta_energy / T)) {
52+
spin[x][y] = -spin[x][y];
53+
}
54+
}
55+
//std::cout << calculate_energy(spin, L, H) << std::endl;
56+
}
57+
return calculate_energy(spin, L, H);
58+
}

cpp/ising.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef __ISING_H__
2+
#define __ISING_H__
3+
4+
extern double calculate_energy(int *spin[], int L, double H);
5+
extern double ising2(double H, double T, int L, int N);
6+
7+
#endif

cpp/ising.hpp.gch

1.09 MB
Binary file not shown.

cpp/ising2.exe

1.77 MB
Binary file not shown.

cpp/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include "ising.hpp"
3+
4+
using namespace std;
5+
6+
int main(int argc, const char * argv[])
7+
{
8+
double H,T;
9+
int N,L;
10+
cout << "H: ";
11+
cin >> H;
12+
cout << "T: ";
13+
cin >> T;
14+
cout << "L: ";
15+
cin >> L;
16+
cout << "N: ";
17+
cin >> N;
18+
cout << ising2(H, T, L, N);
19+
return 0;
20+
}

html/css/ising.css

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
*{
2+
margin: 0;
3+
padding: 0;
4+
/*position: absolute;*/
5+
}
6+
7+
html, body{
8+
width: 100%;
9+
height: 100%;
10+
min-width: 500px;
11+
}
12+
13+
.panel-display{
14+
position: absolute;
15+
left: 0;
16+
width: 70vw;
17+
height: 100vh;
18+
min-width: 500px;
19+
min-height: 500px;
20+
background-color: #ccc;
21+
}
22+
23+
.panel-display #canvas{
24+
position: absolute;
25+
top: 0;
26+
left: 0;
27+
right: 0;
28+
bottom: 0;
29+
margin: auto;
30+
background-color: #000;
31+
}
32+
33+
.panel-display #chart{
34+
position: absolute;
35+
width: 100%;
36+
height: 70%;
37+
min-height: 500px;
38+
top: 0;
39+
bottom: 0;
40+
margin: auto;
41+
}
42+
43+
.panel-contral{
44+
position: absolute;
45+
right: 0;
46+
width: 30vw;
47+
height: 100vh;
48+
min-width: 300px;
49+
min-height: 500px;
50+
background-color: rgba(232, 232, 232, 0.8);
51+
}
52+
53+
.panel-contral .contral-preheat{
54+
margin-top: 33px;
55+
height: 160px;
56+
}
57+
58+
.panel-contral .contral-button{
59+
border: 0;
60+
border-radius: 2px;
61+
font-size: 20px;
62+
color: #000;
63+
background-color: #ccc;
64+
outline: none;
65+
cursor: pointer;
66+
}
67+
68+
.panel-contral .contral-button:hover{
69+
opacity: 0.8;
70+
}
71+
72+
.contral-preheat .contral-button{
73+
position: absolute;
74+
width: 33.3%;
75+
height: 40px;
76+
color: #fff;
77+
background-color: #00f;
78+
}
79+
80+
.contral-preheat .contral-button#start{
81+
margin-left: 13.2%;
82+
}
83+
84+
.contral-preheat .contral-button#reset{
85+
margin-left: 53.2%;
86+
}
87+
88+
.panel-contral .contral-range{
89+
90+
}
91+
92+
.contral-preheat .contral-range{
93+
position: absolute;
94+
margin-left: 13.2%;
95+
width: 73.6%;
96+
height: 20px;
97+
}
98+
99+
.contral-preheat .contral-range#crl{
100+
margin-top: 60px;
101+
}
102+
103+
.contral-preheat .contral-range#crh{
104+
margin-top: 90px;
105+
}
106+
107+
.contral-preheat .contral-range#crt{
108+
margin-top: 120px;
109+
}
110+
111+
.contral-preheat .contral-range-label{
112+
position: absolute;
113+
width: 30%;
114+
height: 20px;
115+
}
116+
117+
.contral-preheat .label-text{
118+
position: absolute;
119+
width: 30%;
120+
height: 20px;
121+
}
122+
123+
.contral-preheat .label-value{
124+
position: absolute;
125+
width: 70%;
126+
height: 20px;
127+
margin-left: 30%;
128+
border: 0;
129+
background-color: #fefefe;
130+
border-radius: 2px;
131+
outline: none;
132+
}
133+
134+
.contral-preheat .contral-range-slide{
135+
position: absolute;
136+
width: 69%;
137+
margin-left: 31%;
138+
cursor: pointer;
139+
}
140+
141+
.panel-contral .contral-analyze{
142+
/*height: 500px;*/
143+
}
144+
145+
.contral-analyze .contral-button{
146+
margin-left: 33.3%;
147+
width: 33.3%;
148+
height: 40px;
149+
color: #fff;
150+
background-color: #00f;
151+
}

html/engine/css/engine.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#display{
2+
position: absolute;
3+
top: 0;
4+
bottom: 0;
5+
left: 0;
6+
right: 0;
7+
margin: auto;
8+
/*background-color: #000;*/
9+
}

html/engine/js/engine.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
(function(){
2+
var engine={};
3+
engine.status = 0;
4+
engine.data = null;
5+
engine.idcount = 0;
6+
engine.child = [];
7+
engine.init = function(id, width, height){
8+
engine.status = 0;
9+
engine.data = null;
10+
this.display = document.getElementById(id);
11+
this.context = this.display.getContext('2d');
12+
if(width && height){
13+
this.setsize(width, height);
14+
}else{
15+
this.setsize(100, 100);
16+
}
17+
return engine;
18+
};
19+
20+
engine.setsize = function(width, height){
21+
this.display.width = width;
22+
this.display.height = height;
23+
// img = new ImageData(this.display.width,this.display.height);
24+
// for (var i = 0; i < this.display.height; i++) {
25+
// for (var j = 0; j < this.display.width; j++) {
26+
// img.data[4*(i*this.display.width+j)+0] = 0x00;
27+
// img.data[4*(i*this.display.width+j)+1] = 0x00;
28+
// img.data[4*(i*this.display.width+j)+2] = 0x00;
29+
// img.data[4*(i*this.display.width+j)+3] = 0xff;
30+
// }
31+
// }
32+
// this.data = img;
33+
return engine;
34+
};
35+
36+
engine.paint = function(context, data){
37+
if(data != null){
38+
context.putImageData(data, 0, 0);
39+
}
40+
for (var i = 0; i < engine.idcount; i++) {
41+
engine.child[i].paint(context, data);
42+
}
43+
engine._update(context, data);
44+
return engine;
45+
};
46+
47+
engine.start = function(first){
48+
if(!first){
49+
engine.status = 1;
50+
}
51+
if (engine.status) {
52+
engine.paint(engine.context, engine.data);
53+
window.setTimeout(engine.start, 40, true);
54+
}
55+
return engine;
56+
};
57+
58+
engine.stop = function(){
59+
engine.status = 0;
60+
return engine;
61+
};
62+
63+
engine.addchild = function(child){
64+
engine.child[engine.idcount++] = child;
65+
return engine;
66+
};
67+
68+
engine.update = function(func){
69+
engine._update = func;
70+
return engine;
71+
};
72+
73+
//interface
74+
engine._update = function(context, data){};
75+
76+
//regist engine object.
77+
window['engine'] = engine;
78+
})();

html/image.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>www</title>
5+
<script type="text/javascript" src="./js/imagelab.js"></script>
6+
</head>
7+
<body>
8+
<canvas id="canvas"></canvas>
9+
<script type="text/javascript">
10+
(function(window){
11+
imagelab.figure('canvas', 400,400).start(true);
12+
})(window);
13+
</script>
14+
</body>
15+
</html>

html/img/ising.png

43 KB
Loading

html/img/ising_0_2.269_37964.png

40.2 KB
Loading

0 commit comments

Comments
 (0)