@@ -9,7 +9,7 @@ A category of types used to specify the desired method for calculating derivativ
9
9
Derivatives are used to form Jacobian matrices when calculating the differential
10
10
element size throughout the integration region.
11
11
12
- See also [`FiniteDifference`](@ref).
12
+ See also [`FiniteDifference`](@ref), [`AutoEnzyme`](@ref) .
13
13
"""
14
14
abstract type DifferentiationMethod end
15
15
27
27
FiniteDifference {T} () where {T <: AbstractFloat } = FiniteDifference {T} (T (1e-6 ))
28
28
FiniteDifference () = FiniteDifference {Float64} ()
29
29
30
+ """
31
+ AutoEnzyme()
32
+
33
+ Use to specify use of the Enzyme.jl for calculating derivatives.
34
+ """
35
+ struct AutoEnzyme <: DifferentiationMethod end
36
+
30
37
# Future Support:
31
- # struct AutoEnzyme <: DifferentiationMethod end
32
38
# struct AutoZygote <: DifferentiationMethod end
33
39
34
40
# ###############################################################################
@@ -52,7 +58,7 @@ function jacobian(
52
58
geometry:: G ,
53
59
ts:: Union{AbstractVector{T}, Tuple{T, Vararg{T}}}
54
60
) where {G <: Geometry , T <: AbstractFloat }
55
- return jacobian (geometry, ts, _default_diff_method (G))
61
+ return jacobian (geometry, ts, _default_diff_method (G, T ))
56
62
end
57
63
58
64
function jacobian (
@@ -68,7 +74,7 @@ function jacobian(
68
74
# Get the partial derivative along the n'th axis via finite difference
69
75
# approximation, where ts is the current parametric position
70
76
function ∂ₙr (ts, n, ε)
71
- # Build left/right parametric coordinates with non-allocating iterators
77
+ # Build left/right parametric coordinates with non-allocating iterators
72
78
left = Iterators. map (((i, t),) -> i == n ? t - ε : t, enumerate (ts))
73
79
right = Iterators. map (((i, t),) -> i == n ? t + ε : t, enumerate (ts))
74
80
# Select orientation of finite-diff
@@ -107,7 +113,7 @@ possible and finite difference approximations otherwise.
107
113
function differential (
108
114
geometry:: G ,
109
115
ts:: Union{AbstractVector{T}, Tuple{T, Vararg{T}}} ,
110
- diff_method:: DifferentiationMethod = _default_diff_method (G)
116
+ diff_method:: DifferentiationMethod = _default_diff_method (G, T )
111
117
) where {G <: Geometry , T <: AbstractFloat }
112
118
J = Iterators. map (_KVector, jacobian (geometry, ts, diff_method))
113
119
return LinearAlgebra. norm (foldl (∧ , J))
0 commit comments