source: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/bin/kpp4palm.ksh @ 3796

Last change on this file since 3796 was 3780, checked in by forkel, 6 years ago

removed read from unit 10 in chemistry_model_mod.f90, added get_mechanismname

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