This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
forked from respec/HSPsquared
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPLANK_Class.py
2013 lines (1719 loc) · 71.6 KB
/
PLANK_Class.py
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
import numpy as np
from numpy import zeros, array
from math import log, exp
import numba as nb
from numba.experimental import jitclass
from HSP2.ADCALC import advect
from HSP2.OXRX_Class import OXRX_Class
from HSP2.NUTRX_Class import NUTRX_Class
from HSP2.RQUTIL import sink, decbal
from HSP2.utilities import make_numba_dict, initm
spec = [
('OXRX', OXRX_Class.class_type.instance_type),
('NUTRX', NUTRX_Class.class_type.instance_type),
('aldh', nb.float64),
('aldl', nb.float64),
('alnpr', nb.float64),
('alr20', nb.float64),
('AMRFG', nb.int32),
('baco2', nb.float64),
('balbod', nb.float64),
('balcla', nb.float64[:]),
('baldep', nb.float64),
('baldox', nb.float64),
('BALFG', nb.int32),
('ballit', nb.float64),
('balno3', nb.float64),
('balorc', nb.float64),
('balorn', nb.float64),
('balorp', nb.float64),
('balpo4', nb.float64),
('balr20', nb.float64[:]),
('baltam', nb.float64),
('balvel', nb.float64),
('benal', nb.float64[:]),
('BFIXFG', nb.int32[:]),
('BINVFG', nb.int32),
('BNPFG', nb.int32),
('bpcntc', nb.float64),
('campr', nb.float64),
('cbnrbo', nb.float64),
('cfbalg', nb.float64),
('cfbalr', nb.float64),
('cflit', nb.float64),
('cfsaex', nb.float64),
('cktrb1', nb.float64),
('cktrb2', nb.float64),
('claldh', nb.float64),
('cmingr', nb.float64),
('cmmbi', nb.float64),
('cmmd1', nb.float64[:]),
('cmmd2', nb.float64[:]),
('cmmlt', nb.float64),
('cmmn', nb.float64),
('cmmnb', nb.float64[:]),
('cmmnp', nb.float64),
('cmmp', nb.float64),
('cmmpb', nb.float64[:]),
('cmmv', nb.float64),
('co2', nb.float64),
('conv', nb.float64),
('cremvl', nb.float64),
('cslit', nb.float64[:]),
('cslof1', nb.float64[:]),
('cslof2', nb.float64[:]),
('ctrbq1', nb.float64),
('ctrbq2', nb.float64),
('cvbc', nb.float64),
('cvbcl', nb.float64),
('cvbn', nb.float64),
('cvbo', nb.float64),
('cvbp', nb.float64),
('cvbpc', nb.float64),
('cvbpn', nb.float64),
('cvnrbo', nb.float64),
('cvpb', nb.float64),
('DECFG', nb.int32),
('delt', nb.float64),
('delt60', nb.float64),
('delts', nb.float64),
('dthbal', nb.float64[:]),
('dthphy', nb.float64),
('dthtba', nb.float64),
('dthzoo', nb.float64),
('errors', nb.int64[:]),
('extb', nb.float64),
('flxbal', nb.float64[:,:]),
('fravl', nb.float64),
('frrif', nb.float64),
('grobal', nb.float64[:]),
('grophy', nb.float64),
('grores', nb.float64[:]),
('grotba', nb.float64),
('grozoo', nb.float64),
('HTFG', nb.int32),
('iorc', nb.float64),
('iorn', nb.float64),
('iorp', nb.float64),
('iphyto', nb.float64),
('itorc', nb.float64),
('itorn', nb.float64),
('itorp', nb.float64),
('itotn', nb.float64),
('itotp', nb.float64),
('izoo', nb.float64),
('limbal', nb.int32[:]),
('limphy', nb.int32),
('litsed', nb.float64),
('lmingr', nb.float64),
('lsnh4', nb.float64[:]),
('lspo4', nb.float64[:]),
('malgr', nb.float64),
('mbal', nb.float64),
('mbalgr', nb.float64[:]),
('minbal', nb.float64),
('mxstay', nb.float64),
('mzoeat', nb.float64),
('naldh', nb.float64),
('nexits', nb.int32),
('nmaxfx', nb.float64),
('nminc', nb.float64),
('nmingr', nb.float64),
('nonref', nb.float64),
('NSFG', nb.int32),
('numbal', nb.int32),
('oorc', nb.float64[:]),
('oorn', nb.float64[:]),
('oorp', nb.float64[:]),
('ophyt', nb.float64[:]),
('orc', nb.float64),
('oref', nb.float64),
('orn', nb.float64),
('orp', nb.float64),
('otorc', nb.float64[:]),
('otorn', nb.float64[:]),
('otorp', nb.float64[:]),
('ototn', nb.float64[:]),
('ototp', nb.float64[:]),
('oxald', nb.float64),
('oxzd', nb.float64),
('ozoo', nb.float64[:]),
('paldh', nb.float64),
('paradf', nb.float64),
('PHFG', nb.int32),
('phybod', nb.float64),
('phycla', nb.float64),
('phydox', nb.float64),
('PHYFG', nb.int32),
('phylit', nb.float64),
('phyno3', nb.float64),
('phyorc', nb.float64),
('phyorn', nb.float64),
('phyorp', nb.float64),
('phypo4', nb.float64),
('physet', nb.float64),
('phytam', nb.float64),
('phyto', nb.float64),
('pmingr', nb.float64),
('potbod', nb.float64),
('pyco2', nb.float64),
('ratclp', nb.float64),
('refr', nb.float64),
('refset', nb.float64),
('rifcq1', nb.float64),
('rifcq2', nb.float64),
('rifcq3', nb.float64),
('rifdf', nb.float64[:]),
('rifvf', nb.float64[:]),
('roorc', nb.float64),
('roorn', nb.float64),
('roorp', nb.float64),
('rophyt', nb.float64),
('rotorc', nb.float64),
('rotorn', nb.float64),
('rotorp', nb.float64),
('rototn', nb.float64),
('rototp', nb.float64),
('rozoo', nb.float64),
('SDLTFG', nb.int32),
('seed', nb.float64),
('simlen', nb.int32),
('snkphy', nb.float64),
('snkorc', nb.float64),
('snkorn', nb.float64),
('snkorp', nb.float64),
('svol', nb.float64),
('talgrh', nb.float64),
('talgrl', nb.float64),
('talgrm', nb.float64),
('tbenal', nb.float64[:]),
('tcbalg', nb.float64[:]),
('tcbalr', nb.float64[:]),
('tcgraz', nb.float64),
('tczfil', nb.float64),
('tczres', nb.float64),
('tn', nb.float64),
('torc', nb.float64),
('torn', nb.float64),
('torp', nb.float64),
('totbod', nb.float64),
('totdox', nb.float64),
('totno3', nb.float64),
('totorc', nb.float64),
('totorn', nb.float64),
('totorp', nb.float64),
('totphy', nb.float64),
('totpo4', nb.float64),
('tottam', nb.float64),
('tottba', nb.float64),
('totzoo', nb.float64),
('tp', nb.float64),
('uunits', nb.int32),
('vol', nb.float64),
('zd', nb.float64),
('zexdel', nb.float64),
('zfil20', nb.float64),
('ZFOOD', nb.int32),
('zoco2', nb.float64),
('zomass', nb.float64),
('zoo', nb.float64),
('zoobod', nb.float64),
('zoodox', nb.float64),
('ZOOFG', nb.int32),
('zoono3', nb.float64),
('zooorc', nb.float64),
('zooorn', nb.float64),
('zooorp', nb.float64),
('zoophy', nb.float64),
('zoopo4', nb.float64),
('zootam', nb.float64),
('zres20', nb.float64),
]
@jitclass(spec)
class PLANK_Class:
#-------------------------------------------------------------------
# class initialization:
#-------------------------------------------------------------------
def __init__(self, siminfo, nexits, vol, ui_rq, ui, ts, OXRX, NUTRX):
''' Initialize instance variables for lower food web simulation '''
self.errors = zeros(int(ui['errlen']), dtype=np.int64)
'''
self.limit = array(8, type=nb.char) #np.chararray(8, itemsize=4)
self.limit[1] = 'LIT'
self.limit[2] = 'NON'
self.limit[3] = 'TEM'
self.limit[4] = 'NIT'
self.limit[5] = 'PO4'
self.limit[6] = 'NONE'
self.limit[7] = 'WAT'
'''
self.delt = siminfo['delt']
delt60 = siminfo['delt'] / 60.0 # delt60 - simulation time interval in hours
self.delt60 = delt60
self.simlen = int(siminfo['steps'])
self.delts = siminfo['delt'] * 60
self.uunits = int(siminfo['units'])
self.nexits = int(nexits)
self.vol = vol
self.svol = self.vol
# inflow/outflow conversion factor:
if self.uunits == 2: # SI conversion: (g/m3)*(m3/ivld) --> [kg/ivld]
self.conv = 1.0e-3
else: # Eng. conversion: (g/m3)*(ft3/ivld) --> [lb/ivld]
self.conv = 6.2428e-5
# flags - table-type PLNK-FLAGS
self.PHYFG = int(ui['PHYFG'])
self.ZOOFG = int(ui['ZOOFG'])
self.BALFG = int(ui['BALFG'])
self.SDLTFG = int(ui['SDLTFG'])
self.AMRFG = int(ui['AMRFG'])
self.DECFG = int(ui['DECFG'])
self.NSFG = int(ui['NSFG'])
self.ZFOOD = int(ui['ZFOOD'])
self.BNPFG = int(ui['BNPFG'])
self.HTFG = int(ui_rq['HTFG'])
self.PHFG = int(ui_rq['PHFG'])
self.bpcntc = NUTRX.bpcntc
self.cvbo = NUTRX.cvbo
self.cvbpc = NUTRX.cvbpc
self.cvbpn = NUTRX.cvbpn
if self.ZOOFG == 1 and self.PHYFG == 0:
self.errors[0] += 1
# ERRMSG: error - zooplankton cannot be simulated without phytoplankton
if self.NSFG == 1 and NUTRX.TAMFG == 0:
self.errors[1] += 1
# ERRMSG: error - ammonia cannot be included in n supply if it is not
if NUTRX.PO4FG == 0:
self.errors[2] += 1
# ERRMSG: error - phosphate must be simulated if plankton are being
self.numbal = 0
self.BFIXFG = zeros(5, dtype=np.int32)
if self.BALFG == 2: # user has selected multiple species with more complex kinetics
# additional benthic algae flags - table-type BENAL-FLAG
self.numbal = int(ui['NUMBAL'])
self.BINVFG = int(ui['BINVFG'])
for i in range(1,5):
self.BFIXFG[i] = int(ui['BFIXFG' + str(i)])
else:
self.numbal = self.BALFG # single species or none
self.cfsaex = 1.0
if self.HTFG > 0 and 'CFSAEX' in ui_rq: # via heat-parm input table
self.cfsaex = ui_rq['CFSAEX']
elif 'CFSAEX' in ui: # fraction of surface exposed - table-type surf-exposed
self.cfsaex = ui['CFSAEX']
# table-type plnk-parm1
self.ratclp = ui['RATCLP']
self.nonref = ui['NONREF']
self.litsed = ui['LITSED']
self.alnpr = ui['ALNPR']
self.extb = ui['EXTB']
self.malgr = ui['MALGR'] * self.delt60
self.paradf = ui['PARADF']
self.refr = 1.0 - self.nonref # define fraction of biomass which is refractory material
# compute derived conversion factors
self.cvbc = self.bpcntc / 100.0
self.cvnrbo = self.nonref * self.cvbo
self.cvbp = (31.0 * self.bpcntc) / (1200.0 * self.cvbpc)
self.cvbn = 14.0 * self.cvbpn * self.cvbp / 31.0
self.cvpb = 31.0 / (1000.0 * self.cvbp)
self.cvbcl = 31.0 * self.ratclp / self.cvpb
# table-type plnk-parm2
self.cmmlt = ui['CMMLT']
self.cmmn = ui['CMMN']
self.cmmnp = ui['CMMNP']
self.cmmp = ui['CMMP']
self.talgrh = ui['TALGRH']
self.talgrl = ui['TALGRL']
self.talgrm = ui['TALGRM']
if self.uunits == 1:
self.talgrh = (self.talgrh - 32.0) * 0.555
self.talgrl = (self.talgrl - 32.0) * 0.555
self.talgrm = (self.talgrm - 32.0) * 0.555
# table-type plnk-parm3
self.alr20 = ui['ALR20'] * delt60 # convert rates from 1/hr to 1/ivl
self.aldh = ui['ALDH'] * delt60
self.aldl = ui['ALDL'] * delt60
self.oxald = ui['OXALD'] * delt60
self.naldh = ui['NALDH'] * delt60
self.paldh = ui['PALDH']
# table-type plnk-parm4
self.nmingr = ui['NMINGR']
self.pmingr = ui['PMINGR']
self.cmingr = ui['CMINGR']
self.lmingr = ui['LMINGR']
self.nminc = ui['NMINC']
# phytoplankton-specific parms - table-type phyto-parm
# this table must always be input so that REFSET is read
self.seed = ui['SEED']
self.mxstay = ui['MXSTAY']
self.oref = ui['OREF']
self.claldh = ui['CLALDH']
self.physet = ui['PHYSET'] * delt60 # change settling rates to units of 1/ivl
self.refset = ui['REFSET'] * delt60 # change settling rates to units of 1/ivl
if self.PHYFG == 1 and self.ZOOFG == 1: # zooplankton-specific parameters
# table-type zoo-parm1
self.mzoeat = ui['MZOEAT'] * delt60 # convert rates from 1/hr to 1/ivl
self.zfil20 = ui['ZFIL20'] * delt60 # convert rates from 1/hr to 1/ivl
self.zres20 = ui['ZRES20'] * delt60 # convert rates from 1/hr to 1/ivl
self.zd = ui['ZD'] * delt60 # convert rates from 1/hr to 1/ivl
self.oxzd = ui['OXZD'] * delt60 # convert rates from 1/hr to 1/ivl
# table-type zoo-parm2
self.tczfil = ui['TCZFIL']
self.tczres = ui['TCZRES']
self.zexdel = ui['ZEXDEL']
self.zomass = ui['ZOMASS']
if self.BALFG >= 1: # benthic algae-specific parms; table-type benal-parm
self.mbal = ui['MBAL'] / self.cvpb # convert maximum benthic algae to micromoles of phosphorus
self.cfbalr = ui['CFBALR']
self.cfbalg = ui['CFBALG']
self.minbal = ui['MINBAL'] / self.cvpb # convert maximum benthic algae to micromoles of phosphorus
self.campr = ui['CAMPR']
self.fravl = ui['FRAVL']
self.nmaxfx = ui['NMAXFX']
self.mbalgr = zeros(self.numbal)
self.tcbalg = zeros(self.numbal)
self.cmmnb = zeros(self.numbal)
self.cmmpb = zeros(self.numbal)
self.cmmd1 = zeros(self.numbal)
self.cmmd2 = zeros(self.numbal)
self.cslit = zeros(self.numbal)
self.balr20 = zeros(self.numbal)
self.tcbalr = zeros(self.numbal)
self.cslof1 = zeros(self.numbal)
self.cslof2 = zeros(self.numbal)
self.grores = zeros(self.numbal)
if self.BALFG == 2: # user has selected multiple species with more complex kinetics
for i in range(self.numbal):
# species-specific growth parms - table type benal-grow
self.mbalgr[i] = ui['MBALGR'] * self.delt60
self.tcbalg[i] = ui['TCBALG']
self.cmmnb[i] = ui['CMMNB']
self.cmmpb[i] = ui['CMMPB']
self.cmmd1[i] = ui['CMMD1']
self.cmmd2[i] = ui['CMMD2']
self.cslit[i] = ui['CSLIT']
# species-specific resp and scour parms - table type benal-resscr
self.balr20[i] = ui['BALR20'] * self.delt60
self.tcbalr[i] = ui['TCBALR']
self.cslof1[i] = ui['CSLOF1'] * self.delt60
self.cslof2[i] = ui['CSLOF2']
self.grores[i] = ui['GRORES']
# grazing and disturbance parms - table-type benal-graze
self.cremvl = ui['CREMVL']
self.cmmbi = ui['CMMBI']
self.tcgraz = ui['TCGRAZ']
hrpyr = 8760.0 #constant
self.cremvl = (self.cremvl / self.cvpb) / hrpyr * self.delt60
if self.SDLTFG == 2: # turbidity regression parms - table-type benal-light
self.ctrbq1 = ui['CTRBQ1']
self.ctrbq2 = ui['CTRBQ2']
self.cktrb1 = ui['CKTRB1']
self.cktrb2 = ui['CKTRB2']
# table-type benal-riff1
self.frrif = ui['FRRIF']
self.cmmv = ui['CMMV']
self.rifcq1 = ui['RIFCQ1']
self.rifcq2 = ui['RIFCQ2']
self.rifcq3 = ui['RIFCQ3']
# table-type benal-riff2
self.rifvf = zeros(5); self.rifdf = zeros(5)
for i in range(1,5):
self.rifvf[i] = ui['RIFVF' + str(i)]
self.rifdf[i] = ui['RIFDF' + str(i)]
# table-type plnk-init
self.phyto = ui['PHYTO']
self.zoo = ui['ZOO']
#benal = ui['BENAL']
self.orn = ui['ORN']
self.orp = ui['ORP']
self.orc = ui['ORC']
# variable initialization:
if self.PHYFG == 0: # initialize fluxes of inactive constituent
self.rophyt = 0.0
self.ophyt[:] = 0.0 #nexits
self.phydox = self.phybod = 0.0
self.phytam = 0.0; self.phyno3 = 0.0; self.phypo4 = 0.0
self.phyorn = 0.0; self.phyorp = 0.0; self.phyorc = 0.0
self.pyco2 = 0.0
self.dthphy = 0.0; self.grophy = 0.0; self.totphy = 0.0
self.rozoo = 0.0
self.ozoo = zeros(nexits)
if self.ZOOFG == 1: # convert zoo to mg/l
self.zoo *= self.zomass
else: # zooplankton not simulated, but use default values
# initialize fluxes of inactive constituent
self.rozoo = 0.0
self.ozoo[:] = 0.0 #nexits
self.zoodox = 0.0; self.zoobod = 0.0
self.zootam = 0.0; self.zoono3 = 0.0; self.zoopo4 = 0.0
self.zooorn = 0.0; self.zooorp = 0.0; self.zooorc = 0.0
self.zoophy = 0.0
self.zoco2 = 0.0
self.grozoo = 0.0; self.dthzoo = 0.0; self.totzoo = 0.0
# benthic algae initialization:
self.benal = zeros(self.numbal)
self.flxbal = zeros((4,5))
if self.numbal == 1: # single species
self.benal[0] = ui['BENAL'] # points to table-type plnk-init above for rvals
elif self.numbal >= 2: # multiple species - table-type benal-init
for n in range(self.numbal):
self.benal[n] = ui['BENAL' + str(n+1)]
else: # no benthic algae simulated
self.baldox = 0.0; self.balbod = 0.0
self.baltam = 0.0; self.balno3 = 0.0; self.balpo4 = 0.0
self.balorn = 0.0; self.balorp = 0.0; self.balorc = 0.0
self.baco2 = 0.0
# compute derived quantities
self.phycla = self.phyto * self.cvbcl
self.balcla = zeros(self.numbal)
for i in range(self.numbal):
self.balcla[i] = self.benal[i] * self.cvbcl
self.lsnh4 = zeros(4)
self.lspo4 = zeros(4)
if self.vol > 0.0: # compute initial summary concentrations
for i in range(1, 4):
self.lsnh4[i] = NUTRX.rsnh4[i] / self.vol
self.lspo4[i] = NUTRX.rspo4[i] / self.vol
# calculate summary concentrations:
(self.torn, self.torp, self.torc, self.potbod, self.tn, self.tp) \
= self.pksums(NUTRX,self.phyto,self.zoo,self.orn,self.orp,self.orc,
NUTRX.no3,NUTRX.tam,NUTRX.no2,self.lsnh4,NUTRX.po4,self.lspo4,OXRX.bod)
return
def simulate(self, tw, phval, co2, tss, OXRX, NUTRX, iphyto, izoo, iorn, iorp, iorc,
wash, solrad, avdepe, avvele, depcor, ro, binv,
pladep_orn, pladep_orp, pladep_orc, advData):
''' '''
# hydraulics:
(nexits, vols, vol, srovol, erovol, sovol, eovol) = advData
self.vol = vol
# initialize temp. vars for DO/BOD and NUTRX states:
po4 = NUTRX.po4
no3 = NUTRX.no3
no2 = NUTRX.no2
tam = NUTRX.tam
dox = OXRX.dox
bod = OXRX.bod
self.co2 = co2
# inflows: convert from [mass/ivld] to [conc.*vol/ivld]
self.iphyto = iphyto / self.conv
self.izoo = izoo / self.conv
self.iorn = iorn / self.conv
self.iorp = iorp / self.conv
self.iorc = iorc / self.conv
#-----------------------------------------------------------
# advection:
#-----------------------------------------------------------
if self.PHYFG == 1:
# advect phytoplankton
(self.phyto, self.rophyt, self.ophyt) \
= self.advplk(self.iphyto,self.svol,srovol,self.vol,erovol,sovol,eovol,nexits,
self.oref,self.mxstay,self.seed,self.delts,self.phyto)
(self.phyto, snkphy) = sink(self.vol,avdepe,self.physet,self.phyto)
self.snkphy = -snkphy
if self.ZOOFG == 1: # zooplankton on; advect zooplankton
(self.zoo, self.rozoo, self.ozoo) \
= self.advplk(self.izoo,self.svol,srovol,vol,erovol,sovol,eovol,nexits,
self.oref,self.mxstay,self.seed,self.delts,self.zoo)
# advect organic nitrogen
inorn = self.iorn + pladep_orn
(self.orn,self.roorn,self.oorn) = advect (inorn, self.orn, nexits, self.svol, self.vol, srovol, erovol, sovol, eovol)
(self.orn, snkorn) = sink(self.vol, avdepe, self.refset, self.orn)
self.snkorn = -snkorn
# advect organic phosphorus
inorp = self.iorp + pladep_orp
(self.orp, self.roorp, self.oorp) = advect(inorp, self.orp, nexits, self.svol, self.vol, srovol, erovol, sovol, eovol)
(self.orp, snkorp) = sink(self.vol, avdepe, self.refset, self.orp)
self.snkorp = -snkorp
# advect total organic carbon
inorc = self.iorc + pladep_orc
(self.orc, self.roorc, self.oorc) = advect (inorc, self.orc, nexits, self.svol, self.vol, srovol, erovol, sovol, eovol)
(self.orc, snkorc) = sink(self.vol, avdepe, self.refset, self.orc)
self.snkorc = -snkorc
if avdepe > 0.17: # enough water to warrant computation of water quality reactions
if self.BALFG > 0:
if self.frrif < 1.0:
# make adjustments to average water velocity and depth for the
# portion of the reach that consists of riffle areas.
if ro < self.rifcq1: # below first cutoff flow
i= 1
elif ro < self.rifcq2: # below second cutoff flow
i= 2
elif ro < self.rifcq3: # below third cutoff flow
i= 3
else: # above third cutoff flow
i= 4
# calculate the adjusted velocity and depth for riffle sections
self.balvel = self.rifvf[i] * avvele
self.baldep = self.rifdf[i] * avdepe
else: # use full depth and velocity
self.balvel = avvele
self.baldep = avdepe
else:
self.balvel = 0.0
self.baldep = 0.0
# calculate solar radiation absorbed; solrad is the solar radiation at gage,
# corrected for location of reach; 0.97 accounts for surface reflection
# (assumed 3 per cent); cfsaex is the ratio of radiation incident to water
# surface to gage radiation values (accounts for regional differences, shading
# of water surface, etc); inlit is a measure of light intensity immediately below
# surface of reach/res and is expressed as ly/min, adjusted for fraction that is
# photosynthetically active.
inlit = 0.97 * self.cfsaex * solrad / self.delt * self.paradf
extsed = 0.0
if self.SDLTFG == 1: # estimate contribution of sediment to light extinction
extsed = self.litsed * tss
elif self.SDLTFG == 2: # equations from dssamt for estimating the extinction coefficient based on discharge and turbidity
# estimate turbidity based on linear regression on flow
turb = self.ctrbq1 * ro**self.ctrbq2
# estimate the portion of the extinction coefficient due to
# sediment based upon a system-wide regression of total
# extinction to turbidity, and then subtracting the
# base extinction coefficient
extsed = (self.cktrb1 * turb**self.cktrb2) - self.extb
if extsed < 0.0: # no effective sediment shading
extsed = 0.0
else: # sediment light extinction not considered
extsed = 0.0
# calculate contribution of phytoplankton to light extinction (self-shading)
extcla = 0.00452 * self.phyto * self.cvbcl
# calculate light available for algal growth, litrch only called here
(self.phylit, self.ballit, self.cflit) = self.litrch (inlit,self.extb,extcla,extsed,avdepe,self.baldep,self.PHYFG,self.BALFG)
#-----------------------------------------------------------
# sestonic algae growth & respiration
#-----------------------------------------------------------
if self.PHYFG == 1: # simulate phytoplankton, phyrx only called here
(po4,no3,tam,dox,self.orn,self.orp,self.orc,bod,self.phyto,self.limphy,self.pyco2,self.phycla,
dophy,bodphy,tamphy,no3phy,po4phy,phdth,phgro,ornphy,orpphy,orcphy) \
= self.phyrx(self.phylit,tw,self.talgrl,self.talgrh,self.talgrm,self.malgr,self.cmmp, \
self.cmmnp,NUTRX.TAMFG,self.AMRFG,self.NSFG,self.cmmn,self.cmmlt,self.delt60, \
self.cflit,self.alr20,self.cvbpn,self.PHFG,self.DECFG,self.cvbpc,self.paldh, \
self.naldh,self.claldh,self.aldl,self.aldh,NUTRX.anaer,self.oxald,self.alnpr, \
self.cvbo,self.refr,self.cvnrbo,self.cvpb,self.cvbcl,self.co2, \
self.nmingr,self.pmingr,self.cmingr,self.lmingr,self.nminc, \
po4,no3,tam,dox,self.orn,self.orp,self.orc,bod,self.phyto)
# compute associated fluxes
self.phydox = dophy * self.vol
self.phybod = bodphy * self.vol
self.phytam = tamphy * self.vol
self.phyno3 = no3phy * self.vol
self.phypo4 = po4phy * self.vol
self.dthphy = -phdth * self.vol
self.grophy = phgro * self.vol
self.phyorn = ornphy * self.vol
self.phyorp = orpphy * self.vol
self.phyorc = orcphy * self.vol
#-----------------------------------------------------------
# zooplankton growth & death:
#-----------------------------------------------------------
if self.ZOOFG == 1: # simulate zooplankton, zorx only called here
(dox,bod,self.zoo,self.orn,self.orp,self.orc,tam,no3,po4,zeat,self.zoco2,dozoo,bodzoo,nitzoo,po4zoo,zgro,zdth,zorn,zorp,zorc) \
= self.zorx(self.zfil20,self.tczfil,tw,self.phyto,self.mzoeat,self.zexdel,self.cvpb, \
self.zres20,self.tczres,NUTRX.anaer,self.zomass,NUTRX.TAMFG,self.refr, \
self.ZFOOD,self.zd,self.oxzd,self.cvbn,self.cvbp,self.cvbc,self.cvnrbo,self.cvbo, \
dox,bod,self.zoo,self.orn,self.orp,self.orc,tam,no3,po4)
# compute associated fluxes
self.zoodox = -dozoo * self.vol
self.zoobod = bodzoo * self.vol
if NUTRX.TAMFG != 0: # ammonia on, so nitrogen excretion goes to ammonia
self.zootam = nitzoo * self.vol
self.zoono3 = 0.0
else: # ammonia off, so nitrogen excretion goes to nitrate
self.zoono3 = nitzoo * self.vol
self.zootam = 0.0
self.zoopo4 = po4zoo * self.vol
self.zoophy = -zeat * self.vol
self.zooorn = zorn * self.vol
self.zooorp = zorp * self.vol
self.zooorc = zorc * self.vol
self.grozoo = zgro * self.vol
self.dthzoo = -zdth * self.vol
self.totzoo = self.grozoo + self.dthzoo
# update phytoplankton state variable to account for zooplankton predation
self.phyto = self.phyto - zeat
# convert phytoplankton expressed as mg biomass/l to chlorophyll a expressed as ug/l
self.phycla = self.phyto * self.cvbcl
self.totphy = self.snkphy + self.zoophy + self.dthphy + self.grophy
#-----------------------------------------------------------
# benthic algae growth & respiration
#-----------------------------------------------------------
self.limbal = zeros(self.numbal, dtype=np.int32)
if self.BALFG > 0:
bgro = zeros(self.numbal)
bdth = zeros(self.numbal)
if self.BALFG == 1: # simulate benthic algae
(po4,no3,tam,dox,self.orn,self.orp,self.orc,bod,self.benal[0],self.limbal[0],self.baco2,self.balcla[0],
dobalg,bodbal,tambal,no3bal,po4bal,bgro[0],bdth[0],ornbal,orpbal,orcbal) \
= self.balrx(self.ballit,tw,self.talgrl,self.talgrh,self.talgrm,self.malgr,self.cmmp, \
self.cmmnp,NUTRX.TAMFG,self.AMRFG,self.NSFG,self.cmmn,self.cmmlt,self.delt60, \
self.cflit,self.alr20,self.cvbpn,self.PHFG,self.DECFG,self.cvbpc,self.paldh, \
self.naldh,self.aldl,self.aldh,NUTRX.anaer,self.oxald,self.cfbalg,self.cfbalr, \
self.alnpr,self.cvbo,self.refr,self.cvnrbo,self.cvpb,self.mbal,depcor, \
self.cvbcl,self.co2,self.nmingr,self.pmingr,self.cmingr,self.lmingr,self.nminc, \
po4,no3,tam,dox,self.orn,self.orp,self.orc,bod,self.benal[0])
elif self.BALFG == 2: # simulate enhanced benthic algae equations from dssamt (!)
# then perform reactions, balrx2 only called here
(po4,no3,tam,dox,self.orn,self.orp,self.orc,bod,self.benal,self.limbal,self.baco2,self.balcla,
dobalg,bodbal,tambal,no3bal,po4bal,bgro,bdth,ornbal,orpbal,orcbal) \
= self.balrx2 (self.ballit,tw,NUTRX.TAMFG,self.NSFG,self.delt60,self.cvbpn,self.PHFG,self.DECFG, \
self.cvbpc,self.alnpr,self.cvbo,self.refr,self.cvnrbo,self.cvpb,depcor, \
self.cvbcl,co2,self.numbal,self.mbalgr,self.cmmpb,self.cmmnb, \
self.balr20,self.tcbalg,self.balvel,self.cmmv,self.BFIXFG,self.cslit,self.cmmd1, \
self.cmmd2,self.tcbalr,self.frrif,self.cremvl,self.cmmbi,binv,self.tcgraz, \
self.cslof1,self.cslof2,self.minbal,self.fravl,self.BNPFG,self.campr,self.nmingr, \
self.pmingr,self.cmingr,self.lmingr,self.nminc,self.nmaxfx,self.grores, \
po4,no3,tam,dox,self.orn,self.orp,self.orc,bod,self.benal)
#compute associated fluxes
self.baldox = dobalg * self.vol
self.balbod = bodbal * self.vol
self.baltam = tambal * self.vol
self.balno3 = no3bal * self.vol
self.balpo4 = po4bal * self.vol
self.balorn = ornbal * self.vol
self.balorp = orpbal * self.vol
self.balorc = orcbal * self.vol
self.grobal = zeros(self.numbal)
self.dthbal = zeros(self.numbal)
for i in range(self.numbal):
self.grobal[i] = bgro[i]
self.dthbal[i] = -bdth[i]
else: # not enough water in reach/res to warrant simulation of quality processes
self.phyorn = 0.0
self.balorn = 0.0
self.zooorn = 0.0
self.phyorp = 0.0
self.balorp = 0.0
self.zooorp = 0.0
self.phyorc = 0.0
self.balorc = 0.0
self.zooorc = 0.0
self.pyco2 = 0.0
self.baco2 = 0.0
self.zoco2 = 0.0
self.phydox = 0.0
self.zoodox = 0.0
self.baldox = 0.0
self.phybod = 0.0
self.zoobod = 0.0
self.balbod = 0.0
self.phytam = 0.0
self.zootam = 0.0
self.baltam = 0.0
self.phyno3 = 0.0
self.zoono3 = 0.0
self.balno3 = 0.0
self.phypo4 = 0.0
self.zoopo4 = 0.0
self.balpo4 = 0.0
if self.PHYFG == 1: # water scarcity limits phytoplankton growth
self.limphy = 1 #'WAT'
self.phycla = self.phyto * self.cvbcl
self.grophy = 0.0
self.dthphy = 0.0
self.zoophy = 0.0
self.totphy = self.snkphy
if self.BALFG > 0: # water scarcity limits benthic algae growth
limc = 1 #'WAT'
self.limbal = zeros(self.numbal, dtype=np.int32)
self.balcla = zeros(self.numbal)
self.grobal = zeros(self.numbal)
self.dthbal = zeros(self.numbal)
for i in range(self.numbal):
self.balcla[i] = self.benal[i] * self.cvbcl
self.limbal[i] = limc
if self.ZOOFG == 1: # water scarcity limits zooplankton growth
self.grozoo= 0.0
self.dthzoo= 0.0
self.totzoo= 0.0
#-----------------------------------------------------------
# store final benthic sums and fluxes
#-----------------------------------------------------------
if self.BALFG > 0:
self.tbenal = zeros(3)
self.grotba = 0.0
self.dthtba = 0.0
for i in range(self.numbal):
self.flxbal[1,i] = self.grobal[i]
self.flxbal[2,i] = self.dthbal[i]
self.flxbal[3,i] = self.grobal[i] + self.dthbal[i]
self.tbenal[1] += self.benal[i]
self.grotba += self.grobal[i]
self.dthtba += self.dthbal[i]
self.tbenal[2] = self.tbenal[1] * self.cvbcl
self.tottba = self.grotba + self.dthtba
#-----------------------------------------------------------
# compute final process fluxes for oxygen, nutrients and organics
#-----------------------------------------------------------
self.totdox = OXRX.readox + OXRX.boddox + OXRX.bendox + NUTRX.nitdox + self.phydox + self.zoodox + self.baldox
self.totbod = OXRX.decbod + OXRX.bnrbod + OXRX.snkbod + NUTRX.denbod + self.phybod + self.zoobod + self.balbod
self.totno3 = NUTRX.nitno3 + NUTRX.denno3 + NUTRX.bodno3 + self.phyno3 + self.zoono3 + self.balno3
self.tottam = NUTRX.nittam + NUTRX.volnh3 + NUTRX.bnrtam + NUTRX.bodtam + self.phytam + self.zootam + self.baltam
self.totpo4 = NUTRX.bnrpo4 + NUTRX.bodpo4 + self.phypo4 + self.zoopo4 + self.balpo4
self.totorn = self.snkorn + self.phyorn + self.zooorn + self.balorn
self.totorp = self.snkorp + self.phyorp + self.zooorp + self.balorp
self.totorc = self.snkorc + self.phyorc + self.zooorc + self.balorc
#-----------------------------------------------------------
# compute summaries of total organics, total n and p, and potbod
#-----------------------------------------------------------
# concentrations:
if self.vol > 0.0:
for i in range(1, 4):
self.lsnh4[i] = NUTRX.rsnh4[i] / self.vol
self.lspo4[i] = NUTRX.rspo4[i] / self.vol
(self.torn, self.torp, self.torc, self.potbod, self.tn, self.tp) \
= self.pksums(NUTRX,self.phyto,self.zoo,self.orn,self.orp,self.orc,
no3,tam,no2,self.lsnh4,po4,self.lspo4,bod)
else:
self.torn = -1.0e30
self.torp = -1.0e30
self.torc = -1.0e30
self.potbod = -1.0e30
self.tn = -1.0e30
self.tp = -1.0e30
(self.itorn, self.itorp, self.itorc, dumval, self.itotn, self.itotp) \
= self.pksums(NUTRX,self.iphyto,self.izoo,self.iorn,self.iorp,self.iorc,
NUTRX.ino3,NUTRX.itam,NUTRX.ino2,NUTRX.isnh4,NUTRX.ipo4,NUTRX.ispo4,OXRX.ibod)
# total outflows:
(self.rotorn, self.rotorp, self.rotorc, dumval, self.rototn, self.rototp) \
= self.pksums(NUTRX,self.rophyt,self.rozoo,self.roorn,self.roorp,self.roorc,
NUTRX.rono3,NUTRX.rotam,NUTRX.rono2,NUTRX.rosnh4,NUTRX.ropo4,NUTRX.rospo4,OXRX.robod)
# outflows by exit:
self.otorn = zeros(nexits); self.otorp = zeros(nexits); self.otorc = zeros(nexits)
self.ototn = zeros(nexits); self.ototp = zeros(nexits)
if nexits > 1:
for i in range(nexits):
(self.otorn[i], self.otorp[i], self.otorc[i], dumval, self.ototn[i], self.ototp[i]) \
= self.pksums(NUTRX,self.ophyt[i],self.ozoo[i],self.oorn[i],self.oorp[i],self.oorc[i],
NUTRX.ono3[i],NUTRX.otam[i],NUTRX.ono2[i],NUTRX.osnh4[i],NUTRX.opo4[i],NUTRX.ospo4[i],OXRX.obod[i])
#-----------------------------------------------------------
# update DO/BOD and nutrient states (for OXRX/NUTRX):
#-----------------------------------------------------------
OXRX.dox = dox
OXRX.bod = bod
NUTRX.po4 = po4
NUTRX.no3 = no3
NUTRX.no2 = no2
NUTRX.tam = tam
# redistribute TAM after algal influence:
(NUTRX.nh3,NUTRX.nh4) = NUTRX.ammion(tw, phval, tam)
self.svol = self.vol # svol is volume at start of time step, update for next time thru
return OXRX, NUTRX
@staticmethod
def advplk(iplank,vols,srovol,vol,erovol,sovol,eovol,nexits,oref,mxstay,seed,delts,plank):
''' advect plankton'''
# calculate concentration of plankton not subject to advection during interval
oflo = (srovol + erovol) / delts
if oref > 0.0 and oflo / oref <= 100.0:
stay = (mxstay - seed) * (2.0**(-oflo / oref)) + seed
else:
stay = seed
if plank > stay:
# convert stay to units of mass; this mass will be converted
# back to units of concentration based on the volume of the
# reach/res at the end of the interval
mstay = stay * vols
# determine concentration of plankton subject to advection;
# this value is passed into subroutine advect
plnkad = plank - stay
# advect plankton
(plnkad, roplk, oplk) = advect(iplank,plnkad,nexits,vols,vol,srovol,erovol,sovol,eovol)
# determine final concentration of plankton in reach/res after advection
plank = plnkad + mstay / vol if vol > 0.0 else plnkad
else: # no plankton leaves the reach/res
roplk = 0.0
oplk = zeros(nexits)
mstay = plank * vols
plank = (mstay + iplank) / vol if vol > 0.0 else -1.0e30
return plank, roplk, oplk
@staticmethod
def algro(light,po4,no3,tw,talgrl,talgrh,talgrm,malgr, cmmp,cmmnp,
TAMFG,AMRFG,tam,NSFG,cmmn,cmmlt,alr20,cflit,delt60,
nmingr,pmingr,lmingr):
''' calculate unit growth and respiration rates for algae
population; both are expressed in units of per interval'''
lim = -999
if light > lmingr: # sufficient light to support growth
if po4 > pmingr and no3 > nmingr: # sufficient nutrients to support growth
if talgrh > tw > talgrl: # water temperature allows growth
if tw < talgrm: # calculate temperature correction fraction
tcmalg = (tw - talgrl) / (talgrm - talgrl)
else:
# no temperature correction to maximum unit growth rate
# is necessary; water temperature is in the optimum
# range for phytoplankton growth
tcmalg = 1.0
# perform temperature correction to maximum unit growth
# rate; units of malgrt are per interval
malgrt = malgr * tcmalg
# calculate maximum phosphorus limited unit growth rate
grop = malgrt * po4 * no3 / ((po4 + cmmp) * (no3 + cmmnp))
# calculate the maximum nitrogen limited unit growth rate
if TAMFG: # consider influence of tam on growth rate
if AMRFG: # calculate tam retardation to nitrogen limited growth rate
malgn = malgrt - 0.757 * tam + 0.051 * no3
# check that calculated unit growth rate does not
# exceed maximum allowable growth rate
if malgn > malgrt:
malgn = malgrt
else:
# check that calculated unit growth rate is not
# less than .001 of the maximum unit growth rate;
# if it is, set the unit growth rate equal to .001
# of the maximum unit growth rate
lolim = 0.001 * malgrt
if malgn < lolim:
malgn = lolim
else: # ammonia retardation is not considered
malgn = malgrt
if NSFG: # include tam in nitrogen pool for calculation of nitrogen limited growth rate
mmn = no3 + tam
else: # tam is not included in nitrogen pool for calculation of nitrogen limited growth
mmn = no3
else: # tam is not simulated