-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspinner.h
More file actions
192 lines (152 loc) · 5.08 KB
/
Copy pathspinner.h
File metadata and controls
192 lines (152 loc) · 5.08 KB
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
/* spinner.h
*
* Copyright (C) 2024 L. Bertini
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SPNR_H
#define SPNR_H
#include <stdlib.h>
#include <stdio.h>
#undef BEGIN_C_DECLS
#undef END_C_DECLS
#ifdef __cplusplus
# define BEGIN_C_DECLS extern "C" {
# define END_C_DECLS }
#else
# define BEGIN_C_DECLS /* empty */
# define END_C_DECLS /* empty */
#endif
#define SPNR_FALSE 0
#define SPNR_TRUE 1
BEGIN_C_DECLS
/* struct forward declaration */
typedef struct spnr_graph_struct spnr_graph_t;
typedef struct spnr_sys_struct spnr_sys_t;
typedef struct spnr_step_struct spnr_step_t;
/* System object
*
* Opaque object representing a spin system
* TODO: comment architecture
*/
typedef struct
{
char const * name;
void * (*priv_alloc) (size_t N, size_t param);
void (*priv_free) (void *priv);
size_t (*spin_size) (void *priv);
void (*set_up) (void *priv, size_t N);
void (*set_rand) (void *priv, size_t N);
void (*fill_prop) (void const *priv, void *prop, size_t k);
void (*accept_prop) (void *priv, void const *prop, size_t k);
float (*calc_delta_h_binary) (void const *priv, size_t n_sites,
float const *J, size_t const *sites,
void const *prop, size_t k);
float (*calc_part_h_binary) (void const* priv, size_t n_sites,
float const *J, size_t const *sites,
size_t k);
float (*calc_phi) (void const *priv, size_t N);
} spnr_sys_kind_t;
struct spnr_sys_struct
{
spnr_sys_kind_t const * kind;
void *priv;
size_t N;
spnr_graph_t *graph;
};
/* Available system kinds */
extern spnr_sys_kind_t const *spnr_ising;
extern spnr_sys_kind_t const *spnr_nvector;
/* System object methods */
spnr_sys_t * spnr_sys_alloc (spnr_graph_t *graph, spnr_sys_kind_t const * kind, size_t param);
void spnr_sys_free (spnr_sys_t * sys);
float spnr_sys_spin_size (spnr_sys_t * sys);
float spnr_sys_calc_h (spnr_sys_t * sys);
float spnr_sys_calc_phi (spnr_sys_t * sys);
/* Graph object
*
* Opaque object representing a graph
* TODO: comment architecture
*/
typedef struct
{
char const * name;
void * (*priv_alloc) (float (*getter)(), size_t N, size_t param);
void (*priv_free) (void *priv);
float (*calc_delta_h) (void const *priv, spnr_sys_t const *sys, void const *prop, size_t k);
float (*calc_h) (void const *priv, size_t N, spnr_sys_t const *sys);
} spnr_graph_kind_t;
struct spnr_graph_struct
{
spnr_graph_kind_t const * kind;
void * priv;
size_t N;
};
/* Available graph kinds */
extern spnr_graph_kind_t const *spnr_cubic;
/* System object methods */
spnr_graph_t * spnr_graph_alloc (spnr_graph_kind_t const *kind,
float (*getter)(),
size_t N, size_t param);
void spnr_graph_free (spnr_graph_t *graph);
/* Stepper object
*
* Opaque object representing a stepper
* TODO: comment architecture
*/
typedef struct {
char const * name;
void * (*priv_alloc) (size_t param);
void (*priv_free) (void *priv);
void (*apply) (void *priv, spnr_sys_t const *sys, float beta);
} spnr_step_kind_t;
struct spnr_step_struct {
spnr_step_kind_t const * kind;
void *priv;
};
/* Available stepper kinds */
extern spnr_step_kind_t const *spnr_metropolis;
/* System object methods */
spnr_step_t * spnr_step_alloc (spnr_step_kind_t const *kind, size_t param);
void spnr_step_free (spnr_step_t *step);
void spnr_step_apply (spnr_step_t const *step, spnr_sys_t const *sys,
float beta);
/* Graph couplings getter functions */
float spnr_ferr ();
/* Data struct
*
* Convenience struct to hold simulation data
* TODO: comment architecture
*/
typedef struct
{
size_t size;
float * h;
float * phi;
} spnr_data_t;
/* Data object methods */
spnr_data_t * spnr_data_alloc (size_t const size);
void spnr_data_free (spnr_data_t *data);
void spnr_data_write (spnr_data_t const *data, char const *fname);
void spnr_data_mean_calc (spnr_data_t const *data,
float *h_mean, float * const phi_mean);
void spnr_data_var_calc (spnr_data_t const * const data,
float * const h_var, float * const phi_var);
void spnr_data_corr_calc (spnr_data_t *corr, spnr_data_t const *data);
void spnr_data_run_and_probe (spnr_data_t *data, spnr_sys_t *sys,
spnr_step_t const *step,
float temp, size_t n_steps_before_probe);
END_C_DECLS
#endif