/
ref_metric_test.c
3423 lines (2997 loc) · 121 KB
/
ref_metric_test.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
/* Copyright 2014 United States Government as represented by the
* Administrator of the National Aeronautics and Space
* Administration. No copyright is claimed in the United States under
* Title 17, U.S. Code. All Other Rights Reserved.
*
* The refine platform is licensed under the Apache License, Version
* 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include "ref_metric.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ref_adapt.h"
#include "ref_adj.h"
#include "ref_args.h"
#include "ref_cell.h"
#include "ref_clump.h"
#include "ref_collapse.h"
#include "ref_dict.h"
#include "ref_edge.h"
#include "ref_egads.h"
#include "ref_export.h"
#include "ref_face.h"
#include "ref_fixture.h"
#include "ref_gather.h"
#include "ref_geom.h"
#include "ref_grid.h"
#include "ref_histogram.h"
#include "ref_import.h"
#include "ref_iso.h"
#include "ref_list.h"
#include "ref_malloc.h"
#include "ref_math.h"
#include "ref_matrix.h"
#include "ref_migrate.h"
#include "ref_mpi.h"
#include "ref_node.h"
#include "ref_part.h"
#include "ref_phys.h"
#include "ref_smooth.h"
#include "ref_sort.h"
#include "ref_split.h"
#include "ref_validation.h"
/*
./test.sh ref_metric && ./ref_metric_test \
../acceptance/2d/linear/two/accept-2d-two-09.b8.ugrid \
--parent ../acceptance/2d/linear/two/accept-2d-two-08.b8.ugrid \
../acceptance/2d/linear/two/accept-2d-two-08.metric
*/
REF_STATUS ref_metric_test_constant_integrand(void *constant_double, REF_DBL t,
REF_DBL *value);
REF_STATUS ref_metric_test_constant_integrand(void *constant_double, REF_DBL t,
REF_DBL *value) {
SUPRESS_UNUSED_COMPILER_WARNING(t);
*value = *((REF_DBL *)constant_double);
return REF_SUCCESS;
}
REF_STATUS ref_metric_test_linear_integrand(void *constant_ax_b, REF_DBL t,
REF_DBL *value);
REF_STATUS ref_metric_test_linear_integrand(void *constant_ax_b, REF_DBL t,
REF_DBL *value) {
REF_DBL a = ((REF_DBL *)constant_ax_b)[0];
REF_DBL b = ((REF_DBL *)constant_ax_b)[1];
*value = a * t + b;
return REF_SUCCESS;
}
REF_STATUS ref_metric_test_quadratic_integrand(void *constant_ax2_bx_c,
REF_DBL t, REF_DBL *value);
REF_STATUS ref_metric_test_quadratic_integrand(void *constant_ax2_bx_c,
REF_DBL t, REF_DBL *value) {
REF_DBL a = ((REF_DBL *)constant_ax2_bx_c)[0];
REF_DBL b = ((REF_DBL *)constant_ax2_bx_c)[1];
REF_DBL c = ((REF_DBL *)constant_ax2_bx_c)[2];
*value = a * t * t + b * t + c;
return REF_SUCCESS;
}
REF_STATUS ref_metric_test_constant_integrand2(void *constant_area,
REF_DBL *bary, REF_DBL *value);
REF_STATUS ref_metric_test_constant_integrand2(void *constant_area,
REF_DBL *bary, REF_DBL *value) {
REF_DBL constant = ((REF_DBL *)constant_area)[0];
REF_DBL area = ((REF_DBL *)constant_area)[1];
SUPRESS_UNUSED_COMPILER_WARNING(bary);
*value = constant * area;
return REF_SUCCESS;
}
REF_STATUS ref_metric_test_xy2(void *state, REF_DBL *bary, REF_DBL *value);
REF_STATUS ref_metric_test_xy2(void *state, REF_DBL *bary, REF_DBL *value) {
REF_DBL area = 1.0;
REF_DBL x = 2.0 * (1.0 - bary[0]);
REF_DBL y = bary[2];
SUPRESS_UNUSED_COMPILER_WARNING(state);
*value = x * y * y * area;
return REF_SUCCESS;
}
int main(int argc, char *argv[]) {
REF_INT fixed_point_pos = REF_EMPTY;
REF_INT curve_limit_pos = REF_EMPTY;
REF_INT parent_pos = REF_EMPTY;
REF_INT wlp_pos = REF_EMPTY;
REF_INT moving_pos = REF_EMPTY;
REF_INT explore_pos = REF_EMPTY;
REF_INT multigrad_pos = REF_EMPTY;
REF_INT lp_pos = REF_EMPTY;
REF_INT combine_pos = REF_EMPTY;
REF_INT opt_goal_pos = REF_EMPTY;
REF_INT no_goal_pos = REF_EMPTY;
REF_INT venditti_pos = REF_EMPTY;
REF_INT belme_pos = REF_EMPTY;
REF_INT euler_opt_goal_pos = REF_EMPTY;
REF_INT euler_cons_pos = REF_EMPTY;
REF_INT viscous_cons_pos = REF_EMPTY;
REF_INT hmax_pos = REF_EMPTY;
REF_INT buffer_pos = REF_EMPTY;
REF_INT kexact_pos = REF_EMPTY;
REF_INT complexity_pos = REF_EMPTY;
REF_INT intersection_pos = REF_EMPTY;
REF_INT gradation_pos = REF_EMPTY;
REF_INT cloud_pos = REF_EMPTY;
REF_INT wake_pos = REF_EMPTY;
REF_INT stepexp_pos = REF_EMPTY;
REF_INT decompose_pos = REF_EMPTY;
REF_INT imply_pos = REF_EMPTY;
REF_INT eigs_pos = REF_EMPTY;
REF_INT error_pos = REF_EMPTY;
REF_MPI ref_mpi;
RSS(ref_mpi_start(argc, argv), "start");
RSS(ref_mpi_create(&ref_mpi), "create");
ref_mpi_stopwatch_start(ref_mpi);
RXS(ref_args_find(argc, argv, "--fixed-point", &fixed_point_pos),
REF_NOT_FOUND, "arg search");
RXS(ref_args_find(argc, argv, "--curve-limit", &curve_limit_pos),
REF_NOT_FOUND, "arg search");
RXS(ref_args_find(argc, argv, "--parent", &parent_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--wlp", &wlp_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--lp", &lp_pos), REF_NOT_FOUND, "arg search");
RXS(ref_args_find(argc, argv, "--combine", &combine_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--multigrad", &multigrad_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--moving", &moving_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--explore", &explore_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--opt-goal", &opt_goal_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--no-goal", &no_goal_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--venditti", &venditti_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--belme", &belme_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--euler-opt-goal", &euler_opt_goal_pos),
REF_NOT_FOUND, "arg search");
RXS(ref_args_find(argc, argv, "--euler-cons", &euler_cons_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--viscous-cons", &viscous_cons_pos),
REF_NOT_FOUND, "arg search");
RXS(ref_args_find(argc, argv, "--kexact", &kexact_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--hmax", &hmax_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--buffer", &buffer_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--complexity", &complexity_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--intersection", &intersection_pos),
REF_NOT_FOUND, "arg search");
RXS(ref_args_find(argc, argv, "--gradation", &gradation_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--cloud", &cloud_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--wake", &wake_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--stepexp", &stepexp_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--decompose", &decompose_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--imply", &imply_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--eigs", &eigs_pos), REF_NOT_FOUND,
"arg search");
RXS(ref_args_find(argc, argv, "--error", &error_pos), REF_NOT_FOUND,
"arg search");
if (curve_limit_pos != REF_EMPTY) {
REF_GRID ref_grid;
REIS(1, curve_limit_pos,
"required args: --curve-limit grid.ext input.metric geom.egads "
"[assoc.gas]");
REIS(5, argc,
"required args: --curve-limit grid.ext input.metric geom.egads "
"[assoc.gas]");
RSS(ref_import_by_extension(&ref_grid, ref_mpi, argv[2]),
"unable to load target grid in position 1");
RSS(ref_part_metric(ref_grid_node(ref_grid), argv[3]),
"unable to load parent metric in position 2");
RSS(ref_egads_load(ref_grid_geom(ref_grid), argv[4]),
"unable to load egads in position 3");
RSS(ref_metric_constrain_curvature(ref_grid), "crv const");
RSS(ref_gather_metric(ref_grid, "ref_metric_test_curve_limit.metric"),
"export curve limit metric");
RSS(ref_export_tec_metric_ellipse(ref_grid, "ref_metric_test_curve_limit"),
"al");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (buffer_pos == 1) {
REF_GRID ref_grid;
REF_DBL complexity, *metric;
REIS(6, argc,
"required args: --buffer grid.ext input-metric.solb complexity "
"output-metric.solb");
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]),
"unable to load target grid in position 2");
ref_mpi_stopwatch_stop(ref_mpi, "read grid");
if (ref_mpi_once(ref_mpi)) printf("reading metric %s\n", argv[3]);
RSS(ref_part_metric(ref_grid_node(ref_grid), argv[3]),
"unable to load parent metric in position 3");
ref_mpi_stopwatch_stop(ref_mpi, "read metric");
complexity = atof(argv[4]);
if (ref_mpi_once(ref_mpi))
printf("buffering at complexity %f\n", complexity);
ref_malloc(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
RSS(ref_metric_from_node(metric, ref_grid_node(ref_grid)), "set node");
RSS(ref_metric_buffer_at_complexity(metric, ref_grid, complexity),
"buffer at complexity");
RSS(ref_metric_to_node(metric, ref_grid_node(ref_grid)), "set node");
ref_free(metric);
ref_mpi_stopwatch_stop(ref_mpi, "buffer");
if (ref_mpi_once(ref_mpi)) printf("writing metric %s\n", argv[5]);
RSS(ref_gather_metric(ref_grid, argv[5]), "export curve limit metric");
ref_mpi_stopwatch_stop(ref_mpi, "write metric");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (wlp_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *scalar, *weight, *metric;
REF_INT p;
REF_DBL gradation, complexity, current_complexity, hmin, hmax;
REF_RECON_RECONSTRUCTION reconstruction = REF_RECON_L2PROJECTION;
REF_INT ldim, wdim;
REIS(1, wlp_pos,
"required args: --wlp grid.meshb scalar.solb weight.solb "
"p gradation complexity output-metric.solb");
if (9 > argc) {
printf(
"required args: --wlp grid.meshb scalar.solb weight.solb "
"p gradation complexity output-metric.solb\n");
return REF_FAILURE;
}
hmin = -1.0;
hmax = -1.0;
if (REF_EMPTY != hmax_pos) {
if (hmax_pos >= argc - 1) {
printf("option missing value: --hmax max_edge_length\n");
return REF_FAILURE;
}
hmax = atof(argv[hmax_pos + 1]);
}
p = atoi(argv[5]);
gradation = atof(argv[6]);
complexity = atof(argv[7]);
if (REF_EMPTY != kexact_pos) {
reconstruction = REF_RECON_KEXACT;
}
if (ref_mpi_once(ref_mpi)) {
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
printf("reconstruction %d\n", (int)reconstruction);
printf("hmin %f hmax %f (negative is inactive)\n", hmin, hmax);
printf("buffer %d (negative is inactive)\n", buffer_pos);
}
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
if (ref_mpi_para(ref_mpi)) {
if (ref_mpi_once(ref_mpi)) printf("part %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]), "part");
ref_mpi_stopwatch_stop(ref_mpi, "part mesh");
} else {
if (ref_mpi_once(ref_mpi)) printf("import %s\n", argv[2]);
RSS(ref_import_by_extension(&ref_grid, ref_mpi, argv[2]), "import");
ref_mpi_stopwatch_stop(ref_mpi, "import mesh");
}
if (ref_mpi_once(ref_mpi)) printf("reading scalar %s\n", argv[3]);
RSS(ref_part_scalar(ref_grid, &ldim, &scalar, argv[3]),
"unable to load scalar in position 3");
REIS(1, ldim, "expected one scalar");
ref_mpi_stopwatch_stop(ref_mpi, "read scalar");
if (ref_mpi_once(ref_mpi)) printf("reading weight %s\n", argv[4]);
RSS(ref_part_scalar(ref_grid, &wdim, &weight, argv[4]),
"unable to load weight in position 4");
REIS(1, wdim, "expected one weight");
ref_malloc(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
RSS(ref_metric_lp(metric, ref_grid, scalar, weight, reconstruction, p,
gradation, complexity),
"lp norm");
ref_mpi_stopwatch_stop(ref_mpi, "compute metric");
if (REF_EMPTY != buffer_pos) {
RSS(ref_metric_buffer_at_complexity(metric, ref_grid, complexity),
"buffer at complexity");
}
if (hmin > 0.0 || hmax > 0.0) {
RSS(ref_metric_limit_h_at_complexity(metric, ref_grid, hmin, hmax,
complexity),
"limit at complexity");
}
RSS(ref_metric_complexity(metric, ref_grid, ¤t_complexity), "cmp");
if (ref_mpi_once(ref_mpi))
printf("actual complexity %e\n", current_complexity);
RSS(ref_metric_to_node(metric, ref_grid_node(ref_grid)), "set node");
ref_free(metric);
ref_free(weight);
ref_free(scalar);
if (ref_mpi_once(ref_mpi)) printf("writing metric %s\n", argv[8]);
RSS(ref_gather_metric(ref_grid, argv[8]), "export curve limit metric");
ref_mpi_stopwatch_stop(ref_mpi, "write metric");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (lp_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *scalar, *metric;
REF_INT p;
REF_DBL gradation, complexity, current_complexity, hmin, hmax;
REF_RECON_RECONSTRUCTION reconstruction = REF_RECON_L2PROJECTION;
REF_INT ldim;
REIS(1, lp_pos,
"required args: --lp grid.meshb scalar-mach.solb p gradation "
"complexity output-metric.solb");
if (8 > argc) {
printf(
"required args: --lp grid.meshb scalar-mach.solb p gradation "
"complexity output-metric.solb\n");
return REF_FAILURE;
}
hmin = -1.0;
hmax = -1.0;
if (REF_EMPTY != hmax_pos) {
if (hmax_pos >= argc - 1) {
printf("option missing value: --hmax max_edge_length\n");
return REF_FAILURE;
}
hmax = atof(argv[hmax_pos + 1]);
}
p = atoi(argv[4]);
gradation = atof(argv[5]);
complexity = atof(argv[6]);
if (REF_EMPTY != kexact_pos) {
reconstruction = REF_RECON_KEXACT;
}
if (ref_mpi_once(ref_mpi)) {
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
printf("reconstruction %d\n", (int)reconstruction);
printf("hmin %f hmax %f (negative is inactive)\n", hmin, hmax);
printf("buffer %d (negative is inactive)\n", buffer_pos);
}
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]),
"unable to load target grid in position 2");
ref_mpi_stopwatch_stop(ref_mpi, "read grid");
if (ref_mpi_once(ref_mpi)) printf("reading scalar %s\n", argv[3]);
RSS(ref_part_scalar(ref_grid, &ldim, &scalar, argv[3]),
"unable to load scalar in position 3");
REIS(1, ldim, "expected one scalar");
ref_mpi_stopwatch_stop(ref_mpi, "read scalar");
ref_malloc(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
RSS(ref_metric_lp(metric, ref_grid, scalar, NULL, reconstruction, p,
gradation, complexity),
"lp norm");
ref_mpi_stopwatch_stop(ref_mpi, "compute metric");
if (REF_EMPTY != buffer_pos) {
RSS(ref_metric_buffer_at_complexity(metric, ref_grid, complexity),
"buffer at complexity");
}
if (hmin > 0.0 || hmax > 0.0) {
RSS(ref_metric_limit_h_at_complexity(metric, ref_grid, hmin, hmax,
complexity),
"limit at complexity");
}
RSS(ref_metric_complexity(metric, ref_grid, ¤t_complexity), "cmp");
if (ref_mpi_once(ref_mpi))
printf("actual complexity %e\n", current_complexity);
RSS(ref_metric_to_node(metric, ref_grid_node(ref_grid)), "set node");
ref_free(metric);
ref_free(scalar);
if (ref_mpi_once(ref_mpi)) printf("writing metric %s\n", argv[7]);
RSS(ref_gather_metric(ref_grid, argv[7]), "export curve limit metric");
ref_mpi_stopwatch_stop(ref_mpi, "write metric");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (combine_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *scalar1, *scalar2, *metric1, *metric2, *metric;
REF_INT p;
REF_DBL gradation, complexity, current_complexity;
REF_RECON_RECONSTRUCTION reconstruction = REF_RECON_L2PROJECTION;
REF_INT ldim, i, node;
REF_DBL s;
REIS(1, combine_pos,
"required args: --combine grid.meshb scalar1.solb scalar2.solb p "
"gradation "
"complexity s output-metric.solb");
if (9 > argc) {
printf(
"required args: --combine grid.meshb scalar1.solb scalar2.solb p "
"gradation "
"complexity s output-metric.solb\n");
return REF_FAILURE;
}
p = atoi(argv[5]);
gradation = atof(argv[6]);
complexity = atof(argv[7]);
s = atof(argv[8]);
if (REF_EMPTY != kexact_pos) {
reconstruction = REF_RECON_KEXACT;
}
if (ref_mpi_once(ref_mpi)) {
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
printf("s %f\n", s);
printf("reconstruction %d\n", (int)reconstruction);
}
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]),
"unable to load target grid in position 2");
ref_mpi_stopwatch_stop(ref_mpi, "read grid");
if (ref_mpi_once(ref_mpi)) printf("reading scalar1 %s\n", argv[3]);
RSS(ref_part_scalar(ref_grid, &ldim, &scalar1, argv[3]),
"unable to load scalar1 in position 3");
REIS(1, ldim, "expected one scalar1");
ref_mpi_stopwatch_stop(ref_mpi, "read scalar1");
if (ref_mpi_once(ref_mpi)) printf("reading scalar2 %s\n", argv[4]);
RSS(ref_part_scalar(ref_grid, &ldim, &scalar2, argv[4]),
"unable to load scalar2 in position 4");
REIS(1, ldim, "expected one scalar2");
ref_mpi_stopwatch_stop(ref_mpi, "read scalar2");
ref_malloc(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
ref_malloc(metric1, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
ref_malloc(metric2, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
RSS(ref_metric_lp(metric1, ref_grid, scalar1, NULL, reconstruction, p,
gradation, complexity),
"lp norm");
ref_mpi_stopwatch_stop(ref_mpi, "multiscale metric1");
RSS(ref_metric_lp(metric2, ref_grid, scalar2, NULL, reconstruction, p,
gradation, complexity),
"lp norm");
ref_mpi_stopwatch_stop(ref_mpi, "multiscale metric2");
each_ref_node_valid_node(ref_grid_node(ref_grid), node) {
REF_DBL log_m1[6];
REF_DBL log_m2[6];
REF_DBL log_m[6];
RSS(ref_matrix_log_m(&(metric1[6 * node]), log_m1), "log");
RSS(ref_matrix_log_m(&(metric2[6 * node]), log_m2), "log");
for (i = 0; i < 6; i++) log_m[i] = (1.0 - s) * log_m1[i] + s * log_m2[i];
RSS(ref_matrix_exp_m(log_m, &(metric[6 * node])), "exp");
}
RSS(ref_metric_gradation_at_complexity(metric, ref_grid, gradation,
complexity),
"gradation at complexity");
ref_mpi_stopwatch_stop(ref_mpi, "metric gradation");
RSS(ref_metric_complexity(metric, ref_grid, ¤t_complexity), "cmp");
if (ref_mpi_once(ref_mpi))
printf("actual complexity %e\n", current_complexity);
RSS(ref_metric_to_node(metric, ref_grid_node(ref_grid)), "set node");
ref_free(metric);
ref_free(metric2);
ref_free(metric1);
ref_free(scalar2);
ref_free(scalar1);
if (ref_mpi_once(ref_mpi)) printf("writing metric %s\n", argv[9]);
RSS(ref_gather_metric(ref_grid, argv[9]), "export curve limit metric");
ref_mpi_stopwatch_stop(ref_mpi, "write metric");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (multigrad_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *grad, *metric;
REF_INT p;
REF_DBL gradation, complexity, current_complexity;
REF_INT ldim;
REIS(1, multigrad_pos,
"required args: --multigrad grid.meshb grad.solb p gradation "
"complexity output-metric.solb");
if (8 > argc) {
printf(
"required args: --multigrad grid.meshb grad.solb p gradation "
"complexity output-metric.solb");
return REF_FAILURE;
}
p = atoi(argv[4]);
gradation = atof(argv[5]);
complexity = atof(argv[6]);
if (ref_mpi_once(ref_mpi)) {
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
}
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]),
"unable to load target grid in position 2");
ref_mpi_stopwatch_stop(ref_mpi, "read grid");
if (ref_mpi_once(ref_mpi)) printf("reading scalar %s\n", argv[3]);
RSS(ref_part_scalar(ref_grid, &ldim, &grad, argv[3]),
"unable to load scalar in position 3");
REIS(3, ldim, "expected one gradent terms");
ref_mpi_stopwatch_stop(ref_mpi, "read grad");
ref_malloc(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
RSS(ref_metric_multigrad(metric, ref_grid, grad, p, gradation, complexity),
"lp norm");
ref_mpi_stopwatch_stop(ref_mpi, "compute metric");
RSS(ref_metric_complexity(metric, ref_grid, ¤t_complexity), "cmp");
if (ref_mpi_once(ref_mpi))
printf("actual complexity %e\n", current_complexity);
RSS(ref_metric_to_node(metric, ref_grid_node(ref_grid)), "set node");
ref_free(metric);
ref_free(grad);
if (ref_mpi_once(ref_mpi)) printf("writing metric %s\n", argv[7]);
RSS(ref_gather_metric(ref_grid, argv[7]), "export curve limit metric");
ref_mpi_stopwatch_stop(ref_mpi, "write metric");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (moving_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *displaced, *scalar, *metric;
REF_INT p;
REF_DBL gradation, complexity;
REF_RECON_RECONSTRUCTION reconstruction = REF_RECON_L2PROJECTION;
REF_INT ldim;
REIS(1, moving_pos,
"required args: --moving grid.meshb displaced.solb scalar.solb p "
"gradation "
"complexity output-metric.solb");
if (9 > argc) {
printf(
"required args: --moving grid.meshb displaced.solb scalar.solb p "
"gradation "
"complexity output-metric.solb\n");
return REF_FAILURE;
}
p = atoi(argv[5]);
gradation = atof(argv[6]);
complexity = atof(argv[7]);
if (REF_EMPTY != kexact_pos) {
reconstruction = REF_RECON_KEXACT;
}
if (ref_mpi_once(ref_mpi)) {
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
printf("reconstruction %d\n", (int)reconstruction);
}
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]),
"unable to load target grid in position 2");
ref_mpi_stopwatch_stop(ref_mpi, "read grid");
if (ref_mpi_once(ref_mpi)) printf("reading displaced %s\n", argv[3]);
RSS(ref_part_scalar(ref_grid, &ldim, &displaced, argv[3]),
"unable to load displaced in position 3");
REIS(3, ldim, "expected 3 [x,y,z]");
ref_mpi_stopwatch_stop(ref_mpi, "read scalar");
if (ref_mpi_once(ref_mpi)) printf("reading scalar %s\n", argv[4]);
RSS(ref_part_scalar(ref_grid, &ldim, &scalar, argv[4]),
"unable to load scalar in position 4");
REIS(1, ldim, "expected 1 scalar");
ref_mpi_stopwatch_stop(ref_mpi, "read scalar");
ref_malloc(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
RSS(ref_metric_moving_multiscale(metric, ref_grid, displaced, scalar,
reconstruction, p, gradation, complexity),
"moving multiscale norm");
RSS(ref_metric_to_node(metric, ref_grid_node(ref_grid)), "set node");
ref_free(metric);
ref_free(displaced);
ref_free(scalar);
if (ref_mpi_once(ref_mpi)) printf("writing metric %s\n", argv[8]);
RSS(ref_gather_metric(ref_grid, argv[8]), "export curve limit metric");
ref_mpi_stopwatch_stop(ref_mpi, "write metric");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (explore_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *field, *scalar, *metric, *output;
REF_INT p;
REF_DBL gradation, complexity;
REF_RECON_RECONSTRUCTION reconstruction = REF_RECON_L2PROJECTION;
REF_INT ldim, node, var;
REF_DBL h0, multiscale_system[12];
REIS(1, explore_pos,
"required args: --explore grid.meshb scalars.solb p gradation "
"complexity metric-h.tec");
if (8 > argc) {
printf(
"required args: --explore grid.meshb scalars.solb p gradation "
"complexity metric-h.tec\n");
return REF_FAILURE;
}
p = atoi(argv[4]);
gradation = atof(argv[5]);
complexity = atof(argv[6]);
if (REF_EMPTY != kexact_pos) {
reconstruction = REF_RECON_KEXACT;
}
if (ref_mpi_once(ref_mpi)) {
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
printf("reconstruction %d\n", (int)reconstruction);
printf("buffer %d (negative is inactive)\n", buffer_pos);
}
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
if (ref_mpi_para(ref_mpi)) {
if (ref_mpi_once(ref_mpi)) printf("part %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]), "part");
ref_mpi_stopwatch_stop(ref_mpi, "part mesh");
} else {
if (ref_mpi_once(ref_mpi)) printf("import %s\n", argv[2]);
RSS(ref_import_by_extension(&ref_grid, ref_mpi, argv[2]), "import");
ref_mpi_stopwatch_stop(ref_mpi, "import mesh");
}
if (ref_mpi_once(ref_mpi))
printf("reading field with scalars %s\n", argv[3]);
RSS(ref_part_scalar(ref_grid, &ldim, &field, argv[3]),
"unable to load scalar in position 3");
RAS(ldim > 0, "expected at least one scalar");
ref_mpi_stopwatch_stop(ref_mpi, "read scalar");
ref_malloc(output, ldim * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
ref_malloc(scalar, ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
ref_malloc(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
for (var = 0; var < ldim; var++) {
if (ref_mpi_once(ref_mpi)) printf("scalar %d of %d\n", var, ldim);
each_ref_node_valid_node(ref_grid_node(ref_grid), node) {
scalar[node] = field[node + ldim * var];
}
RSS(ref_metric_lp(metric, ref_grid, scalar, NULL, reconstruction, p,
gradation, complexity),
"lp norm");
ref_mpi_stopwatch_stop(ref_mpi, "compute metric");
if (REF_EMPTY != buffer_pos) {
RSS(ref_metric_buffer_at_complexity(metric, ref_grid, complexity),
"buffer at complexity");
}
each_ref_node_valid_node(ref_grid_node(ref_grid), node) {
RSS(ref_matrix_diag_m(&(metric[6 * node]), multiscale_system),
"decomp");
RSS(ref_matrix_ascending_eig(multiscale_system), "sort eig");
if (multiscale_system[0] < 0.0) RSS(REF_DIV_ZERO, "sqrt(-1)");
h0 = sqrt(multiscale_system[0]);
if (!ref_math_divisible(1.0, h0)) RSS(REF_DIV_ZERO, "inf h0");
output[node + var * ldim] = 1.0 / h0;
}
}
ref_free(metric);
ref_free(scalar);
if (ref_mpi_once(ref_mpi)) printf("writing sizes %s\n", argv[7]);
RSS(ref_gather_scalar_by_extension(ref_grid, ldim, output, NULL, argv[7]),
"export curve limit metric");
ref_mpi_stopwatch_stop(ref_mpi, "write metric");
ref_free(output);
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (fixed_point_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *scalar, *hess, *metric;
REF_INT p, n, timestep, timestep_increment, node, im;
REF_DBL gradation, complexity, current_complexity, hmin, hmax;
REF_RECON_RECONSTRUCTION reconstruction;
char solb[1024];
REF_INT ldim;
REIS(1, fixed_point_pos,
"required args: --fixed-point grid.meshb scalar-mach-root Ntimesteps "
"timestep_increment p gradation complexity output-metric.solb");
if (10 > argc) {
printf(
"required args: --fixed-point grid.meshb scalar-mach-root Ntimesteps "
"timestep_increment p gradation complexity output-metric.solb");
return REF_FAILURE;
}
hmin = -1.0;
hmax = -1.0;
if (REF_EMPTY != hmax_pos) {
if (hmax_pos >= argc - 1) {
printf("option missing value: --hmax max_edge_length\n");
return REF_FAILURE;
}
hmax = atof(argv[hmax_pos + 1]);
}
n = atoi(argv[4]);
timestep_increment = atoi(argv[5]);
p = atoi(argv[6]);
gradation = atof(argv[7]);
complexity = atof(argv[8]);
reconstruction = REF_RECON_KEXACT;
if (ref_mpi_once(ref_mpi)) {
printf("N=%d\n", n);
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
printf("reconstruction %d\n", (int)reconstruction);
printf("hmin %f hmax %f (negative is inactive)\n", hmin, hmax);
printf("buffer %d (negative is inactive)\n", buffer_pos);
}
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]),
"unable to load target grid in position 2");
ref_mpi_stopwatch_stop(ref_mpi, "read grid");
ref_malloc_init(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL,
0.0);
ref_malloc(hess, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
for (timestep = timestep_increment; timestep <= n;
timestep += timestep_increment) {
snprintf(solb, 1024, "%s%d.solb", argv[3], timestep);
if (ref_mpi_once(ref_mpi))
printf("reading and reconstructing hessian for %s\n", solb);
RSS(ref_part_scalar(ref_grid, &ldim, &scalar, solb),
"unable to load scalar in position 3");
REIS(1, ldim, "expected one scalar");
RSS(ref_recon_hessian(ref_grid, scalar, hess, reconstruction), "hess");
ref_free(scalar);
each_ref_node_valid_node(ref_grid_node(ref_grid), node) {
for (im = 0; im < 6; im++) {
metric[im + 6 * node] += hess[im + 6 * node];
}
}
ref_mpi_stopwatch_stop(ref_mpi, "timestep processed");
}
RSS(ref_metric_local_scale(metric, NULL, ref_grid, p),
"local lp norm scaling");
ref_mpi_stopwatch_stop(ref_mpi, "local scale metric");
RSS(ref_metric_gradation_at_complexity(metric, ref_grid, gradation,
complexity),
"gradation at complexity");
ref_mpi_stopwatch_stop(ref_mpi, "metric gradation and complexity");
if (REF_EMPTY != buffer_pos) {
RSS(ref_metric_buffer_at_complexity(metric, ref_grid, complexity),
"buffer at complexity");
ref_mpi_stopwatch_stop(ref_mpi, "buffer metric");
}
if (hmin > 0.0 || hmax > 0.0) {
RSS(ref_metric_limit_h_at_complexity(metric, ref_grid, hmin, hmax,
complexity),
"limit at complexity");
ref_mpi_stopwatch_stop(ref_mpi, "h-limit metric");
}
RSS(ref_metric_complexity(metric, ref_grid, ¤t_complexity), "cmp");
if (ref_mpi_once(ref_grid_mpi(ref_grid)))
printf("actual complexity %e\n", current_complexity);
RSS(ref_metric_to_node(metric, ref_grid_node(ref_grid)), "set node");
ref_free(hess);
ref_free(metric);
if (ref_mpi_once(ref_mpi)) printf("writing metric %s\n", argv[9]);
RSS(ref_gather_metric(ref_grid, argv[9]), "export curve limit metric");
ref_mpi_stopwatch_stop(ref_mpi, "write metric");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (opt_goal_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *scalar, *metric;
REF_INT p;
REF_DBL gradation, complexity;
REF_RECON_RECONSTRUCTION reconstruction = REF_RECON_L2PROJECTION;
REF_INT ldim;
REF_DBL current_complexity, hmin, hmax;
REIS(1, opt_goal_pos,
"required args: --opt-goal grid.meshb solution.solb p "
"gradation complexity output-metric.solb");
if (8 > argc) {
printf(
"required args: --opt-goal grid.meshb solution.solb p "
"gradation complexity output-metric.solb\n");
return REF_FAILURE;
}
hmin = -1.0;
hmax = -1.0;
if (REF_EMPTY != hmax_pos) {
if (hmax_pos >= argc - 1) {
printf("option missing value: --hmax max_edge_length\n");
return REF_FAILURE;
}
hmax = atof(argv[hmax_pos + 1]);
}
if (REF_EMPTY != kexact_pos) {
reconstruction = REF_RECON_KEXACT;
}
p = atoi(argv[4]);
gradation = atof(argv[5]);
complexity = atof(argv[6]);
if (ref_mpi_once(ref_mpi)) {
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
printf("reconstruction %d\n", (int)reconstruction);
printf("hmin %f hmax %f (negative is inactive)\n", hmin, hmax);
}
if (ref_mpi_once(ref_mpi)) printf("reading grid %s\n", argv[2]);
RSS(ref_part_by_extension(&ref_grid, ref_mpi, argv[2]),
"unable to load target grid in position 2");
if (ref_mpi_once(ref_mpi)) printf("reading solution %s\n", argv[3]);
RSS(ref_part_scalar(ref_grid, &ldim, &scalar, argv[3]),
"unable to load scalar in position 3");
REIS(20, ldim, "expected 20 (5*adj,5*xflux,5*yflux,5*zflux) scalar");
ref_malloc(metric, 6 * ref_node_max(ref_grid_node(ref_grid)), REF_DBL);
RSS(ref_metric_opt_goal(metric, ref_grid, 5, scalar, reconstruction, p,
gradation, complexity),
"opt goal");
if (hmin > 0.0 || hmax > 0.0) {
RSS(ref_metric_limit_h_at_complexity(metric, ref_grid, hmin, hmax,
complexity),
"limit at complexity");
}
RSS(ref_metric_complexity(metric, ref_grid, ¤t_complexity), "cmp");
if (ref_mpi_once(ref_mpi))
printf("actual complexity %e\n", current_complexity);
RSS(ref_metric_to_node(metric, ref_grid_node(ref_grid)), "set node");
ref_free(metric);
ref_free(scalar);
if (ref_mpi_once(ref_mpi)) printf("writing metric %s\n", argv[7]);
RSS(ref_gather_metric(ref_grid, argv[7]), "export opt goal metric");
RSS(ref_grid_free(ref_grid), "free");
RSS(ref_mpi_free(ref_mpi), "free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
if (no_goal_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_NODE ref_node;
REF_DBL *scalar, *metric;
REF_INT p;
REF_DBL gradation, complexity;
REF_RECON_RECONSTRUCTION reconstruction = REF_RECON_L2PROJECTION;
REF_INT ldim;
REF_DBL current_complexity, hmin, hmax;
REF_INT i, node;
REIS(1, no_goal_pos,
"required args: --no-goal grid.meshb solution.solb complexity p "
"gradation output-metric.solb");
if (8 > argc) {
printf(
"required args: --no-goal grid.meshb solution.solb complexity p "
"gradation output-metric.solb\n");
return REF_FAILURE;
}
hmin = -1.0;
hmax = -1.0;
if (REF_EMPTY != hmax_pos) {
if (hmax_pos >= argc - 1) {
printf("option missing value: --hmax max_edge_length\n");
return REF_FAILURE;
}
hmax = atof(argv[hmax_pos + 1]);
}
if (REF_EMPTY != kexact_pos) {
reconstruction = REF_RECON_KEXACT;
}
p = atoi(argv[4]);
gradation = atof(argv[5]);
complexity = atof(argv[6]);
if (ref_mpi_once(ref_mpi)) {
printf("Lp=%d\n", p);
printf("gradation %f\n", gradation);
printf("complexity %f\n", complexity);
printf("reconstruction %d\n", (int)reconstruction);
printf("hmin %f hmax %f (negative is inactive)\n", hmin, hmax);