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

Last change on this file since 3718 was 3458, checked in by kanani, 6 years ago

Reintegrated fixes/changes from branch chemistry

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