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

Last change on this file since 2697 was 2696, checked in by kanani, 7 years ago

Merge of branch palm4u into trunk

  • Property svn:executable set to *
File size: 6.5 KB
Line 
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
35set -eu
36
37
38########################### User SetUp ####################################
39
40export KPP_HOME=`pwd`/kpp
41export KPP=$KPP_HOME/bin/kpp
42
43BASE=`pwd`/kpp4palm
44
45########################## End User Setup ################################
46
47WORK=tmp_kpp4palm
48
49# Default
50
51OUTDIR=`pwd`/../SOURCE
52OUTFILE=chem_gasphase_mod
53DEFDIR=`pwd`/mechanisms/def_smog
54PREFIX=chem_gasphase_mod
55MODE="scalar"
56VLEN=1
57KEEP="NO"
58DE_INDEX="NO"
59DE_INDEX_FAST="NO"
60
61export KPP_SOLVER=Rosenbrock
62
63# get Command line option
64
65echo xxxxxxxxxx
66while  getopts :d:ifkp:o:s:v:w:  c     # get options
67do 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
91done
92shift OPTIND-1
93
94echo $DEFDIR
95
96DEF_PREFIX=${PREFIX}.kpp
97
98# Create or clean working directory
99
100MY_PWD=`pwd`
101mkdir -p $WORK
102rm -rf $WORK/*
103cd $WORK
104
105# kpp dependend, may be changed
106
107KPP_FILE_LIST="Initialize Integrator LinearAlgebra Jacobian Function Rates Util"
108
109
110KPP_SUBROUTINE_LIST="initialize"
111KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST integrate fun"
112KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST kppsolve kppdecomp wlamch wlamch_add"
113KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST jac_sp k_arr "
114KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST update_rconst arr2"
115KPP_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
134fi
135
136# Interface ignore list
137KPP_INTERFACE_IGNORE="waxpy wcopy"
138
139case $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;;
180esac
181#mz-ak-20070509+
182
183KPP_INCLUDE_LIST="Parameters Global JacobianSP Monitor"
184
185#Get definition Files
186
187cp $DEFDIR/*.eqn         .
188cp $DEFDIR/*.spc         .
189cp $DEFDIR/${PREFIX}.kpp     .
190
191# Run kpp
192
193$KPP $DEF_PREFIX
194
195# Get templates for C++ program
196
197cp $BASE/templates/module_header* .           # Use fixed Module_header
198cp $BASE/templates/initialize_kpp_ctrl_template.f90 .  # CTRL kpp time stepping
199
200# file with subroutine list for c++ program create_kpp_module
201
202for i in $KPP_FILE_LIST
203do
204  echo ${PREFIX}_${i} >> file_list
205done
206echo initialize_kpp_ctrl_template >> file_list
207
208# file with subroutine list for c++ program create_kpp_module
209
210for i in $KPP_SUBROUTINE_LIST
211do
212  echo $i >> subroutine_list
213done
214
215# file with include list for c++ program create_kpp_module
216
217for i in $KPP_INCLUDE_LIST
218do
219  echo ${PREFIX}_${i} >> include_list
220done
221
222touch interface_ignore_list
223for i in $KPP_INTERFACE_IGNORE
224do
225  echo $i >> interface_ignore_list
226done
227
228$BASE/bin/kpp4palm.exe $PREFIX $MODE $VLEN $DE_INDEX $DE_INDEX_FAST
229
230
231if [[ -e $OUTDIR/${OUTFILE}.f90 ]] 
232then
233 mv $OUTDIR/${OUTFILE}.f90 $OUTDIR/${OUTFILE}.f90.sav
234fi
235cp -p kk_kpp.f90    $OUTDIR/${OUTFILE}.f90
236#cp -p kk_kpp.f90    $MY_PWD/../SOURCE/${OUTFILE}.f90
237
238echo " "
239echo "Write kpp module -- > " $OUTDIR/${OUTFILE}.f90
240
241if [[ $KEEP = "NO" ]]
242then
243  cd  $MY_PWD
244  rm -rf $WORK
245fi
246exit
247
Note: See TracBrowser for help on using the repository browser.