File indexing completed on 2023-11-24 06:10:13 UTC
view on githubraw file Latest commit 15ec8028 on 2023-11-23 16:15:51 UTC
e0f9a7ba0b Matt*0001 #include "BLING_OPTIONS.h"
0002
0003
0004
0005
0006
0007
0008
0009
15ec8028f7 aver*0010
e0f9a7ba0b Matt*0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 SUBROUTINE AHINI_FOR_AT(p_alkcb, p_dictot, p_bortot, p_hini,
0079 & i, j, k, bi, bj, myIter, myThid )
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 IMPLICIT NONE
0091
0092
0093 #include "SIZE.h"
0094 #include "EEPARAMS.h"
0095 #include "BLING_VARS.h"
0096
0097
0098
0099
0100
0101 _RL p_alkcb
0102 _RL p_dictot
0103 _RL p_bortot
0104 _RL p_hini
0105 INTEGER i,j,k,bi,bj,myIter,myThid
0106
0107 #ifdef CARBONCHEM_SOLVESAPHE
0108
0109
0110
0111
0112 _RL zcar, zbor
0113 _RL zd, zsqrtd, zhmin
0114 _RL za2, za1, za0
0115
0116 IF (p_alkcb .LE. 0. _d 0) THEN
0117 p_hini = 1. _d -3
0118 ELSEIF (p_alkcb .GE. (2. _d 0*p_dictot + p_bortot)) THEN
0119 p_hini = 1. _d -10
0120 ELSE
0121 zcar = p_dictot/p_alkcb
0122 zbor = p_bortot/p_alkcb
0123
0124
0125 za2 = akb(i,j,bi,bj)*(1. _d 0 - zbor) + ak1(i,j,bi,bj)
0126 & *(1. _d 0-zcar)
0127 za1 = ak1(i,j,bi,bj)*akb(i,j,bi,bj)*(1. _d 0 - zbor - zcar)
0128 & + ak1(i,j,bi,bj)*ak2(i,j,bi,bj)*(1. _d 0 - (zcar+zcar))
0129 za0 = ak1(i,j,bi,bj)*ak2(i,j,bi,bj)*akb(i,j,bi,bj)
0130 & *(1. _d 0 - zbor - (zcar+zcar))
0131
0132
0133 zd = za2*za2 - 3. _d 0*za1
0134
0135
0136
0137 IF(zd .GT. 0. _d 0) THEN
0138
0139 zsqrtd = SQRT(zd)
0140 IF(za2 .LT. 0) THEN
0141 zhmin = (-za2 + zsqrtd)/3. _d 0
0142 ELSE
0143 zhmin = -za1/(za2 + zsqrtd)
0144 ENDIF
0145 p_hini = zhmin + SQRT(-(za0 + zhmin*(za1 + zhmin*(za2 + zhmin)))
0146 & /zsqrtd)
0147 ELSE
0148 p_hini = 1. _d -7
0149 ENDIF
0150 ENDIF
0151
0152 #endif /* CARBONCHEM_SOLVESAPHE */
0153 RETURN
0154 END
0155
0156
0157
0158
0159 SUBROUTINE ANW_INFSUP(p_dictot, p_bortot,
0160 & p_po4tot, p_siltot,
0161 & p_nh4tot, p_h2stot,
0162 & p_so4tot, p_flutot,
0163 & p_alknw_inf, p_alknw_sup,
0164 & i, j, k, bi, bj, myIter,
0165 & myThid )
0166
0167
0168
0169
0170
0171 IMPLICIT NONE
0172
0173
0174 #include "SIZE.h"
0175 #include "EEPARAMS.h"
0176 #include "BLING_VARS.h"
0177
0178
0179
0180
0181
0182 _RL p_dictot
0183 _RL p_bortot
0184 _RL p_po4tot
0185 _RL p_siltot
0186 _RL p_nh4tot
0187 _RL p_h2stot
0188 _RL p_so4tot
0189 _RL p_flutot
0190 _RL p_alknw_inf
0191 _RL p_alknw_sup
0192 INTEGER i,j,k,bi,bj,myIter,myThid
0193
0194 #ifdef CARBONCHEM_SOLVESAPHE
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206 p_alknw_inf = -p_po4tot - p_so4tot - p_flutot
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 p_alknw_sup = p_dictot + p_dictot + p_bortot
0220 & + p_po4tot + p_po4tot + p_siltot
0221 & + p_nh4tot + p_h2stot
0222
0223 #endif /* CARBONCHEM_SOLVESAPHE */
0224 RETURN
0225 END
0226
0227
0228
0229
0230 SUBROUTINE CALC_PCO2_SOLVESAPHE(
0231 I t,s,z_dictot,z_po4tot,z_siltot,z_alktot,
0232 U pHlocal,z_pco2,z_co3,
0233 I i,j,k,bi,bj,debugPrt,myIter,myThid )
0234
0235 IMPLICIT NONE
0236
0237
0238 #include "SIZE.h"
0239 #include "EEPARAMS.h"
0240 #include "BLING_VARS.h"
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
ba0b047096 Mart*0251
e0f9a7ba0b Matt*0252 _RL t, s, z_po4tot, z_siltot, z_alktot
0253 _RL z_pco2, z_dictot, pHlocal
0254 _RL z_co3
0255 INTEGER i,j,k,bi,bj
0256 LOGICAL debugPrt
0257 INTEGER myIter,myThid
0258
0259 #ifdef CARBONCHEM_SOLVESAPHE
0260
0261
0262 _RL z_h
0263 _RL z_hini
0264 _RL z_bortot
0265 _RL z_nh4tot
0266 _RL z_h2stot
0267 _RL z_so4tot
0268 _RL z_flutot
0269 _RL z_val
0270 _RL z_co2s
0271 _RL z_fco2
0272 _RL z_hco3
0273 _RL z_co2aq
0274 CHARACTER*(MAX_LEN_MBUF) msgBuf
0275
0276
0277
0278
0279
0280
0281
0282
0283 z_po4tot=z_po4tot*permil
0284 z_siltot=z_siltot*permil
0285 z_alktot=z_alktot*permil
0286 z_dictot=z_dictot*permil
0287
0288
0289 z_so4tot = st(i,j,bi,bj)
0290 z_flutot = ft(i,j,bi,bj)
0291 z_bortot = bt(i,j,bi,bj)
0292
0293 z_nh4tot = 0. _d 0
0294 z_h2stot = 0. _d 0
0295
0296 z_hini = 10. _d 0**(-1. _d 0 * pHlocal)
0297
0298 at_maxniter = 50
0299
0300 IF ( selectPHsolver.EQ.1 ) THEN
0301 #ifdef ALLOW_DEBUG
0302 IF (debugPrt) CALL DEBUG_CALL('SOLVE_AT_GENERAL',myThid)
0303 #endif
0304 CALL SOLVE_AT_GENERAL(z_alktot, z_dictot, z_bortot,
0305 & z_po4tot, z_siltot, z_nh4tot, z_h2stot,
0306 & z_so4tot, z_flutot, z_hini, z_val,
0307 & z_h,
0308 & i, j, k, bi, bj, debugPrt, myIter, myThid )
0309 ELSEIF ( selectPHsolver.EQ.2 ) THEN
0310 #ifdef ALLOW_DEBUG
0311 IF (debugPrt) CALL DEBUG_CALL('SOLVE_AT_GENERAL_SEC',myThid)
0312 #endif
0313 CALL SOLVE_AT_GENERAL_SEC(z_alktot, z_dictot, z_bortot,
0314 & z_po4tot, z_siltot, z_nh4tot, z_h2stot,
0315 & z_so4tot, z_flutot, z_hini, z_val,
0316 & z_h,
0317 & i, j, k, bi, bj, debugPrt, myIter, myThid )
0318 ELSEIF ( selectPHsolver.EQ.3 ) THEN
0319 #ifdef ALLOW_DEBUG
0320 IF (debugPrt) CALL DEBUG_CALL('SOLVE_AT_FAST',myThid)
0321 #endif
0322 CALL SOLVE_AT_FAST(z_alktot, z_dictot, z_bortot,
0323 & z_po4tot, z_siltot, z_nh4tot, z_h2stot,
0324 & z_so4tot, z_flutot, z_hini, z_val,
0325 & z_h,
0326 & i, j, k, bi, bj, debugPrt, myIter, myThid )
0327 ENDIF
0328
0329
0330 IF ( z_h .LT. 0. _d 0 ) THEN
0331 WRITE(msgBuf,'(A,A,A)')
0332 & 'S/R CALC_PCO2_SOLVESAPHE:',
0333 & ' H+ ion concentration less than 0',
0334 & ' Divergence or too many iterations'
0335 CALL PRINT_ERROR( msgBuf, myThid )
0336 STOP 'ABNORMAL END: S/R CALC_PCO2_SOLVESAPHE'
0337 ENDIF
0338
0339
0340 phlocal = -log10(z_h)
0341
0342
0343 z_co2s = z_dictot/
0344 & (1.0 _d 0 + (ak1(i,j,bi,bj)/z_h)
0345 & + (ak1(i,j,bi,bj)*ak2(i,j,bi,bj)/(z_h*z_h)))
0346
0347
0348 z_hco3 = ak1(i,j,bi,bj)*z_dictot /
0349 & (z_h*z_h + ak1(i,j,bi,bj)*z_h
0350 & + ak1(i,j,bi,bj)*ak2(i,j,bi,bj))
0351 z_co3 = ak1(i,j,bi,bj)*ak2(i,j,bi,bj)*z_dictot /
0352 & (z_h*z_h + ak1(i,j,bi,bj)*z_h
0353 & + ak1(i,j,bi,bj)*ak2(i,j,bi,bj))
0354
0355
0356
0357 #ifdef WATERVAP_BUG
0358 z_pco2 = z_co2s/ff(i,j,bi,bj)
0359 #else
0360
0361 z_fco2 = z_co2s/ak0(i,j,bi,bj)
0362 z_pco2 = z_fco2/fugf(i,j,bi,bj)
0363 #endif
0364
0365
0366
0367 z_po4tot = z_po4tot/permil
0368 z_siltot = z_siltot/permil
0369 z_alktot = z_alktot/permil
0370 z_dictot = z_dictot/permil
0371 z_hco3 = z_hco3/permil
0372 z_co3 = z_co3/permil
0373 z_co2aq = z_co2s/permil
0374
0375 #endif /* CARBONCHEM_SOLVESAPHE */
0376 RETURN
0377 END
0378
0379
0380
0381
0382 SUBROUTINE DIC_COEFFS_SURF(
0383 & ttemp,stemp,
0384 & bi,bj,iMin,iMax,jMin,jMax,myThid)
0385
0386
0387
0388
0389 IMPLICIT NONE
0390
0391
0392 #include "SIZE.h"
0393 #include "EEPARAMS.h"
0394 #include "PARAMS.h"
0395 #include "GRID.h"
0396 #include "BLING_VARS.h"
0397
0398 _RL ttemp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
0399 _RL stemp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
0400 INTEGER bi,bj,iMin,iMax,jMin,jMax,myThid
0401
0402 #ifdef CARBONCHEM_SOLVESAPHE
0403
0404
0405 INTEGER i, j
0406 _RL t
0407 _RL s
0408 _RL t_k
0409 _RL t_k_o_100
0410 _RL t_k_o_100_2
0411 _RL dlog_t_k
0412 _RL inv_t_k
0413 _RL ion_st, is_2, sqrtis
0414 _RL s_2, sqrts, s_15, scl, s35
0415 _RL log_fw2sw
0416 _RL B, B1
0417 _RL delta
0418 _RL P1atm
0419 _RL RT
0420 _RL Rgas
0421
0422 _RL total2free
0423 _RL free2sw
0424 _RL total2sw
0425
0426 do i=imin,imax
0427 do j=jmin,jmax
0428 if (hFacC(i,j,1,bi,bj).gt.0. _d 0) then
0429 t = ttemp(i,j)
0430 s = stemp(i,j)
0431
0432
0433 t_k = 273.15 _d 0 + t
0434 t_k_o_100 = t_k/100. _d 0
0435 t_k_o_100_2 = t_k_o_100*t_k_o_100
0436 inv_t_k=1.0 _d 0/t_k
0437 dlog_t_k=LOG(t_k)
0438
0439 ion_st=19.924 _d 0*s/(1000. _d 0-1.005 _d 0*s)
0440 is_2=ion_st*ion_st
0441 sqrtis=sqrt(ion_st)
0442
0443 s_2 = s*s
0444 sqrts=sqrt(s)
0445 s_15 = s*sqrts
0446 scl = s/1.80655 _d 0
0447 s35 = s/35. _d 0
0448
0449 log_fw2sw = LOG( 1. _d 0 - 0.001005 _d 0*s )
0450
0451 IF ( selectBTconst.EQ.1 ) THEN
0452
0453
0454
0455
0456
0457
0458 bt(i,j,bi,bj) = 0.000232 _d 0* scl/10.811 _d 0
0459 ELSEIF ( selectBTconst.EQ.2 ) THEN
0460
0461
0462
0463
0464
0465 bt(i,j,bi,bj) = 0.0002414 _d 0* scl/10.811 _d 0
0466 ENDIF
0467
0468 IF ( selectFTconst.EQ.1 ) THEN
0469
0470
0471
0472
0473
0474 ft(i,j,bi,bj) = 0.000067 _d 0 * scl/18.9984 _d 0
0475 ELSEIF ( selectFTconst.EQ.2 ) THEN
0476
0477
0478
0479
0480
0481 ft(i,j,bi,bj) = 0.000068 _d 0*(s35)
0482 ENDIF
0483
0484
0485
0486
0487
0488
0489 st(i,j,bi,bj) = 0.14 _d 0 * scl/96.062 _d 0
0490
0491
0492
0493
0494
0495
0496 cat(i,j,bi,bj) = 0.010282 _d 0*(s35)
0497
0498
0499
0500
0501
0502
0503 ak0(i,j,bi,bj) = EXP( 93.4517 _d 0/t_k_o_100 - 60.2409 _d 0
0504 & + 23.3585 _d 0*LOG(t_k_o_100)
0505 & + s * (0.023517 _d 0 - 0.023656 _d 0*t_k_o_100
0506 & + 0.0047036 _d 0*t_k_o_100_2))
0507
0508
0509
0510
0511
0512
0513 ff(i,j,bi,bj) = exp(-162.8301 _d 0 + 218.2968 _d 0/t_k_o_100
0514 & + 90.9241 _d 0*log(t_k_o_100) - 1.47696 _d 0*t_k_o_100_2
0515 & + s * (.025695 _d 0 - .025225 _d 0*t_k_o_100
0516 & + 0.0049867 _d 0*t_k_o_100_2))
0517
0518
0519
0520
0521
0522 P1atm = 1.01325 _d 0
0523 Rgas = 83.1451 _d 0
0524 RT = Rgas*t_k
0525 delta = (57.7 _d 0 - 0.118 _d 0*t_k)
0526 B1 = -1636.75 _d 0 + 12.0408 _d 0*t_k - 0.0327957 _d 0*t_k*t_k
0527 B = B1 + 3.16528 _d 0*t_k*t_k*t_k*(0.00001 _d 0)
0528
0529
0530
0531 fugf(i,j,bi,bj) = exp( (B+2. _d 0*delta) * P1atm / RT)
0532 IF ( selectK1K2const.EQ.1 ) THEN
0533
0534
0535
0536
0537
0538
0539 ak1(i,j,bi,bj)=10.**(-1. _d 0*(3670.7 _d 0*inv_t_k
0540 & - 62.008 _d 0 + 9.7944 _d 0*dlog_t_k
0541 & - 0.0118 _d 0 * s + 0.000116 _d 0*s_2))
0542
0543
0544
0545
0546
0547 ak2(i,j,bi,bj)=10.**(-1. _d 0*(1394.7 _d 0*inv_t_k
0548 & + 4.777 _d 0 - 0.0184 _d 0*s + 0.000118 _d 0*s_2))
0549 ELSEIF ( selectK1K2const.EQ.2 ) THEN
0550
0551
0552
0553
0554
0555
0556 ak1(i,j,bi,bj) = EXP(-2307.1255 _d 0*inv_t_k + 2.83655 _d 0
0557 & - 1.5529413 _d 0*dlog_t_k
0558 & + (-4.0484 _d 0*inv_t_k - 0.20760841)*sqrts
0559 & + 0.08468345*s
0560 & - 0.00654208*s_15
0561 & + log_fw2sw )
0562
0563
0564
0565
0566
0567 ak2(i,j,bi,bj) = EXP(-3351.6106 _d 0*inv_t_k - 9.226508 _d 0
0568 & - 0.2005743 _d 0*dlog_t_k
0569 & + ( -23.9722 _d 0*inv_t_k - 0.106901773 _d 0)*sqrts
0570 & + 0.1130822*s - 0.00846934 _d 0*s_15
0571 & + log_fw2sw )
0572 ELSEIF ( selectK1K2const.EQ.3 ) THEN
0573
0574
0575
0576
0577
0578 ak1(i,j,bi,bj) = EXP(2.18867 _d 0 - 2275.0360 _d 0*inv_t_k
0579 & - 1.468591 _d 0*dlog_t_k
0580 & + ( -0.138681 _d 0 - 9.33291 _d 0*inv_t_k)*sqrts
0581 & + 0.0726483 _d 0*s - 0.00574938 _d 0*s_15)
0582
0583
0584
0585
0586 ak2(i,j,bi,bj) = EXP(-0.84226 _d 0 - 3741.1288 _d 0*inv_t_k
0587 & - 1.437139 _d 0*dlog_t_k
0588 & + (-0.128417 _d 0 - 24.41239 _d 0*inv_t_k)*sqrts
0589 & + 0.1195308 _d 0*s - 0.00912840 _d 0*s_15)
0590 ELSEIF ( selectK1K2const.EQ.4 ) THEN
0591
0592
0593
0594
0595
0596
0597 ak1(i,j,bi,bj) = 10. _d 0**( 61.2172 _d 0
0598 & - 3633.86 _d 0*inv_t_k - 9.67770 _d 0*dlog_t_k
0599 & + s*(0.011555 - s*0.0001152 _d 0))
0600
0601
0602
0603
0604
0605 ak2(i,j,bi,bj) = 10. _d 0**(-25.9290 _d 0
0606 & - 471.78 _d 0*inv_t_k + 3.16967 _d 0*dlog_t_k
0607 & + s*(0.01781 _d 0 - s*0.0001122 _d 0))
0608 ELSEIF ( selectK1K2const.EQ.5 ) THEN
0609
0610
0611
0612
0613
0614
0615
0616 ak1(i,j,bi,bj) = 10.0 _d 0**(-1*(6320.813 _d 0*inv_t_k
0617 & + 19.568224 _d 0*dlog_t_k -126.34048 _d 0
0618 & + 13.4038 _d 0*sqrts + 0.03206 _d 0*s - (5.242 _d -5)*s_2
0619 & + (-530.659 _d 0*sqrts - 5.8210 _d 0*s)*inv_t_k
0620 & -2.0664 _d 0*sqrts*dlog_t_k))
0621
0622
0623
0624
0625
0626
0627 ak2(i,j,bi,bj) = 10.0 _d 0**(-1*(5143.692 _d 0*inv_t_k
0628 & + 14.613358 _d 0*dlog_t_k -90.18333 _d 0
0629 & + 21.3728 _d 0*sqrts + 0.1218 _d 0*s - (3.688 _d -4)*s_2
0630 & + (-788.289 _d 0*sqrts - 19.189 _d 0*s)*inv_t_k
0631 & -3.374 _d 0*sqrts*dlog_t_k))
0632 ELSEIF ( selectK1K2const.EQ.6 ) THEN
0633
0634
0635
0636
0637
0638
0639
0640 ak1(i,j,bi,bj) = 10.0 _d 0**(-1.*(6320.813 _d 0*inv_t_k
0641 & + 19.568224 _d 0*dlog_t_k -126.34048 _d 0
0642 & + 13.409160 _d 0*sqrts + 0.031646 _d 0*s - (5.1895 _d -5)*s_2
0643 & + (-531.3642 _d 0*sqrts - 5.713 _d 0*s)*inv_t_k
0644 & -2.0669166 _d 0*sqrts*dlog_t_k))
0645
0646
0647
0648
0649
0650
0651 ak2(i,j,bi,bj) = 10.0 _d 0**(-1.*
0652 & ( 5143.692 _d 0*inv_t_k + 14.613358 _d 0*dlog_t_k
0653 & - 90.18333 _d 0 + 21.225890 _d 0*sqrts + 0.12450870 _d 0*s
0654 & - (3.7243 _d -4)*s_2
0655 & + (-779.3444 _d 0*sqrts - 19.91739 _d 0*s)*inv_t_k
0656 & - 3.3534679 _d 0*sqrts*dlog_t_k ) )
0657 ENDIF /* selectK1K2const */
0658
0659
0660
0661
0662
0663 akb(i,j,bi,bj) = EXP(( -8966.90 _d 0 - 2890.53 _d 0*sqrts
0664 & -77.942 _d 0*s + 1.728 _d 0*s_15 - 0.0996 _d 0*s_2 )*inv_t_k
0665 & + (148.0248 _d 0 + 137.1942 _d 0*sqrts + 1.62142 _d 0*s)
0666 & + (-24.4344 _d 0 - 25.085 _d 0*sqrts - 0.2474 _d 0*s)*
0667 & dlog_t_k + 0.053105 _d 0*sqrts*t_k )
0668
0669
0670
0671
0672
0673 ak1p(i,j,bi,bj) = EXP(115.54 _d 0
0674 & - 4576.752 _d 0*inv_t_k - 18.453 _d 0*dlog_t_k
0675 & + ( 0.69171 _d 0 - 106.736 _d 0*inv_t_k)*sqrts
0676 & + (-0.01844 _d 0 - 0.65643 _d 0*inv_t_k)*s)
0677
0678
0679
0680
0681
0682 ak2p(i,j,bi,bj) = EXP( 172.1033 _d 0
0683 & - 8814.715 _d 0*inv_t_k
0684 & - 27.927 _d 0*dlog_t_k
0685 & + ( 1.3566 _d 0 - 160.340 _d 0*inv_t_k)*sqrts
0686 & + (-0.05778 _d 0 + 0.37335 _d 0*inv_t_k)*s)
0687
0688
0689
0690
0691
0692 ak3p(i,j,bi,bj) = EXP(-18.126 _d 0 - 3070.75 _d 0*inv_t_k
0693 & + ( 2.81197 _d 0 + 17.27039 _d 0*inv_t_k)*sqrts
0694 & + (-0.09984 _d 0 - 44.99486 _d 0*inv_t_k)*s)
0695
0696
0697
0698
0699
0700
0701 aksi(i,j,bi,bj) = EXP(
0702 & 117.40 _d 0 - 8904.2 _d 0*inv_t_k
0703 & - 19.334 _d 0 * dlog_t_k
0704 & + ( 3.5913 _d 0 - 458.79 _d 0*inv_t_k) * sqrtis
0705 & + (-1.5998 _d 0 + 188.74 _d 0*inv_t_k) * ion_st
0706 & + (0.07871 _d 0 - 12.1652 _d 0*inv_t_k) * ion_st*ion_st
0707 & + log_fw2sw )
0708
0709
0710
0711
0712
0713 akn(i,j,bi,bj) = EXP(-0.25444 _d 0 - 6285.33 _d 0*inv_t_k
0714 & + 0.0001635 _d 0 * t_k
0715 & + ( 0.46532 _d 0 - 123.7184 _d 0*inv_t_k)*sqrts
0716 & + (-0.01992 _d 0 + 3.17556 _d 0*inv_t_k)*s)
0717
0718
0719
0720
0721
0722
0723
0724
0725
0726
0727 akhs(i,j,bi,bj) = EXP( 225.838 _d 0 - 13275.3 _d 0*inv_t_k
0728 & - 34.6435 _d 0 * dlog_t_k
0729 & + 0.3449 _d 0*sqrts - 0.0274 _d 0*s)
0730
0731
0732
0733
0734
0735 aks(i,j,bi,bj) = EXP(141.328 _d 0
0736 & - 4276.1 _d 0*inv_t_k - 23.093 _d 0*dlog_t_k
0737 & + ( 324.57 _d 0 - 13856. _d 0*inv_t_k
0738 & - 47.986 _d 0*dlog_t_k) * sqrtis
0739 & + (-771.54 _d 0 + 35474. _d 0*inv_t_k
0740 & + 114.723 _d 0*dlog_t_k) * ion_st
0741 & - 2698. _d 0*inv_t_k*ion_st**1.5 _d 0
0742 & + 1776. _d 0*inv_t_k*ion_st*ion_st
0743 & + log_fw2sw )
0744 IF ( selectHFconst.EQ.1 ) THEN
0745
0746
0747
0748
0749
0750
0751
0752 akf(i,j,bi,bj) = EXP(1590.2 _d 0*inv_t_k - 12.641 _d 0
0753 & + 1.525 _d 0*sqrtis
0754 & + log_fw2sw )
0755 ELSEIF ( selectHFconst.EQ.2 ) THEN
0756
0757
0758
0759
0760
0761 akf(i,j,bi,bj) = EXP( 874. _d 0*inv_t_k - 9.68 _d 0
0762 & + 0.111 _d 0*sqrts )
0763 ENDIF
0764
0765
0766
0767
0768 akw(i,j,bi,bj) = EXP(148.9802 _d 0 - 13847.26 _d 0*inv_t_k
0769 & - 23.6521 _d 0*dlog_t_k
0770 & + (-5.977 _d 0 + 118.67 _d 0*inv_t_k
0771 & + 1.0495 _d 0*dlog_t_k)*sqrts
0772 & - 0.01615 _d 0*s )
0773
0774
0775 total2free = 1. _d 0/
0776 & (1. _d 0 + st(i,j,bi,bj)/aks(i,j,bi,bj))
0777 free2sw = 1. _d 0
0778 & + (st(i,j,bi,bj)/ aks(i,j,bi,bj))
0779 & + (ft(i,j,bi,bj)/(akf(i,j,bi,bj)*total2free))
0780 total2sw = total2free * free2sw
0781 aphscale(i,j,bi,bj) = 1. _d 0 + st(i,j,bi,bj)/aks(i,j,bi,bj)
0782 IF ( selectK1K2const.NE.2 .AND. selectK1K2const.NE.4 ) THEN
0783
0784 ak1(i,j,bi,bj) = ak1(i,j,bi,bj)/total2sw
0785 ak2(i,j,bi,bj) = ak2(i,j,bi,bj)/total2sw
0786 ENDIF
0787 ak1p(i,j,bi,bj) = ak1p(i,j,bi,bj)/total2sw
0788 ak2p(i,j,bi,bj) = ak2p(i,j,bi,bj)/total2sw
0789 ak3p(i,j,bi,bj) = ak3p(i,j,bi,bj)/total2sw
0790 aksi(i,j,bi,bj) = aksi(i,j,bi,bj)/total2sw
0791 akn (i,j,bi,bj) = akn (i,j,bi,bj)/total2sw
0792 akhs(i,j,bi,bj) = akhs(i,j,bi,bj)/total2sw
0793 aks (i,j,bi,bj) = aks (i,j,bi,bj)/total2free
0794 IF ( selectHFconst.EQ.1 ) THEN
0795 akf (i,j,bi,bj) = akf (i,j,bi,bj)/total2free
0796 ENDIF
0797 akw (i,j,bi,bj) = akw (i,j,bi,bj)/total2free
0798
0799
0800
0801
0802
0803
0804 Ksp_TP_Calc(i,j,bi,bj) = 10. _d 0**(-171.9065 _d 0
0805 & - 0.077993 _d 0*t_k
15ec8028f7 aver*0806 & + 2839.319 _d 0*inv_t_k + 71.595 _d 0*LOG10(t_k)
e0f9a7ba0b Matt*0807 & + ( -0.77712 _d 0 + 0.0028426 _d 0*t_k
0808 & + 178.34 _d 0*inv_t_k)*sqrts
0809 & - 0.07711 _d 0*s + 0.0041249 _d 0*s_15)
0810
0811
0812
0813
0814
0815
0816 Ksp_TP_Arag(i,j,bi,bj) = 10. _d 0**(-171.945 _d 0
0817 & - 0.077993 _d 0*t_k
15ec8028f7 aver*0818 & + 2903.293 _d 0*inv_t_k + 71.595 _d 0*LOG10(t_k)
e0f9a7ba0b Matt*0819 & + ( -0.068393 _d 0 + 0.0017276 _d 0*t_k
0820 & + 88.135 _d 0*inv_t_k)*sqrts
0821 & - 0.10018 _d 0*s + 0.0059415 _d 0*s_15)
0822 else
0823 bt(i,j,bi,bj) = 0. _d 0
0824 st(i,j,bi,bj) = 0. _d 0
0825 ft(i,j,bi,bj) = 0. _d 0
0826 cat(i,j,bi,bj) = 0. _d 0
0827 fugf(i,j,bi,bj)= 0. _d 0
0828 ff(i,j,bi,bj) = 0. _d 0
0829 ak0(i,j,bi,bj) = 0. _d 0
0830 ak1(i,j,bi,bj) = 0. _d 0
0831 ak2(i,j,bi,bj) = 0. _d 0
0832 akb(i,j,bi,bj) = 0. _d 0
0833 ak1p(i,j,bi,bj)= 0. _d 0
0834 ak2p(i,j,bi,bj)= 0. _d 0
0835 ak3p(i,j,bi,bj)= 0. _d 0
0836 aksi(i,j,bi,bj)= 0. _d 0
0837 akw(i,j,bi,bj) = 0. _d 0
0838 aks(i,j,bi,bj) = 0. _d 0
0839 akf(i,j,bi,bj) = 0. _d 0
0840 akn(i,j,bi,bj) = 0. _d 0
0841 akhs(i,j,bi,bj)= 0. _d 0
0842 Ksp_TP_Calc(i,j,bi,bj) = 0. _d 0
0843 Ksp_TP_Arag(i,j,bi,bj) = 0. _d 0
0844 aphscale(i,j,bi,bj) = 0. _d 0
0845 endif
0846 end do
0847 end do
0848 #endif /* CARBONCHEM_SOLVESAPHE */
0849 RETURN
0850 END
0851
0852
0853
0854 SUBROUTINE DIC_COEFFS_DEEP(
0855 & ttemp,stemp,
0856 & bi,bj,iMin,iMax,jMin,jMax,
0857 & Klevel,myThid)
0858
0859
0860
0861 IMPLICIT NONE
0862
0863 #include "SIZE.h"
0864 #include "EEPARAMS.h"
0865 #include "PARAMS.h"
0866 #include "GRID.h"
0867 #include "BLING_VARS.h"
0868 _RL ttemp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
0869 _RL stemp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
0870 INTEGER bi,bj,iMin,iMax,jMin,jMax,Klevel,myThid
0871 #ifdef CARBONCHEM_SOLVESAPHE
0872
0873 INTEGER i, j, k
0874 _RL bdepth
0875 _RL cdepth
0876 _RL pressc
0877 _RL t
0878 _RL s
0879 _RL zds
0880 _RL t_k
0881 _RL t_k_o_100
0882 _RL t_k_o_100_2
0883 _RL dlog_t_k
0884 _RL sqrtis
0885 _RL sqrts
0886 _RL s_2
0887 _RL s_15
0888 _RL inv_t_k
0889 _RL ion_st
0890 _RL is_2
0891 _RL scl
0892 _RL zrt
0893 _RL B1
0894 _RL B
0895 _RL delta
0896 _RL Pzatm
0897 _RL zdvi
0898 _RL zdki
0899 _RL pfac
0900
0901 _RL total2free_surf
0902 _RL free2sw_surf
0903 _RL total2sw_surf
0904 _RL total2free
0905 _RL free2sw
0906 _RL total2sw
0907
0908
0909
0910
0911
0912
0913 bdepth = 0. _d 0
0914 cdepth = 0. _d 0
0915 pressc = 1. _d 0
0916 do k = 1,Klevel
0917 cdepth = bdepth + 0.5 _d 0*drF(k)
0918 bdepth = bdepth + drF(k)
0919 pressc = 1. _d 0 + 0.1 _d 0*cdepth
0920 end do
0921
0922
0923
0924 do i=imin,imax
0925 do j=jmin,jmax
0926 if (hFacC(i,j,Klevel,bi,bj).gt.0. _d 0) then
0927 t = ttemp(i,j)
0928 s = stemp(i,j)
0929
0930
0931 t_k = 273.15 _d 0 + t
0932 zrt= 83.14472 _d 0 * t_k
0933 t_k_o_100 = t_k/100. _d 0
0934 t_k_o_100_2=t_k_o_100*t_k_o_100
0935 inv_t_k=1.0 _d 0/t_k
0936 dlog_t_k=log(t_k)
0937
0938 ion_st=19.924 _d 0*s/(1000. _d 0-1.005 _d 0*s)
0939 is_2=ion_st*ion_st
0940 sqrtis=sqrt(ion_st)
0941
0942 s_2=s*s
0943 sqrts=sqrt(s)
0944 s_15=s**1.5 _d 0
0945 scl=s/1.80655 _d 0
0946 zds = s - 34.8 _d 0
0947 total2free_surf = 1. _d 0/
0948 & (1. _d 0 + st(i,j,bi,bj)/aks(i,j,bi,bj))
0949 free2sw_surf = 1. _d 0
0950 & + st(i,j,bi,bj)/ aks(i,j,bi,bj)
0951 & + ft(i,j,bi,bj)/(akf(i,j,bi,bj)*total2free_surf)
0952 total2sw_surf = total2free_surf * free2sw_surf
0953
0954
0955
0956
0957
0958 Pzatm = 1.01325 _d 0+pressc
0959 delta = (57.7 _d 0 - 0.118 _d 0*t_k)
0960 B1 = -1636.75 _d 0 + 12.0408 _d 0*t_k -0.0327957 _d 0*t_k*t_k
0961 B = B1 + 3.16528 _d 0*t_k*t_k*t_k*(0.00001 _d 0)
0962
0963
0964 fugf(i,j,bi,bj) = exp( (B+2. _d 0*delta) * Pzatm / zrt)
0965
0966
0967
0968
0969 zdvi = -18.03 _d 0 + t*(0.0466 _d 0 + t*0.316 _d -3)
0970 zdki = ( -4.53 _d 0 + t*0.0900 _d 0)*1. _d -3
0971 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
0972 aks(i,j,bi,bj) = total2free_surf*aks(i,j,bi,bj) * exp(pfac)
0973
0974 total2free = 1. _d 0/
0975 & (1. _d 0 + st(i,j,bi,bj)/aks(i,j,bi,bj))
0976
0977
0978 free2sw = 1. _d 0
0979 & + st(i,j,bi,bj)/ aks(i,j,bi,bj)
0980
0981 aks(i,j,bi,bj) = aks(i,j,bi,bj)/total2free
0982
0983
0984
0985
0986 zdvi = -9.78 _d 0 + t*(-0.0090 _d 0 - t*0.942 _d -3)
0987 zdki = ( -3.91 _d 0 + t*0.054 _d 0)*1. _d -3
0988 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
0989 akf(i,j,bi,bj) = total2free_surf*akf(i,j,bi,bj) * exp(pfac)
0990
0991 free2sw = free2sw
0992 & + ft(i,j,bi,bj)/akf(i,j,bi,bj)
0993 total2sw = total2free * free2sw
0994
0995 akf(i,j,bi,bj) = akf(i,j,bi,bj)/total2free
0996
0997
0998
0999
1000 zdvi = -25.50 _d 0 -0.151 _d 0*zds + 0.1271 _d 0*t
1001 zdki = ( -3.08 _d 0 -0.578 _d 0*zds + 0.0877 _d 0*t)*1. _d -3
1002 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1003 ak1(i,j,bi,bj) = (total2free_surf*ak1(i,j,bi,bj)
1004 & * exp(pfac))/total2sw
1005
1006
1007
1008
1009 zdvi = -15.82 _d 0 + 0.321 _d 0*zds - 0.0219 _d 0*t
1010 zdki = ( 1.13 _d 0 - 0.314 _d 0*zds - 0.1475 _d 0*t)*1. _d -3
1011 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1012 ak2(i,j,bi,bj) = (total2free_surf*ak2(i,j,bi,bj)
1013 & * exp(pfac))/total2sw
1014
1015
1016
1017
1018 zdvi = -29.48 _d 0 + 0.295 _d 0*zds + 0.1622 _d 0*t
1019 & - 0.002608 _d 0*t*t
1020 zdki = (-2.84 _d 0 + 0.354 _d 0*zds)*1. _d -3
1021 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1022 akb(i,j,bi,bj) = (total2free_surf*akb(i,j,bi,bj)
1023 & * exp(pfac))/total2sw
1024
1025
1026
1027
1028 zdvi = -20.02 _d 0 + 0.1119 _d 0*t - 0.1409 _d -2*t*t
1029 zdki = ( -5.13 _d 0 + 0.0794 _d 0*t)*1. _d -3
1030 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1031 akw(i,j,bi,bj) = (total2free_surf*akw(i,j,bi,bj)
1032 & * exp(pfac))/total2sw
1033
1034
1035
1036
1037
1038 zdvi = -14.51 _d 0 + 0.1211 _d 0*t - 0.321 _d -3*t*t
1039 zdki = ( -2.67 _d 0 + 0.0427 _d 0*t)*1. _d -3
1040 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1041 ak1p(i,j,bi,bj) = (total2free_surf*ak1p(i,j,bi,bj)
1042 & * exp(pfac))/total2sw
1043
1044
1045
1046
1047
1048 zdvi = -23.12 _d 0 + 0.1758 _d 0*t -2.647 _d -3*t*t
1049 zdki = ( -5.15 _d 0 + 0.09 _d 0*t)*1. _d -3
1050 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1051 ak2p(i,j,bi,bj) = (total2free_surf*ak2p(i,j,bi,bj)
1052 & * exp(pfac))/total2sw
1053
1054
1055
1056
1057
1058 zdvi = -26.57 _d 0 + 0.2020 _d 0*t -3.042 _d -3*t*t
1059 zdki = ( -4.08 _d 0 + 0.0714 _d 0*t)*1. _d -3
1060 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1061 ak3p(i,j,bi,bj) = (total2free_surf*ak3p(i,j,bi,bj)
1062 & * exp(pfac))/total2sw
1063
1064
1065
1066
1067
1068
1069 zdvi = -29.48 _d 0 + 0.295 _d 0*zds + 0.1622 _d 0*t
1070 & - 0.002608 _d 0*t*t
1071 zdki = (-2.84 _d 0 + 0.354 _d 0*zds)*1. _d -3
1072 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1073 aksi(i,j,bi,bj) = (total2free_surf*aksi(i,j,bi,bj)
1074 & * exp(pfac))/total2sw
1075
1076
1077
1078
1079
1080 zdvi = -14.80 _d 0 + t*(0.0020 _d 0 - t*0.400 _d -3)
1081 zdki = ( 2.89 _d 0 + t*0.054 _d 0)*1. _d -3
1082 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1083 akhs(i,j,bi,bj) = (total2free_surf*akhs(i,j,bi,bj)
1084 & * exp(pfac))/total2sw
1085
1086
1087
1088
1089
1090 zdvi = -26.43 _d 0 + t*(0.0889 _d 0 - t*0.905 _d -3)
1091 zdki = ( -5.03 _d 0 + t*0.0814 _d 0)*1. _d -3
1092 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1093 akn(i,j,bi,bj) = (total2free_surf*akn(i,j,bi,bj)
1094 & * exp(pfac))/total2sw
1095
1096
1097
1098
1099
1100 zdvi = -48.76 _d 0 + 0.5304 _d 0*t
1101 zdki = (-11.76 _d 0 + 0.3692 _d 0*t)*1. _d -3
1102 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1103 Ksp_TP_Calc(i,j,bi,bj) = Ksp_TP_Calc(i,j,bi,bj) * exp(pfac)
1104
1105
1106
1107
1108
1109 zdvi = -48.76 _d 0 + 0.5304 _d 0*t + 2.8 _d 0
1110 zdki = (-11.76 _d 0 + 0.3692 _d 0*t)*1. _d -3
1111 pfac = (-zdvi + zdki*pressc/2. _d 0)*pressc/zrt
1112 Ksp_TP_Arag(i,j,bi,bj) = Ksp_TP_Arag(i,j,bi,bj) * exp(pfac)
1113 else
1114 bt(i,j,bi,bj) = 0. _d 0
1115 st(i,j,bi,bj) = 0. _d 0
1116 ft(i,j,bi,bj) = 0. _d 0
1117 cat(i,j,bi,bj) = 0. _d 0
1118 fugf(i,j,bi,bj)= 0. _d 0
1119 ff(i,j,bi,bj) = 0. _d 0
1120 ak0(i,j,bi,bj) = 0. _d 0
1121 ak1(i,j,bi,bj) = 0. _d 0
1122 ak2(i,j,bi,bj) = 0. _d 0
1123 akb(i,j,bi,bj) = 0. _d 0
1124 ak1p(i,j,bi,bj)= 0. _d 0
1125 ak2p(i,j,bi,bj)= 0. _d 0
1126 ak3p(i,j,bi,bj)= 0. _d 0
1127 aksi(i,j,bi,bj)= 0. _d 0
1128 akw(i,j,bi,bj) = 0. _d 0
1129 aks(i,j,bi,bj) = 0. _d 0
1130 akf(i,j,bi,bj) = 0. _d 0
1131 akn(i,j,bi,bj) = 0. _d 0
1132 akhs(i,j,bi,bj)= 0. _d 0
1133 Ksp_TP_Calc(i,j,bi,bj) = 0. _d 0
1134 Ksp_TP_Arag(i,j,bi,bj) = 0. _d 0
1135 aphscale(i,j,bi,bj) = 0. _d 0
1136 endif
1137 enddo
1138 enddo
1139 #endif /* CARBONCHEM_SOLVESAPHE */
1140
1141 RETURN
1142 END
1143
1144
1145
1146
1147 SUBROUTINE EQUATION_AT(p_alktot, p_h, p_dictot,
1148 & p_bortot, p_po4tot, p_siltot,
1149 & p_nh4tot, p_h2stot, p_so4tot,
1150 & p_flutot, p_eqn , p_deriveqn,
1151 & i, j, k, bi, bj, myIter,
1152 & myThid )
1153
1154 IMPLICIT NONE
1155
1156
1157 #include "SIZE.h"
1158 #include "EEPARAMS.h"
1159 #include "BLING_VARS.h"
1160
1161
1162
1163
1164
1165 _RL p_alktot
1166 _RL p_h
1167 _RL p_dictot
1168 _RL p_bortot
1169 _RL p_po4tot
1170 _RL p_siltot
1171 _RL p_nh4tot
1172 _RL p_h2stot
1173 _RL p_so4tot
1174 _RL p_flutot
1175 _RL p_deriveqn
1176 _RL p_eqn
1177 INTEGER i,j,k,bi,bj,myIter,myThid
1178
1179 #ifdef CARBONCHEM_SOLVESAPHE
1180
1181
1182
1183
1184
1185 _RL znumer_dic, zdnumer_dic, zdenom_dic, zalk_dic, zdalk_dic
1186 _RL znumer_bor, zdnumer_bor, zdenom_bor, zalk_bor, zdalk_bor
1187 _RL znumer_po4, zdnumer_po4, zdenom_po4, zalk_po4, zdalk_po4
1188 _RL znumer_sil, zdnumer_sil, zdenom_sil, zalk_sil, zdalk_sil
1189 _RL znumer_nh4, zdnumer_nh4, zdenom_nh4, zalk_nh4, zdalk_nh4
1190 _RL znumer_h2s, zdnumer_h2s, zdenom_h2s, zalk_h2s, zdalk_h2s
1191 _RL znumer_so4, zdnumer_so4, zdenom_so4, zalk_so4, zdalk_so4
1192 _RL znumer_flu, zdnumer_flu, zdenom_flu, zalk_flu, zdalk_flu
1193 _RL zalk_wat
1194
1195
1196 znumer_dic = 2. _d 0*ak1(i,j,bi,bj)*ak2(i,j,bi,bj)
1197 & + p_h* ak1(i,j,bi,bj)
1198 zdenom_dic = ak1(i,j,bi,bj)*ak2(i,j,bi,bj)
1199 & + p_h*(ak1(i,j,bi,bj) + p_h)
1200 zalk_dic = p_dictot * (znumer_dic/zdenom_dic)
1201
1202
1203 znumer_bor = akb(i,j,bi,bj)
1204 zdenom_bor = akb(i,j,bi,bj) + p_h
1205 zalk_bor = p_bortot * (znumer_bor/zdenom_bor)
1206
1207
1208 znumer_po4 =
1209 & 3. _d 0*ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)*ak3p(i,j,bi,bj)
1210 & + p_h*(2. _d 0*ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)
1211 & + p_h*ak1p(i,j,bi,bj))
1212 zdenom_po4 = ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)*ak3p(i,j,bi,bj)
1213 & + p_h*(ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)
1214 & + p_h*(ak1p(i,j,bi,bj) + p_h))
1215 zalk_po4 = p_po4tot * (znumer_po4/zdenom_po4 - 1. _d 0)
1216
1217
1218
1219 znumer_sil = aksi(i,j,bi,bj)
1220 zdenom_sil = aksi(i,j,bi,bj) + p_h
1221 zalk_sil = p_siltot * (znumer_sil/zdenom_sil)
1222
1223
1224 znumer_nh4 = akn(i,j,bi,bj)
1225 zdenom_nh4 = akn(i,j,bi,bj) + p_h
1226 zalk_nh4 = p_nh4tot * (znumer_nh4/zdenom_nh4)
1227
1228
1229 znumer_h2s = akhs(i,j,bi,bj)
1230 zdenom_h2s = akhs(i,j,bi,bj) + p_h
1231 zalk_h2s = p_h2stot * (znumer_h2s/zdenom_h2s)
1232
1233
1234 znumer_so4 = aks(i,j,bi,bj)
1235 zdenom_so4 = aks(i,j,bi,bj) + p_h
1236 zalk_so4 = p_so4tot * (znumer_so4/zdenom_so4 - 1. _d 0)
1237
1238
1239 znumer_flu = akf(i,j,bi,bj)
1240 zdenom_flu = akf(i,j,bi,bj) + p_h
1241 zalk_flu = p_flutot * (znumer_flu/zdenom_flu - 1. _d 0)
1242
1243
1244 zalk_wat = akw(i,j,bi,bj)/p_h - p_h/aphscale(i,j,bi,bj)
1245
1246
1247
1248
1249 p_eqn = zalk_dic + zalk_bor + zalk_po4 + zalk_sil
1250 & + zalk_nh4 + zalk_h2s + zalk_so4 + zalk_flu
1251 & + zalk_wat - p_alktot
1252
1253
1254
1255
1256 zdnumer_dic = ak1(i,j,bi,bj)*ak1(i,j,bi,bj)*ak2(i,j,bi,bj)
1257 & + p_h*(4. _d 0*ak1(i,j,bi,bj)*ak2(i,j,bi,bj)
1258 & + p_h* ak1(i,j,bi,bj))
1259 zdalk_dic = -p_dictot*(zdnumer_dic/zdenom_dic**2)
1260
1261
1262 zdnumer_bor = akb(i,j,bi,bj)
1263 zdalk_bor = -p_bortot*(zdnumer_bor/zdenom_bor**2)
1264
1265
1266 zdnumer_po4 = ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)
1267 & *ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)
1268 & *ak3p(i,j,bi,bj)
1269 & + p_h*(4. _d 0*ak1p(i,j,bi,bj)*ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)
1270 & *ak3p(i,j,bi,bj)
1271 & + p_h*(9. _d 0*ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)*ak3p(i,j,bi,bj)
1272 & + ak1p(i,j,bi,bj)*ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)
1273 & + p_h*(4. _d 0*ak1p(i,j,bi,bj)*ak2p(i,j,bi,bj)
1274 & + p_h* ak1p(i,j,bi,bj))))
1275 zdalk_po4 = -p_po4tot * (zdnumer_po4/zdenom_po4**2)
1276
1277
1278 zdnumer_sil = aksi(i,j,bi,bj)
1279 zdalk_sil = -p_siltot * (zdnumer_sil/zdenom_sil**2)
1280
1281
1282 zdnumer_nh4 = akn(i,j,bi,bj)
1283 zdalk_nh4 = -p_nh4tot * (zdnumer_nh4/zdenom_nh4**2)
1284
1285
1286 zdnumer_h2s = akhs(i,j,bi,bj)
1287 zdalk_h2s = -p_h2stot * (zdnumer_h2s/zdenom_h2s**2)
1288
1289
1290 zdnumer_so4 = aks(i,j,bi,bj)
1291 zdalk_so4 = -p_so4tot * (zdnumer_so4/zdenom_so4**2)
1292
1293
1294 zdnumer_flu = akf(i,j,bi,bj)
1295 zdalk_flu = -p_flutot * (zdnumer_flu/zdenom_flu**2)
1296
1297 p_deriveqn = zdalk_dic + zdalk_bor + zdalk_po4 + zdalk_sil
1298 & + zdalk_nh4 + zdalk_h2s + zdalk_so4 + zdalk_flu
1299 & - akw(i,j,bi,bj)/p_h**2 - 1. _d 0/aphscale(i,j,bi,bj)
1300
1301
1302 #endif /* CARBONCHEM_SOLVESAPHE */
1303 RETURN
1304 END
1305
1306
1307
1308
1309 SUBROUTINE SOLVE_AT_FAST(p_alktot, p_dictot, p_bortot,
1310 & p_po4tot, p_siltot, p_nh4tot,
1311 & p_h2stot, p_so4tot, p_flutot,
1312 & p_hini, p_val, p_hnew,
1313 & i, j, k, bi, bj,
1314 & debugPrt, myIter, myThid )
1315
1316
1317
1318 IMPLICIT NONE
1319
1320
1321 #include "SIZE.h"
1322 #include "EEPARAMS.h"
1323 #include "BLING_VARS.h"
1324
1325
1326
1327
1328
1329
1330
1331 _RL p_alktot
1332 _RL p_dictot
1333 _RL p_bortot
1334 _RL p_po4tot
1335 _RL p_siltot
1336 _RL p_nh4tot
1337 _RL p_h2stot
1338 _RL p_so4tot
1339 _RL p_flutot
1340 _RL p_hini
1341 _RL p_val
1342 _RL p_hnew
1343 INTEGER i, j, k, bi, bj
1344 LOGICAL debugPrt
1345 INTEGER myIter, myThid
1346
1347 #ifdef CARBONCHEM_SOLVESAPHE
1348
1349
1350
1351
1352
1353 _RL zh_ini, zh, zh_prev, zh_lnfactor
1354 _RL zhdelta
1355 _RL zeqn, zdeqndh
1356
1357
1358 LOGICAL iterate4pH
1359 _RL pz_exp_threshold
1360 _RL pp_rdel_ah_target
1361 INTEGER niter_atfast
1362
1363 pp_rdel_ah_target = 1. _d -8
1364 pz_exp_threshold = 1.0 _d 0
1365
1366
1367
1368 zh_ini = p_hini
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381 zh = zh_ini
1382
1383 niter_atfast = 0
1384
1385 iterate4pH = .TRUE.
1386 DO WHILE ( iterate4pH )
1387
1388 niter_atfast = niter_atfast + 1
1389 IF ( niter_atfast .GT. at_maxniter ) THEN
1390 zh = -1. _d 0
1391 iterate4pH = .FALSE.
1392 ELSE
1393
1394 zh_prev = zh
1395
1396
1397
1398
1399
1400 CALL EQUATION_AT( p_alktot, zh , p_dictot, p_bortot,
1401 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
1402 & p_so4tot, p_flutot,
1403 & zeqn , zdeqndh,
1404 & i, j, k, bi, bj, myIter, myThid )
1405
1406 iterate4pH = ( zeqn .NE. 0. _d 0 )
1407 ENDIF
1408
1409 IF ( iterate4pH ) THEN
1410 zh_lnfactor = -zeqn/(zdeqndh*zh_prev)
1411 IF(ABS(zh_lnfactor) .GT. pz_exp_threshold) THEN
1412 zh = zh_prev*EXP(zh_lnfactor)
1413 ELSE
1414 zhdelta = zh_lnfactor*zh_prev
1415 zh = zh_prev + zhdelta
1416 ENDIF
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437 iterate4pH = ( ABS(zh_lnfactor) .GE. pp_rdel_ah_target )
1438
1439 ENDIF
1440 ENDDO
1441
1442
1443 p_hnew = zh
1444
1445
1446 IF(zh .GT. 0. _d 0) THEN
1447
1448
1449
1450 CALL EQUATION_AT( p_alktot, zh, p_dictot, p_bortot,
1451 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
1452 & p_so4tot, p_flutot,
1453 & p_val , zdeqndh,
1454 & i, j, k, bi, bj, myIter, myThid )
1455 ELSE
1456
1457 p_val = 1. _d +65
1458 ENDIF
1459
1460
1461 #endif /* CARBONCHEM_SOLVESAPHE */
1462 RETURN
1463 END
1464
1465
1466
1467
1468 SUBROUTINE SOLVE_AT_GENERAL(p_alktot, p_dictot, p_bortot,
1469 & p_po4tot, p_siltot, p_nh4tot,
1470 & p_h2stot, p_so4tot, p_flutot,
1471 & p_hini, p_val, p_hnew,
1472 & i, j, k, bi, bj,
1473 & debugPrt, myIter, myThid )
1474
1475
1476
1477 IMPLICIT NONE
1478
1479
1480 #include "SIZE.h"
1481 #include "EEPARAMS.h"
1482 #include "BLING_VARS.h"
1483
1484
1485
1486
1487
1488
1489
1490 _RL p_alktot
1491 _RL p_dictot
1492 _RL p_bortot
1493 _RL p_po4tot
1494 _RL p_siltot
1495 _RL p_nh4tot
1496 _RL p_h2stot
1497 _RL p_so4tot
1498 _RL p_flutot
1499 _RL p_hini
1500 _RL p_hnew
1501 _RL p_val
1502 INTEGER i, j, k, bi, bj
1503 LOGICAL debugPrt
1504 INTEGER myIter, myThid
1505
1506 #ifdef CARBONCHEM_SOLVESAPHE
1507
1508
1509
1510
1511
1512 _RL zh_ini, zh, zh_prev, zh_lnfactor
1513 _RL p_alknw_inf, p_alknw_sup
1514 _RL zh_min, zh_max
1515 _RL zdelta, zh_delta
1516 _RL zeqn, zdeqndh, zeqn_absmin
1517 INTEGER niter_atgen
1518
1519
1520 LOGICAL iterate4pH
1521 _RL pz_exp_threshold
1522 _RL pp_rdel_ah_target
1523
1524 pp_rdel_ah_target = 1. _d -8
1525 pz_exp_threshold = 1. _d 0
1526
1527
1528 zh_ini = p_hini
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538 #ifdef ALLOW_DEBUG
1539 IF (debugPrt) CALL DEBUG_CALL('ANW_INFSUP',myThid)
1540 #endif
1541 CALL ANW_INFSUP(p_dictot, p_bortot,
1542 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
1543 & p_so4tot, p_flutot,
1544 & p_alknw_inf, p_alknw_sup,
1545 & i, j, k, bi, bj, myIter, myThid )
1546
1547 zdelta = (p_alktot-p_alknw_inf)**2 + 4. _d 0*akw(i,j,bi,bj)
1548 & /aphscale(i,j,bi,bj)
1549
1550 IF(p_alktot .GE. p_alknw_inf) THEN
1551 zh_min = 2. _d 0*akw(i,j,bi,bj) /( p_alktot-p_alknw_inf
1552 & + SQRT(zdelta) )
1553 ELSE
1554 zh_min = aphscale(i,j,bi,bj)*(-(p_alktot-p_alknw_inf)
1555 & + SQRT(zdelta) ) / 2. _d 0
1556 ENDIF
1557
1558 zdelta = (p_alktot-p_alknw_sup)**2 + 4. _d 0*akw(i,j,bi,bj)
1559 & /aphscale(i,j,bi,bj)
1560
1561 IF(p_alktot .LE. p_alknw_sup) THEN
1562 zh_max = aphscale(i,j,bi,bj)*(-(p_alktot-p_alknw_sup)
1563 & + SQRT(zdelta) ) / 2. _d 0
1564 ELSE
1565 zh_max = 2. _d 0*akw(i,j,bi,bj) /( p_alktot-p_alknw_sup
1566 & + SQRT(zdelta) )
1567 ENDIF
1568
1569
1570
1571
1572
1573
1574 zh = MAX(MIN(zh_max, zh_ini), zh_min)
1575
1576
1577
1578
1579 niter_atgen = 0
1580
1581 zeqn_absmin = 1. _d +65
1582
1583 iterate4pH = .TRUE.
1584 DO WHILE ( iterate4pH )
1585
1586 IF ( niter_atgen .GE. at_maxniter ) THEN
1587 zh = -1. _d 0
1588 iterate4pH = .FALSE.
1589 ELSE
1590
1591 zh_prev = zh
1592 #ifdef ALLOW_DEBUG
1593 IF (debugPrt) CALL DEBUG_CALL('EQUATION_AT',myThid)
1594 #endif
1595
1596
1597
1598 CALL EQUATION_AT( p_alktot, zh, p_dictot, p_bortot,
1599 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
1600 & p_so4tot, p_flutot,
1601 & zeqn , zdeqndh,
1602 & i, j, k, bi, bj, myIter, myThid )
1603
1604
1605 IF(zeqn .GT. 0. _d 0) THEN
1606 zh_min = zh_prev
1607 ELSEIF(zeqn .LT. 0. _d 0) THEN
1608 zh_max = zh_prev
1609 ELSE
1610
1611 iterate4pH = .FALSE.
1612 ENDIF
1613 ENDIF
1614
1615 IF ( iterate4pH ) THEN
1616
1617 niter_atgen = niter_atgen + 1
1618
1619 IF(ABS(zeqn) .GE. 0.5 _d 0*zeqn_absmin) THEN
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629 zh = SQRT(zh_max * zh_min)
1630
1631 zh_lnfactor = (zh - zh_prev)/zh_prev
1632 ELSE
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644 zh_lnfactor = -zeqn/(zdeqndh*zh_prev)
1645
1646 IF(ABS(zh_lnfactor) .GT. pz_exp_threshold) THEN
1647 zh = zh_prev*EXP(zh_lnfactor)
1648 ELSE
1649 zh_delta = zh_lnfactor*zh_prev
1650 zh = zh_prev + zh_delta
1651 ENDIF
1652
1653
1654
1655
1656
1657 IF( zh .LT. zh_min ) THEN
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668 zh = SQRT(zh_prev * zh_min)
1669
1670 zh_lnfactor = (zh - zh_prev)/zh_prev
1671 ENDIF
1672
1673 IF( zh .GT. zh_max ) THEN
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684 zh = SQRT(zh_prev * zh_max)
1685
1686 zh_lnfactor = (zh - zh_prev)/zh_prev
1687
1688 ENDIF
1689 ENDIF
1690
1691 zeqn_absmin = MIN( ABS(zeqn), zeqn_absmin)
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706 iterate4pH = ( ABS(zh_lnfactor) .GE. pp_rdel_ah_target )
1707
1708 ENDIF
1709 ENDDO
1710
1711
1712 p_hnew = zh
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722 #ifdef ALLOW_DEBUG
1723 IF (debugPrt) CALL DEBUG_LEAVE('SOLVE_AT_GENERAL',myThid)
1724 #endif
1725 #endif /* CARBONCHEM_SOLVESAPHE */
1726 RETURN
1727 END
1728
1729
1730
1731
1732 SUBROUTINE SOLVE_AT_GENERAL_SEC(p_alktot, p_dictot,
1733 & p_bortot, p_po4tot,
1734 & p_siltot, p_nh4tot,
1735 & p_h2stot, p_so4tot,
1736 & p_flutot, p_hini,
1737 & p_val, p_hnew,
1738 & i, j, k, bi, bj,
1739 & debugPrt, myIter, myThid )
1740
1741
1742
1743 IMPLICIT NONE
1744
1745
1746 #include "SIZE.h"
1747 #include "EEPARAMS.h"
1748 #include "BLING_VARS.h"
1749
1750
1751
1752
1753
1754 _RL p_alktot
1755 _RL p_dictot
1756 _RL p_bortot
1757 _RL p_po4tot
1758 _RL p_siltot
1759 _RL p_nh4tot
1760 _RL p_h2stot
1761 _RL p_so4tot
1762 _RL p_flutot
1763 _RL p_hini
1764 _RL p_hnew
1765 _RL p_val
1766 INTEGER i, j, k, bi, bj
1767 LOGICAL debugPrt
1768 INTEGER myIter, myThid
1769
1770 #ifdef CARBONCHEM_SOLVESAPHE
1771
1772
1773
1774
1775
1776 _RL zh_ini, zh, zh_1, zh_2, zh_delta
1777 _RL p_alknw_inf, p_alknw_sup
1778 _RL zh_min, zh_max
1779 _RL zeqn, zeqn_1, zeqn_2, zeqn_absmin
1780 _RL zdelta, zdeqndh
1781 _RL pp_rdel_ah_target
1782 INTEGER niter_atsec
1783
1784 LOGICAL iterate4pH
1785
1786 pp_rdel_ah_target = 1. _d -8
1787
1788
1789 zh_ini = p_hini
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800 CALL ANW_INFSUP(p_dictot, p_bortot,
1801 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
1802 & p_so4tot, p_flutot,
1803 & p_alknw_inf, p_alknw_sup,
1804 & i, j, k, bi, bj, myIter, myThid )
1805
1806 zdelta = (p_alktot-p_alknw_inf)**2 + 4. _d 0*akw(i,j,bi,bj)
1807 & /aphscale(i,j,bi,bj)
1808
1809 IF(p_alktot .GE. p_alknw_inf) THEN
1810 zh_min = 2. _d 0*akw(i,j,bi,bj) /( p_alktot-p_alknw_inf
1811 & + SQRT(zdelta) )
1812 ELSE
1813 zh_min = aphscale(i,j,bi,bj)*(-(p_alktot-p_alknw_inf)
1814 & + SQRT(zdelta) ) / 2. _d 0
1815 ENDIF
1816
1817 zdelta = (p_alktot-p_alknw_sup)**2 + 4. _d 0*akw(i,j,bi,bj)
1818 & /aphscale(i,j,bi,bj)
1819
1820 IF(p_alktot .LE. p_alknw_sup) THEN
1821 zh_max = aphscale(i,j,bi,bj)*(-(p_alktot-p_alknw_sup)
1822 & + SQRT(zdelta) ) / 2. _d 0
1823 ELSE
1824 zh_max = 2. _d 0*akw(i,j,bi,bj) /( p_alktot-p_alknw_sup
1825 & + SQRT(zdelta) )
1826 ENDIF
1827
1828
1829
1830
1831
1832
1833
1834 zh = MAX(MIN(zh_max, zh_ini), zh_min)
1835
1836
1837
1838 niter_atsec = 0
1839
1840
1841
1842
1843
1844
1845
1846
1847 zh_2 = zh
1848
1849
1850
1851 CALL EQUATION_AT( p_alktot, zh_2, p_dictot, p_bortot,
1852 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
1853 & p_so4tot, p_flutot,
1854 & zeqn_2 , zdeqndh,
1855 & i, j, k, bi, bj, myIter, myThid )
1856
1857 zeqn_absmin = ABS(zeqn_2)
1858
1859
1860
1861 IF(zeqn_2 .LT. 0. _d 0) THEN
1862
1863
1864 zh_max = zh_2
1865
1866
1867
1868 zh_1 = MAX(zh_max/1.25 _d 0, SQRT(zh_min*zh_max))
1869
1870 ELSEIF(zeqn_2 .GT. 0. _d 0) THEN
1871
1872
1873 zh_min = zh_2
1874
1875
1876
1877 zh_1 = MIN(zh_min*1.25 _d 0, SQRT(zh_min*zh_max))
1878
1879 ELSE
1880
1881
1882 p_hnew = zh_2
1883
1884 p_val = zeqn_2
1885 RETURN
1886 ENDIF
1887
1888
1889
1890
1891
1892
1893 niter_atsec = 1
1894
1895
1896
1897
1898 CALL EQUATION_AT( p_alktot, zh_1, p_dictot, p_bortot,
1899 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
1900 & p_so4tot, p_flutot,
1901 & zeqn_1 , zdeqndh,
1902 & i, j, k, bi, bj, myIter, myThid )
1903
1904
1905
1906
1907 IF(zeqn_1 .GT. 0. _d 0) THEN
1908 zh_min = zh_1
1909 ELSEIF(zeqn_1 .LT. 0. _d 0) THEN
1910 zh_max = zh_1
1911 ELSE
1912
1913
1914 p_hnew = zh_1
1915
1916 p_val = zeqn_1
1917 ENDIF
1918
1919 IF(ABS(zeqn_1) .GT. zeqn_absmin) THEN
1920
1921
1922
1923 zh = zh_1
1924 zeqn = zeqn_1
1925 zh_1 = zh_2
1926 zeqn_1 = zeqn_2
1927 zh_2 = zh
1928 zeqn_2 = zeqn
1929 ELSE
1930 zeqn_absmin = ABS(zeqn_1)
1931 ENDIF
1932
1933
1934 niter_atsec = 2
1935
1936 zh_delta = -zeqn_1/((zeqn_2-zeqn_1)/(zh_2 - zh_1))
1937 zh = zh_1 + zh_delta
1938
1939
1940
1941
1942 IF (zh .GT. zh_max) THEN
1943
1944
1945 zh = SQRT(zh_1*zh_max)
1946 ENDIF
1947
1948 IF (zh .LT. zh_min) THEN
1949
1950
1951 zh = SQRT(zh_1*zh_min)
1952 ENDIF
1953
1954 iterate4pH = .TRUE.
1955 DO WHILE ( iterate4pH )
1956
1957 IF ( niter_atsec .GE. at_maxniter ) THEN
1958 zh = -1. _d 0
1959 iterate4pH = .FALSE.
1960 ELSE
1961
1962
1963
1964
1965 CALL EQUATION_AT( p_alktot, zh, p_dictot, p_bortot,
1966 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
1967 & p_so4tot, p_flutot,
1968 & zeqn , zdeqndh,
1969 & i, j, k, bi, bj, myIter, myThid )
1970
1971
1972
1973
1974 IF(zeqn .GT. 0. _d 0) THEN
1975 zh_min = zh
1976 ELSEIF(zeqn .LT. 0. _d 0) THEN
1977 zh_max = zh
1978 ELSE
1979
1980 iterate4pH = .FALSE.
1981 ENDIF
1982 ENDIF
1983
1984 IF ( iterate4pH ) THEN
1985
1986 niter_atsec = niter_atsec + 1
1987
1988 zh_2 = zh_1
1989 zeqn_2 = zeqn_1
1990 zh_1 = zh
1991 zeqn_1 = zeqn
1992
1993 IF(ABS(zeqn) .GE. 0.5 _d 0*zeqn_absmin) THEN
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004 zh = SQRT(zh_max * zh_min)
2005 zh_delta = zh - zh_1
2006 ELSE
2007
2008
2009 zh_delta = -zeqn_1/((zeqn_2-zeqn_1)/(zh_2 - zh_1))
2010 zh = zh_1 + zh_delta
2011
2012
2013
2014
2015 IF( zh .LT. zh_min ) THEN
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026 zh = SQRT(zh_1 * zh_min)
2027 zh_delta = zh - zh_1
2028 ENDIF
2029
2030 IF( zh .GT. zh_max ) THEN
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041 zh = SQRT(zh_1 * zh_max)
2042 zh_delta = zh - zh_1
2043 ENDIF
2044 ENDIF
2045
2046 zeqn_absmin = MIN(ABS(zeqn), zeqn_absmin)
2047
2048
2049
2050
2051 iterate4pH = ( ABS(zh_delta) .GE. pp_rdel_ah_target*zh_1 )
2052
2053 ENDIF
2054 ENDDO
2055
2056
2057 p_hnew = zh
2058
2059
2060 IF(zh .GT. 0. _d 0) THEN
2061
2062
2063
2064 CALL EQUATION_AT( p_alktot, zh, p_dictot, p_bortot,
2065 & p_po4tot, p_siltot, p_nh4tot, p_h2stot,
2066 & p_so4tot, p_flutot,
2067 & p_val , zdeqndh,
2068 & i, j, k, bi, bj, myIter, myThid )
2069 ELSE
2070
2071 p_val = 1. _d +65
2072 ENDIF
2073
2074
2075 #endif /* CARBONCHEM_SOLVESAPHE */
2076 RETURN
2077 END
2078
ba0b047096 Mart*2079