mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-30 17:13:27 +00:00
Added eigvals_ratio for centers
This commit is contained in:
parent
fd83c13333
commit
946e646594
1 changed files with 56 additions and 23 deletions
79
src/Shape.jl
79
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,R}, y_proj_sum::SVector{2,R}, half_box_len::R
|
x_proj_sum::SVector{2,<:Real}, y_proj_sum::SVector{2,<:Real}, half_box_len::Real
|
||||||
) 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,9 +47,7 @@ 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(
|
function center_of_mass(centers::AbstractVector{SVector{2,<:Real}}, half_box_len::Real)
|
||||||
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)
|
||||||
|
|
||||||
|
@ -74,8 +72,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::R, COM::SVector{2,R}
|
particles::AbstractVector{Particle}, half_box_len::Real, COM::SVector{2,<:Real}
|
||||||
) where {R<:Real}
|
)
|
||||||
S11 = 0.0
|
S11 = 0.0
|
||||||
S12 = 0.0
|
S12 = 0.0
|
||||||
S22 = 0.0
|
S22 = 0.0
|
||||||
|
@ -91,23 +89,58 @@ function gyration_tensor(
|
||||||
return LA.Hermitian(SMatrix{2,2}(S11, S12, S12, S22))
|
return LA.Hermitian(SMatrix{2,2}(S11, S12, S12, S22))
|
||||||
end
|
end
|
||||||
|
|
||||||
function gyration_tensor(particles::AbstractVector{Particle}, half_box_len::Real)
|
function gyration_tensor(
|
||||||
COM = center_of_mass(particles, half_box_len)
|
centers::AbstractVector{SVector{2,<:Real}}, half_box_len::Real, COM::SVector{2,<:Real}
|
||||||
|
)
|
||||||
|
S11 = 0.0
|
||||||
|
S12 = 0.0
|
||||||
|
S22 = 0.0
|
||||||
|
|
||||||
|
for c in centers
|
||||||
|
shifted_c = ReCo.restrict_coordinates(c - COM, half_box_len)
|
||||||
|
|
||||||
|
S11 += shifted_c[1]^2
|
||||||
|
S12 += shifted_c[1] * shifted_c[2]
|
||||||
|
S22 += shifted_c[2]^2
|
||||||
|
end
|
||||||
|
|
||||||
|
return LA.Hermitian(SMatrix{2,2}(S11, S12, S12, S22))
|
||||||
|
end
|
||||||
|
|
||||||
|
function gyration_tensor(
|
||||||
|
particles_or_centers::Union{AbstractVector{Particle},AbstractVector{SVector{2,<:Real}}},
|
||||||
|
half_box_len::Real,
|
||||||
|
)
|
||||||
|
COM = center_of_mass(particles_or_centers, half_box_len)
|
||||||
|
|
||||||
return gyration_tensor(particles, half_box_len, COM)
|
return gyration_tensor(particles, half_box_len, COM)
|
||||||
end
|
end
|
||||||
|
|
||||||
function gyration_tensor_eigvals_ratio(
|
function eigvals_ratio(matrix)
|
||||||
particles::AbstractVector{Particle}, half_box_len::Real
|
ev = LA.eigvals(matrix) # Eigenvalues are sorted
|
||||||
)
|
|
||||||
g_tensor = gyration_tensor(particles, half_box_len)
|
|
||||||
ev = LA.eigvals(g_tensor) # Eigenvalues are sorted
|
|
||||||
return abs(ev[1] / ev[2])
|
return abs(ev[1] / ev[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function gyration_tensor_eigvals_ratio(
|
||||||
|
particles_or_centers::Union{AbstractVector{Particle},AbstractVector{SVector{2,<:Real}}},
|
||||||
|
half_box_len::Real,
|
||||||
|
)
|
||||||
|
g_tensor = gyration_tensor(particles_or_centers, half_box_len)
|
||||||
|
return eigvals_ratio(g_tensor)
|
||||||
|
end
|
||||||
|
|
||||||
|
function gyration_tensor_eigvals_ratio(
|
||||||
|
particles_or_centers::Union{AbstractVector{Particle},AbstractVector{SVector{2,<:Real}}},
|
||||||
|
half_box_len::Real,
|
||||||
|
COM::SVector{2,<:Real},
|
||||||
|
)
|
||||||
|
g_tensor = gyration_tensor(particles_or_centers, half_box_len, COM)
|
||||||
|
return eigvals_ratio(g_tensor)
|
||||||
|
end
|
||||||
|
|
||||||
function gyration_tensor_eigvecs(
|
function gyration_tensor_eigvecs(
|
||||||
particles::AbstractVector{Particle}, half_box_len::R, COM::SVector{2,R}
|
particles::AbstractVector{Particle}, half_box_len::Real, COM::SVector{2,<:Real}
|
||||||
) where {R<:Real}
|
)
|
||||||
g_tensor = gyration_tensor(particles, half_box_len, COM)
|
g_tensor = gyration_tensor(particles, half_box_len, COM)
|
||||||
eig_vecs = LA.eigvecs(g_tensor)
|
eig_vecs = LA.eigvecs(g_tensor)
|
||||||
|
|
||||||
|
@ -118,13 +151,13 @@ function gyration_tensor_eigvecs(
|
||||||
end
|
end
|
||||||
|
|
||||||
function elliptical_distance(
|
function elliptical_distance(
|
||||||
v::SVector{2,R},
|
v::SVector{2,<:Real},
|
||||||
COM::SVector{2,R},
|
COM::SVector{2,<:Real},
|
||||||
gyration_tensor_eigvec_to_smaller_eigval::SVector{2,R},
|
gyration_tensor_eigvec_to_smaller_eigval::SVector{2,<:Real},
|
||||||
gyration_tensor_eigvec_to_bigger_eigval::SVector{2,R},
|
gyration_tensor_eigvec_to_bigger_eigval::SVector{2,<:Real},
|
||||||
elliptical_a_b_ratio::R,
|
elliptical_a_b_ratio::Real,
|
||||||
half_box_len::R,
|
half_box_len::Real,
|
||||||
) where {R<:Real}
|
)
|
||||||
v′ = ReCo.restrict_coordinates(v - COM, half_box_len)
|
v′ = ReCo.restrict_coordinates(v - COM, half_box_len)
|
||||||
|
|
||||||
x = LA.dot(v′, gyration_tensor_eigvec_to_bigger_eigval)
|
x = LA.dot(v′, gyration_tensor_eigvec_to_bigger_eigval)
|
||||||
|
|
Loading…
Reference in a new issue