Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test if Ball-AABB tests can improve performance #1686

Open
joaander opened this issue Dec 19, 2023 · 0 comments
Open

Test if Ball-AABB tests can improve performance #1686

joaander opened this issue Dec 19, 2023 · 0 comments
Labels
task Something needs to be done.

Comments

@joaander
Copy link
Member

joaander commented Dec 19, 2023

Description

Test if this class:

/** Ball data structure for use with AABB.

    When querying the AABB tree for all points in a sphere, use a Ball-AABB check.
**/
struct
#ifndef __HIPCC__
    __attribute__((visibility("default")))
#endif
Ball
    {
    vec3<LongReal> m_center;
    LongReal m_radius;

    DEVICE Ball() :
        m_center(0,0,0),
        m_radius(0)
        {
        }

    DEVICE Ball(const vec3<LongReal>& center, LongReal radius) :
        m_center(center),
        m_radius(radius)
        {
        }

    DEVICE void translate(const vec3<Scalar>& v)
        {
        m_center += v;
        }

/** Check if a Ball and AABB overlap

    @param other AABB
    @returns true when the two shapes overlap, false otherwise
*/
DEVICE inline bool overlaps(const AABB& other) const
    {
    // https://stackoverflow.com/questions/28343716/sphere-intersection-test-of-aabb
    LongReal d_squared_min = 0;

    vec3<LongReal> box_min = other.getLower();
    vec3<LongReal> box_max = other.getUpper();

    if( m_center.x < box_min.x )
        {
        d_squared_min += ( m_center.x - box_min.x ) * ( m_center.x - box_min.x );
        }
    else if( m_center.x > box_max.x)
        {
        d_squared_min += ( m_center.x - box_max.x) * ( m_center.x - box_max.x);
        }

    if( m_center.y < box_min.y )
        {
        d_squared_min += ( m_center.y - box_min.y ) * ( m_center.y - box_min.y );
        }
    else if( m_center.y > box_max.y)
        {
        d_squared_min += ( m_center.y - box_max.y) * ( m_center.y - box_max.y);
        }

    if( m_center.z < box_min.z )
        {
        d_squared_min += ( m_center.z - box_min.z ) * ( m_center.z - box_min.z );
        }
    else if( m_center.z > box_max.z)
        {
        d_squared_min += ( m_center.z - box_max.z) * ( m_center.z - box_max.z);
        }

    return d_squared_min <= m_radius * m_radius;
    }
    };

used as the search query in HPMC leads to faster performance.

In my tests so far, it is ~5% faster for a LJ r_cut=2.5 system, but slower for a moderate density hard polyhedra simulation.

Motivation and context

I need to check if higher density hard particle systems can benefit. The ball-AABB check results in hitting ~50% of the AABB nodes (volume of sphere / volume of cube). But, the ball-AABB check is more expensive than AABB-AABB so there are tradeoffs.

@joaander joaander added the task Something needs to be done. label Dec 19, 2023
joaander added a commit that referenced this issue Dec 19, 2023
I was testing whether Ball-AABB would be faster. Will investigate further in a later
PR: #1686
joaander added a commit that referenced this issue Dec 19, 2023
I was testing whether Ball-AABB would be faster. Will investigate further in a later
PR: #1686
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Something needs to be done.
Projects
None yet
Development

No branches or pull requests

1 participant