aboutsummaryrefslogtreecommitdiff
path: root/old/2021-11-10-beforeremovingchecker/symcoord.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--old/2021-11-10-beforeremovingchecker/symcoord.c359
1 files changed, 0 insertions, 359 deletions
diff --git a/old/2021-11-10-beforeremovingchecker/symcoord.c b/old/2021-11-10-beforeremovingchecker/symcoord.c
deleted file mode 100644
index 9a4d49a..0000000
--- a/old/2021-11-10-beforeremovingchecker/symcoord.c
+++ /dev/null
@@ -1,359 +0,0 @@
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 .check = check_eofbepos,
73 .ntrans = 16,
74 .trans = trans_group_udfix,
75};
76
77Coordinate
78coord_coud_sym16 = {
79 .index = index_coud_sym16,
80 .cube = antindex_coud_sym16,
81 .check = check_coud,
82 .ntrans = 16,
83 .trans = trans_group_udfix,
84};
85
86Coordinate
87coord_cp_sym16 = {
88 .index = index_cp_sym16,
89 .cube = antindex_cp_sym16,
90 .check = check_cp,
91 .ntrans = 16,
92 .trans = trans_group_udfix,
93};
94
95Coordinate
96coord_drud_sym16 = {
97 .index = index_drud_sym16,
98 .cube = antindex_drud_sym16,
99 .check = check_drud,
100 .max = POW3TO7 * 64430,
101 .ntrans = 16,
102 .trans = trans_group_udfix,
103};
104
105Coordinate
106coord_drudfin_noE_sym16 = {
107 .index = index_drudfin_noE_sym16,
108 .cube = antindex_drudfin_noE_sym16,
109 .check = check_drudfin_noE,
110 .max = FACTORIAL8 * 2768,
111 .ntrans = 16,
112 .trans = trans_group_udfix,
113};
114
115Coordinate
116coord_khuge = {
117 .index = index_khuge,
118 .cube = antindex_khuge,
119 .check = check_khuge,
120 .max = POW3TO7 * FACTORIAL4 * 64430,
121 .ntrans = 16,
122 .trans = trans_group_udfix,
123};
124
125/* Functions *****************************************************************/
126
127static Cube
128antindex_coud_sym16(uint64_t ind)
129{
130 return sd_coud_16.rep[ind];
131}
132
133static Cube
134antindex_cp_sym16(uint64_t ind)
135{
136 return sd_cp_16.rep[ind];
137}
138
139static Cube
140antindex_eofbepos_sym16(uint64_t ind)
141{
142 return sd_eofbepos_16.rep[ind];
143}
144
145static Cube
146antindex_drud_sym16(uint64_t ind)
147{
148 Cube c;
149
150 c = antindex_eofbepos_sym16(ind/POW3TO7);
151 c.coud = ind % POW3TO7;
152 c.cofb = c.coud;
153 c.corl = c.coud;
154
155 return c;
156}
157
158static Cube
159antindex_drudfin_noE_sym16(uint64_t ind)
160{
161 Cube c1, c2;
162
163 c1 = coord_epud.cube(ind % FACTORIAL8);
164 c2 = antindex_cp_sym16(ind/FACTORIAL8);
165 c1.cp = c2.cp;
166
167 return c1;
168}
169
170static Cube
171antindex_khuge(uint64_t ind)
172{
173 Cube c;
174
175 c = antindex_eofbepos_sym16(ind/(FACTORIAL4*POW3TO7));
176 c.epose = ((c.epose / 24) * 24) + ((ind/POW3TO7) % 24);
177 c.coud = ind % POW3TO7;
178
179 return c;
180}
181
182static uint64_t
183index_coud_sym16(Cube cube)
184{
185 return sd_coud_16.class[coord_coud.index(cube)];
186}
187
188static uint64_t
189index_cp_sym16(Cube cube)
190{
191 return sd_cp_16.class[coord_cp.index(cube)];
192}
193
194static uint64_t
195index_drud_sym16(Cube cube)
196{
197 Trans t;
198 Cube c;
199
200 t = sd_eofbepos_16.transtorep[coord_eofbepos.index(cube)];
201 c = apply_trans(t, cube);
202
203 return index_eofbepos_sym16(c) * POW3TO7 + c.coud;
204}
205
206static uint64_t
207index_drudfin_noE_sym16(Cube cube)
208{
209 Trans t;
210 Cube c;
211
212 t = sd_cp_16.transtorep[coord_cp.index(cube)];
213 c = apply_trans(t, cube);
214
215 return index_cp_sym16(c) * FACTORIAL8 + coord_epud.index(c);
216}
217
218static uint64_t
219index_eofbepos_sym16(Cube cube)
220{
221 return sd_eofbepos_16.class[coord_eofbepos.index(cube)];
222}
223
224static uint64_t
225index_khuge(Cube cube)
226{
227 Trans t;
228 Cube c;
229 uint64_t a;
230
231 t = sd_eofbepos_16.transtorep[coord_eofbepos.index(cube)];
232 c = apply_trans(t, cube);
233 a = (index_eofbepos_sym16(c) * 24) + (c.epose % 24);
234
235 return a * POW3TO7 + c.coud;
236}
237
238/* Other functions ***********************************************************/
239
240static void
241gensym(SymData *sd)
242{
243 uint64_t i, in, nreps = 0;
244 int j;
245 Cube c, d;
246
247 if (sd->generated)
248 return;
249
250 sd->class = malloc(sd->coord->max * sizeof(uint64_t));
251 sd->rep = malloc(sd->coord->max * sizeof(Cube));
252 sd->transtorep = malloc(sd->coord->max * sizeof(Trans));
253
254 if (read_symdata_file(sd)) {
255 sd->generated = true;
256 return;
257 }
258
259 fprintf(stderr, "Cannot load %s, generating it\n", sd->filename);
260
261 for (i = 0; i < sd->coord->max; i++)
262 sd->class[i] = sd->coord->max + 1;
263
264 for (i = 0; i < sd->coord->max; i++) {
265 if (sd->class[i] == sd->coord->max + 1) {
266 c = sd->coord->cube(i);
267 sd->rep[nreps] = c;
268 for (j = 0; j < sd->ntrans; j++) {
269 d = apply_trans(sd->trans[j], c);
270 in = sd->coord->index(d);
271
272 if (sd->class[in] == sd->coord->max + 1) {
273 sd->class[in] = nreps;
274 sd->transtorep[in] =
275 inverse_trans(sd->trans[j]);
276 }
277 }
278 nreps++;
279 }
280 }
281
282 sd->sym_coord->max = nreps;
283 sd->rep = realloc(sd->rep, nreps * sizeof(Cube));
284 sd->generated = true;
285
286 fprintf(stderr, "Found %lu classes\n", nreps);
287
288 if (!write_symdata_file(sd))
289 fprintf(stderr, "Error writing SymData file\n");
290
291 return;
292}
293
294static bool
295read_symdata_file(SymData *sd)
296{
297 init_env();
298
299 FILE *f;
300 char fname[strlen(tabledir)+100];
301 uint64_t n = sd->coord->max, *sn = &sd->sym_coord->max;
302 bool r = true;
303
304 strcpy(fname, tabledir);
305 strcat(fname, "/");
306 strcat(fname, sd->filename);
307
308 if ((f = fopen(fname, "rb")) == NULL)
309 return false;
310
311 r = r && fread(&sd->sym_coord->max, sizeof(uint64_t), 1, f) == 1;
312 r = r && fread(sd->rep, sizeof(Cube), *sn, f) == *sn;
313 r = r && fread(sd->class, sizeof(uint64_t), n, f) == n;
314 r = r && fread(sd->transtorep, sizeof(Trans), n, f) == n;
315
316 fclose(f);
317 return r;
318}
319
320static bool
321write_symdata_file(SymData *sd)
322{
323 init_env();
324
325 FILE *f;
326 char fname[strlen(tabledir)+100];
327 uint64_t n = sd->coord->max, *sn = &sd->sym_coord->max;
328 bool r = true;
329
330 strcpy(fname, tabledir);
331 strcat(fname, "/");
332 strcat(fname, sd->filename);
333
334 if ((f = fopen(fname, "wb")) == NULL)
335 return false;
336
337 r = r && fwrite(&sd->sym_coord->max, sizeof(uint64_t), 1, f) == 1;
338 r = r && fwrite(sd->rep, sizeof(Cube), *sn, f) == *sn;
339 r = r && fwrite(sd->class, sizeof(uint64_t), n, f) == n;
340 r = r && fwrite(sd->transtorep, sizeof(Trans), n, f) == n;
341
342 fclose(f);
343 return r;
344}
345
346void
347init_symcoord()
348{
349 int i;
350
351 static bool initialized = false;
352 if (initialized)
353 return;
354 initialized = true;
355
356 for (i = 0; i < nsymdata; i++)
357 gensym(all_sd[i]);
358}
359

Generated with cgit - Back to sebastiano.tronto.net