Skip to content

Commit

Permalink
Merge pull request #300 from xtalax/precompile
Browse files Browse the repository at this point in the history
Add precompilation stage
  • Loading branch information
xtalax authored Aug 8, 2023
2 parents c360747 + da7fc25 commit 135b04d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
PDEBase = "a7812802-0625-4b9e-961c-d332478797e5"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Expand Down
9 changes: 7 additions & 2 deletions src/MethodOfLines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ using IfElse
using StaticArrays
using Interpolations
using Latexify
import DomainSets
using PrecompileTools
using DomainSets

# See here for the main `symbolic_discretize` and `generate_system` functions
using PDEBase
using PDEBase: unitindices, unitindex, remove, insert, sym_dot, VariableMap, depvar, x2i, d_orders, vcat!
using PDEBase: unitindices, unitindex, remove, insert, sym_dot, VariableMap, depvar, x2i, d_orders, vcat!, update_varmap!
# To Extend
import PDEBase.interface_errors
import PDEBase.check_boundarymap
Expand Down Expand Up @@ -94,6 +95,10 @@ include("discretization/generate_ic_defaults.jl")
include("scalar_discretization.jl")
include("MOL_discretization.jl")

## PrecompileTools
include("precompile.jl")

# Export
export MOLFiniteDifference, discretize, symbolic_discretize, ODEFunctionExpr, generate_code, grid_align, edge_align, center_align, get_discrete, chebyspace
export UpwindScheme, WENOScheme, FunctionalScheme

Expand Down
81 changes: 81 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
@setup_workload begin
@compile_workload begin
begin
@parameters x y t
@variables u(..) v(..)
Dt = Differential(t)
Dx = Differential(x)
Dy = Differential(y)
Dxx = Differential(x)^2
Dyy = Differential(y)^2

∇²(u) = Dxx(u) + Dyy(u)

brusselator_f(x, y, t) = (((x - 0.3)^2 + (y - 0.6)^2) <= 0.1^2) * (t >= 1.1) * 5.0

x_min = y_min = t_min = 0.0
x_max = y_max = 1.0
t_max = 5.0

α = 10.0

u0(x, y, t) = 22(y * (1 - y))^(3 / 2)
v0(x, y, t) = 27(x * (1 - x))^(3 / 2)

eq = [Dt(u(x, y, t)) ~ 1.0 + v(x, y, t) * u(x, y, t)^2 - 4.4 * u(x, y, t) + α * ∇²(u(x, y, t)) + brusselator_f(x, y, t) + Dx(u(x, y, t)) + Dy(v(x, y, t))
Dt(v(x, y, t)) ~ 3.4 * u(x, y, t) - v(x, y, t) * u(x, y, t)^2 + α * ∇²(v(x, y, t)) + Dx(v(x, y, t)*Dx(u(x, y, t))) + Dy(v(x, y, t)*Dy(u(x, y, t)))]

domains = [x Interval(x_min, x_max),
y Interval(y_min, y_max),
t Interval(t_min, t_max)]

# Periodic BCs
bcs = [u(x, y, 0) ~ u0(x, y, 0),
u(0, y, t) ~ u(1, y, t),
u(x, 0, t) ~ u(x, 1, t), v(x, y, 0) ~ v0(x, y, 0),
v(0, y, t) ~ v(1, y, t),
v(x, 0, t) ~ v(x, 1, t)]

@named pdesys = PDESystem(eq, bcs, domains, [x, y, t], [u(x, y, t), v(x, y, t)])

N = 6

order = 2

discretization = MOLFiniteDifference([x => N, y => N], t, approx_order=order, grid_align=center_align)

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys, discretization)

end
begin
@parameters x t
@variables u(..)
Dx = Differential(x)
Dt = Differential(t)
x_min = 0.0
x_max = 1.0
t_min = 0.0
t_max = 6.0

analytic_u2(t, x) = x / (t + 1)

eq = Dt(u(t, x)) ~ -u(t, x) * Dx(u(t, x))

bcs = [u(0, x) ~ x,
u(t, x_min) ~ analytic_u2(t, x_min),
u(t, x_max) ~ analytic_u2(t, x_max)]

domains = [t Interval(t_min, t_max),
x Interval(x_min, x_max)]

dx = 6

@named pdesys = PDESystem(eq, bcs, domains, [t, x], [u(t, x)])

disc = MOLFiniteDifference([x => dx], t, advection_scheme=WENOScheme(), grid_align=edge_align)

prob = discretize(pdesys, disc)
end
end
end

0 comments on commit 135b04d

Please sign in to comment.