#include <vector>
#include <iterator>
#include <cmath>
+#include <cstddef>
DEAL_II_NAMESPACE_OPEN
};
-
+
/**
* Declaration of a specialized
* template of a structure which is
};
-
+
/**
* Declaration of a specialized
* template of a structure which is
*/
template <class BlockVectorType, bool constness>
class Iterator :
-#ifdef HAVE_STD_ITERATOR_CLASS
+#ifdef HAVE_STD_ITERATOR_CLASS
public std::iterator<std::random_access_iterator_tag,
typename Types<BlockVectorType,constness>::value_type>
#else
random_access_iterator<typename Types<BlockVectorType,constness>::value_type,int>
-#endif
+#endif
{
private:
/**
typedef
typename Types<BlockVectorType,constness>::value_type
value_type;
-
+
/**
* Declare some typedefs which
* are standard for iterators
* they work on.
*/
typedef std::random_access_iterator_tag iterator_type;
- typedef ptrdiff_t difference_type;
+ typedef std::ptrdiff_t difference_type;
typedef typename BlockVectorType::reference reference;
typedef value_type *pointer;
typedef
typename Types<BlockVectorType,constness>::dereference_type
dereference_type;
-
+
/**
* Typedef the type of the
* block vector (which differs
*/
Iterator (BlockVector &parent,
const unsigned int global_index);
-
+
/**
* Copy constructor.
*/
const unsigned int index_within_block,
const unsigned int next_break_forward,
const unsigned int next_break_backward);
-
+
public:
-
+
/**
* Copy operator.
*/
* presently pointed to.
*/
dereference_type operator [] (const difference_type d) const;
-
+
/**
* Prefix increment operator. This
* operator advances the iterator to
* exception.
*/
bool operator == (const Iterator &i) const;
-
+
/**
* Same, but compare with an
* iterator of different
* iterator of different
* constness.
*/
- bool operator != (const InverseConstnessIterator &i) const;
+ bool operator != (const InverseConstnessIterator &i) const;
/**
* Check whether this
* iterator of different
* constness.
*/
- bool operator < (const InverseConstnessIterator &i) const;
+ bool operator < (const InverseConstnessIterator &i) const;
/**
* Comparison operator alike
* iterator of different
* constness.
*/
- bool operator <= (const InverseConstnessIterator &i) const;
+ bool operator <= (const InverseConstnessIterator &i) const;
/**
* Comparison operator alike
* iterator of different
* constness.
*/
- bool operator > (const InverseConstnessIterator &i) const;
+ bool operator > (const InverseConstnessIterator &i) const;
/**
* Comparison operator alike
* in front of the present one.
*/
Iterator operator + (const difference_type &d) const;
-
+
/**
* Return an iterator which is
* the given number of elements
* and return the result.
*/
Iterator & operator -= (const difference_type &d);
-
+
/** @addtogroup Exceptions
* @{ */
-
+
/**
* Exception.
*/
* Exception.
*/
DeclException0 (ExcCastingAwayConstness);
- //@}
+ //@}
private:
/**
* Pointer to the block
*/
void move_backward ();
-
+
#ifndef DEAL_II_NAMESP_TEMPL_FRIEND_BUG
/**
* Mark all other instances of
* operators and reinit() functions of derived classes are responsible. This
* class only handles the common part that is independent of the actual vector
* type the block vector is built on.
- *
+ *
*
* <h3>Accessing individual blocks, and resizing vectors</h3>
*
* vector.
*/
typedef VectorType BlockType;
-
+
/*
* Declare standard types used in
* all containers. These types
* norms.
*/
typedef typename BlockType::real_type real_type;
-
+
/**
* Default constructor.
*/
* size.
*/
void collect_sizes ();
-
+
/**
* Call the compress() function on all
* the subblocks of the matrix.
*/
BlockType &
block (const unsigned int i);
-
+
/**
* Read-only access to a single block.
*/
* versions
*/
const BlockIndices &
- get_block_indices () const;
+ get_block_indices () const;
/**
* Number of blocks.
*/
unsigned int n_blocks () const;
-
+
/**
* Return dimension of the vector. This
* is the sum of the dimensions of all
* constant block vector.
*/
const_iterator begin () const;
-
+
/**
* Return an iterator pointing to
* the element past the end.
* the element past the end of a
* constant block vector.
*/
- const_iterator end () const;
+ const_iterator end () const;
/**
* Access components, returns U(i).
*/
value_type operator() (const unsigned int i) const;
-
+
/**
* Access components, returns U(i)
* as a writeable reference.
*/
BlockVectorBase &
operator = (const VectorType &v);
-
+
/**
* Check for equality of two block vector
* types. This operation is only allowed
template <class VectorType2>
bool
operator == (const BlockVectorBase<VectorType2> &v) const;
-
+
/**
* $U = U * V$: scalar product.
*/
* some time.
*/
bool all_zero () const;
-
+
/**
* Return @p true if the vector has no
* negative entries, i.e. all entries are
* vector.
*/
void add (const value_type s);
-
+
/**
* U+=V.
* Simple vector addition, equal to the
* <tt>operator +=</tt>.
*/
void add (const BlockVectorBase& V);
-
+
/**
* U+=a*V.
* Simple addition of a scaled vector.
*/
void add (const value_type a, const BlockVectorBase& V);
-
+
/**
* U+=a*V+b*W.
* Multiple addition of scaled vectors.
*/
void add (const value_type a, const BlockVectorBase& V,
const value_type b, const BlockVectorBase& W);
-
+
/**
* U=s*U+V.
* Scaling and simple vector addition.
*/
void sadd (const value_type s, const BlockVectorBase& V);
-
+
/**
* U=s*U+a*V.
* Scaling and simple addition.
*/
void sadd (const value_type s, const value_type a, const BlockVectorBase& V);
-
+
/**
* U=s*U+a*V+b*W.
* Scaling and multiple addition.
void sadd (const value_type s, const value_type a,
const BlockVectorBase& V,
const value_type b, const BlockVectorBase& W);
-
+
/**
* U=s*U+a*V+b*W+c*X.
* Scaling and multiple addition.
*/
void sadd (const value_type s, const value_type a,
const BlockVectorBase& V,
- const value_type b, const BlockVectorBase& W,
+ const value_type b, const BlockVectorBase& W,
const value_type c, const BlockVectorBase& X);
-
+
/**
* Scale each element of the
* vector by a constant
* given value.
*/
BlockVectorBase & operator /= (const value_type factor);
-
+
/**
* Multiply each element of this
* vector by the corresponding
*/
template <class BlockVector2>
void scale (const BlockVector2 &v);
-
+
/**
* U=a*V. Assignment.
*/
template <class BlockVector2>
void equ (const value_type a, const BlockVector2 &V);
-
+
/**
* U=a*V+b*W.
* Replacing by sum.
* of this object.
*/
unsigned int memory_consumption () const;
-
+
protected:
/**
* Pointer to the array of components.
friend class iterator;
friend class const_iterator;
#endif
-
+
template <typename> friend class BlockVectorBase;
};
// constness. disallow this
Assert (constness==true, ExcCastingAwayConstness());
}
-
+
template <class BlockVectorType, bool constness>
next_break_backward (next_break_backward)
{
}
-
+
template <class BlockVectorType, bool constness>
if ((global_index+d >= next_break_backward) &&
(global_index+d <= next_break_forward))
return parent->block(current_block)(index_within_block + d);
-
+
// if the index is not within the
// block of the block vector into
// which we presently point, then
return (global_index == i.global_index);
}
-
+
template <class BlockVectorType, bool constness>
return (global_index != i.global_index);
}
-
+
template <class BlockVectorType, bool constness>
return (global_index >= i.global_index);
}
-
+
template <class BlockVectorType, bool constness>
indices = parent.block_indices.global_to_local(global_index);
current_block = indices.first;
index_within_block = indices.second;
-
+
next_break_backward
= parent.block_indices.local_to_global (current_block, 0);
next_break_forward
};
}
-
+
template <class BlockVectorType, bool constness>
void
// away
next_break_forward = numbers::invalid_unsigned_int;
};
-
+
++global_index;
}
// between blocks:
--current_block;
index_within_block = parent->block_indices.block_size(current_block)-1;
-
+
// break forwards is now old
// break backward
next_break_forward = next_break_backward-1;
-
+
// compute new break forward
next_break_backward
-= parent->block_indices.block_size (current_block);
next_break_forward = 0;
next_break_backward = 0;
};
-
+
--global_index;
}
-
+
} // namespace BlockVectorIterators
} //namespace internal
{
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
value_type sum = 0.;
for (unsigned int i=0;i<n_blocks();++i)
sum += components[i]*v.components[i];
-
+
return sum;
}
real_type sum = 0.;
for (unsigned int i=0;i<n_blocks();++i)
sum += components[i].norm_sqr();
-
+
return sum;
}
value_type sum = 0.;
for (unsigned int i=0;i<n_blocks();++i)
sum += components[i].mean_value() * components[i].size();
-
+
return sum/size();
}
real_type sum = 0.;
for (unsigned int i=0;i<n_blocks();++i)
sum += components[i].l1_norm();
-
+
return sum;
}
{
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i] -= v.components[i];
}
return *this;
}
-
+
template <class VectorType>
template <class VectorType>
void BlockVectorBase<VectorType>::add (const value_type a)
{
- Assert (numbers::is_finite(a),
+ Assert (numbers::is_finite(a),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
for (unsigned int i=0;i<n_blocks();++i)
{
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i].add(v.components[i]);
const BlockVectorBase<VectorType>& v)
{
- Assert (numbers::is_finite(a),
+ Assert (numbers::is_finite(a),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i].add(a, v.components[i]);
const BlockVectorBase<VectorType>& w)
{
- Assert (numbers::is_finite(a),
+ Assert (numbers::is_finite(a),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(b),
+ Assert (numbers::is_finite(b),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
Assert (n_blocks() == w.n_blocks(),
ExcDimensionMismatch(n_blocks(), w.n_blocks()));
-
-
+
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i].add(a, v.components[i], b, w.components[i]);
const BlockVectorBase<VectorType>& v)
{
- Assert (numbers::is_finite(x),
+ Assert (numbers::is_finite(x),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i].sadd(x, v.components[i]);
const BlockVectorBase<VectorType>& v)
{
- Assert (numbers::is_finite(x),
+ Assert (numbers::is_finite(x),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(a),
+ Assert (numbers::is_finite(a),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i].sadd(x, a, v.components[i]);
const BlockVectorBase<VectorType>& w)
{
- Assert (numbers::is_finite(x),
+ Assert (numbers::is_finite(x),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(a),
+ Assert (numbers::is_finite(a),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(b),
+ Assert (numbers::is_finite(b),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
Assert (n_blocks() == w.n_blocks(),
ExcDimensionMismatch(n_blocks(), w.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i].sadd(x, a, v.components[i], b, w.components[i]);
const BlockVectorBase<VectorType>& y)
{
- Assert (numbers::is_finite(x),
+ Assert (numbers::is_finite(x),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(a),
+ Assert (numbers::is_finite(a),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(b),
+ Assert (numbers::is_finite(b),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(c),
+ Assert (numbers::is_finite(c),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (n_blocks() == v.n_blocks(),
- ExcDimensionMismatch(n_blocks(), v.n_blocks()));
+ ExcDimensionMismatch(n_blocks(), v.n_blocks()));
Assert (n_blocks() == w.n_blocks(),
ExcDimensionMismatch(n_blocks(), w.n_blocks()));
Assert (n_blocks() == y.n_blocks(),
ExcDimensionMismatch(n_blocks(), y.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i].sadd(x, a, v.components[i],
const BlockVectorBase<VectorType>& w)
{
- Assert (numbers::is_finite(a),
+ Assert (numbers::is_finite(a),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(b),
+ Assert (numbers::is_finite(b),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
Assert (n_blocks() == w.n_blocks(),
- ExcDimensionMismatch(n_blocks(), w.n_blocks()));
-
+ ExcDimensionMismatch(n_blocks(), w.n_blocks()));
+
for (unsigned int i=0;i<n_blocks();++i)
{
components[i].equ( a, v.components[i], b, w.components[i]);
const BlockVector2 &v)
{
- Assert (numbers::is_finite(a),
+ Assert (numbers::is_finite(a),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
components[i].equ( a, v.components[i]);
}
BlockVectorBase<VectorType>::operator = (const value_type s)
{
- Assert (numbers::is_finite(s),
+ Assert (numbers::is_finite(s),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
for (unsigned int i=0;i<n_blocks();++i)
components[i] = s;
-
+
return *this;
}
{
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
components[i] = v.components[i];
{
Assert (n_blocks() == v.n_blocks(),
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
-
+
for (unsigned int i=0;i<n_blocks();++i)
components[i] = v.components[i];
-
+
return *this;
}
{
Assert (block_indices == v.block_indices,
ExcDifferentBlockIndices());
-
+
for (unsigned int i=0;i<n_blocks();++i)
if ( ! (components[i] == v.components[i]))
return false;
BlockVectorBase<VectorType>::operator *= (const value_type factor)
{
- Assert (numbers::is_finite(factor),
+ Assert (numbers::is_finite(factor),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
for (unsigned int i=0;i<n_blocks();++i)
BlockVectorBase<VectorType>::operator /= (const value_type factor)
{
- Assert (numbers::is_finite(factor),
+ Assert (numbers::is_finite(factor),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
Assert (factor > 0., ExcZero() );