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

Last change on this file since 4451 was 4451, checked in by raasch, 4 years ago

kpp4 scripts converted from ksh to bash, default mechanism changed from smog to phstatp

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