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