Changeset 2553 for trunk/LMDZ.GENERIC
- Timestamp:
- Jul 21, 2021, 10:44:46 AM (3 years ago)
- Location:
- trunk/LMDZ.GENERIC
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.GENERIC/README
r2550 r2553 1679 1679 Some OpenMP fixes in routines initracer.F, nonoro_gwd_ran_mod.F90, 1680 1680 phys_state_var_mod.F90 and sugas_corrk.F90 1681 1682 == 21/07/2021 == YJ 1683 Chemistry: one input file instead of three for the chemical network 1684 Automatic detection of mono/bi-molecular or quadratic reactions -
trunk/LMDZ.GENERIC/libf/aeronostd/photochemistry_asis.F90
r2542 r2553 95 95 96 96 integer, save :: nreact ! number of reactions in reactions files 97 integer, allocatable, save :: rtype(:) ! reaction rate type98 integer, allocatable, save :: third_body(:) ! if the reaction have a third body: index of the third body, else zero99 logical, allocatable, save :: three_prod(:) ! if the reaction have a three defferent proucts egal .true.100 97 101 98 ! matrix … … 115 112 if (firstcall) then 116 113 print*,'photochemistry: initialize indexes' 117 call indice(nreact ,rtype,third_body,three_prod)114 call indice(nreact) 118 115 allocate(v_phot(nlayer,nb_phot_max)) 119 116 allocate(v_3(nlayer,nb_reaction_3_max)) … … 135 132 print*,'set jonline=.false. in callphys.def' 136 133 print*,'or set photolysis reactions in monoreact file' 137 stop134 call abort 138 135 end if 139 call init_photolysis(nlayer,nreact ,three_prod) ! on-line photolysis136 call init_photolysis(nlayer,nreact) ! on-line photolysis 140 137 allocate(albedo_snow_chim(nw)) 141 138 allocate(albedo_co2_ice_chim(nw)) … … 169 166 if (sza <= 95.) then 170 167 call photolysis_online(nlayer, alt, press, temp, zmmean, rm, & 171 tau, sza, dist_sol, v_phot, e_phot, ig, ngrid, nreact , three_prod)168 tau, sza, dist_sol, v_phot, e_phot, ig, ngrid, nreact) 172 169 if (ngrid.eq.1) then 173 170 do iphot = 1,nb_phot_hv_max … … 198 195 !=================================================================== 199 196 200 call reactionrates(nlayer, nreact, rtype, third_body, three_prod,c, lswitch, dens, &197 call reactionrates(nlayer, nreact, c, lswitch, dens, & 201 198 press, temp, zmmean, sza, surfdust1d, surfice1d, v_phot, v_3, v_4) 202 199 … … 296 293 #else 297 294 write(*,*) "photochemistry_asis error, missing LAPACK routine dgesv" 298 stop295 call abort 299 296 #endif 300 297 … … 412 409 #else 413 410 write(*,*) "photochemistry_asis error, missing LAPACK routine dgesv" 414 stop411 call abort 415 412 #endif 416 413 … … 457 454 !====================================================================== 458 455 459 subroutine reactionrates(nlayer, nreact, rtype, third_body, three_prod, c,&456 subroutine reactionrates(nlayer, nreact, c, & 460 457 lswitch, dens, press, t, zmmean, sza, & 461 458 surfdust1d, surfice1d, & … … 498 495 real (kind = 8), dimension(nlayer,nesp) :: c ! species number density (molecule.cm-3) 499 496 500 integer, intent(in) :: rtype(nreact) ! reaction rate type501 integer, intent(in) :: third_body(nreact) ! if the reaction have a third body: index of the third body, else zero502 logical, intent(in) :: three_prod(nreact) ! if the reaction have three different products egal .true.503 504 497 !---------------------------------------------------------------------- 505 498 ! output … … 537 530 !---------------------------------------------------------------------- 538 531 539 ireact = 1 540 541 ! Reaction from monoreact file are implemented first 542 do while(nb_phot<nb_phot_max-nphot_hard_coding) 543 544 if (rtype(ireact)/=0) then ! skip photolysis reactions 545 ! get right coefficient rate function 546 if (rtype(ireact)==1) then 547 nb_pfunc1 = nb_pfunc1 + 1 548 if (third_body(ireact)==0) then !! third_body check 549 ratec = pfunc1(nlayer,t,dens,pfunc1_param(nb_pfunc1)) 550 else 551 ratec = pfunc1(nlayer,t,c(:,third_body(ireact)),pfunc1_param(nb_pfunc1)) 552 end if 553 else if (rtype(ireact)==2) then 554 nb_pfunc2 = nb_pfunc2 + 1 555 if (third_body(ireact)==0) then !! third_body check 556 ratec = pfunc2(nlayer,t,dens,pfunc2_param(nb_pfunc2)) 557 else 558 ratec = pfunc2(nlayer,t,c(:,third_body(ireact)),pfunc2_param(nb_pfunc2)) 559 end if 560 else if (rtype(ireact)==3) then 561 nb_pfunc3 = nb_pfunc3 + 1 562 if (third_body(ireact)==0) then !! third_body check 563 ratec = pfunc3(nlayer,t,dens,pfunc3_param(nb_pfunc3)) 564 else 565 ratec = pfunc3(nlayer,t,c(:,third_body(ireact)),pfunc3_param(nb_pfunc3)) 566 end if 532 do ireact = 1,nreact 533 if (reactions(ireact)%rtype==0) then 534 nb_hv = nb_hv + 1 535 cycle 536 end if 537 538 ! get right coefficient rate function 539 if (reactions(ireact)%rtype==1) then 540 nb_pfunc1 = nb_pfunc1 + 1 541 if (reactions(ireact)%third_body==0) then !! third_body check 542 ratec = pfunc1(nlayer,t,dens,pfunc1_param(nb_pfunc1)) 567 543 else 568 print*, 'Error in reactionrates: wrong index coefficient rate vphot' 569 print*, 'rtype(ireact) = ',rtype(ireact) 570 print*, 'It should be 1 or 2 ' 571 print*, 'Please check the reaction ',ireact 572 if (ireact>nreact) print*, 'Please check the reaction count into the code beacause ireact > nreact is not possible' 573 stop 544 ratec = pfunc1(nlayer,t,c(:,reactions(ireact)%third_body),pfunc1_param(nb_pfunc1)) 574 545 end if 575 576 ! fill the right type index 546 else if (reactions(ireact)%rtype==2) then 547 nb_pfunc2 = nb_pfunc2 + 1 548 if (reactions(ireact)%third_body==0) then !! third_body check 549 ratec = pfunc2(nlayer,t,dens,pfunc2_param(nb_pfunc2)) 550 else 551 ratec = pfunc2(nlayer,t,c(:,reactions(ireact)%third_body),pfunc2_param(nb_pfunc2)) 552 end if 553 else if (reactions(ireact)%rtype==3) then 554 nb_pfunc3 = nb_pfunc3 + 1 555 if (reactions(ireact)%third_body==0) then !! third_body check 556 ratec = pfunc3(nlayer,t,dens,pfunc3_param(nb_pfunc3)) 557 else 558 ratec = pfunc3(nlayer,t,c(:,reactions(ireact)%third_body),pfunc3_param(nb_pfunc3)) 559 end if 560 else 561 print*, 'Error in reactionrates: wrong index coefficient rate vphot' 562 print*, 'rtype(ireact) = ',reactions(ireact)%rtype 563 print*, 'It should be 1 or 2 ' 564 print*, 'Please check the reaction ',ireact 565 if (ireact>nreact) print*, 'Please check the reaction count into the code beacause ireact > nreact is not possible' 566 call abort 567 end if 568 569 ! fill the right type index 570 if (reactions(ireact)%vtype=="v4") then 571 nb_reaction_4 = nb_reaction_4 + 1 572 v_4(:,nb_reaction_4) = ratec(:) 573 if (reactions(ireact)%three_prod) then ! three_prod check 574 nb_reaction_4 = nb_reaction_4 + 1 575 v_4(:,nb_reaction_4) = ratec(:) 576 end if 577 else if (reactions(ireact)%vtype=="v3") then 578 nb_reaction_3 = nb_reaction_3 + 1 579 v_3(:,nb_reaction_3) = ratec(:) 580 if (reactions(ireact)%three_prod) then ! three_prod check 581 nb_reaction_3 = nb_reaction_3 + 1 582 v_3(:,nb_reaction_3) = ratec(:) 583 end if 584 else if (reactions(ireact)%vtype=="vphot") then 577 585 nb_phot = nb_phot + 1 578 586 v_phot(:,nb_phot) = ratec(:) 579 if ( three_prod(ireact)) then ! three_prod check587 if (reactions(ireact)%three_prod) then ! three_prod check 580 588 nb_phot = nb_phot + 1 581 589 v_phot(:,nb_phot) = ratec(:) 582 590 end if 583 591 else 584 nb_hv = nb_hv + 1 592 print*, 'Error in reactionrates: wrong type coefficient rate' 593 print*, 'vtype(ireact) = ',reactions(ireact)%vtype 594 print*, 'It should be v4, v3 or vphot ' 595 print*, 'Please check the reaction ',ireact 596 if (ireact>nreact) print*, 'Please check the reaction count into the code beacause ireact > nreact is not possible' 597 call abort 585 598 end if 586 587 ireact = ireact + 1588 589 end do590 591 ! Reaction from bimolreact file are implemented secondly592 do while(nb_reaction_4<nb_reaction_4_max-n4_hard_coding)593 594 ! get right coefficient rate function595 if (rtype(ireact)==1) then596 nb_pfunc1 = nb_pfunc1 + 1597 if (third_body(ireact)==0) then !! third_body check598 ratec = pfunc1(nlayer,t,dens,pfunc1_param(nb_pfunc1))599 else600 ratec = pfunc1(nlayer,t,c(:,third_body(ireact)),pfunc1_param(nb_pfunc1))601 end if602 else if (rtype(ireact)==2) then603 nb_pfunc2 = nb_pfunc2 + 1604 if (third_body(ireact)==0) then !! third_body check605 ratec = pfunc2(nlayer,t,dens,pfunc2_param(nb_pfunc2))606 else607 ratec = pfunc2(nlayer,t,c(:,third_body(ireact)),pfunc2_param(nb_pfunc2))608 end if609 else if (rtype(ireact)==3) then610 nb_pfunc3 = nb_pfunc3 + 1611 if (third_body(ireact)==0) then !! third_body check612 ratec = pfunc3(nlayer,t,dens,pfunc3_param(nb_pfunc3))613 else614 ratec = pfunc3(nlayer,t,c(:,third_body(ireact)),pfunc3_param(nb_pfunc3))615 end if616 else617 print*, 'Error in reactionrates: wrong index coefficient rate v4'618 print*, 'rtype(ireact) = ',rtype(ireact)619 print*, 'It should be 1 or 2 '620 print*, 'Please check the reaction ',ireact-nb_phot_max621 if (ireact>nreact) print*, 'Please check the reaction count into the code beacause ireact > nreact is not possible'622 stop623 end if624 625 ! fill the right type index626 nb_reaction_4 = nb_reaction_4 + 1627 v_4(:,nb_reaction_4) = ratec(:)628 if (three_prod(ireact)) then ! three_prod check629 nb_reaction_4 = nb_reaction_4 + 1630 v_4(:,nb_reaction_4) = ratec(:)631 end if632 633 ireact = ireact + 1634 635 end do636 637 ! Reaction from quadrareact file are implemented thirdly638 do while(nb_reaction_3<nb_reaction_3_max-n3_hard_coding)639 640 ! get right coefficient rate function641 if (rtype(ireact)==1) then642 nb_pfunc1 = nb_pfunc1 + 1643 if (third_body(ireact)==0) then !! third_body check644 ratec = pfunc1(nlayer,t,dens,pfunc1_param(nb_pfunc1))645 else646 ratec = pfunc1(nlayer,t,c(:,third_body(ireact)),pfunc1_param(nb_pfunc1))647 end if648 else if (rtype(ireact)==2) then649 nb_pfunc2 = nb_pfunc2 + 1650 if (third_body(ireact)==0) then !! third_body check651 ratec = pfunc2(nlayer,t,dens,pfunc2_param(nb_pfunc2))652 else653 ratec = pfunc2(nlayer,t,c(:,third_body(ireact)),pfunc2_param(nb_pfunc2))654 end if655 else if (rtype(ireact)==3) then656 nb_pfunc3 = nb_pfunc3 + 1657 if (third_body(ireact)==0) then !! third_body check658 ratec = pfunc3(nlayer,t,dens,pfunc3_param(nb_pfunc3))659 else660 ratec = pfunc3(nlayer,t,c(:,third_body(ireact)),pfunc3_param(nb_pfunc3))661 end if662 else663 print*, 'Error in reactionrates: wrong index coefficient rate v3'664 print*, 'rtype(ireact) = ',rtype(ireact)665 print*, 'It should be 1 or 2 '666 print*, 'Please check the reaction ',ireact-nb_phot_max-nb_reaction_4_max667 if (ireact>nreact) print*, 'Please check the reaction count into the code beacause ireact > nreact is not possible'668 stop669 end if670 671 ! fill the right type index672 nb_reaction_3 = nb_reaction_3 + 1673 v_3(:,nb_reaction_3) = ratec(:)674 if (three_prod(ireact)) then ! three_prod check675 nb_reaction_3 = nb_reaction_3 + 1676 v_3(:,nb_reaction_3) = ratec(:)677 end if678 679 ireact = ireact + 1680 599 681 600 end do … … 688 607 689 608 if (firstcall) then 690 ireact = ireact-1691 if (ireact /= nreact) print*, 'wrong dimensions in reactionrates : number of reaction should be ', nreact,' and not ', ireact692 609 if ((nb_phot /= nb_phot_max) .or. & 693 610 (nb_reaction_3 /= nb_reaction_3_max) .or. & … … 704 621 print*, 'n4_hard_coding = ', n4_hard_coding 705 622 print*, 'n3_hard_coding = ', n3_hard_coding 706 stop623 call abort 707 624 end if 708 625 if ((nb_hv /= nb_hv_max) .or. & … … 719 636 print*, 'nb_pfunc2_max = ', nb_pfunc2_max 720 637 print*, 'nb_pfunc3_max = ', nb_pfunc3_max 721 stop638 call abort 722 639 end if 723 640 firstcall = .false. … … 843 760 !================================================================ 844 761 845 subroutine indice(nreact ,rtype,third_body,three_prod)762 subroutine indice(nreact) 846 763 847 764 !================================================================ … … 869 786 870 787 integer, intent(out) :: nreact ! number of reactions in reactions files 871 integer, allocatable, intent(out) :: rtype(:) ! reaction rate type872 integer, allocatable, intent(out) :: third_body(:) ! if the reaction have a third body: index of the third body, else zero873 logical, allocatable, intent(out) :: three_prod(:) ! if the reaction have a three defferent proucts egal .true.874 788 875 789 ! local … … 880 794 881 795 character(len = 128) :: reactfile ! reactions table file name 882 character(len = 128) :: monoreact ! photochemical reactions table file name883 character(len = 128) :: bimolreact ! bimolecular reactions table file name884 character(len = 128) :: quadrareact ! quadratic reactions table file name885 796 integer :: nbq ! number of species in reactions file 886 integer :: pnlines ! number of lines in photochemical reactions file 887 integer :: bnlines ! number of lines in bimolecular reactions file 888 integer :: qnlines ! number of lines in quadratic reactions file 797 integer :: nlines ! number of lines in reactions file 889 798 integer :: pnreact ! number of reaction in photochemical reactions file 890 799 integer :: bnreact ! number of reaction in bimolecular reactions file … … 909 818 910 819 ! Get number of reactions 911 pnlines = 0 912 bnlines = 0 913 qnlines = 0 820 nlines = 0 914 821 nreact = 0 915 822 pnreact = 0 … … 917 824 qnreact = 0 918 825 919 write(*,*) "Read photochemical reaction" 920 monoreact = "monoreact" ! default 921 call getin_p("monoreact",monoreact) ! default path 922 write(*,*) " monoreact = ",trim(monoreact) 923 924 write(*,*) "Read bimolecular reaction" 925 bimolreact = "bimolreact" ! default 926 call getin_p("bimolreact",bimolreact) ! default path 927 write(*,*) " bimolreact = ",trim(bimolreact) 928 929 write(*,*) "Read quadratic reaction" 930 quadrareact = "quadrareact" ! default 931 call getin_p("quadrareact",quadrareact) ! default path 932 write(*,*) " quadrareact = ",trim(quadrareact) 933 934 call count_react(monoreact,pnlines,pnreact,nb_phot,nb_hv,nb_pfunc1,nb_pfunc2,nb_pfunc3) 935 call count_react(bimolreact,bnlines,bnreact,nb_reaction_4,nb_hv,nb_pfunc1,nb_pfunc2,nb_pfunc3) 936 call count_react(quadrareact,qnlines,qnreact,nb_reaction_3,nb_hv,nb_pfunc1,nb_pfunc2,nb_pfunc3) 937 nreact = pnreact + bnreact + qnreact 826 write(*,*) "Read reaction file" 827 reactfile = "reactfile" ! default 828 call getin_p("reactfile",reactfile) ! default path 829 write(*,*) " reactfile = ",trim(reactfile) 830 831 call count_react(reactfile,nlines,nreact,nb_phot,nb_reaction_4,nb_reaction_3,nb_hv,nb_pfunc1,nb_pfunc2,nb_pfunc3) 938 832 939 833 !!!!!!!!!!! Hard coding reaction !!!!!!!!!!!!!!!!!!!!!!!!!!! … … 964 858 allocate(indice_4(nb_reaction_4_max)) 965 859 allocate(indice_3(nb_reaction_3_max)) 966 allocate(rtype(nreact)) 967 allocate(third_body(nreact)) 968 allocate(three_prod(nreact)) 860 allocate(reactions(nreact)) 969 861 allocate(jlabel(nb_phot_hv_max,2)) 970 allocate(jparamline(nb_ phot_hv_max))862 allocate(jparamline(nb_hv_max)) 971 863 allocate(pfunc1_param(nb_pfunc1_max)) 972 864 allocate(pfunc2_param(nb_pfunc2_max)) … … 979 871 specheckr(:) = 0 980 872 specheckp(:) = 0 981 rtype(:) = 0 982 third_body(:) = 0 873 reactions(:) = reaction('',-1,0,.false.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.) 983 874 pfunc1_param(:) = rtype1(0.,0.,0.,0.,0.) 984 875 pfunc2_param(:) = rtype2(0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.) 985 876 pfunc3_param(:) = rtype3(0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.) 986 nb_pfunc1 = 0 987 nb_pfunc2 = 0 988 nb_pfunc3 = 0 989 three_prod(:) = .false. 877 nb_phot = 0 878 nb_reaction_4 = 0 879 nb_reaction_3 = 0 990 880 jlabel(:,:) = '' 991 881 jparamline(:) = '' 992 882 993 call get_react(monoreact,pnlines,pnreact,rtype(1:pnreact),third_body(1:pnreact),three_prod(1:pnreact), & 994 nb_phot,specheck,specheckr,specheckp,'vphot',nbq,nb_pfunc1,nb_pfunc2,nb_pfunc3) 995 call get_react(bimolreact,bnlines,bnreact,rtype(pnreact+1:pnreact+bnreact),third_body(pnreact+1:pnreact+bnreact), & 996 three_prod(pnreact+1:pnreact+bnreact),nb_reaction_4,specheck,specheckr,specheckp,'v4',nbq,nb_pfunc1,nb_pfunc2,nb_pfunc3) 997 call get_react(quadrareact,qnlines,qnreact,rtype(pnreact+bnreact+1:nreact),third_body(pnreact+bnreact+1:nreact), & 998 three_prod(pnreact+bnreact+1:nreact),nb_reaction_3,specheck,specheckr,specheckp,'v3',nbq,nb_pfunc1,nb_pfunc2,nb_pfunc3) 883 call get_react(reactfile,nlines,nreact,specheck,specheckr,specheckp,nbq,nb_phot,nb_reaction_4,nb_reaction_3) 999 884 1000 885 ! rewrite jlabel corretly for output 1001 886 do ireact=1,nb_phot_hv_max 1002 if ( three_prod(ireact)) then887 if (reactions(ireact)%three_prod) then 1003 888 jlabel(ireact+1:nb_phot_hv_max,2) = jlabel(ireact:nb_phot_hv_max-1,2) 1004 889 jlabel(ireact+1:nb_phot_hv_max,1) = jlabel(ireact:nb_phot_hv_max-1,1) … … 1031 916 else 1032 917 print*, 'Error in indice: bad value in specheckr or specheckp' 1033 stop918 call abort 1034 919 end if 1035 920 end if … … 1067 952 print*, 'nb_phot_hv_max = ', nb_phot_hv_max 1068 953 print*, 'nb_hv_max = ', nb_hv_max 1069 stop954 call abort 1070 955 end if 1071 956 … … 1195 1080 do 1196 1081 n = n + 1 1082 if (n>nmax) then 1083 print*,'Error in split_str: to much words' 1084 print*,'limit = ',nmax 1085 print*,'change it, if you want, with increasing nmax' 1086 print*,'line is:',line 1087 call abort 1088 end if 1197 1089 read(line,*,iostat=ios) buf(1:n) ! use list-directed input 1198 1090 if (ios==0) then … … 1202 1094 exit ! if all the words are obtained, finish 1203 1095 endif 1204 if (n>nmax) then1205 print*,'Error in split_str: to much words'1206 print*,'limit = ',nmax1207 print*,'change it, if you want, with increasing nmax'1208 stop1209 end if1210 1096 enddo 1211 1097 end subroutine split_str … … 1213 1099 !***************************************************************** 1214 1100 1215 subroutine count_react(reactfile,nlines,nreact,nrtype,nb_hv,nb_pfunc1,nb_pfunc2,nb_pfunc3)1101 subroutine find_vtype(reactline,vtype) 1216 1102 1217 1103 !***************************************************************** 1218 1104 1105 use tracer_h, only: nesp 1106 use chimiedata_h, only: indexchim 1107 1108 implicit none 1109 1110 character(len = 50), intent(in) :: reactline ! all reactants of one reaction 1111 character(*), intent(inout) :: vtype ! "v3", "v4" or "vphot" 1112 1113 integer :: nwr ! number of reactant for a reaction 1114 integer,parameter :: nmax = 5 ! number max of reactants or products 1115 character(len = 24) :: words(nmax) ! to get words in reactants and products line 1116 integer :: stochio(nesp) ! stoichiometry of reaction 1117 integer :: iword 1118 1119 ! init 1120 stochio(:) = 0 1121 1122 ! split reactant 1123 call split_str(reactline,words,nwr,nmax) 1124 1125 ! set stochio 1126 do iword = 1,nwr 1127 if (trim(words(iword))=="M") exit 1128 if (trim(words(iword))/="hv" & 1129 .and. trim(words(iword))/="dummy") stochio(indexchim(words(iword))) = stochio(indexchim(words(iword))) + 1 1130 end do 1131 1132 ! set vtype 1133 if (sum(stochio)==1) then 1134 vtype = "vphot" 1135 else if (sum(stochio)==2) then 1136 if (any(stochio==2)) then 1137 vtype = "v3" 1138 else 1139 vtype = "v4" 1140 end if 1141 else if (sum(stochio)==3) then 1142 if (any(stochio==2)) then 1143 vtype = "v4" 1144 else 1145 print*,'Error in photochemistry_asis (find_vtype):' 1146 print*,'3 different reactants not implemented' 1147 call abort 1148 end if 1149 else 1150 print*,'Error in photochemistry_asis (find_vtype):' 1151 print*,'more than 2 different reactants not implemented' 1152 call abort 1153 end if 1154 1155 end subroutine find_vtype 1156 1157 !***************************************************************** 1158 1159 subroutine count_react(reactfile,nlines,nreact,nb_phot,nb_reaction_4,nb_reaction_3,nb_hv,nb_pfunc1,nb_pfunc2,nb_pfunc3) 1160 1161 !***************************************************************** 1162 1219 1163 use types_asis, only : nb_phot_hv_max 1220 1164 1221 1165 implicit none 1222 character(*), intent(in) :: reactfile ! name of the file to read 1223 integer, intent(inout) :: nlines ! number of lines in the file 1224 integer, intent(out) :: nreact ! real number of reaction 1225 integer, intent(inout) :: nrtype ! number of reaction for calculation 1226 integer, intent(inout) :: nb_hv, nb_pfunc1, nb_pfunc2, nb_pfunc3 1166 character(*), intent(in) :: reactfile ! name of the file to read 1167 integer, intent(inout) :: nlines ! number of lines in the file 1168 integer, intent(out) :: nreact ! real number of reaction 1169 integer, intent(inout) :: nb_phot ! dimension of "vphot" reaction 1170 integer, intent(inout) :: nb_reaction_4 ! dimension of "v4" reaction 1171 integer, intent(inout) :: nb_reaction_3 ! dimension of "v3" reaction 1172 integer, intent(inout) :: nb_hv ! number of typerate 0 reaction 1173 integer, intent(inout) :: nb_pfunc1 ! number of typerate 1 reaction 1174 integer, intent(inout) :: nb_pfunc2 ! number of typerate 2 reaction 1175 integer, intent(inout) :: nb_pfunc3 ! number of typerate 3 reaction 1227 1176 1228 1177 ! local 1229 character(len = 50) :: reactline ! all reactants of one reaction 1230 character(len = 50) :: prodline ! all produts of one reaction 1231 integer :: typerate ! get the type of the rate reaction coefficient (pfunc_i) 1232 integer :: nwp ! number of products for a reaction 1233 integer,parameter :: nmax = 5 ! number max of reactants or products 1234 character(len = 24) :: words(nmax) ! to get words in reactants and products line 1178 character(len = 50) :: reactline ! all reactants of one reaction 1179 character(len = 50) :: prodline ! all produts of one reaction 1180 integer :: typerate ! get the type of the rate reaction coefficient (pfunc_i) 1181 character(5) :: vtype ! "v3", "v4" or "vphot" 1182 integer :: nwp ! number of products for a reaction 1183 integer,parameter :: nmax = 5 ! number max of reactants or products 1184 character(len = 24) :: words(nmax) ! to get words in reactants and products line 1235 1185 integer :: ierr 1236 1186 1237 nreact = 0 1187 nreact = 0 1188 vtype = '' 1238 1189 1239 1190 open(402, form = 'formatted', status = 'old', & … … 1247 1198 write(*,*)' monoreact=filename or bimolreact=filename or quadrareact=filename' 1248 1199 write(*,*)' depending on what chemical reaction type it is' 1249 stop1200 call abort 1250 1201 end if 1251 1202 … … 1253 1204 read(402,'(A,A,I2)',iostat=ierr) reactline, prodline, typerate 1254 1205 if (ierr<0) exit 1206 ! count the number of lines 1255 1207 nlines = nlines + 1 1256 1208 if (reactline(1:1)/='!' .and. reactline(1:1)/='') then 1257 1209 ! count the number of reaction 1258 1210 nreact = nreact + 1 1211 1212 call find_vtype(reactline,vtype) 1259 1213 call split_str(prodline,words,nwp,nmax) 1260 nrtype = nrtype + 1 1261 ! check three product reaction 1262 if (nwp>2 .and. trim(words(1))/=trim(words(2)) & 1263 .and. trim(words(1))/=trim(words(3)) & 1264 .and. trim(words(2))/=trim(words(3))) nrtype = nrtype + 1 1214 1215 ! count the dimension of each rate reaction coefficient type 1216 if (trim(vtype)=="vphot") then 1217 nb_phot = nb_phot + 1 1218 ! check three product reaction 1219 if (nwp>2 .and. trim(words(1))/=trim(words(2)) & 1220 .and. trim(words(1))/=trim(words(3)) & 1221 .and. trim(words(2))/=trim(words(3))) nb_phot = nb_phot + 1 1222 else if (trim(vtype)=="v4") then 1223 nb_reaction_4 = nb_reaction_4 + 1 1224 ! check three product reaction 1225 if (nwp>2 .and. trim(words(1))/=trim(words(2)) & 1226 .and. trim(words(1))/=trim(words(3)) & 1227 .and. trim(words(2))/=trim(words(3))) nb_reaction_4 = nb_reaction_4 + 1 1228 else if (trim(vtype)=="v3") then 1229 nb_reaction_3 = nb_reaction_3 + 1 1230 ! check three product reaction 1231 if (nwp>2 .and. trim(words(1))/=trim(words(2)) & 1232 .and. trim(words(1))/=trim(words(3)) & 1233 .and. trim(words(2))/=trim(words(3))) nb_reaction_3 = nb_reaction_3 + 1 1234 else 1235 print*,'Error in photochemistry_asis (count_react):' 1236 print*,'vtype not found' 1237 call abort 1238 end if 1265 1239 1266 1240 ! count the number of each rate reaction coefficient type … … 1282 1256 print*, 'It should be 0 for photolysis reations and 1 or 2 for the others' 1283 1257 print*, 'And not : ', typerate 1284 stop1258 call abort 1285 1259 end if 1286 1260 … … 1295 1269 !***************************************************************** 1296 1270 1297 subroutine get_react(reactfile,nlines,nreact,rtype,third_body,three_prod, & 1298 nrtype,specheck,specheckr,specheckp,typeindice,nbq, & 1299 init_nb_pfunc1,init_nb_pfunc2,init_nb_pfunc3) 1271 subroutine get_react(reactfile,nlines,nreact,specheck,specheckr,specheckp, & 1272 nbq,nb_phot,nb_reaction_4,nb_reaction_3) 1300 1273 1301 1274 !***************************************************************** … … 1310 1283 integer, intent(in) :: nlines ! number of lines in the file 1311 1284 integer, intent(in) :: nreact ! real number of reaction in the file 1312 integer, intent(inout) :: rtype(nreact) ! reaction rate type 1313 integer, intent(inout) :: third_body(nreact) ! if the reaction have a third body: index of the third body, else zero 1314 logical, intent(inout) :: three_prod(nreact) ! if the reaction have a three defferent proucts egal .true. 1315 integer, intent(out) :: nrtype ! number of calculation reactions 1285 integer, intent(out) :: nb_phot ! number of "vphot" calculation reactions 1286 integer, intent(out) :: nb_reaction_4 ! number of "vphot" calculation reactions 1287 integer, intent(out) :: nb_reaction_3 ! number of "vphot" calculation reactions 1316 1288 integer, intent(inout) :: specheck(nesp) ! to count the species of traceur.def in reactions file 1317 1289 integer, intent(inout) :: specheckr(nesp) ! to count the reactant species of traceur.def in reactions file 1318 1290 integer, intent(inout) :: specheckp(nesp) ! to count the product species of traceur.def in reactions file 1319 character(*), intent(in) :: typeindice ! reaction type (v3, v4 or vphot)1320 1291 integer, intent(inout) :: nbq ! number of species in reactions file 1321 integer, intent(inout) :: init_nb_pfunc1 ! in : initial value of nb_pfunc1 - out : final value of nb_pfunc11322 integer, intent(inout) :: init_nb_pfunc2 ! in : initial value of nb_pfunc2 - out : final value of nb_pfunc21323 integer, intent(inout) :: init_nb_pfunc3 ! in : initial value of nb_pfunc3 - out : final value of nb_pfunc31324 1292 1325 1293 ! local … … 1333 1301 integer :: iindice(2*nmax) ! indice of species (for indice variables) 1334 1302 character(len = 500) :: paramline ! line of reactions parameters 1335 character(len = 50) :: reactants(nreact,nmax) ! reactions reactants 1336 character(len = 50) :: products(nreact,nmax) ! reactions products 1337 logical :: spedouble ! check if a specie appears twice in reactants or products 1338 integer :: ierr, ilines, ireact, i_dummy, iw, iwhere, i 1339 integer :: nb_hv, nb_pfunc1, nb_pfunc2, nb_pfunc3 1340 1341 i_dummy = 1 1342 nrtype = 0 1343 ireact = 0 1344 nb_hv = 0 1345 nb_pfunc1 = init_nb_pfunc1 1346 nb_pfunc2 = init_nb_pfunc2 1347 nb_pfunc3 = init_nb_pfunc3 1303 integer :: stochio(nesp) ! stoichiometry of reaction 1304 integer :: ierr, ilines, ireact, i_dummy, iw, ispe, iloc 1305 integer :: nb_phot_hv, nb_hv, nb_pfunc1, nb_pfunc2, nb_pfunc3 1306 1307 i_dummy = 1 1308 ireact = 0 1309 nb_phot = 0 1310 nb_phot_hv = 0 1311 nb_hv = 0 1312 nb_pfunc1 = 0 1313 nb_pfunc2 = 0 1314 nb_pfunc3 = 0 1348 1315 1349 1316 open(402, form = 'formatted', status = 'old', & … … 1357 1324 write(*,*)' monoreact=filename or bimolreact=filename or quadrareact=filename' 1358 1325 write(*,*)' depending on what chemical reaction type it is' 1359 stop1326 call abort 1360 1327 end if 1361 1328 … … 1368 1335 if (reactline(1:1)/='!' .and. reactline(1:1)/='') then 1369 1336 1370 ! increment number of reactions and init1337 ! increment number of reactions 1371 1338 ireact = ireact + 1 1372 !!!!!!!!!!!!!!!!!!!!!!!!!!! for fill indice part 1373 nrtype = nrtype + 1 1374 nindice(:) = 0.0 1375 iindice(:) = i_dummy 1376 !!!!!!!!!!!!!!!!!!!!!!!!!!! end 1377 ! get indice, rate type and parameters 1339 1340 ! fill reaction vtype 1341 call find_vtype(reactline,reactions(ireact)%vtype) 1342 if (trim(reactions(ireact)%vtype)=="v4") then 1343 nb_reaction_4 = nb_reaction_4 + 1 1344 else if (trim(reactions(ireact)%vtype)=="v3") then 1345 nb_reaction_3 = nb_reaction_3 + 1 1346 else if (trim(reactions(ireact)%vtype)=="vphot") then 1347 nb_phot = nb_phot + 1 1348 else 1349 print*,'Error in photochemistry_asis (get_react):' 1350 print*,'vtype not found' 1351 call abort 1352 end if 1353 1354 ! fill reaction rate type and parameters 1378 1355 if (trim(paramline)=='') then 1379 print*, 'Error in reactfile: where are the parameters - line',ilines1380 stop1356 print*, 'Error in reactfile: where are the parameters - line',ilines 1357 call abort 1381 1358 else 1382 read(paramline,*) rtype(ireact) 1383 if (rtype(ireact)==1) then 1384 nb_pfunc1 = nb_pfunc1 + 1 1385 read(paramline,*) rtype(ireact), pfunc1_param(nb_pfunc1) 1386 else if (rtype(ireact)==0) then 1387 nb_hv = nb_hv + 1 1388 if (jonline) then 1389 read(paramline,'(I5,A,A)') rtype(ireact), jlabel(nb_hv,1), jparamline(nb_hv) 1359 read(paramline,*) reactions(ireact)%rtype 1360 if (reactions(ireact)%rtype==1) then 1361 nb_pfunc1 = nb_pfunc1 + 1 1362 read(paramline,*) reactions(ireact)%rtype, pfunc1_param(nb_pfunc1) 1363 else if (reactions(ireact)%rtype==0) then 1364 nb_hv = nb_hv + 1 1365 nb_phot_hv = nb_phot_hv + 1 1366 if (jonline) then 1367 read(paramline,'(I5,A,A)') reactions(ireact)%rtype, jlabel(nb_hv,1), jparamline(nb_hv) 1368 else 1369 read(paramline,*) reactions(ireact)%rtype, jlabel(nb_hv,1) 1370 end if 1371 else if (reactions(ireact)%rtype==2) then 1372 nb_pfunc2 = nb_pfunc2 + 1 1373 read(paramline,*) reactions(ireact)%rtype, pfunc2_param(nb_pfunc2) 1374 else if (reactions(ireact)%rtype==3) then 1375 nb_pfunc3 = nb_pfunc3 + 1 1376 read(paramline,*) reactions(ireact)%rtype, pfunc3_param(nb_pfunc3) 1377 end if 1378 end if 1379 1380 ! WARNING: the implementation is limited to 3 different reactants (for now only 2) and 3 different products 1381 nindice(:) = 0.0 ! 3 first indice for reactants, 3 following for products 1382 iindice(:) = i_dummy ! 3 first indice for reactants, 3 following for products 1383 1384 !-----------------! 1385 !--- reactants ---! 1386 !-----------------! 1387 1388 ! init for reactant 1389 stochio(:) = 0 1390 ! split reactant 1391 call split_str(reactline,words,nwr,nmax) 1392 ! set species that are photolysed 1393 if (reactions(ireact)%rtype==0) jlabel(nb_hv,2) = words(1) 1394 ! find reactant stochio 1395 do iw = 1,nwr 1396 ! fill third body index 1397 if (trim(words(iw))=="M") then 1398 if (iw==nwr) then 1399 exit 1400 else if (iw==nwr-1) then 1401 reactions(ireact)%third_body = indexchim(words(iw+1)) 1402 exit 1403 else 1404 print*, 'Error in reactfile: just only one specie can be after M corresponding to the third body - line',ilines 1405 call abort 1406 end if 1407 end if 1408 ! count stochio 1409 if (trim(words(iw))/="hv" & 1410 .and. trim(words(iw))/="dummy") stochio(indexchim(words(iw))) = stochio(indexchim(words(iw))) + 1 1411 end do 1412 ! get reaction reactant stochio and indice 1413 iloc = 0 1414 do ispe = 1,nesp 1415 if (stochio(ispe)==0) cycle 1416 iloc = iloc + 1 1417 nindice(iloc) = stochio(ispe) 1418 iindice(iloc) = ispe 1419 ! check up: to count the species used in 'reactfile' 1420 if (specheck(ispe)==0) then 1421 specheckr(ispe) = 1 1422 specheck(ispe) = 1 1423 nbq = nbq + 1 1424 else if (specheckr(ispe)==0) then 1425 specheckr(ispe) = 1 1426 end if 1427 end do 1428 ! fill reaction reactant stochio and indice 1429 reactions(ireact)%ir1 = nindice(1) 1430 reactions(ireact)%r1 = iindice(1) 1431 reactions(ireact)%ir2 = nindice(2) 1432 reactions(ireact)%r2 = iindice(2) 1433 reactions(ireact)%ir3 = nindice(3) 1434 reactions(ireact)%r3 = iindice(3) 1435 1436 !----------------! 1437 !--- products ---! 1438 !----------------! 1439 1440 ! init for products 1441 stochio(:) = 0 1442 ! split products 1443 call split_str(prodline,words,nwp,nmax) 1444 ! find products stochio 1445 do iw = 1,nwp 1446 stochio(indexchim(words(iw))) = stochio(indexchim(words(iw))) + 1 1447 end do 1448 ! get reaction product stochio and indice 1449 iloc = 3 1450 do ispe = 1,nesp 1451 if (stochio(ispe)==0) cycle 1452 iloc = iloc + 1 1453 nindice(iloc) = stochio(ispe) 1454 iindice(iloc) = ispe 1455 ! check up: to count the species used in 'reactfile' 1456 if (specheck(ispe)==0) then 1457 specheckp(ispe) = 1 1458 specheck(ispe) = 1 1459 nbq = nbq + 1 1460 else if (specheckp(ispe)==0) then 1461 specheckp(ispe) = 1 1462 end if 1463 end do 1464 ! fill reaction product stochio and indice 1465 reactions(ireact)%ip1 = nindice(4) 1466 reactions(ireact)%p1 = iindice(4) 1467 reactions(ireact)%ip2 = nindice(5) 1468 reactions(ireact)%p2 = iindice(5) 1469 reactions(ireact)%ip3 = nindice(6) 1470 reactions(ireact)%p3 = iindice(6) 1471 ! set reaction three prod to true with checking in position 6 if there is three different products 1472 if (nindice(6)/=0) reactions(ireact)%three_prod = .true. 1473 1474 1475 !-------------------------! 1476 !--- fill indice array ---! 1477 !-------------------------! 1478 1479 if (trim(reactions(ireact)%vtype)=="v4") then 1480 if (nindice(6)==0) then ! reaction with 1 or 2 products 1481 ! z4spec(ir1,r1,ir2,r2,ip1,p1,ip2,p2) 1482 indice_4(nb_reaction_4) = z4spec(nindice(1), iindice(1), nindice(2), iindice(2), nindice(4), iindice(4), nindice(5), iindice(5)) 1483 else ! reaction with 3 different products 1484 indice_4(nb_reaction_4) = z4spec(nindice(1)/2., iindice(1), nindice(2)/2., iindice(2), nindice(4), iindice(4), nindice(5)/2., iindice(5)) 1485 nb_reaction_4 = nb_reaction_4 + 1 1486 indice_4(nb_reaction_4) = z4spec(nindice(1)/2., iindice(1), nindice(2)/2., iindice(2), nindice(6), iindice(6), nindice(5)/2., iindice(5)) 1487 end if 1488 else if (trim(reactions(ireact)%vtype)=="v3") then 1489 if (nindice(6)==0) then ! reaction with 1 or 2 products 1490 ! z3spec(ir1,r1,ip1,p1,ip2,p2) 1491 indice_3(nb_reaction_3) = z3spec(nindice(1), iindice(1), nindice(4), iindice(4), nindice(5), iindice(5)) 1492 else ! reaction with 3 different products 1493 indice_3(nb_reaction_3) = z3spec(nindice(1)/2., iindice(1), nindice(4), iindice(4), 0.0, i_dummy) 1494 nb_reaction_3 = nb_reaction_3 + 1 1495 indice_3(nb_reaction_3) = z3spec(nindice(1)/2., iindice(1), nindice(5), iindice(5), nindice(6), iindice(6)) 1496 end if 1497 else if (trim(reactions(ireact)%vtype)=="vphot") then 1498 if (reactions(ireact)%rtype==0) then 1499 if (nindice(6)==0) then ! reaction with 1 or 2 products 1500 ! z3spec(ir1,r1,ip1,p1,ip2,p2) 1501 indice_phot(nb_phot_hv) = z3spec(nindice(1), iindice(1), nindice(4), iindice(4), nindice(5), iindice(5)) 1502 else ! reaction with 3 different products 1503 indice_phot(nb_phot_hv) = z3spec(nindice(1)/2., iindice(1), nindice(4), iindice(4), 0.0, i_dummy) 1504 nb_phot = nb_phot + 1 1505 nb_phot_hv = nb_phot_hv + 1 1506 indice_phot(nb_phot_hv) = z3spec(nindice(1)/2., iindice(1), nindice(5), iindice(5), nindice(6), iindice(6)) 1507 end if 1390 1508 else 1391 read(paramline,*) rtype(ireact), jlabel(nb_hv,1) 1509 if (nindice(6)==0) then ! reaction with 1 or 2 products 1510 ! z3spec(ir1,r1,ip1,p1,ip2,p2) 1511 indice_phot(nb_phot_hv_max+nb_phot-nb_phot_hv) = z3spec(nindice(1), iindice(1), nindice(4), iindice(4), nindice(5), iindice(5)) 1512 else ! reaction with 3 different products 1513 indice_phot(nb_phot_hv_max+nb_phot-nb_phot_hv) = z3spec(nindice(1)/2., iindice(1), nindice(4), iindice(4), 0.0, i_dummy) 1514 nb_phot = nb_phot + 1 1515 indice_phot(nb_phot_hv_max+nb_phot-nb_phot_hv) = z3spec(nindice(1)/2., iindice(1), nindice(5), iindice(5), nindice(6), iindice(6)) 1516 end if 1392 1517 end if 1393 else if (rtype(ireact)==2) then 1394 nb_pfunc2 = nb_pfunc2 + 1 1395 read(paramline,*) rtype(ireact), pfunc2_param(nb_pfunc2) 1396 else if (rtype(ireact)==3) then 1397 nb_pfunc3 = nb_pfunc3 + 1 1398 read(paramline,*) rtype(ireact), pfunc3_param(nb_pfunc3) 1399 end if 1518 else 1519 print*,'Error in photochemistry_asis (get_react):' 1520 print*,'vtype',reactions(ireact)%vtype,' not implemented' 1521 call abort 1400 1522 end if 1401 1523 1402 ! get reactants 1403 call split_str(reactline,words,nwr,nmax) 1404 if (rtype(ireact)==0) jlabel(nb_hv,2) = words(1) 1405 ! loop on reactants 1406 do iw=1,nwr 1407 ! store reactants in variable 'reactants' 1408 reactants(ireact,iw) = trim(words(iw)) 1409 ! check third body and exit reactants loop 1410 if (reactants(ireact,iw)=='M') then 1411 if (iw==nwr) then 1412 exit 1413 else if (iw==nwr-1) then 1414 third_body(ireact) = indexchim(words(iw+1)) 1415 exit 1416 else 1417 print*, 'Error in reactfile: just only one specie can be after M corresponding to the third body - line',ilines 1418 stop 1419 end if 1420 end if 1421 if (trim(words(iw))/='hv' .and. trim(words(iw))/='dummy') then 1422 iwhere = indexchim(words(iw)) 1423 ! check if species are chemical tracers 1424 if (iwhere>nesp) then 1425 print*, 'Error: in ', trim(reactfile) 1426 print*, 'check if the specie', trim(words(iw)),' is include into chemical tracers in traceur.def' 1427 stop 1428 end if 1429 ! to count the species used in 'reactfile' 1430 if (specheck(iwhere)==0) then 1431 specheckr(iwhere) = 1 1432 specheck(iwhere) = 1 1433 nbq = nbq + 1 1434 else if (specheckr(iwhere)==0) then 1435 specheckr(iwhere) = 1 1436 end if 1437 1438 !!!!!!!!!!!!!!!!!!! for fill indice part 1439 ! fill stochiometry and indice of rection species depending of reaction type 1440 if (trim(typeindice)=='v3') then 1441 nindice(1) = 2.0 1442 iindice(1) = indexchim(words(iw)) 1443 if (nwr>3 .or. nwr<2) print*, 'Error in reactfile: wrong number of reactants for v3 reaction line',ilines 1444 if (nwr==2 .and. trim(words(1))/=trim(words(2))) print*, 'Error in reactfile: both reactants should be the same for v3 reaction line',ilines 1445 else if (trim(typeindice)=='v4') then 1446 nindice(iw) = 1.0 1447 iindice(iw) = indexchim(words(iw)) 1448 else if (trim(typeindice)=='vphot') then 1449 nindice(1) = 1.0 1450 if (iw>2) then 1451 print*, 'Something weird in your photolysis reaction' 1452 print*, 'You should have 1 reactants and hv' 1453 print*, 'Reactants are: ',words 1454 stop 1455 end if 1456 iindice(1) = indexchim(words(iw)) 1457 end if 1458 !!!!!!!!!!!!!!!!!!! end 1459 1460 end if 1461 end do 1462 1463 ! same as reactants but for the products 1464 call split_str(prodline,words,nwp,nmax) 1465 do iw=1,nwp 1466 spedouble = .false. 1467 products(ireact,iw) = trim(words(iw)) 1468 if (trim(words(iw))/='hv' .and. trim(words(iw))/='dummy' .and. trim(words(iw))/='M') then 1469 iwhere = indexchim(words(iw)) 1470 if (iwhere>nesp) then 1471 print*, 'Error: in ', trim(reactfile) 1472 print*, 'check if the specie', trim(words(iw)),' is include into chemical tracers in traceur.def' 1473 stop 1474 end if 1475 if (specheck(iwhere)==0) then 1476 specheckp(iwhere) = 1 1477 specheck(iwhere) = 1 1478 nbq = nbq + 1 1479 else if (specheckp(iwhere)==0) then 1480 specheckp(iwhere) = 1 1481 end if 1482 1483 !!!!!!!!!!!!!!!!!!!!!!!!!! for fill indice part 1484 if (trim(typeindice)=='v3' .or. trim(typeindice)=='vphot') then 1485 iindice(1+iw) = indexchim(words(iw)) 1486 do i=1,iw-1 1487 if (iindice(1+iw)==iindice(1+i)) then 1488 nindice(1+i) = nindice(1+i) + 1.0 1489 iindice(1+iw) = i_dummy 1490 spedouble = .true. 1491 end if 1492 end do 1493 if (.not. spedouble) nindice(1+iw) = 1.0 1494 else if (trim(typeindice)=='v4') then 1495 iindice(2+iw) = indexchim(words(iw)) 1496 do i=1,iw-1 1497 if (iindice(2+iw)==iindice(2+i)) then 1498 nindice(2+i) = nindice(2+i) + 1.0 1499 iindice(2+iw) = i_dummy 1500 spedouble = .true. 1501 end if 1502 end do 1503 if (.not. spedouble) nindice(2+iw) = 1.0 1504 end if 1505 !!!!!!!!!!!!!!!!!!!!!!!!!!! end 1506 else 1507 print*, 'Error: no hv, dummy or M in products' 1508 stop 1509 end if 1510 end do 1511 1512 ! fill indice variables 1513 if (trim(typeindice)=='v3') then 1514 if (nindice(4)/=0.0) then ! reaction with 3 products 1515 if (nindice(3)==0.0) then ! 2 are the same species 1516 indice_3(nrtype) = z3spec(nindice(1), iindice(1), nindice(2), iindice(2), nindice(4), iindice(4)) 1517 else ! reaction with 3 different products 1518 indice_3(nrtype) = z3spec(nindice(1)/2., iindice(1), nindice(2), iindice(2), 0.0, i_dummy) 1519 nrtype = nrtype + 1 1520 indice_3(nrtype) = z3spec(nindice(1)/2., iindice(1), nindice(3), iindice(3), nindice(4), iindice(4)) 1521 three_prod(ireact) = .true. 1522 end if 1523 else ! reaction with 1 or 2 products 1524 indice_3(nrtype) = z3spec(nindice(1), iindice(1), nindice(2), iindice(2), nindice(3), iindice(3)) 1525 end if 1526 else if (trim(typeindice)=='v4') then 1527 if (nindice(5)/=0.0) then ! reaction with 3 products 1528 if (nindice(4)==0.0) then ! 2 are the same species 1529 indice_4(nrtype) = z4spec(nindice(1), iindice(1), nindice(2), iindice(2), nindice(3), iindice(3), nindice(5), iindice(5)) 1530 else ! reaction with 3 different products 1531 indice_4(nrtype) = z4spec(nindice(1)/2., iindice(1), nindice(2)/2., iindice(2), nindice(3), iindice(3), nindice(4)/2., iindice(4)) 1532 nrtype = nrtype + 1 1533 indice_4(nrtype) = z4spec(nindice(1)/2., iindice(1), nindice(2)/2., iindice(2), nindice(5), iindice(5), nindice(4)/2., iindice(4)) 1534 three_prod(ireact) = .true. 1535 end if 1536 else ! reaction with 1 or 2 products 1537 indice_4(nrtype) = z4spec(nindice(1), iindice(1), nindice(2), iindice(2), nindice(3), iindice(3), nindice(4), iindice(4)) 1538 end if 1539 else if (trim(typeindice)=='vphot') then 1540 if (nindice(4)/=0.0) then ! reaction with 3 products 1541 if (nindice(3)==0.0) then ! 2 are the same species 1542 indice_phot(nrtype) = z3spec(nindice(1), iindice(1), nindice(2), iindice(2), nindice(4), iindice(4)) 1543 else ! reaction with 3 different products 1544 indice_phot(nrtype) = z3spec(nindice(1)/2., iindice(1), nindice(2), iindice(2), 0.0, i_dummy) 1545 nrtype = nrtype + 1 1546 indice_phot(nrtype) = z3spec(nindice(1)/2., iindice(1), nindice(3), iindice(3), nindice(4), iindice(4)) 1547 three_prod(ireact) = .true. 1548 end if 1549 else ! reaction with 1 or 2 products 1550 indice_phot(nrtype) = z3spec(nindice(1), iindice(1), nindice(2), iindice(2), nindice(3), iindice(3)) 1551 end if 1552 end if 1553 1554 end if 1555 1556 end do 1557 1558 init_nb_pfunc1 = nb_pfunc1 1559 init_nb_pfunc2 = nb_pfunc2 1560 init_nb_pfunc3 = nb_pfunc3 1524 end if ! end if comment line 1525 1526 end do ! end loop on lines 1561 1527 1562 1528 close(402) -
trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_mod.F90
r2542 r2553 45 45 contains 46 46 47 subroutine init_photolysis(nlayer,nreact,three_prod) 48 47 subroutine init_photolysis(nlayer,nreact) 48 49 use types_asis, only: reactions 49 50 use tracer_h 50 51 use chimiedata_h, only: indexchim … … 53 54 integer, intent(in) :: nlayer ! number of atmospheric layers 54 55 integer, intent(in) :: nreact ! number of reactions in reactions files 55 logical, intent(in) :: three_prod(nreact) ! if the reaction have a three defferent products egal .true. 56 integer :: iphot,tdim_max,i3prod,nd,ij,iw,ilay 56 integer :: iphot,tdim_max,i3prod,ij,iw,ilay,ireact 57 57 integer :: specheck(nesp) 58 58 … … 94 94 endif 95 95 end do 96 nd = nb_hv_max97 96 98 97 ! Get temperature dimension and allocate 99 allocate(tdim(n d))98 allocate(tdim(nb_hv_max)) 100 99 tdim(:) = 1 101 100 tdim_max = 1 102 do iphot=1,n d101 do iphot=1,nb_hv_max 103 102 read(jparamline(iphot),*) tdim(iphot) 104 103 if (tdim(iphot) > tdim_max) tdim_max = tdim(iphot) … … 106 105 107 106 ! allocation 108 allocate(qy(nw,n d))109 allocate(xs(tdim_max,nw,n d))107 allocate(qy(nw,nb_hv_max)) 108 allocate(xs(tdim_max,nw,nb_hv_max)) 110 109 allocate(sj(nlayer,nw,nb_phot_hv_max)) 111 allocate(xs_temp(tdim_max,n d))110 allocate(xs_temp(tdim_max,nb_hv_max)) 112 111 xs(:,:,:) = 0. 113 112 xs_temp(:,:) = 0. … … 119 118 120 119 i3prod = 0 121 122 ! read and grid cross-sections (photolysis should be first reactions in monoreact file) 123 do iphot=1,nd 120 ireact = 0 121 122 ! read and grid cross-sections 123 do iphot=1,nb_hv_max 124 ireact = ireact + 1 124 125 call rdxsi(nw,wl,xs(:tdim(iphot),:,iphot),jparamline(iphot),xs_temp(:tdim(iphot),iphot),qy(:,iphot),tdim(iphot),jlabel(iphot+i3prod,2)) 125 if (three_prod(iphot)) i3prod = i3prod + 1 126 do while(reactions(ireact)%rtype/=0) 127 ireact = ireact + 1 128 end do 129 if (reactions(ireact)%three_prod) i3prod = i3prod + 1 126 130 end do 127 131 128 132 ! init sj for no temperature dependent cross sections (tdim.eq.1) 129 iphot = 0 130 ij = 0 133 iphot = 0 134 ij = 0 135 ireact = 0 131 136 do while(iphot<nb_phot_hv_max) 132 ij = ij + 1 133 iphot = iphot + 1 137 ij = ij + 1 138 iphot = iphot + 1 139 ireact = ireact + 1 134 140 if (tdim(ij).eq.1) then 135 141 do iw = 1,nw-1 … … 139 145 end do 140 146 endif 141 if (three_prod(ij)) then 147 do while(reactions(ireact)%rtype/=0) 148 ireact = ireact + 1 149 end do 150 if (reactions(ireact)%three_prod) then 142 151 iphot = iphot + 1 143 152 if (tdim(ij).eq.1) then … … 882 891 print*, 'ERROR: temperature cross section file' 883 892 print*, ' has to be sorted from low to high values' 884 print*, ' Check monoreactfile'893 print*, ' Check reactfile file' 885 894 stop 886 895 end if … … 903 912 write(*,*)'2) You can check if the file is in datadir/cross_sections/' 904 913 write(*,*)'3) You can change the input cross_sections file name in' 905 write(*,*)' chemestry/ monoreactfile for the specie:',trim(species)914 write(*,*)' chemestry/reactfile file for the specie:',trim(species) 906 915 stop 907 916 end if … … 960 969 write(*,*)'2) You can check if the file is in datadir/cross_sections/' 961 970 write(*,*)'3) You can change the input photodissociation yield file name in' 962 write(*,*)' chemestry/ monoreactfile for the specie:',trim(species)971 write(*,*)' chemestry/reactfile file for the specie:',trim(species) 963 972 stop 964 973 end if -
trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_online.F
r2542 r2553 4 4 $ zmmean, rm, 5 5 $ tau, sza, dist_sol, v_phot, e_phot, ig, ngrid, 6 $ nreact , three_prod)6 $ nreact) 7 7 8 8 !*********************************************************************** … … 21 21 use tracer_h 22 22 use chimiedata_h, only: indexchim 23 use types_asis, only: nb_phot_hv_max, nb_phot_max, jlabel 23 use types_asis, only: nb_phot_hv_max, nb_phot_max, jlabel, 24 $ reactions 24 25 25 26 implicit none … … 38 39 integer, intent(in) :: ig ! grid point index 39 40 integer, intent(in) :: nreact ! number of reactions in reactions files 40 logical, intent(in) :: three_prod(nreact) ! if the reaction have a three defferent products egal .true.41 41 42 42 ! output … … 71 71 real, dimension(0:nlayer,nlayer) :: dsdh 72 72 73 integer :: i, ilay, iw, ialt, iphot, ispe, ij, igas 73 integer :: i, ilay, iw, ialt, iphot, ispe, ij, igas, ireact 74 74 real :: deltaj 75 75 … … 85 85 !==== set temperature-dependent cross-sections and optical depths 86 86 87 iphot = 0 88 ij = 0 89 igas = 0 87 iphot = 0 88 ij = 0 89 igas = 0 90 ireact = 0 90 91 91 92 do while(iphot<nb_phot_hv_max) 92 ij = ij + 1 93 iphot = iphot + 1 93 ij = ij + 1 94 iphot = iphot + 1 95 ireact = ireact + 1 94 96 95 97 if (tdim(ij).eq.1) then … … 106 108 igas = igas + 1 107 109 end if 108 if (three_prod(ij)) iphot = iphot + 1 110 do while(reactions(ireact)%rtype/=0) 111 ireact = ireact + 1 112 end do 113 if (reactions(ireact)%three_prod) iphot = iphot + 1 109 114 else 110 115 call setsj(nb_phot_hv_max,nlayer,nw,temp,tdim(ij), … … 131 136 end do 132 137 133 if (three_prod(ij)) then 138 do while(reactions(ireact)%rtype/=0) 139 ireact = ireact + 1 140 end do 141 if (reactions(ireact)%three_prod) then 134 142 iphot = iphot + 1 135 143 do iw = 1,nw-1 -
trunk/LMDZ.GENERIC/libf/aeronostd/types_asis.F90
r2542 r2553 85 85 end type rtype3 86 86 87 ! reaction type 88 89 type reaction 90 character(5) :: vtype 91 integer :: rtype 92 integer :: third_body 93 logical :: three_prod 94 integer :: ir1 95 integer :: r1 96 integer :: ir2 97 integer :: r2 98 integer :: ir3 99 integer :: r3 100 integer :: ip1 101 integer :: p1 102 integer :: ip2 103 integer :: p2 104 integer :: ip3 105 integer :: p3 106 end type reaction 107 87 108 ! pfunc parameters for the reaction rates 88 109 … … 90 111 type(rtype2), allocatable, save :: pfunc2_param(:) 91 112 type(rtype3), allocatable, save :: pfunc3_param(:) 113 114 ! reactions attributs 115 116 type(reaction), allocatable, save :: reactions(:) 92 117 93 118 ! dimension of pfunc type variables
Note: See TracChangeset
for help on using the changeset viewer.