Advanced Multi-Physics (AMP)
On-Line Documentation
RandomAccessIndexer.h
Go to the documentation of this file.
1#ifndef included_AMP_RandomAccessIndexer
2#define included_AMP_RandomAccessIndexer
3
4#include <map>
5
6#include "AMP/vectors/VectorIndexer.h"
7
8
9namespace AMP::LinearAlgebra {
10
12{
13private:
14 // Temporary fix for const correctness.
15 mutable std::map<size_t, size_t> d_SuperToSub;
16 mutable std::map<size_t, size_t> d_SubToSuper;
17
18public:
20 void addID( size_t i ) { d_SuperToSub[i] = 0; }
21 void finalize()
22 {
23 std::map<size_t, size_t>::iterator c = d_SuperToSub.begin();
24 size_t lid = 0;
25 while ( c != d_SuperToSub.end() ) {
26 c->second = lid;
27 d_SubToSuper[lid] = c->first;
28 lid++;
29 c++;
30 }
31 }
32
33 virtual bool isInSub( size_t i ) const { return d_SuperToSub.find( i ) != d_SuperToSub.end(); }
34 virtual size_t getIncrement( size_t i ) const
35 {
36 std::map<size_t, size_t>::iterator c = d_SuperToSub.find( i );
37 AMP_ASSERT( c != d_SuperToSub.end() );
38 c++;
39 if ( c != d_SuperToSub.end() )
40 return ( c->first - i );
41 return 2000000000; // For a SubsetVector, the iterator returns end when the
42 // internal iterator iterates past the end;
43 }
44
45 virtual size_t getSubID( size_t i ) const { return d_SuperToSub[i]; }
46 virtual size_t getSuperID( size_t i ) const { return d_SubToSuper[i]; }
47 virtual size_t getNumLocalElements( Vector::shared_ptr v ) const
48 {
49 size_t start = v->getCommunicationList()->getStartGID();
50 size_t end = v->getCommunicationList()->numLocalRows() + start;
51 size_t i = 0;
52 std::map<size_t, size_t>::iterator c = d_SuperToSub.begin();
53 while ( c != d_SuperToSub.end() ) {
54 if ( c->first >= start )
55 break;
56 i++;
57 c++;
58 }
59 std::map<size_t, size_t>::reverse_iterator d = d_SuperToSub.rbegin();
60 while ( d != d_SuperToSub.rend() ) {
61 if ( d->first < end )
62 break;
63 i++;
64 d++;
65 }
66 return d_SuperToSub.size() - i;
67 }
68};
69} // namespace AMP::LinearAlgebra
70
71#endif
virtual size_t getSuperID(size_t i) const
Given a global id in the SubsetVector, return the corresponding global id in the underlying vector.
virtual size_t getNumLocalElements(Vector::shared_ptr v) const
virtual size_t getSubID(size_t i) const
Given a global id in the underlying vector, return the subset global id.
virtual bool isInSub(size_t i) const
Given a global id in the underlying vector, this returns true if the global id is in the SubsetVector...
virtual size_t getIncrement(size_t i) const
Given a global id in the underlying vector, return the distance to the next id in the SubsetVector.
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
Definition Vector.h:60
#define AMP_ASSERT(EXP)
Assert error.



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page