Professional Documents
Culture Documents
David Zwicker
(Dated: August 18, 2022)
We here document the differential operators and the associated boundary conditions that are used
in the finite difference approximation. We also derive special versions of the Laplace operator that
conserves the total mass.
I. GENERAL CONSIDERATIONS For a vector field vα (r), which associate a vector with
each grid point, possible boundary conditions are
The main objects in ‘py-pde‘ are fields that are ex-
pressed on discretized grids. The package provides many value: vα = Aα (2a)
functions to manipulate these fields. Some functions normal component: n α vα =A (2b)
(e.g., addition, multiplication, integrals) do only use the normal derivative: nβ ∂β vα = Bα (2c)
actual field values, while others (e.g., differential opera- normal comp. of normal deriv.: nα nβ ∂β vα =B (2d)
tors and interpolation) might require information on the
behavior of the field at the boundary. This documents There are now many more options, where the first two
specifies details for how boundary conditions are handled. specify values (Dirichlet conditions) and the last two
Generally, boundary conditions are imposed using so- specify derivatives (Neumann conditions). Additionally,
called ghost cells (or virtual points), which specify the the conditions differ in that they either specify the full
value of the fields one support point beyond the bound- vector (conditions 1 and 3) or just the normal component
ary. The idea is that the values of the ghost cells are (conditions 2 and 4). The latter choice obviously contains
set such that the boundary condition between the ghost less information, but is sufficient for differential operators
cell and the first real cell is imposed exactly. While this that reduce the field rank (e.g., divergence). Conversely,
is quite straight-forward for scalar fields, fields of higher specifying the full vector using the first or third condi-
rank (i.e., vector and tensor fields) require more care. To tion is necessary for interpolating vector fields correctly.
2
Note also that the Dirichlet condition imposes the dot Note that the Dirichlet condition in this case imposes
product between the normal vector and the vector field, the dot product between the normal vector and the vec-
which in a simple 1d system implies v1 (x = xL ) = −A tor field, which in a simple 1d system implies v1 (x =
and v1 (x = xR ) = A for the lower and upper boundary, xL ) = −A and v1 (x = xR ) = A for the lower and up-
respectively. Similarly, the Neumann condition evaluates per boundary, respectively. Similarly, the Neumann con-
the directional derivative of the vector field in the normal dition evaluates the directional derivative of the vector
direction nβ of the boundary. field in the normal direction nβ of the boundary. This
implies that the tangential components of the vector field
do not affect the boundary condition.
II. BOUNDARY CONDITIONS FOR
DIFFERENTIAL OPERATORS
D. Vector Laplacian
We start with general considerations that are indepen-
dent of the grid type. Here, we consider differential op- The Vector Laplacian is a simple generalization of the
erators that act on fields defined in a domain Ω. In par- ordinary Laplace operator to a vector field vα (r). Possi-
ticular, we discuss the boundary conditions that can be ble boundary conditions are
enforced with each type of operator. We here use a com-
value: v α = Aα (6a)
ponent notation with implicit Einstein summation to de-
note contractions explicitly. For instance, ∂α vα denotes normal derivative: nβ ∂β vα = Bα (6b)
the divergence of a vector field vα (r), and tαα (r) is the
which are applied at positions r ∈ ∂Ω.
trace of a tensor field tαβ (r).
Moreover, the Laplace operator in spherical coordinates A. Boundary condition at the origin
′
reads ∇2 f (r) = f ′′ (r) + f r(r) , which in the discretized
version becomes Due to the symmetry, only vanishing derivatives are
allowed at the inner boundary at the origin, implying the
yn+1 − 2yn + yn−1 yn+1 − yn−1
∂α2 f ∼ + (16) virtual support point y−1 = y0 . Hence, the differential
∆r2 2rn ∆r operators become
y1 − y0 4y0
A. Boundary condition at the origin ∂α vα (r)|r=0 ∼ + (20a)
2∆r ∆r
2
y 1 − y0
∂α f (r)r=0 ∼ 3 (20b)
Due to the symmetry, only vanishing derivatives are ∆r2
allowed at the inner boundary at the origin, implying the
virtual support point y−1 = y0 . Hence, the differential Note that the latter expression applies to both the non-
operators become conservative and the conservative form of the Laplacian.
y1 − y0 2y0
∂α vα (r)|r=0 ∼ + (17a) B. Boundary condition at the outer side
2∆r ∆r
y1 − y 0
∂α2 f (r)r=0 ∼ 2
(17b)
∆r2 At the outer boundary, we can impose boundary con-
ditions similar to the Cartesian grid.
a. Dirichlet (Constant value): Assuming the
B. Boundary condition at the outer side boundary condition f (R) = a, we obtain yN = 2a−yN −1 .
b. Neumann (Constant derivative): Here, we con-
At the outer boundary, we can impose boundary con- sider the boundary condition f ′ (L) = b, which specifies
ditions similar to the Cartesian grid. the outward derivative to equal the value b. We obtain
a. Dirichlet (Constant value): Assuming the yn = yn−1 + b∆x.
boundary condition f (R) = a, we obtain yN = 2a−yN −1 .
b. Neumann (Constant derivative): Here, we con-
sider the boundary condition f ′ (L) = b, which specifies C. Conservative Laplace operator
the outward derivative to equal the value b. We obtain
yn = yn−1 + b∆x. We call a discrete Laplace operator conservative when
it preserves the desirable conservation equation
Z I
V. DIFFERENTIAL OPERATORS ON ∂α2 f dV = ∂α f nα dS . (21)
SPHERICAL GRID Ω ∂Ω
Note that this form of the Laplace operator is notRconser- which also skip the factor 4π. Eq. (23) provides an ex-
vative, i. e., the discretized version of the integral ∂α2 f dr pression for the operator, which relies on the values on
does not vanish. the adjacent boundaries. Since integrating the operator
5
over the entire domain corresponds to summing all con- where the derivatives f ′ (r) are evaluated at the midpoints
tributions from individual shells, this formulation ensures and can thus be represented as
that adjacent shells have opposite contributions, so that
n+1 − yn
y
finally only the outer boundaries contribute, ensuring the f ′ rn+ 12 ∼ (26a)
conservative property. Taken together we find ∆r
y −y
n n−1
f ′ rn− 21 ∼ . (26b)
∆r
In the special case where the spherical grid does not have
a hole (r0 = 0), we then arrive at
ZZ ZZ
r2 sin θ ∂α2 f drdθ = sin θ∂r r2 ∂r f (r, θ) + ∂θ sin θ∂θ f (r, θ) drdθ
cell(n,m) cell(n,m)
Z rn+ 1 Z θm+ 1
2 2
∂r r2 ∂r f (r, θ) dr + ∆r
= cos θm− 21 − cos θm+ 12 ∂θ sin θ∂θ f (r, θ) dθ
rn− 1 θm− 1
2 2
r 1 θm+ 1
− cos θm+ 21 r2 ∂r f (r, θ) rn+ 21 + ∆r sin θ∂θ f (r, θ) θ 21
= cos θm− 21 (28)
n− m−
2 2
Here we assumed that we can neglect angular depen- implementation of the operator, we again integrate over
dencies in the radial integral and vice versa. Using the a single shell,
(scaled) volume of a grid cell, Z r 1
n+ r 1
2
∂α vα r2 dr = r2 vr (r) rn+ 21
3 3 (32)
rn+ 1 − r
n− 12 n−
rn− 1 2
Vn,m = cos θm− 12 − cos θm+ 12 2
, (29) 2
3
Consequently, we find
we can write this as
2 2
rn+ 1 vr (rn+ 1 ) − r v (r 1 )
n− 1 r n− 2
r 1
Vn,m ∂α2 f = cos θm− 12 − cos θm+ 12 r2 ∂r f (r, θ) rn+ 21 ∂α vα ∼ 2 2 2
(33)
n−
2 Vn
θm+ 1
+ ∆r sin θ∂θ f (r, θ) θ 21 (30) where Vn is given by Eq. (24).
m−
2
The divergence of a spherically-symmetric vector field The divergence of a spherically-symmetric vector ten-
reads sor field reads
vanish. The integral over the shell reads where we skipped the factor 4π stemming from the an-
Z r 1 gle integration. Assuming that the quantity Dϕ (tαβ ) is
n+ r 1
2
∂β trβ r2 dr = r2 vr (r) rn+ 21
(35) constant across the discretization cell, we thus find
rn− 1 n−
2
2 h irn +∆r/2
Vn Dϕ (tαβ ) ∼ 2rtϕϕ (r) (40)
and we find rn −∆r/2
2 2
rn+ 1 vr (rn+ 1 ) − r v (r 1 ) where Vn is given by Eq. (24). Consequently,
2 n− 1 r n− 2
∂ α vα ∼ 2 2
(36)
Vn 2 h i
Dϕ (tαβ ) ∼ rn+ 21 tϕϕ (rn+ 21 ) − rn− 21 tϕϕ (rn− 12 ) (41)
where Vn is given by Eq. (24). Vn
h i h i
′
2
2rn+ 12 trr (rn+ 21 ) − tϕϕ (rn+ 21 ) + rn+ 1 trr (rn+ 1 ) − 2rn− 1
2 2
trr (rn− 1 ) − tϕϕ (r
2 n− 1) − r
2
2
t′ (r 1 )
n− 1 rr n− 2
2 2
∂α ∂β tαβ ∼
Vn
(46)