// $Id$
// Version: $Name$
//
-// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
template <typename Number>
Vector<Number>::Vector (const Vector<Number>& v)
:
- dim(v.size()),
- maxdim(v.size()),
+ vec_size(v.size()),
+ max_vec_size(v.size()),
val(0)
{
- if (dim != 0)
+ if (vec_size != 0)
{
- val = new Number[maxdim];
+ val = new Number[max_vec_size];
Assert (val != 0, ExcOutOfMemory());
std::copy (v.begin(), v.end(), begin());
}
template <typename OtherNumber>
Vector<Number>::Vector (const Vector<OtherNumber>& v)
:
- dim(v.size()),
- maxdim(v.size()),
+ vec_size(v.size()),
+ max_vec_size(v.size()),
val(0)
{
- if (dim != 0)
+ if (vec_size != 0)
{
- val = new Number[maxdim];
+ val = new Number[max_vec_size];
Assert (val != 0, ExcOutOfMemory());
std::copy (v.begin(), v.end(), begin());
}
template <typename Number>
Vector<Number>::Vector (const PETScWrappers::Vector &v)
:
- dim(v.size()),
- maxdim(v.size()),
+ vec_size(v.size()),
+ max_vec_size(v.size()),
val(0)
{
- if (dim != 0)
+ if (vec_size != 0)
{
- val = new Number[maxdim];
+ val = new Number[max_vec_size];
Assert (val != 0, ExcOutOfMemory());
// get a representation of the vector
int ierr = VecGetArray (static_cast<const Vec&>(v), &start_ptr);
AssertThrow (ierr == 0, ExcPETScError(ierr));
- std::copy (start_ptr, start_ptr+dim, begin());
+ std::copy (start_ptr, start_ptr+vec_size, begin());
// restore the representation of the
// vector
template <typename Number>
Vector<Number>::Vector (const PETScWrappers::MPI::Vector &v)
:
- dim(0),
- maxdim(0),
+ vec_size(0),
+ max_vec_size(0),
val(0)
{
if (v.size() != 0)
void
Vector<Number>::swap (Vector<Number> &v)
{
- std::swap (dim, v.dim);
- std::swap (maxdim, v.maxdim);
+ std::swap (vec_size, v.vec_size);
+ std::swap (max_vec_size, v.max_vec_size);
std::swap (val, v.val);
}
bool
Vector<Number>::all_zero () const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
const_iterator p = begin(),
e = end();
bool
Vector<Number>::is_non_negative () const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
const_iterator p = begin(),
e = end();
template <typename Number2>
Number Vector<Number>::operator * (const Vector<Number2>& v) const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
if (this == reinterpret_cast<const Vector<Number>*>(&v))
return norm_sqr();
- Assert (dim == v.size(), ExcDimensionMismatch(dim, v.size()));
+ Assert (vec_size == v.size(), ExcDimensionMismatch(vec_size, v.size()));
Number sum0 = 0,
sum1 = 0,
// allowing pipelined commands to be
// executed in parallel
const_iterator ptr = begin(),
- eptr = ptr + (dim/4)*4;
+ eptr = ptr + (vec_size/4)*4;
typename Vector<Number2>::const_iterator vptr = v.begin();
while (ptr!=eptr)
{
template <typename Number>
Number Vector<Number>::norm_sqr () const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
Number sum0 = 0,
sum1 = 0,
// allowing pipelined commands to be
// executed in parallel
const_iterator ptr = begin(),
- eptr = ptr + (dim/4)*4;
+ eptr = ptr + (vec_size/4)*4;
while (ptr!=eptr)
{
sum0 += internal::VectorHelper::sqr(*ptr++);
template <typename Number>
Number Vector<Number>::mean_value () const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
Number sum0 = 0,
sum1 = 0,
// allowing pipelined commands to be
// executed in parallel
const_iterator ptr = begin(),
- eptr = ptr + (dim/4)*4;
+ eptr = ptr + (vec_size/4)*4;
while (ptr!=eptr)
{
sum0 += *ptr++;
template <typename Number>
Number Vector<Number>::l1_norm () const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
Number sum0 = 0,
sum1 = 0,
// allowing pipelined commands to be
// executed in parallel
const_iterator ptr = begin(),
- eptr = ptr + (dim/4)*4;
+ eptr = ptr + (vec_size/4)*4;
while (ptr!=eptr)
{
sum0 += std::fabs(*ptr++);
template <typename Number>
Number Vector<Number>::lp_norm (const Number p) const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
Number sum0 = 0,
sum1 = 0,
// allowing pipelined commands to be
// executed in parallel
const_iterator ptr = begin(),
- eptr = ptr + (dim/4)*4;
+ eptr = ptr + (vec_size/4)*4;
while (ptr!=eptr)
{
sum0 += std::pow(std::fabs(*ptr++), p);
template <typename Number>
Number Vector<Number>::linfty_norm () const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
Number max0=0.,
max1=0.,
max2=0.,
max3=0.;
- for (unsigned int i=0; i<(dim/4); ++i)
+ for (unsigned int i=0; i<(vec_size/4); ++i)
{
if (max0<std::fabs(val[4*i])) max0=std::fabs(val[4*i]);
if (max1<std::fabs(val[4*i+1])) max1=std::fabs(val[4*i+1]);
if (max3<std::fabs(val[4*i+3])) max3=std::fabs(val[4*i+3]);
};
// add up remaining elements
- for (unsigned int i=(dim/4)*4; i<dim; ++i)
+ for (unsigned int i=(vec_size/4)*4; i<vec_size; ++i)
if (max0<std::fabs(val[i]))
max0 = std::fabs(val[i]);
template <typename Number>
Vector<Number>& Vector<Number>::operator += (const Vector<Number>& v)
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
add (v);
return *this;
template <typename Number>
Vector<Number>& Vector<Number>::operator -= (const Vector<Number>& v)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
iterator i_ptr = begin(),
i_end = end();
template <typename Number>
void Vector<Number>::add (const Number v)
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
iterator i_ptr = begin(),
i_end = end();
template <typename Number>
void Vector<Number>::add (const Vector<Number>& v)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
iterator i_ptr = begin(),
i_end = end();
template <typename Number>
void Vector<Number>::add (const Number a, const Vector<Number>& v)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
iterator i_ptr = begin(),
i_end = end();
void Vector<Number>::add (const Number a, const Vector<Number>& v,
const Number b, const Vector<Number>& w)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
- Assert (dim == w.dim, ExcDimensionMismatch(dim, w.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
+ Assert (vec_size == w.vec_size, ExcDimensionMismatch(vec_size, w.vec_size));
iterator i_ptr = begin(),
i_end = end();
const_iterator v_ptr = v.begin(),
template <typename Number>
void Vector<Number>::sadd (const Number x, const Vector<Number>& v)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
iterator i_ptr = begin(),
i_end = end();
const_iterator v_ptr = v.begin();
void Vector<Number>::sadd (const Number x, const Number a,
const Vector<Number>& v)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
iterator i_ptr = begin(),
i_end = end();
const_iterator v_ptr = v.begin();
const Vector<Number>& v, const Number b,
const Vector<Number>& w)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
- Assert (dim == w.dim, ExcDimensionMismatch(dim, w.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
+ Assert (vec_size == w.vec_size, ExcDimensionMismatch(vec_size, w.vec_size));
iterator i_ptr = begin(),
i_end = end();
const_iterator v_ptr = v.begin(),
const Vector<Number>& w, const Number c,
const Vector<Number>& y)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
- Assert (dim == w.dim, ExcDimensionMismatch(dim, w.dim));
- Assert (dim == y.dim, ExcDimensionMismatch(dim, y.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
+ Assert (vec_size == w.vec_size, ExcDimensionMismatch(vec_size, w.vec_size));
+ Assert (vec_size == y.vec_size, ExcDimensionMismatch(vec_size, y.vec_size));
iterator i_ptr = begin(),
i_end = end();
const_iterator v_ptr = v.begin(),
template <typename Number>
void Vector<Number>::scale (const Number factor)
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
iterator ptr = begin();
const const_iterator eptr = end();
template <typename Number2>
void Vector<Number>::scale (const Vector<Number2> &s)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == s.dim, ExcDimensionMismatch(dim, s.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == s.vec_size, ExcDimensionMismatch(vec_size, s.vec_size));
iterator ptr = begin();
const const_iterator eptr = end();
void Vector<Number>::equ (const Number a, const Vector<Number>& u,
const Number b, const Vector<Number>& v)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == u.dim, ExcDimensionMismatch(dim, u.dim));
- Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == u.vec_size, ExcDimensionMismatch(vec_size, u.vec_size));
+ Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
iterator i_ptr = begin(),
i_end = end();
const_iterator u_ptr = u.begin(),
template <typename Number2>
void Vector<Number>::equ (const Number a, const Vector<Number2>& u)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == u.dim, ExcDimensionMismatch(dim, u.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == u.vec_size, ExcDimensionMismatch(vec_size, u.vec_size));
iterator i_ptr = begin(),
i_end = end();
typename Vector<Number2>::const_iterator u_ptr = u.begin();
template <typename Number>
void Vector<Number>::ratio (const Vector<Number> &a, const Vector<Number> &b)
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (a.dim == b.dim, ExcDimensionMismatch (a.dim, b.dim));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (a.vec_size == b.vec_size, ExcDimensionMismatch (a.vec_size, b.vec_size));
// no need to reinit with zeros, since
// we overwrite them anyway
Vector<Number>&
Vector<Number>::operator = (const Vector<Number>& v)
{
- if (v.dim != dim)
- reinit (v.dim, true);
- if (dim!=0)
+ if (v.vec_size != vec_size)
+ reinit (v.vec_size, true);
+ if (vec_size!=0)
std::copy (v.begin(), v.end(), begin());
return *this;
Vector<Number>&
Vector<Number>::operator = (const Vector<Number2>& v)
{
- if (v.size() != dim)
+ if (v.size() != vec_size)
reinit (v.size(), true);
- if (dim!=0)
+ if (vec_size!=0)
std::copy (v.begin(), v.end(), begin());
return *this;
Vector<Number> &
Vector<Number>::operator = (const PETScWrappers::Vector &v)
{
- if (v.size() != dim)
+ if (v.size() != vec_size)
reinit (v.size(), true);
- if (dim != 0)
+ if (vec_size != 0)
{
// get a representation of the vector
// and copy it
int ierr = VecGetArray (static_cast<const Vec&>(v), &start_ptr);
AssertThrow (ierr == 0, ExcPETScError(ierr));
- std::copy (start_ptr, start_ptr+dim, begin());
+ std::copy (start_ptr, start_ptr+vec_size, begin());
// restore the representation of the
// vector
bool
Vector<Number>::operator == (const Vector<Number2>& v) const
{
- Assert (dim!=0, ExcEmptyObject());
- Assert (dim == v.size(), ExcDimensionMismatch(dim, v.size()));
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == v.size(), ExcDimensionMismatch(vec_size, v.size()));
- for (unsigned int i=0; i<dim; ++i)
+ for (unsigned int i=0; i<vec_size; ++i)
if (val[i] != v.val[i])
return false;
template <typename Number>
void Vector<Number>::print (const char* format) const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
if (!format) format = " %5.2f";
for (unsigned int j=0;j<size();j++)
std::printf (format, val[j]);
const bool scientific,
const bool across) const
{
- Assert (dim!=0, ExcEmptyObject());
+ Assert (vec_size!=0, ExcEmptyObject());
AssertThrow (out, ExcIO());
std::ios::fmtflags old_flags = out.flags();
unsigned int
Vector<Number>::memory_consumption () const
{
- return sizeof(*this) + (maxdim * sizeof(Number));
+ return sizeof(*this) + (max_vec_size * sizeof(Number));
}