Changeset 3298 for palm/trunk/SOURCE/chem_gasphase_mod.f90
- Timestamp:
- Oct 2, 2018 12:21:11 PM (6 years ago)
- Location:
- palm/trunk/SOURCE
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SOURCE
- Property svn:mergeinfo changed
-
palm/trunk/SOURCE/chem_gasphase_mod.f90
r2766 r3298 1 1 MODULE chem_gasphase_mod 2 3 ! Mechanism: passive 4 ! 2 5 !------------------------------------------------------------------------------! 3 6 ! 4 7 ! ******Module chem_gasphase_mod is automatically generated by kpp4palm ****** 5 8 ! 6 ! *********Please do NOT change this Code ********* 9 ! *********Please do NOT change this Code,it will be ovewritten ********* 10 ! 11 !------------------------------------------------------------------------------! 12 ! This file was created by KPP (http://people.cs.vt.edu/asandu/Software/Kpp/) 13 ! and kpp4palm (created by Klaus Ketelsen). kpp4palm is an adapted version 14 ! of KP4 (Jöckel,P.,Kerkweg,A.,Pozzer,A.,Sander,R.,Tost,H.,Riede, 15 ! H.,Baumgaertner,A.,Gromov,S.,and Kern,B.,2010: Development cycle 2 of 16 ! the Modular Earth Submodel System (MESSy2),Geosci. Model Dev.,3,717-752, 17 ! https://doi.org/10.5194/gmd-3-717-2010). KP4 is part of the Modular Earth 18 ! Submodel System (MESSy),which is is available under the GNU General Public 19 ! License (GPL). 20 ! 21 ! KPP is free software; you can redistribute it and/or modify it under the terms 22 ! of the General Public Licence as published by the Free Software Foundation; 23 ! either version 2 of the License,or (at your option) any later version. 24 ! KPP is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; 25 ! without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 26 ! PURPOSE. See the GNU General Public Licence for more details. 7 27 ! 8 28 !------------------------------------------------------------------------------! … … 11 31 ! PALM is free software: you can redistribute it and/or modify it under the 12 32 ! terms of the GNU General Public License as published by the Free Software 13 ! Foundation, either version 3 of the License,or (at your option) any later33 ! Foundation,either version 3 of the License,or (at your option) any later 14 34 ! version. 15 35 ! 16 ! PALM is distributed in the hope that it will be useful, 36 ! PALM is distributed in the hope that it will be useful,but WITHOUT ANY 17 37 ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 38 ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 39 ! 20 40 ! You should have received a copy of the GNU General Public License along with 21 ! PALM. If not, 41 ! PALM. If not,see <http://www.gnu.org/licenses/>. 22 42 ! 23 43 ! Copyright 1997-2018 Leibniz Universitaet Hannover … … 30 50 ! Former revisions: 31 51 ! ----------------- 32 ! $Id: module_header 2460 2017-09-13 14:47:48Z forkel $ 33 ! Removed preprocessor directive __chem 34 ! 35 ! 2460 2017-09-13 14:47:48Z forkel 36 ! 37 ! 38 ! Variables for photolyis added 39 ! 40 ! 41 ! 52 ! $Id: chem_gasphase_mod.f90 3287 2018-09-28 10:19:58Z forkel $ 53 ! forkel June 2018: qvap,fakt added 54 ! forkel June 2018: reset case in Initialize,Integrate,Update_rconst 55 ! 56 ! 57 ! 3287 2018-09-28 10:19:58Z forkel 58 ! 59 ! forkel Sept. 2017: Variables for photolyis added 42 60 ! 43 61 ! … … 52 70 USE kinds, ONLY: dp=>wp 53 71 54 USE pegrid, ONLY: myid, threads_per_task72 USE pegrid, ONLY: myid, threads_per_task 55 73 56 74 IMPLICIT NONE 57 75 PRIVATE 58 !SAVE ! NOTE: OCCURS AGAIN IN AUTOMATICALLY GENERATED CODE...76 !SAVE ! note: occurs again in automatically generated code ... 59 77 60 78 ! PUBLIC :: IERR_NAMES … … 63 81 ! ,REQ_MCFCT,IP_MAX,jname 64 82 65 PUBLIC :: eqn_names, phot_names, spc_names83 PUBLIC :: eqn_names, phot_names, spc_names 66 84 PUBLIC :: nmaxfixsteps 67 PUBLIC :: atol, rtol68 PUBLIC :: nspec, nreact85 PUBLIC :: atol, rtol 86 PUBLIC :: nspec, nreact 69 87 PUBLIC :: temp 88 PUBLIC :: qvap 89 PUBLIC :: fakt 70 90 PUBLIC :: phot 71 91 PUBLIC :: rconst 72 92 PUBLIC :: nvar 73 93 PUBLIC :: nphot 74 75 PUBLIC :: initialize,integrate,update_rconst 94 PUBLIC :: vl_dim ! PUBLIC to ebable other MODULEs to distiguish between scalar and vec 95 96 PUBLIC :: initialize, integrate, update_rconst 76 97 PUBLIC :: chem_gasphase_integrate 77 98 PUBLIC :: initialize_kpp_ctrl … … 82 103 83 104 LOGICAL, PARAMETER :: l_vector = .FALSE. 84 INTEGER, PARAMETER :: i_lu_di = 0105 INTEGER, PARAMETER :: i_lu_di = 2 85 106 INTEGER, PARAMETER :: vl_dim = 1 86 107 INTEGER :: vl 87 108 88 109 INTEGER :: vl_glo 89 INTEGER :: is, ie110 INTEGER :: is, ie 90 111 91 INTEGER, DIMENSION(vl_dim) :: kacc,krej 112 113 INTEGER, DIMENSION(vl_dim) :: kacc, krej 92 114 INTEGER, DIMENSION(vl_dim) :: ierrv 93 LOGICAL :: data_loaded = . false.115 LOGICAL :: data_loaded = .FALSE. 94 116 ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 95 117 ! … … 107 129 ! 108 130 ! File : chem_gasphase_mod_Parameters.f90 109 ! Time : Fri Dec 8 11:54:15 2017110 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm131 ! Time : Tue Sep 25 18:34:57 2018 132 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 111 133 ! Equation file : chem_gasphase_mod.kpp 112 134 ! Output root filename : chem_gasphase_mod … … 120 142 121 143 ! NSPEC - Number of chemical species 122 INTEGER, PARAMETER :: nspec = 2144 INTEGER, PARAMETER :: nspec = 2 123 145 ! NVAR - Number of Variable species 124 INTEGER, PARAMETER :: nvar = 2146 INTEGER, PARAMETER :: nvar = 2 125 147 ! NVARACT - Number of Active species 126 INTEGER, PARAMETER :: nvaract = 2148 INTEGER, PARAMETER :: nvaract = 2 127 149 ! NFIX - Number of Fixed species 128 INTEGER, PARAMETER :: nfix = 1150 INTEGER, PARAMETER :: nfix = 1 129 151 ! NREACT - Number of reactions 130 INTEGER, PARAMETER :: nreact = 2152 INTEGER, PARAMETER :: nreact = 2 131 153 ! NVARST - Starting of variables in conc. vect. 132 INTEGER, PARAMETER :: nvarst = 1154 INTEGER, PARAMETER :: nvarst = 1 133 155 ! NFIXST - Starting of fixed in conc. vect. 134 INTEGER, PARAMETER :: nfixst = 3156 INTEGER, PARAMETER :: nfixst = 3 135 157 ! NONZERO - Number of nonzero entries in Jacobian 136 INTEGER, PARAMETER :: nonzero = 2158 INTEGER, PARAMETER :: nonzero = 2 137 159 ! LU_NONZERO - Number of nonzero entries in LU factoriz. of Jacobian 138 INTEGER, PARAMETER :: lu_nonzero = 2160 INTEGER, PARAMETER :: lu_nonzero = 2 139 161 ! CNVAR - (NVAR+1) Number of elements in compressed row format 140 INTEGER, PARAMETER :: cnvar = 3162 INTEGER, PARAMETER :: cnvar = 3 141 163 ! CNEQN - (NREACT+1) Number stoicm elements in compressed col format 142 INTEGER, PARAMETER :: cneqn = 3164 INTEGER, PARAMETER :: cneqn = 3 143 165 ! NHESS - Length of Sparse Hessian 144 INTEGER,PARAMETER :: nhess = 1 145 ! NLOOKAT - Number of species to look at 146 INTEGER,PARAMETER :: nlookat = 0 147 ! NMONITOR - Number of species to monitor 148 INTEGER,PARAMETER :: nmonitor = 0 166 INTEGER, PARAMETER :: nhess = 1 149 167 ! NMASS - Number of atoms to check mass balance 150 INTEGER, PARAMETER :: nmass = 1168 INTEGER, PARAMETER :: nmass = 1 151 169 152 170 ! Index declaration for variable species in C and VAR 153 171 ! VAR(ind_spc) = C(ind_spc) 154 172 155 INTEGER, PARAMETER,PUBLIC :: ind_pm10 = 1156 INTEGER, PARAMETER,PUBLIC :: ind_pm25 = 2173 INTEGER, PARAMETER, PUBLIC :: ind_pm10 = 1 174 INTEGER, PARAMETER, PUBLIC :: ind_pm25 = 2 157 175 158 176 ! Index declaration for fixed species in C … … 165 183 166 184 ! NJVRP - Length of sparse Jacobian JVRP 167 INTEGER, PARAMETER :: njvrp = 2185 INTEGER, PARAMETER :: njvrp = 2 168 186 169 187 ! NSTOICM - Length of Sparse Stoichiometric Matrix 170 INTEGER, PARAMETER :: nstoicm = 1188 INTEGER, PARAMETER :: nstoicm = 1 171 189 172 190 … … 186 204 ! 187 205 ! File : chem_gasphase_mod_Global.f90 188 ! Time : Fri Dec 8 11:54:15 2017189 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm206 ! Time : Tue Sep 25 18:34:57 2018 207 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 190 208 ! Equation file : chem_gasphase_mod.kpp 191 209 ! Output root filename : chem_gasphase_mod … … 207 225 REAL(kind=dp):: fix(nfix) 208 226 ! VAR,FIX are chunks of array C 209 equivalence( c(1),var(1))227 EQUIVALENCE( c(1), var(1)) 210 228 ! RCONST - Rate constants (global) 211 229 REAL(kind=dp):: rconst(nreact) 212 230 ! TIME - Current integration time 213 231 REAL(kind=dp):: time 214 ! SUN - Sunlight intensity between [0,1]215 REAL(kind=dp):: sun216 232 ! TEMP - Temperature 217 REAL(dp),dimension(:),allocatable :: temp 218 ! RTOLS - (scalar) Relative tolerance 219 REAL(kind=dp):: rtols 233 REAL(kind=dp):: temp 220 234 ! TSTART - Integration start time 221 235 REAL(kind=dp):: tstart 222 ! TEND - Integration end time223 REAL(kind=dp):: tend224 ! DT - Integration step225 REAL(kind=dp):: dt226 236 ! ATOL - Absolute tolerance 227 237 REAL(kind=dp):: atol(nvar) … … 230 240 ! STEPMIN - Lower bound for integration step 231 241 REAL(kind=dp):: stepmin 232 ! STEPMAX - Upper bound for integration step233 REAL(kind=dp):: stepmax234 242 ! CFACTOR - Conversion factor for concentration units 235 243 REAL(kind=dp):: cfactor 236 ! DDMTYPE - DDM sensitivity w.r.t.: 0=init.val.,1=params237 INTEGER :: ddmtype238 244 239 245 ! INLINED global variable declarations 240 246 241 ! declaration of global variable declarations for photolysis will come from 247 ! QVAP - Water vapor 248 REAL(kind=dp):: qvap 249 ! FAKT - Conversion factor 250 REAL(kind=dp):: fakt 251 242 252 243 253 ! INLINED global variable declarations … … 260 270 ! 261 271 ! File : chem_gasphase_mod_JacobianSP.f90 262 ! Time : Fri Dec 8 11:54:15 2017263 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm272 ! Time : Tue Sep 25 18:34:57 2018 273 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 264 274 ! Equation file : chem_gasphase_mod.kpp 265 275 ! Output root filename : chem_gasphase_mod … … 275 285 276 286 277 INTEGER, PARAMETER,DIMENSION(2):: lu_irow = (/ &287 INTEGER, PARAMETER, DIMENSION(2):: lu_irow = (/ & 278 288 1, 2 /) 279 289 280 INTEGER, PARAMETER,DIMENSION(2):: lu_icol = (/ &290 INTEGER, PARAMETER, DIMENSION(2):: lu_icol = (/ & 281 291 1, 2 /) 282 292 283 INTEGER, PARAMETER,DIMENSION(3):: lu_crow = (/ &293 INTEGER, PARAMETER, DIMENSION(3):: lu_crow = (/ & 284 294 1, 2, 3 /) 285 295 286 INTEGER, PARAMETER,DIMENSION(3):: lu_diag = (/ &296 INTEGER, PARAMETER, DIMENSION(3):: lu_diag = (/ & 287 297 1, 2, 3 /) 288 298 … … 304 314 ! 305 315 ! File : chem_gasphase_mod_Monitor.f90 306 ! Time : Fri Dec 8 11:54:15 2017307 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm316 ! Time : Tue Sep 25 18:34:57 2018 317 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 308 318 ! Equation file : chem_gasphase_mod.kpp 309 319 ! Output root filename : chem_gasphase_mod … … 315 325 316 326 317 CHARACTER(len=15), PARAMETER,DIMENSION(2):: spc_names = (/ &327 CHARACTER(len=15), PARAMETER, DIMENSION(2):: spc_names = (/ & 318 328 'PM10 ','PM25 ' /) 319 329 320 INTEGER,DIMENSION(1):: lookat 321 INTEGER,DIMENSION(1):: monitor 322 CHARACTER(len=15),DIMENSION(1):: smass 323 CHARACTER(len=100),PARAMETER,DIMENSION(2):: eqn_names = (/ & 330 CHARACTER(len=100), PARAMETER, DIMENSION(2):: eqn_names = (/ & 324 331 'PM10 --> PM10 ',& 325 332 'PM25 --> PM25 ' /) … … 329 336 ! inline f90_data: declaration of global variables for photolysis 330 337 ! REAL(kind=dp):: phot(nphot)must eventually be moved to global later for 331 INTEGER, PARAMETER :: nphot = 1338 INTEGER, PARAMETER :: nphot = 1 332 339 ! phot photolysis frequencies 333 340 REAL(kind=dp):: phot(nphot) 334 341 335 INTEGER, PARAMETER,PUBLIC :: j_no2 = 1336 337 CHARACTER(len=15), PARAMETER,DIMENSION(nphot):: phot_names = (/ &342 INTEGER, PARAMETER, PUBLIC :: j_no2 = 1 343 344 CHARACTER(len=15), PARAMETER, DIMENSION(nphot):: phot_names = (/ & 338 345 'J_NO2 '/) 339 346 … … 367 374 ! 368 375 ! File : chem_gasphase_mod_Initialize.f90 369 ! Time : Fri Dec 8 11:54:15 2017370 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm376 ! Time : Tue Sep 25 18:34:57 2018 377 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 371 378 ! Equation file : chem_gasphase_mod.kpp 372 379 ! Output root filename : chem_gasphase_mod … … 393 400 ! 394 401 ! File : chem_gasphase_mod_Integrator.f90 395 ! Time : Fri Dec 8 11:54:15 2017396 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm402 ! Time : Tue Sep 25 18:34:57 2018 403 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 397 404 ! Equation file : chem_gasphase_mod.kpp 398 405 ! Output root filename : chem_gasphase_mod … … 432 439 433 440 !~~~> statistics on the work performed by the rosenbrock method 434 INTEGER, PARAMETER :: nfun=1,njac=2,nstp=3,nacc=4,&435 nrej=5, ndec=6,nsol=7,nsng=8,&436 ntexit=1, nhexit=2,nhnew = 3441 INTEGER, PARAMETER :: nfun=1, njac=2, nstp=3, nacc=4, & 442 nrej=5, ndec=6, nsol=7, nsng=8, & 443 ntexit=1, nhexit=2, nhnew = 3 437 444 438 445 ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 451 458 ! 452 459 ! File : chem_gasphase_mod_LinearAlgebra.f90 453 ! Time : Fri Dec 8 11:54:15 2017454 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm460 ! Time : Tue Sep 25 18:34:57 2018 461 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 455 462 ! Equation file : chem_gasphase_mod.kpp 456 463 ! Output root filename : chem_gasphase_mod … … 478 485 ! 479 486 ! File : chem_gasphase_mod_Jacobian.f90 480 ! Time : Fri Dec 8 11:54:15 2017481 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm487 ! Time : Tue Sep 25 18:34:57 2018 488 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 482 489 ! Equation file : chem_gasphase_mod.kpp 483 490 ! Output root filename : chem_gasphase_mod … … 505 512 ! 506 513 ! File : chem_gasphase_mod_Function.f90 507 ! Time : Fri Dec 8 11:54:15 2017508 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm514 ! Time : Tue Sep 25 18:34:57 2018 515 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 509 516 ! Equation file : chem_gasphase_mod.kpp 510 517 ! Output root filename : chem_gasphase_mod … … 534 541 ! 535 542 ! File : chem_gasphase_mod_Rates.f90 536 ! Time : Fri Dec 8 11:54:15 2017537 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm543 ! Time : Tue Sep 25 18:34:57 2018 544 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 538 545 ! Equation file : chem_gasphase_mod.kpp 539 546 ! Output root filename : chem_gasphase_mod … … 560 567 ! 561 568 ! File : chem_gasphase_mod_Util.f90 562 ! Time : Fri Dec 8 11:54:15 2017563 ! Working directory : /home/forkel-r/palmstuff/work/chemistry201 71117/GASPHASE_PREPROC/tmp_kpp4palm569 ! Time : Tue Sep 25 18:34:57 2018 570 ! Working directory : /home/forkel-r/palmstuff/work/chemistry20180925/UTIL/chemistry/gasphase_preproc/tmp_kpp4palm 564 571 ! Equation file : chem_gasphase_mod.kpp 565 572 ! Output root filename : chem_gasphase_mod … … 575 582 576 583 ! notes: 577 ! - 578 ! - 579 ! - 580 ! - 581 ! - 582 ! - 583 ! - 584 ! - l_vector is automatically defined by kp4 585 ! - vl_dim is automatically defined by kp4 586 ! - i_lu_di is automatically defined by kp4 587 ! - wanted is automatically defined by xmecca 588 ! - icntrl rcntrl are automatically defined by kpp 589 ! - "USE messy_main_tools" is in MODULE_header of messy_mecca_kpp.f90 590 ! - SAVE will be automatically added by kp4 584 591 585 592 !SAVE … … 587 594 ! for fixed time step control 588 595 ! ... max. number of fixed time steps (sum must be 1) 589 INTEGER, PARAMETER :: nmaxfixsteps = 50596 INTEGER, PARAMETER :: nmaxfixsteps = 50 590 597 ! ... switch for fixed time stepping 591 LOGICAL, PUBLIC :: l_fixed_step = .false.592 INTEGER, PUBLIC :: nfsteps = 1598 LOGICAL, PUBLIC :: l_fixed_step = .FALSE. 599 INTEGER, PUBLIC :: nfsteps = 1 593 600 ! ... number of kpp control PARAMETERs 594 INTEGER, PARAMETER,PUBLIC :: nkppctrl = 20601 INTEGER, PARAMETER, PUBLIC :: nkppctrl = 20 595 602 ! 596 INTEGER, DIMENSION(nkppctrl), PUBLIC :: icntrl = 0597 REAL(dp), DIMENSION(nkppctrl),PUBLIC :: rcntrl = 0.0_dp598 REAL(dp), DIMENSION(nmaxfixsteps),PUBLIC :: t_steps = 0.0_dp603 INTEGER, DIMENSION(nkppctrl), PUBLIC :: icntrl = 0 604 REAL(dp), DIMENSION(nkppctrl), PUBLIC :: rcntrl = 0.0_dp 605 REAL(dp), DIMENSION(nmaxfixsteps), PUBLIC :: t_steps = 0.0_dp 599 606 600 607 ! END header MODULE initialize_kpp_ctrl_template … … 619 626 END INTERFACE kppsolve 620 627 628 INTERFACE jac_sp 629 MODULE PROCEDURE jac_sp 630 END INTERFACE jac_sp 631 632 INTERFACE k_arr 633 MODULE PROCEDURE k_arr 634 END INTERFACE k_arr 635 636 INTERFACE update_rconst 637 MODULE PROCEDURE update_rconst 638 END INTERFACE update_rconst 639 640 INTERFACE arr2 641 MODULE PROCEDURE arr2 642 END INTERFACE arr2 643 644 INTERFACE initialize_kpp_ctrl 645 MODULE PROCEDURE initialize_kpp_ctrl 646 END INTERFACE initialize_kpp_ctrl 647 648 INTERFACE error_output 649 MODULE PROCEDURE error_output 650 END INTERFACE error_output 651 652 INTERFACE wscal 653 MODULE PROCEDURE wscal 654 END INTERFACE wscal 655 656 !INTERFACE not working INTERFACE waxpy 657 !INTERFACE not working MODULE PROCEDURE waxpy 658 !INTERFACE not working END INTERFACE waxpy 659 660 INTERFACE rosenbrock 661 MODULE PROCEDURE rosenbrock 662 END INTERFACE rosenbrock 663 664 INTERFACE funtemplate 665 MODULE PROCEDURE funtemplate 666 END INTERFACE funtemplate 667 668 INTERFACE jactemplate 669 MODULE PROCEDURE jactemplate 670 END INTERFACE jactemplate 671 621 672 INTERFACE kppdecomp 622 673 MODULE PROCEDURE kppdecomp 623 674 END INTERFACE kppdecomp 624 675 625 INTERFACE wlamch626 MODULE PROCEDURE wlamch627 END INTERFACE wlamch628 629 INTERFACE wlamch_add630 MODULE PROCEDURE wlamch_add631 END INTERFACE wlamch_add632 633 INTERFACE jac_sp634 MODULE PROCEDURE jac_sp635 END INTERFACE jac_sp636 637 INTERFACE k_arr638 MODULE PROCEDURE k_arr639 END INTERFACE k_arr640 641 INTERFACE update_rconst642 MODULE PROCEDURE update_rconst643 END INTERFACE update_rconst644 645 INTERFACE arr2646 MODULE PROCEDURE arr2647 END INTERFACE arr2648 649 INTERFACE initialize_kpp_ctrl650 MODULE PROCEDURE initialize_kpp_ctrl651 END INTERFACE initialize_kpp_ctrl652 653 INTERFACE error_output654 MODULE PROCEDURE error_output655 END INTERFACE error_output656 657 !interface not working INTERFACE wcopy658 !interface not working MODULE PROCEDURE wcopy659 !interface not working END INTERFACE wcopy660 661 INTERFACE wscal662 MODULE PROCEDURE wscal663 END INTERFACE wscal664 665 !interface not working INTERFACE waxpy666 !interface not working MODULE PROCEDURE waxpy667 !interface not working END INTERFACE waxpy668 669 INTERFACE rosenbrock670 MODULE PROCEDURE rosenbrock671 END INTERFACE rosenbrock672 673 INTERFACE funtemplate674 MODULE PROCEDURE funtemplate675 END INTERFACE funtemplate676 677 INTERFACE jactemplate678 MODULE PROCEDURE jactemplate679 END INTERFACE jactemplate680 681 676 INTERFACE chem_gasphase_integrate 682 677 MODULE PROCEDURE chem_gasphase_integrate 683 678 END INTERFACE chem_gasphase_integrate 684 679 685 INTERFACE fill_temp686 MODULE PROCEDURE fill_temp687 END INTERFACE fill_temp688 PUBLIC fill_temp689 690 680 691 681 CONTAINS … … 694 684 695 685 686 INTEGER :: j, k 696 687 697 688 INTEGER :: i 698 689 REAL(kind=dp):: x 699 690 k = is 700 691 cfactor = 1.000000e+00_dp 701 692 702 x = (0.)*cfactor 703 DO i = 1,nvar 704 var(i) = x 693 x = (0.) * cfactor 694 DO i = 1 , nvar 705 695 ENDDO 706 696 707 x = (0.) *cfactor708 DO i = 1 ,nfix697 x = (0.) * cfactor 698 DO i = 1 , nfix 709 699 fix(i) = x 710 700 ENDDO … … 720 710 END SUBROUTINE initialize 721 711 722 SUBROUTINE integrate( tin, tout,&723 icntrl_u, rcntrl_u,istatus_u,rstatus_u,ierr_u)724 725 726 REAL(kind=dp), INTENT(in):: tin ! start time727 REAL(kind=dp), INTENT(in):: tout ! END time712 SUBROUTINE integrate( tin, tout, & 713 icntrl_u, rcntrl_u, istatus_u, rstatus_u, ierr_u) 714 715 716 REAL(kind=dp), INTENT(IN):: tin ! start time 717 REAL(kind=dp), INTENT(IN):: tout ! END time 728 718 ! OPTIONAL input PARAMETERs and statistics 729 INTEGER, INTENT( in), OPTIONAL :: icntrl_u(20)730 REAL(kind=dp), INTENT(in), OPTIONAL :: rcntrl_u(20)731 INTEGER, INTENT( out),OPTIONAL :: istatus_u(20)732 REAL(kind=dp), INTENT(out),OPTIONAL :: rstatus_u(20)733 INTEGER, INTENT( out),OPTIONAL :: ierr_u734 735 REAL(kind=dp):: rcntrl(20), rstatus(20)736 INTEGER :: icntrl(20), istatus(20),ierr737 738 INTEGER, SAVE :: ntotal = 0719 INTEGER, INTENT(IN), OPTIONAL :: icntrl_u(20) 720 REAL(kind=dp), INTENT(IN), OPTIONAL :: rcntrl_u(20) 721 INTEGER, INTENT(OUT), OPTIONAL :: istatus_u(20) 722 REAL(kind=dp), INTENT(OUT), OPTIONAL :: rstatus_u(20) 723 INTEGER, INTENT(OUT), OPTIONAL :: ierr_u 724 725 REAL(kind=dp):: rcntrl(20), rstatus(20) 726 INTEGER :: icntrl(20), istatus(20), ierr 727 728 INTEGER, SAVE :: ntotal = 0 739 729 740 730 icntrl(:) = 0 … … 744 734 745 735 !~~~> fine-tune the integrator: 746 icntrl(1) = 0 ! 0 - non- autonomous,1 -autonomous747 icntrl(2) = 0 ! 0 - vector tolerances,1 -scalars748 749 ! IF OPTIONAL PARAMETERs are given, and IF they are >0,736 icntrl(1) = 0 ! 0 - non- autonomous, 1 - autonomous 737 icntrl(2) = 0 ! 0 - vector tolerances, 1 - scalars 738 739 ! IF OPTIONAL PARAMETERs are given, and IF they are >0, 750 740 ! THEN they overwrite default settings. 751 IF ( present(icntrl_u))THEN752 where(icntrl_u(:)> 0)icntrl(:) = icntrl_u(:)741 IF (PRESENT(icntrl_u))THEN 742 WHERE(icntrl_u(:)> 0)icntrl(:) = icntrl_u(:) 753 743 ENDIF 754 IF ( present(rcntrl_u))THEN755 where(rcntrl_u(:)> 0)rcntrl(:) = rcntrl_u(:)744 IF (PRESENT(rcntrl_u))THEN 745 WHERE(rcntrl_u(:)> 0)rcntrl(:) = rcntrl_u(:) 756 746 ENDIF 757 747 758 748 759 CALL rosenbrock(nvar, var,tin,tout, &760 atol, rtol, &761 rcntrl, icntrl,rstatus,istatus,ierr)749 CALL rosenbrock(nvar, var, tin, tout, & 750 atol, rtol, & 751 rcntrl, icntrl, rstatus, istatus, ierr) 762 752 763 753 !~~~> debug option: show no of steps … … 768 758 ! IF OPTIONAL PARAMETERs are given for output they 769 759 ! are updated with the RETURN information 770 IF ( present(istatus_u))istatus_u(:) = istatus(:)771 IF ( present(rstatus_u))rstatus_u(:) = rstatus(:)772 IF ( present(ierr_u))ierr_u = ierr760 IF (PRESENT(istatus_u))istatus_u(:) = istatus(:) 761 IF (PRESENT(rstatus_u))rstatus_u(:) = rstatus(:) 762 IF (PRESENT(ierr_u)) ierr_u = ierr 773 763 774 764 END SUBROUTINE integrate 775 765 776 SUBROUTINE fun(v, f,rct,vdot)766 SUBROUTINE fun(v, f, rct, vdot) 777 767 778 768 ! V - Concentrations of variable species (local) … … 794 784 END SUBROUTINE fun 795 785 796 SUBROUTINE kppsolve(jvs, x)786 SUBROUTINE kppsolve(jvs, x) 797 787 798 788 ! JVS - sparse Jacobian of variables … … 801 791 REAL(kind=dp):: x(nvar) 802 792 803 x(2) = x(2) / jvs(2)804 x(1) = x(1) / jvs(1)793 x(2) = x(2) / jvs(2) 794 x(1) = x(1) / jvs(1) 805 795 806 796 END SUBROUTINE kppsolve 807 797 808 SUBROUTINE kppdecomp( jvs,ier) 809 ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 810 ! Sparse LU factorization 811 ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 812 813 814 INTEGER :: ier 815 REAL(kind=dp):: jvs(lu_nonzero),w(nvar),a 816 INTEGER :: k,kk,j,jj 817 818 a = 0. ! mz_rs_20050606 819 ier = 0 820 DO k=1,nvar 821 ! mz_rs_20050606: don't check if real value == 0 822 ! IF(jvs( lu_diag(k)).eq. 0.)THEN 823 IF(abs(jvs(lu_diag(k)))< tiny(a))THEN 824 ier = k 825 RETURN 826 ENDIF 827 DO kk = lu_crow(k),lu_crow(k+ 1)- 1 828 w( lu_icol(kk)) = jvs(kk) 829 ENDDO 830 DO kk = lu_crow(k),lu_diag(k)- 1 831 j = lu_icol(kk) 832 a = - w(j)/ jvs( lu_diag(j)) 833 w(j) = - a 834 DO jj = lu_diag(j)+ 1,lu_crow(j+ 1)- 1 835 w( lu_icol(jj)) = w( lu_icol(jj))+ a*jvs(jj) 836 ENDDO 837 ENDDO 838 DO kk = lu_crow(k),lu_crow(k+ 1)- 1 839 jvs(kk) = w( lu_icol(kk)) 840 ENDDO 841 ENDDO 842 843 END SUBROUTINE kppdecomp 844 845 REAL(kind=dp)FUNCTION wlamch( c) 846 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 847 ! returns epsilon machine 848 ! after LAPACK 849 ! replace this by the function from the optimized LAPACK implementation: 850 ! CALL SLAMCH('E') or CALL DLAMCH('E') 851 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 852 ! USE chem_gasphase_mod_Precision 853 854 CHARACTER :: c 855 INTEGER :: i 856 REAL(kind=dp),SAVE :: eps 857 REAL(kind=dp) :: suma 858 REAL(kind=dp),PARAMETER :: one=1.0_dp, half=0.5_dp 859 LOGICAL,SAVE :: first=.true. 860 861 IF (first)THEN 862 first = .false. 863 eps = half**(16) 864 DO i = 17,80 865 eps = eps*half 866 CALL wlamch_add(one,eps,suma) 867 IF (suma.le.one)goto 10 868 ENDDO 869 PRINT*,'ERROR IN WLAMCH. EPS < ',Eps 870 RETURN 871 10 eps = eps*2 872 i = i- 1 873 ENDIF 874 875 wlamch = eps 876 877 END FUNCTION wlamch 878 879 SUBROUTINE wlamch_add( a,b,suma) 880 ! USE chem_gasphase_mod_Precision 881 882 REAL(kind=dp)a,b,suma 883 suma = a + b 884 885 END SUBROUTINE wlamch_add 886 887 SUBROUTINE jac_sp(v,f,rct,jvs) 798 SUBROUTINE jac_sp(v, f, rct, jvs) 888 799 889 800 ! V - Concentrations of variable species (local) … … 914 825 END SUBROUTINE jac_sp 915 826 916 elemental REAL(kind=dp)FUNCTION k_arr (k_298, tdep,temp)827 elemental REAL(kind=dp)FUNCTION k_arr (k_298, tdep, temp) 917 828 ! arrhenius FUNCTION 918 829 919 REAL, INTENT( in):: k_298 ! k at t = 298.15k920 REAL, INTENT( in):: tdep ! temperature dependence921 REAL(kind=dp), INTENT(in):: temp ! temperature830 REAL, INTENT(IN):: k_298 ! k at t = 298.15k 831 REAL, INTENT(IN):: tdep ! temperature dependence 832 REAL(kind=dp), INTENT(IN):: temp ! temperature 922 833 923 834 intrinsic exp 924 835 925 k_arr = k_298 * exp(tdep*(1._dp/temp- 3.3540e-3_dp))! 1/298.15=3.3540e-3836 k_arr = k_298 * exp(tdep* (1._dp/temp- 3.3540e-3_dp))! 1/298.15=3.3540e-3 926 837 927 838 END FUNCTION k_arr 928 839 929 840 SUBROUTINE update_rconst() 930 INTEGER :: j,k841 INTEGER :: k 931 842 932 843 k = is … … 942 853 END SUBROUTINE update_rconst 943 854 944 REAL(kind=dp)FUNCTION arr2( a0,b0,temp) 855 ! END FUNCTION ARR2 856 REAL(kind=dp)FUNCTION arr2( a0, b0, temp) 945 857 REAL(kind=dp):: temp 946 REAL(kind=dp):: a0, b0947 arr2 = a0 * exp( - b0 / temp)858 REAL(kind=dp):: a0, b0 859 arr2 = a0 * exp( - b0 / temp) 948 860 END FUNCTION arr2 949 861 950 SUBROUTINE initialize_kpp_ctrl(status ,iou,modstr)862 SUBROUTINE initialize_kpp_ctrl(status) 951 863 952 864 953 865 ! i/o 954 INTEGER, INTENT(out):: status 955 INTEGER, INTENT(in) :: iou ! LOGICAL i/o unit 956 CHARACTER(len=*),INTENT(in) :: modstr ! read <modstr>.nml 866 INTEGER, INTENT(OUT):: status 957 867 958 868 ! local … … 962 872 ! check fixed time steps 963 873 tsum = 0.0_dp 964 DO i=1, nmaxfixsteps874 DO i=1, nmaxfixsteps 965 875 IF (t_steps(i)< tiny(0.0_dp))exit 966 876 tsum = tsum + t_steps(i) … … 982 892 WRITE(*,*) ' RCNTRL : ',rcntrl 983 893 ! 984 ! note: this is onlymeaningful for vectorized (kp4)rosenbrock- methods894 ! note: this is ONLY meaningful for vectorized (kp4)rosenbrock- methods 985 895 IF (l_vector)THEN 986 896 IF (l_fixed_step)THEN … … 1000 910 END SUBROUTINE initialize_kpp_ctrl 1001 911 1002 SUBROUTINE error_output(c, ierr,pe)1003 1004 1005 INTEGER, INTENT(in):: ierr1006 INTEGER, INTENT(in):: pe1007 REAL(dp), DIMENSION(:),INTENT(in):: c912 SUBROUTINE error_output(c, ierr, pe) 913 914 915 INTEGER, INTENT(IN):: ierr 916 INTEGER, INTENT(IN):: pe 917 REAL(dp), DIMENSION(:), INTENT(IN):: c 1008 918 1009 919 write(6,*) 'ERROR in chem_gasphase_mod ',ierr,C(1) … … 1012 922 END SUBROUTINE error_output 1013 923 1014 SUBROUTINE wcopy(n,x,incx,y,incy) 1015 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1016 ! copies a vector,x,to a vector,y: y <- x 1017 ! only for incX=incY=1 1018 ! after BLAS 1019 ! replace this by the function from the optimized BLAS implementation: 1020 ! CALL SCOPY(N,X,1,Y,1) or CALL DCOPY(N,X,1,Y,1) 1021 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1022 ! USE chem_gasphase_mod_Precision 1023 1024 INTEGER :: i,incx,incy,m,mp1,n 1025 REAL(kind=dp):: x(n),y(n) 1026 1027 IF (n.le.0)RETURN 1028 1029 m = mod(n,8) 1030 IF( m .ne. 0)THEN 1031 DO i = 1,m 1032 y(i) = x(i) 1033 ENDDO 1034 IF( n .lt. 8)RETURN 1035 ENDIF 1036 mp1 = m+ 1 1037 DO i = mp1,n,8 1038 y(i) = x(i) 1039 y(i + 1) = x(i + 1) 1040 y(i + 2) = x(i + 2) 1041 y(i + 3) = x(i + 3) 1042 y(i + 4) = x(i + 4) 1043 y(i + 5) = x(i + 5) 1044 y(i + 6) = x(i + 6) 1045 y(i + 7) = x(i + 7) 1046 ENDDO 1047 1048 END SUBROUTINE wcopy 1049 1050 SUBROUTINE wscal(n,alpha,x,incx) 924 SUBROUTINE wscal(n, alpha, x, incx) 1051 925 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1052 926 ! constant times a vector: x(1:N) <- Alpha*x(1:N) … … 1057 931 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1058 932 1059 INTEGER :: i, incx,m,mp1,n1060 REAL(kind=dp) :: x(n), alpha1061 REAL(kind=dp), PARAMETER :: zero=0.0_dp, one=1.0_dp933 INTEGER :: i, incx, m, mp1, n 934 REAL(kind=dp) :: x(n), alpha 935 REAL(kind=dp), PARAMETER :: zero=0.0_dp, one=1.0_dp 1062 936 1063 937 IF (alpha .eq. one)RETURN 1064 938 IF (n .le. 0)RETURN 1065 939 1066 m = mod(n, 5)1067 IF ( m .ne. 0)THEN940 m = mod(n, 5) 941 IF ( m .ne. 0)THEN 1068 942 IF (alpha .eq. (- one))THEN 1069 DO i = 1, m943 DO i = 1, m 1070 944 x(i) = - x(i) 1071 945 ENDDO 1072 946 ELSEIF (alpha .eq. zero)THEN 1073 DO i = 1, m947 DO i = 1, m 1074 948 x(i) = zero 1075 949 ENDDO 1076 950 ELSE 1077 DO i = 1, m1078 x(i) = alpha* x(i)951 DO i = 1, m 952 x(i) = alpha* x(i) 1079 953 ENDDO 1080 954 ENDIF 1081 IF ( n .lt. 5)RETURN955 IF ( n .lt. 5)RETURN 1082 956 ENDIF 1083 957 mp1 = m + 1 1084 958 IF (alpha .eq. (- one))THEN 1085 DO i = mp1, n,51086 x(i) 959 DO i = mp1, n, 5 960 x(i) = - x(i) 1087 961 x(i + 1) = - x(i + 1) 1088 962 x(i + 2) = - x(i + 2) … … 1091 965 ENDDO 1092 966 ELSEIF (alpha .eq. zero)THEN 1093 DO i = mp1, n,51094 x(i) 967 DO i = mp1, n, 5 968 x(i) = zero 1095 969 x(i + 1) = zero 1096 970 x(i + 2) = zero … … 1099 973 ENDDO 1100 974 ELSE 1101 DO i = mp1, n,51102 x(i) = alpha*x(i)1103 x(i + 1) = alpha* x(i + 1)1104 x(i + 2) = alpha* x(i + 2)1105 x(i + 3) = alpha* x(i + 3)1106 x(i + 4) = alpha* x(i + 4)975 DO i = mp1, n, 5 976 x(i) = alpha* x(i) 977 x(i + 1) = alpha* x(i + 1) 978 x(i + 2) = alpha* x(i + 2) 979 x(i + 3) = alpha* x(i + 3) 980 x(i + 4) = alpha* x(i + 4) 1107 981 ENDDO 1108 982 ENDIF … … 1110 984 END SUBROUTINE wscal 1111 985 1112 SUBROUTINE waxpy(n, alpha,x,incx,y,incy)986 SUBROUTINE waxpy(n, alpha, x, incx, y, incy) 1113 987 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1114 988 ! constant times a vector plus a vector: y <- y + Alpha*x … … 1119 993 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1120 994 1121 INTEGER :: i, incx,incy,m,mp1,n1122 REAL(kind=dp):: x(n), y(n),alpha1123 REAL(kind=dp), PARAMETER :: zero = 0.0_dp995 INTEGER :: i, incx, incy, m, mp1, n 996 REAL(kind=dp):: x(n), y(n), alpha 997 REAL(kind=dp), PARAMETER :: zero = 0.0_dp 1124 998 1125 999 IF (alpha .eq. zero)RETURN 1126 1000 IF (n .le. 0)RETURN 1127 1001 1128 m = mod(n, 4)1129 IF ( m .ne. 0)THEN1130 DO i = 1, m1131 y(i) = y(i) + alpha*x(i)1002 m = mod(n, 4) 1003 IF ( m .ne. 0)THEN 1004 DO i = 1, m 1005 y(i) = y(i) + alpha* x(i) 1132 1006 ENDDO 1133 IF ( n .lt. 4)RETURN1007 IF ( n .lt. 4)RETURN 1134 1008 ENDIF 1135 1009 mp1 = m + 1 1136 DO i = mp1, n,41137 y(i) = y(i) + alpha*x(i)1138 y(i + 1) = y(i + 1) + alpha*x(i + 1)1139 y(i + 2) = y(i + 2) + alpha*x(i + 2)1140 y(i + 3) = y(i + 3) + alpha*x(i + 3)1010 DO i = mp1, n, 4 1011 y(i) = y(i) + alpha* x(i) 1012 y(i + 1) = y(i + 1) + alpha* x(i + 1) 1013 y(i + 2) = y(i + 2) + alpha* x(i + 2) 1014 y(i + 3) = y(i + 3) + alpha* x(i + 3) 1141 1015 ENDDO 1142 1016 1143 1017 END SUBROUTINE waxpy 1144 1018 1145 SUBROUTINE rosenbrock(n, y,tstart,tend,&1146 abstol, reltol, &1147 rcntrl, icntrl,rstatus,istatus,ierr)1019 SUBROUTINE rosenbrock(n, y, tstart, tend, & 1020 abstol, reltol, & 1021 rcntrl, icntrl, rstatus, istatus, ierr) 1148 1022 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1149 1023 ! … … 1172 1046 !~~~> input arguments: 1173 1047 ! 1174 !- y(n)= vector of initial conditions (at t=tstart)1175 !- [tstart,tend] = time range of integration1048 !- y(n) = vector of initial conditions (at t=tstart) 1049 !- [tstart, tend] = time range of integration 1176 1050 ! (if Tstart>Tend the integration is performed backwards in time) 1177 !- reltol,abstol = user precribed accuracy1178 !- SUBROUTINE fun( t,y,ydot) = ode FUNCTION,1051 !- reltol, abstol = user precribed accuracy 1052 !- SUBROUTINE fun( t, y, ydot) = ode FUNCTION, 1179 1053 ! returns Ydot = Y' = F(T,Y) 1180 !- SUBROUTINE jac( t,y,jcb) = jacobian of the ode FUNCTION,1054 !- SUBROUTINE jac( t, y, jcb) = jacobian of the ode FUNCTION, 1181 1055 ! returns Jcb = dFun/dY 1182 !- icntrl(1:20)= INTEGER inputs PARAMETERs1183 !- rcntrl(1:20)= REAL inputs PARAMETERs1056 !- icntrl(1:20) = INTEGER inputs PARAMETERs 1057 !- rcntrl(1:20) = REAL inputs PARAMETERs 1184 1058 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1185 1059 ! 1186 1060 !~~~> output arguments: 1187 1061 ! 1188 !- y(n) - > vector of final states (at t- >tEND)1189 !- istatus(1:20)- > INTEGER output PARAMETERs1190 !- rstatus(1:20)- > REAL output PARAMETERs1191 !- 1062 !- y(n) - > vector of final states (at t- >tend) 1063 !- istatus(1:20) - > INTEGER output PARAMETERs 1064 !- rstatus(1:20) - > REAL output PARAMETERs 1065 !- ierr - > job status upon RETURN 1192 1066 ! success (positive value) or 1193 1067 ! failure (negative value) … … 1262 1136 1263 1137 !~~~> arguments 1264 INTEGER, INTENT( in):: n1265 REAL(kind=dp), INTENT(inout):: y(n)1266 REAL(kind=dp), INTENT(in) :: tstart,tend1267 REAL(kind=dp), INTENT(in) :: abstol(n),reltol(n)1268 INTEGER, INTENT( in):: icntrl(20)1269 REAL(kind=dp), INTENT(in):: rcntrl(20)1270 INTEGER, INTENT( inout):: istatus(20)1271 REAL(kind=dp), INTENT(inout):: rstatus(20)1272 INTEGER, INTENT(out):: ierr1273 !~~~> PARAMETERs of the rosenbrock method, up to 6 stages1274 INTEGER :: ros_s, rosmethod1275 INTEGER, PARAMETER :: rs2=1,rs3=2,rs4=3,rd3=4,rd4=5,rg3=61276 REAL(kind=dp):: ros_a(15), ros_c(15),ros_m(6),ros_e(6),&1277 ros_alpha(6), ros_gamma(6),ros_elo1138 INTEGER, INTENT(IN) :: n 1139 REAL(kind=dp), INTENT(INOUT):: y(n) 1140 REAL(kind=dp), INTENT(IN) :: tstart, tend 1141 REAL(kind=dp), INTENT(IN) :: abstol(n), reltol(n) 1142 INTEGER, INTENT(IN) :: icntrl(20) 1143 REAL(kind=dp), INTENT(IN) :: rcntrl(20) 1144 INTEGER, INTENT(INOUT):: istatus(20) 1145 REAL(kind=dp), INTENT(INOUT):: rstatus(20) 1146 INTEGER, INTENT(OUT) :: ierr 1147 !~~~> PARAMETERs of the rosenbrock method, up to 6 stages 1148 INTEGER :: ros_s, rosmethod 1149 INTEGER, PARAMETER :: rs2=1, rs3=2, rs4=3, rd3=4, rd4=5, rg3=6 1150 REAL(kind=dp):: ros_a(15), ros_c(15), ros_m(6), ros_e(6), & 1151 ros_alpha(6), ros_gamma(6), ros_elo 1278 1152 LOGICAL :: ros_newf(6) 1279 1153 CHARACTER(len=12):: ros_name 1280 1154 !~~~> local variables 1281 REAL(kind=dp):: roundoff, facmin,facmax,facrej,facsafe1282 REAL(kind=dp):: hmin, hmax,hstart1155 REAL(kind=dp):: roundoff, facmin, facmax, facrej, facsafe 1156 REAL(kind=dp):: hmin, hmax, hstart 1283 1157 REAL(kind=dp):: texit 1284 INTEGER :: i, uplimtol,max_no_steps1285 LOGICAL :: autonomous, vectortol1158 INTEGER :: i, uplimtol, max_no_steps 1159 LOGICAL :: autonomous, vectortol 1286 1160 !~~~> PARAMETERs 1287 REAL(kind=dp), PARAMETER :: zero = 0.0_dp, one = 1.0_dp1288 REAL(kind=dp), PARAMETER :: deltamin = 1.0e-5_dp1161 REAL(kind=dp), PARAMETER :: zero = 0.0_dp, one = 1.0_dp 1162 REAL(kind=dp), PARAMETER :: deltamin = 1.0e-5_dp 1289 1163 1290 1164 !~~~> initialize statistics … … 1298 1172 ! For Vector tolerances (ICNTRL(2) == 0) the code uses AbsTol(1:N) and RelTol(1:N) 1299 1173 IF (icntrl(2) == 0)THEN 1300 vectortol = . true.1174 vectortol = .TRUE. 1301 1175 uplimtol = n 1302 1176 ELSE 1303 vectortol = . false.1177 vectortol = .FALSE. 1304 1178 uplimtol = 1 1305 1179 ENDIF … … 1313 1187 CASE (3) 1314 1188 CALL ros4 1315 CASE (0, 4)1189 CASE (0, 4) 1316 1190 CALL rodas3 1317 1191 CASE (5) … … 1321 1195 CASE default 1322 1196 PRINT *,'Unknown Rosenbrock method: ICNTRL(3) =',ICNTRL(3) 1323 CALL ros_errormsg(- 2, tstart,zero,ierr)1197 CALL ros_errormsg(- 2, tstart, zero, ierr) 1324 1198 RETURN 1325 1199 END select … … 1332 1206 ELSE 1333 1207 PRINT *,'User-selected max no. of steps: ICNTRL(4) =',ICNTRL(4) 1334 CALL ros_errormsg(- 1, tstart,zero,ierr)1208 CALL ros_errormsg(- 1, tstart, zero, ierr) 1335 1209 RETURN 1336 1210 ENDIF 1337 1211 1338 1212 !~~~> unit roundoff (1+ roundoff>1) 1339 Roundoff = WLAMCH('E')1213 roundoff = epsilon(one) 1340 1214 1341 1215 !~~~> lower bound on the step size: (positive value) … … 1346 1220 ELSE 1347 1221 PRINT *,'User-selected Hmin: RCNTRL(1) =',RCNTRL(1) 1348 CALL ros_errormsg(- 3, tstart,zero,ierr)1222 CALL ros_errormsg(- 3, tstart, zero, ierr) 1349 1223 RETURN 1350 1224 ENDIF … … 1353 1227 hmax = abs(tend-tstart) 1354 1228 ELSEIF (rcntrl(2)> zero)THEN 1355 hmax = min(abs(rcntrl(2)), abs(tend-tstart))1229 hmax = min(abs(rcntrl(2)), abs(tend-tstart)) 1356 1230 ELSE 1357 1231 PRINT *,'User-selected Hmax: RCNTRL(2) =',RCNTRL(2) 1358 CALL ros_errormsg(- 3, tstart,zero,ierr)1232 CALL ros_errormsg(- 3, tstart, zero, ierr) 1359 1233 RETURN 1360 1234 ENDIF 1361 1235 !~~~> starting step size: (positive value) 1362 1236 IF (rcntrl(3) == zero)THEN 1363 hstart = max(hmin, deltamin)1237 hstart = max(hmin, deltamin) 1364 1238 ELSEIF (rcntrl(3)> zero)THEN 1365 hstart = min(abs(rcntrl(3)), abs(tend-tstart))1239 hstart = min(abs(rcntrl(3)), abs(tend-tstart)) 1366 1240 ELSE 1367 1241 PRINT *,'User-selected Hstart: RCNTRL(3) =',RCNTRL(3) 1368 CALL ros_errormsg(- 3, tstart,zero,ierr)1242 CALL ros_errormsg(- 3, tstart, zero, ierr) 1369 1243 RETURN 1370 1244 ENDIF … … 1376 1250 ELSE 1377 1251 PRINT *,'User-selected FacMin: RCNTRL(4) =',RCNTRL(4) 1378 CALL ros_errormsg(- 4, tstart,zero,ierr)1252 CALL ros_errormsg(- 4, tstart, zero, ierr) 1379 1253 RETURN 1380 1254 ENDIF … … 1385 1259 ELSE 1386 1260 PRINT *,'User-selected FacMax: RCNTRL(5) =',RCNTRL(5) 1387 CALL ros_errormsg(- 4, tstart,zero,ierr)1261 CALL ros_errormsg(- 4, tstart, zero, ierr) 1388 1262 RETURN 1389 1263 ENDIF … … 1395 1269 ELSE 1396 1270 PRINT *,'User-selected FacRej: RCNTRL(6) =',RCNTRL(6) 1397 CALL ros_errormsg(- 4, tstart,zero,ierr)1271 CALL ros_errormsg(- 4, tstart, zero, ierr) 1398 1272 RETURN 1399 1273 ENDIF … … 1405 1279 ELSE 1406 1280 PRINT *,'User-selected FacSafe: RCNTRL(7) =',RCNTRL(7) 1407 CALL ros_errormsg(- 4, tstart,zero,ierr)1281 CALL ros_errormsg(- 4, tstart, zero, ierr) 1408 1282 RETURN 1409 1283 ENDIF 1410 1284 !~~~> check IF tolerances are reasonable 1411 DO i=1, uplimtol1412 IF ((abstol(i)<= zero).or. (reltol(i)<= 10.0_dp*roundoff)&1285 DO i=1, uplimtol 1286 IF ((abstol(i)<= zero).or. (reltol(i)<= 10.0_dp* roundoff)& 1413 1287 .or. (reltol(i)>= 1.0_dp))THEN 1414 1288 PRINT *,' AbsTol(',i,') = ',AbsTol(i) 1415 1289 PRINT *,' RelTol(',i,') = ',RelTol(i) 1416 CALL ros_errormsg(- 5, tstart,zero,ierr)1290 CALL ros_errormsg(- 5, tstart, zero, ierr) 1417 1291 RETURN 1418 1292 ENDIF … … 1421 1295 1422 1296 !~~~> CALL rosenbrock method 1423 CALL ros_integrator(y, tstart,tend,texit, &1424 abstol, reltol, &1297 CALL ros_integrator(y, tstart, tend, texit, & 1298 abstol, reltol, & 1425 1299 ! Integration parameters 1426 autonomous, vectortol,max_no_steps, &1427 roundoff, hmin,hmax,hstart, &1428 facmin, facmax,facrej,facsafe, &1300 autonomous, vectortol, max_no_steps, & 1301 roundoff, hmin, hmax, hstart, & 1302 facmin, facmax, facrej, facsafe, & 1429 1303 ! Error indicator 1430 1304 ierr) … … 1435 1309 1436 1310 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1437 SUBROUTINE ros_errormsg(code, t,h,ierr)1311 SUBROUTINE ros_errormsg(code, t, h, ierr) 1438 1312 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1439 1313 ! Handles all error messages 1440 1314 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1441 1315 1442 REAL(kind=dp), INTENT(in):: t,h1443 INTEGER, INTENT(in) :: code1444 INTEGER, INTENT(out):: ierr1316 REAL(kind=dp), INTENT(IN):: t, h 1317 INTEGER, INTENT(IN) :: code 1318 INTEGER, INTENT(OUT):: ierr 1445 1319 1446 1320 ierr = code 1447 print * ,&1321 print * , & 1448 1322 'Forced exit from Rosenbrock due to the following error:' 1449 1323 1450 1324 select CASE (code) 1451 CASE (- 1) 1325 CASE (- 1) 1452 1326 PRINT *,'--> Improper value for maximal no of steps' 1453 CASE (- 2) 1327 CASE (- 2) 1454 1328 PRINT *,'--> Selected Rosenbrock method not implemented' 1455 CASE (- 3) 1329 CASE (- 3) 1456 1330 PRINT *,'--> Hmin/Hmax/Hstart must be positive' 1457 CASE (- 4) 1331 CASE (- 4) 1458 1332 PRINT *,'--> FacMin/FacMax/FacRej must be positive' 1459 1333 CASE (- 5) … … 1464 1338 PRINT *,'--> Step size too small: T + 10*H = T',& 1465 1339 ' or H < Roundoff' 1466 CASE (- 8) 1340 CASE (- 8) 1467 1341 PRINT *,'--> Matrix is repeatedly singular' 1468 1342 CASE default … … 1470 1344 END select 1471 1345 1472 print * ,"t=",t,"and h=",h1346 print * , "t=", t, "and h=", h 1473 1347 1474 1348 END SUBROUTINE ros_errormsg 1475 1349 1476 1350 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1477 SUBROUTINE ros_integrator (y, tstart,tend,t, &1478 abstol, reltol, &1351 SUBROUTINE ros_integrator (y, tstart, tend, t, & 1352 abstol, reltol, & 1479 1353 !~~~> integration PARAMETERs 1480 autonomous, vectortol,max_no_steps, &1481 roundoff, hmin,hmax,hstart, &1482 facmin, facmax,facrej,facsafe, &1354 autonomous, vectortol, max_no_steps, & 1355 roundoff, hmin, hmax, hstart, & 1356 facmin, facmax, facrej, facsafe, & 1483 1357 !~~~> error indicator 1484 1358 ierr) … … 1491 1365 1492 1366 !~~~> input: the initial condition at tstart; output: the solution at t 1493 REAL(kind=dp), INTENT(inout):: y(n)1367 REAL(kind=dp), INTENT(INOUT):: y(n) 1494 1368 !~~~> input: integration interval 1495 REAL(kind=dp), INTENT(in):: tstart,tend1496 !~~~> output: time at which the solution is RETURNed (t=t ENDIF success)1497 REAL(kind=dp), INTENT(out):: t1369 REAL(kind=dp), INTENT(IN):: tstart, tend 1370 !~~~> output: time at which the solution is RETURNed (t=tendIF success) 1371 REAL(kind=dp), INTENT(OUT):: t 1498 1372 !~~~> input: tolerances 1499 REAL(kind=dp), INTENT(in):: abstol(n),reltol(n)1373 REAL(kind=dp), INTENT(IN):: abstol(n), reltol(n) 1500 1374 !~~~> input: integration PARAMETERs 1501 LOGICAL, INTENT(in):: autonomous,vectortol1502 REAL(kind=dp), INTENT(in):: hstart,hmin,hmax1503 INTEGER, INTENT(in):: max_no_steps1504 REAL(kind=dp), INTENT(in):: roundoff,facmin,facmax,facrej,facsafe1375 LOGICAL, INTENT(IN):: autonomous, vectortol 1376 REAL(kind=dp), INTENT(IN):: hstart, hmin, hmax 1377 INTEGER, INTENT(IN):: max_no_steps 1378 REAL(kind=dp), INTENT(IN):: roundoff, facmin, facmax, facrej, facsafe 1505 1379 !~~~> output: error indicator 1506 INTEGER, INTENT(out):: ierr1380 INTEGER, INTENT(OUT):: ierr 1507 1381 ! ~~~~ Local variables 1508 REAL(kind=dp):: ynew(n), fcn0(n),fcn(n)1509 REAL(kind=dp):: k(n* ros_s),dfdt(n)1382 REAL(kind=dp):: ynew(n), fcn0(n), fcn(n) 1383 REAL(kind=dp):: k(n* ros_s), dfdt(n) 1510 1384 #ifdef full_algebra 1511 REAL(kind=dp):: jac0(n, n),ghimj(n,n)1385 REAL(kind=dp):: jac0(n, n), ghimj(n, n) 1512 1386 #else 1513 REAL(kind=dp):: jac0(lu_nonzero), ghimj(lu_nonzero)1387 REAL(kind=dp):: jac0(lu_nonzero), ghimj(lu_nonzero) 1514 1388 #endif 1515 REAL(kind=dp):: h, hnew,hc,hg,fac,tau1516 REAL(kind=dp):: err, yerr(n)1517 INTEGER :: pivot(n), direction,ioffset,j,istage1518 LOGICAL :: rejectlasth, rejectmoreh,singular1389 REAL(kind=dp):: h, hnew, hc, hg, fac, tau 1390 REAL(kind=dp):: err, yerr(n) 1391 INTEGER :: pivot(n), direction, ioffset, j, istage 1392 LOGICAL :: rejectlasth, rejectmoreh, singular 1519 1393 !~~~> local PARAMETERs 1520 REAL(kind=dp), PARAMETER :: zero = 0.0_dp, one = 1.0_dp1521 REAL(kind=dp), PARAMETER :: deltamin = 1.0e-5_dp1394 REAL(kind=dp), PARAMETER :: zero = 0.0_dp, one = 1.0_dp 1395 REAL(kind=dp), PARAMETER :: deltamin = 1.0e-5_dp 1522 1396 !~~~> locally called FUNCTIONs 1523 1397 ! REAL(kind=dp) WLAMCH … … 1529 1403 t = tstart 1530 1404 rstatus(nhexit) = zero 1531 h = min( max(abs(hmin), abs(hstart)),abs(hmax))1532 IF (abs(h)<= 10.0_dp* roundoff)h = deltamin1533 1534 IF (t END>= tstart)THEN1405 h = min( max(abs(hmin), abs(hstart)), abs(hmax)) 1406 IF (abs(h)<= 10.0_dp* roundoff)h = deltamin 1407 1408 IF (tend >= tstart)THEN 1535 1409 direction = + 1 1536 1410 ELSE 1537 1411 direction = - 1 1538 1412 ENDIF 1539 h = direction* h1540 1541 rejectlasth=. false.1542 rejectmoreh=. false.1413 h = direction* h 1414 1415 rejectlasth=.FALSE. 1416 rejectmoreh=.FALSE. 1543 1417 1544 1418 !~~~> time loop begins below 1545 1419 1546 timeloop: DO WHILE((direction > 0).and.((t- t END)+ roundoff <= zero)&1547 .or. (direction < 0).and.((tend-t) + roundoff <= zero))1548 1549 IF (istatus(nstp)> max_no_steps)THEN ! too many steps1550 CALL ros_errormsg(- 6, t,h,ierr)1420 timeloop: DO WHILE((direction > 0).and.((t- tend) + roundoff <= zero)& 1421 .or. (direction < 0).and.((tend-t) + roundoff <= zero)) 1422 1423 IF (istatus(nstp)> max_no_steps)THEN ! too many steps 1424 CALL ros_errormsg(- 6, t, h, ierr) 1551 1425 RETURN 1552 1426 ENDIF 1553 IF (((t+ 0.1_dp*h) == t).or.(h <= roundoff))THEN ! step size too small1554 CALL ros_errormsg(- 7, t,h,ierr)1427 IF (((t+ 0.1_dp* h) == t).or.(h <= roundoff))THEN ! step size too small 1428 CALL ros_errormsg(- 7, t, h, ierr) 1555 1429 RETURN 1556 1430 ENDIF 1557 1431 1558 1432 !~~~> limit h IF necessary to avoid going beyond tend 1559 h = min(h, abs(tend-t))1433 h = min(h, abs(tend-t)) 1560 1434 1561 1435 !~~~> compute the FUNCTION at current time 1562 CALL funtemplate(t, y,fcn0)1563 istatus(nfun) = istatus(nfun) + 11436 CALL funtemplate(t, y, fcn0) 1437 istatus(nfun) = istatus(nfun) + 1 1564 1438 1565 1439 !~~~> compute the FUNCTION derivative with respect to t 1566 1440 IF (.not.autonomous)THEN 1567 CALL ros_funtimederivative(t, roundoff,y,&1568 fcn0, dfdt)1441 CALL ros_funtimederivative(t, roundoff, y, & 1442 fcn0, dfdt) 1569 1443 ENDIF 1570 1444 1571 1445 !~~~> compute the jacobian at current time 1572 CALL jactemplate(t, y,jac0)1573 istatus(njac) = istatus(njac) + 11446 CALL jactemplate(t, y, jac0) 1447 istatus(njac) = istatus(njac) + 1 1574 1448 1575 1449 !~~~> repeat step calculation until current step accepted 1576 1450 untilaccepted: do 1577 1451 1578 CALL ros_preparematrix(h, direction,ros_gamma(1),&1579 jac0, ghimj,pivot,singular)1452 CALL ros_preparematrix(h, direction, ros_gamma(1), & 1453 jac0, ghimj, pivot, singular) 1580 1454 IF (singular)THEN ! more than 5 consecutive failed decompositions 1581 CALL ros_errormsg(- 8, t,h,ierr)1455 CALL ros_errormsg(- 8, t, h, ierr) 1582 1456 RETURN 1583 1457 ENDIF 1584 1458 1585 1459 !~~~> compute the stages 1586 stage: DO istage = 1, ros_s1460 stage: DO istage = 1, ros_s 1587 1461 1588 1462 ! current istage offset. current istage vector is k(ioffset+ 1:ioffset+ n) 1589 ioffset = n* (istage-1)1463 ioffset = n* (istage-1) 1590 1464 1591 1465 ! for the 1st istage the FUNCTION has been computed previously 1592 IF (istage == 1)THEN1593 !slim: CALL wcopy(n, fcn0,1,fcn,1)1594 1466 IF (istage == 1)THEN 1467 !slim: CALL wcopy(n, fcn0, 1, fcn, 1) 1468 fcn(1:n) = fcn0(1:n) 1595 1469 ! istage>1 and a new FUNCTION evaluation is needed at the current istage 1596 1470 ELSEIF(ros_newf(istage))THEN 1597 !slim: CALL wcopy(n, y,1,ynew,1)1598 1599 DO j = 1, istage-11600 CALL waxpy(n, ros_a((istage-1)*(istage-2)/2+ j),&1601 k(n* (j- 1)+ 1),1,ynew,1)1471 !slim: CALL wcopy(n, y, 1, ynew, 1) 1472 ynew(1:n) = y(1:n) 1473 DO j = 1, istage-1 1474 CALL waxpy(n, ros_a((istage-1) * (istage-2) /2+ j), & 1475 k(n* (j- 1) + 1), 1, ynew, 1) 1602 1476 ENDDO 1603 tau = t + ros_alpha(istage) *direction*h1604 CALL funtemplate(tau, ynew,fcn)1605 istatus(nfun) = istatus(nfun) + 11477 tau = t + ros_alpha(istage) * direction* h 1478 CALL funtemplate(tau, ynew, fcn) 1479 istatus(nfun) = istatus(nfun) + 1 1606 1480 ENDIF ! IF istage == 1 ELSEIF ros_newf(istage) 1607 !slim: CALL wcopy(n, fcn,1,k(ioffset+ 1),1)1481 !slim: CALL wcopy(n, fcn, 1, k(ioffset+ 1), 1) 1608 1482 k(ioffset+ 1:ioffset+ n) = fcn(1:n) 1609 DO j = 1, istage-11610 hc = ros_c((istage-1) *(istage-2)/2+ j)/(direction*h)1611 CALL waxpy(n, hc,k(n*(j- 1)+ 1),1,k(ioffset+ 1),1)1483 DO j = 1, istage-1 1484 hc = ros_c((istage-1) * (istage-2) /2+ j) /(direction* h) 1485 CALL waxpy(n, hc, k(n* (j- 1) + 1), 1, k(ioffset+ 1), 1) 1612 1486 ENDDO 1613 1487 IF ((.not. autonomous).and.(ros_gamma(istage).ne.zero))THEN 1614 hg = direction* h*ros_gamma(istage)1615 CALL waxpy(n, hg,dfdt,1,k(ioffset+ 1),1)1488 hg = direction* h* ros_gamma(istage) 1489 CALL waxpy(n, hg, dfdt, 1, k(ioffset+ 1), 1) 1616 1490 ENDIF 1617 CALL ros_solve(ghimj, pivot,k(ioffset+ 1))1491 CALL ros_solve(ghimj, pivot, k(ioffset+ 1)) 1618 1492 1619 1493 END DO stage … … 1621 1495 1622 1496 !~~~> compute the new solution 1623 !slim: CALL wcopy(n, y,1,ynew,1)1497 !slim: CALL wcopy(n, y, 1, ynew, 1) 1624 1498 ynew(1:n) = y(1:n) 1625 DO j=1, ros_s1626 CALL waxpy(n, ros_m(j),k(n*(j- 1)+ 1),1,ynew,1)1499 DO j=1, ros_s 1500 CALL waxpy(n, ros_m(j), k(n* (j- 1) + 1), 1, ynew, 1) 1627 1501 ENDDO 1628 1502 1629 1503 !~~~> compute the error estimation 1630 !slim: CALL wscal(n, zero,yerr,1)1504 !slim: CALL wscal(n, zero, yerr, 1) 1631 1505 yerr(1:n) = zero 1632 DO j=1, ros_s1633 CALL waxpy(n, ros_e(j),k(n*(j- 1)+ 1),1,yerr,1)1506 DO j=1, ros_s 1507 CALL waxpy(n, ros_e(j), k(n* (j- 1) + 1), 1, yerr, 1) 1634 1508 ENDDO 1635 err = ros_errornorm(y, ynew,yerr,abstol,reltol,vectortol)1509 err = ros_errornorm(y, ynew, yerr, abstol, reltol, vectortol) 1636 1510 1637 1511 !~~~> new step size is bounded by facmin <= hnew/h <= facmax 1638 fac = min(facmax, max(facmin,facsafe/err**(one/ros_elo)))1639 hnew = h* fac1512 fac = min(facmax, max(facmin, facsafe/err** (one/ros_elo))) 1513 hnew = h* fac 1640 1514 1641 1515 !~~~> check the error magnitude and adjust step size 1642 istatus(nstp) = istatus(nstp) + 11643 IF ((err <= one).or.(h <= hmin))THEN !~~~> accept step1644 istatus(nacc) = istatus(nacc) + 11645 !slim: CALL wcopy(n, ynew,1,y,1)1516 istatus(nstp) = istatus(nstp) + 1 1517 IF ((err <= one).or.(h <= hmin))THEN !~~~> accept step 1518 istatus(nacc) = istatus(nacc) + 1 1519 !slim: CALL wcopy(n, ynew, 1, y, 1) 1646 1520 y(1:n) = ynew(1:n) 1647 t = t + direction* h1648 hnew = max(hmin, min(hnew,hmax))1521 t = t + direction* h 1522 hnew = max(hmin, min(hnew, hmax)) 1649 1523 IF (rejectlasth)THEN ! no step size increase after a rejected step 1650 hnew = min(hnew, h)1524 hnew = min(hnew, h) 1651 1525 ENDIF 1652 1526 rstatus(nhexit) = h 1653 1527 rstatus(nhnew) = hnew 1654 1528 rstatus(ntexit) = t 1655 rejectlasth = . false.1656 rejectmoreh = . false.1529 rejectlasth = .FALSE. 1530 rejectmoreh = .FALSE. 1657 1531 h = hnew 1658 1532 exit untilaccepted ! exit the loop: WHILE step not accepted 1659 1533 ELSE !~~~> reject step 1660 1534 IF (rejectmoreh)THEN 1661 hnew = h* facrej1535 hnew = h* facrej 1662 1536 ENDIF 1663 1537 rejectmoreh = rejectlasth 1664 rejectlasth = . true.1538 rejectlasth = .TRUE. 1665 1539 h = hnew 1666 IF (istatus(nacc)>= 1) istatus(nrej) = istatus(nrej) + 11540 IF (istatus(nacc)>= 1) istatus(nrej) = istatus(nrej) + 1 1667 1541 ENDIF ! err <= 1 1668 1542 … … 1678 1552 1679 1553 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1680 REAL(kind=dp)FUNCTION ros_errornorm(y, ynew,yerr,&1681 abstol, reltol,vectortol)1554 REAL(kind=dp)FUNCTION ros_errornorm(y, ynew, yerr, & 1555 abstol, reltol, vectortol) 1682 1556 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1683 1557 !~~~> computes the "scaled norm" of the error vector yerr … … 1685 1559 1686 1560 ! Input arguments 1687 REAL(kind=dp), INTENT(in):: y(n),ynew(n),&1688 yerr(n), abstol(n),reltol(n)1689 LOGICAL, INTENT(in):: vectortol1561 REAL(kind=dp), INTENT(IN):: y(n), ynew(n), & 1562 yerr(n), abstol(n), reltol(n) 1563 LOGICAL, INTENT(IN):: vectortol 1690 1564 ! Local variables 1691 REAL(kind=dp):: err, scale,ymax1565 REAL(kind=dp):: err, scale, ymax 1692 1566 INTEGER :: i 1693 REAL(kind=dp), PARAMETER :: zero = 0.0_dp1567 REAL(kind=dp), PARAMETER :: zero = 0.0_dp 1694 1568 1695 1569 err = zero 1696 DO i=1, n1697 ymax = max(abs(y(i)), abs(ynew(i)))1570 DO i=1, n 1571 ymax = max(abs(y(i)), abs(ynew(i))) 1698 1572 IF (vectortol)THEN 1699 scale = abstol(i) + reltol(i)*ymax1573 scale = abstol(i) + reltol(i) * ymax 1700 1574 ELSE 1701 scale = abstol(1) + reltol(1)*ymax1575 scale = abstol(1) + reltol(1) * ymax 1702 1576 ENDIF 1703 err = err+ (yerr(i)/scale)**21577 err = err+ (yerr(i) /scale) ** 2 1704 1578 ENDDO 1705 1579 err = sqrt(err/n) 1706 1580 1707 ros_errornorm = max(err, 1.0d-10)1581 ros_errornorm = max(err, 1.0d-10) 1708 1582 1709 1583 END FUNCTION ros_errornorm … … 1711 1585 1712 1586 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1713 SUBROUTINE ros_funtimederivative(t, roundoff,y,&1714 fcn0, dfdt)1587 SUBROUTINE ros_funtimederivative(t, roundoff, y, & 1588 fcn0, dfdt) 1715 1589 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1716 1590 !~~~> the time partial derivative of the FUNCTION by finite differences … … 1718 1592 1719 1593 !~~~> input arguments 1720 REAL(kind=dp), INTENT(in):: t,roundoff,y(n),fcn0(n)1594 REAL(kind=dp), INTENT(IN):: t, roundoff, y(n), fcn0(n) 1721 1595 !~~~> output arguments 1722 REAL(kind=dp), INTENT(out):: dfdt(n)1596 REAL(kind=dp), INTENT(OUT):: dfdt(n) 1723 1597 !~~~> local variables 1724 1598 REAL(kind=dp):: delta 1725 REAL(kind=dp), PARAMETER :: one = 1.0_dp, deltamin = 1.0e-6_dp1726 1727 delta = sqrt(roundoff) *max(deltamin,abs(t))1728 CALL funtemplate(t+ delta, y,dfdt)1729 istatus(nfun) = istatus(nfun) + 11730 CALL waxpy(n, (- one),fcn0,1,dfdt,1)1731 CALL wscal(n, (one/delta),dfdt,1)1599 REAL(kind=dp), PARAMETER :: one = 1.0_dp, deltamin = 1.0e-6_dp 1600 1601 delta = sqrt(roundoff) * max(deltamin, abs(t)) 1602 CALL funtemplate(t+ delta, y, dfdt) 1603 istatus(nfun) = istatus(nfun) + 1 1604 CALL waxpy(n, (- one), fcn0, 1, dfdt, 1) 1605 CALL wscal(n, (one/delta), dfdt, 1) 1732 1606 1733 1607 END SUBROUTINE ros_funtimederivative … … 1735 1609 1736 1610 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1737 SUBROUTINE ros_preparematrix(h, direction,gam,&1738 jac0, ghimj,pivot,singular)1611 SUBROUTINE ros_preparematrix(h, direction, gam, & 1612 jac0, ghimj, pivot, singular) 1739 1613 ! --- --- --- --- --- --- --- --- --- --- --- --- --- 1740 1614 ! Prepares the LHS matrix for stage calculations … … 1748 1622 !~~~> input arguments 1749 1623 #ifdef full_algebra 1750 REAL(kind=dp), INTENT(in):: jac0(n,n)1624 REAL(kind=dp), INTENT(IN):: jac0(n, n) 1751 1625 #else 1752 REAL(kind=dp), INTENT(in):: jac0(lu_nonzero)1626 REAL(kind=dp), INTENT(IN):: jac0(lu_nonzero) 1753 1627 #endif 1754 REAL(kind=dp), INTENT(in):: gam1755 INTEGER, INTENT(in):: direction1628 REAL(kind=dp), INTENT(IN):: gam 1629 INTEGER, INTENT(IN):: direction 1756 1630 !~~~> output arguments 1757 1631 #ifdef full_algebra 1758 REAL(kind=dp), INTENT(out):: ghimj(n,n)1632 REAL(kind=dp), INTENT(OUT):: ghimj(n, n) 1759 1633 #else 1760 REAL(kind=dp), INTENT(out):: ghimj(lu_nonzero)1634 REAL(kind=dp), INTENT(OUT):: ghimj(lu_nonzero) 1761 1635 #endif 1762 LOGICAL, INTENT(out):: singular1763 INTEGER, INTENT(out):: pivot(n)1636 LOGICAL, INTENT(OUT):: singular 1637 INTEGER, INTENT(OUT):: pivot(n) 1764 1638 !~~~> inout arguments 1765 REAL(kind=dp), INTENT(inout):: h ! step size is decreased when lu fails1639 REAL(kind=dp), INTENT(INOUT):: h ! step size is decreased when lu fails 1766 1640 !~~~> local variables 1767 INTEGER :: i, ising,nconsecutive1641 INTEGER :: i, ising, nconsecutive 1768 1642 REAL(kind=dp):: ghinv 1769 REAL(kind=dp), PARAMETER :: one = 1.0_dp, half = 0.5_dp1643 REAL(kind=dp), PARAMETER :: one = 1.0_dp, half = 0.5_dp 1770 1644 1771 1645 nconsecutive = 0 1772 singular = . true.1646 singular = .TRUE. 1773 1647 1774 1648 DO WHILE (singular) 1775 1649 1776 !~~~> construct ghimj = 1/(h* gam)-jac01650 !~~~> construct ghimj = 1/(h* gam) - jac0 1777 1651 #ifdef full_algebra 1778 !slim: CALL wcopy(n* n,jac0,1,ghimj,1)1779 !slim: CALL wscal(n* n,(- one),ghimj,1)1652 !slim: CALL wcopy(n* n, jac0, 1, ghimj, 1) 1653 !slim: CALL wscal(n* n, (- one), ghimj, 1) 1780 1654 ghimj = - jac0 1781 ghinv = one/(direction* h*gam)1782 DO i=1, n1783 ghimj(i, i) = ghimj(i,i)+ ghinv1655 ghinv = one/(direction* h* gam) 1656 DO i=1, n 1657 ghimj(i, i) = ghimj(i, i) + ghinv 1784 1658 ENDDO 1785 1659 #else 1786 !slim: CALL wcopy(lu_nonzero, jac0,1,ghimj,1)1787 !slim: CALL wscal(lu_nonzero, (- one),ghimj,1)1660 !slim: CALL wcopy(lu_nonzero, jac0, 1, ghimj, 1) 1661 !slim: CALL wscal(lu_nonzero, (- one), ghimj, 1) 1788 1662 ghimj(1:lu_nonzero) = - jac0(1:lu_nonzero) 1789 ghinv = one/(direction* h*gam)1790 DO i=1, n1791 ghimj(lu_diag(i)) = ghimj(lu_diag(i)) + ghinv1663 ghinv = one/(direction* h* gam) 1664 DO i=1, n 1665 ghimj(lu_diag(i)) = ghimj(lu_diag(i)) + ghinv 1792 1666 ENDDO 1793 1667 #endif 1794 1668 !~~~> compute lu decomposition 1795 CALL ros_decomp( ghimj, pivot,ising)1669 CALL ros_decomp( ghimj, pivot, ising) 1796 1670 IF (ising == 0)THEN 1797 1671 !~~~> IF successful done 1798 singular = . false.1672 singular = .FALSE. 1799 1673 ELSE ! ising .ne. 0 1800 1674 !~~~> IF unsuccessful half the step size; IF 5 consecutive fails THEN RETURN 1801 istatus(nsng) = istatus(nsng) + 11675 istatus(nsng) = istatus(nsng) + 1 1802 1676 nconsecutive = nconsecutive+1 1803 singular = . true.1677 singular = .TRUE. 1804 1678 PRINT*,'Warning: LU Decomposition returned ISING = ',ISING 1805 1679 IF (nconsecutive <= 5)THEN ! less than 5 consecutive failed decompositions 1806 h = h* half1680 h = h* half 1807 1681 ELSE ! more than 5 consecutive failed decompositions 1808 1682 RETURN … … 1816 1690 1817 1691 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1818 SUBROUTINE ros_decomp( a, pivot,ising)1692 SUBROUTINE ros_decomp( a, pivot, ising) 1819 1693 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1820 1694 ! Template for the LU decomposition … … 1822 1696 !~~~> inout variables 1823 1697 #ifdef full_algebra 1824 REAL(kind=dp), INTENT(inout):: a(n,n)1698 REAL(kind=dp), INTENT(INOUT):: a(n, n) 1825 1699 #else 1826 REAL(kind=dp), INTENT(inout):: a(lu_nonzero)1700 REAL(kind=dp), INTENT(INOUT):: a(lu_nonzero) 1827 1701 #endif 1828 1702 !~~~> output variables 1829 INTEGER, INTENT(out):: pivot(n),ising1703 INTEGER, INTENT(OUT):: pivot(n), ising 1830 1704 1831 1705 #ifdef full_algebra 1832 CALL dgetrf( n, n,a,n,pivot,ising)1706 CALL dgetrf( n, n, a, n, pivot, ising) 1833 1707 #else 1834 CALL kppdecomp(a, ising)1708 CALL kppdecomp(a, ising) 1835 1709 pivot(1) = 1 1836 1710 #endif 1837 istatus(ndec) = istatus(ndec) + 11711 istatus(ndec) = istatus(ndec) + 1 1838 1712 1839 1713 END SUBROUTINE ros_decomp … … 1841 1715 1842 1716 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1843 SUBROUTINE ros_solve( a, pivot,b)1717 SUBROUTINE ros_solve( a, pivot, b) 1844 1718 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1845 1719 ! Template for the forward/backward substitution (using pre-computed LU decomposition) … … 1847 1721 !~~~> input variables 1848 1722 #ifdef full_algebra 1849 REAL(kind=dp), INTENT(in):: a(n,n)1723 REAL(kind=dp), INTENT(IN):: a(n, n) 1850 1724 INTEGER :: ising 1851 1725 #else 1852 REAL(kind=dp), INTENT(in):: a(lu_nonzero)1726 REAL(kind=dp), INTENT(IN):: a(lu_nonzero) 1853 1727 #endif 1854 INTEGER, INTENT(in):: pivot(n)1728 INTEGER, INTENT(IN):: pivot(n) 1855 1729 !~~~> inout variables 1856 REAL(kind=dp), INTENT(inout):: b(n)1730 REAL(kind=dp), INTENT(INOUT):: b(n) 1857 1731 1858 1732 #ifdef full_algebra 1859 1733 CALL DGETRS( 'N',N ,1,A,N,Pivot,b,N,ISING) 1860 IF (info < 0)THEN1861 print* ,"error in dgetrs. ising=",ising1734 IF (info < 0)THEN 1735 print* , "error in dgetrs. ising=", ising 1862 1736 ENDIF 1863 1737 #else 1864 CALL kppsolve( a, b)1738 CALL kppsolve( a, b) 1865 1739 #endif 1866 1740 1867 istatus(nsol) = istatus(nsol) + 11741 istatus(nsol) = istatus(nsol) + 1 1868 1742 1869 1743 END SUBROUTINE ros_solve … … 1893 1767 ! C(i,j) = ros_C( (i-1)*(i-2)/2 + j) 1894 1768 1895 ros_a(1) = (1.0_dp) /g1896 ros_c(1) = (- 2.0_dp) /g1769 ros_a(1) = (1.0_dp) /g 1770 ros_c(1) = (- 2.0_dp) /g 1897 1771 !~~~> does the stage i require a new FUNCTION evaluation (ros_newf(i) =true) 1898 1772 ! or does it re-use the function evaluation from stage i-1 (ros_NewF(i) =FALSE) 1899 ros_newf(1) = . true.1900 ros_newf(2) = . true.1773 ros_newf(1) = .TRUE. 1774 ros_newf(2) = .TRUE. 1901 1775 !~~~> m_i = coefficients for new step solution 1902 ros_m(1) = (3.0_dp) /(2.0_dp*g)1903 ros_m(2) = (1.0_dp) /(2.0_dp*g)1776 ros_m(1) = (3.0_dp) /(2.0_dp* g) 1777 ros_m(2) = (1.0_dp) /(2.0_dp* g) 1904 1778 ! E_i = Coefficients for error estimator 1905 ros_e(1) = 1.0_dp/(2.0_dp* g)1906 ros_e(2) = 1.0_dp/(2.0_dp* g)1907 !~~~> ros_elo = estimator of local order - 1779 ros_e(1) = 1.0_dp/(2.0_dp* g) 1780 ros_e(2) = 1.0_dp/(2.0_dp* g) 1781 !~~~> ros_elo = estimator of local order - the minimum between the 1908 1782 ! main and the embedded scheme orders plus one 1909 1783 ros_elo = 2.0_dp 1910 !~~~> y_stage_i ~ y( t + h* alpha_i)1784 !~~~> y_stage_i ~ y( t + h* alpha_i) 1911 1785 ros_alpha(1) = 0.0_dp 1912 1786 ros_alpha(2) = 1.0_dp 1913 !~~~> gamma_i = \sum_j gamma_{i, j}1787 !~~~> gamma_i = \sum_j gamma_{i, j} 1914 1788 ros_gamma(1) = g 1915 ros_gamma(2) = -g1789 ros_gamma(2) = -g 1916 1790 1917 1791 END SUBROUTINE ros2 … … 1946 1820 !~~~> does the stage i require a new FUNCTION evaluation (ros_newf(i) =true) 1947 1821 ! or does it re-use the function evaluation from stage i-1 (ros_NewF(i) =FALSE) 1948 ros_newf(1) = . true.1949 ros_newf(2) = . true.1950 ros_newf(3) = . false.1822 ros_newf(1) = .TRUE. 1823 ros_newf(2) = .TRUE. 1824 ros_newf(3) = .FALSE. 1951 1825 !~~~> m_i = coefficients for new step solution 1952 1826 ros_m(1) = 0.1e+01_dp … … 1957 1831 ros_e(2) = - 0.29079558716805469821718236208017e+01_dp 1958 1832 ros_e(3) = 0.22354069897811569627360909276199_dp 1959 !~~~> ros_elo = estimator of local order - 1833 !~~~> ros_elo = estimator of local order - the minimum between the 1960 1834 ! main and the embedded scheme orders plus 1 1961 1835 ros_elo = 3.0_dp 1962 !~~~> y_stage_i ~ y( t + h* alpha_i)1836 !~~~> y_stage_i ~ y( t + h* alpha_i) 1963 1837 ros_alpha(1) = 0.0_dp 1964 1838 ros_alpha(2) = 0.43586652150845899941601945119356_dp 1965 1839 ros_alpha(3) = 0.43586652150845899941601945119356_dp 1966 !~~~> gamma_i = \sum_j gamma_{i, j}1840 !~~~> gamma_i = \sum_j gamma_{i, j} 1967 1841 ros_gamma(1) = 0.43586652150845899941601945119356_dp 1968 1842 ros_gamma(2) = 0.24291996454816804366592249683314_dp … … 2007 1881 ros_a(6) = 0.0_dp 2008 1882 2009 ros_c(1) = -0.7137615036412310e+01_dp1883 ros_c(1) = -0.7137615036412310e+01_dp 2010 1884 ros_c(2) = 0.2580708087951457e+01_dp 2011 1885 ros_c(3) = 0.6515950076447975_dp 2012 ros_c(4) = -0.2137148994382534e+01_dp2013 ros_c(5) = -0.3214669691237626_dp2014 ros_c(6) = -0.6949742501781779_dp1886 ros_c(4) = -0.2137148994382534e+01_dp 1887 ros_c(5) = -0.3214669691237626_dp 1888 ros_c(6) = -0.6949742501781779_dp 2015 1889 !~~~> does the stage i require a new FUNCTION evaluation (ros_newf(i) =true) 2016 1890 ! or does it re-use the function evaluation from stage i-1 (ros_NewF(i) =FALSE) 2017 ros_newf(1) = . true.2018 ros_newf(2) = . true.2019 ros_newf(3) = . true.2020 ros_newf(4) = . false.1891 ros_newf(1) = .TRUE. 1892 ros_newf(2) = .TRUE. 1893 ros_newf(3) = .TRUE. 1894 ros_newf(4) = .FALSE. 2021 1895 !~~~> m_i = coefficients for new step solution 2022 1896 ros_m(1) = 0.2255570073418735e+01_dp … … 2025 1899 ros_m(4) = 0.1093502252409163e+01_dp 2026 1900 !~~~> e_i = coefficients for error estimator 2027 ros_e(1) = -0.2815431932141155_dp2028 ros_e(2) = -0.7276199124938920e-01_dp2029 ros_e(3) = -0.1082196201495311_dp2030 ros_e(4) = -0.1093502252409163e+01_dp2031 !~~~> ros_elo = estimator of local order - 1901 ros_e(1) = -0.2815431932141155_dp 1902 ros_e(2) = -0.7276199124938920e-01_dp 1903 ros_e(3) = -0.1082196201495311_dp 1904 ros_e(4) = -0.1093502252409163e+01_dp 1905 !~~~> ros_elo = estimator of local order - the minimum between the 2032 1906 ! main and the embedded scheme orders plus 1 2033 1907 ros_elo = 4.0_dp 2034 !~~~> y_stage_i ~ y( t + h* alpha_i)1908 !~~~> y_stage_i ~ y( t + h* alpha_i) 2035 1909 ros_alpha(1) = 0.0_dp 2036 1910 ros_alpha(2) = 0.1145640000000000e+01_dp 2037 1911 ros_alpha(3) = 0.6552168638155900_dp 2038 1912 ros_alpha(4) = ros_alpha(3) 2039 !~~~> gamma_i = \sum_j gamma_{i, j}1913 !~~~> gamma_i = \sum_j gamma_{i, j} 2040 1914 ros_gamma(1) = 0.5728200000000000_dp 2041 ros_gamma(2) = -0.1769193891319233e+01_dp1915 ros_gamma(2) = -0.1769193891319233e+01_dp 2042 1916 ros_gamma(3) = 0.7592633437920482_dp 2043 ros_gamma(4) = -0.1049021087100450_dp1917 ros_gamma(4) = -0.1049021087100450_dp 2044 1918 2045 1919 END SUBROUTINE ros4 … … 2074 1948 ros_c(1) = 4.0_dp 2075 1949 ros_c(2) = 1.0_dp 2076 ros_c(3) = -1.0_dp1950 ros_c(3) = -1.0_dp 2077 1951 ros_c(4) = 1.0_dp 2078 ros_c(5) = -1.0_dp2079 ros_c(6) = -(8.0_dp/3.0_dp)1952 ros_c(5) = -1.0_dp 1953 ros_c(6) = -(8.0_dp/3.0_dp) 2080 1954 2081 1955 !~~~> does the stage i require a new FUNCTION evaluation (ros_newf(i) =true) 2082 1956 ! or does it re-use the function evaluation from stage i-1 (ros_NewF(i) =FALSE) 2083 ros_newf(1) = . true.2084 ros_newf(2) = . false.2085 ros_newf(3) = . true.2086 ros_newf(4) = . true.1957 ros_newf(1) = .TRUE. 1958 ros_newf(2) = .FALSE. 1959 ros_newf(3) = .TRUE. 1960 ros_newf(4) = .TRUE. 2087 1961 !~~~> m_i = coefficients for new step solution 2088 1962 ros_m(1) = 2.0_dp … … 2095 1969 ros_e(3) = 0.0_dp 2096 1970 ros_e(4) = 1.0_dp 2097 !~~~> ros_elo = estimator of local order - 1971 !~~~> ros_elo = estimator of local order - the minimum between the 2098 1972 ! main and the embedded scheme orders plus 1 2099 1973 ros_elo = 3.0_dp 2100 !~~~> y_stage_i ~ y( t + h* alpha_i)1974 !~~~> y_stage_i ~ y( t + h* alpha_i) 2101 1975 ros_alpha(1) = 0.0_dp 2102 1976 ros_alpha(2) = 0.0_dp 2103 1977 ros_alpha(3) = 1.0_dp 2104 1978 ros_alpha(4) = 1.0_dp 2105 !~~~> gamma_i = \sum_j gamma_{i, j}1979 !~~~> gamma_i = \sum_j gamma_{i, j} 2106 1980 ros_gamma(1) = 0.5_dp 2107 1981 ros_gamma(2) = 1.5_dp … … 2129 2003 ros_s = 6 2130 2004 2131 !~~~> y_stage_i ~ y( t + h* alpha_i)2005 !~~~> y_stage_i ~ y( t + h* alpha_i) 2132 2006 ros_alpha(1) = 0.000_dp 2133 2007 ros_alpha(2) = 0.386_dp … … 2137 2011 ros_alpha(6) = 1.000_dp 2138 2012 2139 !~~~> gamma_i = \sum_j gamma_{i, j}2013 !~~~> gamma_i = \sum_j gamma_{i, j} 2140 2014 ros_gamma(1) = 0.2500000000000000_dp 2141 ros_gamma(2) = -0.1043000000000000_dp2015 ros_gamma(2) = -0.1043000000000000_dp 2142 2016 ros_gamma(3) = 0.1035000000000000_dp 2143 ros_gamma(4) = -0.3620000000000023e-01_dp2017 ros_gamma(4) = -0.3620000000000023e-01_dp 2144 2018 ros_gamma(5) = 0.0_dp 2145 2019 ros_gamma(6) = 0.0_dp … … 2160 2034 ros_a(8) = 0.6019134481288629e+01_dp 2161 2035 ros_a(9) = 0.1253708332932087e+02_dp 2162 ros_a(10) = -0.6878860361058950_dp2036 ros_a(10) = -0.6878860361058950_dp 2163 2037 ros_a(11) = ros_a(7) 2164 2038 ros_a(12) = ros_a(8) … … 2167 2041 ros_a(15) = 1.0_dp 2168 2042 2169 ros_c(1) = -0.5668800000000000e+01_dp2170 ros_c(2) = -0.2430093356833875e+01_dp2171 ros_c(3) = -0.2063599157091915_dp2172 ros_c(4) = -0.1073529058151375_dp2173 ros_c(5) = -0.9594562251023355e+01_dp2174 ros_c(6) = -0.2047028614809616e+02_dp2043 ros_c(1) = -0.5668800000000000e+01_dp 2044 ros_c(2) = -0.2430093356833875e+01_dp 2045 ros_c(3) = -0.2063599157091915_dp 2046 ros_c(4) = -0.1073529058151375_dp 2047 ros_c(5) = -0.9594562251023355e+01_dp 2048 ros_c(6) = -0.2047028614809616e+02_dp 2175 2049 ros_c(7) = 0.7496443313967647e+01_dp 2176 ros_c(8) = -0.1024680431464352e+02_dp2177 ros_c(9) = -0.3399990352819905e+02_dp2050 ros_c(8) = -0.1024680431464352e+02_dp 2051 ros_c(9) = -0.3399990352819905e+02_dp 2178 2052 ros_c(10) = 0.1170890893206160e+02_dp 2179 2053 ros_c(11) = 0.8083246795921522e+01_dp 2180 ros_c(12) = -0.7981132988064893e+01_dp2181 ros_c(13) = -0.3152159432874371e+02_dp2054 ros_c(12) = -0.7981132988064893e+01_dp 2055 ros_c(13) = -0.3152159432874371e+02_dp 2182 2056 ros_c(14) = 0.1631930543123136e+02_dp 2183 ros_c(15) = -0.6058818238834054e+01_dp2057 ros_c(15) = -0.6058818238834054e+01_dp 2184 2058 2185 2059 !~~~> m_i = coefficients for new step solution … … 2201 2075 !~~~> does the stage i require a new FUNCTION evaluation (ros_newf(i) =true) 2202 2076 ! or does it re-use the function evaluation from stage i-1 (ros_NewF(i) =FALSE) 2203 ros_newf(1) = . true.2204 ros_newf(2) = . true.2205 ros_newf(3) = . true.2206 ros_newf(4) = . true.2207 ros_newf(5) = . true.2208 ros_newf(6) = . true.2209 2210 !~~~> ros_elo = estimator of local order - 2077 ros_newf(1) = .TRUE. 2078 ros_newf(2) = .TRUE. 2079 ros_newf(3) = .TRUE. 2080 ros_newf(4) = .TRUE. 2081 ros_newf(5) = .TRUE. 2082 ros_newf(6) = .TRUE. 2083 2084 !~~~> ros_elo = estimator of local order - the minimum between the 2211 2085 ! main and the embedded scheme orders plus 1 2212 2086 ros_elo = 4.0_dp … … 2271 2145 !~~~> does the stage i require a new FUNCTION evaluation (ros_newf(i) =true) 2272 2146 ! or does it re-use the function evaluation from stage i-1 (ros_NewF(i) =FALSE) 2273 ros_newf(1) = . true.2274 ros_newf(2) = . true.2275 ros_newf(3) = . true.2276 ros_newf(4) = . true.2277 2278 !~~~> ros_elo = estimator of local order - 2147 ros_newf(1) = .TRUE. 2148 ros_newf(2) = .TRUE. 2149 ros_newf(3) = .TRUE. 2150 ros_newf(4) = .TRUE. 2151 2152 !~~~> ros_elo = estimator of local order - the minimum between the 2279 2153 ! main and the embedded scheme orders plus 1 2280 2154 ros_elo = 3.0_dp … … 2288 2162 END SUBROUTINE rosenbrock 2289 2163 2290 SUBROUTINE funtemplate( t, y,ydot)2164 SUBROUTINE funtemplate( t, y, ydot) 2291 2165 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2292 2166 ! Template for the ODE function call. … … 2294 2168 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2295 2169 !~~~> input variables 2296 REAL(kind=dp):: t, y(nvar)2170 REAL(kind=dp):: t, y(nvar) 2297 2171 !~~~> output variables 2298 2172 REAL(kind=dp):: ydot(nvar) … … 2302 2176 told = time 2303 2177 time = t 2304 CALL fun( y, fix,rconst,ydot)2178 CALL fun( y, fix, rconst, ydot) 2305 2179 time = told 2306 2180 2307 2181 END SUBROUTINE funtemplate 2308 2182 2309 SUBROUTINE jactemplate( t, y,jcb)2183 SUBROUTINE jactemplate( t, y, jcb) 2310 2184 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2311 2185 ! Template for the ODE Jacobian call. … … 2313 2187 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2314 2188 !~~~> input variables 2315 REAL(kind=dp):: t, y(nvar)2189 REAL(kind=dp):: t, y(nvar) 2316 2190 !~~~> output variables 2317 2191 #ifdef full_algebra 2318 REAL(kind=dp):: jv(lu_nonzero), jcb(nvar,nvar)2192 REAL(kind=dp):: jv(lu_nonzero), jcb(nvar, nvar) 2319 2193 #else 2320 2194 REAL(kind=dp):: jcb(lu_nonzero) … … 2323 2197 REAL(kind=dp):: told 2324 2198 #ifdef full_algebra 2325 INTEGER :: i, j2199 INTEGER :: i, j 2326 2200 #endif 2327 2201 … … 2329 2203 time = t 2330 2204 #ifdef full_algebra 2331 CALL jac_sp(y, fix,rconst,jv)2332 DO j=1, nvar2333 DO i=1, nvar2334 jcb(i, j) = 0.0_dp2205 CALL jac_sp(y, fix, rconst, jv) 2206 DO j=1, nvar 2207 DO i=1, nvar 2208 jcb(i, j) = 0.0_dp 2335 2209 ENDDO 2336 2210 ENDDO 2337 DO i=1, lu_nonzero2338 jcb(lu_irow(i), lu_icol(i)) = jv(i)2211 DO i=1, lu_nonzero 2212 jcb(lu_irow(i), lu_icol(i)) = jv(i) 2339 2213 ENDDO 2340 2214 #else 2341 CALL jac_sp( y, fix,rconst,jcb)2215 CALL jac_sp( y, fix, rconst, jcb) 2342 2216 #endif 2343 2217 time = told … … 2345 2219 END SUBROUTINE jactemplate 2346 2220 2347 SUBROUTINE chem_gasphase_integrate (time_step_len,conc,tempk,photo,ierrf,xnacc,xnrej,istatus,l_debug,pe) 2221 SUBROUTINE kppdecomp( jvs, ier) 2222 ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2223 ! sparse lu factorization 2224 ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2225 ! loop expansion generated by kp4 2226 2227 INTEGER :: ier 2228 REAL(kind=dp):: jvs(lu_nonzero), w(nvar), a 2229 INTEGER :: k, kk, j, jj 2230 2231 a = 0. 2232 ier = 0 2233 2234 ! i = 1 2235 ! i = 2 2236 RETURN 2237 2238 END SUBROUTINE kppdecomp 2239 2240 SUBROUTINE chem_gasphase_integrate (time_step_len, conc, tempi, qvapi, fakti, photo, ierrf, xnacc, xnrej, istatus, l_debug, pe, & 2241 icntrl_i, rcntrl_i) 2348 2242 2349 2243 IMPLICIT NONE 2350 2244 2351 REAL(dp), INTENT(IN) :: time_step_len 2352 REAL(dp), DIMENSION(:,:), INTENT(INOUT) :: conc 2353 REAL(dp), DIMENSION(:,:), INTENT(INOUT) :: photo 2354 REAL(dp), DIMENSION(:), INTENT(IN) :: tempk 2355 INTEGER, INTENT(OUT), OPTIONAL :: ierrf(:) 2356 INTEGER, INTENT(OUT), OPTIONAL :: xnacc(:) 2357 INTEGER, INTENT(OUT), OPTIONAL :: xnrej(:) 2358 INTEGER, INTENT(INOUT), OPTIONAL :: istatus(:) 2359 INTEGER, INTENT(IN), OPTIONAL :: pe 2360 LOGICAL, INTENT(IN), OPTIONAL :: l_debug 2245 REAL(dp), INTENT(IN) :: time_step_len 2246 REAL(dp), DIMENSION(:, :), INTENT(INOUT) :: conc 2247 REAL(dp), DIMENSION(:, :), INTENT(IN) :: photo 2248 REAL(dp), DIMENSION(:), INTENT(IN) :: tempi 2249 REAL(dp), DIMENSION(:), INTENT(IN) :: qvapi 2250 REAL(dp), DIMENSION(:), INTENT(IN) :: fakti 2251 INTEGER, INTENT(OUT), OPTIONAL :: ierrf(:) 2252 INTEGER, INTENT(OUT), OPTIONAL :: xnacc(:) 2253 INTEGER, INTENT(OUT), OPTIONAL :: xnrej(:) 2254 INTEGER, INTENT(INOUT), OPTIONAL :: istatus(:) 2255 INTEGER, INTENT(IN), OPTIONAL :: pe 2256 LOGICAL, INTENT(IN), OPTIONAL :: l_debug 2257 INTEGER, DIMENSION(nkppctrl), INTENT(IN), OPTIONAL :: icntrl_i 2258 REAL(dp), DIMENSION(nkppctrl), INTENT(IN), OPTIONAL :: rcntrl_i 2361 2259 2362 2260 INTEGER :: k ! loop variable 2363 REAL(dp) :: dt 2364 INTEGER, DIMENSION(20) :: istatus_u 2365 INTEGER :: ierr_u 2366 2367 2368 if (present (istatus)) istatus = 0 2369 2370 DO k=1,vl_glo,vl_dim 2261 REAL(dp) :: dt 2262 INTEGER, DIMENSION(20) :: istatus_u 2263 INTEGER :: ierr_u 2264 INTEGER :: istatf 2265 INTEGER :: vl_dim_lo 2266 2267 2268 IF (PRESENT (istatus)) istatus = 0 2269 IF (PRESENT (icntrl_i)) icntrl = icntrl_i 2270 IF (PRESENT (rcntrl_i)) rcntrl = rcntrl_i 2271 2272 vl_glo = size(tempi, 1) 2273 2274 vl_dim_lo = vl_dim 2275 DO k=1, vl_glo, vl_dim_lo 2371 2276 is = k 2372 ie = min(k+vl_dim-1,vl_glo) 2373 vl = ie-is+1 2374 2375 c(:) = conc(is,:) 2376 2377 temp = tempk(is) 2378 2379 phot(:) = photo(is,:) 2277 ie = min(k+ vl_dim_lo-1, vl_glo) 2278 vl = ie-is+ 1 2279 2280 c(:) = conc(is, :) 2281 2282 temp = tempi(is) 2283 2284 qvap = qvapi(is) 2285 2286 fakt = fakti(is) 2287 2288 CALL initialize 2289 2290 phot(:) = photo(is, :) 2380 2291 2381 2292 CALL update_rconst … … 2384 2295 2385 2296 ! integrate from t=0 to t=dt 2386 CALL integrate(0._dp, dt,icntrl,rcntrl,istatus_u = istatus_u,ierr_u=ierr_u) 2387 2388 2389 IF (PRESENT(l_debug) .AND. PRESENT(pe)) THEN 2390 IF (l_debug) CALL error_output(conc(is,:),ierr_u,pe) 2391 ENDIF 2392 conc(is,:) = c(:) 2393 2394 ! Return Diagnostic Information 2395 2396 if(PRESENT(ierrf)) ierrf(is) = ierr_u 2397 if(PRESENT(xnacc)) xnacc(is) = istatus_u(4) 2398 if(PRESENT(xnrej)) xnrej(is) = istatus_u(5) 2399 2400 if (PRESENT (istatus)) then 2401 istatus(1:8) = istatus(1:8) + istatus_u(1:8) 2297 CALL integrate(0._dp, dt, icntrl, rcntrl, istatus_u = istatus_u, ierr_u=ierr_u) 2298 2299 2300 IF (PRESENT(l_debug) .AND. PRESENT(pe)) THEN 2301 IF (l_debug) CALL error_output(conc(is, :), ierr_u, pe) 2302 ENDIF 2303 2304 conc(is, :) = c(:) 2305 2306 ! RETURN diagnostic information 2307 2308 IF (PRESENT(ierrf)) ierrf(is) = ierr_u 2309 IF (PRESENT(xnacc)) xnacc(is) = istatus_u(4) 2310 IF (PRESENT(xnrej)) xnrej(is) = istatus_u(5) 2311 2312 IF (PRESENT (istatus)) THEN 2313 istatus(1:8) = istatus(1:8) + istatus_u(1:8) 2402 2314 ENDIF 2403 2315 … … 2407 2319 ! Deallocate input arrays 2408 2320 2409 if (ALLOCATED(temp)) DEALLOCATE(temp) 2410 2411 data_loaded = .false. 2321 2322 data_loaded = .FALSE. 2412 2323 2413 2324 RETURN 2414 2325 END SUBROUTINE chem_gasphase_integrate 2415 2416 SUBROUTINE fill_temp(status,array)2417 2418 INTEGER, INTENT(OUT) :: status2419 REAL(dp), INTENT(IN), DIMENSION(:) :: array2420 2421 status = 02422 IF (.not. ALLOCATED(temp)) &2423 ALLOCATE(temp(size(array)))2424 2425 IF (data_loaded .AND. (vl_glo /= size(array,1))) THEN2426 status = 12427 RETURN2428 END IF2429 2430 vl_glo = size(array,1)2431 temp = array2432 data_loaded = .TRUE.2433 2434 RETURN2435 2436 END SUBROUTINE fill_temp2437 2326 2438 2327 END MODULE chem_gasphase_mod
Note: See TracChangeset
for help on using the changeset viewer.