27#if defined(_MSC_VER) && (_MSC_VER < 1800)
29#define isfinite _finite
47 return std::numeric_limits<real_t>::infinity();
62#if defined(MFEM_USE_SINGLE)
72 return std::fmin(
real_t(rand())/max, 0.9999999403953552_r);
120 :
data(size_, h_mt, d_mt),
size(size_) { }
123 template <
int N,
typename T = real_t>
125 { std::copy(values, values + N,
GetData()); }
142 void Load(std::istream ** in,
int np,
int *
dim);
145 void Load(std::istream &in,
int Size);
234 MFEM_DEPRECATED
inline operator const real_t *()
const {
return data; }
425#ifdef MFEM_USE_ADIOS2
504 return (std::fpclassify(val) == FP_SUBNORMAL) ? 0.0 : val;
512 return isfinite(val);
514 return std::isfinite(val);
521 for (
int i = 0; i < n; i++)
530 MFEM_ASSERT(
s>=0,
"Unexpected negative size.");
626 MFEM_ASSERT(
data && i >= 0 && i <
size,
627 "index [" << i <<
"] is out of range [0," <<
size <<
")");
634 MFEM_ASSERT(
data && i >= 0 && i <
size,
635 "index [" << i <<
"] is out of range [0," <<
size <<
")");
661 for (
int i = 0; i < n; i++)
663 d += (x[i]-y[i])*(x[i]-y[i]);
686 MFEM_ASSERT(
p.Size() ==
Size(),
"Incompatible vector sizes.");
697 MFEM_ASSERT(
p.Size() ==
Size(),
"Incompatible vector sizes.");
719 MPI_Allreduce(&loc_prod, &glb_prod, 1, MFEM_MPI_REAL_T, MPI_SUM, comm);
Class used by MFEM to store pointers to host and/or device memory.
void SetHostPtrOwner(bool own) const
Set/clear the ownership flag for the host pointer. Ownership indicates whether the pointer will be de...
int Capacity() const
Return the size of the allocated memory.
void MakeAlias(const Memory &base, int offset, int size)
Create a memory object that points inside the memory object base.
bool UseDevice() const
Read the internal device flag.
void SyncAlias(const Memory &base, int alias_size) const
Update the alias Memory *this to match the memory location (all valid locations) of its base Memory,...
bool OwnsHostPtr() const
Return true if the host pointer is owned. Ownership indicates whether the pointer will be deleted by ...
MemoryType GetMemoryType() const
Return a MemoryType that is currently valid. If both the host and the device pointers are currently v...
void Sync(const Memory &other) const
Copy the host/device pointer validity flags from other to *this.
void DeleteDevice(bool copy_to_host=true)
Delete the device pointer, if owned. If copy_to_host is true and the data is valid only on device,...
void Reset()
Reset the memory to be empty, ensuring that Delete() will be a no-op.
void Wrap(T *ptr, int size, bool own)
Wrap an externally allocated host pointer, ptr with the current host memory type returned by MemoryMa...
void Delete()
Delete the owned pointers and reset the Memory object.
void New(int size)
Allocate host memory for size entries with the current host memory type returned by MemoryManager::Ge...
void Randomize(int seed=0)
Set random values in the vector.
void PrintHash(std::ostream &out) const
Print the Vector size and hash of its data.
real_t & Elem(int i)
Access Vector entries. Index i = 0 .. size-1.
Vector(int size_, MemoryType mt)
Create a Vector of size size_ using MemoryType mt.
void StealData(real_t **p)
Changes the ownership of the data; after the call the Vector is empty.
void SetSize(int s, const Vector &v)
Resize the vector to size s using the MemoryType of v.
void SetVector(const Vector &v, int offset)
virtual const real_t * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
const real_t & operator[](int i) const
Read only access to Vector entries using [] for 0-based indexing.
void median(const Vector &lo, const Vector &hi)
v = median(v,lo,hi) entrywise. Implementation assumes lo <= hi.
void Load(std::istream &in)
Load a vector from an input stream, reading the size from the stream.
void Neg()
(*this) = -(*this)
real_t * begin()
STL-like begin.
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
virtual real_t * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
void SetDataAndSize(real_t *d, int s)
Set the Vector data and size.
Vector(Vector &base, int base_offset, int size_)
Create a Vector referencing a sub-vector of the Vector base starting at the given offset,...
real_t Normlinf() const
Returns the l_infinity norm of the vector.
void MakeDataOwner() const
Set the Vector data (host pointer) ownership flag.
real_t Norml1() const
Returns the l_1 norm of the vector.
bool OwnsData() const
Read the Vector data (host pointer) ownership flag.
void SetSubVector(const Array< int > &dofs, const real_t value)
Set the entries listed in dofs to the given value.
friend void subtract(const Vector &v1, const Vector &v2, Vector &v)
Set v = v1 - v2.
Memory< real_t > & GetMemory()
Return a reference to the Memory object used by the Vector.
void AddElementVector(const Array< int > &dofs, const Vector &elemvect)
Add elements of the elemvect Vector to the entries listed in dofs. Negative dof values cause the -dof...
real_t operator*(const real_t *) const
Dot product with a double * array.
real_t & operator[](int i)
Access Vector entries using [] for 0-based indexing.
int CheckFinite() const
Count the number of entries in the Vector for which isfinite is false, i.e. the entry is a NaN or +/-...
void AddSubVector(const Vector &v, int offset)
const real_t * end() const
STL-like end (const version).
void Swap(Vector &other)
Swap the contents of two Vectors.
Vector & operator*=(real_t c)
void SyncAliasMemory(const Vector &v) const
Update the alias memory location of the vector to match v.
real_t Norml2() const
Returns the l2 norm of the vector.
void SyncMemory(const Vector &v) const
Update the memory location of the vector to match v.
void Load(std::istream **in, int np, int *dim)
Reads a vector from multiple files.
real_t DistanceSquaredTo(const real_t *p) const
Compute the square of the Euclidean distance to another vector.
Vector & Set(const real_t a, const Vector &x)
(*this) = a * x
real_t * end()
STL-like end.
const Memory< real_t > & GetMemory() const
Return a reference to the Memory object used by the Vector, const version.
void NewMemoryAndSize(const Memory< real_t > &mem, int s, bool own_mem)
Reset the Vector to use the given external Memory mem and size s.
real_t Max() const
Returns the maximal element of the vector.
virtual bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
Vector(int size_, MemoryType h_mt, MemoryType d_mt)
Create a Vector of size size_ using host MemoryType h_mt and device MemoryType d_mt.
void Destroy()
Destroy a vector.
Vector(const T(&values)[N])
Create a vector using a braced initializer list.
int Size() const
Returns the size of the vector.
virtual void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
real_t Sum() const
Return the sum of the vector entries.
void Print_HYPRE(std::ostream &out) const
Prints vector to stream out in HYPRE_Vector format.
void SetSize(int s)
Resize the vector to size s.
void Reciprocal()
(*this)(i) = 1.0 / (*this)(i)
virtual real_t * HostWrite()
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), false).
void NewDataAndSize(real_t *d, int s)
Set the Vector data and size, deleting the old data, if owned.
real_t Normlp(real_t p) const
Returns the l_p norm of the vector.
Vector & operator-=(real_t c)
const real_t * begin() const
STL-like begin (const version).
int Capacity() const
Return the size of the currently allocated data array.
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
Vector & operator=(const real_t *v)
Copy Size() entries from v.
void SetSubVectorComplement(const Array< int > &dofs, const real_t val)
Set all vector entries NOT in the dofs Array to the given val.
virtual real_t * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
virtual ~Vector()
Destroys vector.
real_t Min() const
Returns the minimal element of the vector.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
Vector & operator+=(real_t c)
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
real_t * StealData()
Changes the ownership of the data; after the call the Vector is empty.
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
real_t & operator()(int i)
Access Vector entries using () for 0-based indexing.
void DeleteDevice(bool copy_to_host=true)
Delete the device pointer, if owned. If copy_to_host is true and the data is valid only on device,...
Vector(real_t *data_, int size_)
Creates a vector referencing an array of doubles, owned by someone else.
void cross3D(const Vector &vin, Vector &vout) const
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
Vector & operator/=(real_t c)
friend void add(const Vector &v1, const Vector &v2, Vector &v)
Set v = v1 + v2.
real_t DistanceTo(const real_t *p) const
Compute the Euclidean distance to another vector.
const T * Read(const Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for read access to mem with the mfem::Device's DeviceMemoryClass, if on_dev = true,...
void Swap(Array< T > &, Array< T > &)
real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
T * Write(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for write access to mem with the mfem::Device's DeviceMemoryClass, if on_dev = true,...
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
real_t rand_real()
Generate a random real_t number in the interval [0,1) using rand().
bool IsFinite(const real_t &val)
real_t Distance(const real_t *x, const real_t *y, const int n)
real_t InnerProduct(HypreParVector *x, HypreParVector *y)
real_t DistanceSquared(const real_t *x, const real_t *y, const int n)
T * ReadWrite(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for read+write access to mem with the mfem::Device's DeviceMemoryClass,...
int CheckFinite(const real_t *v, const int n)
MemoryType
Memory types supported by MFEM.
void Swap< Vector >(Vector &a, Vector &b)
Specialization of the template function Swap<> for class Vector.
real_t p(const Vector &x, real_t t)