-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ad92a3
commit 1001307
Showing
8 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,4 @@ end | |
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
struct FirstDerivative{T} <: AbstractVector{T} | ||
x::AbstractVector{<:Real} | ||
y::AbstractVector{T} | ||
bc::NTuple{2}{T} | ||
direction::Symbol | ||
function FirstDerivative{T}(x, y, bc, direction) where {T} | ||
size(x) == size(y) || throw(DimensionMismatch( | ||
"cannot match grid of length $(length(x)) with vector of length $(length(y))")) | ||
direction ∈ (:upward, :downward) || throw(ArgumentError("direction must be :upward or :downward")) | ||
return new(x, y, bc, direction) | ||
end | ||
end | ||
|
||
function FirstDerivative(x::AbstractVector, y::AbstractVector; bc = (0, 0), direction = :upward) | ||
FirstDerivative{eltype(y)}(x, y, bc, direction) | ||
end | ||
|
||
|
||
Base.size(d::FirstDerivative) = (length(d.x), 1) | ||
|
||
Base.IndexStyle(d::FirstDerivative) = IndexLinear() | ||
|
||
function Base.getindex(d::FirstDerivative{T}, i::Int) where {T} | ||
(; x, y, bc, direction) = d | ||
if direction == :upward | ||
if i == length(x) | ||
return convert(T, bc[end]) | ||
else | ||
Δxp = x[min(i, length(x)-1)+1] - x[min(i, length(x)-1)] | ||
return (y[i+1] - y[i]) / Δxp | ||
end | ||
else | ||
if i == 1 | ||
return convert(T, bc[1]) | ||
else | ||
Δxm = x[max(i-1, 1) + 1] - x[max(i-1, 1)] | ||
return (y[i] - y[i-1]) / Δxm | ||
end | ||
end | ||
end | ||
|
||
|
||
struct SecondDerivative{T} <: AbstractVector{T} | ||
x::AbstractVector{<:Real} | ||
y::AbstractVector{T} | ||
bc::NTuple{2}{T} | ||
function SecondDerivative{T}(x, y, bc) where {T} | ||
length(x) == length(y) || throw(DimensionMismatch( | ||
"cannot match grid of length $(length(x)) with vector of length $(length(y))")) | ||
return new(x, y, bc) | ||
end | ||
end | ||
|
||
function SecondDerivative(x::AbstractVector, y::AbstractVector; bc = (0, 0)) | ||
SecondDerivative{eltype(y)}(x, y, bc) | ||
end | ||
|
||
|
||
Base.size(d::SecondDerivative) = (length(d.x), 1) | ||
|
||
Base.IndexStyle(d::SecondDerivative) = IndexLinear() | ||
|
||
function Base.getindex(d::SecondDerivative{T}, i::Int) where {T} | ||
(; x, y, bc) = d | ||
Δxp = x[min(i, length(x)-1)+1] - x[min(i, length(x)-1)] | ||
Δxm = x[max(i-1, 1) + 1] - x[max(i-1, 1)] | ||
Δx = (Δxm + Δxp) / 2 | ||
if i == 1 | ||
return y[2] / (Δxp * Δx) + (y[1] - bc[1] * Δxm) / (Δxm * Δx) - 2 * y[1] / (Δxp * Δxm) | ||
elseif i == length(x) | ||
return (y[end] + bc[end] * Δxp) / (Δxp * Δx) + y[end - 1] / (Δxm * Δx) - 2 * y[end] / (Δxp * Δxm) | ||
else | ||
return y[i + 1] / (Δxp * Δx) + y[i - 1] / (Δxm * Δx) - 2 * y[i] / (Δxp * Δxm) | ||
end | ||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
struct Derivative | ||
x::Vector{Float64} | ||
end | ||
|
||
function FirstDerivative(x, y::T, i; bc = (0, 0), direction = :up) | ||
if method == :up | ||
Δxp = x[min(i, n-1)+1] - x[min(i, n-1)] | ||
(i < length(x)) ? (y[i+1] - y[i]) / Δxp : convert(T, bc[end]) | ||
elseif method == :down | ||
Δxm = x[max(i-1, 1) + 1] - x[max(i-1, 1)] | ||
(i > 1) ? (y[i] - y[i-1]) / Δxm : convert(T, bc[1]) | ||
end | ||
end | ||
|
||
function SecondDerivative(x, y::T, i, bc = (0, 0)) | ||
Δxp = x[min(i, n-1)+1] - x[min(i, n-1)] | ||
Δxm = x[max(i-1, 1) + 1] - x[max(i-1, 1)] | ||
Δx = (Δxm + Δxp) / 2 | ||
(1 < i < length(x)) ? (y[i + 1] / (Δxp * Δx) + y[i - 1] / (Δxm * Δx) - 2 * y[i] / (Δxp * Δxm)) : ((i == 1) ? (y[2] / (Δxp * Δx) + (y[1] - bc[1] * Δxm) / (Δxm * Δx) - 2 * y[1] / (Δxp * Δxm)) : ((y[end] + bc[end] * Δxp) / (Δxp * Δx) + y[end - 1] / (Δxm * Δx) - 2 * y[end] / (Δxp * Δxm))) | ||
|
||
|
||
if method == :upwind | ||
Δxp = x[min(i, n-1)+1] - x[min(i, n-1)] | ||
Δfp = y[min(i, n-1)+1] - y[min(i, n-1)] | ||
if Δxp != 0 | ||
return Δfxp / Δxp | ||
else | ||
return 0.0 | ||
end | ||
else | ||
Δxm = x[max(i-1, 1) + 1] - x[max(i-1, 1)] | ||
Δfm = f[max(i-1, 1) + 1] - f[max(i-1, 1)] | ||
if Δxm != 0 | ||
return Δfxm / Δxm | ||
else | ||
return 0.0 | ||
end | ||
end | ||
end | ||
elseif method == :down | ||
return x[min(i, n-1)+1] - x[min(i, n-1)] | ||
struct ∂down | ||
grid::Vector{Float64} | ||
end | ||
|
||
struct ∂down | ||
grid::Vector{Float64} | ||
end | ||
upwinding(wgrid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using InfinitesimalGenerators, Test, Statistics, LinearAlgebra, Expokit | ||
|
||
|
||
xbar = 0.0 | ||
κ = 0.1 | ||
σ = 0.02 | ||
|
1001307
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
1001307
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/108812
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: