2 Dimensional Ising Model Simulate the change in energy and magnetization in a ferro magnet

Loading...
Searching...
No Matches
data_type.hpp
Go to the documentation of this file.
1
12#ifndef __DATA_TYPE__
13#define __DATA_TYPE__
14
15#include <sys/types.h>
16#include <type_traits>
17
18 class data_t {
19 public:
20 double E, M, E2, M2, M_abs;
21
22 data_t()
23 {
24 this->E = 0.;
25 this->E2 = 0.;
26 this->M = 0.;
27 this->M2 = 0.;
28 this->M_abs = 0.;
29 }
30
31 data_t(double E, double E2, double M, double M2, double M_abs)
32 {
33 this->E = E;
34 this->E2 = E2;
35 this->M = M;
36 this->M2 = M2;
37 this->M_abs = M_abs;
38 }
39
40 template <class T> data_t operator/(T num)
41 {
42 data_t res;
43 res.E = this->E / (double)num;
44 res.E2 = this->E2 / (double)num;
45 res.M = this->M / (double)num;
46 res.M2 = this->M2 / (double)num;
47 res.M_abs = this->M_abs / (double)num;
48
49 return res;
50 }
51
52 template <class T> data_t& operator/=(T num)
53 {
54 this->E /= (double)num;
55 this->E2 /= (double)num;
56 this->M /= (double)num;
57 this->M2 /= (double)num;
58 this->M_abs /= (double)num;
59
60 return *this;
61 }
62
63 template <class T> data_t operator*(T num)
64 {
65 data_t res;
66 res.E = this->E * (double)num;
67 res.E2 = this->E2 * (double)num;
68 res.M = this->M * (double)num;
69 res.M2 = this->M2 * (double)num;
70 res.M_abs = this->M_abs * (double)num;
71
72 return res;
73 }
74
75 template <class T> data_t& operator*=(T num)
76 {
77 this->E *= (double)num;
78 this->E2 *= (double)num;
79 this->M *= (double)num;
80 this->M2 *= (double)num;
81 this->M_abs *= (double)num;
82
83 return *this;
84 }
85
86 data_t operator+(const data_t &b)
87 {
88 data_t res;
89 res.E = this->E + b.E;
90 res.E2 = this->E2 + b.E2;
91 res.M = this->M + b.M;
92 res.M2 = this->M2 + b.M2;
93 res.M_abs = this->M_abs + b.M_abs;
94
95 return res;
96 }
97
98 data_t& operator+=(const data_t &b)
99 {
100 this->E += b.E;
101 this->E2 += b.E2;
102 this->M += b.M;
103 this->M2 += b.M2;
104 this->M_abs += b.M_abs;
105
106 return *this;
107 }
108
109 template <class T> void operator=(T num)
110 {
111 this->E = (double)num;
112 this->E2 = (double)num;
113 this->M = (double)num;
114 this->M2 = (double)num;
115 this->M_abs = (double)num;
116 }
117};
118
119#endif
data_t
Definition: data_type.hpp:18