33 for (
int i = 0; i < s; i++)
50 for (i = 0; i < np; i++)
58 for (i = 0; i < np; i++)
59 for (j = 0; j < dim[i]; j++)
69 for (
int i = 0; i <
size; i++)
88 const double *d =
data;
90 #ifdef MFEM_USE_OPENMP
91 #pragma omp parallel for reduction(+:prod)
93 for (
int i = 0; i < s; i++)
105 mfem_error(
"Vector::operator*(const Vector &) const");
114 for (
int i = 0; i <
size; i++)
124 for (
int i = 0; i <
size; i++)
134 double *p =
data, v = value;
135 for (i = 0; i < s; i++)
144 for (
int i = 0; i <
size; i++)
154 for (
int i = 0; i <
size; i++)
163 for (
int i = 0; i <
size; i++)
175 mfem_error(
"Vector::operator-=(const Vector &)");
178 for (
int i = 0; i <
size; i++)
190 mfem_error(
"Vector::operator+=(const Vector &)");
193 for (
int i = 0; i <
size; i++)
205 mfem_error(
"Vector::Add(const double, const Vector &)");
210 for (
int i = 0; i <
size; i++)
212 data[i] += a * Va(i);
223 mfem_error(
"Vector::Set(const double, const Vector &)");
226 for (
int i = 0; i <
size; i++)
236 double *vp = v.
data, *p =
data + offset;
239 if (offset+vs >
size)
241 mfem_error(
"Vector::SetVector(const Vector &, int)");
245 for (
int i = 0; i < vs; i++)
253 for (
int i = 0; i <
size; i++)
264 mfem_error(
"add(Vector &v1, Vector &v2, Vector &v)");
268 #ifdef MFEM_USE_OPENMP
269 #pragma omp parallel for
271 for (
int i = 0; i < v.
size; i++)
282 mfem_error (
"add(Vector &v1, double alpha, Vector &v2, Vector &v)");
289 else if (alpha == 1.0)
295 const double *v1p = v1.
data, *v2p = v2.
data;
298 #ifdef MFEM_USE_OPENMP
299 #pragma omp parallel for
301 for (
int i = 0; i < s; i++)
303 vp[i] = v1p[i] + alpha*v2p[i];
312 mfem_error (
"add(const double a, const Vector &x, const Vector &y,"
325 const double *xp = x.
data;
326 const double *yp = y.
data;
330 #ifdef MFEM_USE_OPENMP
331 #pragma omp parallel for
333 for (
int i = 0; i < s; i++)
335 zp[i] = a * (xp[i] + yp[i]);
345 mfem_error(
"add(const double a, const Vector &x,\n"
346 " const double b, const Vector &y, Vector &z)");
370 const double *xp = x.
data;
371 const double *yp = y.
data;
375 #ifdef MFEM_USE_OPENMP
376 #pragma omp parallel for
378 for (
int i = 0; i < s; i++)
380 zp[i] = a * xp[i] + b * yp[i];
390 mfem_error (
"subtract(const Vector &, const Vector &, Vector &)");
393 const double *xp = x.
data;
394 const double *yp = y.
data;
398 #ifdef MFEM_USE_OPENMP
399 #pragma omp parallel for
401 for (
int i = 0; i < s; i++)
403 zp[i] = xp[i] - yp[i];
411 mfem_error(
"subtract(const double a, const Vector &x,"
412 " const Vector &y, Vector &z)");
425 const double *xp = x.
data;
426 const double *yp = y.
data;
430 #ifdef MFEM_USE_OPENMP
431 #pragma omp parallel for
433 for (
int i = 0; i < s; i++)
435 zp[i] = a * (xp[i] - yp[i]);
444 for (
int i = 0; i <
size; i++)
450 else if (v[i] > hi[i])
459 int i, j, n = dofs.
Size();
463 for (i = 0; i < n; i++)
465 if ((j=dofs[i]) >= 0)
467 elemvect(i) =
data[j];
471 elemvect(i) = -
data[-1-j];
478 int i, j, n = dofs.
Size();
480 for (i = 0; i < n; i++)
482 if ((j=dofs[i]) >= 0)
484 elem_data[i] =
data[j];
488 elem_data[i] = -
data[-1-j];
495 int i, j, n = dofs.
Size();
497 for (i = 0; i < n; i++)
499 if ((j=dofs[i]) >= 0)
501 data[j] = elemvect(i);
505 data[-1-j] = -elemvect(i);
512 int i, j, n = dofs.
Size();
514 for (i = 0; i < n; i++)
516 if ((j=dofs[i]) >= 0)
518 data[j] = elem_data[i];
522 data[-1-j] = -elem_data[i];
529 int i, j, n = dofs.
Size();
531 for (i = 0; i < n; i++)
532 if ((j=dofs[i]) >= 0)
534 data[j] += elemvect(i);
538 data[-1-j] -= elemvect(i);
544 int i, j, n = dofs.
Size();
546 for (i = 0; i < n; i++)
548 if ((j = dofs[i]) >= 0)
550 data[j] += elem_data[i];
554 data[-1-j] -= elem_data[i];
562 int i, j, n = dofs.
Size();
564 for (i = 0; i < n; i++)
565 if ((j=dofs[i]) >= 0)
567 data[j] += a * elemvect(i);
571 data[-1-j] -= a * elemvect(i);
585 if (!
size) {
return; }
595 if ( i % width == 0 )
610 std::ios::fmtflags old_fmt = out.flags();
611 out.setf(std::ios::scientific);
612 std::streamsize old_prec = out.precision(14);
616 for (i = 0; i <
size; i++)
618 out <<
data[i] <<
'\n';
621 out.precision(old_prec);
628 const double max = (double)(RAND_MAX) + 1.;
636 srand((
unsigned)seed);
638 for (
int i = 0; i <
size; i++)
640 data[i] = fabs(rand()/max);
646 return sqrt((*
this)*(*
this));
652 for (
int i = 0; i <
size; i++)
654 max = std::max(std::abs(
data[i]), max);
662 for (
int i = 0; i <
size; i++)
664 sum += std::abs(
data[i]);
671 MFEM_ASSERT(p > 0.0,
"Vector::Normlp");
680 if (p < std::numeric_limits<double>::infinity())
683 for (
int i = 0; i <
size; i++)
685 sum += pow(fabs(
data[i]), p);
687 return pow(sum, 1.0/p);
697 double max =
data[0];
699 for (
int i = 1; i <
size; i++)
710 double min =
data[0];
712 for (
int i = 1; i <
size; i++)
725 for (
int i = 0; i <
size; i++)
int Size() const
Logical size of the array.
void SetVector(const Vector &v, int offset)
Vector()
Default constructor for Vector. Sets size = 0 and data = NULL.
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)
Resize the vector if the new size is different.
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
int Size() const
Returns the size of the vector.
double Normlinf() const
Returns the l_infinity norm of the vector.
void Randomize(int seed=0)
Set random values in the vector.
void add(const Vector &v1, const Vector &v2, Vector &v)
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 median(const Vector &lo, const Vector &hi)
v = median(v,lo,hi) entrywise. Implementation assumes lo <= hi.
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 & operator*=(double c)
double Min() const
Returns the minimal element of the vector.
double Norml1() const
Returns the l_1 norm of the vector.
double Distance(const double *x, const double *y, const int n)
void subtract(const Vector &x, const Vector &y, Vector &z)
void mfem_error(const char *msg)
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.
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.
Vector & operator-=(double c)
Vector & operator+=(const Vector &v)
double Sum() const
Return the sum of the vector entries.
void Neg()
(*this) = -(*this)