Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
correlation::core::NeighborGraph Class Reference

Compressed Sparse Row (CSR) based graph representing atomic connectivity. More...

#include <NeighborGraph.hpp>

Public Member Functions

 NeighborGraph ()=default
 Default constructor.
 NeighborGraph (size_t node_count)
 Constructs a graph with a fixed number of nodes.
 NeighborGraph (const NeighborGraph &other)
 Copy constructor.
 NeighborGraph (NeighborGraph &&other) noexcept
 Move constructor.
NeighborGraph & operator= (const NeighborGraph &other)
 Copy assignment operator.
NeighborGraph & operator= (NeighborGraph &&other) noexcept
 Move assignment operator.
 ~NeighborGraph ()=default
 Destructor.
void addDirectedEdge (const Edge &edge)
 Adds a directed edge between two atoms.
void addDirectedEdge (AtomID source, AtomID target, real_t distance, const math::Vector3< real_t > &r_ij)
 Adds a directed edge between two atoms using individual parameters.
void finalize () const
 Finalizes the graph into Compressed Sparse Row (CSR) storage.
void assignCSR (size_t node_count, std::vector< size_t > offsets, std::vector< Neighbor > neighbors, std::vector< AtomID > targets)
 Directly assigns Compressed Sparse Row (CSR) storage.
std::span< const Neighbor > getNeighbors (size_t atom_index) const
 Retrieves the neighbor list for a specific atom.
std::span< const AtomID > getNeighborIndices (size_t atom_index) const
 Retrieves a lightweight index-only view of neighbors for a specific atom.
bool areConnected (AtomIndex first_atom, AtomIndex second_atom) const
 Checks if two atoms are connected by an edge using binary search.
std::vector< bool > getDenseAdjacencyMatrix () const
 Generates a flattened dense adjacency matrix.
size_t nodeCount () const noexcept
size_t edgeCount () const noexcept
std::span< const size_t > offsets () const noexcept
std::span< const AtomID > targets () const noexcept
std::span< const Neighbor > neighbors () const noexcept

Private Member Functions

 NeighborGraph (const std::scoped_lock< std::mutex > &, const NeighborGraph &other)
 NeighborGraph (const std::scoped_lock< std::mutex > &, NeighborGraph &other) noexcept
void ensureFinalized () const

Private Attributes

size_t node_count_ {0}
std::atomic< bool > is_finalized_ {true}
std::mutex finalize_mutex_
std::vector< Edge > unfinalized_edges_
std::vector< size_t > offsets_ {0}
std::vector< Neighbor > neighbors_
std::vector< AtomID > targets_

Detailed Description

Compressed Sparse Row (CSR) based graph representing atomic connectivity.

Stores bonds and neighbor interactions as directed edges with deterministic row sorting by (target_index, distance). Eliminates per-row vector allocations and provides lightweight index-only views for high-throughput traversals.

Constructor & Destructor Documentation

◆ NeighborGraph() [1/6]

correlation::core::NeighborGraph::NeighborGraph ( )
explicitdefault

Default constructor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NeighborGraph() [2/6]

correlation::core::NeighborGraph::NeighborGraph ( size_t node_count)
explicit

Constructs a graph with a fixed number of nodes.

Parameters
node_countThe total number of atoms/nodes in the graph.

◆ NeighborGraph() [3/6]

correlation::core::NeighborGraph::NeighborGraph ( const NeighborGraph & other)

Copy constructor.

Parameters
otherThe graph instance to copy from.
Here is the call graph for this function:

◆ NeighborGraph() [4/6]

correlation::core::NeighborGraph::NeighborGraph ( NeighborGraph && other)
noexcept

Move constructor.

Parameters
otherThe graph instance to move from.
Here is the call graph for this function:

◆ ~NeighborGraph()

correlation::core::NeighborGraph::~NeighborGraph ( )
default

Destructor.

◆ NeighborGraph() [5/6]

correlation::core::NeighborGraph::NeighborGraph ( const std::scoped_lock< std::mutex > & ,
const NeighborGraph & other )
private
Here is the call graph for this function:

◆ NeighborGraph() [6/6]

correlation::core::NeighborGraph::NeighborGraph ( const std::scoped_lock< std::mutex > & ,
NeighborGraph & other )
privatenoexcept
Here is the call graph for this function:

Member Function Documentation

◆ addDirectedEdge() [1/2]

void correlation::core::NeighborGraph::addDirectedEdge ( AtomID source,
AtomID target,
real_t distance,
const math::Vector3< real_t > & r_ij )
inline

Adds a directed edge between two atoms using individual parameters.

Parameters
sourceIndex of the source atom.
targetIndex of the target atom.
distanceSeparation distance (Angstrom).
r_ijRelative position vector from source to target.
Here is the call graph for this function:

◆ addDirectedEdge() [2/2]

void correlation::core::NeighborGraph::addDirectedEdge ( const Edge & edge)

Adds a directed edge between two atoms.

Parameters
edgeThe directed edge details containing source, target, distance, and vector.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ areConnected()

bool correlation::core::NeighborGraph::areConnected ( AtomIndex first_atom,
AtomIndex second_atom ) const
nodiscard

Checks if two atoms are connected by an edge using binary search.

Parameters
first_atomFirst atom index.
second_atomSecond atom index.
Returns
True if second_atom is a neighbor of first_atom.
Here is the call graph for this function:

◆ assignCSR()

void correlation::core::NeighborGraph::assignCSR ( size_t node_count,
std::vector< size_t > offsets,
std::vector< Neighbor > neighbors,
std::vector< AtomID > targets )

Directly assigns Compressed Sparse Row (CSR) storage.

Parameters
node_countNumber of nodes.
offsetsRow offsets array of size node_count + 1.
neighborsFlat neighbors array of size offsets.back().
targetsFlat target indices array of size offsets.back().
Here is the call graph for this function:

◆ edgeCount()

size_t correlation::core::NeighborGraph::edgeCount ( ) const
nodiscardnoexcept
Returns
Total number of directed edges in the graph.
Here is the call graph for this function:

◆ ensureFinalized()

void correlation::core::NeighborGraph::ensureFinalized ( ) const
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ finalize()

void correlation::core::NeighborGraph::finalize ( ) const

Finalizes the graph into Compressed Sparse Row (CSR) storage.

Sorts all neighbor rows by (index, distance) deterministically. Automatically invoked before queries if edges have been modified.

Here is the caller graph for this function:

◆ getDenseAdjacencyMatrix()

std::vector< bool > correlation::core::NeighborGraph::getDenseAdjacencyMatrix ( ) const
nodiscard

Generates a flattened dense adjacency matrix.

Returns
A vector of booleans of size N*N.
Here is the call graph for this function:

◆ getNeighborIndices()

std::span< const AtomID > correlation::core::NeighborGraph::getNeighborIndices ( size_t atom_index) const
nodiscard

Retrieves a lightweight index-only view of neighbors for a specific atom.

Parameters
atom_indexIndex of the atom.
Returns
Contiguous span of AtomID indices.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNeighbors()

std::span< const Neighbor > correlation::core::NeighborGraph::getNeighbors ( size_t atom_index) const
nodiscard

Retrieves the neighbor list for a specific atom.

Parameters
atom_indexIndex of the atom.
Returns
Contiguous span of Neighbor objects.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighbors()

std::span< const Neighbor > correlation::core::NeighborGraph::neighbors ( ) const
nodiscardnoexcept
Returns
CSR flat neighbors span of size edgeCount().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nodeCount()

size_t correlation::core::NeighborGraph::nodeCount ( ) const
nodiscardnoexcept
Returns
Total number of nodes in the graph.
Here is the caller graph for this function:

◆ offsets()

std::span< const size_t > correlation::core::NeighborGraph::offsets ( ) const
nodiscardnoexcept
Returns
CSR row offsets span of size nodeCount() + 1.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

NeighborGraph & correlation::core::NeighborGraph::operator= ( const NeighborGraph & other)

Copy assignment operator.

Parameters
otherThe graph instance to copy from.
Returns
Reference to this graph.
Here is the call graph for this function:

◆ operator=() [2/2]

NeighborGraph & correlation::core::NeighborGraph::operator= ( NeighborGraph && other)
noexcept

Move assignment operator.

Parameters
otherThe graph instance to move from.
Returns
Reference to this graph.
Here is the call graph for this function:

◆ targets()

std::span< const AtomID > correlation::core::NeighborGraph::targets ( ) const
nodiscardnoexcept
Returns
CSR flat target indices span of size edgeCount().
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ finalize_mutex_

std::mutex correlation::core::NeighborGraph::finalize_mutex_
mutableprivate

◆ is_finalized_

std::atomic<bool> correlation::core::NeighborGraph::is_finalized_ {true}
mutableprivate

◆ neighbors_

std::vector<Neighbor> correlation::core::NeighborGraph::neighbors_
mutableprivate

◆ node_count_

size_t correlation::core::NeighborGraph::node_count_ {0}
private

◆ offsets_

std::vector<size_t> correlation::core::NeighborGraph::offsets_ {0}
mutableprivate

◆ targets_

std::vector<AtomID> correlation::core::NeighborGraph::targets_
mutableprivate

◆ unfinalized_edges_

std::vector<Edge> correlation::core::NeighborGraph::unfinalized_edges_
mutableprivate

The documentation for this class was generated from the following files: