-
Notifications
You must be signed in to change notification settings - Fork 0
/
magP.h
193 lines (168 loc) · 4.31 KB
/
magP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#ifndef __magp_h__
#define __magp_h__
#include <string>
/**
* @class MagP64
* @brief Abstract type representing magnetization type chosen for cavity messages.
*
* @note The `MagP64` type allows fast executions with inexact outcomes by neglecting all `tanh` operations.
*
*/
struct MagP64
{
// member
double mag; ///< Magnetization
// constructor and destructor
/**
* @brief Default constructor.
*
*/
MagP64 () {};
/**
* @brief Constructor with value.
*
* @param x magnetization
*
* @note In MagP64 the value is equal to the mag.
*
*/
MagP64 (const double & x) : mag (x) {};
/**
* @brief Default destructor.
*
*/
~MagP64 () = default;
/**
* @brief Copy constructor.
*
* @param m MagP64 object
*
*/
MagP64 (const MagP64 & m) { this->mag = m.mag; }
/**
* @brief Assigment operator constructor.
*
* @param m MagP64 object
*
*/
MagP64 & operator = (const MagP64 & m) { this->mag = m.mag; return *this; }
// utilities
/**
* @brief Return the mag description (plain for MagP64).
*
*/
std :: string magformat () const { return "plain"; }
/**
* @brief Get the magnetization value.
*
* @note In MagP64 the value is equal to the mag.
*
*/
double value () const { return this->mag; }
// math operators
/**
* @brief Overload operator.
*
* @details Add magnetization ( (m1 + m2) / (1 + m1*m2) ) with clamp.
*
* @see mag :: clamp
*
* @param m MagP64 object
*
*/
MagP64 operator % (const MagP64 & m) { return MagP64(mag :: clamp( (this->mag + m.mag) / (1. + this->mag * m.mag), -1., 1.) ); }
/**
* @brief Overload operator.
*
* @details Just a simple addition of the mag values.
*
* @param m MagP64 object
*
*/
MagP64 operator + (const MagP64 & m) { return MagP64(this->mag + m.mag); }
/**
* @brief Overload operator.
*
* @details Just a simple division as (mag / x)
*
* @param x double value
*
*/
MagP64 operator / (const double & x) { return MagP64(this->mag / x); }
/**
* @brief Overload operator.
*
* @details Just a simple product as (mag * x)
*
* @param x double value
*
*/
double operator * (const double & x) { return this->mag * x; }
/**
* @brief Overload operator.
*
* @details Just a simple product as (x * mag)
*
* @param x double value
* @param m MagP64 object
*
*/
friend double operator * (const double & x, const MagP64 & m) { return m.mag * x; }
/**
* @brief Overload operator
*
* @details Combine two mags as (mag * mag)
*
* @param m MagP64 object
*
*/
MagP64 operator ^ (const MagP64 & m) { return MagP64(this->mag * m.mag); }
/**
* @brief Overload operator.
*
* @details Subtract values (val1 - val2)
*
* @note In MagP64 the values are equal to the mags.
*
* @param m MagP64 object
*
*/
double operator - (const MagP64 & m) { return this->mag - m.mag; }
/**
* @brief Get a magnetization with a flipped sign.
*
* @details flip magnetization sign
*
*/
MagP64 operator - () const { return MagP64(-this->mag); }
// logical operators
/**
* @brief Check magnetization equality.
*
* @details Compare magnetizations
*
* @param m MagP64 object
*
*/
bool operator == (const MagP64 & m) { return this->mag == m.mag; }
/**
* @brief Check magnetization not equality.
*
* @details compare magnetizations
*
* @param m MagP64 object
*
*/
bool operator != (const MagP64 & m) { return this->mag != m.mag; }
/**
* @brief Print operator with stdout/stderr.
*
* @details print mag
*
* @param os ostream operator
* @param m MagP64 object
*
*/
friend std :: ostream & operator << (std :: ostream & os, const MagP64 & m);
};
#endif // __magp_h__