|
| 1 | +# MethodOfLines.jl |
| 2 | + |
| 3 | +Provides automatic discretization of symbolic PDE systems as defined with ModelingToolkit.jl |
| 4 | + |
| 5 | +Usage: |
| 6 | +``` |
| 7 | +discretization = MOLFiniteDifference(dxs, |
| 8 | + <your choice of continuous variable, usually time>; |
| 9 | + upwind_order = <currently hard coded to 1>, |
| 10 | + centered_order = <currently hard coded to 2>, |
| 11 | + grid_align = your grid type choice>) |
| 12 | +prob = discretize(pdesys, discretization) |
| 13 | +``` |
| 14 | +Where dxs is a vector of pairs of parameters to the grid step in this dimension, i.e. `[x=>0.2, y=>0.1]` |
| 15 | + |
| 16 | +Currently supported grid types: `center_align` and `edge_align` |
| 17 | +center_align: naive grid, starting from lower boundary, ending on upper boundary with step of dx |
| 18 | +edge_align: offset grid, set halfway between the points that would be generated with center_align, with extra points at either end that are above and below the supremum and infimum by dx/2. |
| 19 | +This provides higher accuracy with neumann/robin boundary conditions. |
| 20 | + |
| 21 | +Currently boundary conditions defined in terms of derivatives at the boundary are unsupported. |
| 22 | + |
| 23 | +## Full Example: |
| 24 | +``` |
| 25 | +## 2D Diffusion |
| 26 | +
|
| 27 | +# Variables, parameters, and derivatives |
| 28 | +@parameters t x y |
| 29 | +@variables u(..) |
| 30 | +Dxx = Differential(x)^2 |
| 31 | +Dyy = Differential(y)^2 |
| 32 | +Dt = Differential(t) |
| 33 | +# Domain edges |
| 34 | +t_min= 0. |
| 35 | +t_max = 2.0 |
| 36 | +x_min = 0. |
| 37 | +x_max = 2. |
| 38 | +y_min = 0. |
| 39 | +y_max = 2. |
| 40 | +
|
| 41 | +# Discretization parameters |
| 42 | +dx = 0.1; dy = 0.2 |
| 43 | +order = 2 |
| 44 | +
|
| 45 | +# Analytic solution for boundary conditions |
| 46 | +analytic_sol_func(t, x, y) = exp(x + y) * cos(x + y + 4t) |
| 47 | +
|
| 48 | +# Equation |
| 49 | +eq = Dt(u(t, x, y)) ~ Dxx(u(t, x, y)) + Dyy(u(t, x, y)) |
| 50 | +
|
| 51 | +# Initial and boundary conditions |
| 52 | +bcs = [u(t_min,x,y) ~ analytic_sol_func(t_min, x, y), |
| 53 | + u(t, x_min, y) ~ analytic_sol_func(t, x_min, y), |
| 54 | + u(t, x_max, y) ~ analytic_sol_func(t, x_max, y), |
| 55 | + u(t, x,y_min) ~ analytic_sol_func(t, x, y_min), |
| 56 | + u(t, x, y_max) ~ analytic_sol_func(t, x, y_max)] |
| 57 | +
|
| 58 | +# Space and time domains |
| 59 | +domains = [t ∈ Interval(t_min, t_max), |
| 60 | + x ∈ Interval(x_min, x_max), |
| 61 | + y ∈ Interval(y_min, y_max)] |
| 62 | +
|
| 63 | +# PDE system |
| 64 | +@named pdesys = PDESystem([eq], bcs, domains, [t, x, y], [u(t, x, y)]) |
| 65 | +
|
| 66 | +# Method of lines discretization |
| 67 | +discretization = MOLFiniteDifference([x=>dx,y=>dy],t;centered_order=order) |
| 68 | +prob = ModelingToolkit.discretize(pdesys,discretization) |
| 69 | +
|
| 70 | +# Solution of the ODE system |
| 71 | +sol = solve(prob,Tsit5()) |
| 72 | +``` |
0 commit comments