Skip to content

Commit 0161a48

Browse files
refactor: update to ModelingToolkit@10
1 parent ab84c98 commit 0161a48

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

docs/src/howitworks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Next, the boundary conditions are discretized, creating an equation for each poi
1212

1313
After that, the system of PDEs is discretized, creating a finite difference equation for each point in their interior. Specific terms are recognized, and the best implemented scheme for these terms dispatched. For example, advection terms are discretized with the upwind scheme. There are also special schemes for the nonlinear Laplacian and spherical Laplacian. See [here for how this term matching occurs](https://github.com/SciML/MethodOfLines.jl/blob/master/src/discretization/generate_finite_difference_rules.jl), note that the order the generated rules are applied is important, with more specific rules applied first to avoid their terms being matched incorrectly by more general rules. The [SymbolicUtils.jl docs](https://symbolicutils.juliasymbolics.org/rewrite/) are a useful companion here. See [here for the practical implementation of the finite difference schemes](https://github.com/SciML/MethodOfLines.jl/blob/master/src/discretization/differential_discretizer.jl).
1414

15-
Now we have a system of equations which are either ODEs, linear, or nonlinear equations and an equal number of unknowns. See [here for the system](@ref brusssys) that is generated for the Brusselator at low point count. The structure of the system is simplified with `ModelingToolkit.structural_simplify`, and then either an `ODEProblem` or `NonlinearProblem` is returned. Under the hood, the `ODEProblem` generates a fast semidiscretization, written in Julia with `RuntimeGeneratedFunctions`. See [here for an example of the generated code](@ref brusscode) for the Brusselator system at low point count.
15+
Now we have a system of equations which are either ODEs, linear, or nonlinear equations and an equal number of unknowns. See [here for the system](@ref brusssys) that is generated for the Brusselator at low point count. The structure of the system is simplified with `ModelingToolkit.mtkcompile`, and then either an `ODEProblem` or `NonlinearProblem` is returned. Under the hood, the `ODEProblem` generates a fast semidiscretization, written in Julia with `RuntimeGeneratedFunctions`. See [here for an example of the generated code](@ref brusscode) for the Brusselator system at low point count.

src/MOL_discretization.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ function get_discrete(pdesys, discretization)
6666
[Num(x) => s.grid[x] for x in s.x̄], [Num(u) => s.discvars[u] for u in s.ū]))
6767
end
6868

69-
function ModelingToolkit.ODEFunctionExpr(
69+
function ODEFunctionExpr(
7070
pdesys::PDESystem, discretization::MethodOfLines.MOLFiniteDifference)
7171
sys, tspan = SciMLBase.symbolic_discretize(pdesys, discretization)
7272
try
7373
if tspan === nothing
7474
@assert true "Codegen for NonlinearSystems is not yet implemented."
7575
else
76-
simpsys = structural_simplify(sys)
77-
return ODEFunctionExpr(simpsys)
76+
simpsys = mtkcompile(sys)
77+
return ODEFunction(simpsys; expression = Val{true})
7878
end
7979
catch e
8080
println("The system of equations is:")
@@ -94,7 +94,7 @@ function SciMLBase.ODEFunction(
9494
if tspan === nothing
9595
@assert true "Codegen for NonlinearSystems is not yet implemented."
9696
else
97-
simpsys = structural_simplify(sys)
97+
simpsys = mtkcompile(sys)
9898
if analytic !== nothing
9999
analytic = analytic isa Dict ? analytic : Dict(analytic)
100100
s = getfield(sys, :metadata).discretespace

src/discretization/staggered_discretize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function SciMLBase.discretize(pdesys::PDESystem,
33
analytic = nothing, kwargs...) where {G <: StaggeredGrid}
44
sys, tspan = SciMLBase.symbolic_discretize(pdesys, discretization)
55
try
6-
simpsys = structural_simplify(sys)
6+
simpsys = mtkcompile(sys)
77
if tspan === nothing
88
add_metadata!(get_metadata(sys), sys)
99
return prob = NonlinearProblem(simpsys, ones(length(simpsys.unknowns));

test/pde_systems/MOL_NonlinearProblem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using DomainSets
1414
0 ~ b + d - 2 * c,
1515
0 ~ d - 1]
1616
@named ns = NonlinearSystem(eqs, [a, b, c, d], [])
17-
sns = structural_simplify(ns)
17+
sns = mtkcompile(ns)
1818
prob = NonlinearProblem(sns, zeros(length(get_unknowns(sns))), [])
1919

2020
sol = NonlinearSolve.solve(prob, NewtonRaphson())

0 commit comments

Comments
 (0)