|
| 1 | +""" |
| 2 | +Utility function to help generating consistent docstrings across the package. |
| 3 | +""" |
| 4 | +# TODO we should add a consistency check using the string $name(; $keyword_default) against the standard console output of name() |
| 5 | +function generic_solver_docstring(description::String, |
| 6 | + name::String, |
| 7 | + solver_class::String, |
| 8 | + references::String, |
| 9 | + keyword_description::String, |
| 10 | + keyword_default::String) |
| 11 | + if !isempty(keyword_default) |
| 12 | + # Chunk string and remove empty lines |
| 13 | + kws = split(keyword_default, "\n") |
| 14 | + keywords_split = [kw for kw in kws if !isempty(rstrip(kw))] |
| 15 | + |
| 16 | + # Indent the keywords properly |
| 17 | + indentation = repeat(" ", length(name)+3) |
| 18 | + # We do not indent the first kw and no newline for the last one |
| 19 | + if length(keyword_default) > 1 |
| 20 | + keywords_split[1] = keywords_split[1] * "\n" |
| 21 | + for i in 2:(length(keywords_split)-1) |
| 22 | + keywords_split[i] = indentation * keywords_split[i] * "\n" |
| 23 | + end |
| 24 | + keywords_split[end] = indentation * keywords_split[end] |
| 25 | + end |
| 26 | + # Flatten into string |
| 27 | + keyword_default = join(keywords_split) |
| 28 | + # Remove trailing comma |
| 29 | + keyword_default = strip(keyword_default, [',']) |
| 30 | + end |
| 31 | + start_docstring = !isempty(keyword_default) ? """ |
| 32 | + ```julia |
| 33 | + $name(; $keyword_default) |
| 34 | + ``` |
| 35 | +
|
| 36 | + $solver_class |
| 37 | + """ : |
| 38 | + """ |
| 39 | + ```julia |
| 40 | + $name() |
| 41 | + ``` |
| 42 | +
|
| 43 | + $solver_class |
| 44 | + """ |
| 45 | + |
| 46 | + keyword_docstring = """ |
| 47 | +
|
| 48 | + ### Keyword Arguments |
| 49 | +
|
| 50 | + $keyword_description |
| 51 | + """ |
| 52 | + |
| 53 | + return start_docstring * description * keyword_docstring * |
| 54 | + "## References\n" * references |
| 55 | +end |
| 56 | + |
| 57 | +function explicit_rk_docstring(description::String, |
| 58 | + name::String; |
| 59 | + references::String = "", |
| 60 | + extra_keyword_description::String = "", |
| 61 | + extra_keyword_default::String = "") |
| 62 | + keyword_default = """ |
| 63 | + stage_limiter! = OrdinaryDiffEq.trivial_limiter!, |
| 64 | + step_limiter! = OrdinaryDiffEq.trivial_limiter!, |
| 65 | + """ * extra_keyword_default |
| 66 | + |
| 67 | + keyword_default_description = """ |
| 68 | + - `stage_limiter!`: function of the form `limiter!(u, integrator, p, t)` |
| 69 | + - `step_limiter!`: function of the form `limiter!(u, integrator, p, t)` |
| 70 | + """ * extra_keyword_description |
| 71 | + |
| 72 | + generic_solver_docstring( |
| 73 | + description, name, "Explicit Runge-Kutta Method. ", references, |
| 74 | + keyword_default_description, keyword_default |
| 75 | + ) |
| 76 | +end |
| 77 | + |
| 78 | +function rosenbrock_docstring(description::String, |
| 79 | + name::String; |
| 80 | + references::String = "", |
| 81 | + extra_keyword_description = "", |
| 82 | + extra_keyword_default = "", |
| 83 | + with_step_limiter = false) |
| 84 | + keyword_default = """ |
| 85 | + autodiff = Val{true}(), |
| 86 | + concrete_jac = nothing, |
| 87 | + linsolve = nothing, |
| 88 | + precs = DEFAULT_PRECS, |
| 89 | + """ * extra_keyword_default |
| 90 | + |
| 91 | + keyword_default_description = """ |
| 92 | + - `autodiff`: boolean to control if the Jacobian should be computed via AD or not |
| 93 | + - `concrete_jac`: function of the form `jac!(J, u, p, t)` |
| 94 | + - `linsolve`: custom solver for the inner linear systems |
| 95 | + - `precs`: custom preconditioner for the inner linear solver |
| 96 | + """ * extra_keyword_description |
| 97 | + |
| 98 | + if with_step_limiter |
| 99 | + keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n" |
| 100 | + keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n" |
| 101 | + end |
| 102 | + |
| 103 | + generic_solver_docstring( |
| 104 | + description, name, "Rosenbrock Method. ", references, |
| 105 | + keyword_default_description, keyword_default |
| 106 | + ) |
| 107 | +end |
| 108 | + |
| 109 | +function rosenbrock_wanner_docstring(description::String, |
| 110 | + name::String; |
| 111 | + references::String = "", |
| 112 | + extra_keyword_description = "", |
| 113 | + extra_keyword_default = "", |
| 114 | + with_step_limiter = false) |
| 115 | + keyword_default = """ |
| 116 | + autodiff = Val{true}(), |
| 117 | + concrete_jac = nothing, |
| 118 | + linsolve = nothing, |
| 119 | + precs = DEFAULT_PRECS, |
| 120 | + """ * extra_keyword_default |
| 121 | + |
| 122 | + keyword_default_description = """ |
| 123 | + - `autodiff`: boolean to control if the Jacobian should be computed via AD or not |
| 124 | + - `concrete_jac`: function of the form `jac!(J, u, p, t)` |
| 125 | + - `linsolve`: custom solver for the inner linear systems |
| 126 | + - `precs`: custom preconditioner for the inner linear solver |
| 127 | + """ * extra_keyword_description |
| 128 | + |
| 129 | + if with_step_limiter |
| 130 | + keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n" |
| 131 | + keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n" |
| 132 | + end |
| 133 | + |
| 134 | + generic_solver_docstring( |
| 135 | + description, name, "Rosenbrock-Wanner Method. ", references, |
| 136 | + keyword_default_description, keyword_default |
| 137 | + ) |
| 138 | +end |
| 139 | + |
| 140 | +# TODO other classes |
0 commit comments