Advanced Multi-Physics (AMP)
On-Line Documentation
VectorData.h
Go to the documentation of this file.
1#ifndef included_AMP_VectorData
2#define included_AMP_VectorData
3
4#include "AMP/utils/AMP_MPI.h"
5#include "AMP/utils/enable_shared_from_this.h"
6#include "AMP/utils/typeid.h"
7#include "AMP/vectors/Scalar.h"
8#include "AMP/vectors/Variable.h"
9#include "AMP/vectors/data/DataChangeFirer.h"
10
11#include <memory>
12
13
14namespace AMP::IO {
15class RestartManager;
16}
17
18
19namespace AMP::LinearAlgebra {
20
21
22// Forward declares
23class CommunicationList;
24template<typename TYPE>
25class VectorDataIterator;
26
27
38{
39public: // Get basic information
41 virtual ~VectorData() {}
42
43
45 virtual std::string VectorDataName() const = 0;
46
47
53 virtual size_t numberOfDataBlocks() const = 0;
54
59 virtual size_t sizeOfDataBlock( size_t i = 0 ) const = 0;
60
66 inline size_t getLocalSize() const { return d_localSize; }
71 inline size_t getGlobalSize() const { return d_globalSize; }
72
76 inline size_t getLocalStartID() const { return d_localStart; }
77
81 virtual std::vector<size_t> getLocalSizes() const;
82
87 virtual size_t getGhostSize() const = 0;
88
92 virtual bool hasGhosts() const = 0;
93
95 virtual void fillGhosts( const Scalar &x ) = 0;
96
98 virtual size_t getNumberOfComponents() const;
99
104 virtual std::shared_ptr<VectorData> getComponent( size_t i = 0 );
105
110 virtual std::shared_ptr<const VectorData> getComponent( size_t i = 0 ) const;
111
113 virtual bool hasContiguousData() const { return true; }
114
115public: // Get/Set data
119 template<class TYPE>
120 void putRawData( const TYPE *buf );
121
126 template<class TYPE>
127 void getRawData( TYPE *buf ) const;
128
138 template<class TYPE>
139 void setValuesByLocalID( size_t num, const size_t *indices, const TYPE *vals );
140
149 template<class TYPE>
150 void setGhostValuesByGlobalID( size_t num, const size_t *indices, const TYPE *vals );
151
161 template<class TYPE>
162 void setValuesByGlobalID( size_t num, const size_t *indices, const TYPE *vals );
163
174 template<class TYPE>
175 void addValuesByLocalID( size_t num, const size_t *indices, const TYPE *vals );
176
186 template<class TYPE>
187 void addValuesByGlobalID( size_t num, const size_t *indices, const TYPE *vals );
188
195 template<class TYPE>
196 void addGhostValuesByGlobalID( size_t num, const size_t *indices, const TYPE *vals );
197
198
207 template<class TYPE>
208 void getGhostAddValuesByGlobalID( size_t num, const size_t *indices, TYPE *vals ) const;
209
210
218 template<class TYPE>
219 void getValuesByLocalID( size_t num, const size_t *indices, TYPE *vals ) const;
220
229 template<class TYPE>
230 void getValuesByGlobalID( size_t num, const size_t *indices, TYPE *vals ) const;
231
239 template<class TYPE>
240 void getGhostValuesByGlobalID( size_t num, const size_t *indices, TYPE *vals ) const;
241
247 template<class TYPE>
248 size_t getAllGhostValues( TYPE *vals ) const;
249
250
251public: // Advanced (virtual) get/set values
256 virtual void putRawData( const void *buf, const typeID &id ) = 0;
257
263 virtual void getRawData( void *buf, const typeID &id ) const = 0;
264
275 virtual void
276 setValuesByLocalID( size_t num, const size_t *indices, const void *vals, const typeID &id ) = 0;
277
287 virtual void setGhostValuesByGlobalID( size_t num,
288 const size_t *indices,
289 const void *vals,
290 const typeID &id ) = 0;
291
303 virtual void
304 addValuesByLocalID( size_t num, const size_t *indices, const void *vals, const typeID &id ) = 0;
305
313 virtual void addGhostValuesByGlobalID( size_t num,
314 const size_t *indices,
315 const void *vals,
316 const typeID &id ) = 0;
317
327 virtual void getGhostAddValuesByGlobalID( size_t num,
328 const size_t *indices,
329 void *vals,
330 const typeID &id ) const = 0;
331
332
341 virtual void
342 getValuesByLocalID( size_t num, const size_t *indices, void *vals, const typeID &id ) const = 0;
343
352 virtual void getGhostValuesByGlobalID( size_t num,
353 const size_t *indices,
354 void *vals,
355 const typeID &id ) const = 0;
363 virtual size_t getAllGhostValues( void *vals, const typeID &id ) const = 0;
364
365
366public: // Advanced functions
374 virtual uint64_t getDataID() const = 0;
375
379 virtual void *getRawDataBlockAsVoid( size_t i ) = 0;
380
385 virtual const void *getRawDataBlockAsVoid( size_t i ) const = 0;
386
390 virtual size_t sizeofDataBlockType( size_t i ) const = 0;
391
395 virtual typeID getType( size_t block ) const = 0;
396
401 inline bool isType( const typeID &id, size_t block ) const;
402
406 virtual void swapData( VectorData &rhs ) = 0;
407
410 virtual std::shared_ptr<VectorData> cloneData( const std::string &name = "" ) const = 0;
411
419 virtual bool isAnAliasOf( const VectorData &rhs ) const;
420
426 virtual void reset();
427
428public:
434 virtual void
435 dumpOwnedData( std::ostream &out, size_t GIDoffset = 0, size_t LIDoffset = 0 ) const;
436
441 virtual void dumpGhostedData( std::ostream &out, size_t offset = 0 ) const = 0;
442
443public: // Virtual functions dealing with the update status
459
460
476
477
483 virtual void setUpdateStatus( UpdateState state ) = 0;
484
500 virtual void makeConsistent( ScatterType t ) = 0;
501
507 virtual void makeConsistent();
508
510 virtual const AMP_MPI &getComm() const = 0;
511
513 virtual std::shared_ptr<CommunicationList> getCommunicationList() const = 0;
514
519 virtual void setCommunicationList( std::shared_ptr<CommunicationList> comm ) = 0;
520
524 virtual void setNoGhosts();
525
532
533 virtual void
534 print( std::ostream &os, const std::string &name = "A", const std::string &prefix = "" ) const;
535
536public: // Non-virtual functions
547 template<class TYPE = double>
549
551 template<class TYPE = double>
553
555 template<class TYPE = double>
557
568 template<class TYPE = double>
570
572 template<class TYPE = double>
574
576 template<class TYPE = double>
578
584 template<typename RETURN_TYPE>
585 RETURN_TYPE *getRawDataBlock( size_t i = 0 );
586
592 template<typename RETURN_TYPE>
593 const RETURN_TYPE *getRawDataBlock( size_t i = 0 ) const;
594
598 template<typename TYPE>
599 bool isType() const;
600
604 template<typename TYPE>
605 bool isBlockType( size_t i = 0 ) const;
606
613 virtual void copyGhostValues( const VectorData &rhs ) = 0;
614
615
616public:
619 virtual void dataChanged() = 0;
620
621 /* \brief Returns true if this vector has this element
622 * \param[in] GID The global ID of the element
623 */
624 virtual bool containsGlobalElement( size_t GID ) const = 0;
625
631 virtual void assemble() {}
632
633
634public: // update status
640 virtual std::shared_ptr<UpdateState> getUpdateStatusPtr() const = 0;
641
648 virtual void setUpdateStatusPtr( std::shared_ptr<UpdateState> rhs ) = 0;
649
650
651public: // Non virtual functions
653 uint64_t getID() const;
654
655
656public: // Write/read restart data
662 virtual void registerChildObjects( AMP::IO::RestartManager *manager ) const;
663
669 virtual void writeRestart( int64_t fid ) const;
670
671 VectorData( int64_t fid, AMP::IO::RestartManager *manager );
672
673protected: // Internal data
674 size_t d_localSize = 0;
675 size_t d_globalSize = 0;
676 size_t d_localStart = 0;
677
678 // Friends
679 friend class VectorOperations;
680
681
682public:
684 VectorData() = default;
685 VectorData( const VectorData & ) = delete;
686};
687
688
689} // namespace AMP::LinearAlgebra
690
691
692#include "AMP/vectors/data/VectorData.inline.h"
693
694
695#endif
Provides C++ wrapper around MPI routines.
Definition AMP_MPI.h:63
Class to manage reading/writing restart data.
Interface for managing classes that need to know when managed data has changed.
Iterator for local data in a vector.
A class used to hold vector data.
Definition VectorData.h:38
virtual void makeConsistent(ScatterType t)=0
Update shared values on entire communicator.
virtual void dataChanged()=0
Notify listeners that data has changed in this vector.
virtual void addValuesByLocalID(size_t num, const size_t *indices, const void *vals, const typeID &id)=0
Add values to vector entities by their local offset.
virtual std::shared_ptr< CommunicationList > getCommunicationList() const =0
Get the CommunicationList for this Vector.
virtual void getGhostAddValuesByGlobalID(size_t num, const size_t *indices, void *vals, const typeID &id) const =0
get ghosted values to add to off-proc elements
void getGhostAddValuesByGlobalID(size_t num, const size_t *indices, TYPE *vals) const
get ghosted values to add to off-proc elements
virtual const void * getRawDataBlockAsVoid(size_t i) const =0
Return a pointer to a particular block of memory in the vector.
virtual void setUpdateStatus(UpdateState state)=0
Sets the current update state of the Vector.
virtual size_t getGhostSize() const =0
Number of entries "owned" by other cores stored on this core.
virtual bool containsGlobalElement(size_t GID) const =0
virtual void setValuesByLocalID(size_t num, const size_t *indices, const void *vals, const typeID &id)=0
Set values in the vector by their local offset.
virtual void swapData(VectorData &rhs)=0
Swap the data with another VectorData object.
virtual void dumpGhostedData(std::ostream &out, size_t offset=0) const =0
Write data owned by other processors to an std::ostream.
void getRawData(TYPE *buf) const
Copy data out of this vector.
virtual typeID getType(size_t block) const =0
Return the typeid of the given block.
virtual void copyGhostValues(const VectorData &rhs)=0
Copy ghosted vlues to a vector.
virtual UpdateState getLocalUpdateStatus() const =0
Return the current update state of the Vector.
virtual void setUpdateStatusPtr(std::shared_ptr< UpdateState > rhs)=0
Tie the current update state to another.
virtual uint64_t getDataID() const =0
A unique id for the underlying data allocation.
RETURN_TYPE * getRawDataBlock(size_t i=0)
Obtain a particular contiguous block of data cast to RETURN_TYPE.
virtual std::vector< size_t > getLocalSizes() const
The local sizes on each rank.
virtual bool hasGhosts() const =0
Check if any entries "owned" by other cores are stored on this core.
virtual void fillGhosts(const Scalar &x)=0
Zero all ghost data (does not modify consistent status)
VectorData(const VectorData &)=delete
uint64_t getID() const
Get a unique id hash for the vector.
virtual bool isAnAliasOf(const VectorData &rhs) const
Check if the two VectorData objects are alias of each other.
bool isBlockType(size_t i=0) const
Check if the data is of the given type.
size_t getAllGhostValues(TYPE *vals) const
Get all ghost values.
virtual bool hasContiguousData() const
returns whether all data for the vector on a single process is contiguous
Definition VectorData.h:113
virtual void print(std::ostream &os, const std::string &name="A", const std::string &prefix="") const
VectorDataIterator< TYPE > end()
Return an iterator to the end of the data.
virtual std::shared_ptr< const VectorData > getComponent(size_t i=0) const
Number of elements in the ith component.
virtual void setGhostValuesByGlobalID(size_t num, const size_t *indices, const void *vals, const typeID &id)=0
Set ghost values using global identifier.
virtual size_t getAllGhostValues(void *vals, const typeID &id) const =0
Get all ghost values in the vector.
size_t getLocalSize() const
Number of elements "owned" by this core.
Definition VectorData.h:66
virtual void dumpOwnedData(std::ostream &out, size_t GIDoffset=0, size_t LIDoffset=0) const
Write owned data to an std::ostream.
VectorData(int64_t fid, AMP::IO::RestartManager *manager)
virtual size_t sizeofDataBlockType(size_t i) const =0
Return the result of sizeof(TYPE) for the given data block.
VectorDataIterator< const TYPE > begin() const
Return an iterator to the beginning of the data.
virtual std::shared_ptr< VectorData > cloneData(const std::string &name="") const =0
Clone the data.
void getValuesByGlobalID(size_t num, const size_t *indices, TYPE *vals) const
get values in the vector by their local offset
virtual void setCommunicationList(std::shared_ptr< CommunicationList > comm)=0
Set the CommunicationList for this Vector.
virtual void registerChildObjects(AMP::IO::RestartManager *manager) const
Register any child objects.
VectorData()=default
Default constructors.
virtual void getRawData(void *buf, const typeID &id) const =0
Copy data out of this vector.
virtual void setNoGhosts()
Ensure this vector has no ghosts.
void getValuesByLocalID(size_t num, const size_t *indices, TYPE *vals) const
Get local values in the vector by their global offset.
virtual const AMP_MPI & getComm() const =0
Get the communicator.
virtual void * getRawDataBlockAsVoid(size_t i)=0
Return a pointer to a particular block of memory in the vector.
void setValuesByGlobalID(size_t num, const size_t *indices, const TYPE *vals)
Set owned or shared values using global identifier.
virtual void writeRestart(int64_t fid) const
Write restart data to file.
bool isType() const
Check if the data is of the given type.
void putRawData(const TYPE *buf)
Copy data into this vector.
virtual std::string VectorDataName() const =0
Get the type name.
virtual void getValuesByLocalID(size_t num, const size_t *indices, void *vals, const typeID &id) const =0
Get local values in the vector by their global offset.
virtual std::shared_ptr< VectorData > getComponent(size_t i=0)
Number of elements in the ith component.
size_t d_globalSize
Number of local values.
Definition VectorData.h:675
size_t getLocalStartID() const
get local start id core.
Definition VectorData.h:76
void addGhostValuesByGlobalID(size_t num, const size_t *indices, const TYPE *vals)
Add shared values using global identifier.
void setGhostValuesByGlobalID(size_t num, const size_t *indices, const TYPE *vals)
Set ghost values using global identifier.
virtual size_t numberOfDataBlocks() const =0
Number of blocks of contiguous data in the Vector.
void setValuesByLocalID(size_t num, const size_t *indices, const TYPE *vals)
Set values in the vector by their local offset.
VectorDataIterator< TYPE > begin()
Return an iterator to the beginning of the data.
virtual std::shared_ptr< UpdateState > getUpdateStatusPtr() const =0
Return the current update state of this Vector.
virtual void addGhostValuesByGlobalID(size_t num, const size_t *indices, const void *vals, const typeID &id)=0
Add shared values using global identifier.
virtual AMP::Utilities::MemoryType getMemoryLocation() const
returns the memory location for data
Definition VectorData.h:528
virtual void putRawData(const void *buf, const typeID &id)=0
Copy data into this vector.
virtual size_t getNumberOfComponents() const
Return integer number of data components.
void addValuesByGlobalID(size_t num, const size_t *indices, const TYPE *vals)
Add owned or shared values using global identifier.
virtual void getGhostValuesByGlobalID(size_t num, const size_t *indices, void *vals, const typeID &id) const =0
Get ghost values in the vector by their global offset.
size_t d_localStart
Number of global values.
Definition VectorData.h:676
virtual void reset()
reset the vector data object
virtual ~VectorData()
Virtual destructor.
Definition VectorData.h:41
void addValuesByLocalID(size_t num, const size_t *indices, const TYPE *vals)
Add values to vector entities by their local offset.
VectorDataIterator< const TYPE > constEnd() const
Return an iterator to the end of the data.
virtual void assemble()
This method is used to implement the assemble interface of PETSc.
Definition VectorData.h:631
VectorDataIterator< const TYPE > end() const
Return an iterator to the end of the data.
void getGhostValuesByGlobalID(size_t num, const size_t *indices, TYPE *vals) const
Get ghost values in the vector by their global offset.
virtual size_t sizeOfDataBlock(size_t i=0) const =0
Number of elements in a data block.
UpdateState getGlobalUpdateStatus() const
Return the current update state of the Vector.
size_t getGlobalSize() const
Number of total entries in this vector across all cores.
Definition VectorData.h:71
const RETURN_TYPE * getRawDataBlock(size_t i=0) const
Obtain a particular contiguous block of data cast to RETURN_TYPE.
virtual void makeConsistent()
Update shared values on entire communicator.
bool isType(const typeID &id, size_t block) const
Is the data of the given type.
VectorDataIterator< const TYPE > constBegin() const
Return an iterator to the beginning of the data.
A class used to hold vector operations.
Scalar is a class used to store a scalar variable that may be different types/precision.
Definition Scalar.h:21
Enhancement of std::enable_shared_from_this.
UpdateState
The four states a Vector can be in.
Definition Variable.h:26
ScatterType
Flag to choose algorithm for makeConsistent.
Definition Variable.h:21
MemoryType
Enum to store pointer type.
Definition Memory.h:21
Class to store type info.
Definition typeid.h:210



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