forked from kdolum/cosmic-string-simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lisp
1551 lines (1389 loc) · 66 KB
/
test.lisp
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(in-package "CL-USER")
;;;Explicit initial conditions of various types
;;Just make one diamond for testing
(defun make-test-diamond ()
(let ((diamond (make-diamond :start (make-4vector 1.0 0.0 0.0 0.0)
:left (make-4vector 0.7 0.4 0.0 0.5)
:right (make-4vector 1.3 0.4 0.0 0.5))))
(setf (diamond-end diamond) (compute-diamond-end diamond))
diamond))
;;Make string from derivatives a'(t-sigma) and b'(sigma +t)
;;This should be rewritten to use the initial-conditions code like make-test-ab
;; Function rewritten to use the initial-conditions code like make-test-ab by ALE
(defun make-test-ab-prime (a-pfunction b-pfunction max-sigma points &key (offset zero-3vector) (string-number 0))
(let ((starts (explicit-string-from-apbp a-pfunction b-pfunction max-sigma points :offset offset)))
(if *test-string-explicit-output* (output-explicit-test-string starts)
(process-explicit-string starts string-number))))
;;Make a string from functions for a and b. MAX-SIGMA is the length of the string.
;;Functions will be called with POINTS values from 0 below MAX-SIGMA.
;;The argument of a is tau-sigma, meaning that increasing argument goes around the string the opposite way.
(defun explicit-string-from-apbp (a-pfunction b-pfunction max-sigma points &key (offset zero-3vector))
(mirror-image-let ((delta-sigma (/ max-sigma points))
(a-data (make-array points)))
(mirror-images
(loop for index below points
for sigma = (* delta-sigma index)
for a = (3to4vector (3vector-scale (funcall a-pfunction (+ sigma (/ delta-sigma 2))) (* 0.5 delta-sigma)) (* 0.5 delta-sigma))
do (setf (aref a-data index) a)))
(explicit-string-from-discrete-apbp a-data b-data :offset offset)))
;;Accepts discrete functions ap(t-sigma) and bp(t+sigma). These functions are lists of 3-vector values, and the index
;;in the list has no special meaning. The implicit t+/sigma argument changes by the spatial distance at each step,
;;so the tangent vector automatically has magnitude 1. The total argument change in the two functions must be the same.
;;We return a list of starting points for a diamond world sheet overlapping *initial-time*
(defun explicit-string-from-discrete-apbp (a b &key (offset zero-3vector))
(loop with results = (make-array (length a))
with start = (3to4vector offset *initial-time*)
with start-new = start
for index below (length a)
do (if (< (4vector-t start) *initial-time*)
(setf start-new (4vector+ start (aref b index)))
(setf start-new (4vector- start (aref a index))))
do (setf (aref results index) start-new)
do (setf start start-new)
finally
(return results)))
;;Create a string with a given shape, specified by position and
;;velocity functions
(defun make-test-string (x-function v-function max-sigma points &key open)
;;First make list of diamonds that touch at right and left
(finish-test-string (make-test-string-1 x-function v-function max-sigma points open) open))
;;DIAMONDS is a list of diamonds linked corner to corner for the initial conditions
;;If OPEN, the string has :DELETED at the ends
;;But this does not work properly unless it is inert
(defun finish-test-string (diamonds open)
(when *test-string-explicit-output*
(when open (error "There are no open explicit strings"))
(return-from finish-test-string
(output-explicit-test-string diamonds)))
(dolist (diamond diamonds)
(handle-new-diamond diamond))
;;Now make future diamonds so they are connected
(loop for last = (car (last diamonds)) then this
for this in diamonds ;Every pair of adjacent diamonds
for deleted = open then nil ;Open string starts with :deleted
for new = (if deleted :deleted
(make-diamond :left (diamond-end last)
:right (diamond-end this)
:start (diamond-right last)
:sw last
:se this
:tag (create-loop-tag (globalize-position (diamond-right last)))
:a-kink-created (diamond-a-kink-created last)
:b-kink-created (diamond-b-kink-created this)
))
unless (< (max (4vector-t (diamond-p this))
(4vector-t (diamond-q this)))
(/ (- diamond-span fudge-coordinates) 2))
do (error "Diamond edge longer than half span: ~S" this)
do (setf (diamond-ne last) new
(diamond-nw this) new)
unless (eq new :deleted)
do (setf (diamond-end new) (compute-diamond-end new))
(when open (setf (diamond-inertp new) t))
(handle-new-diamond new))
(check-data-structures))
;;This makes diamonds that are touching at the points, all of which are
;;at the present time. We call the functions exactly POINTS times.
(defun make-test-string-1 (x-function v-function max-sigma points open)
(loop with delta-sigma = (/ max-sigma points)
with origin = (3to4vector (funcall x-function 0.0) *initial-time*) ;starting and ending point of loop, as 4 vector at time 0
for index from 1 to (if open (1- points) points) ;Index of next point
for left = origin then right ;go around segments of loop
for right = (if (= index points) ;last point is just first
origin
(3to4vector (funcall x-function (* delta-sigma index)) *initial-time*)) ;Compute next point, 4vector
for center = (3vector-scale (3vector+ left right) 0.5)
for delta-x = (3vector- right left) ;left-to-right distance
for raw-v = (funcall v-function (* delta-sigma (- index 0.5))) ;midway between left and right
;;Component perpendicular to delta-x
for v = (3vector- raw-v (3vector-scale
delta-x
(/ (3vector-dot delta-x raw-v)
(3vector-dot delta-x delta-x))))
for speed = (3vector-length v)
for gamma = (/ 1 (sqrt (- 1 (* speed speed)))) ;boost factor
;;Compute the real delta-sigma. It may be different because of
;;using a finite number of points
for energy = (* gamma (3vector-length delta-x))
for delta-xt = (3vector-scale v energy) ;bottom-to-top dist
for delta-xt2 = (3vector-scale delta-xt 0.5) ;center to top dist
for p0 = (/ energy 2) ;time component of vectors
for start3 = (3vector- center delta-xt2) ;beginning of diamond
for end3 = (3vector+ center delta-xt2)
for start = (3to4vector start3 (- *initial-time* p0))
unless (fudge= delta-sigma energy (/ delta-sigma points))
do (warn "delta-sigma = ~S but energy = ~S. Maybe your x is not properly parameterized"
delta-sigma energy)
;;Convert everything to 4vectors and create diamond
collect (let ((new (make-diamond :start start
:left left
:right right
:end (3to4vector end3 (+ *initial-time* p0))
:a-kink-created (globalize-position start)
:b-kink-created (globalize-position start)
:tag (create-loop-tag (globalize-position start))
)))
(when open (setf (diamond-inertp new) t))
new)))
(defun setup-circle (&optional (points 20))
(make-test-string
#'(lambda (sigma) (make-3vector (cos sigma) (sin sigma) 0.0))
#'(lambda (sigma) (declare (ignore sigma)) zero-3vector)
(* 2 pi)
points))
(defun setup-links (&optional (points 16))
(make-test-string
#'(lambda (sigma) (make-3vector (+ 1.5 (cos sigma)) (+ 2.0 (sin sigma)) 2.0)) ;position
#'(lambda (sigma) (make-3vector (* 0.6 (sin (* 3 (+ 1 sigma)))) ;velocity
(* 0.6 (sin (* 4 (+ 2 sigma))))
(* 0.6 (sin (* 5 (+ 3 sigma))))))
(* 2 pi)
points)
(make-test-string
#'(lambda (sigma) (make-3vector (+ 2.5 (cos sigma)) 2.0 (+ 2.0 (sin sigma)))) ;position
#'(lambda (sigma) (make-3vector (* 0.6 (sin (* 3 (+ 1 sigma)))) ;velocity
(* 0.6 (sin (* 4 (+ 2 sigma))))
(* 0.6 (sin (* 5 (+ 3 sigma))))))
(* 2 pi)
points))
(defun setup-random-links (&key (points 80) (speed 0.1) velocities)
(unless velocities
(setq velocities (loop repeat points
collect (list (random speed) (random speed) (random speed)))))
(make-test-string
#'(lambda (sigma) (make-3vector (+ 3.5 (cos sigma)) (+ 5.0 (sin sigma)) 5.0))
#'(lambda (sigma) (declare (ignore sigma))
(list-3vector (pop velocities)))
(* 2 pi)
points)
(unless velocities
(setq velocities (loop repeat points
collect (list (random speed) (random speed) (random speed)))))
(make-test-string
#'(lambda (sigma) (make-3vector (+ 2.5 (cos sigma)) (+ 5.0 (/ (sin sigma) (sqrt 2))) (+ 5.0 (/ (sin sigma) (sqrt 2)))))
#'(lambda (sigma) (declare (ignore sigma))
(list-3vector (pop velocities)))
(* 2 pi)
points))
;;Circle with random perturbations
(defun setup-random-circle (&optional (points 8) velocities)
(unless velocities
(setq velocities (loop repeat points
collect (list (random 0.1) (random 0.1) (random 0.1)))))
(make-test-string
#'(lambda (sigma) (make-3vector (+ 5.0 (cos sigma)) (+ 5.0 (sin sigma)) 5.0))
#'(lambda (sigma) (declare (ignore sigma))
(list-3vector (pop velocities)))
(* 2 pi)
points))
(defun setup-moving-random-circle (&optional (points 80) velocities)
(unless velocities
(setq velocities (loop repeat points
collect (list (random 0.1) (+ 0.5 (random 0.1)) (random 0.1)))))
(make-test-string
#'(lambda (sigma) (make-3vector (+ 5.0 (cos sigma)) (+ 4.4 (sin sigma)) 5.0))
#'(lambda (sigma) (declare (ignore sigma))
(list-3vector (pop velocities)))
(* 2 pi)
points))
(defun setup-aco (&optional (points 52))
(make-test-string
#'(lambda (sigma) (make-3vector (/ (cos sigma) 2)
(/ (sin sigma) 2)
(/ (if (> sigma pi) (- (* 2 pi) sigma) sigma) 2)))
#'(lambda (sigma) (make-3vector (/ (sin sigma) 2)
(/ (- (cos sigma)) 2)
(if (> sigma pi) -0.5 0.5)))
(* 2 pi)
points))
(defun setup-burden (&rest ignore)
(declare (ignore ignore))
(error "use SETUP-BURDEN-LOOP instead of SETUP-BURDEN"))
;;Sets up the Burden loop parametrized by m, n and psi
;;The created diamonds overlaps time *INITIAL-TIME* and the center is at spatial position OFFSET
;;Our functions return A and B, not A' and B'. The tangent vectors are given by
;;A' = dA/dt = -dA/dsigma = (cos(m sigma/ampl), 0, sin(m sigma/ampl))
;;B' = dB/dt = dB/dsigma = (cos(n sigma/ampl), 0, -sin(m sigma/ampl)) rotated by psi
;;Cusps occur when A'=B'=(0,0,+/-1), so sigma_a = (j+1/2) pi ampl/m, sigma_b = (k+1/2) pi ampl/n
;;with j and k integers of opposite parity. The A' that appears on diamond edges is the difference between two
;;successive values of A, and likewise for B. We don't want this to be the cusp value. Since the
;;functions are called for sigma = 2 pi ampl l/pts) with l an integer, we would not want a cusp to occur at
;;sigma = 2 pi ampl (l+1/2)/pts, which would be the difference of two successive l values. So we need not to have
;;2 (l+1/2)/pts = (j+1/2)/m, i.e., pts/(2 m) = (l+1/2)/(j+1/2). Thus pts/(2 m) and likewise pts/(2 n)
;;should not be the ratio of odd integers.
(defun setup-burden-loop (&optional (n 1) (m 2) (psi (/ pi 2.0)) (points 4096)
(amplitude 1.0) (offset zero-3vector))
(flet ((check-ratio (m name)
(let ((ratio (/ points (* 2 m))))
(when (and (oddp (numerator ratio)) (oddp (denominator ratio)))
(warn "POINTS/2~A = ~S, so there will be diamonds moving at the speed of light" name ratio)))))
(check-ratio m :m) (check-ratio n :n))
(make-test-ab
#'(lambda (sigma)
(make-3vector (* amplitude (/ (sin (/ (* m (- sigma)) amplitude)) m))
0.0
(* amplitude (/ (cos (/ (* m sigma) amplitude)) m))))
#'(lambda (sigma)
(make-3vector (* amplitude (/ (sin (/ (* n sigma) amplitude)) n) (cos psi))
(* amplitude (/ (sin (/ (* n sigma) amplitude)) n) (sin psi))
(* amplitude (/ (cos (/ (* n sigma) amplitude)) n))
))
(* amplitude 2 pi)
points
:offset offset))
;;The Garfinkel-Vachaspati loop, with 4 kinks
;;ALPHA is the angle between a' and b'
(defun setup-gv (alpha &key (offset zero-3vector))
(let ((length 0.5)) ;Diamonds must not be too big or we get errors
(flet ((make (sigma alpha)
(cond ((or (zerop sigma) (fudge= sigma (* 2 length) 1e-15)) (make-zero-3vector))
((fudge= sigma length 1e-15) (make-3vector (* length (cos alpha)) (* length (sin alpha)) 0.0))
(t (error "Unexpected sigma in setup-gv")))))
(make-test-ab
#'(lambda (sigma) (make sigma 0.0)) ;a always along x axis
#'(lambda (sigma) (make sigma alpha))
(* length 2)
2 ;Points
:offset offset))))
;;Check gravity power against Garfinkel-Vachaspati paper
(defun gv-gravity-power (alpha)
(let ((p (+ 1 (cos alpha)))
(n (- 1 (cos alpha))))
(* (/ 32 (expt (sin alpha) 2))
(+ (* p (log (/ 2 p))) (* n (log (/ 2 n)))))))
(defun setup-loop-production (&optional (points 100))
(make-test-string
#'(lambda (sigma)
(let* ((theta (- sigma (* 1.25 pi)))
(r (/ 1 (- (expt (* 1.30 pi) 2) (expt theta 2)))))
(make-3vector (* r (cos theta)) (* r (sin theta)) (* theta 0.02))))
#'(lambda (sigma)
(let* ((theta (- sigma (* 1.25 pi)))
;; (r (/ 1 (- (expt (* 1.30 pi) 2) (expt theta 2))))
)
(make-3vector (* 0.4 (cos theta)) (* 0.4 (sin theta)) (* theta -0.1))))
(* 2.5 pi)
points
:open t))
;;Movie with wiggles passing to left and right
(defun setup-colliding-wiggles (&optional (points 300) (length 12.0) (amplitude 0.2))
(flet ((xy (sigma omega)
(if (or (< sigma 0.5) (> sigma 1.5)) (values 0.0 0.0)
(let* ((angle (* pi (- sigma 0.5))) ;0..pi in 0.5 to 1.5
(a (/ (* amplitude (sin angle)) omega))) ;Envelope
(values (* (if (= omega 1.0) (sqrt 2.0) 1.0) ;Expand in x because envelope small when this big
a (cos (* omega angle)))
(* a (sin (* omega angle))))))))
(make-test-string
#'(lambda (sigma)
(decf sigma (/ length 2))
(multiple-value-bind (x y) (xy (abs sigma) (if (plusp sigma) 7.0 1.0))
(make-3vector x y sigma)))
#'(lambda (sigma)
(decf sigma (/ length 2))
(make-3vector 0.0 0.0 (- (signum sigma))) ;move at speed of light towards origin
)
length
points
:open t)))
;;The first 0 of J_0
(defparameter Bessel-zero 2.4048255577)
;;A loop without a cusp. No Good.
(defun setup-no-cusp (&optional (points 32) (spread 0.4))
(let ((main (sqrt (- 1.0 (expt spread 2))))) ;Amplitude of main part of derivative
(flet ((ab (sigma)
(values (cos (* Bessel-zero (sin sigma))) ;Integrates to 0 regardless of main
(* Bessel-zero (sin sigma)))))
(make-test-ab-prime
#'(lambda (sigma) (multiple-value-bind (x y) (ab sigma)
(make-3vector (* main x)
(+ (* main y) (* spread (sin sigma)))
(* spread (cos sigma)))))
#'(lambda (sigma) (multiple-value-bind (x y) (ab sigma) (make-3vector (- x) 0.0 y)))
(* 2 pi)
points))))
;;2d moving circle for periodic boundary conditions
(defun setup-moving-circle (&optional (points 8) (v 0.5))
(make-test-string
#'(lambda (sigma) (make-3vector (+ 2.5 (cos sigma))
(+ 2.5 (sin sigma))
2.5))
#'(lambda (sigma) (make-3vector ;;v 0.0
(/ v (sqrt 2)) (/ v (sqrt 2))
(* 0.01 (cos sigma)))) ;small rotation
(* 2 pi)
points))
;;Slightly different version.
(defun setup-rising-circle (&optional (points 8) (v 0.5))
(make-test-string
#'(lambda (sigma) (make-3vector (+ 2.5 (cos sigma))
(+ 4.0 (sin sigma))
2.6))
#'(lambda (sigma) (make-3vector 0.0 (/ v (sqrt 2))
(* 0.01 (cos sigma)))) ;small rotation
(* 2 pi)
points))
(defun setup-falling-circle (&optional (points 8) (v 0.5))
(make-test-string
#'(lambda (sigma) (make-3vector (+ 2.5 (cos sigma))
2.0 ;X-Z plane
(+ 2.5 (sin sigma))))
#'(lambda (sigma) (make-3vector 0.0 (- (/ v (sqrt 2)))
(* 0.01 (cos sigma)))) ;small rotation
(* 2 pi)
points))
(defun setup-loop (points)
(make-test-string
#'(lambda (sigma) (make-3vector (cos sigma) (sin sigma) 0.0))
#'(lambda (sigma)
(make-3vector 0.0 0.0 (* 0.5 (cos sigma))))
(* 2 pi)
points))
;;Get 32 bits of actually random number from /dev/urandom. Sbcl (make-random-state t) just uses the current time,
;;which is the same in all processors
;;There is some hair involving not buffering the file, so we can only read the few bytes we need
;;We never return 0, which is used as a code for seed not supplied.
(defun get-really-random-number ()
(loop for random = (with-open-stream (f (sb-sys:make-fd-stream (sb-unix:unix-open "/dev/urandom" sb-unix:o_rdonly 0)
:element-type '(unsigned-byte 32)
:buffering :none :file "/dev/urandom"))
(read-byte f))
repeat 10
unless (zerop random)
do (format t "~&Random seed #x~X~%" random) (return random)
finally (error "Failed to get a nonzero random seed")))
;;Make a random-state from thirty-two random bits
(defun make-random-state-from-32 (random-32)
(sb-kernel::%make-random-state (sb-kernel::init-random-state random-32)))
;;Save the random seed for reproducing runs
(defun save-random-seed (&optional (file (random-seed-file *output-directory*)))
(with-open-file (stream file :direction :output)
(print *random-state* stream)))
;;Load previously stored random seed
(defun load-random-seed (&optional (file (random-seed-file (input-directory))))
(with-open-file (stream file)
(let ((seed (read stream))) ;get one form
(assert (random-state-p seed))
(format t "~&Reading random seed from ~S~%" file)
(setq *random-state* seed)
t)))
(defun maybe-delete-file (file)
(when (probe-file file)
(delete-file file)))
;;Remove previous output files. If random-seed set, delete that as well.
(defun delete-old-output (random-seed)
(format t "~&Deleting old output files...") (force-output)
(mapc #'maybe-delete-file (directory (all-dump-files *job-number*))) ;Delete old dumps for this job
(mapc #'maybe-delete-file (successor-files))
(maybe-delete-file (job-loop-spectrum-file))
(maybe-delete-file (job-bh-loop-spectrum-file))
(when random-seed
(maybe-delete-file (random-seed-file *output-directory*)))
(format t "done~%"))
;;Gives the smallest conformal time for light to cross the simulation volume
;;Since wiggles travel roughly at half light velocity, this gives the time before
;;correlations can contaminate evolution of the network.
(defun light-crossing-time (size)
size)
(defparameter *x-max* 0.5) ;maximum size loop we wait for before stopping run
;;If we are logging loops we need to wait until loops produced with size x-max * total-size will
;;have been deleted. This means the loop must oscillate twice and also the ratio of the loop size
;;to the horizon size (conformal time) must be less than *loop-preservation-threshold* (lpt).
(defun default-simulation-end (total-size initial-time lpt)
(let ((tmax (+ initial-time (light-crossing-time total-size)))) ;Last conformal time simulated.
;;Last loop formed with conformal size xmax tmax
;;It must oscillate twice (with fixed physical period given currently by l_phys/2) to know that it is
;;not self-intersecting, and then one more time to reach the deletion point.
(let ((extra (* 0.5 3 *x-max*)))
(cond ((null lpt)) ;No preservation threshold
((zerop lpt) ;Never deleting loops
(error "Can't default duration when loops are not deleted"))
(t
(setq extra (max extra (- (/ *x-max* lpt) 1))))) ;Relative extra physical time for lpt t = tmax xmax
(adjust-conformal-time-end tmax extra))))
;;Duration from the initial-time to the default-simulation-end time.
(defun default-duration-loops (total-size initial-time ldf *era*)
(- (default-simulation-end total-size initial-time ldf) initial-time))
(define-timer :simulate)
;;General driver for running simulations
(defun simulate (body-function &rest args &key ((:time *report-time*)) &allow-other-keys)
(maybe-time :overall
(account-time :simulate
(apply #'simulate-1 body-function args))))
(defmacro define-simulate-function (name &body body)
`(defun ,name (body-function ;Function to call to create initial string
&key ,@simulate-keywords)
,@body))
;;The arguments to SIMULATE
(define-simulate-argument size) ;Total size of simulation volume, or NIL for infinite
(define-simulate-argument split-factor 1 fixnum) ;Number of job volumes in each dimension
(define-simulate-argument ijkl) ;Starting point in IJKL coordinates
(define-simulate-argument overwrite) ;If set, clear output directory first. Otherwise it must be empty or non-existent
(define-simulate-argument reproduce) ;T = reproduce previous run. Directory: get seeds from that directory
(define-simulate-argument log) ;Write loop spectrum files
(define-simulate-argument timestamp 0.1 double-float) ;Timestamp at given interval
(define-simulate-argument start 1.0 double-float) ;Global time of start of whole simulation run. Can be used in init.
(define-simulate-argument end nil double-float) ;Global ending time of whole simulation run.
(define-simulate-argument time) ;This argument is handled by SIMULATE instead of SIMULATE-1
(define-simulate-argument room nil) ;Report space utilization at the end
(define-simulate-argument usage-report nil) ;Report memory usage periodically
(define-simulate-argument energy-report nil) ;Report energy in initial and final string.
;;Dump control.
(define-simulate-argument dump-times nil) ;List of times at which to do full dumps (including lengths)
(define-simulate-argument length-times nil) ;List of times at which to dump lengths
;;Instead of or in addition to specifying a list, you can specify things this way:
(define-simulate-argument dump-start nil double-float) ;Global time of first dump.
(define-simulate-argument dump-interval nil double-float) ;Interval between dumps
(define-simulate-argument dump-end nil) ;No dumps after this global time (plus fudge factor)
(define-simulate-argument dump-diamonds t)
(define-simulate-argument length-start nil double-float) ;Same variables for writing length
(define-simulate-argument length-interval nil double-float)
(define-simulate-argument length-end nil)
(define-simulate-argument bh-number nil)
(define-simulate-argument bh-size nil)
;;bh intersection control
(define-simulate-argument bh-times nil)
(define-simulate-argument bh-start nil double-float)
(define-simulate-argument bh-interval nil double-float)
(define-simulate-argument bh-end nil)
(define-simulate-argument pointbh nil)
(define-simulate-argument all-bhs nil)
(define-simulate-argument bh-probability nil double-float)
;;Return ordered list of (TIME ONLY-LENGTH-P) for the global set of dumps.
;;OVERALL-START is the global time that the simulation began. No dumps will be scheduled before then.
;;OUR-END is the global ending time of this simulation. We will not return any times after that.
(defun dump-schedule (overall-start our-end dump-times dump-start dump-interval dump-end
length-times length-start length-interval length-end)
(let* ((dumps (dump-schedule-1 overall-start our-end dump-times dump-start dump-interval dump-end))
(lengths (dump-schedule-1 overall-start our-end length-times length-start length-interval length-end))
(all (sort (copy-list ;SORT is destructive
(union dumps lengths :test #'fudge=global))
#'<)))
(loop for time in all
collect (list time (not (member time dumps :test #'fudge=global))))))
;;Return times that are either in TIMES or in the set from START (or 0.0) by INTERVAL to END (if any)
;;and between OVERALL-START and OUR-END. We are generous in which times are allowed, so, for example,
;; :start 4.4 :dump 0.1 will dump the initial conditions.
;;We return even times that come before the start of this job, so step number is just the position in the list.
;;Return value is not sorted.
(defun dump-schedule-1 (overall-start our-end times start interval end)
(union ;Supplied times that are not beyond the end of the run
(remove-if-not #'(lambda (time) (< time (+ our-end fudge-global-coordinates))) times) ;Too early checked elsewhere
(and interval ;Generate times between start and end
(loop for time from (or start 0.0) below (+ (if end (min end our-end) our-end) fudge-global-coordinates)
by interval
unless (< time (- overall-start fudge-global-coordinates)) ;ignore implicit too-early times
collect time))
:test #'fudge=global))
(defun check-initial-time (start)
(when (or (and (eq *era* :matter) (< start 4.0))
(and (eq *era* :radiation) (< start 2.0)))
(error "Initial time is too small for ~A era" *era*)))
(defvar *simulate-dry-run* nil) ;If set, simulate does nothing but check arguments
(defvar *simulate-just-write-info* nil) ;If set, simulate does nothing but write run-info file
;;Check for problems in simulate arguments. This happens even on a dry run.
(defun simulate-check-arguments (start end size log)
(check-initial-time start)
(unless (or size end)
(error "You didn't give SIZE, so we are in infinite volume, but then you must give END"))
(loop for last = nil then time
for (time probability) in *intersection-probabilities*
unless (and (numberp time) (numberp probability) (<= 0.0 probability 1.)
(or (null last) (> time last)))
do (error "*INTERSECTION-PROBABILITIES* should be an ordered list of (time probability))"))
(when *delete-unlucky-loops*
(cond ((and (= *intersection-probability* 1.0) (null *intersection-probabilities*))
(warn "Setting :DELETE-UNLUCKY-LOOPS with p=1 does not make sense"))
(log
(warn "You're deleting unlucky loops in self-intersecting trajectories and also logging loop sizes, so the results will not be accurate"))))
(when (and (not (zerop *loop-preservation-dump-start*)) ;Not the default
(not *loop-preservation-dump-x*))
(error "Giving :LOOP-PRESERVATION-DUMP-START without :LOOP-PRESERVATION-DUMP-X does not make sense")))
(defun simulate-check-dump-arguments (overall-start times start interval end dump-p)
(loop for time in times
when (< time (- overall-start fudge-global-coordinates))
do (error "Dump explicitly requested for time ~F before overall start time ~F" time overall-start))
(unless (or times interval) ;Not dumping. Shouldn't specify dump parameters
(when (and dump-p ;Dump, not just length
*loop-preservation-dump-x*)
(error "Giving :LOOP-PRESERVATION-DUMP-X without doing any dumps does not make sense"))
(when start
(error "Giving start time but no interval does not make sense"))
(when end
(error "Giving end time but no interval does not make sense"))))
(define-simulate-function simulate-1
(declare (ignore time)) ;Handled already in SIMULATE
(simulate-coerce) ;Coerce argument types
(simulate-check-arguments start end size log)
(simulate-check-dump-arguments start dump-times dump-start dump-interval dump-end t)
(simulate-check-dump-arguments start length-times length-start length-interval length-end nil)
(when *simulate-dry-run* (return-from simulate-1 "Dry run succeeded"))
(when pointbh
(setf *pointbh* pointbh)
(setf *bh-probability* bh-probability))
(when all-bhs
(setf *all-bhs* all-bhs))
(when (and bh-number (null *pointbh*))
(setf bh-times (bh-schedule bh-start bh-interval bh-end)))
(setf *dump-diamonds* dump-diamonds)
(if *dump-diamonds*
(format t "Dumping Diamonds~%")
(format t "NOT Dumping Diamonds~%"))
(when *simulate-just-write-info*
;;Use supplied end or last time covered by overall run. This is before the actual ending time of the last layer.
;;We only come here in the manager, so this can be figured out.
(let* ((overall-end (or end (+ start (jobs-duration size split-factor *manager-jobs*))))
(dump-schedule (dump-schedule start overall-end ;List of all dumps and whether they involve only lengths
dump-times dump-start dump-interval dump-end
length-times length-start length-interval length-end))
(length-times (mapcar #'car dump-schedule)) ;Times when length will be dumped, i.e., any dump
(full-dump-times (mapcar #'car (remove-if #'second dump-schedule)))) ;Times of actual dumps
(return-from simulate-1
(write-run-info-file :start start
:end overall-end
:dump-times full-dump-times :length-times length-times :bh-times bh-times
:split-factor split-factor :total-size size
:bh-size bh-size :bh-number bh-number))))
(when *job-number*
(format t "~&********** JOB ~D **********~%" *job-number*))
(cond (size ;Size given: normal case. It is the periodicity distance.
(initialize :total-size size :split-factor split-factor :ijkl ijkl :job-number *job-number*
:ijkl-origin (3to4vector zero-3vector *time-offset*)
:start start
:bh-size bh-size :bh-number bh-number :bh-start bh-start))
(t ;Infinite volume
(initialize :total-size nil)))
; (if *bh-number* ;if number of BH is set create the blackholes.dat file
; (if (eq *job-number* 0)
; (progn
; (sort-bhs)
; (format t "BHs has been created"))
; (format t "BHs created by other job")))
(let* ((end-local (and end (local-time end))) ;Convert to local
;;Local ending time of job. Fudge factor here is to make this go after the successor output event.
(job-end (+ (job-end-t) fudge-coordinates)))
(when (> *initial-time* job-end)
(error "Initial time ~S is after end of job volume ~S" *initial-time* job-end))
(unless (and end-local (<= end-local job-end)) ;default or restrict end to end of cube
(setq end-local job-end))
(let* ((our-end (global-time end-local)) ;Global ending time of this job
(dump-schedule (dump-schedule start our-end ;Dumps to be done by this job
dump-times dump-start dump-interval dump-end
length-times length-start length-interval length-end))
(*last-dump-time* (car (last dump-times))) ;Last explicitly given dump time for preservation code, or NIL
(*overall-end-time* (if *last-dump-time* ;take the largest result possible
(if *total-size* (max *last-dump-time* (+ start *total-size*)) *last-dump-time*)
job-end))) ;fall back on the guaranteed number if nothing's set
(format t "Overall end time for minimum diamond width calculation is ~S~%" *overall-end-time*)
(when overwrite ;Overwriting old files?
(delete-old-output (not reproduce))) ;Delete them.
(ensure-directories-exist (job-filename *output-directory* *job-number* "")) ;Make output directory if needed
(cond (*random-seed* ;Do things differently under manager
(setq *random-state* (make-random-state-from-32 *random-seed*)))
(reproduce ;Doing run again
(let ((*input-directory* (if (eq reproduce t) *input-directory* ;Reproduce from here
reproduce))) ;or given place
(load-random-seed))) ;get random state from before
(t (setq *random-state* (make-random-state-from-32 (get-really-random-number)))
(save-random-seed))) ;Save it out for later
(funcall body-function) ;Now initialize the run
(when (and (null *pointbh*) *bh-number*) ;if number of BH is set create the blackholes.dat file
(format t "File: ~S~%" (probe-file "blackholes.dat"))
(format t "BHs created by other job")
(my-bhs)
(clean-mybhs))
;;Regardless of how long we will run now, put in the event to communicate strings to successors
(main-calendar-add (job-end-t) (make-successor-output (job-end-t)))
;;Put in all events for dumping
(loop with created = nil ;Create directory first time it is needed
with step = 0 ;Count actual dumps
for (time only-lengths-p) in dump-schedule
do (when (>= (local-time time) (- *initial-time* fudge-coordinates)) ;Is this dump in our time period?
(request-dump (unless only-lengths-p step) time)
(unless (or only-lengths-p created)
(ensure-directories-exist (dump-file *job-number* 0)) ;If dumping create dump directory once
(setq created t)))
do (unless only-lengths-p (incf step))) ;Count step, even if dump is too early for us
(when timestamp
(main-calendar-add *initial-time* (make-timestamp *initial-time* timestamp)))
(when usage-report
(let ((first-usage-report (+ *initial-time* usage-report)))
(main-calendar-add first-usage-report (make-usage-report first-usage-report usage-report))))
(let ((initial-energy (and energy-report (total-length (get-paths (+ *initial-time* .01))))))
(setq *start-real-time* (get-internal-real-time) ;Save start times for usage reporting
*start-run-time* (get-internal-run-time)
*last-real-time* 0
*last-run-time* 0)
(when log ;Writing loop file
(setq *loops-found* (make-array 1000 :element-type 'double-float :fill-pointer 0 :adjustable t))
(when *bh-start*
(setq *bh-loops-found* (make-array 1000 :element-type 'double-float :fill-pointer 0 :adjustable t))))
(when (and *pointbh* *bh-start*)
(when (and (>= (local-time *bh-start*) (current-time)) (<= (local-time *bh-start*) end-local))
(evolve-until (local-time *bh-start*))
(format t "Creating point like BHs at ~S~%" *bh-start*)
(create-point-bhs)))
(when (and (null *pointbh*) bh-times) ;if bh-time is set check that is during the evolution and analyse the intersections
(loop for tbh in bh-times
do (when (and (>= (local-time tbh) (current-time)) (<= (local-time tbh) end-local))
(evolve-until (local-time tbh))
(format t "Checking BH intersections at ~S~%" tbh)
(create-bhs))))
(evolve-until end-local) ;Do it
(when (and *pointbh* *bh-start*)
(when (and (>= (local-time *bh-start*) (local-time (global-job-start *total-size* *time-offset* *job-number*))) (<= (local-time *bh-start*) end-local))
(writepointbhs)))
(when log
(if *loops-output* ;Stream already open
(write-recorded-loops) ;Use it
(with-open-file (*loops-output* (job-loop-spectrum-file) :direction :output
:if-does-not-exist :create :element-type '(unsigned-byte 64))
(write-recorded-loops))) ;Open new file and use it
(when *bh-start*
(if *bh-loops-output*
(write-recorded-bh-loops)
(with-open-file (*bh-loops-output* (job-bh-loop-spectrum-file) :direction :output
:if-does-not-exist :create :element-type '(unsigned-byte 64))
(write-recorded-bh-loops)))))
(when *length-output*
(force-output *length-output*)) ;Avoid loss of buffered lengths data
(when *report-time*
(format t "~&~:D diamonds advanced, ~D non-null sides could not be fixed immediately~%"
*advance-diamond-count* *compute-diamond-adjust-count*)
(format t "~D intersections performed ~@[(~D rejoinings)~], ~D rejoining~:P suppressed~@[ (~$%)~] to avoid monsters~:[~;, ~D skipped because of probability~]~%"
*intersections-performed* (and *count-rejoinings* *rejoinings-performed*) *suppressed-rejoinings*
(and (plusp *intersections-performed*)
(round (/ (* *suppressed-rejoinings* 100) *intersections-performed*)))
(plusp *intersections-unlucky*)
*intersections-unlucky*))
(format t "~&Finished with global time ~$~%" (global-time (current-time)))
(when energy-report
(format t "~% Total energy in initial conditions is ~D." initial-energy)
(format t "~% Total energy in non-inert remains is ~D." (total-length))
(format t "~% Energy difference is ~D." (- initial-energy (total-length)))
)))
(when room
(gc :full t)
(room))
(format t "~&********** JOB ~D COMPLETED **********~%~%" *job-number*)))
(defun simulate-continue (job-number &rest simulate-keys)
(apply #'simulate
#'(lambda ()
(read-initial-strings))
:job-number job-number
simulate-keys))
;;Run simulation and continue through job number N-1, all in this processor
(defun simulate-n (n function &rest simulate-keys)
(apply #'simulate function :job-number 0 simulate-keys)
(loop for job from 1 below n
do (format t "~&****************************** JOB ~D ******************************~%" job)
do (apply #'simulate-continue job simulate-keys)))
(defun simple-test (&rest simulate-keys &key (overwrite t) (size 20.0)
(start-time 5.0)
&allow-other-keys)
(apply #'simulate #'setup-moving-random-circle
;This gives the defaults or harmlessly duplicates the keywords
:overwrite overwrite :size size :start start-time
simulate-keys))
(defun test-aco (&rest simulate-keys &key (overwrite t) (size 20.0)
(start-time 1.0)
&allow-other-keys)
(apply #'simulate
#'setup-aco
:overwrite overwrite :size size :start start-time
simulate-keys))
(defun test-collision (&rest simulate-keys &key (overwrite t) (size 5.0)
&allow-other-keys)
(apply #'simulate
#'(lambda ()
(setup-rising-circle)
(setup-falling-circle))
:overwrite overwrite :size size
simulate-keys))
;; simulates links with varying resolution initial conditions (no ramdom velocities)
(defun test-links (&rest simulate-keys &key (overwrite t) (points 16) (size 4.0)
&allow-other-keys)
(apply #'simulate
#'(lambda ()
(setup-links points))
:overwrite overwrite :size size
simulate-keys))
;;Vachaspati-Vilenkin initial conditions
(defun do-vv (&rest keys)
(apply #'do-initial-1 #'setup-vv keys))
;;Explicit initial conditions. Default start time is 0.0.
(defun do-explicit (&rest keys &key (start 0.0) &allow-other-keys)
(apply #'do-initial-1 #'setup-explicit
:start start keys))
;;Driver for simulations with initial condition surface.
;;START here is what you want the clock to read at the initial condition time.
(defun do-initial-1 (setup-function &rest simulate-keys &key size (split-factor 1) (start 1.0) &allow-other-keys)
(let ((start-offset (/ (* (/ 3.5 4.0) size (sqrt (/ 2.0 3.0))) split-factor))) ;Desired time from origin to initial
(apply #'simulate #'(lambda () (maybe-setup-initial setup-function))
:time-offset (- start start-offset)
:start start
simulate-keys)))
;;Minimum size of simulation
(defun minimum-vv-simulation-size (split-factor)
(if (> split-factor 1)
(* split-factor 17.0) ;Size of each must be at least 12 sqrt(2). See notes.
20.0) ;This is about the smallest you can have without ending up with lattice overlap
)
(defun test-vv (&rest simulate-keys &key (overwrite t)
size
(split-factor 1)
&allow-other-keys)
(unless size
(setq size (minimum-vv-simulation-size split-factor)))
(apply #'do-vv :overwrite overwrite :size size simulate-keys))
;;Setup initial conditions if we are in one of the first layers
(defun maybe-setup-initial (setup-function)
(cond ((initialization-surface-p)
(maybe-time :setup (funcall setup-function)))
(t (format t "~&Initialization surface in the past. Reading strings...")
(read-initial-strings))))
;;;Checking system
;;Check various things in our data structures
(defun check-data-structures ()
(map-main-calendar #'check-main-calendar-entry)
(map-final-diamonds #'check-diamond)
(map-read-diamonds #'check-diamond)
;;Slow
;; (check-angles)
t)
;;Check that cells system is working.
(defun check-intersection-list (diamond)
(let* ((seen (make-hash-table :test #'eq)) ;Creates a hash table to keep track of diamonds from end points
(possibilities nil))
;;Get possibilities old way.
(map-main-calendar
#'(lambda (time object) ;Find any diamond on calendar
(declare (ignore time))
(when (typep object 'diamond) ;Look at all diamonds
(unless (diamond-inertp object) ;Doesn't go in list if inert
(unless (gethash object seen)
(setf (gethash object seen) t) ;Set the hash table to know that we have checked this diamond already
(push object possibilities))))))
;;Get possibilities that have bounding box overlap
(flet ((bounding-box-check (d)
(and (not (eq d diamond))
(diamond-box-overlap d diamond))))
(setq possibilities (remove-if-not #'bounding-box-check possibilities))
(let ((new-possibilities nil))
(do-diamond-cells-diamonds (d diamond)
(when (bounding-box-check d) (push d new-possibilities)))
;;Make sure there are no possibilities that the old system found and the new system lost.
;;Vice versa is OK because they might belong to neighbors and not be in the calendar
(unless (null (set-difference possibilities new-possibilities))
(error "Cell system failed for ~D" diamond))))))
(defun check-angles ()
(map-main-calendar
#'(lambda (time diamond1)
(declare (ignore time))
(when (diamondp diamond1)
(let ((p (3vector- (diamond-left diamond1) (diamond-start diamond1))))
(map-main-calendar
#'(lambda (time diamond2)
(declare (ignore time))
(when (diamondp diamond2)
(let* ((q (3vector- (diamond-right diamond2) (diamond-start diamond2)))
(cos (/ (3vector-dot p q) (3vector-length p) (3vector-length q))))
(when (> cos (- 1.0 1e-14))
(error "SW edge of ~S, ~S is too close to SE edge of ~S, ~S, cos ~F"
diamond1 p diamond2 q cos)))))))))))
(defun check-main-calendar-entry (time object)
(assert (>= time (current-time)))
(etypecase object
(diamond (assert (= (4vector-t (diamond-end object)) time))
(check-diamond object t))
(intersection (assert (= (4vector-t (event-location object)) time))
(assert (member object (diamond-pending-intersections (intersection-diamond-1 object))))
(when (intersection-diamond-2 object)
(assert (member object (diamond-pending-intersections (intersection-diamond-2 object))))))
(dump-request
(assert (fudge= (global-time time) (dump-request-time object) fudge-global-coordinates))) ;Check that it is in at the right time
;; (age-objects)
(timestamp)
(stop-evolving)
(successor-output)
))
(defun check-object-neighbors (object neighbors)
(assert neighbors) ;shouldn't be in table if none
(typecase object
(diamond (check-diamond object nil))))
(defun check-position-standardized (position)
(assert (< (4vector-Euclidian-distance position (standardize-position position)) fudge-coordinates)))
(defun check-diamond (diamond &optional from-queue-p)
(assert (diamondp diamond))
;; (check-position-standardized (diamond-left diamond))
;; (check-position-standardized (diamond-start diamond))
;; (check-position-standardized (diamond-right diamond))
(assert (< (3vector-length (diamond-p diamond)) (/ diamond-span 2)))
(assert (< (3vector-length (diamond-q diamond)) (/ diamond-span 2)))
;;Sides of diamonds should be null, but some deviation should be tolerated
;;when diamonds are cut.
;;Not doing this currently. Definition of 4vector-dot was changed
;; (assert (< (4vector-dot (diamond-p diamond) (diamond-p diamond)) 1d-5))
;; (assert (< (4vector-dot (diamond-q diamond) (diamond-q diamond)) 1d-5))
; (assert (> (3vector-length (diamond-p diamond)) (/ minimum-diamond-width 10))) ;allow something for redshifts
; (assert (> (3vector-length (diamond-q diamond)) (/ minimum-diamond-width 10)))
(mirror-images (assert (diamond-a-kink-created diamond)))
(unless (diamond-inertp diamond)
(assert (diamond-minima diamond)) ;Make sure that bounding box has been installed
(assert (diamond-maxima diamond)))
(mirror-image-let ((ne (diamond-ne diamond))
(se (diamond-se diamond)))
(mirror-images
(assert (not (and ne se))) ;At most one right (left) link
(let ((east (or ne se)))
(when from-queue-p ;Could be an old diamond whose advancement message has been delayed
(assert (or east (right-rejoining-junction diamond))))
(when east ;If exists, make sure right type
(assert (typep east '(or diamond handle keyword))) ;east may be :deleted, a keyword
(loop for index below (resource-pointer diamond-resource)
when (eq (aref (resource-objects diamond-resource) index) east)
do (error "~A link goes to a diamond in the resource for reuse" :east))))
(when (diamondp ne)
(assert (eq (diamond-end diamond) ;End of this diamond
(diamond-left ne))) ;the leftmost point of this one
;;This might not hold if the NE diamond has been cut.
;;(assert (eq (diamond-right diamond) (diamond-start ne)))
(if (not (eq (diamond-sw ne) diamond))
(format t "~S~%" diamond))
(assert (eq (diamond-sw ne) diamond)) ;reverse link
)))
(assert (not (4vector= (diamond-left diamond) (diamond-right diamond)
1e-14)))
(when from-queue-p ;If in our queue, more tests
(assert (or (diamond-finalp diamond)
(point-mine (diamond-end diamond)))) ;Shouldn't be here unless we own it
;;If the end is in the past, we should have advanced it already
(assert (<= (current-time) (4vector-t (diamond-end diamond)))
()
"~S ends in the past" diamond)
)
(check-diamond-intersections diamond)
(check-points-eq diamond)
;;Very slow
;; (check-intersection-list diamond)
)
;;Not used
(defun check-diamond-neighbors (diamond)
(mirror-images
(assert (or (diamond-w diamond)
(left-rejoining-junction diamond)))
) ;mirror-images
)
(defun check-points-eq (diamond)
(mirror-images
(let ((nw (diamond-nw diamond))
(sw (diamond-sw diamond)))
(if (and (diamondp nw)
(4vector= (diamond-right nw) (diamond-end diamond) fudge-coordinates))
(assert (eq (diamond-right nw) (diamond-end diamond))))
(if (and (diamondp nw)
(4vector= (diamond-start nw) (diamond-left diamond) fudge-coordinates))
(assert (eq (diamond-start nw) (diamond-left diamond))))
(if (and (diamondp sw)
(4vector= (diamond-right sw) (diamond-start diamond) fudge-coordinates))
(assert (eq (diamond-right sw) (diamond-start diamond)))) ;failing
(if (and (diamondp sw)
(4vector= (diamond-end sw) (diamond-left diamond) fudge-coordinates))
(assert (eq (diamond-end sw) (diamond-left diamond)))))))
(defun check-diamond-intersections (diamond)
(let*((pending-intersection-list (diamond-pending-intersections diamond)))
(loop for cons on pending-intersection-list
for intersection = (car cons)
do (check-pending-in-both intersection)
do (loop for other in (cdr cons) ;check for duplicates
when (4vector= (intersection-spacetime intersection)
(intersection-spacetime other)
fudge-coordinates)
do (error "Two intersections in the same place?")))))
(defun check-dump-junction (junction)
(when (and (rejoining-junction-p junction)
(rejoining-junction-dump-time junction))
(let* ((diamond (or (junction-left-diamond junction) (junction-right-diamond junction)))
(junction-time (global-time (diamond-position-time diamond :a (rejoining-junction-a junction)
:b (rejoining-junction-b junction)))))
(unless (fudge= (rejoining-junction-dump-time junction) junction-time