-
Notifications
You must be signed in to change notification settings - Fork 3
/
GROW_JAN_2017.pl
6437 lines (5354 loc) · 183 KB
/
GROW_JAN_2017.pl
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
#! /usr/bin/perl -w
use warnings;
use strict;
use Data::Dumper;
use POSIX;
# GROWTH BY OPTIMIZATION OF WORK: A tool to predict fracture growth
# Dec 2016
# By: Jess McBeck, Michele Cooke, Betsy Madden
## GENERAL USAGE #########################################################################################
# GROW.pl <filename.in> <increment angle> <start angle> <end angle> <forecast parameters>
# <filename.in> fric2d input file, must exist in the current directory, and end in ".in"
# <increment angle> the number of degrees between each potential crack
# <start angle> the angle at which to start searching efficient orietations
# <end angle> the angle at which to end searching (last crack orientation test < end angle)
# <forecast parameters> i.e. 'min-0.80', 'max-0.95'
# min/max designating min or max of envelope to construct,
# and percentage (80% = 0.80) to determine extent of envelope
# DESCRIPTION OF FILES GENERATED ##########################################################################
# Input filename : foo.in
# foo.eff : fric2d input file of most efficient geometry found so far
# foo.raw : summary of work calculated for various orientations,
# nearly identical to standard output
# foo_cont<num>.in : If any faults propagate for more than 5 iterations, this program
# restarts the process with the same input parameters, except the new input
# file, which contains the contents of the most efficient geometry found in the
# last iteration of crack growth. This automatic restart frees memory.
# standard output: fric2d output statements, work calculated for each scenario,
# scenario number of most efficient geometry for each propagation
# if any scenario did not produce slip on the pupative element just created
# Testing filenames: i.e. files generated to test all possible orientations
# foo_prop_fault_end_angle.in : prop = propagation number, fault = fault name,
# end = end growing from (1 or 2),
# angle = clockwise orientation of potential element
# foo_tune_prop_fault_end_angle.in : same values as file described above, but "tune"
# indicates that the faults are being tuned
# foo.prev_seq : the input file of the geometry before a sequential growth of the faults
# this input file is preserved so the linear search of the most efficient orientations
# can use this input file to generate correct geometries for new geometries to test
# *Crack INPUT LINE USAGE #################################################################################
# *Crack properties represent intact rock values.
# *Fault properties represent fault values.
# In FRIC2D input file:
# Line that specifies the new fault characteristics of the potential element
# -Must contain the tag *Crack at the beginning of the input file line
# -Be placed after the fault header that contains the fault name, but before the list of individual fault segments
# For example:
# *----------------------
# *Fault Conditions
# *----------------------
# *fault name grow_tails? from_end1? from_end2?
# *num xbeg ybeg xend yend stiffS stiffN ten-str init-coh slid-coh stat-fric dy-fric crit-slip dist
# *---- ---- ---- ---- ---- ------ ------ --- --- ----- ------- ------ ---------
# fault left no no yes
# *tag stiffS stiffN ten-str shear-str coh int-fric dy-fric crit-dist
# *Crack 1.00E+10 1.00E+10 100 0.00008 10 1.35 1.35 0
# 41 0 10 20.670 10 1.00E+10 1.00E+10 100.0 0.0 0 0.6 0.6 0
#
# After one element is added to this fault the input file reads:
# *----------------------
# *Fault Conditions
# *----------------------
# *fault name grow_tails? from_end1? from_end2?
# *num xbeg ybeg xend yend stiffS stiffN ten-str init-coh slid-coh stat-fric dy-fric crit-slip dist
# *---- ---- ---- ---- ---- ------ ------ --- --- ----- ------- ------ ---------
# fault left no no yes
# *tag stiffS stiffN ten-str shear-str coh int-fric dy-fric crit-dist
# *Crack 1.00E+10 1.00E+10 100 0.00008 10 1.35 1.35 0
# 41 0 10 20.670 10 1.00E+10 1.00E+10 100.0 0.0 0 0.6 0.6 0
# 1 20.670 10 20.31351470 10.35648530 1.00E+10 1.00E+10 100 0.00008 10 1.35 1.35 0
#
# WHEN GROWING FROM A POINT ##########################################################################################################
# In FRIC2D input file:
# The lines that specifies the point from which a new flaw will grow:
# -Muat be placed after the Fault Conditions header
# -Must contain *Flaw-Intact at the beginning of the line, then name, x coordinate of point, y coordinate of point, element length
# and remaining characteristics of intact rock through which crack propagates
# - Must be preceded with *Flaw-Fault line if the user wants to change properties modelling intact rock to fault characteristics
# For example:
# *----------------------
# *Fault Conditions
# *----------------------
# *Tag fault xcoor ycoor length grow_both? stiffS stiffN cohes friction - s friction -d L
# *Flaw-Fault 1e10 1e10 0 0.62 0.58 0.00025
# *Flaw-Intact backthrust 0.055424 0.01173379 0.002 yes 1e10 1e10 100 0.96 0.72 0.00025
# WHEN GROWING IN MODEL WHERE TOPOGRAPHY AND GRAVITY IS IMPORTANT
# GROW.pl <input.in> <inc angle> <start angle> <end angle> <topo.topo> <forecast parameters>
# <input.in> = fric2d input filename
# <inc angle> = angle increment (resolution of search for orientations)
# <start angle> the angle at which to start searching efficient orietations
# <end angle> the angle at which to end searching
# <topo.topo> = fric2d topography filename
# <forecast parameters> i.e. 'min-0.80', 'max-0.95'
# min/max designating min or max of envelope to construct,
# and percentage (0.80) to determine extent of envelope
# FUNCTION DECLARATIONS
########################################################################################################################################
# propagate more than one fault with sequential search of minimum work
sub grow;
# return range of angles to test
sub get_angles;
# returns a hash table listing hashes of scenarios that specify
# the fault name and the angle for which to calculate work
sub get_scenarios;
# reads first input file to determine if
# using stress or displacement conditions, returns true
# if minimizing work (false is maximizing is more efficient config)
sub get_efficient_criteria;
# get mode that we are running fric2d
sub get_run_mode;
# check that input values are as we expect
sub check_input;
# format and write output
sub write_output;
sub write_index;
sub format_std_output;
sub print_work_summary;
# copy file to another with the shell
sub transfer_file;
# get name and end of the fault that is growing
sub get_fault_names;
sub check_final_intersections;
# get the coordinates and length of the
# crack that will propagate from this flaw
sub get_flaw_info;
# make the various input/output filenames
sub make_names;
# find max and min in list
sub max_list;
sub min_list;
# EXECUTING MAIN FUNCTION
####################################################
grow;
# FUNCTION DEFINITIONS
#####################################################
# Main function
sub grow
{
my ($input_filename, $inc_angle, $start_angle, $end_angle, $topo_filename, $forecast) = @ARGV[0..6];
# check that input file ends in .in, and angle values are appropriate
check_input($input_filename, $inc_angle, $start_angle, $end_angle);
# not using a work criterion for now
my $input_criterion = 0;
# if we are passing work from previous run
my $prev_run_work = 0;
# if last input parameter is a number (a work value)
# then set intial work to value found in last GROW call
if ($ARGV[-1] =~ /^\d+\.\d+/)
{
$prev_run_work = $ARGV[-1];
}
# determine what mode we are running GROW
# DB (debugging without growing from pt),
# "sand debug" (growing from pt and debugging)
# "sand" (growing from a point),
# "fric" just plain old fric2d
my $run_mode = get_run_mode($input_filename, $ARGV[-2], $ARGV[-1]);
# if choosing smallest angle = 'min', if choosing largest angle = 'max'
# and # multiplied by max delwext/A
if ($topo_filename && !($topo_filename =~ /.topo/) && ($topo_filename =~ /min/ || $topo_filename =~ /max/))
{
$forecast = $topo_filename;
}
if ($forecast && ($forecast =~ /min/ || $forecast =~ /max/))
{
$forecast =~ s/-/ /g;
# ensure forecast parameters correct
my ($limit, $p) = split(/\s+/, $forecast);
if ($p > 1 || $p <= 0)
{
die "ERROR: FORECAST PERCENTAGE P MUST BE BETWEEN 0 AND 1 \n";
}
}
# if forecast parameter read in, but does not contain min or max key words
# set to zero, for later if statements
if ($forecast && !($forecast =~ /min/ || $forecast =~ /max/))
{
$forecast = '';
}
# string to accumulate with the work data
my $raw_output = "Executing GROW version Dec 2016\n\n"
."Reading FRIC2D input file: $input_filename \n"
."\tIncrement angle: $inc_angle \n"
."\tStarting angle: $start_angle \n"
."\tEnding angle: $end_angle \n";
if ($topo_filename && ($topo_filename =~ /.topo/))
{
$raw_output = $raw_output."\tTopo file: $topo_filename \n";
}
if ($forecast && ($forecast =~ /min/ || $forecast =~ /max/))
{
$raw_output = $raw_output."\tForecast parameters: $forecast \n";
}
print "\n$raw_output";
# make the various file names
my $root = substr($input_filename, 0, -3);
my ($prev_filename, $efficient_filename, $testing_filename,
$fric_output_filename, $output_filename, $out_raw_filename, $restart_filename) =
make_names($root);
# copy the input file to a new file
transfer_file($input_filename, $prev_filename);
# set the initial most efficient configuration to the input file
transfer_file($input_filename, $efficient_filename);
# get a list of all the faults and flaws that are growing:
# here, the end value of flaws doesn't matter
my @fault_names = get_fault_names($prev_filename);
my $fault = "";
# only get the name of a fault to calculate work criterion
# in function get_initial_work
if ($input_criterion != 0)
{
$fault = substr($fault_names[0], 0, -2);
}
# get the initial work of the system,
# use a random fault to get the work criterion
my ($prev_work, $crit_work, $new_work_out, $new_raw_out) =
get_initial_work($input_filename, $fric_output_filename, $fault,
$run_mode, $prev_run_work,
$input_criterion,
$topo_filename);
# keep list of all most efficient work found so far
my @works = ($prev_work);
my @works_unnorm = ($prev_work);
# update the print statements
$raw_output = $raw_output.$new_raw_out;
# returns true if the most efficient scenario minimizes work
my $is_minimizing = get_efficient_criteria($prev_filename);
if ($is_minimizing)
{
print "\tUsing displacements: minimizing work.\n";
}
else
{
print "\tUsing stress: maximizing work.\n";
}
# if no faults are propagating and not running the sandbox version
if (scalar(@fault_names) == 0 && !($run_mode =~ /sand/))
{
die "NO FAULTS PROPAGATING: check flags in input file.\n";
}
# number of iterations of propagation
my $prop_num = 0;
# if running a sand box model, if so
# find the geometry that minimizes work for the first iteration
# after this iteration, let GROW function as usual
if ($run_mode =~ /sand/)
{
# get flaw names, only if not followed by fault propertie
my @flaw_names = get_flaw_names($prev_filename);
# if there are flaws propagating in the input file
if (scalar(@flaw_names) != 0)
{
$prop_num++;
# get range of angles: test full circle to test both up and down orientations
my @flaw_angles = get_angles(0, 359, $inc_angle);
# get a hash table of scenarios to test for the first
# iteration
my ($flaw_scen_ref, $flaw_scen_num) = get_sequence(\@flaw_names, \@flaw_angles);
my %flaw_scenarios = %$flaw_scen_ref;
# execute sequence with $is_sand = 1
my ($min_work_unnorm, $min_work, $new_raw_out2) =
execute_sequence ($run_mode, $forecast, 1, $prev_work, $inc_angle, $flaw_scen_ref, $prop_num, $is_minimizing,
$prev_filename, $efficient_filename, $raw_output,
$output_filename, $out_raw_filename, $topo_filename);
# update the print statements
$raw_output = $new_raw_out2;
# add to list of work values to print cumulative summary
if ($min_work != -1)
{
push(@works, $min_work);
push(@works_unnorm, $min_work_unnorm);
}
# if no elements slip, use last minimum work (probably better to use min work found in this iteration)
else
{
push(@works, $prev_work);
push(@works_unnorm, $prev_work);
}
$prev_work = $works_unnorm[-1];
# continue to propagate unless the Coulomb criteria was not satisfied
# if the criteria was not satisfied, $min_work = -1,
# if no more fauls are growing, $min_work = 0
my $continue_grow = test_prop_many($prev_work, $min_work,
0, # critical work value not used
1); # faults will always be growing at this point
# if we should not propagate any more
# exit execution
if (!$continue_grow)
{
print "NO FAILURE ON FLAWS AT SPECIFIED POINT(S). \n";
}
}
else
{
print "WARNING: Running sandbox, but no Flaws found in input file. \n";
}
}
# get range of angles to search for larger search
my @angle_range = get_angles($start_angle, $end_angle, $inc_angle);
# get a list of all the faults that are growing # FORMATTED: fault_name end_growing
# at this point, if using sandbox version all *Flaws are written as full fric2d faults now
# now this will include *Flaws that are growing
@fault_names = get_fault_names($efficient_filename);
# test if any faults are propagating
if (scalar(@fault_names) == 0)
{
die "NO FAULTS PROPAGATING: check flags in $efficient_filename \n";
}
# if ran sandbox model and faults are still propagating
# replace fault properties for single element listed
# with *Flaw-Fault properties
if ($run_mode =~ /sand/)
{
reset_flaw_all($efficient_filename, \@fault_names);
}
# get hash of scenarios to test for each iteration of crack growth
# assumes that all the fault names are fully listed faults in fric2d input file
# Key: fault name, values: list of angles to check
my $sequence_ref = get_sequence(\@fault_names, \@angle_range);
my %sequence = %$sequence_ref;
# start growing the fault
# continue_propagate = 0 when fault intersects
# or none of newly added elements are slipping
my $continue_propagate = 1;
while ($continue_propagate)
{
# increment the number that indicates the
# step of crack growth
$prop_num++;
# reset the last input geometry to the most efficient
# geometry found after adding the last sequential growth sequence
transfer_file($efficient_filename, $prev_filename);
# grow the faults sequentially by minimizing work for individual fault
# here, GROW always thinks we are not propagating from point
my ($min_work_unnorm, $min_work, $new_raw_out2) =
execute_sequence ($run_mode, $forecast, 0, $prev_work, $inc_angle, $sequence_ref, $prop_num, $is_minimizing,
$prev_filename, $efficient_filename, $raw_output,
$output_filename, $out_raw_filename, $topo_filename);
# update the print statements
$raw_output = $new_raw_out2;
# add to list of work values to print cumulative summary
# @works now contains delWext/A values
# @works_unnorm, contains Wext values
push(@works, $min_work);
push(@works_unnorm, $min_work_unnorm);
# reset previous work value to normalize work in next iteration
$prev_work = $works_unnorm[-1];
# test if the end points of any faults intersect,
# if true, then set growing flag to "no" in efficient input file
check_final_intersections($efficient_filename);
# get the new list of scenarios to test, in case
# any faults are intersecting boundary
# get the name of faults still growing, after checking the intersections
@fault_names = get_fault_names($efficient_filename);
# update the sequence if any faults are still growing
$sequence_ref = get_sequence(\@fault_names, \@angle_range);
# check if no more faults are growing
my $if_sequence = 1;
if (scalar(@fault_names) == 0)
{
$if_sequence = 0;
}
# continue to propagate unless the Coulomb criteria was not satisfied
# if the criteria was not satisfied, $min_work = -1, $min_scenario = -1
# if no more fauls are growing, $min_work = 0
$crit_work = 0;
$continue_propagate = test_prop_many($prev_work, $min_work,
$crit_work,
$if_sequence);
# print most efficient work values calculated so far
my $out_stat = "\nCUMULATIVE SUMMARY\n".sprintf("%-10s %-20s %-20s\n", "PROP", "Wext(J)", "delWext/delA (J/m^2)");
for my $i (0..$#works)
{
my $label = $i;
if ($i == 0)
{
$label = "Initial";
# normalized value of initial work not reported
$works[0] = 'N/A';
}
# if most efficient work not found because no failure
elsif ($works[$i] == -1)
{
$works[$i] = $works[$i-1];;
}
$out_stat = $out_stat.sprintf("%-10s %-20s %-20s\n", $label, $works_unnorm[$i], $works[$i]);
}
$out_stat = $out_stat."\n";
print "$out_stat";
$raw_output = $raw_output.$out_stat;
write_output($out_raw_filename, $raw_output);
# if we will continue to grow faults
if ($continue_propagate)
{
%sequence = %$sequence_ref;
# reset the previous work of the system
# to the minimum work found at this iteration
$prev_work = $works_unnorm[-1];
# restart the program to clear memory if propagated 5 times
if ($prop_num == 5)
{
#die; ###### for debuggin
# copy contents of .eff to file named "next_filename"
transfer_file($efficient_filename, $restart_filename);
my $out = "\nRESTARTING PROCESS TO FREE MEMORY\n\tRECORDING: $efficient_filename \n\tAND CONTINUING WITH: $restart_filename \n";
print $out;
$raw_output = $raw_output.$out;
write_output($out_raw_filename, $raw_output);
# set the new input file to the most efficient file found during the last iteration
$ARGV[0] = $restart_filename;
# remember unnormalized work calculated for this file, so we don't recalculate in next iteration
push(@ARGV, $min_work_unnorm);
my $formatted = join("\t", @ARGV);
print "PASSING INPUT ARGUMENTS\n\t$formatted\n";
exec($^X, $0, @ARGV);
}
}
else
{
print "EFFICIENT FILE: $efficient_filename\n";
}
}
}
# FUNCTIONS TO MODIFY FRI2D INPUT FILES
# set flags in input file to stop growing of a fault
sub stop_grow;
# generate FRIC2D input file with 1 new element
sub make_input_file;
# make the input file that describes this scenario, with multiple faults
sub make_input_file_scenario;
# FUNCTIONS TO CALCULATE WORK
# get the work of the system
sub calc_work;
# run FRIC2D
sub run_FRIC2D;
# run the sandbox version of FRIC2D
sub run_sandbox;
# calculate external work
sub get_work;
# removes from hash table any scenario that does not contain slipping pupative element
sub remove_not_slipping_ineff;
# function that returns work value normalized by length of
# propagating fault in the input file
sub normalize_work;
# get max and min of list of numbers
sub max;
sub min;
# counter number of possible strucutres an element tip bay intersect with
# 2*number of faults + number of boundary segments
sub get_intersect_structs;
# grow the faults sequentially by minimizing work for individual faults
# called:
# my ($min_work_unnorm, $min_work, $new_raw_out2) =
# execute_sequence ($run_mode, $forcast, $is_sand, $prev_work, $angle_inc, $sequence_ref, $prop_num, $is_minimizing,
# $prev_filename, $efficient_filename, $raw_output,
# $output_filename, $out_raw_filename, $topo_filename);
# input: what program to execute (fric, sand, debug),
# bool = true if growing from point, false otherwise
# angle increment of first general search
# reference to sequence hash table fault name => list of angles to search
# number of current iteration of crack growth
# if we are minimizing work (true), false if otherwise
# name of previous file, and the most efficient file found so far (?)
# current string that represents the raw output
# name of output filename, raw_output filename and topography filename
# topo filename may not exist
# output: minimum Wext, minimum delWext/A
sub execute_sequence
{
my ($run_mode, $forecast, $is_sand, $prev_prop_work, $angle_inc, $sequence_ref, $prop_num,
$is_min,
$prev_filename, $efficient_filename,
$raw_output,
$output_filename, $out_raw_filename,
$topo_filename) = @_;
my %sequence = %$sequence_ref;
my $root = substr($efficient_filename, 0, -4);
# hash table to remember efficient angle found for this fault
my %eff_fault_angle;
my $print_screen_summary;
my $curr_eff = 1e20;
my $curr_work = 1e20;
# final work of the system to return after testing all orientations
my $final_work = 0;
# final unnormalized work
my $final_work_unnorm = 0;
# work of previous propagation of growth
#my $prev_prop_work = $prev_work;
# preserve the contents of the previous input file before sequential growth
# to use in the linear growth later
my $seq_filename;
# remember the contents of this file for the tuning step
# to normalize work by the fault length added within the entire propagation sequence
my $prev_prop_filename = $prev_filename."_seq";
transfer_file($prev_filename, $prev_prop_filename);
# for each fault listed in sequence hash table
# these keys MUST be sorted or else the incorrect scenarios will be removed as duplicated
for my $fault (sort keys %sequence)
{
my $out = "\nPROPAGATION: $prop_num \nTESTING ANGLES FOR FAULT AND END: $fault \n\n";
print $out;
$raw_output = $raw_output.$out;
write_output($out_raw_filename, $raw_output);
my $formatted_fault = $fault;
$formatted_fault =~ s/\s/_/;
# get the angles to test for this fault
my @angles = @{$sequence{$fault}};
# hash table to store work calculated for this fault
# angle => normalized work pairs
my %this_fault = ();
# angle => unnormalized work
my %this_fault_unnorm = ();
my %this_file = ();
# for each angle listed in this key
foreach (@angles)
{
my $angle = $_;
# make the testing filename (fric2d input and output files)
my $testing_filename = $root."_".$prop_num."_".$formatted_fault."_".$angle.".in";
my $fric_output_filename = $root."_".$prop_num."_".$formatted_fault."_".$angle.".out";
# create the hash table that describes this scenario
my $pair_ref = {$fault => $angle} ;
# make the input file that represents this scenario at $testing_filename
make_input_file_scenario($prev_filename, $testing_filename,
$pair_ref, $is_sand);
# get number of structures that could be possibly intersecting
my $structure_num = get_intersect_structs($testing_filename);
my $fault_intersect = correct_intersections($testing_filename, $pair_ref, 0, $structure_num);
my $result;
if ($fault_intersect)
{
# print statement
$result = "No work calculated => A fault intersects itself, or could not correct all intersections";
}
# if a fault does not intersect itself
else
{
# calculate the work
$curr_work = calc_work($run_mode, $testing_filename,
$fric_output_filename, $topo_filename);
if ($curr_work eq "nan")
{
die "FRIC2D ERROR: Work calculated as nan for file: $fric_output_filename \n";
}
if (!$curr_work)
{
die "PASSING ERROR: Work was not passed, or not calculated. \n";
}
# normalize work by total length of propagating fault ## now normalize by newly added fracture area
# record not normalized work
my $curr_work_unnorm = $curr_work;
# normalize work
#print "normalizing in main loop \n";
$curr_work = normalize_work($prev_prop_work, $curr_work, $testing_filename, $prev_prop_filename);
# record work in hash table for this fault
$this_fault{$angle} = $curr_work;
# record index and filename in hash table
$this_file{$angle} = $fric_output_filename;
$this_fault_unnorm{$angle} = $curr_work_unnorm;
# update minimum/maximum work, now using max delWext/A
if ($curr_work > 0 && ($is_min && $curr_work < $curr_eff || (!$is_min && $curr_work > $curr_eff)))
{
$curr_eff = $curr_work;
}
# print statement
$result = "$curr_work_unnorm\t$curr_work";
}
# print statements
my $print_screen_summary = format_std_out($fric_output_filename,
$prop_num, $result, $fault, $angle);
$raw_output = $raw_output.$print_screen_summary;
write_output($out_raw_filename, $raw_output);
} # end loop of testing all angles for one fault
# if hash table is empty, then one fault intersects at all orientations
# when faults intersection work = 0
my $inter_self = 0;
if (!%this_fault)
{
$inter_self = 1;
}
my %all_faults_unnorm = %this_fault_unnorm;
my %all_faults = %this_fault;
my %forecast_works = %this_fault; # use full distribution of wext vs angles to calculate forecast, do not remove non slipping elements
# remove scenarios from the hash table if the element(s) that were just added
# are not slipping if we are not using debug mode (which will not produce
# .out files
# save all the work calculations for the summary output
if (!($run_mode =~ /debug/) && !$inter_self)
{
%this_fault = remove_not_slipping_ineff($is_min, \%this_file, \%this_fault);
}
#my %all_faults = %this_fault;
my ($eff_angle, $eff_work) = ();
my $eff_work_unnorm = 0;
# if hash is empty after removing non-slipping scenarios
# then work = -1
# then signal that all elements not slipping, but continue to test the other faults
if (!%this_fault)
{
# change the flags in the previous input file so correct fault is not growing
# and so the next iteration uses this input file
stop_grow($prev_filename, $fault);
# stop growth in efficient filename as well, so that
# new propagation knows that fault stopped in case not slipping
# fault is last to grow fault
stop_grow($efficient_filename, $fault);
# stop growth in previous propagation file, because this used in tuning
stop_grow($prev_prop_filename, $fault);
# notify user/raw output that fault not growing anymore
my $out = "\nNEW ELEMENTS ADDED NOT SLIPPING/EFFICIENT\n\tFAULT AND END: $fault \n\tSTOPPING GROWTH\n";
# signal to not copy files
$eff_angle = -2;
# if all orientations tested intersect that fault
if ($inter_self)
{
$out = "\nALL NEW ELEMENTS ADDED INTERSECT SAME FAULT\n\tFAULT AND END: $fault \n\tSTOPPING GROWTH\n";
$eff_angle = -3;
}
print $out;
$raw_output = $raw_output.$out;
write_output($out_raw_filename, $raw_output);
}
# at least one added element is slipping, find max delWext/A value
else
{
my %valid_works = %this_fault;
# remove the orienations that produce negative work
foreach my $angle (keys %this_fault_unnorm)
{
my $curr_w = $this_fault_unnorm{$angle};
if ($curr_w < 0)
{
delete $valid_works{$angle};
}
}
# if forecasting
if ($forecast)
{
($eff_angle, $eff_work, $eff_work_unnorm) = get_wext_forecast(\%forecast_works, $forecast, $is_min,
$root, $prop_num, $formatted_fault,
$fault, $prev_filename, $topo_filename,
$raw_output, $out_raw_filename,
$prev_prop_work, $prev_prop_filename, $is_sand, $run_mode);
#print 'adding interp work to all work at this increment \n';
$all_faults_unnorm{$eff_angle} = $eff_work_unnorm;
$all_faults{$eff_angle} = $eff_work;
}
else
{
# if we apply displacement boundary conditions,
# most efficient configuration minimizes work (stress/tractions)
if ($is_min)
{
# find the minimum work and remember the index at which this happens
($eff_angle, $eff_work) = get_minima_scenario(\%valid_works);
}
else
{
# if the most efficient configuration maximizes work (displacements)
# i.e. allows the most slip/displacements
($eff_angle, $eff_work) = get_maxima_scenario(\%valid_works);
}
$eff_work_unnorm = $this_fault_unnorm{$eff_angle};
}
}
# if we calculated the work for a scenario
# there was at least one good/not intersecting geometry (angle != -1)
# and one of the newly added elements is slipping (angle != -2)
if ($eff_angle > -1)
{
$seq_filename = $root."_".$prop_num."_".$formatted_fault."_".$eff_angle.".in";
# copy the appropriate files to the scenario that minimizes work
transfer_file($seq_filename, $efficient_filename);
# reset the last input geometry to the most efficient
# geometry found after adding the last sequential growth sequence
transfer_file($efficient_filename, $prev_filename);
# remember fault name and minimum angle
$eff_fault_angle{$fault} = $eff_angle;
$final_work = $eff_work;
$final_work_unnorm = $eff_work_unnorm; #$this_fault_unnorm{$eff_angle};
# used to normalize by work calculated after adding last element
# now normalize by work of previous propagation
#$prev_work = $final_work_unnorm;
}
# if none of the elements added to this fault is slipping
elsif ($eff_angle == -2)
{
# print statements
$eff_angle = "No angle found because no added elements slipped or efficient";
}
elsif ($eff_angle == -3)
{
$eff_angle = "No angle found because all added elements intersect same fault";
}
# print out all angle, work calculated for this fault
$raw_output = $raw_output.print_work_summary(1, "PROPAGATION: $prop_num \nSUMMARY FOR FAULT AND END: $fault\n\tEFFICIENT ANGLE: $eff_angle\n",
\%all_faults_unnorm, \%all_faults);
write_output($out_raw_filename, $raw_output);
} # close loop of each fault,
# at this point work calculated for each angle for each fault
# if final work not zero, then value has been found
if ($final_work != 0)
{
$raw_output = $raw_output.print_work_summary(0, "BEFORE TUNING PROPAGATION: $prop_num \nMOST EFFICIENT delWext/delA (J/m^2): $final_work\nGEOMETRY IN FILE: $seq_filename \n", \%eff_fault_angle);
write_output($out_raw_filename, $raw_output);
# RUN TUNING ALGORITHM, only if not forecasting
if (!$forecast)
{
($final_work_unnorm, $final_work, my $raw_output_2) =
tune_angles($final_work_unnorm, $final_work, $prev_prop_work,
\%eff_fault_angle, $seq_filename, $angle_inc/2,
$run_mode, $forecast, $is_sand, $prop_num, $is_min,
$prev_prop_filename, $efficient_filename,
$raw_output,$output_filename, $out_raw_filename, $topo_filename);
$raw_output = $raw_output_2;
}
}
# if no more faults are growing (none of the added elements are slipping)
# so final, most efficient work not found for all faults
else
{
my $out = "\nPROPAGATION: $prop_num \nNO MORE FAULTS ARE GROWING, SO DID NOT CHECK TUNED ANGLES\n";
print $out;
$raw_output = $raw_output.$out;
write_output($out_raw_filename, $raw_output);
# signal that no more faults are growing
$final_work = -1;
}
# return minimum work for all the scenarios tested
return ($final_work_unnorm, $final_work, $raw_output);
}
# determine if two hash tables are equal
sub is_hash_equal;
# get the angles to test in the tuning sequence
sub get_tuned_sequence;
# called: ;
# ($final_work_unnorm, $final_work, my $raw_output_2) =
# tune_angles($final_work_unnorm, $final_work, $prev_work, \%eff_fault_angle, $seq_filename, $angle_inc/2,
# $run_mode, $is_sand, $prop_num, $is_min,
# $prev_filename_sequence, $efficient_filename,
# $raw_output,$output_filename, $out_raw_filename, $topo_filename);
# input: most efficient work calculated in last iteration
# reference to hash of most efficient geometry found so dar
# filename of most efficient input file
# angle increment to search away from most efficient orientation
# other variables: see above function for description
# output: most efficient work found in this iteration or last iteration
sub tune_angles
{
# for each fault listed in the sequence hash table
# find the minimum angle of the list of angles given
# change current .eff to .prev, set new .prev to corresponding input file
# remember this minimum angle and fault in hash table
my ($prev_work_unnorm, $prev_work, $prev_prop_work_unnorm, $fault_angle_ref, $seq_filename, $angle_inc,
$run_mode, $forecast, $is_sand, $prop_num, $is_min,
$prev_prop_filename, $efficient_filename, $raw_output,
$output_filename, $out_raw_filename,$topo_filename) = @_;
# do not forecast/interpolate between values of wext
$forecast = 0;
my $root = substr($efficient_filename, 0, -4)."_tune";
my $print_screen_summary;
my $curr_eff = 1e20;
my $curr_work = 1e20;
# most efficient work found in first and tuning sequence
# set to the previous work in case most efficient work not found in tuning sequence
my $final_work = $prev_work;
my $final_work_unnorm = $prev_work_unnorm;
# get the sequence of angles to test for all faults
my %testing_sequences = get_tuned_sequence($fault_angle_ref, $angle_inc);
# if no testing sequences found, because none of the faults are now growing
if (!%testing_sequences)
{
my $out = "\nTUNING PROPAGATION $prop_num \n\tNO FAULTS GROWING \n";
$raw_output = $raw_output.$out;
write_output($out_raw_filename, $raw_output);
return ($final_work, $raw_output);
}
# most efficient geometry found thus far
my %efficient_geometry = %$fault_angle_ref;
# for each fault listed in sequence hash table
# these keys MUST be sorted or else the incorrect scenarios will be removed as duplicated
for my $fault (sort keys %testing_sequences)
{
my $formatted_fault = $fault;
$formatted_fault =~ s/\s/_/;
# get the angles to test for this fault
my @angles = @{$testing_sequences{$fault}};
# get the angles to fix for the other faults: whatever the most efficient hash table holds
my %testing_geometry = %efficient_geometry;
# remove the fault from the hash table that records the geometry that we are testing
delete $testing_geometry{$fault};
# hash table to store work calculated for this fault
# angle => work pairs
my %this_fault = ();
my %this_fault_unnorm = ();
my %this_file = ();
# for each angle listed in this key, which includes opt-inc/2, opt, opt+inc/2
foreach (@angles)
{
my $angle = $_;
# make the testing filename (fric2d input and output files)
my $testing_filename = $root."_".$prop_num."_".$formatted_fault."_".$angle.".in";
my $fric_output_filename = $root."_".$prop_num."_".$formatted_fault."_".$angle.".out";
# create the hash table that describes this scenario
# from the efficient hash table, and whatever angle testing during this iteration
$testing_geometry{$fault} = $angle;
# print the testing geometry
my $out = "\nTUNING PROPAGATION $prop_num \n";
$raw_output = $raw_output.$out;
write_output($out_raw_filename, $raw_output);
$out = $out."TESTING GEOMETRY\n".sprintf("\t%-10s %-10s\n", "Fault", "Angle");
foreach my $fault (sort keys %testing_geometry)
{
$out = $out.sprintf("\t%-10s %-10s\n", $fault, $testing_geometry{$fault});
}
$out = $out."\n";
print $out;
# if the testing geometry == the efficient geometry, use the efficient
# geometry from the previous function, because the efficient scenario here will be
# (i.e. we already tested this combination, then don't recalculate work)
my $previously_tested = is_hash_equal(\%testing_geometry, $fault_angle_ref);
# if a fault intersects itself
my $fault_intersect = 0;
# if this geometry has not been previously tested, then make the input file
if (!$previously_tested)
{
# for all the keys in the testing geometry
# build input file with 1 new element added to previously tested
# test for intersections with 1 element
# set testing file as previous file to add subsequent elements
# but use same testing filename (??)
my $prev_build = $prev_prop_filename;
for my $fault (sort keys %testing_geometry)
{
my $ref_one_element = {$fault => $testing_geometry{$fault}};
make_input_file_scenario($prev_build, $testing_filename,
$ref_one_element, $is_sand);
# get number of structures that could be possibly intersecting
my $structure_num = get_intersect_structs($testing_filename);
my $fault_intersect = correct_intersections($testing_filename, $ref_one_element, 0, $structure_num);
# if fault does not intersect itself, preserve input file and add next element
if (!$fault_intersect)