1#ifndef included_AMP_Vector
2#define included_AMP_Vector
4#include "AMP/utils/Units.h"
5#include "AMP/utils/Utilities.h"
6#include "AMP/utils/enable_shared_from_this.h"
7#include "AMP/vectors/Variable.h"
8#include "AMP/vectors/data/VectorData.h"
9#include "AMP/vectors/operations/VectorOperations.h"
76 explicit Vector(
const std::string &name );
85 Vector( std::shared_ptr<VectorData> data,
86 std::shared_ptr<VectorOperations>
ops,
87 std::shared_ptr<Variable>
var,
88 std::shared_ptr<AMP::Discretization::DOFManager> DOFManager );
103 virtual std::string
type()
const;
137 if ( x.get() ==
this )
371 std::shared_ptr<Vector>
clone()
const;
381 std::shared_ptr<Vector>
clone(
const std::string &name )
const;
390 std::shared_ptr<Vector>
clone(
const std::shared_ptr<Variable> name )
const;
409 inline std::shared_ptr<AMP::Discretization::DOFManager>
getDOFManager()
const;
542 template<
typename VIEW_TYPE>
550 template<
typename VIEW_TYPE>
556 template<
typename VIEW_TYPE>
571 template<
class TYPE =
double>
578 template<
class TYPE =
double>
585 template<
class TYPE =
double>
601 template<
class TYPE =
double>
608 template<
class TYPE =
double>
615 template<
class TYPE =
double>
626 template<
typename RETURN_TYPE>
637 template<
typename RETURN_TYPE>
689 template<
typename TYPE>
722 template<
typename TYPE>
727 template<
typename TYPE>
732 template<
typename TYPE>
737 template<
typename TYPE>
742 template<
typename TYPE>
747 template<
typename TYPE>
752 template<
typename TYPE>
791 template<
typename TYPE =
double>
800 template<
typename TYPE =
double>
809 template<
typename TYPE =
double>
818 template<
typename TYPE =
double>
829 template<
typename TYPE>
868 std::shared_ptr<std::vector<std::any>>
d_Views;
880#include "AMP/vectors/Vector.inline.h"
Provides C++ wrapper around MPI routines.
Class to manage reading/writing restart data.
A class used to hold vector data.
A class used by Vector::select and Vector::selectInto to create vectors with particular data.
Abstraction of a discrete Vector in a linear simulation.
void setName(const std::string &name)
Set the vector name.
void dumpGhostedData(std::ostream &out, size_t offset=0) const
size_t getNumberOfComponents() const
Return integer number of patch data components in vector.
void makeConsistent(AMP::LinearAlgebra::ScatterType t)
void axpy(const Scalar &alpha, const Vector &x, const Vector &y)
Set this vector to alpha * x + y. .
Scalar wrmsNormMask(const Vector &x, const Vector &mask, const Vector &y) const
Return a weighted norm of a subset of a vector.
void getGhostValuesByGlobalID(int num, const size_t *indices, TYPE *vals) const
void getValuesByGlobalID(int num, const size_t *indices, TYPE *vals) const
bool containsGlobalElement(size_t id)
Vector::const_shared_ptr subsetVectorForVariable(const std::string &name) const
Retrieve a sub-vector associated with a particular Variable.
virtual void reset()
Reset.
uint64_t getDataID() const
void copy(const Vector &x)
Set vector equal to x For Vectors, .
void setValuesByGlobalID(int num, const size_t *indices, const TYPE *vals)
Scalar min() const
Return the minimum value of the vector. .
std::shared_ptr< Vector > clone() const
Allocate space in the same fashion as this
size_t sizeofDataBlockType(size_t i) const
virtual ~Vector()
Destructor.
TYPE getValueByLocalID(size_t i) const
Return a local value from the vector.
std::shared_ptr< std::vector< std::any > > d_Views
VectorDataIterator< const TYPE > end() const
Return an iterator to the end of the data.
VectorDataIterator< const TYPE > begin() const
Return an iterator to the beginning of the data.
virtual void swapVectors(Vector &other)
Swap the data in this Vector for another.
size_t getGhostSize() const
void addGhostValuesByGlobalID(int num, const size_t *indices, const TYPE *vals)
VectorDataIterator< const TYPE > constEnd() const
Return an iterator to the end of the data.
VectorDataIterator< const TYPE > constBegin() const
Return an iterator to the beginning of the data.
Vector::const_shared_ptr subsetVectorForComponent(size_t index) const
Retrieve ith subvector.
void swapData(VectorData &rhs)
const_shared_ptr select(const VectorSelector &criterion) const
Selects a portion of this vector and creates a view.
Scalar dot(const Vector &x) const
Return the dot product of this vector with the argument vector.
TYPE getGhostValueByGlobalID(size_t i) const
Return a ghost value from the vector.
Scalar mean() const
Return the maximum value of the vector. .
void addValuesByLocalID(int num, size_t *indices, const TYPE *vals)
Vector(int64_t fid, AMP::IO::RestartManager *manager)
Read restart data to file.
std::shared_ptr< VIEW_TYPE > getView() const
If a particular type of view of this Vector has been created, return it.
void subtract(const Vector &x, const Vector &y)
Subtracts one vector from another. For Vectors, .
const AMP_MPI & getComm() const
AMP::LinearAlgebra::UpdateState getUpdateStatus() const
size_t getGlobalSize() const
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
void operator=(const Vector &)=delete
No direct copying.
std::shared_ptr< VectorData > getVectorData()
Return the pointer to the VectorData.
void copyCast(std::shared_ptr< const Vector > x)
Copy up/down-casting this
virtual Vector::const_shared_ptr selectInto(const VectorSelector &criterion) const
Vector::shared_ptr subsetVectorForComponent(size_t index)
Retrieve ith subvector.
void linearSum(const Scalar &alpha, const Vector &x, const Scalar &beta, const Vector &y)
Set a vector to be a linear combination of two vectors. .
void scale(const Scalar &alpha)
Scale a vector. For Vectors, .
virtual std::string type() const
Return the name of the vector.
std::shared_ptr< Vector > clone(const std::string &name) const
Allocate space in the same fashion as this
std::shared_ptr< VectorOperations > d_VectorOps
Scalar minQuotient(const Vector &x) const
Returns the minimum of the quotient of two vectors:
std::pair< Scalar, Scalar > L2NormAndDot(const Vector &x) const
Return the L2 norm of this vector and the dot product with the argument vector.
void setNoGhosts()
Ensure this vector has no ghosts.
std::shared_ptr< AMP::Discretization::DOFManager > d_DOFManager
void setVariable(const std::shared_ptr< Variable > name)
Change the variable associated with this vector.
const RETURN_TYPE * getRawDataBlock(size_t i=0) const
Obtain a particular contiguous block of data cast to RETURN_TYPE.
std::shared_ptr< VectorOperations > getVectorOperations()
Return the pointer to the VectorOperation.
void addValuesByGlobalID(int num, const size_t *indices, const TYPE *vals)
size_t sizeOfDataBlock(size_t i=0) const
std::shared_ptr< Variable > d_Variable
uint64_t getID() const
Get a unique id hash for the vector.
std::shared_ptr< VectorData > d_VectorData
virtual void setUnits(AMP::Units)
Get the units for this Vector.
void setUpdateStatus(AMP::LinearAlgebra::UpdateState state)
void reciprocal(const Vector &x)
Set this to the component-wise reciprocal of a vector. .
virtual Vector::shared_ptr selectInto(const VectorSelector &criterion)
Selects a portion of this vector and puts a view into a vector.
const std::shared_ptr< Variable > getVariable() const
Get the variable associated with this vector.
void add(const Vector &x, const Vector &y)
Adds two vectors. For Vectors, .
void setToScalar(const Scalar &alpha)
Set all compenents of a vector to a scalar. For Vectors, the components of this are set to .
TYPE getValueByGlobalID(size_t i) const
Return a value from the vector.
bool isType(size_t block) const
std::string getName() const
Return the vector name.
size_t numberOfDataBlocks() const
virtual void registerChildObjects(AMP::IO::RestartManager *manager) const
Register any child objects.
void * getRawDataBlockAsVoid(size_t i)
void putRawData(const TYPE *buf)
bool hasView() const
If a particular type of view of this Vector has been created, return true.
Scalar wrmsNorm(const Vector &x, const Vector &y) const
Return a weighted norm of a vector.
std::shared_ptr< CommunicationList > getCommunicationList() const
Get the CommunicationList for this Vector.
RETURN_TYPE * getRawDataBlock(size_t i=0)
Obtain a particular contiguous block of data cast to RETURN_TYPE.
Vector::const_shared_ptr subsetVectorForVariable(std::shared_ptr< const Variable > var) const
Retrieve a sub-vector associated with a particular Variable.
shared_ptr select(const VectorSelector &criterion)
Selects a portion of this vector and creates a view.
Scalar sum() const
Return the maximum value of the vector. .
Vector(std::shared_ptr< VectorData > data, std::shared_ptr< VectorOperations > ops, std::shared_ptr< Variable > var, std::shared_ptr< AMP::Discretization::DOFManager > DOFManager)
Create an vector.
void setMin(const Scalar &val)
modify vector to have min value 'val' specified
AMP::Utilities::MemoryType getMemoryLocation() const
returns the memory location for data
virtual void writeRestart(int64_t fid) const
Write restart data to file.
std::shared_ptr< AMP::Discretization::DOFManager > getDOFManager() const
Get the DOFManager for this Vector.
Scalar max() const
Return the maximum value of the vector. .
void multiply(const Vector &x, const Vector &y)
Component-wise multiply one vector with another. For Vectors, .
std::shared_ptr< const VectorData > getVectorData() const
Return the pointer to the VectorData.
void setGhostValuesByGlobalID(int num, const size_t *indices, const TYPE *vals)
void setValuesByLocalID(int num, size_t *indices, const TYPE *vals)
void abs(const Vector &x)
Set this to the component-wise absolute value of a vector. .
std::shared_ptr< Vector > clone(const std::shared_ptr< Variable > name) const
Allocate space in the same fashion as this
Scalar L2Norm() const
Return discrete -norm of this vector.
void axpby(const Scalar &alpha, const Scalar &beta, const Vector &x)
Set this vector alpha * x + this. .
Scalar maxNorm() const
Return the -norm of this vector.
void dumpOwnedData(std::ostream &out, size_t GIDoffset=0, size_t LIDoffset=0) const
const void * getRawDataBlockAsVoid(size_t i) const
void zero()
Set vector entries (including ghosts) to zero.
Vector::shared_ptr subsetVectorForVariable(const std::string &name)
Retrieve a sub-vector associated with a particular Variable.
Scalar L1Norm() const
Return discrete -norm of this vector.
bool equals(const Vector &x, const Scalar &tol=1e-6) const
Check if two vectors are equal.
VectorDataIterator< TYPE > begin()
Return an iterator to the beginning of the data.
virtual void copyVector(std::shared_ptr< const Vector > x)
void swapVectors(Vector::shared_ptr other)
Swap the data in this Vector for another.
Vector(const Vector &)=delete
No direct copying.
void setCommunicationList(std::shared_ptr< CommunicationList > comm)
Vector(const std::string &name)
Create an empty vector with the given name.
auto & getUnits() const
Get the units for this Vector.
std::shared_ptr< const Vector > const_shared_ptr
void setRandomValues()
Set data in this vector to random values on [0,1).
Vector::shared_ptr subsetVectorForVariable(std::shared_ptr< const Variable > var)
Retrieve a sub-vector associated with a particular Variable.
std::string VectorDataName() const
void setValueByGlobalID(size_t i, TYPE v)
Set a value in the vector.
std::shared_ptr< const VectorOperations > getVectorOperations() const
Return the pointer to the VectorOperation.
void getRawData(TYPE *buf) const
virtual std::unique_ptr< Vector > rawClone() const
Allocate space in the same fashion as this
size_t getLocalSize() const
void divide(const Vector &x, const Vector &y)
Component-wise divide one vector by another. For Vectors, .
void getValuesByLocalID(int num, const size_t *indices, TYPE *vals) const
void registerView(std::shared_ptr< VIEW_TYPE > v) const
Add a view of this vector to an internal queue.
size_t getLocalStartID() const
Vector()
Empty Constructor.
void setMax(const Scalar &val)
modify vector to have max value 'val' specified
void scale(const Scalar &alpha, const Vector &x)
Set vector equal to scaled input. For Vectors, .
TYPE getLocalValueByGlobalID(size_t i) const
Return a local value from the vector.
void addScalar(const Vector &x, const Scalar &alpha)
set vector to .
std::shared_ptr< Variable > getVariable()
Get the variable associated with this vector.
std::shared_ptr< VectorData > cloneData() const
VectorDataIterator< TYPE > end()
Return an iterator to the end of the data.
virtual void rename(const std::string &src, const std::string &dst)
Renames.
Scalar is a class used to store a scalar variable that may be different types/precision.
Provides a class for storing units.
Enhancement of std::enable_shared_from_this.
#define AMP_ASSERT(EXP)
Assert error.
UpdateState
The four states a Vector can be in.
ScatterType
Flag to choose algorithm for makeConsistent.
std::ostream & operator<<(std::ostream &out, const Matrix &p)
MemoryType
Enum to store pointer type.