mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-21 00:51:21 +00:00
Fixed SVector with Real
This commit is contained in:
parent
e395e14fa1
commit
658c33f5a2
2 changed files with 20 additions and 18 deletions
|
@ -5,11 +5,11 @@ export angle2, norm2d, sq_norm2d
|
||||||
using StaticArrays: SVector
|
using StaticArrays: SVector
|
||||||
|
|
||||||
"""
|
"""
|
||||||
angle2(a::SVector{2,Real}, b::SVector{2,Real})
|
angle2(a::SVector{2,R}, b::SVector{2,R}) where {R<:Real}
|
||||||
|
|
||||||
Returns the angle φ from vector a to b while φ ∈ [-π, π].
|
Returns the angle φ from vector a to b while φ ∈ [-π, π].
|
||||||
"""
|
"""
|
||||||
function angle2(a::SVector{2,Real}, b::SVector{2,Real})
|
function angle2(a::SVector{2,R}, b::SVector{2,R}) where {R<:Real}
|
||||||
θ_a = atan(a[2], a[1])
|
θ_a = atan(a[2], a[1])
|
||||||
θ_b = atan(b[2], b[1])
|
θ_b = atan(b[2], b[1])
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@ function angle2(a::SVector{2,Real}, b::SVector{2,Real})
|
||||||
return rem2pi(θ, RoundNearest)
|
return rem2pi(θ, RoundNearest)
|
||||||
end
|
end
|
||||||
|
|
||||||
function sq_norm2d(v::SVector{2,Real})
|
function sq_norm2d(v::SVector{2,R}) where {R<:Real}
|
||||||
return v[1]^2 + v[2]^2
|
return v[1]^2 + v[2]^2
|
||||||
end
|
end
|
||||||
|
|
||||||
function norm2d(v::SVector{2,Real})
|
function norm2d(v::SVector{2,R}) where {R<:Real}
|
||||||
return sqrt(sq_norm2d(v))
|
return sqrt(sq_norm2d(v))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
30
src/Shape.jl
30
src/Shape.jl
|
@ -22,8 +22,8 @@ function project_back_from_unit_circle(θ::Real, half_box_len::Real)
|
||||||
end
|
end
|
||||||
|
|
||||||
function center_of_mass_from_proj_sums(
|
function center_of_mass_from_proj_sums(
|
||||||
x_proj_sum::SVector{2,Real}, y_proj_sum::SVector{2,Real}, half_box_len::Real
|
x_proj_sum::SVector{2,R}, y_proj_sum::SVector{2,R}, half_box_len::R
|
||||||
)
|
) where {R<:Real}
|
||||||
# Prevent for example atan(1e-16, 1e-15) != 0 with rounding
|
# Prevent for example atan(1e-16, 1e-15) != 0 with rounding
|
||||||
digits = 5
|
digits = 5
|
||||||
|
|
||||||
|
@ -47,7 +47,9 @@ function center_of_mass_from_proj_sums(
|
||||||
return SVector(COM_x, COM_y)
|
return SVector(COM_x, COM_y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function center_of_mass(centers::AbstractVector{SVector{2,Real}}, half_box_len::Real)
|
function center_of_mass(
|
||||||
|
centers::AbstractVector{SVector{2,R}}, half_box_len::R
|
||||||
|
) where {R<:Real}
|
||||||
x_proj_sum = SVector(0.0, 0.0)
|
x_proj_sum = SVector(0.0, 0.0)
|
||||||
y_proj_sum = SVector(0.0, 0.0)
|
y_proj_sum = SVector(0.0, 0.0)
|
||||||
|
|
||||||
|
@ -72,8 +74,8 @@ function center_of_mass(particles::AbstractVector{Particle}, half_box_len::Real)
|
||||||
end
|
end
|
||||||
|
|
||||||
function gyration_tensor(
|
function gyration_tensor(
|
||||||
particles::AbstractVector{Particle}, half_box_len::Real, COM::SVector{2,Real}
|
particles::AbstractVector{Particle}, half_box_len::R, COM::SVector{2,R}
|
||||||
)
|
) where {R<:Real}
|
||||||
S11 = 0.0
|
S11 = 0.0
|
||||||
S12 = 0.0
|
S12 = 0.0
|
||||||
S22 = 0.0
|
S22 = 0.0
|
||||||
|
@ -104,8 +106,8 @@ function gyration_tensor_eigvals_ratio(
|
||||||
end
|
end
|
||||||
|
|
||||||
function gyration_tensor_eigvecs(
|
function gyration_tensor_eigvecs(
|
||||||
particles::AbstractVector{Particle}, half_box_len::Real, COM::SVector{2,Real}
|
particles::AbstractVector{Particle}, half_box_len::R, COM::SVector{2,R}
|
||||||
)
|
) where {R<:Real}
|
||||||
g_tensor = gyration_tensor(particles, half_box_len, COM)
|
g_tensor = gyration_tensor(particles, half_box_len, COM)
|
||||||
eig_vecs = eigvecs(g_tensor)
|
eig_vecs = eigvecs(g_tensor)
|
||||||
|
|
||||||
|
@ -116,13 +118,13 @@ function gyration_tensor_eigvecs(
|
||||||
end
|
end
|
||||||
|
|
||||||
function elliptical_distance(
|
function elliptical_distance(
|
||||||
v::SVector{2,Real},
|
v::SVector{2,R},
|
||||||
COM::SVector{2,Real},
|
COM::SVector{2,R},
|
||||||
gyration_tensor_eigvec_to_smaller_eigval::SVector{2,Real},
|
gyration_tensor_eigvec_to_smaller_eigval::SVector{2,R},
|
||||||
gyration_tensor_eigvec_to_bigger_eigval::SVector{2,Real},
|
gyration_tensor_eigvec_to_bigger_eigval::SVector{2,R},
|
||||||
goal_gyration_tensor_eigvals_ratio::Real,
|
goal_gyration_tensor_eigvals_ratio::R,
|
||||||
half_box_len::Real,
|
half_box_len::R,
|
||||||
)
|
) where {R<:Real}
|
||||||
v′ = ReCo.minimum_image(v - COM, half_box_len)
|
v′ = ReCo.minimum_image(v - COM, half_box_len)
|
||||||
|
|
||||||
x = dot(v′, gyration_tensor_eigvec_to_bigger_eigval)
|
x = dot(v′, gyration_tensor_eigvec_to_bigger_eigval)
|
||||||
|
|
Loading…
Reference in a new issue