17 #include "../general/array.hpp"
18 #include "../general/globals.hpp"
19 #ifdef MFEM_USE_SUNDIALS
20 #include <nvector/nvector_serial.h>
24 #if defined(_MSC_VER) && (_MSC_VER < 1800)
26 #define isfinite _finite
38 inline int CheckFinite(
const double *v,
const int n);
67 void Load (std::istream ** in,
int np,
int *
dim);
70 void Load(std::istream &in,
int Size);
73 void Load(std::istream &in) {
int s; in >> s;
Load (in, s); }
126 inline operator double *() {
return data; }
131 inline operator const double *()
const {
return data; }
143 double &
Elem (
int i);
146 const double &
Elem (
int i)
const;
154 inline const double &
operator() (
int i)
const;
205 friend void add (
const double a,
const Vector &x,
250 double Normlp(
double p)
const;
260 inline double DistanceTo(
const double *p)
const;
269 #ifdef MFEM_USE_SUNDIALS
271 explicit Vector(N_Vector nv);
290 return isfinite(val);
292 return std::isfinite(val);
299 for (
int i = 0; i < n; i++)
311 data =
new double[s];
336 data =
new double[s];
351 MFEM_ASSERT(
data && i >= 0 && i <
size,
352 "index [" << i <<
"] is out of range [0," <<
size <<
")");
359 MFEM_ASSERT(
data && i >= 0 && i <
size,
360 "index [" << i <<
"] is out of range [0," <<
size <<
")");
390 for (
int i = 0; i < n; i++)
392 d += (x[i]-y[i])*(x[i]-y[i]);
398 inline double Distance(
const double *x,
const double *y,
const int n)
429 double loc_prod = x * y;
431 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)
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 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)
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.
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.
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.
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(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
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
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)
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)