*/
virtual void equ(const Number a, const VectorSpaceVector<Number> &V) override;
+ /**
+ * Return wether the vector contains only elements with value zero.
+ */
+ virtual bool all_zero() const override;
+
/**
* Return the mean value of all the entries of this vector.
*/
* This function is mainly for internal consistency checks and should
* seldom be used when not in debug mode since it uses quite some time.
*/
- bool all_zero () const;
+ virtual bool all_zero () const override;
/**
* Compute the mean value of all the entries in the vector.
* This is a collective operation. This function is expensive, because
* potentially all elements have to be checked.
*/
- bool all_zero () const;
+ virtual bool all_zero () const override;
/**
* Compute the mean value of all the entries in the vector.
*/
virtual void equ(const Number a, const VectorSpaceVector<Number> &V);
+ /**
+ * Return wether the vector contains only elements with value zero.
+ */
+ virtual bool all_zero() const override;
+
/**
* Return the mean value of all the entries of this vector.
*/
+ template <typename Number>
+ bool Vector<Number>::all_zero() const
+ {
+ Assert(this->size(), ExcEmptyObject());
+
+ const size_type size = this->size();
+ for (size_type i=0; i<size; ++i)
+ if (this->val[i] != Number())
+ return false;
+
+ return true;
+ }
+
+
+
template <typename Number>
typename Vector<Number>::value_type Vector<Number>::mean_value() const
{
*/
virtual void equ(const double a, const VectorSpaceVector<double> &V);
+ /**
+ * Return wether the vector contains only elements with value zero.
+ */
+ virtual bool all_zero() const override;
+
/**
* Return the mean value of the element of this vector.
*/
// ---------------------------------------------------------------------
//
-// Copyright (C) 2015 - 2016 by the deal.II authors
+// Copyright (C) 2015 - 2017 by the deal.II authors
//
// This file is part of the deal.II library.
//
*/
virtual void equ(const Number a, const VectorSpaceVector<Number> &V) = 0;
+ /**
+ * Return whether the vector contains only elements with value zero.
+ */
+ virtual bool all_zero() const = 0;
+
/**
* Return the mean value of all the entries of this vector.
*/
+ template <typename Number>
+ bool Vector<Number>::all_zero() const
+ {
+ return (linfty_norm() == 0) ? true : false;
+ }
+
+
+
template <typename Number>
typename Vector<Number>::value_type Vector<Number>::mean_value() const
{
+ bool Vector::all_zero() const
+ {
+ // get a representation of the vector and
+ // loop over all the elements
+ double *start_ptr = (*vector)[0];
+ const double *ptr = start_ptr,
+ *eptr = start_ptr + vector->MyLength();
+ unsigned int flag = 0;
+ while (ptr != eptr)
+ {
+ if (*ptr != 0)
+ {
+ flag = 1;
+ break;
+ }
+ ++ptr;
+ }
+
+ // Check that the vector is zero on _all_ processors.
+ const Epetra_MpiComm *mpi_comm
+ = dynamic_cast<const Epetra_MpiComm *>(&vector->Map().Comm());
+ Assert(mpi_comm != nullptr, ExcInternalError());
+ unsigned int num_nonzero = Utilities::MPI::sum(flag, mpi_comm->Comm());
+
+ return num_nonzero == 0;
+ }
+
+
+
double Vector::mean_value() const
{
double mean_value(0.);