-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEvolutionFunctions.jl
More file actions
57 lines (47 loc) · 1.37 KB
/
Copy pathEvolutionFunctions.jl
File metadata and controls
57 lines (47 loc) · 1.37 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
"The evolution functions have been designed to apply variable boundary conditions."
module EvolutionFunctions
export ramp
export triangular
export step
export sigmoid
export constant
"Return an unbounded ramp function. By default, it is the identity. Otherwise, the scaling factor is 1/T."
function ramp(T::Float64=1.0)
t::Float64 -> t/T
end
"Return a triangular evolution function ranging from 0 to 1, centered at T, having edges at 0 and 2T."
function triangular(T::Float64)
triangular(0.0, T)
end
"Return a triangular evolution function ranging from 0 to 1, centered at Tmax, having edges at T0 and 2Tmax-T0."
function triangular(T0::Float64, Tmax::Float64)
t::Float64 -> begin
Δ = Tmax - T0
u = (t - T0) / Δ
v = (t - Tmax) / Δ
max(min(u, 1.0-v), .0)
end
end
"Return the Heaviside function."
function step(T::Float64)
t::Float64 -> t > T ? 1.0 : 0.0
end
"Return a sigmoid-like function with edges at 0 and 2ϵ."
function smoothstep(ϵ::Float64)
smoothstep(ϵ, ϵ)
end
"Return a sigmoid-like function centered at T and edges at ±ϵ."
function smoothstep(T::Float64, ϵ::Float64)
t::Float64 -> begin
u::Float64 = (t - T + ϵ) / (2 * ϵ)
if u < 0.0 return 0.0
elseif u < 1.0 return 3*u^2 - 2*u^3
else return 1.0
end
end
end
"Return a constant function which is always evaluated to 1."
function constant()
t::Float64 -> 1.0
end
end