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, 16 months 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
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-2021  Klaus Ketelsen and MPI-CH (April 2007)
20# Copyright 2017-2021  Karlsruhe Institute of Technology
21# Copyright 2017-2021  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 4843 2021-01-15 15:22:11Z raasch $
42# Changed default mechanism from smog to phstatp
43#
44#
45# 4451 2020-03-10 07:25:32Z raasch
46# rename kpp4palm.ksh to kpp4palm.sh, convert to bash
47#
48# 3800 2019-03-15 16:40:25Z forkel
49# Removed edit of phot(nphot) for version edit phot(nphot), now done in fortran_file.C (15.03.2019, forkel)
50# Editing with sed to add dummy statements toavoud unused variables (15.03.2019, forkel)
51#
52# 3780 2019-03-05 11:19:45Z forkel
53# forkel   05. March 2019: cs_mech and set_cm
54# forkel   30. Oktober 2018: Integrating contents of kp4_compress into chem_gasphase_mod.f90
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
75# Initial revision
76#
77#
78##########################################################################
79#
80#
81# Other notes:
82# ------------#
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
110MECH=phstatp
111OUTDIR=`pwd`/../../../SOURCE
112OUTFILE=chem_gasphase_mod
113DEFDIR=`pwd`/mechanisms/def_phastatp
114PREFIX=chem_gasphase_mod
115MODE="scalar"
116VLEN=1
117KEEP="NO"
118UPDT="NO"
119DE_INDEX=0
120DE_INDEX_FAST="YES"
121
122export KPP_SOLVER=Rosenbrock
123
124# get Command line option
125
126while  getopts :m:i:fkup:o:s:vl:w:  c     # get options
127do case $c in
128      m)   MECH=$OPTARG;;            # mechanism
129
130      i)   DE_INDEX=$OPTARG;;        # if set, deindexing
131
132      f)   DE_INDEX_FAST="YES";;     # if set, fast deindexing
133
134      k)   KEEP="YES";;              # keep Working directory
135
136      o)   OUTDIR=$OPTARG;;          # Output directory of Generated Code =
137                                     # SOURCE directory (do not change)
138
139      p)   PREFIX=$OPTARG;;          # Name Prefix (chem_gasphase_mod, do not change)
140
141      s)   KPP_SOLVER=$OPTARG;;      # Chosen solver (only Rosebrock solvers work for vector mode)
142
143      u)   UPDT="YES";;              # update mechanisms/def_$MECH/chem_gasphase_mod.f90
144
145      v)   MODE="vector";;           # Set to vector Mode
146
147      l)   VLEN=$OPTARG;;            # Set vector length
148
149      w)   WORK=$OPTARG;;            # Working directory
150
151      \?)  print ${0##*/} "unknown option:" $OPTARG
152           print "USAGE: ${0##*/} [ -m dir -e -k -u -o dir -p name -s solver -v -l length -w dir ] "
153           exit 1;;
154   esac
155done
156
157echo MECHANISM = $MECH
158echo DE_INDEX = $DE_INDEX
159echo KEEP = $KEEP
160echo UPDT = $UPDT
161echo MODE = $MODE
162echo VLEN = $VLEN
163
164DEF_PREFIX=${PREFIX}.kpp
165DEFDIR=`pwd`/mechanisms/def_$MECH
166echo DEFDIR = $DEFDIR
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"
178if [[ $MODE = "vector" ]]
179 then
180KPP_FILE_LIST="$KPP_FILE_LIST kp4_compress_subroutines"
181fi
182
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"
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
207   cp $BASE/templates/kp4_compress_header ${PREFIX}_kp4_compress_header.f90
208   cp $BASE/templates/kp4_compress_subroutines ${PREFIX}_kp4_compress_subroutines.f90
209fi
210
211# Interface ignore list
212KPP_INTERFACE_IGNORE=" "
213
214echo " "
215echo KPP_SOLVER $KPP_SOLVER
216echo " "
217
218case $KPP_SOLVER in
219    ROS2) ;;
220
221    Rosenbrock)   
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"
227
228      else 
229        KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST FunTemplate JacTemplate"
230        KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST kco_initialize kco_compress kco_finalize"
231      fi;;
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"
239      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate";;
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"
268if [[ $MODE = "vector" ]]
269 then
270KPP_INCLUDE_LIST="$KPP_INCLUDE_LIST kp4_compress_header"
271fi
272
273#Get definition Files
274
275cp $DEFDIR/*.eqn         .
276cp $DEFDIR/*.spc         .
277cp $DEFDIR/${PREFIX}.kpp     .
278
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
289! CS_MECH for check of mechanism name with namelist
290  CHARACTER(LEN=30) :: CS_MECH
291#ENDINLINE
292EOF
293
294# Store mechanism name in file mech_list
295cat  >> mech_list  <<  EOF
296!   Mechanism: $MECH
297!
298EOF
299
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
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
344echo start kpp4palm.exe with arguments
345echo $PREFIX $MODE $VLEN $DE_INDEX $DE_INDEX_FAST
346
347$BASE/bin/kpp4palm.exe $PREFIX $MODE $VLEN $DE_INDEX $DE_INDEX_FAST
348
349# Add dummy statements in order to prevent warnings due to unused variables
350#
351sed -i -e '/cfactor =/a !  ' kk_kpp.f90
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
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
356if [[ $MODE = "vector" ]]
357then
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(vl,nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
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
363sed -i -e '/! Computation of equation rates/i BLANKS  IF ( f(nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
364sed -i -e '/! Computation of equation rates/i !  ' kk_kpp.f90
365fi
366
367if [[ $MODE = "vector" ]]
368then
369sed -i -e '/REAL(kind=dp) :: b/a  BLANKS  IF ( f(vl,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
372else
373sed -i -e '/REAL(kind=dp):: b/a BLANKS  IF ( f(nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
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
378sed -i -e '/one=1.0_dp/a BLANKS  IF ( incx == 0 )  CONTINUE' kk_kpp.f90
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
384sed -i -e '/IF (alpha .eq. zero)RETURN/i BLANKS  IF ( incx == 0  .OR.  incy == 0 )  CONTINUE' kk_kpp.f90
385
386sed -i -e '/INTENT(INOUT):: b(n)/a BLANKS  IF ( pivot(1) == 0 )  CONTINUE' kk_kpp.f90
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
390sed -i -e '1,$s/BLANKS /  /  ' kk_kpp.f90
391
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
400if [[ $UPDT = "YES" ]]
401then
402cp -p kk_kpp.f90    $DEFDIR/${OUTFILE}.f90
403echo " "
404echo "Write kpp module -- > " $DEFDIR/${OUTFILE}.f90
405fi
406
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.