17 #include "../general/array.hpp"
18 #ifdef MFEM_USE_SUNDIALS
19 #include <nvector/nvector_serial.h>
23 #if defined(_MSC_VER) && (_MSC_VER < 1800)
25 #define isfinite _finite
33 inline int CheckFinite(
const double *v,
const int n);
62 void Load (std::istream ** in,
int np,
int *
dim);
65 void Load(std::istream &in,
int Size);
68 void Load(std::istream &in) {
int s; in >> s;
Load (in, s); }
119 inline operator double *() {
return data; }
124 inline operator const double *()
const {
return data; }
136 double &
Elem (
int i);
139 const double &
Elem (
int i)
const;
147 inline const double &
operator() (
int i)
const;
197 friend void add (
const double a,
const Vector &x,
228 void Print(std::ostream & out = std::cout,
int width = 8)
const;
242 double Normlp(
double p)
const;
259 #ifdef MFEM_USE_SUNDIALS
261 explicit Vector(N_Vector nv);
280 return isfinite(val);
282 return std::isfinite(val);
289 for (
int i = 0; i < n; i++)
301 data =
new double[s];
326 data =
new double[s];
341 MFEM_ASSERT(
data && i >= 0 && i <
size,
342 "index [" << i <<
"] is out of range [0," <<
size <<
")");
349 MFEM_ASSERT(
data && i >= 0 && i <
size,
350 "index [" << i <<
"] is out of range [0," <<
size <<
")");
376 inline double Distance(
const double *x,
const double *y,
const int n)
381 for (
int i = 0; i < n; i++)
383 d += (x[i]-y[i])*(x[i]-y[i]);
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)
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.
double & Elem(int i)
Access Vector entries. Index i = 0 .. size-1.
void Print(std::ostream &out=std::cout, int width=8) const
Prints vector to stream out.
void SetSize(int s)
Resize the vector to size s.
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 GetSubVector(const Array< int > &dofs, Vector &elemvect) const
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.
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 operator*(const double *) const
Dot product with a double * array.
Vector & operator=(const double *v)
bool IsFinite(const double &val)
void Load(std::istream **in, int np, int *dim)
Reads a vector from multiple files.
double Normlp(double p) const
Returns the l_p norm of 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.
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.
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 > &)
double Distance(const double *x, const double *y, const int n)
void Print_HYPRE(std::ostream &out) const
Prints vector to stream out in HYPRE_Vector format.
void SetDataAndSize(double *d, int s)
Set the Vector data and size.
Vector & Set(const double a, const Vector &x)
(*this) = a * x
Vector & Add(const double a, const Vector &Va)
(*this) += a * Va
double Max() const
Returns the maximal element of the vector.
void Destroy()
Destroy a vector.
Vector & operator-=(double c)
friend void add(const Vector &v1, const Vector &v2, Vector &v)
Set v = v1 + v2.
Vector & operator+=(const Vector &v)
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)