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-2017 Klaus Ketelsen and MPI-CH (April 2007) |
---|
20 | # Copyright 2017-2017 Karlsruhe Institute of Technology |
---|
21 | # Copyright 2017-2017 Leibniz Universitaet Hannover |
---|
22 | #------------------------------------------------------------------------------# |
---|
23 | # |
---|
24 | # Current revisions: |
---|
25 | # ------------------ |
---|
26 | # |
---|
27 | # |
---|
28 | # Former revisions: |
---|
29 | # ----------------- |
---|
30 | # $Id: kpp4palm.ksh 2699 2017-12-15 12:38:41Z suehring $ |
---|
31 | # Initial revision |
---|
32 | # |
---|
33 | # |
---|
34 | # |
---|
35 | # |
---|
36 | # Other notes: |
---|
37 | # ------------# |
---|
38 | # Re-introduced relative path for KPP_HOME |
---|
39 | # Subroutine list adapted to lowercase subroutine names |
---|
40 | # Added arr2, removed update_sun and k_3rd from subroutine list |
---|
41 | # Renamed output file to chem_gasphase_mod |
---|
42 | # Renamed this fikle from kp4/ksh to kpp4kpp.ksh |
---|
43 | # changed location of def_mechanism directories to GASPHASE_PREPROC/mechanisms |
---|
44 | # |
---|
45 | # Nov. 2016: Initial Version of KPP chemistry convertor by Klaus Ketelsen |
---|
46 | # |
---|
47 | # |
---|
48 | |
---|
49 | set -eu |
---|
50 | |
---|
51 | |
---|
52 | ########################### User SetUp #################################### |
---|
53 | |
---|
54 | export KPP_HOME=`pwd`/kpp |
---|
55 | export KPP=$KPP_HOME/bin/kpp |
---|
56 | |
---|
57 | BASE=`pwd`/kpp4palm |
---|
58 | |
---|
59 | ########################## End User Setup ################################ |
---|
60 | |
---|
61 | WORK=tmp_kpp4palm |
---|
62 | |
---|
63 | # Default |
---|
64 | |
---|
65 | OUTDIR=`pwd`/../../../SOURCE |
---|
66 | OUTFILE=chem_gasphase_mod |
---|
67 | DEFDIR=`pwd`/mechanisms/def_smog |
---|
68 | PREFIX=chem_gasphase_mod |
---|
69 | MODE="scalar" |
---|
70 | VLEN=1 |
---|
71 | KEEP="NO" |
---|
72 | DE_INDEX="NO" |
---|
73 | DE_INDEX_FAST="NO" |
---|
74 | |
---|
75 | export KPP_SOLVER=Rosenbrock |
---|
76 | |
---|
77 | # get Command line option |
---|
78 | |
---|
79 | echo xxxxxxxxxx |
---|
80 | while getopts :d:ifkp:o:s:v:w: c # get options |
---|
81 | do case $c in |
---|
82 | d) DEFDIR=$OPTARG;; # directory of definition files |
---|
83 | |
---|
84 | i) DE_INDEX="YES";; # if set, deindexing |
---|
85 | |
---|
86 | f) DE_INDEX_FAST="YES";; # if set, fast deindexing |
---|
87 | |
---|
88 | k) KEEP="YES";; # keep Working directory |
---|
89 | |
---|
90 | o) OUTDIR=$OPTARG;; # Output directory of Generated Code |
---|
91 | |
---|
92 | p) PREFIX=$OPTARG;; # Name Prefix |
---|
93 | |
---|
94 | s) KPP_SOLVER=$OPTARG;; # Name Prefix |
---|
95 | |
---|
96 | v) MODE="vector" |
---|
97 | VLEN=$OPTARG;; # Set to vector Mode |
---|
98 | |
---|
99 | w) WORK=$OPTARG;; # Working directory |
---|
100 | |
---|
101 | \?) print ${0##*/} "unknown option:" $OPTARG |
---|
102 | print "USAGE: ${0##*/} [ -d dir -e -k -o dir -p name -s solver -v length -w dir ] " |
---|
103 | exit 1;; |
---|
104 | esac |
---|
105 | done |
---|
106 | shift OPTIND-1 |
---|
107 | |
---|
108 | echo $DEFDIR |
---|
109 | |
---|
110 | DEF_PREFIX=${PREFIX}.kpp |
---|
111 | |
---|
112 | # Create or clean working directory |
---|
113 | |
---|
114 | MY_PWD=`pwd` |
---|
115 | mkdir -p $WORK |
---|
116 | rm -rf $WORK/* |
---|
117 | cd $WORK |
---|
118 | |
---|
119 | # kpp dependend, may be changed |
---|
120 | |
---|
121 | KPP_FILE_LIST="Initialize Integrator LinearAlgebra Jacobian Function Rates Util" |
---|
122 | |
---|
123 | |
---|
124 | KPP_SUBROUTINE_LIST="initialize" |
---|
125 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST integrate fun" |
---|
126 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST kppsolve kppdecomp wlamch wlamch_add" |
---|
127 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST jac_sp k_arr " |
---|
128 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST update_rconst arr2" |
---|
129 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST initialize_kpp_ctrl error_output" |
---|
130 | |
---|
131 | # if [[ $MODE = "vector" && $KPP_SOLVER = "ROS2" ]] |
---|
132 | # then |
---|
133 | # cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90 # get vector Solver |
---|
134 | # else |
---|
135 | # # KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST FunTemplate JacTemplate Update_SUN " |
---|
136 | # KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY" |
---|
137 | # if [[ $MODE = "vector" ]] |
---|
138 | # then |
---|
139 | # cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90 # get vector Solver |
---|
140 | # else |
---|
141 | # KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock FunTemplate JacTemplate Update_SUN" |
---|
142 | # fi |
---|
143 | # fi |
---|
144 | if [[ $MODE = "vector" ]] |
---|
145 | then |
---|
146 | # get vector Solver |
---|
147 | cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90 |
---|
148 | fi |
---|
149 | |
---|
150 | # Interface ignore list |
---|
151 | KPP_INTERFACE_IGNORE="waxpy wcopy" |
---|
152 | |
---|
153 | case $KPP_SOLVER in |
---|
154 | ROS2) ;; |
---|
155 | |
---|
156 | Rosenbrock) |
---|
157 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST wcopy wscal waxpy" |
---|
158 | if [[ $MODE != "vector" ]] |
---|
159 | then |
---|
160 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST rosenbrock funtemplate jactemplate" |
---|
161 | fi;; |
---|
162 | |
---|
163 | rosenbrock_mz) |
---|
164 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY" |
---|
165 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock FunTemplate JacTemplate Update_SUN";; |
---|
166 | |
---|
167 | rosenbrock) |
---|
168 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY" |
---|
169 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST rosenbrock funtemplate jactemplate";; |
---|
170 | |
---|
171 | kpp_lsode) |
---|
172 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY" |
---|
173 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppLsode DLSODE JAC_CHEM FUN_CHEM" |
---|
174 | KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE JAC_CHEM KppDecomp KppSolve";; |
---|
175 | |
---|
176 | kpp_radau5) |
---|
177 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY FUN_CHEM JAC_CHEM SET2ZERO" |
---|
178 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST RADAU5 Update_SUN" |
---|
179 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppSolveCmplx KppDecompCmplx";; |
---|
180 | |
---|
181 | kpp_sdirk) |
---|
182 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY" |
---|
183 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST SDIRK JAC_CHEM SET2ZERO FUN_CHEM" |
---|
184 | KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE Set2zero SET2ZERO FUN_CHEM";; |
---|
185 | |
---|
186 | kpp_seulex) |
---|
187 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY" |
---|
188 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST ATMSEULEX" |
---|
189 | KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST SEULEX_ErrorMsg SEULEX_Integrator FUN_CHEM JAC_CHEM SEUL" |
---|
190 | KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE SEULEX_Integrator SDIRK FUN_CHEM SEUL";; |
---|
191 | |
---|
192 | \?) print "SORRY ONLY ROSENBROCK METHODS WORK AT THE MOMENT:" $KPP_SOLVER |
---|
193 | exit 1;; |
---|
194 | esac |
---|
195 | #mz-ak-20070509+ |
---|
196 | |
---|
197 | KPP_INCLUDE_LIST="Parameters Global JacobianSP Monitor" |
---|
198 | |
---|
199 | #Get definition Files |
---|
200 | |
---|
201 | cp $DEFDIR/*.eqn . |
---|
202 | cp $DEFDIR/*.spc . |
---|
203 | cp $DEFDIR/${PREFIX}.kpp . |
---|
204 | |
---|
205 | # Run kpp |
---|
206 | |
---|
207 | $KPP $DEF_PREFIX |
---|
208 | |
---|
209 | # Get templates for C++ program |
---|
210 | |
---|
211 | cp $BASE/templates/module_header* . # Use fixed Module_header |
---|
212 | cp $BASE/templates/initialize_kpp_ctrl_template.f90 . # CTRL kpp time stepping |
---|
213 | |
---|
214 | # file with subroutine list for c++ program create_kpp_module |
---|
215 | |
---|
216 | for i in $KPP_FILE_LIST |
---|
217 | do |
---|
218 | echo ${PREFIX}_${i} >> file_list |
---|
219 | done |
---|
220 | echo initialize_kpp_ctrl_template >> file_list |
---|
221 | |
---|
222 | # file with subroutine list for c++ program create_kpp_module |
---|
223 | |
---|
224 | for i in $KPP_SUBROUTINE_LIST |
---|
225 | do |
---|
226 | echo $i >> subroutine_list |
---|
227 | done |
---|
228 | |
---|
229 | # file with include list for c++ program create_kpp_module |
---|
230 | |
---|
231 | for i in $KPP_INCLUDE_LIST |
---|
232 | do |
---|
233 | echo ${PREFIX}_${i} >> include_list |
---|
234 | done |
---|
235 | |
---|
236 | touch interface_ignore_list |
---|
237 | for i in $KPP_INTERFACE_IGNORE |
---|
238 | do |
---|
239 | echo $i >> interface_ignore_list |
---|
240 | done |
---|
241 | |
---|
242 | $BASE/bin/kpp4palm.exe $PREFIX $MODE $VLEN $DE_INDEX $DE_INDEX_FAST |
---|
243 | |
---|
244 | |
---|
245 | if [[ -e $OUTDIR/${OUTFILE}.f90 ]] |
---|
246 | then |
---|
247 | mv $OUTDIR/${OUTFILE}.f90 $OUTDIR/${OUTFILE}.f90.sav |
---|
248 | fi |
---|
249 | cp -p kk_kpp.f90 $OUTDIR/${OUTFILE}.f90 |
---|
250 | #cp -p kk_kpp.f90 $MY_PWD/../SOURCE/${OUTFILE}.f90 |
---|
251 | |
---|
252 | echo " " |
---|
253 | echo "Write kpp module -- > " $OUTDIR/${OUTFILE}.f90 |
---|
254 | |
---|
255 | if [[ $KEEP = "NO" ]] |
---|
256 | then |
---|
257 | cd $MY_PWD |
---|
258 | rm -rf $WORK |
---|
259 | fi |
---|
260 | exit |
---|
261 | |
---|