Skip to content

Commit d1fc6ac

Browse files
Merge pull request #32 from bowenszhu/update-readme
Add package intro and an example in README
2 parents a5040d2 + e94a30b commit d1fc6ac

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,69 @@
11
# ModelOrderReduction.jl
22

33
[![Github Action CI](https://github.com/SciML/ModelOrderReduction.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/SciML/ModelOrderReduction.jl/actions/workflows/CI.yml)
4-
[![codecov](https://codecov.io/gh/SciML/ModelOrderReduction.jl/graph/badge.svg)](https://codecov.io/gh/SciML/ModelOrderReduction.jl)
5-
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
4+
[![codecov](https://codecov.io/gh/SciML/ModelOrderReduction.jl/branch/main/graph/badge.svg)](https://app.codecov.io/gh/SciML/ModelOrderReduction.jl/tree/main)
5+
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
6+
7+
ModelOrderReduction.jl is a package for automatically reducing the computational complexity
8+
of mathematical models, while keeping expected fidelity within a controlled error bound.
9+
These methods function a submodel with a projection
10+
where solving the smaller model gives approximation information about the full model.
11+
MOR.jl uses [ModelingToolkit.jl](https://github.com/SciML/ModelingToolkit.jl)
12+
as a system description and automatically transforms equations
13+
to the subform, defining the observables to automatically lazily reconstruct the full
14+
model on-demand in a fast and stable form.
15+
16+
## Example
17+
#### Proper Orthogonal Decomposition and Discrete Empirical Interpolation Method (POD-DEIM) on the FitzHugh-Nagumo system
18+
```julia
19+
using ModelingToolkit, MethodOfLines, DifferentialEquations, ModelOrderReduction
20+
21+
# firstly construct a ModelingToolkit.PDESystem for the FitzHugh-Nagumo model
22+
@variables x t v(..) w(..)
23+
Dx = Differential(x)
24+
Dxx = Dx^2
25+
Dt = Differential(t)
26+
const L = 1.0
27+
const ε = 0.015
28+
const b = 0.5
29+
const γ = 2.0
30+
const c = 0.05
31+
f(v) = v * (v - 0.1) * (1.0 - v)
32+
i₀(t) = 50000.0t^3 * exp(-15.0t)
33+
eqs =* Dt(v(x, t)) ~ ε^2 * Dxx(v(x, t)) + f(v(x, t)) - w(x, t) + c,
34+
Dt(w(x, t)) ~ b * v(x, t) - γ * w(x, t) + c]
35+
bcs = [v(x, 0.0) ~ 0.0, w(x, 0) ~ 0.0, Dx(v(0, t)) ~ -i₀(t), Dx(v(L, t)) ~ 0.0]
36+
domains = [x (0.0, L), t (0.0, 14.0)]
37+
ivs = [x, t]
38+
dvs = [v(x, t), w(x, t)]
39+
pde_sys = PDESystem(eqs, bcs, domains, ivs, dvs; name = Symbol("FitzHugh-Nagumo"))
40+
41+
# transfer to a ModelingToolkit.ODESystem by automated discretization via MethodOfLines
42+
N = 15 # equidistant discretization intervals
43+
dx = (L - 0.0) / N
44+
dxs = [x => dx]
45+
discretization = MOLFiniteDifference(dxs, t)
46+
ode_sys, tspan = symbolic_discretize(pde_sys, discretization)
47+
simp_sys = structural_simplify(ode_sys)
48+
ode_prob = ODEProblem(simp_sys, nothing, tspan)
49+
50+
# solve the full-order model to get snapshots
51+
sol = solve(ode_prob, Tsit5())
52+
snapshot_simpsys = Array(sol.original_sol)
53+
54+
# set POD and DEIM dimensions
55+
# apply POD-DEIM to obtain the reduced-order model
56+
pod_dim = deim_dim = 5
57+
deim_sys = deim(simp_sys, snapshot_simpsys, pod_dim; deim_dim = deim_dim)
58+
deim_prob = ODEProblem(deim_sys, nothing, tspan)
59+
deim_sol = solve(deim_prob, Tsit5())
60+
61+
# retrieve the approximate solution of the original full-order model
62+
sol_deim_x = deim_sol[x]
63+
sol_deim_v = deim_sol[v(x, t)]
64+
sol_deim_w = deim_sol[w(x, t)]
65+
```
66+
67+
The following figure shows the comparison of the solutions of the 32-dimension full-order model and the POD5-DEIM5 reduced-order model.
68+
69+
![comparison](https://user-images.githubusercontent.com/45696147/195765614-df9092a2-4fca-4602-bb15-81e65b2b572e.svg)

0 commit comments

Comments
 (0)