|
2 | 2 |
|
3 | 3 | import DifferentialEquations
|
4 | 4 | import PyPlot
|
| 5 | +import ConfParser |
| 6 | +import ArgParse |
| 7 | + |
5 | 8 | const DE = DifferentialEquations
|
6 | 9 | const plt = PyPlot
|
| 10 | +const CP = ConfParser |
| 11 | +const AP = ArgParse |
7 | 12 | include("L96m.jl")
|
8 | 13 |
|
| 14 | +################################################################################ |
| 15 | +# function section ############################################################# |
| 16 | +################################################################################ |
| 17 | +function parse_cli_args() |
| 18 | + ap_settings = AP.ArgParseSettings() |
| 19 | + AP.@add_arg_table ap_settings begin |
| 20 | + "--cfg", "-c" |
| 21 | + help = "name of the ini-file to be used as config" |
| 22 | + arg_type = String |
| 23 | + default = "cfg.ini" |
| 24 | + end |
| 25 | + |
| 26 | + return AP.parse_args(ap_settings) |
| 27 | +end |
| 28 | + |
| 29 | +function get_cfg_value(config::CP.ConfParse, sect::String, key::String, default) |
| 30 | + return try |
| 31 | + val = CP.retrieve(config, sect, key) |
| 32 | + if isa(val, String) && String != typeof(default) |
| 33 | + parse(typeof(default), val) |
| 34 | + else |
| 35 | + val |
| 36 | + end |
| 37 | + catch |
| 38 | + default |
| 39 | + end |
| 40 | +end |
| 41 | + |
| 42 | +function print_var(var_name::String; offset::Int = 0) |
| 43 | + println( |
| 44 | + " "^offset, |
| 45 | + rpad(var_name, RPAD_VAR), |
| 46 | + lpad(eval(Symbol(var_name)), LPAD_VAR) |
| 47 | + ) |
| 48 | +end |
| 49 | + |
| 50 | +function print_var(var_names::Array{String}) |
| 51 | + println("# Parameters") |
| 52 | + for var_name in var_names |
| 53 | + print_var(var_name, offset = 2) |
| 54 | + end |
| 55 | +end |
9 | 56 |
|
10 | 57 | ################################################################################
|
11 |
| -# constants section ############################################################ |
| 58 | +# config section ############################################################### |
| 59 | +################################################################################ |
| 60 | +args_dict = parse_cli_args() |
| 61 | +config = try |
| 62 | + CP.ConfParse(args_dict["cfg"]) |
| 63 | +catch |
| 64 | + CP.ConfParse("cfg.ini") |
| 65 | +end |
| 66 | + |
| 67 | +CP.parse_conf!(config) |
| 68 | + |
| 69 | +################################################################################ |
| 70 | +# parameters section ########################################################### |
12 | 71 | ################################################################################
|
13 | 72 | const RPAD = 42
|
| 73 | +const RPAD_VAR = 21 |
14 | 74 | const LPAD_INTEGER = 7
|
15 | 75 | const LPAD_FLOAT = 13
|
16 |
| -const SOLVER = DE.Tsit5() |
17 |
| - |
18 |
| -const T = 4 # integration time |
19 |
| -const T_compile = 1e-10 # force JIT compilation |
20 |
| -const T_conv = 100 # converging integration time |
| 76 | +const LPAD_VAR = 29 |
| 77 | + |
| 78 | +parameters = String[] |
| 79 | +# integration parameters ####################################################### |
| 80 | +# T integration time |
| 81 | +# T_conv converging integration time |
| 82 | +# T_compile force JIT compilation |
| 83 | +push!(parameters, "T", "T_conv", "T_compile") |
| 84 | + |
| 85 | +const T = get_cfg_value(config, "integration", "T", 4.0) |
| 86 | +const T_conv = get_cfg_value(config, "integration", "T_conv", 100.0) |
| 87 | +const T_compile = 1e-10 |
21 | 88 | #const T_learn = 15 # time to gather training data for GP
|
22 | 89 | #const T_hist = 10000 # time to gather histogram statistics
|
23 | 90 |
|
24 |
| -# integrator parameters |
25 |
| -const dtmax = 1e-3 # maximum step size |
| 91 | +# time-stepper parameters ###################################################### |
| 92 | +# SOLVER time-stepper itself |
| 93 | +# dtmax maximum step size |
| 94 | +# reltol relative tolerance |
| 95 | +# abstol absolute tolerance |
| 96 | +push!(parameters, "SOLVER", "dtmax", "reltol", "abstol") |
| 97 | + |
| 98 | +const SOLVER_STR = get_cfg_value(config, "integration", "SOLVER", "Tsit5") |
| 99 | +const SOLVER = getfield(DE, Symbol(SOLVER_STR))() |
| 100 | +const dtmax = get_cfg_value(config, "integration", "dtmax", 1e-3) |
26 | 101 | #const tau = 1e-3 # maximum step size for histogram statistics
|
27 | 102 | #const dt_conv = 0.01 # maximum step size for converging to attractor
|
28 |
| -const reltol = 1e-3 # relative tolerance |
29 |
| -const abstol = 1e-6 # absolute tolerance |
| 103 | +const reltol = get_cfg_value(config, "integration", "reltol", 1e-3) |
| 104 | +const abstol = get_cfg_value(config, "integration", "abstol", 1e-6) |
30 | 105 |
|
| 106 | +# save/plot parameters ######################################################### |
31 | 107 | const k = 1 # index of the slow variable to save etc.
|
32 | 108 | const j = 1 # index of the fast variable to save/plot etc.
|
| 109 | +push!(parameters, "k", "j") |
33 | 110 |
|
| 111 | +# L96 parameters ############################################################### |
34 | 112 | const hx = -0.8
|
| 113 | +push!(parameters, "hx") |
| 114 | + |
| 115 | +print_var(parameters) |
35 | 116 |
|
36 | 117 | ################################################################################
|
37 | 118 | # IC section ###################################################################
|
|
50 | 131 | ################################################################################
|
51 | 132 | # main section #################################################################
|
52 | 133 | ################################################################################
|
| 134 | +println("# Main") |
53 | 135 |
|
54 | 136 | # force compilation of functions used in numerical integration
|
55 | 137 | print(rpad("(JIT compilation)", RPAD))
|
|
0 commit comments