forked from kashif/evolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.c
1628 lines (1490 loc) · 55.9 KB
/
command.c
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
/*************************************************************
* This file is part of the Surface Evolver source code. *
* Programmer: Ken Brakke, [email protected] *
*************************************************************/
/*************************************************************
*
* file: command.c
*
* Purpose: Interactive user interface command interpreter.
*/
#include "include.h"
/*************************************************************
*
* function: recalc()
*
* purpose: get everything recalculated and redisplayed
* after user changes surface.
*/
void recalc()
{
global_timestamp++; /* so INFO quantities will recalc later */
if ( need_fe_reorder_flag )
{ /* straighten out facet order around edges */
if ( web.representation == SOAPFILM )
{ edge_id e_id;
FOR_ALL_EDGES(e_id)
fe_reorder(e_id);
}
need_fe_reorder_flag = 0;
}
reset_rot_order();
if ( web.torus_flag ) calc_periods(ADJUST_VOLUMES);
else if ( web.torus_period ) calc_periods(NO_ADJUST_VOLUMES);
if ( transform_expr[0] )
{ calc_view_transform_gens();
transform_gen_expr(transform_expr);
}
recalc_verts();
if ( overall_size <= 0 ) resize();
update_display();
if ( phase_flag )
{
if ( web.representation == STRING )
{ edge_id e_id;
FOR_ALL_EDGES(e_id)
set_e_phase_density(e_id);
}
else
{ facet_id f_id;
FOR_ALL_FACETS(f_id)
set_f_phase_density(f_id);
}
}
#ifdef MPI_EVOLVER
if ( this_task == 0 )
#endif
{
calc_content(Q_FIXED);
/* if ( web.torus_flag ) fix_volconst(); */
calc_pressure();
calc_energy();
change_flag = 0;
}
reset_conj_grad();
if ( normal_motion_flag ) begin_normal_motion();
} /* end recalc() */
/******************************************************************
*
* function: reset_conj_grad()
*
* purpose: re-initialize conjugate gradient.
*
*/
void reset_conj_grad()
{ int i;
vertex_id v_id;
int size = SDIM;
#ifdef MPI_EVOLVER
if ( this_task == MASTER_TASK )
{ struct mpi_command message;
message.cmd = mpi_RESET_CONJ_GRAD;
message.mode = ribiere_flag;
MPI_Bcast(&message,sizeof(struct mpi_command),MPI_BYTE,MASTER_TASK,
MPI_COMM_WORLD);
}
#endif
/* reset conjugate gradient */
if ( cg_hvector ) myfree((char *)cg_hvector);
cg_hvector = NULL;
cg_oldsum = 0.0;
if ( conj_grad_flag && ( ribiere_flag ) )
{ int r_attr = find_attribute(VERTEX,RIBIERE_ATTR_NAME);
if ( r_attr == -1 )
{ add_attribute(VERTEX,RIBIERE_ATTR_NAME,REAL_TYPE,1,&size,0,NULL,MPI_NO_PROPAGATE);
r_attr = find_attribute(VERTEX,RIBIERE_ATTR_NAME);
}
FOR_ALL_VERTICES(v_id)
{ REAL *g = (REAL*)get_extra(v_id,r_attr);
for ( i = 0 ; i < SDIM ; i++ ) g[i] = 0.0;
}
}
} /* end reset_conj_grad() */
/*************************************************************
*
* function: old_menu()
*
* purpose: Handle one command. Useful for event loopers.
*/
int old_menu (char *text)
{ int retval = 0;
if ( text[0] == '!' )
retval = old_history(text); /* history list */
else
retval = command(text,ADD_TO_HISTORY);
if ( change_flag )
recalc();
return retval;
} // end old_menu ()
/*************************************************************
*
* function: letter_commands()
*
* purpose: handle the single-letter commands.
*
*/
void report_times (void);
void letter_command (int c)
{
char response[140];
body_id b_id;
REAL val; /* for scanf */
int i,n,k;
int znum;
int old;
switch ( c )
{
/* Reporting */
case 'C': run_checks();
outstring("Checks completed.\n");
break;
case 'c': /* report count of elements and status */
memory_report();
break;
case 'E': dump_force(); break;
case 'e' : extrapolate(); break;
case 'i': /* i for information */
information();
break;
case 'v' : /* show volumes and quantities */
show_volumes();
break;
case 'z' : /* curvature test */
if ( web.representation == SIMPLEX )
outstring("Not implemented for simplex representation.\n");
curtest();
break;
case 'X' : /* extra attributes */
{
outstring(
" Element Attribute Type Offset Bytes Dimensions\n");
for ( i = 0 ; i < NUMELEMENTS; i++ )
{ for ( k = 0 ; k < web.skel[i].extra_count ; k++ )
{ int j;
sprintf(msg,"%9s %32s %10s %5d %5d ",typenames[i],
EXTRAS(i)[k].name,
datatype_name[EXTRAS(i)[k].type],
EXTRAS(i)[k].offset,
datatype_size[EXTRAS(i)[k].type]*EXTRAS(i)[k].array_spec.datacount);
for ( j = 0 ; j < EXTRAS(i)[k].array_spec.dim ; j++ )
sprintf(msg+strlen(msg),"[%d]",EXTRAS(i)[k].array_spec.sizes[j]);
if ( EXTRAS(i)[k].array_spec.dim == 0 ) strcat(msg," scalar ");
outstring(msg);
outstring("\n");
}
}
}
break;
/* Controlling model characteristics */
case 'A' : /* set adjustable parameters */
if ( set_parameters() )
recalc();
break;
case 'a' : /* toggle area normalization of force */
old = web.area_norm_flag;
web.area_norm_flag = !web.area_norm_flag;
web.norm_check_flag = 0; /* default OFF */
if ( web.area_norm_flag )
{ outstring("Area normalization ON.");
if ( old ) outstring(" (was on)\n");
else outstring(" (was off)\n");
prompt("If you want to check normal change, enter ratio: ",response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
if ( val > 0.0000001 )
{ web.norm_check_flag = 1;
web.norm_check_max = val;
}
calc_energy(); /* to make sure vertex areas set */
}
else
{ outstring("Area normalization OFF.");
if ( old ) outstring(" (was on)\n");
else outstring(" (was off)\n");
}
break;
case 'b' : /* set body volumes and pressures */
if ( web.skel[BODY].count == 0 )
{ outstring("No bodies.\n");
break;
}
{ REAL pp;
FOR_ALL_BODIES(b_id)
{
if ( get_battr(b_id) & PRESSURE )
{
pp = get_body_pressure(b_id);
sprintf(msg,"Body %s. Current pressure %f. Enter new: ",
ELNAME(b_id),(DOUBLE)pp);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&pp) > 0 )
{ set_body_pressure(b_id,pp);
reset_conj_grad();
if ( everything_quantities_flag )
{ struct gen_quant *q = GEN_QUANT(bptr(b_id)->volquant);
if ( pp == 0.0 )
{ q->modulus = 1.0;
q->flags &= ~(Q_FIXED|Q_ENERGY|Q_CONSERVED);
q->flags |= Q_INFO;
}
else
{ q->modulus = -pp;
q->flags &= ~(Q_FIXED|Q_INFO|Q_CONSERVED);
q->flags |= Q_ENERGY;
}
}
}
} /* end PRESSURE */
else /* edit volumes */
{
pp = get_body_fixvol(b_id);
sprintf(msg,"Body %s. Current target volume %g. Enter new: ",
ELNAME(b_id),(DOUBLE)pp);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
cmdptr = response;
if ( const_expr(response,&pp) > 0 )
{ set_body_fixvol(b_id,pp);
reset_conj_grad();
if ( pp == 0.0 )
{ if ( get_attr(b_id) & FIXEDVOL)
{ unset_attr(b_id,FIXEDVOL);
if ( everything_quantities_flag )
{ struct gen_quant *q = GEN_QUANT(bptr(b_id)->volquant);
q->target = 0.0;
q->flags &= ~(Q_FIXED|Q_ENERGY|Q_CONSERVED);
q->flags |= Q_INFO;
}
}
}
else
{
set_attr(b_id,FIXEDVOL);
if ( everything_quantities_flag )
{ struct gen_quant *q = GEN_QUANT(bptr(b_id)->volquant);
q->target = pp;
q->flags &= ~(Q_INFO|Q_ENERGY|Q_CONSERVED);
q->flags |= Q_FIXED;
}
}
}
}
} /* end BODIES */
} /* end block */
recalc();
break;
case 'f' : /* Set diffusion */
sprintf(msg,"Diffusion constant is %f. Enter new: ",
(DOUBLE)web.diffusion_const);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
web.diffusion_const = val;
if ( web.diffusion_const == 0.0 )
web.diffusion_flag = 0;
else web.diffusion_flag = 1;
break;
case 'G' : /* control gravity */
if ( web.representation == SIMPLEX )
{ outstring(
"Gravity not implemented for simplex representation.\n");
break;
}
if ( web.gravflag )
sprintf(msg,"Gravity is now ON with gravitational constant %f.\n",
(DOUBLE)web.grav_const);
else sprintf(msg,"Gravity is now OFF.\n");
outstring(msg);
prompt("Enter new constant (0 for OFF): ",response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
{ web.grav_const = val;
if ( web.grav_const != 0.0 ) web.gravflag = 1;
else web.gravflag = 0;
}
if (gravity_quantity_num >= 0 )
GEN_QUANT(gravity_quantity_num)->modulus =
web.gravflag ? web.grav_const : 0.0;
recalc();
break;
case 'J' : /* toggle jiggling on every move */
web.jiggle_flag = !web.jiggle_flag;
if ( web.jiggle_flag )
{ outstring("Now jiggling on every move.\n");
sprintf(msg,
"Enter temperature for jiggling (default %f): ",
(DOUBLE)web.temperature);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
web.temperature = val;
}
else outstring("Jiggling on every move disabled.\n");
break;
case 'k' : /* Magnitude of force opposing boundary short-circuiting */
sprintf(msg,"Gap constant is %f. Enter new: ",
(DOUBLE)web.spring_constant);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
web.spring_constant = val;
if ( everything_quantities_flag )
GEN_QUANT(gap_quantity_num)->modulus = val;
if ( web.spring_constant == 0.0 )
web.convex_flag = 0;
else
web.convex_flag = 1;
recalc();
break;
case 'M' : /* change model type */
if ( web.representation == SIMPLEX )
{ outstring(
"Higher-order models not implemented for simplex representation.\n");
break;
}
change_model();
recalc();
break;
case 'm' : /* Setting motion scale factor */
web.motion_flag = !web.motion_flag;
if ( web.motion_flag )
{
sprintf(msg,"Enter scale factor (%g): ",(DOUBLE)web.scale);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
web.scale = val;
}
else
{ energy_init = 0;
sprintf(msg,"Scale optimizing. Enter scale limit (%g): ",(DOUBLE)web.maxscale);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
web.maxscale = val;
if ( web.scale > web.maxscale )
web.scale = web.maxscale;
}
break;
case 'p' : /* Ambient pressure for compressible volumes */
if ( web.bodycount == 0 )
{ outstring("Can't do pressure without bodies.\n");
break;
}
sprintf(msg,"Pressure now %f\n",(DOUBLE)web.pressure);
outstring(msg);
prompt("Enter pressure (0 for rigid volumes): ",response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
web.pressure = val;
if ( web.pressure > 0.00000001 )
{
if ( !web.full_flag && !valid_id(web.outside_body) )
add_outside();
web.projection_flag = 0;
web.pressure_flag = 1;
if ( everything_quantities_flag )
{ FOR_ALL_BODIES(b_id)
create_pressure_quant(b_id);
}
}
else
{
web.projection_flag = 1;
web.pressure_flag = 0;
}
recalc();
break;
case 'Q': /* quantities */
report_quantities();
break;
case 'T': /* profiling times */
report_times();
break;
case 'W': /* homothety toggle */
web.homothety = !web.homothety;
sprintf(msg,"Homothety adjustment is %s.\n",
web.homothety ? "ON" : "OFF");
outstring(msg);
if ( web.homothety )
{ sprintf(msg,"Enter target size (%g): ",
(DOUBLE)homothety_target);
prompt(msg,response,sizeof(response));
const_expr(response,&homothety_target);
if ( logfd ) fprintf(logfd,"%f\n",(DOUBLE)homothety_target);
}
break;
/* Surface modification */
case 'g' : /* one gradient descent iteration */
if ( breakflag ) break;
iterate();
break;
case 'j' : /* jiggling */
sprintf(msg,"Enter temperature for jiggling (default %f): ",
(DOUBLE)web.temperature);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
web.temperature = val;
jiggle();
recalc();
break;
case 'K' : /* skinny triangle long edge subdivide */
if ( web.representation == SIMPLEX )
{ outstring(
"Not implemented for simplex representation.\n");
break;
}
for (;;)
{
prompt("Enter minimum acute angle desired(h for histogram): ",
response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( tolower(response[0]) == 'h' )
skinny_histogram();
else break;
}
if ( const_expr(response,&val) > 0 )
{
if ( web.counts_reported & facet_refine_count_bit )
web.facet_refine_count = 0;
sprintf(msg,"Edges refined: %d\n",
web.facet_refine_count += n = skinny(val));
web.counts_reported |= facet_refine_count_bit;
outstring(msg);
recalc();
}
break;
case 'l' : /* long edge subdivide */
for (;;)
{
prompt("Enter maximum edge length desired(h for histogram): ",response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( tolower(response[0]) == 'h' )
edge_histogram();
else break;
}
if ( const_expr(response,&val) > 0 )
{ web.max_len = val;
if ( web.counts_reported & edge_refine_count_bit )
web.equi_count = 0;
sprintf(msg,"Edges refined: %d\n",
web.edge_refine_count += n = articulate(web.max_len));
outstring(msg);
web.counts_reported |= edge_refine_count_bit;
if ( n > 0 ) recalc();
}
break;
case 'N' : /* Normalize target volumes to current volumes */
FOR_ALL_BODIES(b_id)
set_body_fixvol(b_id,get_body_volume(b_id));
outstring("Target volumes adjusted.\n");
break;
case 'n' : /* notching ridges and valleys */
if ( web.representation == SIMPLEX )
{ outstring(
"Not implemented for simplex representation.\n");
break;
}
for (;;)
{
prompt("Enter maximum angle(radians) between normals(h for histogram): ",response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( tolower(response[0]) == 'h' )
{ if ( web.representation == STRING )
command("histogram(vertex,dihedral)",NO_HISTORY);
else ridge_histogram();
}
else break;
}
if ( const_expr(response,&val) > 0 )
{ if ( web.representation == STRING )
{ sprintf(msg,
"refine edge ee where max(ee.vertex,dihedral) > %f",
(DOUBLE)val);
command(msg,NO_HISTORY);
web.notch_count = web.where_count;
}
else
{ web.max_angle = val;
if ( web.max_angle <= 0.0 ) break;
if ( web.counts_reported & notch_count_bit )
web.equi_count = 0;
sprintf(msg,"Number of edges notched: %d\n",
web.notch_count += n = ridge_notcher(web.max_angle));
outstring(msg);
web.counts_reported |= notch_count_bit;
if ( n > 0 ) recalc();
}
}
break;
case 'O' : /* pop nonminimal edges */
if ( web.representation == SIMPLEX )
{ outstring(
"Edge popping not implemented for simplex representation.\n");
break;
}
if ( web.representation == STRING )
{
if ( web.counts_reported & vertex_pop_count_bit )
web.vertex_pop_count = 0;
web.vertex_pop_count += n = verpop_str();
sprintf(msg,"Vertices popped: %d\n",web.vertex_pop_count);
outstring(msg);
web.counts_reported |= vertex_pop_count_bit;
}
else
{
if ( web.counts_reported & edge_pop_count_bit )
web.edge_pop_count = 0;
web.edge_pop_count = n = edgepop_film();
sprintf(msg,"Edges popped: %d\n",web.edge_pop_count);
outstring(msg);
web.counts_reported |= edge_pop_count_bit;
}
if ( n > 0 ) recalc();
break;
case 'o' : /* pop nonminimal edges and vertices */
if ( web.representation == SIMPLEX )
{ outstring(
"Vertex popping not implemented for simplex representation.\n");
break;
}
if ( web.representation == STRING )
web.vertex_pop_count = n = verpop_str();
else
web.vertex_pop_count = n = popfilm();
if ( web.counts_reported & vertex_pop_count_bit )
web.edge_pop_count = 0;
sprintf(msg,"Vertices popped: %d\n",web.vertex_pop_count);
outstring(msg);
web.counts_reported |= vertex_pop_count_bit;
if ( n > 0 ) recalc();
break;
case 'r' : refine(); energy_init = 0;
memory_report();
web.min_area /= 4;
web.max_len /= 2;
web.min_length /= 2;
recalc();
break;
case 't' : /* tiny edge subdivide */
for (;;)
{
prompt("Enter minimum edge length desired(h for histogram): ",response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( tolower(response[0]) == 'h' )
edge_histogram();
else break;
}
web.min_length = 0.0;
if ( const_expr(response,&val) > 0 )
web.min_length = val;
else break;
if ( web.min_length <= 0.0 ) break;
if ( web.counts_reported & edge_delete_count_bit )
web.edge_delete_count = 0;
sprintf(msg,"Deleted edges: %d\n",
web.edge_delete_count += n = edgeweed(web.min_length));
outstring(msg);
web.counts_reported |= edge_delete_count_bit;
if ( n > 0 ) recalc();
break;
case 'U' : /* conjugate gradient */
old = conj_grad_flag;
if ( conj_grad_flag )
{ if ( cg_hvector ) myfree((char *)cg_hvector);
cg_hvector = NULL;
cg_oldsum = 0.0;
conj_grad_flag = 0;
outstring("Conjugate gradient now OFF.");
if ( old ) outstring(" (was on)\n");
else outstring(" (was off)\n");
}
else
{ conj_grad_flag = 1;
outstring("Conjugate gradient now ON.");
if ( old ) outstring(" (was on)\n");
else outstring(" (was off)\n");
reset_conj_grad();
if ( web.motion_flag )
kb_error(1639,"Fixed scale is ON! Probably not a good idea with conjugate gradient.\n",WARNING);
}
break;
case 'u' : /* equiangulate */
if ( web.counts_reported & equi_count_bit )
web.equi_count = 0;
sprintf(msg,"Edges switched in equiangulation: %d\n",
web.equi_count += n = equiangulate() );
web.counts_reported |= equi_count_bit;
outstring(msg);
if ( n > 0 )
{ recalc();
if ( web.torus_flag )
fix_volconst();
}
break;
case 'V' : /* move vertex to average of neighbors */
vertex_average(VOLKEEP);
outstring("Vertex averaging done.\n");
recalc();
break;
case 'w' : /* weed small triangles */
if ( web.representation == SIMPLEX )
{ outstring(
"Triangle weeding not implemented for simplex representation.\n");
break;
}
for (;;)
{
prompt("Enter minimum area desired(h for histogram): ",
response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( tolower(response[0]) == 'h' )
area_histogram();
else break;
}
web.min_area = 0.0;
if ( const_expr(response,&val) > 0 )
web.min_area = val;
else break;
if ( web.min_area <= 0.0 ) break;
if ( web.counts_reported & facet_delete_count_bit )
web.facet_delete_count = 0;
sprintf(msg,"Skinny triangles weeded: %d\n",
web.facet_delete_count += n = areaweed(web.min_area));
outstring(msg);
web.counts_reported |= facet_delete_count_bit;
if ( n > 0 ) recalc();
break;
case 'y' : /* torus duplication */
if ( web.representation == SIMPLEX )
{ outstring(
"Torus duplication not implemented for simplex representation.\n");
break;
}
if ( ! web.torus_flag )
{ outstring("Torus model not in effect.\n");
break;
}
if ( SDIM == 2 )
prompt("Duplicate which period(1,2)? ",response,sizeof(response));
else
prompt("Duplicate which period(1,2,3)? ",response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
i = atoi(response);
if ( i < 1 || i > SDIM )
outstring("Improper period number.\n");
else tordup(i-1);
recalc();
break;
case 'Z' : /* zooming in on vertex */
znum = loc_ordinal(web.zoom_v) + 1;
sprintf(msg,"Enter zoom vertex number (%d): ",znum);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
sscanf(response,"%d",&znum);
/* check vertex still exists */
{ vertex_id v_id;
int found = 0;
FOR_ALL_VERTICES(v_id)
{ if ( znum == (loc_ordinal(v_id)+1) )
{ web.zoom_v = v_id; found = 1; break; }
}
if ( !found )
{ kb_error(1640,"Zoom vertex not found.\n",WARNING);
break;
}
}
sprintf(msg,"Enter cut-off radius (%f): ",(DOUBLE)web.zoom_radius);
prompt(msg,response,sizeof(response));
if ( logfd ) fprintf(logfd,"%s\n",response);
if ( const_expr(response,&val) > 0 )
web.zoom_radius = val;
zoom_vertex(web.zoom_v,web.zoom_radius);
recalc();
break;
/* Graphical output */
case 'D' : old = go_display_flag;
go_display_flag = !go_display_flag;
if ( go_display_flag )
{ outstring("Automatic display ON.");
update_display();
}
else
outstring("Automatic display OFF.");
if ( old ) outstring(" (was on)\n");
else outstring(" (was off)\n");
break;
case 'd' :
dump();
break;
case 'P' : /* create graphics data file */
display_file(-1);
break;
case 's' : /* Show image */
if ( !go_display_flag && !dont_resize_flag )
resize();
go_display_flag = 1;
do_show();
break;
/* Process control */
case 'F' : /* log commands */
if ( logfd )
{ fclose(logfd);
logfd = NULL;
outstring("Command logging OFF.\n");
break;
}
prompt("Name of log file: ",response,sizeof(response));
if ( response[0] == '\0' ) break;
logfd = fopen(response,"w");
if ( logfd == NULL )
{ perror(response); break; }
break;
case 'S' : /* save binary form */
outstring("Binary save not currently functional.\nUse 'd' Ascii dump.\n");
break;
case 'R' : /* restore(NULL); */
outstring("R (restore) command discontinued.\n");
break;
case 'x' :
case 'q' : /* Exit */
if ( logfd )
{ fclose(logfd);
logfd = NULL;
outstring("Command logging OFF.\n");
}
if ( subshell_depth )
{ exit_flag = 1;
break;
}
#ifdef __cplusplus
loadfilename[0] = 0;
loadstub();
#else
startup(NULL);
#ifdef MPI_EVOLVER
/* MPI_Barrier(MPI_COMM_WORLD); */ /* extra kludge needed */
#endif
longjmp(jumpbuf[0],1); /* kludge, but current command
list just got deallocated */
#endif
break;
case '?' :
case 'H' :
case 'h' : /* help screen */
main_help();
break;
case ' ' : break;
case '\t' : break;
case '\b' : break;
case '\r' : break;
case '\n' : break;
default : if ( c != '\0' )
{ sprintf(msg,"Illegal command: %c. Type h for help.\n", c);
outstring(msg);
}
break;
} /* end switch */
} /* end letter_command() */
/********************************************************************
*
* Function: extrapolate()
*
* Purpose: prints extrapolation of results to infinite resolution
*
*/
void extrapolate()
{
int m;
REAL d1,d2,ext;
for ( m = 0 ; m <= reflevel ; m++ )
{
#ifdef FLOAT128
sprintf(msg,"refinement: %1d energy: %*.*Qg ",m,DWIDTH,DPREC,extrap_val[m]);
#elif defined(LONGDOUBLE)
sprintf(msg,"refinement: %1d energy: %*.*Lg ",m,DWIDTH,DPREC,extrap_val[m]);
#else
sprintf(msg,"refinement: %1d energy: %19.15f ",m,extrap_val[m]);
#endif
outstring(msg);
if ( m > 1 ) /* can extrapolate */
{ d1 = extrap_val[m-1] - extrap_val[m-2];
d2 = extrap_val[m] - extrap_val[m-1];
ext = extrap_val[m] - d2*d2/(d2 - d1);
#ifdef FLOAT128
sprintf(msg,"extrapolation: %*.*Qg\n",DWIDTH,DPREC,ext);
#elif defined(LONGDOUBLE)
sprintf(msg,"extrapolation: %*.*Lg\n",DWIDTH,DPREC,ext);
#else
sprintf(msg,"extrapolation: %19.15f\n",ext);
#endif
outstring(msg);
}
else outstring("\n");
}
} // end extrapolate()
/*****************************************************************
*
* function: recalc_verts()
*
* purpose: recalculate vertex coordinates after boundaries or
* constraints changed.
*
*/
void recalc_verts()
{
vertex_id v_id;
if ( threadflag )
thread_launch(TH_PROJECT_ALL_ACTUAL,VERTEX);
else
FOR_ALL_VERTICES(v_id)
{
if ( get_vattr(v_id) & BOUNDARY )
{ struct boundary *boundary = get_boundary(v_id);
REAL *param = get_param(v_id);
REAL *x = get_coord(v_id);
int j;
for ( j = 0 ; j < SDIM ; j++ )
x[j] = eval(boundary->coordf[j],param,v_id,NULL);
}
if ( get_vattr(v_id) & CONSTRAINT )
project_v_constr(v_id,ACTUAL_MOVE,RESET_ONESIDEDNESS);
}
} // end recalc_verts()
/*****************************************************************
*
* function: information()
*
* purpose: prints information for 'i' command
*
*/
void information()
{
REAL total_volume;
body_id b_id;
sprintf(msg,"Datafile: %s\n",datafilename);
outstring(msg);
if ( web.area_norm_flag )
{ sprintf(msg,"Total time: %f\n",(DOUBLE)total_time);
outstring(msg);
}
#ifdef FLOAT128
sprintf(msg,"Total energy: %*.*Qg\n",DWIDTH,DPREC,web.total_energy);
#elif defined(LONGDOUBLE)
sprintf(msg,"Total energy: %*.*Lg\n",DWIDTH,DPREC,web.total_energy);
#else
sprintf(msg,"Total energy: %17.15g\n",web.total_energy);
#endif
outstring(msg);
if ( web.spring_energy != 0.0 )
{
#ifdef FLOAT128
sprintf(msg,"Gap energy: %*.*Qg\n",DWIDTH,DPREC,web.spring_energy);
#elif defined(LONGDOUBLE)
sprintf(msg,"Gap energy: %*.*Lg\n",DWIDTH,DPREC,web.spring_energy);
#else
sprintf(msg,"Gap energy: %17.15g\n",web.spring_energy);
#endif
outstring(msg);
}
#ifdef FLOAT128
sprintf(msg,"Total %s: %*.*Qg\n",areaname,DWIDTH,DPREC,web.total_area);
#elif defined(LONGDOUBLE)
sprintf(msg,"Total %s: %*.*Lg\n",areaname,DWIDTH,DPREC,web.total_area);
#else
sprintf(msg,"Total %s: %17.15g\n",areaname,web.total_area);
#endif
outstring(msg);
if ( web.conformal_flag )
{ sprintf(msg,"Euclidean measure: %17.15f\n",
(DOUBLE)euclidean_area);
outstring(msg);
}
if ( web.modeltype == LAGRANGE )
{ if ( bezier_flag )
sprintf(msg,"Lagrange order %d (Bezier basis polynomials)\n",
web.lagrange_order);
else
sprintf(msg,"Lagrange order %d\n",web.lagrange_order);
outstring(msg);
}
sprintf(msg,"Integral order 1D: %d 2D: %d\n",web.gauss1D_order,
web.gauss2D_order);