source: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/bin/kpp4palm.sh @ 4843

Last change on this file since 4843 was 4843, checked in by raasch, 3 years ago

local namelist parameter added to switch off the module although the respective module namelist appears in the namelist file, further copyright updates

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 13.6 KB
RevLine 
[4451]1#!/bin/bash
[2696]2
[2699]3# kpp4palm - script for creating gasphase module
4
5#------------------------------------------------------------------------------#
6# This file is part of the PALM model system.
[2696]7#
[2699]8# PALM is free software: you can redistribute it and/or modify it under the terms
9# of the GNU General Public License as published by the Free Software Foundation,
10# either version 3 of the License, or (at your option) any later version.
[2696]11#
[2699]12# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
[2696]15#
[2699]16# You should have received a copy of the GNU General Public License along with
17# PALM. If not, see <http://www.gnu.org/licenses/>.
18#
[4843]19# Copyright 2017-2021  Klaus Ketelsen and MPI-CH (April 2007)
20# Copyright 2017-2021  Karlsruhe Institute of Technology
21# Copyright 2017-2021  Leibniz Universitaet Hannover
[2699]22#------------------------------------------------------------------------------#
[3298]23# Nov. 2016: Initial Version of KPP chemistry convertor adapted for PALM
24# by Klaus Ketelsen
[2699]25#
[3298]26# This code is a modified version of KP4 (Jöckel, P., Kerkweg, A., Pozzer, A.,
27# Sander, R., Tost, H., Riede, H., Baumgaertner, A., Gromov, S., and Kern, B.,
28# 2010: Development cycle 2 of the Modular Earth Submodel System (MESSy2),
29# Geosci. Model Dev., 3, 717-752, https://doi.org/10.5194/gmd-3-717-2010).
30# KP4 is part of the Modular Earth Submodel System (MESSy), which is is
31# available under the  GNU General Public License (GPL).
32#
33#------------------------------------------------------------------------------#
34#
[2696]35# Current revisions:
36# ------------------
37#
38#
39# Former revisions:
40# -----------------
[2699]41# $Id: kpp4palm.sh 4843 2021-01-15 15:22:11Z raasch $
[4454]42# Changed default mechanism from smog to phstatp
43#
44#
45# 4451 2020-03-10 07:25:32Z raasch
[4451]46# rename kpp4palm.ksh to kpp4palm.sh, convert to bash
47#
48# 3800 2019-03-15 16:40:25Z forkel
[3799]49# Removed edit of phot(nphot) for version edit phot(nphot), now done in fortran_file.C (15.03.2019, forkel)
[3800]50# Editing with sed to add dummy statements toavoud unused variables (15.03.2019, forkel)
[3799]51#
52# 3780 2019-03-05 11:19:45Z forkel
[3780]53# forkel   05. March 2019: cs_mech and set_cm
[3458]54# forkel   30. Oktober 2018: Integrating contents of kp4_compress into chem_gasphase_mod.f90
[3298]55# forkel   25. September 2018: Added cat for $MECH to pass mechanism name to kpp4palm
56# ketelsen 18. September 2018: Added cat for '#INLINE F90_GLOBAL'
57# (moved here from mechanisms/def_MECH/chem_gasphase.kpp
58#
59# forkel: 14. September  2018: WCOPY removed
60# ketelsen: July 2018: Adaptations for vektor mode
61# forkel June 2018: re-established original case of subroutine names
62# forkel May 2018: additional copying of chem_gasphase_mod.f90 into $DEFDIR
63# forkel 20.04.2018: removed  wlamch and wlamch_add from $KPP_SUBROUTINE_LIST
64#                    (epsilon(one) is used now)
65# forkel March 2017
66# Re-introduced relative path for KPP_HOME
67# Subroutine list adapted to lowercase subroutine names
68# Added arr2, removed update_sun and k_3rd from subroutine list
69# Renamed output file to chem_gasphase_mod
70# Renamed this file from kp4/ksh to kpp4kpp.ksh
71# changed location of def_mechanism directories to gasphase_preproc/mechanisms
72#
73#
74# 2718 2018-01-02 08:49:38Z maronga
[2699]75# Initial revision
76#
77#
[3298]78##########################################################################
[2696]79#
[2699]80#
81# Other notes:
82# ------------#
[2696]83# Re-introduced relative path for KPP_HOME
84# Subroutine list adapted to lowercase subroutine names
85# Added arr2, removed update_sun and k_3rd from subroutine list
86# Renamed output file to chem_gasphase_mod
87# Renamed this fikle from kp4/ksh to kpp4kpp.ksh
88# changed location of def_mechanism directories to GASPHASE_PREPROC/mechanisms
89#
90# Nov. 2016: Initial Version of KPP chemistry convertor by Klaus Ketelsen
91#
92#
93
94set -eu
95
96
97########################### User SetUp ####################################
98
99export KPP_HOME=`pwd`/kpp
100export KPP=$KPP_HOME/bin/kpp
101
102BASE=`pwd`/kpp4palm
103
104########################## End User Setup ################################
105
106WORK=tmp_kpp4palm
107
108# Default
109
[4454]110MECH=phstatp
[2699]111OUTDIR=`pwd`/../../../SOURCE
[2696]112OUTFILE=chem_gasphase_mod
[4454]113DEFDIR=`pwd`/mechanisms/def_phastatp
[2696]114PREFIX=chem_gasphase_mod
115MODE="scalar"
116VLEN=1
117KEEP="NO"
[3298]118UPDT="NO"
119DE_INDEX=0
120DE_INDEX_FAST="YES"
[2696]121
122export KPP_SOLVER=Rosenbrock
123
124# get Command line option
125
[3298]126while  getopts :m:i:fkup:o:s:vl:w:  c     # get options
[2696]127do case $c in
[3298]128      m)   MECH=$OPTARG;;            # mechanism
[2696]129
[3298]130      i)   DE_INDEX=$OPTARG;;        # if set, deindexing
[2696]131
132      f)   DE_INDEX_FAST="YES";;     # if set, fast deindexing
133
134      k)   KEEP="YES";;              # keep Working directory
135
[3458]136      o)   OUTDIR=$OPTARG;;          # Output directory of Generated Code =
137                                     # SOURCE directory (do not change)
[2696]138
[3458]139      p)   PREFIX=$OPTARG;;          # Name Prefix (chem_gasphase_mod, do not change)
[2696]140
[3458]141      s)   KPP_SOLVER=$OPTARG;;      # Chosen solver (only Rosebrock solvers work for vector mode)
[2696]142
[3458]143      u)   UPDT="YES";;              # update mechanisms/def_$MECH/chem_gasphase_mod.f90
[2696]144
[3298]145      v)   MODE="vector";;           # Set to vector Mode
146
147      l)   VLEN=$OPTARG;;            # Set vector length
148
[2696]149      w)   WORK=$OPTARG;;            # Working directory
150
151      \?)  print ${0##*/} "unknown option:" $OPTARG
[3298]152           print "USAGE: ${0##*/} [ -m dir -e -k -u -o dir -p name -s solver -v -l length -w dir ] "
[2696]153           exit 1;;
154   esac
155done
156
[3298]157echo MECHANISM = $MECH
158echo DE_INDEX = $DE_INDEX
159echo KEEP = $KEEP
160echo UPDT = $UPDT
161echo MODE = $MODE
162echo VLEN = $VLEN
[2696]163
164DEF_PREFIX=${PREFIX}.kpp
[3298]165DEFDIR=`pwd`/mechanisms/def_$MECH
166echo DEFDIR = $DEFDIR
[2696]167
168# Create or clean working directory
169
170MY_PWD=`pwd`
171mkdir -p $WORK
172rm -rf $WORK/*
173cd $WORK
174
175# kpp dependend, may be changed
176
177KPP_FILE_LIST="Initialize Integrator LinearAlgebra Jacobian Function Rates Util"
[3458]178if [[ $MODE = "vector" ]]
179 then
180KPP_FILE_LIST="$KPP_FILE_LIST kp4_compress_subroutines"
181fi
[2696]182
[3298]183KPP_SUBROUTINE_LIST="Initialize"
184KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST INTEGRATE Fun"
185KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppSolve KppDecomp"
186KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Jac_SP k_arr "
187KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Update_RCONST ARR2"
[2696]188KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST initialize_kpp_ctrl error_output"
189
190# if [[ $MODE = "vector" && $KPP_SOLVER = "ROS2" ]]
191# then
192#   cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90    # get vector Solver
193# else
194# #  KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST FunTemplate JacTemplate Update_SUN "
195#   KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
196#   if [[ $MODE = "vector" ]]
197#   then
198#     cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90  # get vector Solver
199#   else
200#     KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate Update_SUN"
201#   fi
202# fi
203 if [[ $MODE = "vector" ]]
204 then
205   # get vector Solver
206   cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90
[3458]207   cp $BASE/templates/kp4_compress_header ${PREFIX}_kp4_compress_header.f90
208   cp $BASE/templates/kp4_compress_subroutines ${PREFIX}_kp4_compress_subroutines.f90
[2696]209fi
210
211# Interface ignore list
[3298]212KPP_INTERFACE_IGNORE=" "
[2696]213
[3298]214echo " "
215echo KPP_SOLVER $KPP_SOLVER
216echo " "
217
[2696]218case $KPP_SOLVER in
219    ROS2) ;;
220
221    Rosenbrock)   
[3298]222      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WSCAL WAXPY"
223      if [[ $MODE != "vector" ]]
224      then
225         KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate"
226        KPP_INTERFACE_IGNORE="WAXPY"
[3458]227
[3298]228      else
229        KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST FunTemplate JacTemplate"
[3458]230        KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST kco_initialize kco_compress kco_finalize"
[3298]231      fi;;
[2696]232
233    rosenbrock_mz)
234      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
235      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate Update_SUN";;
236
237    rosenbrock)
238      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
[3298]239      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate";;
[2696]240
241    kpp_lsode)
242      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
243      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppLsode DLSODE JAC_CHEM FUN_CHEM"
244      KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE JAC_CHEM KppDecomp KppSolve";;
245
246    kpp_radau5)
247      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY FUN_CHEM JAC_CHEM SET2ZERO"
248      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST RADAU5 Update_SUN"
249      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppSolveCmplx KppDecompCmplx";;
250
251    kpp_sdirk)
252       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
253       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST SDIRK JAC_CHEM SET2ZERO FUN_CHEM"
254       KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE Set2zero SET2ZERO FUN_CHEM";;
255
256    kpp_seulex)
257       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
258       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST ATMSEULEX"
259       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST SEULEX_ErrorMsg SEULEX_Integrator FUN_CHEM JAC_CHEM SEUL"
260       KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE SEULEX_Integrator SDIRK FUN_CHEM SEUL";;
261
262   \?)  print "SORRY ONLY ROSENBROCK METHODS WORK AT THE MOMENT:" $KPP_SOLVER
263        exit 1;;
264esac
265#mz-ak-20070509+
266
267KPP_INCLUDE_LIST="Parameters Global JacobianSP Monitor"
[3458]268if [[ $MODE = "vector" ]]
269 then
270KPP_INCLUDE_LIST="$KPP_INCLUDE_LIST kp4_compress_header"
271fi
[2696]272
273#Get definition Files
274
275cp $DEFDIR/*.eqn         .
276cp $DEFDIR/*.spc         .
277cp $DEFDIR/${PREFIX}.kpp     .
278
[3298]279# Global variable are defined here
280# This has the advantage that it is not necessary to include these variables in all .kpp definition files
281
282cat  >> ${PREFIX}.kpp  <<  EOF
283#INLINE F90_GLOBAL
284! QVAP - Water vapor
285  REAL(kind=dp) :: QVAP
286! FAKT - Conversion factor
287  REAL(kind=dp) :: FAKT
288
[3780]289! CS_MECH for check of mechanism name with namelist
290  CHARACTER(LEN=30) :: CS_MECH
[3298]291#ENDINLINE
292EOF
293
294# Store mechanism name in file mech_list
295cat  >> mech_list  <<  EOF
296!   Mechanism: $MECH
297!
298EOF
299
[3780]300# Store mechanism name for cs_mech
301cat  >> set_cm  <<  EOF
302
303! Set cs_mech for check with mechanism name from namelist
304    cs_mech = '$MECH'
305EOF
306
[2696]307# Run kpp
308
309$KPP $DEF_PREFIX
310
311# Get templates for C++ program
312
313cp $BASE/templates/module_header* .           # Use fixed Module_header
314cp $BASE/templates/initialize_kpp_ctrl_template.f90 .  # CTRL kpp time stepping
315
316# file with subroutine list for c++ program create_kpp_module
317
318for i in $KPP_FILE_LIST
319do
320  echo ${PREFIX}_${i} >> file_list
321done
322echo initialize_kpp_ctrl_template >> file_list
323
324# file with subroutine list for c++ program create_kpp_module
325
326for i in $KPP_SUBROUTINE_LIST
327do
328  echo $i >> subroutine_list
329done
330
331# file with include list for c++ program create_kpp_module
332
333for i in $KPP_INCLUDE_LIST
334do
335  echo ${PREFIX}_${i} >> include_list
336done
337
338touch interface_ignore_list
339for i in $KPP_INTERFACE_IGNORE
340do
341  echo $i >> interface_ignore_list
342done
343
[3458]344echo start kpp4palm.exe with arguments
[3298]345echo $PREFIX $MODE $VLEN $DE_INDEX $DE_INDEX_FAST
346
[2696]347$BASE/bin/kpp4palm.exe $PREFIX $MODE $VLEN $DE_INDEX $DE_INDEX_FAST
348
[3799]349# Add dummy statements in order to prevent warnings due to unused variables
350#
351sed -i -e '/cfactor =/a !  ' kk_kpp.f90
[3800]352sed -i -e '/cfactor =/a BLANKS  IF ( lu_crow(1) == 1  .OR.  lu_icol(1) == 1  .OR.  lu_irow(1) == 1 )  CONTINUE ' kk_kpp.f90
[3799]353sed -i -e '/cfactor =/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
354sed -i -e '/cfactor =/a !  ' kk_kpp.f90
355
[3298]356if [[ $MODE = "vector" ]]
357then
[3799]358sed -i -e '/! Computation of equation rates/i ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
[3800]359sed -i -e '/! Computation of equation rates/i BLANKS  IF ( f(vl,nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
[3799]360sed -i -e '/! Computation of equation rates/i !  ' kk_kpp.f90
361else
362sed -i -e '/! Computation of equation rates/i ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
[3800]363sed -i -e '/! Computation of equation rates/i BLANKS  IF ( f(nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
[3799]364sed -i -e '/! Computation of equation rates/i !  ' kk_kpp.f90
[3298]365fi
[2696]366
[3799]367if [[ $MODE = "vector" ]]
368then
[3800]369sed -i -e '/REAL(kind=dp) :: b/a  BLANKS  IF ( f(vl,nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
[3799]370sed -i -e '/REAL(kind=dp) :: b/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
371sed -i -e '/REAL(kind=dp):: b/a !' kk_kpp.f90
372else
[3800]373sed -i -e '/REAL(kind=dp):: b/a BLANKS  IF ( f(nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
[3799]374sed -i -e '/REAL(kind=dp):: b/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
375sed -i -e '/REAL(kind=dp):: b/a !' kk_kpp.f90
376fi
377
[3800]378sed -i -e '/one=1.0_dp/a BLANKS  IF ( incx == 0 )  CONTINUE' kk_kpp.f90
[3799]379sed -i -e '/one=1.0_dp/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
380sed -i -e '/one=1.0_dp/a !  ' kk_kpp.f90
381
382sed -i -e '/IF (alpha .eq. zero)RETURN/i !  ' kk_kpp.f90
383sed -i -e '/IF (alpha .eq. zero)RETURN/i ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
[3800]384sed -i -e '/IF (alpha .eq. zero)RETURN/i BLANKS  IF ( incx == 0  .OR.  incy == 0 )  CONTINUE' kk_kpp.f90
[3799]385
[3800]386sed -i -e '/INTENT(INOUT):: b(n)/a BLANKS  IF ( pivot(1) == 0 )  CONTINUE' kk_kpp.f90
[3799]387sed -i -e '/INTENT(INOUT):: b(n)/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
388sed -i -e '/INTENT(INOUT):: b(n)/a !  ' kk_kpp.f90
389
[3800]390sed -i -e '1,$s/BLANKS /  /  ' kk_kpp.f90
391
[2696]392if [[ -e $OUTDIR/${OUTFILE}.f90 ]] 
393then
394 mv $OUTDIR/${OUTFILE}.f90 $OUTDIR/${OUTFILE}.f90.sav
395fi
396cp -p kk_kpp.f90    $OUTDIR/${OUTFILE}.f90
397echo " "
398echo "Write kpp module -- > " $OUTDIR/${OUTFILE}.f90
399
[3298]400if [[ $UPDT = "YES" ]]
401then
402cp -p kk_kpp.f90    $DEFDIR/${OUTFILE}.f90
403echo " "
404echo "Write kpp module -- > " $DEFDIR/${OUTFILE}.f90
405fi
406
[2696]407if [[ $KEEP = "NO" ]]
408then
409  cd  $MY_PWD
410  rm -rf $WORK
411fi
412exit
413
Note: See TracBrowser for help on using the repository browser.