/
WSD ABM.nlogo
5298 lines (4599 loc) · 142 KB
/
WSD ABM.nlogo
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EXTENSIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
extensions [matrix GIS bitmap]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; AGENT BREEDS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; breed [farmers farmer]
breed [drillers driller]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GLOBAL VARIABLES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
globals
[
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;GROUNDWATER MODEL;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
max-error
max-head
min-head
max-K
min-K
iterations
aquifer-width
A
A-row-list
A-row-reduced-list
A-row-reduced-matrix
A-column-list
A-column-reduced-list
A-reduced
inverse-A
C
C-row-list
C-row-reduced-list
C-row-reduced-matrix
C-reduced
solution-vector
number-of-unknowns
K-patch-read
;;;;;;;;lists of patches;;;;;;;
no-flow-cells-list
fixed-head-cells-list
remove-cells-list
remove-cells-list-corrected
active-cells-remap
active-cells-remap-indexes
;;;;;;;multiplier functions;;;;;;;
sine-recharge
sine-well
;;;;;;river budget term;;;;;;;;
riv-budget
;;;;;;well pumping budget term;;;;;;;;
well-budget
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;SOCIAL MODEL;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
year
month
base-water-price
variable-water-price
water-price
canal-water-used
well-water-used
wd-artichoke
wd-broccoli
wd-cabbage
partichoke
pbroccoli
pcabbage
yartichoke
ybroccoli
ycabbage
ocartichoke
ocbroccoli
occabbage
crop-list
profit-list
yield-list
water-price-list
wd-list
oc-list
waiting-period-list
count-bankrupt
cropnames-list
acreage-list
acreage-list-pct
wdAF-list
wdM3-list
netprice-list
current-canal-volume
canal-water-price
max-depth-list ;; list containing maximum water table depths historically observed in the aquifer
max-depth-value ;; the maximum historical water table depth recorded (this is used by the driller to determine depths on new wells)
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;Crop Samples;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;CROP AREAS;;;;;;;;;;
%-of-Grains
%-of-Alfalfa
%-of-Cotton
%-of-Onion
%-of-Truck
%-of-Deciduous
%-of-Grapes
%-of-Potatoes
%-of-Melon
%-of-Carrots
%-of-Citrus
%-of-Fallow
output-almonds
output-cherries
output-citrus
output-grapes
output-pistachios
output-tomatoes
output-cotton
output-alfalfa
output-silageandforage
output-onions
output-bellpeppers
output-potatoes
output-fallow
output-almonds_name
output-cherries_name
output-citrus_name
output-grapes_name
output-pistachios_name
output-tomatoes_name
output-cotton_name
output-alfalfa_name
output-silageandforagee
output-onions_name
output-bellpeppers_name
output-potatoes_name
output-fallow_name
filename
cost-differentials_name
price-sensitivity_name
mutation-rate_name
starting-water-price_name
electricity-price_name
%-optimizers_name
target-water-level_name
canal-water-price_name
drought-index_name
prices_name
inflow-to-basin_name
; establishment-revenue-list
; establishment-costs-list
; establishment-water-demand-list
ready-to-histogram?
m-list
n-list
total-wells-drilled
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;DATASETS;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
csv
fileList
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;GINI;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
gini-index-reserve
lorenz-points
model-ready?
plots-ready?
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;; GIS;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
kern-shapefile
kern-raster
gis-envelope
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; AGENT/PATCH VARIABLES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
patches-own
[
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;GROUNDWATER MODEL;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;source and sink terms;;;;;;;
Qwell ;; well pumping rate [L3/T]
Qwell-temp ;; temporary dummy variable to initialize heads
Qcanal
Qcanal-temp
Qinjection ;; well injection rate [L3/T]
Qinjection-temp ;; temporary dummy variable to initialize heads
Recharge ;; recharge [L3/L2*T] ~ [L/T]
Recharge-temp ;; temporary dummy variable to initialize heads
ET ;; evapotranspiration, function of depth to water table [L3/L2*T] ~ [L/T]
ET-max-rate-temp ;; temporary dummy variable to initialize heads
ET-max-rate-patch
ET-extinction-depth-patch
ET-land-surface-elevation-patch
DRAIN ;; drain discharge, depends on h-d [L3/T] Note: divide by cell area in sourceterm equation
DRAIN-elevation-patch
DRAIN-conductance-patch
RIV ;; leakage from river [L3/L2*T] ~ [L/T]
RIV-elevation-patch
RIV-bottom-patch
RIV-conductance-patch
;;;;;;patch hydraulic parameters;;;;;;;
S-patch ;; storativity of each patch
S-patch-temp ;; temporary dummy variable to solve for steady state
K-patch ;; conductivity of each patch
T-patch ;; transmissivity of each patch
;;;;;;;;;type of patch;;;;;;;;
interior-node? ;; is this an active patch?
adjacent-to-boundary? ;; is this patch adjacent to a boundary?
interior-but-corner? ;; out of the interior nodes, is it in the corner?
;;;;;;patch bc's;;;;;
no-flow? ;; is this a no-flow cell?
fixed-head? ;; is this a fixed head cell?
fixed-flux? ;; is this a fixed flux cell?
;;;;;;patch neighbours;;;;
N-neighbour
S-neighbour
E-neighbour
W-neighbour
;;;;;;patch features;;;;;
well?
injection?
recharge?
ET?
DRAIN?
RIV?
;;;;;;;head values;;;;;;
H ;; heads at the new timestep
Hinew ;; heads at the new iteration
Hinitial ;; a reference H to calculate drawdowns
Hground ;; level of ground
H-ex-ante ;; level of ground water before planting
;;;;;;solution process parameters;;;;;
TN
TS
TE
TW
TC
Ncof
Scof
Ecof
Wcof
Ccof
SourceTerm
RHS
patch-number-tag
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;SOCIAL MODEL;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
water
money
wealth
current-crop
current-crop-index
gmlist
gmlist-temp
past-crop-index-list
past-crop-list
past-gm-list
past-water-price-list
weight-list
wait-counter
current-crop-temp
position-of-this-crop
mycrop
bankrupt?
water-level
well-depth
pumping-cost
dry-well?
new-well-needed?
mortgage?
payments-made
canal-rights-rank
canal-volume-claimed
canal-water?
crop-assigned?
farmer-well-here?
gw-bank-here?
farmer-here?
optimizer?
copycat?
tree-grower?
mutate?
]
drillers-own
[
client-list ;;list of farmers waiting for a new well
drilling-depth ;;how deep they drill — [m]
drilling-duration ;;how long they take to build a well — [months]
drilling-queue ;;how many farmers are waiting for a well
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GROUNDWATER MODEL VIEWS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to refresh-view
if view = "patch numbering" [ask patches with [interior-node? = true] [set plabel precision patch-number-tag 1 set plabel-color black]]
if view = "boundary conditions" [view-bc ask patches with [no-flow? = true][set pcolor black] ask patches with [fixed-head? = true][set pcolor blue]ask patches with [RIV? = true][set pcolor cyan] ask patches with [well? = true][set pcolor red] ask patches with [injection? = true][set pcolor blue]]
if view = "wells" [ask patches with [interior-node? = true][set plabel ""] ask patches with [well? = true][set plabel-color black set plabel "W"] ask patches with [injection? = true][set plabel-color black set plabel "R"]]
if view = "T (values)" [ask patches [set plabel "" set plabel precision T-patch 0 set plabel-color black]]
if view = "K (values)" [ask patches [set plabel "" set plabel precision K-patch 0 set plabel-color black]]
if view = "K (contours)" [setup-maxmin-K ask patches with [interior-node? = true and no-flow? = false and ET? = false and fixed-head? = false and DRAIN? = false and RIV? = false] [set pcolor scale-color brown K-patch min-K max-K set plabel precision K-patch 0 set plabel-color black] ask patches with [no-flow? = true][set pcolor black]]
if view = "S (values)" [ask patches [set plabel "" set plabel precision S-patch 5 set plabel-color black]]
if view = "crops" [ask patches [set plabel ""]]
if view = "heads (values)" [ask patches [set plabel precision H 0 set plabel-color black]]
if view = "heads (contours)" [setup-maxmin-heads ask patches with [interior-node? = true and no-flow? = false and ET? = false and fixed-head? = false and DRAIN? = false and RIV? = false] [setup-maxmin-heads set pcolor scale-color gray H min-head max-head set plabel precision H 0 set plabel-color black] ask patches with [no-flow? = true][set pcolor black] ask patches with [ET? = true][set plabel precision H 0 set plabel-color black]]
if view = "areal recharge" [ask patches [set plabel "" set plabel precision Recharge 4 set plabel-color black]]
if view = "ET" [ask patches [set plabel "" ask patches with [ET? = true][set plabel precision Recharge 4 set plabel-color black set pcolor green]]]
if view = "DRAIN conductance" [ask patches with [DRAIN? = true][set plabel DRAIN-conductance-patch]]
if view = "DRAIN flow [m3/d] and head values" [ask patches with [DRAIN? = true][set plabel precision DRAIN 0] ask patches with [DRAIN? = false][set plabel precision H 0 set plabel-color black]] ;; cells that are not drains show the head value
if view = "DRAIN flow [L/s] and head values" [ask patches with [DRAIN? = true][set plabel precision (DRAIN * 1000 / 86400) 0] ask patches with [DRAIN? = false][set plabel precision H 0 set plabel-color black]] ;; cells that are not drains show the head value
if view = "RIV flow [m3/d] and head values" [ask patches with [RIV? = true][set plabel precision RIV 0 if RIV < 0 [set pcolor red] if RIV >= 0 [set pcolor cyan]] ask patches with [RIV? = false][set plabel precision H 0 set plabel-color black]] ;; cells that are not drains show the head value
if view = "RIV flow [L/s] and head values" [ask patches with [RIV? = true][set plabel precision (RIV * 1000 / 86400) 0 if RIV < 0 [set pcolor red] if RIV >= 0 [set pcolor cyan]] ask patches with [RIV? = false][set plabel precision H 0 set plabel-color black]] ;; cells that are not drains show the head value
if view = "RIV flow [L/s] and drawdowns" [ask patches with [RIV? = true][set plabel precision (RIV * 1000 / 86400) 0 if RIV < 0 [set pcolor red] if RIV >= 0 [set pcolor cyan]] ask patches with [RIV? = false][set plabel precision (Hinitial - H) 0 set plabel-color black]] ;; cells that are not drains show the head value
if view = "RIV stage and head values" [ask patches with [DRAIN? = true][set plabel precision RIV-elevation-patch 0] ask patches with [DRAIN? = false][set plabel precision H 0 set plabel-color black]] ;; cells that are not drains show the head value
if view = "RIV bottom and head values" [ask patches with [DRAIN? = true][set plabel precision RIV-bottom-patch 0] ask patches with [DRAIN? = false][set plabel precision H 0 set plabel-color black]] ;; cells that are not drains show the head value
if view = "RIV conductance" [ask patches with [DRAIN? = true][set plabel precision RIV-conductance-patch 0] ask patches with [DRAIN? = false][set plabel ""]] ;; cells that are not drains are blank
end
to reset-view
ask patches [set pcolor white set plabel "" set plabel-color black view-bc]
end
to view-bc
ifelse left-bc = "no-flow"
[ask patches with [pxcor = 0][set pcolor black]]
[ask patches with [pxcor = 0][set pcolor blue]]
ifelse right-bc = "no-flow"
[ask patches with [pxcor = max-pxcor][set pcolor black]]
[ask patches with [pxcor = max-pxcor][set pcolor blue]]
ifelse top-bc = "no-flow"
[ask patches with [pycor = max-pycor][set pcolor black]]
[ask patches with [pycor = max-pycor][set pcolor blue]]
ifelse bottom-bc = "no-flow"
[ask patches with [pycor = min-pycor][set pcolor black]]
[ask patches with [pycor = min-pycor][set pcolor blue]]
ask patches with [fixed-head? = true][set pcolor blue]
ask patches with [ET? = true][set pcolor brown]
ask patches with [DRAIN? = true][set pcolor magenta]
ask patches with [RIV? = true][set pcolor cyan]
end
to setup-maxmin-heads ;; finds max and min H values for colour-coding
set max-head [H] of max-one-of patches with [interior-node? = true and no-flow? = false][H]
set min-head [H] of min-one-of patches with [interior-node? = true and no-flow? = false][H]
end
to setup-maxmin-K ;; finds max and min K values for colour-coding
set max-K [K-patch] of max-one-of patches [K-patch]
set min-K [K-patch] of min-one-of patches [K-patch]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET INITIAL HEADS TO CALCULATE DRAWDOWNS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to set-initial-heads
ask patches with [interior-node? = true][
set Hground 500
set Hinitial 400]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET BCs / POINT-AND-CLICK ON THE INTERFACE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to change-to-fixed-head
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set pcolor blue
set fixed-head? true
set no-flow? false
set H fixed-head-value-new
set K-patch K
ifelse aquifer-type = "confined"
[set T-patch (K-patch * aquifer-thickness)] ;; sets transmissivity and storage for confined conditions
[set T-patch (K-patch * H)] ;; sets transmissivity and storage for unconfined conditions
set plabel-color black
set plabel H
]
]
end
to change-to-no-flow
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set pcolor black
set fixed-head? false
set no-flow? true
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET HYDRAULIC PARAMETERS / POINT-AND-CLICK ON THE INTERFACE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to set-K
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set K-patch K-input
set plabel-color black
set plabel K-patch
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET DRAIN / POINT-AND-CLICK ON THE INTERFACE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to set-DRAIN-patch
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set DRAIN? true
set DRAIN-elevation-patch DRAIN-elevation
set DRAIN-conductance-patch DRAIN-conductance
set plabel-color black
set pcolor magenta
set plabel DRAIN-conductance-patch
]
]
end
to clear-DRAIN-patches-all
ask patches with [DRAIN? = true]
[
set DRAIN? false
set DRAIN 0
set DRAIN-elevation-patch 0
set DRAIN-conductance-patch 0
set pcolor white
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET RIV / POINT-AND-CLICK ON THE INTERFACE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to set-RIV-patch
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set RIV? true
set RIV-elevation-patch RIV-elevation
set RIV-bottom-patch RIV-bottom
set RIV-conductance-patch RIV-conductance
set plabel-color black
set pcolor cyan
set plabel RIV-elevation-patch
]
]
end
to clear-RIV-patches-all
ask patches with [RIV? = true]
[
set RIV? false
set RIV 0
set RIV-elevation-patch 0
set RIV-bottom-patch 0
set RIV-conductance-patch 0
set pcolor white
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET ET / POINT-AND-CLICK ON THE INTERFACE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to set-ET-patch
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set ET? true
set ET-max-rate-patch ET-max-rate
set ET-extinction-depth-patch ET-extinction-depth
set ET-land-surface-elevation-patch ET-land-surface-elevation
set plabel-color black
set pcolor brown
set plabel ET-max-rate-patch
]
]
end
to clear-ET-patches-all
ask patches with [ET? = true]
[
set ET? false
set ET-max-rate 0
set ET-extinction-depth 0
set ET-land-surface-elevation 0
set pcolor white
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET FIXED FLUX — POINT-AND-CLICK ON THE INTERFACE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to place-fixed-flux
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set pcolor magenta
set fixed-flux? true
set injection? true
set Qinjection Qfixed-flux
set plabel-color black
set plabel Qinjection
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET WELLS — POINT-AND-CLICK ON THE INTERFACE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to place-pumping-well
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set pcolor red
set well? true
set Qwell Qwell-input
;set screen-level screen-level-input
set plabel-color black
set plabel Qwell
]
]
end
to place-injection-well
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set pcolor blue
set injection? true
set Qinjection Qinjection-input
set plabel-color black
set plabel Qinjection
]
]
end
;; the following routines allow clearing the view from stresses and resetting them using the interface buttons
to hide-stresses-patches
ask patches with [well? = true or injection? = true]
[
if well? = true [set pcolor white set plabel-color red]
if injection? = true [set pcolor white set plabel-color blue]
]
end
to hide-stresses-labels
ask patches with [well? = true or injection? = true]
[
if well? = true [set plabel ""]
if injection? = true [set plabel ""]
]
end
to clear-stresses
ask patches with [well? = true or injection? = true]
[
if well? = true [set Qwell 0 hide-stresses-patches hide-stresses-labels set well? false]
if injection? = true [set Qinjection 0 hide-stresses-patches hide-stresses-labels set injection? false]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET RECHARGE / POINT-AND-CLICK ON THE INTERFACE AND ALL CELLS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to set-recharge-all-patches
ask patches with [interior-node? = true][set Recharge areal-recharge]
end
to set-recharge-single-patch
if mouse-down? ;; reports true or false to indicate whether mouse button is down
[
ask patch mouse-xcor mouse-ycor
[
set Recharge areal-recharge
set plabel-color black
set plabel Recharge
]
]
end
to clear-recharge
ask patches with [interior-node? = true][set Recharge 0]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MULTIPLIER FUNCTIONS / RECHARGE AND WELLS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to calculate-multiplier-sine-recharge ;; assumes that recharge occurs in (southern hemisphere) winter
let B-recharge (2 * pi / 365)
let C-recharge 81.75
set sine-recharge sin (B-recharge * (ticks - C-recharge) * 180 / pi) ;; note that the sine function here is in degrees, not in radians
if sine-recharge < 0 [set sine-recharge 0]
end
to calculate-multiplier-sine-wells ;; assumes that pumping occurs in (southern hemisphere) summer
let B-well (2 * pi / 365)
let C-well -81.75
set sine-well sin (B-well * (ticks - C-well) * 180 / pi) ;; note that the sine function here is in degrees, not in radians
if sine-well < 0 [set sine-well 0]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SETUP PROCEDURES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup-model
ca
reset-ticks
setup-world
setup-bc
setup-initial-heads
setup-hydraulic-parameters
setup-sources
setup-maxmin-heads
setup-neighbours
setup-patch-numbering
setup-patches-adjacent-to-boundary
refresh-view
end
to setup-world
resize-world 0 (N + 1) 0 (M + 1) ;; defines number of cells in X (N) and Y (M) direction, leaves additional patches for the boundary conditions NOTE: N=M
ask patches [set pcolor white] ;; set initial colour of patches to white
ask patches [set well? false set recharge? false ] ;; initially none of the patches have wells or recharge, setup-pumping and setup-recharge modify this tag
end
to setup-bc
ask patches [set no-flow? false set fixed-head? false set interior-node? true] ;; initialize these location indicators: all nodes are interior and no bc tags - easier for further coding
ask patches [if (pxcor = min-pxcor) or (pxcor = max-pxcor) or (pycor = max-pycor) or (pycor = min-pycor) [set interior-node? false]] ;; tag interior and boundary nodes
ifelse left-bc = "no-flow"
[ask patches with [pxcor = 0][set pcolor black set no-flow? true set interior-node? false set fixed-head? false set K-patch 0 set T-patch 0]]
[ask patches with [pxcor = 0][set pcolor blue set fixed-head? true set interior-node? false set H left-bc-head]]
ifelse right-bc = "no-flow"
[ask patches with [pxcor = max-pxcor][set pcolor black set no-flow? true set interior-node? false set fixed-head? false set K-patch 0 set T-patch 0]]
[ask patches with [pxcor = max-pxcor][set pcolor blue set fixed-head? true set interior-node? false set H right-bc-head]]
ifelse top-bc = "no-flow"
[ask patches with [pycor = max-pycor][set pcolor black set no-flow? true set interior-node? false set fixed-head? false set K-patch 0 set T-patch 0]]
[ask patches with [pycor = max-pycor][set pcolor blue set fixed-head? true set interior-node? false set H top-bc-head]]
ifelse bottom-bc = "no-flow"
[ask patches with [pycor = min-pycor][set pcolor black set no-flow? true set interior-node? false set fixed-head? false set K-patch 0 set T-patch 0]]
[ask patches with [pycor = min-pycor][set pcolor blue set fixed-head? true set interior-node? false set H bottom-bc-head]]
end
to setup-initial-heads
ask patches with [interior-node? = true] [set H initial-heads] ;; set the initial heads in interior nodes
end
to setup-hydraulic-parameters ;; sets a homogeneous conductivity to the whole model using the input box on the interface (avoids having cells with no K value)
ask patches with [no-flow? = false]
[
set K-patch K
ifelse aquifer-type = "confined"
[set T-patch (K-patch * aquifer-thickness) set S-patch S] ;; sets transmissivity and storage for confined conditions
[set T-patch (K-patch * H) set S-patch Sy] ;; sets transmissivity and storage for unconfined conditions
]
end
to setup-sources
ask patches [set well? false] ;; initialize patch tags without wells
ask patches [set injection? false] ;; initialize patch tags without injection
ask patches [set recharge? false] ;; initialize patch tags without recharge
ask patches [set ET? false] ;; initialize patch tags without ET
ask patches [set DRAIN? false] ;; initialize patch tags without DRAIN
ask patches [set RIV? false] ;; initialize patch tags without leakage from river
;; Sources and stresses can be added directly through the interface, otherwise manually (directly in the code) here:
;; pumping wells, units of [m3/day] ~ [L3/T]
;; injection wells, units of [m3/day] ~ [L3/T]
;; recharge cells, units of [L3/L2*T] ~ [L/T]
;; ET cells, units of [L3/L2*T] ~ [L/T]
;; DRAIN cells, units of [L3/T]
;; RIV cells, units of [L3/T]
end
to setup-neighbours
ask patches with [interior-node? = true]
[
set N-neighbour patch-at 0 1 ;; neighbour North of this patch
set S-neighbour patch-at 0 -1 ;; neighbour South of this patch
set E-neighbour patch-at 1 0 ;; neighbour East of this patch
set W-neighbour patch-at -1 0 ;; neighbour West of this patch
]
end
to setup-patch-numbering
ask patches with [interior-node? = true]
[set patch-number-tag pxcor + (M - pycor) * N]
end
to setup-patches-adjacent-to-boundary
ask patches with [interior-node? = true]
[
ifelse (pxcor = (min-pxcor + 1) or pxcor = (max-pxcor - 1) or pycor = (min-pycor + 1) or pycor = (max-pycor - 1))
[set adjacent-to-boundary? true]
[set adjacent-to-boundary? false]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN ITERATION LOOP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to GO
;; *******INSERT SOCIAL MODEL FUNCTIONS IN THE FOLLOWING BLOCK******
if social-model = TRUE ;; option to deactivate the social model and run groundwater model only
[
ask one-of patches [SET-WATER-PRICE]
; ask patches
; [set-pumping-cost]
UPDATE-CANAL-WATER-PRICE
if drilling? = TRUE
[
if ticks > 0 [UPDATE-MAX-WATER-DEPTH] ;; keeps track of the max water table depth observed in the basin
CHECK-IF-DRY-WELLS ;; if farmer well goes dry, farmer hires driller. Drills new well at a cost defined by 'drilling-cost' slider in the interface
DRILL-A-WELL ;; when a farmer contacts a drilling company
]
ESTABLISH-TREES
CLAIM-WATER
; UPDATE-PUMPING-RATES
]
UPDATE-INFLOW-TO-BASIN
iterate
ifelse water-level-labels? = FALSE [set view "crops"][set view "heads (values)"]
refresh-view
if social-model = TRUE
[
ask turtles[
set-pumping-costs-ex-post
CALCULATE-MARGIN] ;; ex post calculation
SELL-CROPS
BANKRUPT
UPDATE-CROP-COUNTS
UPDATE-CROP-VIEW
update-crop-distribution
update-lorenz-and-gini
]
tick
prepare-output
set year year + 1
set plots-ready? TRUE
end
to iterate
if aquifer-type = "unconfined" [prepare-equations solve-once update-unconfined-transmissivities]
if aquifer-type = "confined" [solve-once]
end
to update-unconfined-transmissivities
ask patches [set T-patch (K-patch * H)]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; POPULATE THE MODEL WITH INITIAL HEADS — STEADY STATE RUN WITH NO STRESSES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to initialize-heads ;; runs the model ONCE, with all stresses = 0 to set up the initial heads
reset-ticks
ask patches
[
if aquifer-type = "confined" ;; sets transmissivity and storage for confined conditions
[set T-patch (K-patch * aquifer-thickness) set S-patch S]
if aquifer-type = "unconfined" ;; sets transmissivity and storage for unconfined conditions
[set T-patch (K-patch * H) set S-patch Sy]
set Qwell-temp Qwell ;; save the original values to restore after the init, they are needed for the steady/transient simulation
set Qinjection-temp Qinjection
set Recharge-temp Recharge
set S-patch-temp S-patch
set ET-max-rate-temp ET-max-rate-patch
set Qwell 0 ;; we set these parameters to zero for the init, which is steady state without any stresses
set Qinjection 0
set Recharge 0
set S-patch 0
set ET-max-rate-patch 0
]
ask patches with [ET? = true] ;; sets the ET cell to a fixed-head condition to give a reasonalble steady-state solution considering long-term equilibrium at H = ground elevation - extinction depth
[
set H (ET-land-surface-elevation - ET-extinction-depth-patch)
set fixed-head? true
]
prepare-equations ;; set up the equations for this solution
iterate
refresh-view
;; now prepare equations for the main simulation
if solver = "steady-state" [prepare-equations-steadystate] ;; note that the fixed-head assumption for ET cells is maintained here
if solver = "transient" [ask patches with [ET? = true][set fixed-head? false] prepare-equations-transient] ;; remove the fixed-head assumption of ET cells for subsequent transient simulations
set-initial-heads
end
to prepare-equations-steadystate
ask patches
[
set Qwell Qwell-temp
set Qinjection Qinjection-temp
set Recharge Recharge-temp
set S-patch 0 ;; S=0 for steady state simulations and stresses are activated
set ET-max-rate-patch ET-max-rate-temp
]
prepare-equations
end
to prepare-equations-transient
ask patches
[
set Qwell Qwell-temp
set Qinjection Qinjection-temp
set Recharge Recharge-temp
set S-patch S-patch-temp
set ET-max-rate-patch ET-max-rate-temp
] ;; restores original parameters for the simulation
prepare-equations
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PREPARE EQUATIONS AND DEFINE THE INVERSE OF MATRIX A ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; executed ONCE for CONFINED conditions (T does not change during the simulation) and ITERATIVELY for unconfined conditions (T=Kxh varies during the simulation)
to prepare-equations
calculate-conductances
modify-conductances-for-bcs
build-matrix-A
remove-inactive-cells-from-A-matrix
calculate-inverse-A
end
to calculate-conductances ;; sets the interblock transmissivities using the harmonic mean
ask patches with [interior-node? = true]
[
set TN [T-patch] of N-neighbour ;; T of patch North of here
set TS [T-patch] of S-neighbour ;; T of patch South of here
set TE [T-patch] of E-neighbour ;; T of patch East of here
set TW [T-patch] of W-neighbour ;; T of patch West of here
set TC [T-patch] of self
;; using the harmonic mean of conductivity
set Ncof (1 / (delta ^ 2)) * (2 * TC * TN) / (TC + TN) ;; Coeff for head North of this patch
set Scof (1 / (delta ^ 2)) * (2 * TC * TS) / (TC + TS) ;; Coeff for head South of this patch
set Ecof (1 / (delta ^ 2)) * (2 * TC * TE) / (TC + TE) ;; Coeff for head East of this patch
set Wcof (1 / (delta ^ 2)) * (2 * TC * TW) / (TC + TW) ;; Coeff for head West of this patch
set Ccof -1 * (Ncof + Scof + Ecof + Wcof + S-patch / delta-t) ;; Coeff for head at this patch
]
end
to modify-conductances-for-bcs
ask patches with [interior-node? = true]