33 for (
int i = 0; i < s; i++)
48 for (i = 0; i < np; i++)
54 for (i = 0; i < np; i++)
55 for (j = 0; j < dim[i]; j++)
63 for (
int i = 0; i <
size; i++)
80 const double *d =
data;
82 #ifdef MFEM_USE_OPENMP
83 #pragma omp parallel for reduction(+:prod)
85 for (
int i = 0; i < s; i++)
94 mfem_error(
"Vector::operator*(const Vector &) const");
102 for (
int i = 0; i <
size; i++)
110 for (
int i = 0; i <
size; i++)
118 double *p =
data, v = value;
119 for (i = 0; i < s; i++)
126 for (
int i = 0; i <
size; i++)
134 for (
int i = 0; i <
size; i++)
141 for (
int i = 0; i <
size; i++)
150 mfem_error(
"Vector::operator-=(const Vector &)");
152 for (
int i = 0; i <
size; i++)
161 mfem_error(
"Vector::operator+=(const Vector &)");
163 for (
int i = 0; i <
size; i++)
172 mfem_error(
"Vector::Add(const double, const Vector &)");
176 for (
int i = 0; i <
size; i++)
177 data[i] += a * Va(i);
186 mfem_error(
"Vector::Set(const double, const Vector &)");
188 for (
int i = 0; i <
size; i++)
196 double *vp = v.
data, *p =
data + offset;
199 if (offset+vs >
size)
200 mfem_error(
"Vector::SetVector(const Vector &, int)");
203 for (
int i = 0; i < vs; i++)
209 for (
int i = 0; i <
size; i++)
216 double *data = v1->
data;
231 mfem_error(
"add(Vector &v1, Vector &v2, Vector &v)");
234 #ifdef MFEM_USE_OPENMP
235 #pragma omp parallel for
237 for (
int i = 0; i < v.
size; i++)
245 mfem_error (
"add(Vector &v1, double alpha, Vector &v2, Vector &v)");
251 else if (alpha == 1.0)
257 const double *v1p = v1.
data, *v2p = v2.
data;
260 #ifdef MFEM_USE_OPENMP
261 #pragma omp parallel for
263 for (
int i = 0; i < s; i++)
264 vp[i] = v1p[i] + alpha*v2p[i];
272 mfem_error (
"add(const double a, const Vector &x, const Vector &y,"
285 const double *xp = x.
data;
286 const double *yp = y.
data;
290 #ifdef MFEM_USE_OPENMP
291 #pragma omp parallel for
293 for (
int i = 0; i < s; i++)
294 zp[i] = a * (xp[i] + yp[i]);
303 mfem_error(
"add(const double a, const Vector &x,\n"
304 " const double b, const Vector &y, Vector &z)");
328 const double *xp = x.
data;
329 const double *yp = y.
data;
333 #ifdef MFEM_USE_OPENMP
334 #pragma omp parallel for
336 for (
int i = 0; i < s; i++)
337 zp[i] = a * xp[i] + b * yp[i];
345 mfem_error (
"subtract(const Vector &, const Vector &, Vector &)");
347 const double *xp = x.
data;
348 const double *yp = y.
data;
352 #ifdef MFEM_USE_OPENMP
353 #pragma omp parallel for
355 for (
int i = 0; i < s; i++)
356 zp[i] = xp[i] - yp[i];
363 mfem_error(
"subtract(const double a, const Vector &x,"
364 " const Vector &y, Vector &z)");
377 const double *xp = x.
data;
378 const double *yp = y.
data;
382 #ifdef MFEM_USE_OPENMP
383 #pragma omp parallel for
385 for (
int i = 0; i < s; i++)
386 zp[i] = a * (xp[i] - yp[i]);
394 for (
int i = 0; i <
size; i++)
398 else if (v[i] > hi[i])
405 int i, j, n = dofs.
Size();
409 for (i = 0; i < n; i++)
410 if ((j=dofs[i]) >= 0)
411 elemvect(i) =
data[j];
413 elemvect(i) = -
data[-1-j];
418 int i, j, n = dofs.
Size();
420 for (i = 0; i < n; i++)
421 if ((j=dofs[i]) >= 0)
422 elem_data[i] =
data[j];
424 elem_data[i] = -
data[-1-j];
429 int i, j, n = dofs.
Size();
431 for (i = 0; i < n; i++)
432 if ((j=dofs[i]) >= 0)
433 data[j] = elemvect(i);
435 data[-1-j] = -elemvect(i);
440 int i, j, n = dofs.
Size();
442 for (i = 0; i < n; i++)
443 if ((j=dofs[i]) >= 0)
444 data[j] = elem_data[i];
446 data[-1-j] = -elem_data[i];
451 int i, j, n = dofs.
Size();
453 for (i = 0; i < n; i++)
454 if ((j=dofs[i]) >= 0)
455 data[j] += elemvect(i);
457 data[-1-j] -= elemvect(i);
462 int i, j, n = dofs.
Size();
464 for (i = 0; i < n; i++)
465 if ((j=dofs[i]) >= 0)
466 data[j] += elem_data[i];
468 data[-1-j] -= elem_data[i];
474 int i, j, n = dofs.
Size();
476 for (i = 0; i < n; i++)
477 if ((j=dofs[i]) >= 0)
478 data[j] += a * elemvect(i);
480 data[-1-j] -= a * elemvect(i);
493 if ( i % width == 0 )
504 std::ios::fmtflags old_fmt = out.flags();
505 out.setf(std::ios::scientific);
506 std::streamsize old_prec = out.precision(14);
510 for (i = 0; i <
size; i++)
511 out <<
data[i] <<
'\n';
513 out.precision(old_prec);
520 const double max = (double)(RAND_MAX) + 1.;
526 srand((
unsigned)seed);
528 for (
int i = 0; i <
size; i++)
529 data[i] = fabs(rand()/max);
534 return sqrt((*
this)*(*
this));
539 double max = fabs(
data[0]);
541 for (
int i = 1; i <
size; i++)
542 if (fabs(
data[i]) > max)
552 for (
int i = 0; i <
size; i++)
553 sum += fabs (
data[i]);
560 MFEM_ASSERT(p > 0.0,
"Vector::Normlp");
565 if (p < std::numeric_limits<double>::infinity())
568 for (
int i = 0; i <
size; i++)
569 sum += pow(fabs(
data[i]), p);
570 return pow(sum, 1.0/p);
578 double max =
data[0];
580 for (
int i = 1; i <
size; i++)
589 double min =
data[0];
591 for (
int i = 1; i <
size; i++)
602 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)
Resizes 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 Euclidian distance to another vector.
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 swap(Vector *v1, Vector *v2)
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)