Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 840c926

Browse files
authored
Merge pull request #19 from JuliaDiffEq/master
merge master
2 parents 797b394 + 806acc1 commit 840c926

20 files changed

+1773
-527
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ version = "4.1.0"
55

66
[deps]
77
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
8+
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
89
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
910
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
11+
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
1012
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1113
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
1214
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

README.md

Lines changed: 212 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,216 @@
55
[![Coverage Status](https://coveralls.io/repos/JuliaDiffEq/DiffEqOperators.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/JuliaDiffEq/DiffEqOperators.jl?branch=master)
66
[![codecov.io](http://codecov.io/github/shivin9/DiffEqOperators.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaDiffEq/DiffEqOperators.jl?branch=master)
77

8-
## Julia Library to solve PDEs using Finite Difference Method
9-
This library is going to be a part of DiffEq.jl to become the PDE solver alongside Fenics.jl.
8+
DiffEqOperators.jl provides a set of pre-defined operators for use with
9+
DifferentialEquations.jl. These operators make it easy to discretize and solve
10+
common partial differential equations.
1011

11-
Blog posts related to the development of DiffEqOperators.jl can he found [here](https://shivin9.github.io/blog/blogposts/)
12+
## Automated Finite Difference Method (FDM) Operators
13+
14+
This library provides lazy operators for arbitrary order uniform and non-uniform
15+
finite difference discretizations of arbitrary high derivative order and for
16+
arbitrarily high dimensions.
17+
18+
There are two types of `DerivativeOperator`s: the `CenteredDifference` operator
19+
and the `UpwindDifference` operator. The `CenteredDifference` operator utilizes
20+
a central difference scheme while the upwind operator requires a coefficient
21+
to be defined to perform an upwinding difference scheme.
22+
23+
### Operators Constructors
24+
25+
The constructors are as follows:
26+
27+
```julia
28+
CenteredDifference{N}(derivative_order::Int,
29+
approximation_order::Int, dx,
30+
len::Int, coeff_func=nothing)
31+
32+
UpwindDifference{N}(derivative_order::Int,
33+
approximation_order::Int, dx
34+
len::Int, coeff_func=nothing)
35+
```
36+
37+
The arguments are:
38+
39+
- `N`: The directional dimension of the discretization. If `N` is not given,
40+
it is assumed to be 1, i.e. differencing occurs along columns.
41+
- `derivative_order`: the order of the derivative to discretize.
42+
- `approximation_order`: the order of the discretization in terms of O(dx^order).
43+
- `dx`: the spacing of the discretization. If `dx` is a `Number`, the operator
44+
is a uniform discretization. If `dx` is an array, then the operator is a
45+
non-uniform discretization.
46+
- `len`: the length of the discretization in the direction of the operator.
47+
- `coeff_func`: An operational argument for a coefficient function `f(du,u,p,t)`
48+
which sets the coefficients of the operator. If `coeff_func` is a `Number`
49+
then the coefficients are set to be constant with that number. If `coeff_func`
50+
is an `AbstractArray` with length matching `len`, then the coefficients are
51+
constant but spatially dependent.
52+
53+
`N`-dimensional derivative operators need to act against a value of at least
54+
`N` dimensions.
55+
56+
### Example
57+
58+
The 3-dimensional Laplacian is created by:
59+
60+
```julia
61+
N = 64
62+
Dxx = CenteredDifference(2,2,dx,N)
63+
Dyy = CenteredDifference{2}(2,2,dx,N)
64+
Dzz = CenteredDifference{3}(2,2,dx,N)
65+
L = Dxx + Dyy + Dzz
66+
67+
u = rand(N,N,N)
68+
L*u
69+
```
70+
71+
### Derivative Operator Actions
72+
73+
These operators are lazy, meaning the memory is not allocated. Similarly, the
74+
operator actions `*` can be performed without ever building the operator
75+
matrices. Additionally, `mul!(y,L,x)` can be performed for non-allocating
76+
applications of the operator.
77+
78+
### Concretizations
79+
80+
The following concretizations are provided:
81+
82+
- `Array`
83+
- `SparseMatrixCSC`
84+
- `BandedMatrix`
85+
- `BlockBandedMatrix`
86+
87+
Additionally, the function `sparse` is overloaded to give the most efficient
88+
matrix type for a given operator. For one-dimensional derivatives this is a
89+
`BandedMatrix`, while for higher dimensional operators this is a `BlockBandedMatrix`.
90+
The concretizations are made to act on `vec(u)`.
91+
92+
## Boundary Condition Operators
93+
94+
Boundary conditions are implemented through a ghost node approach. The discretized
95+
values `u` should be the interior of the domain so that, for the boundary value
96+
operator `Q`, `Q*u` is the discretization on the closure of the domain. By
97+
using it like this, `L*Q*u` is the `NxN` operator which satisfies the boundary
98+
conditions.
99+
100+
### Periodic Boundary Conditions
101+
102+
The constructor `PeriodicBC` provides the periodic boundary condition operator.
103+
104+
### Robin Boundary Conditions
105+
106+
The variables in l are `[αl, βl, γl]`, and correspond to a BC of the form
107+
`al*u(0) + bl*u'(0) = cl`, and similarly `r` for the right boundary
108+
`ar*u(N) + br*u'(N) = cl`.
109+
110+
```julia
111+
RobinBC(l::AbstractArray{T}, r::AbstractArray{T}, dx::AbstractArray{T}, order = one(T))
112+
```
113+
114+
Additionally, the following helpers exist for the Neumann `u'(0) = α` and
115+
Dirichlet `u(0) = α` cases.
116+
117+
```julia
118+
Dirichlet0BC(T::Type)
119+
DirichletBC::AbstractVector{T}, dx::AbstractVector{T}, order = 1)
120+
Neumann0BC(dx::Union{AbstractVector{T}, T}, order = 1)
121+
NeumannBC::AbstractVector{T}, dx::AbstractVector{T}, order = 1)
122+
```
123+
124+
### General Boundary Conditions
125+
126+
Implements a generalization of the Robin boundary condition, where α is a vector
127+
of coefficients. Represents a condition of the form
128+
α[1] + α[2]u[0] + α[3]u'[0] + α[4]u''[0]+... = 0
129+
130+
```julia
131+
GeneralBC(αl::AbstractArray{T}, αr::AbstractArray{T}, dx::AbstractArray{T}, order = 1)
132+
```
133+
134+
### Multidimensional Boundary Conditions
135+
136+
```julia
137+
Q_dim = MultiDimBC(Q, size(u), dim)
138+
```
139+
140+
turns `Q` into a boundary condition along the dimension `dim`. Additionally,
141+
to apply the same boundary values to all dimensions, one can use
142+
143+
```julia
144+
Qx,Qy,Qz = MultiDimBC(YourBC, size(u)) # Here u is 3d
145+
```
146+
147+
Multidimensional BCs can then be composed into a single operator with:
148+
149+
```julia
150+
Q = compose(BCs...)
151+
```
152+
153+
### Operator Actions
154+
155+
The boundary condition operators act lazily by appending the appropriate values
156+
to the end of the array, building the ghost-point extended version for the
157+
derivative operator to act on. This utilizes special array types to not require
158+
copying the interior data.
159+
160+
### Concretizations
161+
162+
The following concretizations are provided:
163+
164+
- `Array`
165+
- `SparseMatrixCSC`
166+
167+
Additionally, the function `sparse` is overloaded to give the most efficient
168+
matrix type for a given operator. For these operators it's `SparseMatrixCSC`.
169+
The concretizations are made to act on `vec(u)`.
170+
171+
## GhostDerivative Operators
172+
173+
When `L` is a `DerivativeOperator` and `Q` is a boundary condition operator,
174+
`L*Q` produces a `GhostDerivative` operator which is the composition of the
175+
two operations.
176+
177+
### Concretizations
178+
179+
The following concretizations are provided:
180+
181+
- `Array`
182+
- `SparseMatrixCSC`
183+
- `BandedMatrix`
184+
185+
Additionally, the function `sparse` is overloaded to give the most efficient
186+
matrix type for a given operator. For these operators it's `BandedMatrix` unless
187+
the boundary conditions are `PeriodicBC`, in which case it's `SparseMatrixCSC`.
188+
The concretizations are made to act on `vec(u)`.
189+
190+
## Matrix-Free Operators
191+
192+
```julia
193+
MatrixFreeOperator(f::F, args::N;
194+
size=nothing, opnorm=true, ishermitian=false) where {F,N}
195+
```
196+
197+
A `MatrixFreeOperator` is a linear operator `A*u` where the action of `A` is
198+
explicitly defined by an in-place function `f(du, u, p, t)`.
199+
200+
## Jacobian-Vector Product Operators
201+
202+
```julia
203+
JacVecOperator{T}(f,u::AbstractArray,p=nothing,t::Union{Nothing,Number}=nothing;autodiff=true,ishermitian=false,opnorm=true)
204+
```
205+
206+
The `JacVecOperator` is a linear operator `J*v` where `J` acts like `df/du`
207+
for some function `f(u,p,t)`. For in-place operations `mul!(w,J,v)`, `f`
208+
is an in-place function `f(du,u,p,t)`.
209+
210+
## Operator Compositions
211+
212+
Multiplying two DiffEqOperators will build a `DiffEqOperatorComposition`, while
213+
adding two DiffEqOperators will build a `DiffEqOperatorCombination`. Multiplying
214+
a DiffEqOperator by a scalar will produce a `DiffEqScaledOperator`. All
215+
will inherit the appropriate action.
216+
217+
### Efficiency of Composed Operator Actions
218+
219+
Composed operator actions utilize NNLib.jl in order to do cache-efficient
220+
convolution operations in higher dimensional combinations.

docs/DiffEqOperators.md

Lines changed: 0 additions & 138 deletions
This file was deleted.

docs/HeatEquation.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)