Skip to content

Conversation

@GiggleLiu
Copy link
Collaborator

Notes

  1. Avoid using abstract type as type fields
struct Lattice{T}
    vectors::AbstractMatrix{T}
    pbc::AbstractVector{Bool}
end

Should be changed to

struct Lattice{T}
    vectors::Matrix{T}
    pbc::Vector{Bool}
end

or

struct Lattice{T, MT<:AbstractMatrix{T}, VT<:AbstractVector{Bool}}
    vectors::MT
    pbc::VT
end

Otherwise, the type is unstable. For more, please check the performance tips: https://docs.julialang.org/en/v1/manual/performance-tips/

  1. Symbolic type and string type.
struct Ion{T}
    species::String
    charge::Int
    frac_pos::AbstractVector{T}
end

Here, I would chose to use Symbol type rather than the String type. Symbol is faster and is more static, while having less freedom.

  1. Use CartesianIndices

CartesianIndices can make you manipulate high dimensional arrays much easier. Please read this blog post:
https://julialang.org/blog/2016/02/iteration/

@Br0kenSmi1e Br0kenSmi1e merged commit 1cbe55b into main Feb 25, 2025
5 checks passed
@Br0kenSmi1e
Copy link
Owner

Appreciate your advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants