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

Last change on this file since 3298 was 3298, checked in by kanani, 3 years ago

Merge chemistry branch at r3297 to trunk

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