This repository was archived by the owner on Jul 19, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathcoefficient_functions.jl
More file actions
67 lines (63 loc) · 3.31 KB
/
coefficient_functions.jl
File metadata and controls
67 lines (63 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
```
compute_coeffs(coeff_func, current_coeffs)
```
Calculates the coefficients for the stencil of UpwindDifference operators.
"""
function compute_coeffs!(coeff_func::Number, current_coeffs::AbstractVector{T}) where {T<:Number}
return current_coeffs .+= coeff_func
end
function compute_coeffs!(coeff_func::AbstractVector{T}, current_coeffs::AbstractVector{T}) where {T<:Number}
return current_coeffs[:] += coeff_func
end
# Coefficient functions when coeff_func is a Function and current_coeffs exists
function compute_coeffs!(coeff_func::Function, current_coeffs::AbstractVector{T}) where {T<:Number}
if hasmethod(coeff_func, (Vector{T},))
current_coeffs[:] = coeff_func(current_coeffs)
else
map!(coeff_func, current_coeffs, current_coeffs)
end
return current_coeffs
# if hasmethod(coeff_func, (Int,)) # assume we want to provide the index of coefficients to coeff_func
# for i = 1:length(current_coeffs)
# current_coeffs[i] += coeff_func(i)
# end
# return current_coeffs
# elseif hasmethod(coeff_func, (Vector{Int},)) # assume we want to provide the index of coefficients to coeff_func
# current_coeffs[:] += coeff_func(collect(1:length(current_coeffs)))
# return current_coeffs
# elseif hasmethod(coeff_func, (UnitRange{Int},)) # assume we want to provide the index of coefficients to coeff_func
# current_coeffs[:] += coeff_func(1:length(current_coeffs))
# return current_coeffs
# elseif hasmethod(coeff_func, (Float64,)) # assume we want coeff_func to operate on existing coefficients
# map!(coeff_func, current_coeffs, current_coeffs)
# return current_coeffs
# elseif hasmethod(coeff_func, (Vector{Float64},)) # assume we want to coeff_func to operate on existing coefficients
# current_coeffs[:] = coeff_func(current_coeffs)
# return current_coeffs
# else
# error("Coefficient functions with the arguments of $coeff_func have not been implemented.")
# end
end
compute_coeffs(coeff_func::Number, current_coeffs::AbstractVector{T}) where {T<:Number} = current_coeffs .+ coeff_func
compute_coeffs(coeff_func::AbstractVector{T}, current_coeffs::AbstractVector{T}) where {T<:Number} = coeff_func + current_coeffs
function compute_coeffs(coeff_func::Function, current_coeffs::AbstractVector{T}) where {T<:Number}
if hasmethod(coeff_func, (Vector{T},))
return coeff_func(current_coeffs)
else
return map(coeff_func, current_coeffs)
end
# if hasmethod(coeff_func, (Int,))
# return current_coeffs + map(coeff_func, collect(1:length(current_coeffs)))
# elseif hasmethod(coeff_func, (Vector{Int},))
# return current_coeffs + coeff_func(collect(1:length(current_coeffs)))
# elseif hasmethod(coeff_func, (UnitRange{Int},))
# return current_coeffs + coeff_func(1:length(current_coeffs))
# elseif hasmethod(coeff_func, (Float64,)) # assume we want coeff_func to operate on existing coefficients
# return map(coeff_func, current_coeffs)
# elseif hasmethod(coeff_func, (Vector{Float64},)) # assume we want to coeff_func to operate on existing coefficients
# return coeff_func(current_coeffs)
# else
# error("Coefficient functions with the arguments of coeff_func $coeff_func have not been implemented.")
# end
end