17 #include "../general/array.hpp"
20 #if defined(_MSC_VER) && (_MSC_VER < 1800)
22 #define isfinite _finite
30 inline int CheckFinite(
const double *v,
const int n);
56 void Load (std::istream ** in,
int np,
int *
dim);
59 void Load(std::istream &in,
int Size);
62 void Load(std::istream &in) {
int s; in >> s;
Load (in, s); }
90 inline operator double *() {
return data; }
92 inline operator const double *()
const {
return data; }
104 double &
Elem (
int i);
107 const double &
Elem (
int i)
const;
113 inline const double &
operator() (
int i)
const;
162 friend void add (
const double a,
const Vector &x,
191 void Print(std::ostream & out = std::cout,
int width = 8)
const;
205 double Normlp(
double p)
const;
231 for (
int i = 0; i < n; i++)
236 if (!std::isfinite(v[i]))
250 data =
new double[s];
275 data =
new double[s];
290 MFEM_ASSERT(
data && i >= 0 && i <
size,
291 "index [" << i <<
"] is out of range [0," <<
size <<
")");
298 MFEM_ASSERT(
data && i >= 0 && i <
size,
299 "index [" << i <<
"] is out of range [0," <<
size <<
")");
325 inline double Distance(
const double *x,
const double *y,
const int n)
330 for (
int i = 0; i < n; i++)
332 d += (x[i]-y[i])*(x[i]-y[i]);
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)
double & Elem(int i)
Sets value in vector. 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)
Resizes the vector if the new size is different.
friend void subtract(const Vector &v1, const Vector &v2, Vector &v)
Do v = v1 - v2.
double Norml2() const
Returns the l2 norm of the vector.
double & operator()(int i)
Sets value in vector. Index i = 0 .. size-1.
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 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
Vector & operator=(const double *v)
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.
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 SetSubVector(const Array< int > &dofs, const Vector &elemvect)
void Print_HYPRE(std::ostream &out) const
Prints vector to stream out in HYPRE_Vector format.
void SetDataAndSize(double *d, int s)
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)
Do v = v1 + v2.
Vector & operator+=(const Vector &v)
double Sum() const
Return the sum of the vector entries.
virtual ~Vector()
Destroys vector.
void Neg()
(*this) = -(*this)