You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# depvarbcmaps will dictate what to replace the variable terms with in the bcs
142
142
# replace u(t,0) with u₁, etc
143
143
# * Assume that the BC is in terms of an explicit expression, not containing references to variables other than u_ at the boundary
144
-
144
+
j = s.x2i[x_]
145
+
shift(::LowerBoundary) =zero(II)
146
+
shift(::UpperBoundary) =-unitindex(N, j)
145
147
for u in s.ū
146
148
ifisequal(operation(u), operation(u_))
147
-
depvarderivbcmaps = [(Differential(x_)^d)(u_) =>half_offset_centered_difference(derivweights.halfoffsetmap[Differential(x_)^d], II, s, (s.x2i[x_],x_), u, ufunc) for d in derivweights.orders[x_]]
149
+
depvarderivbcmaps = [(Differential(x_)^d)(u_) =>half_offset_centered_difference(derivweights.halfoffsetmap[Differential(x_)^d], II+shift(boundary), s, (j,x_), u, ufunc) for d in derivweights.orders[x_]]
148
150
149
-
depvarbcmaps = [u_ =>half_offset_centered_difference(derivweights.interpmap[x_], II, s, (s.x2i[x_],x_), u, ufunc)]
151
+
depvarbcmaps = [u_ =>half_offset_centered_difference(derivweights.interpmap[x_], II+shift(boundary), s, (j,x_), u, ufunc)]
Copy file name to clipboardExpand all lines: src/discretization/generate_finite_difference_rules.jl
+29-37Lines changed: 29 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,9 @@
4
4
Interpolate gridpoints by taking the average of the values of the discrete points, or if the offset is outside the grid, extrapolate the value with dx.
@@ -39,7 +36,7 @@ where `finitediff(u, i)` is the finite difference at the interpolated point `i`
39
36
40
37
And so on.
41
38
"""
42
-
functioncartesian_nonlinear_laplacian(expr, II, derivweights, s, x, u)
39
+
functioncartesian_nonlinear_laplacian(expr, II, derivweights, s::DiscreteSpace{N}, x, u)where N
43
40
# Based on the paper https://web.mit.edu/braatzgroup/analysis_of_finite_difference_discretization_schemes_for_diffusion_in_spheres_with_variable_diffusivity.pdf
44
41
# See scheme 1, namely the term without the 1/r dependence. See also #354 and #371 in DiffEqOperators, the previous home of this package.
45
42
@@ -50,8 +47,10 @@ function cartesian_nonlinear_laplacian(expr, II, derivweights, s, x, u)
# Get the outer weights and stencil. clip() essentially removes a point from either end of the grid, for this reason this function is only defined on the interior, not in bcs
# Get the outer weights and stencil. clip() essentially removes a point from either end of the grid, for this reason this function is only defined on the interior, not in bcs#
# Get the correct weights and stencils for this II
57
56
inner_deriv_weights_and_stencil = [get_half_offset_weights_and_stencil(D_inner, I, s, jx) for I in outerstencil]
@@ -61,7 +60,7 @@ function cartesian_nonlinear_laplacian(expr, II, derivweights, s, x, u)
61
60
map_vars_to_interpolated(stencil, weights) = [v =>dot(weights, s.discvars[v][stencil]) for v in s.ū]
62
61
63
62
# Map parameters to interpolated values. Using simplistic extrapolation/interpolation for now as grids are uniform
64
-
map_params_to_interpolated(itap) = x =>interpolate_discrete_param(II[j], s, itap[j]-II[j], x, D_inner.boundary_point_count)
63
+
map_params_to_interpolated(I) = x =>interpolate_discrete_param(II[j], s, I[j]-II[j], x, D_inner.boundary_point_count)
65
64
66
65
# Take the inner finite difference
67
66
inner_difference = [dot(inner_weights, s.discvars[u][inner_stencil]) for (inner_weights, inner_stencil) in inner_deriv_weights_and_stencil]
@@ -75,31 +74,11 @@ function cartesian_nonlinear_laplacian(expr, II, derivweights, s, x, u)
75
74
end
76
75
77
76
"""
78
-
`cartesian_nonlinear_laplacian`
79
-
80
-
Differential(x)(expr(x)*Differential(x)(u(x)))
81
-
82
-
Given an internal multiplying expression `expr`, return the correct finite difference equation for the nonlinear laplacian at the location in the grid given by `II`.
83
-
84
-
The inner derivative is discretized with the half offset centered scheme, giving the derivative at interpolated grid points offset by dx/2 from the regular grid.
85
-
86
-
The outer derivative is discretized with the centered scheme, giving the nonlinear laplacian at the grid point `II`.
where `finitediff(u, i)` is the finite difference at the interpolated point `i` in the grid.
79
+
Based on https://web.mit.edu/braatzgroup/analysis_of_finite_difference_discretization_schemes_for_diffusion_in_spheres_with_variable_diffusivity.pdf
101
80
102
-
And so on.
81
+
See scheme 1 in appendix A. The r = 0 case is treated in a later appendix
103
82
"""
104
83
functionspherical_diffusion(innerexpr, II, derivweights, s, r, u)
105
84
# Based on the paper https://web.mit.edu/braatzgroup/analysis_of_finite_difference_discretization_schemes_for_diffusion_in_spheres_with_variable_diffusivity.pdf
# Since rules don't test for equivalence of multiplication/ division, we need to do it manually
145
125
rules = [@rule*(~~c, $(Differential(x))(*(~~a, $(Differential(x))(u), ~~b)), ~~d) =>*(~~c,cartesian_nonlinear_laplacian(*(a..., b...), II, derivweights, s, x, u), ~~d) for x in s.x̄, u in s.ū]
146
126
147
-
rules = [@rule$(Differential(x))(*(~~a, $(Differential(x))(u), ~~b)) =>cartesian_nonlinear_laplacian(*(a..., b...), II, derivweights, s, x, u) for x in s.x̄, u in s.ū]
127
+
rules =vcat(rules, [@rule/(*(~~c, $(Differential(x))(*(~~a, $(Differential(x))(u), ~~b)), ~~d), ~f) =>*(~~c,cartesian_nonlinear_laplacian(*(a..., b...), II, derivweights, s, x, u), ~~d)/~f for x in s.x̄, u in s.ū])
128
+
129
+
rules =vcat(rules, [@rule/(*(~~c, $(Differential(x))(/(*(~~a, $(Differential(x))(u), ~~b), ~g)), ~~d), ~f) =>*(~~c,cartesian_nonlinear_laplacian(*(a..., b...)/~g, II, derivweights, s, x, u), ~~d)/~f for x in s.x̄, u in s.ū])
130
+
131
+
rules =vcat(rules, [@rule$(Differential(x))(/(*(~~a, $(Differential(x))(u), ~~b), ~d)) =>cartesian_nonlinear_laplacian(*(a..., b...)/~d, II, derivweights, s, x, u) for x in s.x̄, u in s.ū])
148
132
149
133
rules =vcat(vec(rules), vec([@rule ($(Differential(x))($(Differential(x))(u)/~a)) =>cartesian_nonlinear_laplacian(1/~a, II, derivweights, s, x, u) for x in s.x̄, u in s.ū]))
134
+
135
+
rules =vcat(rules, [@rule/(*(~~c, $(Differential(x))(/($(Differential(x))(u), ~g)), ~~d), ~f) =>*(~~c,cartesian_nonlinear_laplacian(1/~g, II, derivweights, s, x, u), ~~d)/~f for x in s.x̄, u in s.ū])
136
+
137
+
rules =vcat(rules, [@rule*(~~c, $(Differential(x))(/($(Differential(x))(u), ~g)), ~~d) =>*(~~c,cartesian_nonlinear_laplacian(1/~g, II, derivweights, s, x, u), ~~d) for x in s.x̄, u in s.ū])
0 commit comments