aboutsummaryrefslogtreecommitdiff
path: root/src/symcoord.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 21:37:34 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 21:37:34 +0100
commit3568412f8f230774d0d11d7ed1c897424f95d3ef (patch)
tree77223792d8c925a9b1fc32b3f4341e943b5f8209 /src/symcoord.c
parent67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff)
downloadnissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz
nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to 'src/symcoord.c')
-rw-r--r--src/symcoord.c355
1 files changed, 355 insertions, 0 deletions
diff --git a/src/symcoord.c b/src/symcoord.c
new file mode 100644
index 0000000..97a8d9a
--- /dev/null
+++ b/src/symcoord.c
@@ -0,0 +1,355 @@
1#include "symcoord.h"
2
3static Cube antindex_coud_sym16(uint64_t ind);
4static Cube antindex_cp_sym16(uint64_t ind);
5static Cube antindex_eofbepos_sym16(uint64_t ind);
6static Cube antindex_drud_sym16(uint64_t ind);
7static Cube antindex_drudfin_noE_sym16(uint64_t ind);
8static Cube antindex_khuge(uint64_t ind);
9
10static uint64_t index_coud_sym16(Cube cube);
11static uint64_t index_cp_sym16(Cube cube);
12static uint64_t index_eofbepos_sym16(Cube cube);
13static uint64_t index_drud_sym16(Cube cube);
14static uint64_t index_drudfin_noE_sym16(Cube cube);
15static uint64_t index_khuge(Cube cube);
16
17static void gensym(SymData *sd);
18static bool read_symdata_file(SymData *sd);
19static bool write_symdata_file(SymData *sd);
20
21/* Transformation groups and symmetry data ***********************************/
22
23static Trans
24trans_group_udfix[16] = {
25 uf, ur, ub, ul,
26 df, dr, db, dl,
27 uf_mirror, ur_mirror, ub_mirror, ul_mirror,
28 df_mirror, dr_mirror, db_mirror, dl_mirror,
29};
30
31static SymData
32sd_coud_16 = {
33 .filename = "sd_coud_16",
34 .coord = &coord_coud,
35 .sym_coord = &coord_coud_sym16,
36 .ntrans = 16,
37 .trans = trans_group_udfix
38};
39
40static SymData
41sd_cp_16 = {
42 .filename = "sd_cp_16",
43 .coord = &coord_cp,
44 .sym_coord = &coord_cp_sym16,
45 .ntrans = 16,
46 .trans = trans_group_udfix
47};
48
49static SymData
50sd_eofbepos_16 = {
51 .filename = "sd_eofbepos_16",
52 .coord = &coord_eofbepos,
53 .sym_coord = &coord_eofbepos_sym16,
54 .ntrans = 16,
55 .trans = trans_group_udfix
56};
57
58static int nsymdata = 3;
59static SymData * all_sd[] = {
60 &sd_coud_16,
61 &sd_cp_16,
62 &sd_eofbepos_16,
63};
64
65
66/* Coordinates and their implementation **************************************/
67
68Coordinate
69coord_eofbepos_sym16 = {
70 .index = index_eofbepos_sym16,
71 .cube = antindex_eofbepos_sym16,
72 .ntrans = 16,
73 .trans = trans_group_udfix,
74};
75
76Coordinate
77coord_coud_sym16 = {
78 .index = index_coud_sym16,
79 .cube = antindex_coud_sym16,
80 .ntrans = 16,
81 .trans = trans_group_udfix,
82};
83
84Coordinate
85coord_cp_sym16 = {
86 .index = index_cp_sym16,
87 .cube = antindex_cp_sym16,
88 .ntrans = 16,
89 .trans = trans_group_udfix,
90};
91
92Coordinate
93coord_drud_sym16 = {
94 .index = index_drud_sym16,
95 .cube = antindex_drud_sym16,
96 .max = POW3TO7 * 64430,
97 .ntrans = 16,
98 .trans = trans_group_udfix,
99};
100
101Coordinate
102coord_drudfin_noE_sym16 = {
103 .index = index_drudfin_noE_sym16,
104 .cube = antindex_drudfin_noE_sym16,
105 .max = FACTORIAL8 * 2768,
106 .ntrans = 16,
107 .trans = trans_group_udfix,
108};
109
110Coordinate
111coord_khuge = {
112 .index = index_khuge,
113 .cube = antindex_khuge,
114 .max = POW3TO7 * FACTORIAL4 * 64430,
115 .ntrans = 16,
116 .trans = trans_group_udfix,
117};
118
119/* Functions *****************************************************************/
120
121static Cube
122antindex_coud_sym16(uint64_t ind)
123{
124 return sd_coud_16.rep[ind];
125}
126
127static Cube
128antindex_cp_sym16(uint64_t ind)
129{
130 return sd_cp_16.rep[ind];
131}
132
133static Cube
134antindex_eofbepos_sym16(uint64_t ind)
135{
136 return sd_eofbepos_16.rep[ind];
137}
138
139static Cube
140antindex_drud_sym16(uint64_t ind)
141{
142 Cube c;
143
144 c = antindex_eofbepos_sym16(ind/POW3TO7);
145 c.coud = ind % POW3TO7;
146 c.cofb = c.coud;
147 c.corl = c.coud;
148
149 return c;
150}
151
152static Cube
153antindex_drudfin_noE_sym16(uint64_t ind)
154{
155 Cube c1, c2;
156
157 c1 = coord_epud.cube(ind % FACTORIAL8);
158 c2 = antindex_cp_sym16(ind/FACTORIAL8);
159 c1.cp = c2.cp;
160
161 return c1;
162}
163
164static Cube
165antindex_khuge(uint64_t ind)
166{
167 Cube c;
168
169 c = antindex_eofbepos_sym16(ind/(FACTORIAL4*POW3TO7));
170 c.epose = ((c.epose / 24) * 24) + ((ind/POW3TO7) % 24);
171 c.coud = ind % POW3TO7;
172
173 return c;
174}
175
176static uint64_t
177index_coud_sym16(Cube cube)
178{
179 return sd_coud_16.class[coord_coud.index(cube)];
180}
181
182static uint64_t
183index_cp_sym16(Cube cube)
184{
185 return sd_cp_16.class[coord_cp.index(cube)];
186}
187
188static uint64_t
189index_drud_sym16(Cube cube)
190{
191 Trans t;
192 Cube c;
193
194 t = sd_eofbepos_16.transtorep[coord_eofbepos.index(cube)];
195 c = apply_trans(t, cube);
196
197 return index_eofbepos_sym16(c) * POW3TO7 + c.coud;
198}
199
200static uint64_t
201index_drudfin_noE_sym16(Cube cube)
202{
203 Trans t;
204 Cube c;
205
206 t = sd_cp_16.transtorep[coord_cp.index(cube)];
207 c = apply_trans(t, cube);
208
209 return index_cp_sym16(c) * FACTORIAL8 + coord_epud.index(c);
210}
211
212static uint64_t
213index_eofbepos_sym16(Cube cube)
214{
215 return sd_eofbepos_16.class[coord_eofbepos.index(cube)];
216}
217
218static uint64_t
219index_khuge(Cube cube)
220{
221 Trans t;
222 Cube c;
223 uint64_t a;
224
225 t = sd_eofbepos_16.transtorep[coord_eofbepos.index(cube)];
226 c = apply_trans(t, cube);
227 a = (index_eofbepos_sym16(c) * 24) + (c.epose % 24);
228
229 return a * POW3TO7 + c.coud;
230}
231
232/* Other functions ***********************************************************/
233
234static void
235gensym(SymData *sd)
236{
237 uint64_t i, in, nreps = 0;
238 int j;
239 Cube c, d;
240
241 if (sd->generated)
242 return;
243
244 sd->class = malloc(sd->coord->max * sizeof(uint64_t));
245 sd->rep = malloc(sd->coord->max * sizeof(Cube));
246 sd->transtorep = malloc(sd->coord->max * sizeof(Trans));
247
248 if (read_symdata_file(sd)) {
249 sd->generated = true;
250 return;
251 }
252
253 fprintf(stderr, "Cannot load %s, generating it\n", sd->filename);
254
255 for (i = 0; i < sd->coord->max; i++)
256 sd->class[i] = sd->coord->max + 1;
257
258 for (i = 0; i < sd->coord->max; i++) {
259 if (sd->class[i] == sd->coord->max + 1) {
260 c = sd->coord->cube(i);
261 sd->rep[nreps] = c;
262 for (j = 0; j < sd->ntrans; j++) {
263 d = apply_trans(sd->trans[j], c);
264 in = sd->coord->index(d);
265
266 if (sd->class[in] == sd->coord->max + 1) {
267 sd->class[in] = nreps;
268 sd->transtorep[in] =
269 inverse_trans(sd->trans[j]);
270 }
271 }
272 nreps++;
273 }
274 }
275
276 sd->sym_coord->max = nreps;
277 sd->rep = realloc(sd->rep, nreps * sizeof(Cube));
278 sd->generated = true;
279
280 fprintf(stderr, "Found %lu classes\n", nreps);
281
282 if (!write_symdata_file(sd))
283 fprintf(stderr, "Error writing SymData file\n");
284
285 return;
286}
287
288static bool
289read_symdata_file(SymData *sd)
290{
291 init_env();
292
293 FILE *f;
294 char fname[strlen(tabledir)+100];
295 uint64_t n = sd->coord->max, *sn = &sd->sym_coord->max;
296 bool r = true;
297
298 strcpy(fname, tabledir);
299 strcat(fname, "/");
300 strcat(fname, sd->filename);
301
302 if ((f = fopen(fname, "rb")) == NULL)
303 return false;
304
305 r = r && fread(&sd->sym_coord->max, sizeof(uint64_t), 1, f) == 1;
306 r = r && fread(sd->rep, sizeof(Cube), *sn, f) == *sn;
307 r = r && fread(sd->class, sizeof(uint64_t), n, f) == n;
308 r = r && fread(sd->transtorep, sizeof(Trans), n, f) == n;
309
310 fclose(f);
311 return r;
312}
313
314static bool
315write_symdata_file(SymData *sd)
316{
317 init_env();
318
319 FILE *f;
320 char fname[strlen(tabledir)+100];
321 uint64_t n = sd->coord->max, *sn = &sd->sym_coord->max;
322 bool r = true;
323
324 strcpy(fname, tabledir);
325 strcat(fname, "/");
326 strcat(fname, sd->filename);
327
328 if ((f = fopen(fname, "wb")) == NULL)
329 return false;
330
331 r = r && fwrite(&sd->sym_coord->max, sizeof(uint64_t), 1, f) == 1;
332 r = r && fwrite(sd->rep, sizeof(Cube), *sn, f) == *sn;
333 r = r && fwrite(sd->class, sizeof(uint64_t), n, f) == n;
334 r = r && fwrite(sd->transtorep, sizeof(Trans), n, f) == n;
335
336 fclose(f);
337 return r;
338}
339
340void
341init_symcoord()
342{
343 int i;
344
345 static bool initialized = false;
346 if (initialized)
347 return;
348 initialized = true;
349
350 init_coord();
351
352 for (i = 0; i < nsymdata; i++)
353 gensym(all_sd[i]);
354}
355

Generated with cgit - Back to sebastiano.tronto.net