-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim.h
337 lines (231 loc) · 10.2 KB
/
sim.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#ifndef SIM_H
#define SIM_H
// This file reserves the `bead`, `poly` and `ens` namespaces
// in addition to the `sim` namespace.
#include "exts.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
// This structure represents a bead and is a part of `struct poly`.
struct bead;
// This structure represents a polymer and is a part of `struct ens`.
struct poly;
// This structure represents an ensemble and is a part of `struct sim`.
struct ens;
// This structure contains all the necessary bookkeeping beside `struct ens`.
struct sim;
typedef double (* ens_pot)(struct ens const*,
struct bead const*, struct bead const*);
// The call `ens_pot_zero(ens, r0, r1)` always returns zero.
__attribute__ ((__const__, __nonnull__, __pure__))
double ens_pot_zero(struct ens const*,
struct bead const*, struct bead const*);
typedef double (* ens_potext)(struct ens const*, struct bead const*);
// The call `ens_potext_zero(ens, r)` always returns zero.
__attribute__ ((__const__, __nonnull__, __pure__))
double ens_potext_zero(struct ens const*, struct bead const*);
// The call `ens_norm2(ens, r)` returns the norm squared
// of `r` according to the minimum image convention.
// This is equivalent to `ens_dist2(ens, z, r)`, where `z` is the origin.
__attribute__ ((__nonnull__, __pure__))
double ens_norm2(struct ens const*, struct bead const*);
// The call `ens_norm(ens, r)` returns the norm
// of `r` according to the minimum image convention.
// This is equivalent to `sqrt(ens_norm2(ens, r))`.
__attribute__ ((__nonnull__, __pure__))
double ens_norm(struct ens const*, struct bead const*);
// The call `ens_dist2(ens, r0, r1)` returns the distance squared
// between `r0` and `r1` according to the minimum image convention.
__attribute__ ((__nonnull__, __pure__))
double ens_dist2(struct ens const*, struct bead const*, struct bead const*);
// The call `ens_dist(ens, r0, r1)` returns the distance
// between `r0` and `r1` according to the minimum image convention.
// This is equivalent to `sqrt(ens_dist2(ens, r0, r1))`.
__attribute__ ((__nonnull__, __pure__))
double ens_dist(struct ens const*, struct bead const*, struct bead const*);
// TODO Document these kinetic energy calculators.
// Kinetic energy for the degrees of freedom by the equipartition theorem.
__attribute__ ((__nonnull__, __pure__))
double ens_kindf(struct ens const*);
// Kinetic energy within a polymer from one bead to the previous one.
__attribute__ ((__nonnull__, __pure__))
double ens_kin_polybead_bw(struct ens const*, size_t, size_t);
// Kinetic energy within a polymer from one bead to the next one.
__attribute__ ((__nonnull__, __pure__))
double ens_kin_polybead_fw(struct ens const*, size_t, size_t);
// Kinetic energy within a polymer from each bead to the previous one.
__attribute__ ((__nonnull__, __pure__))
double ens_kin_bead_bw(struct ens const*, size_t);
// Kinetic energy within a polymer from each bead to the next one.
__attribute__ ((__nonnull__, __pure__))
double ens_kin_bead_fw(struct ens const*, size_t);
// Kinetic energy within a polymer.
__attribute__ ((__nonnull__, __pure__))
double ens_kin_poly(struct ens const*, size_t);
// Kinetic energy.
__attribute__ ((__nonnull__, __pure__))
double ens_kin_total(struct ens const*);
// TODO Document these potential energy calculators.
// Potential energy between certain beads of all polymers.
__attribute__ ((__nonnull__, __pure__))
double ens_potint_bead(struct ens const*, size_t);
// External potential energy for one bead in a polymer.
__attribute__ ((__nonnull__, __pure__))
double ens_potext_polybead(struct ens const*, size_t, size_t);
// External potential energy for every bead in a polymer.
__attribute__ ((__nonnull__, __pure__))
double ens_potext_bead(struct ens const*, size_t);
// Potential energy for one bead over all polymers.
__attribute__ ((__nonnull__, __pure__))
double ens_pot_bead(struct ens const*, size_t);
// Potential energy.
__attribute__ ((__nonnull__, __pure__))
double ens_pot_total(struct ens const*);
// TODO Document these estimators.
typedef double (* sim_est)(struct sim const*, void const*);
// Thermodynamic energy estimator.
__attribute__ ((__nonnull__ (1)))
double sim_est_thermal(struct sim const*, void const*);
// Mixed energy estimator.
__attribute__ ((__nonnull__ (1)))
double sim_est_mixed(struct sim const*, void const*);
// Virial energy estimator.
__attribute__ ((__nonnull__ (1)))
double sim_est_virial(struct sim const*, void const*);
// The call `sim_set_potint(sim, f)` sets `f`
// as the internal (polymer-to-polymer) potential of the simulation `sim`.
__attribute__ ((__nonnull__))
void sim_set_potint(struct sim*, ens_pot);
// The call `sim_set_potext(sim, f)` sets `f`
// as the external (bead-to-origin) potential of the simulation `sim`.
__attribute__ ((__nonnull__))
void sim_set_potext(struct sim*, ens_potext);
// TODO Document these weight configuration setters.
typedef void (* sim_weighter)(struct sim*, void const*);
__attribute__ ((__nonnull__ (1)))
void sim_weight_const(struct sim*, void const*);
// TODO Document these permutation configuration setters.
typedef void (* sim_permer)(struct sim*, void const*);
__attribute__ ((__nonnull__ (1)))
void sim_perm_close(struct sim*, void const*);
__attribute__ ((__nonnull__ (1)))
void sim_perm_open(struct sim*, void const*);
__attribute__ ((__nonnull__ (1)))
void sim_perm_chain(struct sim*, void const*);
__attribute__ ((__nonnull__ (1)))
void sim_perm_random(struct sim*, void const*);
// TODO Document these position configuration setters.
typedef void (* sim_placer)(struct sim*, size_t, struct bead const*, double,
void const*);
__attribute__ ((__nonnull__ (1, 3)))
void sim_placer_point(struct sim*, size_t, struct bead const*, double,
void const*);
__attribute__ ((__nonnull__ (1, 3)))
void sim_placer_random(struct sim*, size_t, struct bead const*, double,
void const*);
__attribute__ ((__nonnull__ (1, 3)))
void sim_placer_knot(struct sim*, size_t, struct bead const*, double,
void const*);
__attribute__ ((__nonnull__ (1)))
void sim_place_point(struct sim*, sim_placer, void const*);
__attribute__ ((__nonnull__ (1)))
void sim_place_random(struct sim*, sim_placer, void const*);
__attribute__ ((__nonnull__ (1)))
void sim_place_lattice(struct sim*, sim_placer, void const*);
__attribute__ ((__nonnull__ (1)))
void sim_place_file(struct sim*, sim_placer, void const*);
// TODO Document these movers.
typedef void (* sim_mover)(struct sim*);
__attribute__ ((__nonnull__))
void sim_move_null(struct sim*);
__attribute__ ((__nonnull__))
void sim_move_accept_ssm(struct sim*);
__attribute__ ((__nonnull__))
void sim_move_reject_ssm(struct sim*);
__attribute__ ((__nonnull__))
void sim_move_adjust_ssm(struct sim*);
__attribute__ ((__nonnull__))
void sim_move_ssm(struct sim*, size_t, size_t);
__attribute__ ((__nonnull__))
void sim_move_accept_cmd(struct sim*);
__attribute__ ((__nonnull__))
void sim_move_reject_cmd(struct sim*);
__attribute__ ((__nonnull__))
void sim_move_adjust_cmd(struct sim*);
__attribute__ ((__nonnull__))
void sim_move_cmd(struct sim*, size_t);
// TODO Document these move proposers.
typedef double (* sim_proposer)(struct sim*);
__attribute__ ((__nonnull__))
double sim_propose_ssm(struct sim*);
__attribute__ ((__nonnull__))
double sim_propose_cmd(struct sim*);
// TODO Document these move deciders.
typedef void (* sim_decider)(struct sim*);
__attribute__ ((__nonnull__))
void sim_decide_mq(struct sim*, double);
// TODO Document these resource managers.
typedef bool (* sim_printer)(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__))
bool sim_res_close(struct sim const*, FILE*);
__attribute__ ((__nonnull__))
FILE* sim_res_open(struct sim const*, char const*);
__attribute__ ((__nonnull__ (1, 2, 3)))
bool sim_res_print(struct sim const*, char const*, sim_printer, void const*);
// TODO Document these resource printers.
__attribute__ ((__nonnull__ (1, 2)))
bool print_length(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_periodic(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_pots(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_ndim(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_npoly(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_nbead(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_nsubdiv(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_ndiv(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_energy_bead(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_energy_link(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_energy(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_corrtime(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_params(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_posdist(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_raddist(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_polys(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_progress(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_results(struct sim const*, FILE*, void const*);
__attribute__ ((__nonnull__ (1, 2)))
bool print_wrong_results_fast(struct sim const*, FILE*, void const*);
// TODO Document these environment managers.
__attribute__ ((__nonnull__))
bool sim_init_fs(struct sim const*);
__attribute__ ((__nonnull__))
bool sim_fini_fs(struct sim const*);
__attribute__ ((__nonnull__))
bool sim_save_const(struct sim const*);
__attribute__ ((__nonnull__))
bool sim_save_mut(struct sim const*);
// TODO Document these simulation managers.
void sim_free(struct sim*);
__attribute__ ((__malloc__))
struct sim* sim_alloc(size_t, size_t, size_t, size_t,
size_t, size_t, size_t, size_t, size_t,
bool, bool, double, double, double);
__attribute__ ((__nonnull__))
bool sim_run(struct sim*);
#endif