Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraDysis committed Feb 23, 2025
1 parent fad180c commit ef7383e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 93 deletions.
14 changes: 7 additions & 7 deletions src/fdm/differentiation_matrix.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
fdm_differentiation_matrix(::Type{TR}, der_order::Integer, acc_order::Integer, n::Integer, boundary::Bool=false)
fdm_differentiation_matrix(::Type{TR}, derivative_order::Integer, accuracy_order::Integer, n::Integer, boundary::Bool=false)
Construct a matrix representing a finite difference operator for numerical differentiation.
# Arguments
- `TR`: Type parameter for the real number type to be used
- `der_order`: Order of the derivative to approximate
- `acc_order`: Order of accuracy for the approximation
- `derivative_order`: Order of the derivative to approximate
- `accuracy_order`: Order of accuracy for the approximation
- `n`: Number of grid points
- `boundary`: Flag to indicate if the matrix should include shifted boundary finite difference coefficients (default: `false`)
- `transpose`: Flag to indicate if the matrix should be transposed (default: `false`)
Expand All @@ -23,20 +23,20 @@ Construct a matrix representing a finite difference operator for numerical diffe
"""
function fdm_differentiation_matrix(
::Type{TR},
der_order::Integer,
acc_order::Integer,
derivative_order::Integer,
accuracy_order::Integer,
n::Integer;
boundary::Bool=true,
transpose::Bool=false,
) where {TR<:Real}
op = fdm_centralop(der_order, acc_order, one(TR))
op = fdm_centralop(derivative_order, accuracy_order, one(TR))
num_side = op.num_side
wts = op.wts

if boundary
diffmat = BandedMatrix(Zeros{TR}(n, n), (num_side, num_side))
else
op_left, op_right = fdm_boundop(der_order, acc_order, one(TR))
op_left, op_right = fdm_boundop(derivative_order, accuracy_order, one(TR))
num_boundcoeffs = op_left.num_coeffs
wts_left, wts_right = op_left.wts, op_right.wts

Expand Down
8 changes: 4 additions & 4 deletions src/fdm/dissipation.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
fdm_dissipation_order(acc_order::Integer)
fdm_dissipation_order(accuracy_order::Integer)
Calculate the order of dissipation needed for a given finite difference accuracy order [Babiuc:2007vr](@cite).
For a scheme of accuracy order 2r-2, returns dissipation order 2r.
"""
function fdm_dissipation_order(acc_order::Integer)
@argcheck iseven(acc_order) "Only even orders are supported."
r = div(acc_order + 2, 2)
function fdm_dissipation_order(accuracy_order::Integer)
@argcheck iseven(accuracy_order) "Only even orders are supported."
r = div(accuracy_order + 2, 2)
return 2r
end

Expand Down
56 changes: 28 additions & 28 deletions src/fdm/operator.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct FDMCentralOp{TR<:Real}
der_order::Integer
acc_order::Integer
derivative_order::Integer
accuracy_order::Integer
num_coeffs::Integer
num_side::Integer
wts::Vector{TR}
Expand All @@ -15,30 +15,30 @@ end
end

"""
fdm_centralop(der_order::Integer, acc_order::Integer, dx::TR) where {TR<:AbstractFloat}
fdm_centralop(derivative_order::Integer, accuracy_order::Integer, dx::TR) where {TR<:AbstractFloat}
Create a central finite difference operator with specified derivative order and accuracy.
# Arguments
- `der_order::Integer`: The order of the derivative to approximate
- `acc_order::Integer`: The desired order of accuracy (must be even)
- `derivative_order::Integer`: The order of the derivative to approximate
- `accuracy_order::Integer`: The desired order of accuracy (must be even)
- `dx::TR`: Grid spacing
```
"""
function fdm_centralop(
der_order::Integer, acc_order::Integer, dx::TR
derivative_order::Integer, accuracy_order::Integer, dx::TR
) where {TR<:AbstractFloat}
wts = fdm_central_weights(TR, der_order, acc_order)
wts = fdm_central_weights(TR, derivative_order, accuracy_order)
num_coeffs = length(wts)
num_side = div(num_coeffs - 1, 2)
return FDMCentralOp{TR}(
der_order, acc_order, num_coeffs, num_side, wts, one(TR) / dx^der_order
derivative_order, accuracy_order, num_coeffs, num_side, wts, one(TR) / dx^derivative_order
)
end

struct FDMBoundOp{TR<:Real}
der_order::Integer
acc_order::Integer
derivative_order::Integer
accuracy_order::Integer
num_coeffs::Integer
num_points::Integer
wts::Matrix{TR}
Expand All @@ -53,34 +53,34 @@ end
end

"""
fdm_boundop(der_order::Integer, acc_order::Integer, dx::TR) where {TR<:AbstractFloat}
fdm_boundop(derivative_order::Integer, accuracy_order::Integer, dx::TR) where {TR<:AbstractFloat}
Create a shifted finite difference operator with specified derivative order and accuracy for boundary.
# Arguments
- `der_order::Integer`: The order of the derivative to approximate
- `acc_order::Integer`: The desired order of accuracy (must be even)
- `derivative_order::Integer`: The order of the derivative to approximate
- `accuracy_order::Integer`: The desired order of accuracy (must be even)
- `dx::TR`: Grid spacing
```
"""
function fdm_boundop(
der_order::Integer, acc_order::Integer, dx::TR
derivative_order::Integer, accuracy_order::Integer, dx::TR
) where {TR<:AbstractFloat}
wts_left, wts_right = fdm_boundary_weights(TR, der_order, acc_order)
wts_left, wts_right = fdm_boundary_weights(TR, derivative_order, accuracy_order)
num_coeffs = size(wts_left, 1)
num_points = size(wts_left, 2)
op_left = FDMBoundOp{TR}(
der_order, acc_order, num_coeffs, num_points, wts_left, one(TR) / dx^der_order
derivative_order, accuracy_order, num_coeffs, num_points, wts_left, one(TR) / dx^derivative_order
)
op_right = FDMBoundOp{TR}(
der_order, acc_order, num_coeffs, num_points, wts_right, one(TR) / dx^der_order
derivative_order, accuracy_order, num_coeffs, num_points, wts_right, one(TR) / dx^derivative_order
)
return op_left, op_right
end

struct FDMHermiteOp{TR<:Real}
der_order::Integer
acc_order::Integer
derivative_order::Integer
accuracy_order::Integer
num_coeffs::Integer
num_side::Integer
Dwts::Vector{TR}
Expand All @@ -97,30 +97,30 @@ function (op::FDMHermiteOp{TR})(
end

"""
fdm_hermiteop(der_order::Integer, acc_order::Integer, dx::TR) where {TR<:AbstractFloat}
fdm_hermiteop(derivative_order::Integer, accuracy_order::Integer, dx::TR) where {TR<:AbstractFloat}
Create a Hermite finite difference operator with specified derivative order and accuracy.
# Arguments
- `der_order::Integer`: The order of the derivative to approximate
- `acc_order::Integer`: The desired order of accuracy (must be even)
- `derivative_order::Integer`: The order of the derivative to approximate
- `accuracy_order::Integer`: The desired order of accuracy (must be even)
- `dx::TR`: Grid spacing
"""
function fdm_hermiteop(
der_order::Integer, acc_order::Integer, dx::TR
derivative_order::Integer, accuracy_order::Integer, dx::TR
) where {TR<:AbstractFloat}
Dwts, Ewts = fdm_hermite_weights(TR, der_order, acc_order)
Dwts, Ewts = fdm_hermite_weights(TR, derivative_order, accuracy_order)
num_coeffs = length(Dwts)
num_side = div(num_coeffs - 1, 2)
return FDMHermiteOp{TR}(
der_order,
acc_order,
derivative_order,
accuracy_order,
num_coeffs,
num_side,
Dwts,
Ewts,
one(TR) / dx^der_order,
one(TR) / dx^(der_order - 1),
one(TR) / dx^derivative_order,
one(TR) / dx^(derivative_order - 1),
)
end

Expand Down
30 changes: 15 additions & 15 deletions src/fdm/utils.jl
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
"""
fdm_central_width(der_order::Integer, acc_order::Integer)
fdm_central_width(derivative_order::Integer, accuracy_order::Integer)
Calculate the number of coefficients needed for central FDM stencil.
# Arguments
- `der_order::Integer`: Order of the derivative
- `acc_order::Integer`: Order of accuracy
- `derivative_order::Integer`: Order of the derivative
- `accuracy_order::Integer`: Order of accuracy
# References
- [Finite difference coefficient - Wikipedia](https://en.wikipedia.org/wiki/Finite_difference_coefficient)
"""
function fdm_central_width(der_order::Integer, acc_order::Integer)
function fdm_central_width(derivative_order::Integer, accuracy_order::Integer)
# https://github.com/maroba/findiff/blob/master/findiff/coefs.py
# coefficients number for central difference
return 2 * div(der_order + 1, 2) - 1 + acc_order
return 2 * div(derivative_order + 1, 2) - 1 + accuracy_order
end

"""
fdm_hermite_width(der_order::Integer, acc_order::Integer)
fdm_hermite_width(derivative_order::Integer, accuracy_order::Integer)
Calculate the number of coefficients needed for Hermite FDM stencil.
# Arguments
- `der_order::Integer`: Order of the derivative
- `acc_order::Integer`: Order of accuracy
- `derivative_order::Integer`: Order of the derivative
- `accuracy_order::Integer`: Order of accuracy
# References
- [fornberg2021algorithm](@citet*)
"""
function fdm_hermite_width(der_order::Integer, acc_order::Integer)
return return div(der_order, 2) + div(acc_order, 2)
function fdm_hermite_width(derivative_order::Integer, accuracy_order::Integer)
return return div(derivative_order, 2) + div(accuracy_order, 2)
end

"""
fdm_boundary_width(der_order::Integer, acc_order::Integer)
fdm_boundary_width(derivative_order::Integer, accuracy_order::Integer)
Calculate the number of coefficients needed for shifted boundary FDM stencil.
# Arguments
- `der_order::Integer`: Order of the derivative
- `acc_order::Integer`: Order of accuracy
- `derivative_order::Integer`: Order of the derivative
- `accuracy_order::Integer`: Order of accuracy
"""
function fdm_boundary_width(der_order::Integer, acc_order::Integer)
return der_order + acc_order
function fdm_boundary_width(derivative_order::Integer, accuracy_order::Integer)
return derivative_order + accuracy_order
end

"""
Expand Down
Loading

0 comments on commit ef7383e

Please sign in to comment.