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 raasch $ |
---|
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 | |
---|
81 | set -eu |
---|
82 | |
---|
83 | |
---|
84 | ########################### User SetUp #################################### |
---|
85 | |
---|
86 | export KPP_HOME=`pwd`/kpp |
---|
87 | export KPP=$KPP_HOME/bin/kpp |
---|
88 | |
---|
89 | BASE=`pwd`/kpp4palm |
---|
90 | |
---|
91 | ########################## End User Setup ################################ |
---|
92 | |
---|
93 | WORK=tmp_kpp4palm |
---|
94 | |
---|
95 | # Default |
---|
96 | |
---|
97 | MECH=smog |
---|
98 | OUTDIR=`pwd`/../../../SOURCE |
---|
99 | OUTFILE=chem_gasphase_mod |
---|
100 | DEFDIR=`pwd`/mechanisms/def_smog |
---|
101 | PREFIX=chem_gasphase_mod |
---|
102 | MODE="scalar" |
---|
103 | VLEN=1 |
---|
104 | KEEP="NO" |
---|
105 | UPDT="NO" |
---|
106 | DE_INDEX=0 |
---|
107 | DE_INDEX_FAST="YES" |
---|
108 | |
---|
109 | export KPP_SOLVER=Rosenbrock |
---|
110 | |
---|
111 | # get Command line option |
---|
112 | |
---|
113 | while getopts :m:i:fkup:o:s:vl:w: c # get options |
---|
114 | do 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 |
---|
141 | done |
---|
142 | shift OPTIND-1 |
---|
143 | |
---|
144 | echo MECHANISM = $MECH |
---|
145 | echo DE_INDEX = $DE_INDEX |
---|
146 | echo KEEP = $KEEP |
---|
147 | echo UPDT = $UPDT |
---|
148 | echo MODE = $MODE |
---|
149 | echo VLEN = $VLEN |
---|
150 | |
---|
151 | DEF_PREFIX=${PREFIX}.kpp |
---|
152 | DEFDIR=`pwd`/mechanisms/def_$MECH |
---|
153 | echo DEFDIR = $DEFDIR |
---|
154 | |
---|
155 | # Create or clean working directory |
---|
156 | |
---|
157 | MY_PWD=`pwd` |
---|
158 | mkdir -p $WORK |
---|
159 | rm -rf $WORK/* |
---|
160 | cd $WORK |
---|
161 | |
---|
162 | # kpp dependend, may be changed |
---|
163 | |
---|
164 | KPP_FILE_LIST="Initialize Integrator LinearAlgebra Jacobian Function Rates Util" |
---|
165 | |
---|
166 | |
---|
167 | KPP_SUBROUTINE_LIST="Initialize" |
---|
168 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST INTEGRATE Fun" |
---|
169 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppSolve KppDecomp" |
---|
170 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Jac_SP k_arr " |
---|
171 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Update_RCONST ARR2" |
---|
172 | KPP_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 |
---|
191 | fi |
---|
192 | |
---|
193 | # Interface ignore list |
---|
194 | KPP_INTERFACE_IGNORE=" " |
---|
195 | |
---|
196 | echo " " |
---|
197 | echo KPP_SOLVER $KPP_SOLVER |
---|
198 | echo " " |
---|
199 | |
---|
200 | case $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;; |
---|
244 | esac |
---|
245 | #mz-ak-20070509+ |
---|
246 | |
---|
247 | KPP_INCLUDE_LIST="Parameters Global JacobianSP Monitor" |
---|
248 | |
---|
249 | #Get definition Files |
---|
250 | |
---|
251 | cp $DEFDIR/*.eqn . |
---|
252 | cp $DEFDIR/*.spc . |
---|
253 | cp $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 | |
---|
258 | cat >> ${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 |
---|
266 | EOF |
---|
267 | |
---|
268 | # Store mechanism name in file mech_list |
---|
269 | cat >> mech_list << EOF |
---|
270 | ! Mechanism: $MECH |
---|
271 | ! |
---|
272 | EOF |
---|
273 | |
---|
274 | # Run kpp |
---|
275 | |
---|
276 | $KPP $DEF_PREFIX |
---|
277 | |
---|
278 | # Get templates for C++ program |
---|
279 | |
---|
280 | cp $BASE/templates/module_header* . # Use fixed Module_header |
---|
281 | cp $BASE/templates/initialize_kpp_ctrl_template.f90 . # CTRL kpp time stepping |
---|
282 | |
---|
283 | # file with subroutine list for c++ program create_kpp_module |
---|
284 | |
---|
285 | for i in $KPP_FILE_LIST |
---|
286 | do |
---|
287 | echo ${PREFIX}_${i} >> file_list |
---|
288 | done |
---|
289 | echo initialize_kpp_ctrl_template >> file_list |
---|
290 | |
---|
291 | # file with subroutine list for c++ program create_kpp_module |
---|
292 | |
---|
293 | for i in $KPP_SUBROUTINE_LIST |
---|
294 | do |
---|
295 | echo $i >> subroutine_list |
---|
296 | done |
---|
297 | |
---|
298 | # file with include list for c++ program create_kpp_module |
---|
299 | |
---|
300 | for i in $KPP_INCLUDE_LIST |
---|
301 | do |
---|
302 | echo ${PREFIX}_${i} >> include_list |
---|
303 | done |
---|
304 | |
---|
305 | touch interface_ignore_list |
---|
306 | for i in $KPP_INTERFACE_IGNORE |
---|
307 | do |
---|
308 | echo $i >> interface_ignore_list |
---|
309 | done |
---|
310 | |
---|
311 | echo start kp4.exe with arguments |
---|
312 | echo $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 |
---|
317 | if [[ $MODE = "vector" ]] |
---|
318 | then |
---|
319 | sed -i -e 's/phot(nphot/phot(vl_dim,nphot/g' kk_kpp.f90 |
---|
320 | fi |
---|
321 | |
---|
322 | if [[ -e $OUTDIR/${OUTFILE}.f90 ]] |
---|
323 | then |
---|
324 | mv $OUTDIR/${OUTFILE}.f90 $OUTDIR/${OUTFILE}.f90.sav |
---|
325 | fi |
---|
326 | cp -p kk_kpp.f90 $OUTDIR/${OUTFILE}.f90 |
---|
327 | echo " " |
---|
328 | echo "Write kpp module -- > " $OUTDIR/${OUTFILE}.f90 |
---|
329 | |
---|
330 | if [[ $UPDT = "YES" ]] |
---|
331 | then |
---|
332 | cp -p kk_kpp.f90 $DEFDIR/${OUTFILE}.f90 |
---|
333 | echo " " |
---|
334 | echo "Write kpp module -- > " $DEFDIR/${OUTFILE}.f90 |
---|
335 | fi |
---|
336 | |
---|
337 | if [[ $KEEP = "NO" ]] |
---|
338 | then |
---|
339 | cd $MY_PWD |
---|
340 | rm -rf $WORK |
---|
341 | fi |
---|
342 | exit |
---|
343 | |
---|