66[ ![ Coverage Status] ( https://coveralls.io/repos/JuliaDiffEq/DiffEqOperators.jl/badge.svg?branch=master&service=github )] ( https://coveralls.io/github/JuliaDiffEq/DiffEqOperators.jl?branch=master )
77[ ![ codecov.io] ( http://codecov.io/github/shivin9/DiffEqOperators.jl/coverage.svg?branch=master )] ( http://codecov.io/github/JuliaDiffEq/DiffEqOperators.jl?branch=master )
88
9- Construct high order finite-difference operators to discretize a partial
9+ Construct high- order finite-difference operators to discretize a partial
1010differential equation and its boundary conditions by the method of
11- lines. This reduces it to a system of ordinary differential
11+ lines. This reduces it to a system of ordinary differential
1212equations that can be solved by [ ` DifferentialEquations.jl ` ] ( https://juliadiffeq.org/ ) .
1313
1414Both centered and [ upwind] ( https://en.wikipedia.org/wiki/Upwind_scheme )
1515operators are provided, for domains of any dimension, arbitrarily
16- spaced grids, and for any order of accuracy. The cases of 1, 2 and
16+ spaced grids, and for any order of accuracy. The cases of 1, 2, and
17173 dimensions with an evenly spaced grid are optimized with a
18- convolution routine from ` NNlib.jl ` . Care is taken to avoid
18+ convolution routine from ` NNlib.jl ` . Care is taken to avoid
1919unnecessary allocations.
2020
21- Any operator can be concretised as an ` Array ` , a ` BandedMatrix ` or
21+ Any operator can be concretized as an ` Array ` , a ` BandedMatrix ` or
2222a sparse matrix.
2323
2424## The simplest case
2525
2626As shown in the figure, the operators act on a set of samples
27- ` f_j = f(x_j) ` for a function ` f ` at a grid of points ` x_j ` . The
27+ ` f_j = f(x_j) ` for a function ` f ` at a grid of points ` x_j ` . The
2828grid has ` n ` interior points at ` x_j = jh ` for ` j = 1 ` to ` n ` , and 2
29- boundary points at ` x_0 = 0 ` and ` x_{n+1} = (n+1) h ` . The input to
29+ boundary points at ` x_0 = 0 ` and ` x_{n+1} = (n+1) h ` . The input to
3030the numerical operators is a vector ` u = [f_1, f_2, …, f_N] ` , and
3131they output a vector of sampled derivatives `du ≈ [ f'(x_1), f'(x_2),
32- …, f'(x_N)] `, or a higher order derivative as requested.
32+ …, f'(x_N)] `, or a higher- order derivative as requested.
3333
3434A numerical derivative operator ` D ` of order ` m ` can be constructed
35- for this grid with ` D = CenteredDifference(1, m, h, n) ` The argument
36- ` 1 ` indicates that this is a first derivative. Order ` m ` means
35+ for this grid with ` D = CenteredDifference(1, m, h, n) ` . The argument
36+ ` 1 ` indicates that this is the first derivative. Order ` m ` means
3737that the operator is exact up to rounding when ` f ` is a polynomial
3838of degree ` m ` or lower.
3939
4040The derivative operator ` D ` is used along with a boundary condition
41- operator ` Q ` , to compute derivatives at the interior points of the
42- grid. A simple boundary condition ` f(x_0) = f(x_n+1) = 0 ` is
41+ operator ` Q ` to compute derivatives at the interior points of the
42+ grid. A simple boundary condition ` f(x_0) = f(x_n+1) = 0 ` is
4343constructed with ` Q = Dirichlet0BC(eltype(u)) ` .
4444
4545Given these definitions, the derivatives are calculated as if the
46- operators ` D ` and ` Q ` were matrices. ` du = D*Q*u ` . This is an
47- abuse of notation! The particular ` Q ` in this example is a linear
48- operator, but in general boundary conditions are affine operators.
46+ operators ` D ` and ` Q ` were matrices, ` du = D*Q*u ` . This is an
47+ abuse of notation! The particular ` Q ` in this example is a linear
48+ operator but, in general, boundary conditions are affine operators.
4949They have the form ` Q(x) = M*x + c ` , where ` M ` is a matrix and ` c `
50- is a constant vector. As a consequence, ` Q ` can not be concretized
50+ is a constant vector. As a consequence, ` Q ` cannot be concretized
5151to a matrix.
5252
5353![ Actions of DiffEqOperators on interior points and ghost points] ( action.svg )
5454
5555The operator ` D ` works by interpolating a polynomial of degree ` m `
56- through ` m+1 ` adjacent points on the grid. Near the middle of the
56+ through ` m+1 ` adjacent points on the grid. Near the middle of the
5757grid, the derivative is approximated at ` x_j ` by interpolating a
58- polynomial of order ` m ` with ` x_j ` at its centre. To define a
59- order-` m ` polynomial, values are required at ` m+1 ` points. When
58+ polynomial of order ` m ` with ` x_j ` at its centre. To define an
59+ order-` m ` polynomial, values are required at ` m+1 ` points. When
6060` x_j ` is too close to the boundary for that to fit, the polynomial
6161is interpolated through the leftmost or rightmost ` m+1 ` points,
6262including two “ghost” points that ` Q ` appends on the boundaries.
6363The numerical derivatives are linear combinations of the values
64- through which the polynomials are interpolated. The vectors of
64+ through which the polynomials are interpolated. The vectors of the
6565coefficients in these linear combinations are called “stencils”.
6666Because ` D ` takes values at the ghost points and returns values at
67- the interior points, it is a ` n×(n+2) ` matrix.
67+ the interior points, it is an ` n×(n+2) ` matrix.
6868
6969The boundary condition operator ` Q `
70- acts as an ` (n+2)×n ` matrix. The output ` Q*u ` is a vector of values
70+ acts as an ` (n+2)×n ` matrix. The output ` Q*u ` is a vector of values
7171on the ` n ` interior and the 2 boundary points, ` [a, f(x_1), …, f(x_N), b] ` .
72- The interior points take the values of ` u ` . The values ` a ` and ` b ` are
73- samples at “ghost” points on the grid boundaries. As shown, these
72+ The interior points take the values of ` u ` . The values ` a ` and ` b ` are
73+ samples at “ghost” points on the grid boundaries. As shown, these
7474values are assigned so that an interpolated polynomial ` P(x) ` satisfies
75- the left hand boundary condition, and ` Q(x) ` satisfies the right hand
76- boundary condition. The boundary conditions provided by the
75+ the left hand boundary condition, and ` Q(x) ` satisfies the right- hand
76+ boundary condition. The boundary conditions provided by the
7777library are precisely those for which the values ` a ` and ` b ` are affine
7878functions of the interior values ` f_j ` , so that ` Q ` is an affine operator.
7979
@@ -84,28 +84,28 @@ and the derivative and boundary condition operators are similar
8484to matrices.
8585
8686In two dimensions, the values ` f(x_j) ` are naturally stored as a
87- matrix. Taking derivatives along the downwards axis is easy, because
88- matrices act columnwise. Horizontal derivatives can be taken by
89- transposing the matrices. The derivative along the rightward axis
90- is ` (D*F')' = F*D' ` . This is easy to code, but less easy to read
87+ matrix. Taking derivatives along the downwards axis is easy, because
88+ matrices act columnwise. Horizontal derivatives can be taken by
89+ transposing the matrices. The derivative along the rightward axis
90+ is ` (D*F')' = F*D' ` . This is easy to code, but less easy to read
9191for those who haven't seen it before.
9292
9393When a function has three or more arguments, its values are naturally
94- stored in a higher dimensional array. Julia's multiplication
94+ stored in a higher- dimensional array. Julia's multiplication
9595operator is only defined for ` Vector ` and ` Matrix ` , so applying an
9696operator matrix to these arrays would require a complicated and
9797error prone series of ` reshape ` and axis permutation functions.
9898
9999Therefore the types of derivative and boundary condition operators
100- are parameterised by the axis along which the operator acts. With
100+ are parameterised by the axis along which the operator acts. With
101101derivative operators, the axis is supplied as a type parameter.
102102The simple case ` CenteredDifference(…) ` is equivalent to
103103` CenteredDifference{1}(…) ` , row-wise derivatives are taken by
104104` CenteredDifference{2}(…) ` , sheet-wise by ` CenteredDifference{3}(…) ` ,
105105and along the ` N ` th axis by ` CenteredDifference{N}(…) ` .
106106
107- Boundary conditions are more complicated. See ` @doc MultiDimBC `
108- for how they are supposed to work in multiple dimensions. They
107+ Boundary conditions are more complicated. See ` @doc MultiDimBC `
108+ for how they are supposed to work in multiple dimensions. They
109109don't currently work that way.
110110
111111## Constructors
@@ -125,15 +125,15 @@ UpwindDifference{N}(derivative_order::Int,
125125The arguments are:
126126
127127- ` N ` : The directional dimension of the discretization. If ` N ` is not given,
128- it is assumed to be 1, i.e. differencing occurs along columns.
128+ it is assumed to be 1, i.e., differencing occurs along columns.
129129- ` derivative_order ` : the order of the derivative to discretize.
130130- ` approximation_order ` : the order of the discretization in terms of O(dx^order).
131131- ` dx ` : the spacing of the discretization. If ` dx ` is a ` Number ` , the operator
132132 is a uniform discretization. If ` dx ` is an array, then the operator is a
133133 non-uniform discretization.
134134- ` len ` : the length of the discretization in the direction of the operator.
135135- ` coeff_func ` : An operational argument for a coefficient function ` f(du,u,p,t) `
136- which sets the coefficients of the operator. If ` coeff_func ` is a ` Number `
136+ which sets the coefficients of the operator. If ` coeff_func ` is a ` Number ` ,
137137 then the coefficients are set to be constant with that number. If ` coeff_func `
138138 is an ` AbstractArray ` with length matching ` len ` , then the coefficients are
139139 constant but spatially dependent.
@@ -159,11 +159,11 @@ The following concretizations are provided:
159159
160160Additionally, the function ` sparse ` is overloaded to give the most efficient
161161matrix type for a given operator. For one-dimensional derivatives this is a
162- ` BandedMatrix ` , while for higher dimensional operators this is a ` BlockBandedMatrix ` .
162+ ` BandedMatrix ` , while for higher- dimensional operators this is a ` BlockBandedMatrix ` .
163163The concretizations are made to act on ` vec(u) ` .
164164
165- A contraction operator concretizes to an ordinary matrix, no matter which dimension
166- the contraction acts along, by doing the kroncker product formulation. I.e., the
165+ A contraction operator concretizes to an ordinary matrix, no matter which dimension
166+ the contraction acts along, by doing the Kronecker product formulation. I.e., the
167167action of the built matrix will match the action on ` vec(u) ` .
168168
169169## Boundary Condition Operators
@@ -281,4 +281,4 @@ will inherit the appropriate action.
281281### Efficiency of Composed Operator Actions
282282
283283Composed operator actions utilize NNLib.jl in order to do cache-efficient
284- convolution operations in higher dimensional combinations.
284+ convolution operations in higher- dimensional combinations.
0 commit comments