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
{{ message }}
This repository was archived by the owner on Jul 19, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: src/derivative_operators/derivative_operator.jl
+95-10Lines changed: 95 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -37,9 +37,9 @@ function nonlinear_diffusion!{N}(du::AbstractVector{T}, second_differential_orde
37
37
#p is given as some function of q , p being the diffusion coefficient
38
38
39
39
@assert approx_order>1"approximation_order must be greater than 1."
40
-
if first_differential_order >0
40
+
if first_differential_order >0
41
41
du .= (CenteredDifference{N}(first_differential_order,approx_order,dx,nknots)*q).*(CenteredDifference{N}(second_differential_order,approx_order,dx,nknots)*p)
42
-
else
42
+
else
43
43
du .= q[2:(nknots +1)].*(CenteredDifference{N}(second_differential_order,approx_order,dx,nknots)*p)
44
44
end
45
45
@@ -88,10 +88,10 @@ function CenteredDifference{N}(derivative_order::Int,
# Because it's a N x (N+2) operator, the last stencil on the sides are the [b,0,x,x,x,x] stencils, not the [0,x,x,x,x,x] stencils, since we're never solving for the derivative at the boundary point.
221
+
deriv_spots = (-div(stencil_length,2)+1) :-1
222
+
223
+
stencil_coefs = [convert(SVector{stencil_length, T}, calculate_weights(derivative_order, zero(T), generate_coordinates(i, stencil_x, dummy_x, dx))) for i in interior_x]
A helper function to compute the coefficients of a derivative operator including the boundary coefficients in the half offset centered scheme. See table 2 in https://web.njit.edu/~jiang/math712/fornberg.pdf
@@ -240,7 +278,6 @@ function CompleteHalfCenteredDifference(derivative_order::Int,
240
278
# _high_boundary_coefs = SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, oneunit(T)*x0, reverse(right_boundary_x))) for x0 in R_boundary_deriv_spots]
241
279
242
280
offside =0
243
-
244
281
coefficients =nothing
245
282
246
283
@@ -255,6 +292,54 @@ function CompleteHalfCenteredDifference(derivative_order::Int,
# Because it's a N x (N+2) operator, the last stencil on the sides are the [b,0,x,x,x,x] stencils, not the [0,x,x,x,x,x] stencils, since we're never solving for the derivative at the boundary point.
stencil_coefs = [convert(SVector{centered_stencil_length,T}, calculate_weights(derivative_order, hx[i], x[i-endpoint+1:i+endpoint])) for i in endpoint+1:length(hx)-endpoint, 2)]
319
+
# For each boundary point, for each tappoint in the half offset central difference stencil, we need to calculate the coefficients for the stencil.
320
+
321
+
322
+
_low_boundary_coefs = [convert(SVector{boundary_stencil_length,T}, calculate_weights(derivative_order, offset, low_boundary_x)) for offset in L_boundary_deriv_spots]
_high_boundary_coefs = [convert(SVector{boundary_stencil_length,T}, calculate_weights(derivative_order, offset, high_boundary_x)) for offset in R_boundary_deriv_spots]
@@ -357,7 +442,7 @@ function UpwindDifference{N}(derivative_order::Int,
357
442
358
443
# compute high_boundary_coefs: low_boundary_coefs[upwind = 1 downwind = 2, index of point]
359
444
_upwind_coefs =SMatrix{1,boundary_point_count + offside}([convert(SVector{boundary_stencil_length, T}, calculate_weights(derivative_order, x[i+1], x[len-boundary_stencil_length+3:len+2])) for i in len-boundary_point_count+1-offside:len])
360
-
if offside ==0
445
+
if offside ==0
361
446
_downwind_coefs =SMatrix{1,boundary_point_count}([convert(SVector{boundary_stencil_length,T}, calculate_weights(derivative_order, x[i+1], x[i-stencil_length+2:i+1])) for i in len-boundary_point_count+1:len])
362
447
elseif offside ==1
363
448
_downwind_coefs =SMatrix{1,boundary_point_count + offside}([convert(SVector{boundary_stencil_length,T}, calculate_weights(derivative_order, x[i+1], x[i-stencil_length+2+offside:i+1+offside])) for i in len-boundary_point_count+1-offside:len-offside+1])
0 commit comments