15 #include "../general/array.hpp"
16 #include "../general/globals.hpp"
17 #include "../general/mem_manager.hpp"
18 #include "../general/device.hpp"
19 #ifdef MFEM_USE_SUNDIALS
20 #include <nvector/nvector_serial.h>
25 #if defined(_MSC_VER) && (_MSC_VER < 1800)
27 #define isfinite _finite
39 inline int CheckFinite(
const double *v,
const int n);
92 void Load(std::istream ** in,
int np,
int *
dim);
95 void Load(std::istream &in,
int Size);
98 void Load(std::istream &in) {
int s; in >> s;
Load(in, s); }
160 {
return const_cast<double*
>((
const double*)
data); }
165 inline operator double *() {
return data; }
170 inline operator const double *()
const {
return data; }
200 const double &
Elem(
int i)
const;
261 friend void add(
const double a,
const Vector &x,
306 double Normlp(
double p)
const;
316 inline double DistanceTo(
const double *p)
const;
326 const double *
Read(
bool on_dev =
true)
const
349 #ifdef MFEM_USE_SUNDIALS
351 explicit Vector(N_Vector nv);
370 return isfinite(val);
372 return std::isfinite(val);
379 for (
int i = 0; i < n; i++)
469 MFEM_ASSERT(
data && i >= 0 && i <
size,
470 "index [" << i <<
"] is out of range [0," <<
size <<
")");
477 MFEM_ASSERT(
data && i >= 0 && i <
size,
478 "index [" << i <<
"] is out of range [0," <<
size <<
")");
504 for (
int i = 0; i < n; i++)
506 d += (x[i]-y[i])*(x[i]-y[i]);
512 inline double Distance(
const double *x,
const double *y,
const int n)
543 double loc_prod = x * y;
545 MPI_Allreduce(&loc_prod, &glb_prod, 1, MPI_DOUBLE, MPI_SUM, comm);
void SetSubVector(const Array< int > &dofs, const double value)
Set the entries listed in dofs to the given value.
void SetVector(const Vector &v, int offset)
int CheckFinite(const double *v, const int n)
double * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
Vector()
Default constructor for Vector. Sets size = 0 and data = NULL.
void NewDataAndSize(double *d, int s)
Set the Vector data and size, deleting the old data, if owned.
void MakeDataOwner() const
Set the Vector data (host pointer) ownership flag.
double & Elem(int i)
Access Vector entries. Index i = 0 .. size-1.
void SyncMemory(const Vector &v)
Update the memory location of the vector to match v.
void SetSize(int s)
Resize the vector to size s.
void Delete()
Delete the owned pointers. The Memory is not reset by this method.
friend void subtract(const Vector &v1, const Vector &v2, Vector &v)
Set v = v1 - v2.
double Norml2() const
Returns the l2 norm of the vector.
double & operator()(int i)
Access Vector entries using () for 0-based indexing.
void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
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...
void StealData(double **p)
Changes the ownership of the data; after the call the Vector is empty.
int Capacity() const
Return the size of the currently allocated data array.
T * Write(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for write access to mem with the mfem::Device MemoryClass, if on_dev = true...
int Size() const
Returns the size of the vector.
void Swap< Vector >(Vector &a, Vector &b)
Specialization of the template function Swap<> for class Vector.
double Normlinf() const
Returns the l_infinity norm of the vector.
void Randomize(int seed=0)
Set random values in the vector.
double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
double * GetData() const
Return a pointer to the beginning of the Vector data.
int Capacity() const
Return the size of the allocated memory.
Memory< double > & GetMemory()
Return a reference to the Memory object used by the Vector.
double operator*(const double *) const
Dot product with a double * array.
MemoryType GetMemoryType() const
Return a MemoryType that is currently valid. If both the host and the device pointers are currently v...
Vector & operator=(const double *v)
Copy Size() entries from v.
bool IsFinite(const double &val)
void Load(std::istream **in, int np, int *dim)
Reads a vector from multiple files.
bool OwnsData() const
Read the Vector data (host pointer) ownership flag.
void Wrap(T *ptr, int size, bool own)
Wrap an externally allocated host pointer, ptr with type MemoryType::HOST.
const double * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
double Normlp(double p) const
Returns the l_p norm of the vector.
void SetSize(int s, Vector &v)
Resize the vector to size s using the MemoryType of v.
double * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
void Swap(Vector &other)
Swap the contents of two Vectors.
void median(const Vector &lo, const Vector &hi)
v = median(v,lo,hi) entrywise. Implementation assumes lo <= hi.
double DistanceSquared(const double *x, const double *y, const int n)
void Load(std::istream &in)
Load a vector from an input stream, reading the size from the stream.
double * StealData()
Changes the ownership of the data; after the call the Vector is empty.
bool OwnsHostPtr() const
Return true if the host pointer is owned. Ownership indicates whether the pointer will be deleted by ...
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 MemoryClass, if on_dev = true...
void Reset()
Reset the memory to be empty, ensuring that Delete() will be a no-op.
void AddElementVector(const Array< int > &dofs, const Vector &elemvect)
Add (element) subvector to the vector.
Vector & operator/=(double c)
double DistanceTo(const double *p) const
Compute the Euclidean distance to another vector.
void SetSubVectorComplement(const Array< int > &dofs, const double val)
Set all vector entries NOT in the 'dofs' array to the given 'val'.
Vector(double *_data, int _size)
Creates a vector referencing an array of doubles, owned by someone else.
Vector & operator*=(double c)
double Min() const
Returns the minimal element of the vector.
double Norml1() const
Returns the l_1 norm of the vector.
void Swap(Array< T > &, Array< T > &)
void ClearOwnerFlags() const
Clear the ownership flags for the host and device pointers, as well as any internal data allocated by...
double Distance(const double *x, const double *y, const int n)
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
MemoryType
Memory types supported by MFEM.
void SetHostPtrOwner(bool own) const
Set/clear the ownership flag for the host pointer. Ownership indicates whether the pointer will be de...
void Sync(const Memory &other) const
Copy the host/device pointer validity flags from other to *this.
void Print_HYPRE(std::ostream &out) const
Prints vector to stream out in HYPRE_Vector format.
double DistanceSquaredTo(const double *p) const
Compute the square of the Euclidean distance to another vector.
void SetDataAndSize(double *d, int s)
Set the Vector data and size.
Vector & Set(const double a, const Vector &x)
(*this) = a * x
double InnerProduct(HypreParVector *x, HypreParVector *y)
Vector & Add(const double a, const Vector &Va)
(*this) += a * Va
T * ReadWrite(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for read+write access to mem with the mfem::Device MemoryClass, if on_dev = true...
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
double Max() const
Returns the maximal element of the vector.
void New(int size)
Allocate host memory for size entries with type MemoryType::HOST.
void NewMemoryAndSize(const Memory< double > &mem, int s, bool own_mem)
Reset the Vector to use the given external Memory mem and size s.
void Destroy()
Destroy a vector.
Vector & operator-=(double c)
double infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
int CheckFinite() const
Count the number of entries in the Vector for which isfinite is false, i.e. the entry is a NaN or +/-...
double * HostWrite()
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), false).
friend void add(const Vector &v1, const Vector &v2, Vector &v)
Set v = v1 + v2.
Vector(int size_, MemoryType mt)
Create a Vector of size size_ using MemoryType mt.
bool UseDevice() const
Read the internal device flag.
Vector & operator+=(const Vector &v)
const Memory< double > & GetMemory() const
Return a reference to the Memory object used by the Vector, const version.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
double Sum() const
Return the sum of the vector entries.
virtual N_Vector ToNVector()
Return a new wrapper SUNDIALS N_Vector of type SUNDIALS_NVEC_SERIAL.
virtual ~Vector()
Destroys vector.
void Neg()
(*this) = -(*this)
void SyncAliasMemory(const Vector &v)
Update the alias memory location of the vector to match v.