void reinit(const size_type n,
const bool omit_zeroing_entries = false);
+ /**
+ * Change the dimension to that of the vector V. The elements of V are not
+ * copied.
+ */
+ virtual void reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries = false) override;
+
/**
* Import all the element from the input vector @p V.
* VectorOperation::values @p operation is used to decide if the
std::shared_ptr<const CommunicationPatternBase> communication_pattern =
std::shared_ptr<const CommunicationPatternBase> ()) override;
+ /**
+ * Sets all elements of the vector to the scalar @p s. This operation is
+ * only allowed if @p s is equal to zero.
+ */
+ virtual Vector<Number> &operator= (const Number s) override;
+
/**
* Multiply the entive vector by a fixed factor.
*/
*/
//@{
+ /**
+ * Change the dimension to that of the vector V. The elements of V are not
+ * copied.
+ */
+ virtual void reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries = false);
+
/**
* Multiply the entire vector by a fixed factor.
*/
+ template <typename Number>
+ void
+ BlockVector<Number>::reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries)
+ {
+ Assert(dynamic_cast<const BlockVector<Number> *>(&V)!=NULL,
+ ExcVectorTypeNotCompatible());
+ const BlockVector<Number> &down_V = dynamic_cast<const BlockVector<Number> &>(V);
+ reinit(down_V, omit_zeroing_entries);
+ }
+
+
template <typename Number>
BlockVector<Number> &
BlockVector<Number>::operator *= (const Number factor)
*/
//@{
+ /**
+ * Change the dimension to that of the vector V. The elements of V are not
+ * copied.
+ */
+ virtual void reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries = false);
+
/**
* Multiply the entire vector by a fixed factor.
*/
+ template <typename Number>
+ void Vector<Number>::reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries)
+ {
+ // Downcast. Throws an exception if invalid.
+ Assert(dynamic_cast<const Vector<Number> *>(&V)!=NULL,
+ ExcVectorTypeNotCompatible());
+ const Vector<Number> &down_V = dynamic_cast<const Vector<Number> &>(V);
+
+ reinit(down_V, omit_zeroing_entries);
+ }
+
+
+
template <typename Number>
Vector<Number> &
Vector<Number>::operator += (const VectorSpaceVector<Number> &vv)
template <typename InputIterator>
Vector(const InputIterator first, const InputIterator last);
+ /**
+ * Set the global size of the vector to @p size. The stored elements have
+ * their index in [0,size).
+ *
+ * If the flag @p omit_zeroing_entries is set to false, the memory will be
+ * initialized with zero, otherwise the memory will be untouched (and the
+ * user must make sure to fill it with reasonable data before using it).
+ */
+ virtual void reinit(const size_type size,
+ const bool omit_zeroing_entries = false);
+
+ /**
+ * Uses the same IndexSet as the one of the input vector @p in_vector and
+ * allocates memory for this vector.
+ *
+ * If the flag @p omit_zeroing_entries is set to false, the memory will be
+ * initialized with zero, otherwise the memory will be untouched (and the
+ * user must make sure to fill it with reasonable data before using it).
+ */
+ template <typename Number2>
+ void reinit(const ReadWriteVector<Number2> &in_vector,
+ const bool omit_zeroing_entries = false);
+
+ /**
+ * Initializes the vector. The indices are specified by @p
+ * locally_stored_indices.
+ *
+ * If the flag @p omit_zeroing_entries is set to false, the memory will be
+ * initialized with zero, otherwise the memory will be untouched (and the
+ * user must make sure to fill it with reasonable data before using it).
+ * locally_stored_indices.
+ */
+ virtual void reinit(const IndexSet &locally_stored_indices,
+ const bool omit_zeroing_entries = false);
+
+
+ /**
+ * Change the dimension to that of the vector V. The elements of V are not
+ * copied.
+ */
+ virtual void reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries = false);
+
/**
* Copies the data of the input vector @p in_vector.
*/
namespace LinearAlgebra
{
+ template <typename Number>
+ void Vector<Number>::reinit(const size_type size,
+ const bool omit_zeroing_entries)
+ {
+ ReadWriteVector<Number>::reinit(size, omit_zeroing_entries);
+ }
+
+
+
+ template <typename Number>
+ template <typename Number2>
+ void Vector<Number>::reinit(const ReadWriteVector<Number2> &in_vector,
+ const bool omit_zeroing_entries)
+ {
+ ReadWriteVector<Number>::reinit(in_vector, omit_zeroing_entries);
+ }
+
+
+
+ template <typename Number>
+ void Vector<Number>::reinit(const IndexSet &locally_stored_indices,
+ const bool omit_zeroing_entries)
+ {
+ ReadWriteVector<Number>::reinit(locally_stored_indices, omit_zeroing_entries);
+ }
+
+
+
+ template <typename Number>
+ void Vector<Number>::reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries)
+ {
+ // Check that casting will work.
+ Assert(dynamic_cast<const Vector<Number>*>(&V)!=NULL, ExcVectorTypeNotCompatible());
+
+ // Downcast V. If fails, throws an exception.
+ const Vector<Number> &down_V = dynamic_cast<const Vector<Number>&>(V);
+ Assert(down_V.size()==this->size(),
+ ExcMessage("Cannot add two vectors with different numbers of elements"));
+
+ ReadWriteVector<Number>::reinit(down_V, omit_zeroing_entries);
+ }
+
+
+
template <typename Number>
Vector<Number> &Vector<Number>::operator= (const Vector<Number> &in_vector)
{
{
this->thread_loop_partitioner = in_vector.thread_loop_partitioner;
if (this->size() != in_vector.size())
- this->reinit(in_vector, true);
+ ReadWriteVector<Number>::reinit(in_vector, true);
dealii::internal::VectorOperations::Vector_copy<Number, Number2> copier(in_vector.val, this->val);
internal::VectorOperations::parallel_for(copier, 0, this->size(), this->thread_loop_partitioner);
in.getline(buf,16,'\n');
sz = std::atoi(buf);
- this->reinit(sz,true);
+ ReadWriteVector<Number>::reinit(sz,true);
char c;
// in >> c;
#ifdef DEAL_II_WITH_TRILINOS
#include <deal.II/lac/trilinos_epetra_communication_pattern.h>
+#include <deal.II/lac/trilinos_epetra_vector.h>
#include "Epetra_MultiVector.h"
#endif
class Vector;
}
}
-
-namespace LinearAlgebra
-{
- namespace EpetraWrappers
- {
- class Vector;
- }
-}
#endif
#ifdef DEAL_II_WITH_CUDA
* initialized with zero, otherwise the memory will be untouched (and the
* user must make sure to fill it with reasonable data before using it).
*/
- void reinit (const size_type size,
- const bool omit_zeroing_entries = false);
+ virtual void reinit (const size_type size,
+ const bool omit_zeroing_entries = false);
/**
* Uses the same IndexSet as the one of the input vector @p in_vector and
* user must make sure to fill it with reasonable data before using it).
* locally_stored_indices.
*/
- void reinit (const IndexSet &locally_stored_indices,
- const bool omit_zeroing_entries = false);
+ virtual void reinit (const IndexSet &locally_stored_indices,
+ const bool omit_zeroing_entries = false);
#ifdef DEAL_II_WITH_CXX11
/**
#ifdef DEAL_II_WITH_MPI
#include <deal.II/base/index_set.h>
-#include <deal.II/lac/read_write_vector.h>
+#include <deal.II/base/subscriptor.h>
+#include <deal.II/lac/trilinos_epetra_communication_pattern.h>
#include <deal.II/lac/vector_space_vector.h>
#include <memory>
#include "mpi.h"
* @ingroup Vectors
* @author Bruno Turcksin, 2015
*/
- class Vector : public VectorSpaceVector<double>
+ class Vector : public VectorSpaceVector<double>, public Subscriptor
{
public:
/**
const MPI_Comm &communicator,
const bool omit_zeroing_entries = false);
+ /**
+ * Change the dimension to that of the vector V. The elements of V are not
+ * copied.
+ */
+ virtual void reinit(const VectorSpaceVector<double> &V,
+ const bool omit_zeroing_entries = false);
+
/**
* Copy function. This function takes a Vector and copies all the
* elements. The Vector will have the same parallel distribution as @p
*/
Vector &operator= (const Vector &V);
+ /**
+ * Sets all elements of the vector to the scalar @p s. This operation is
+ * only allowed if @p s is equal to zero.
+ */
+ Vector &operator= (const double s);
+
/**
* Imports all the elements present in the vector's IndexSet from the input
* vector @p V. VectorOperation::values @p operation is used to decide if
virtual double add_and_dot(const double a,
const VectorSpaceVector<double> &V,
const VectorSpaceVector<double> &W);
+ /**
+ * This function always returns false and is present only for backward
+ * compatibily.
+ */
+ bool has_ghost_elements() const;
/**
* Return the global size of the vector, equal to the sum of the number of
*/
std::shared_ptr<const CommunicationPattern> epetra_comm_pattern;
};
+
+
+ inline
+ bool Vector::has_ghost_elements() const
+ {
+ return false;
+ }
}
}
+
+/**
+ * Declare dealii::LinearAlgebra::EpetraWrappers::Vector as distributed vector.
+ */
+template <>
+struct is_serial_vector<LinearAlgebra::EpetraWrappers::Vector> : std_cxx11::false_type
+{
+};
+
DEAL_II_NAMESPACE_CLOSE
#endif
# include <deal.II/lac/full_matrix.h>
# include <deal.II/lac/exceptions.h>
# include <deal.II/lac/trilinos_vector.h>
+# include <deal.II/lac/trilinos_epetra_vector.h>
# include <deal.II/lac/vector_view.h>
#ifdef DEAL_II_WITH_CXX11
typedef types::global_dof_index size_type;
typedef typename numbers::NumberTraits<Number>::real_type real_type;
+ /**
+ * Change the dimension to that of the vector V. The elements of V are not
+ * copied.
+ */
+ virtual void reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries = false) = 0;
+
+ /**
+ * Sets all elements of the vector to the scalar @p s. This operation is
+ * only allowed if @p s is equal to zero.
+ */
+ virtual VectorSpaceVector<Number> &operator= (const Number s) = 0;
/**
* Multiply the entire vector by a fixed factor.
+ template <typename Number>
+ void Vector<Number>::reinit(const VectorSpaceVector<Number> &V,
+ const bool omit_zeroing_entries)
+ {
+ reinit(V.size(), omit_zeroing_entries);
+ }
+
+
+
template <typename Number>
void Vector<Number>::import(const ReadWriteVector<Number> &V,
VectorOperation::values operation,
+ template <typename Number>
+ Vector<Number> &Vector<Number>::operator= (const Number s)
+ {
+ Assert(s == Number(), ExcMessage("Onlyt 0 can be assigned to a vector."));
+ (void)s;
+
+ cudaError_t error_code = cudaMemset(val, 0, n_elements*sizeof(Number));
+ AssertCuda(error_code);
+
+ return *this;
+ }
+
+
+
template <typename Number>
Vector<Number> &Vector<Number>::operator*= (const Number factor)
{
void Vector<Number>::print(std::ostream &out,
const unsigned int precision,
const bool scientific,
- const bool across) const
+ const bool ) const
{
AssertThrow(out, ExcIO());
std::ios::fmtflags old_flags = out.flags();
#include <boost/io/ios_state.hpp>
+#include <deal.II/lac/read_write_vector.h>
#include "Epetra_Import.h"
#include "Epetra_Map.h"
#include "Epetra_MpiComm.h"
Vector::Vector(const Vector &V)
:
+ Subscriptor(),
vector(new Epetra_FEVector(V.trilinos_vector()))
{}
+ void Vector::reinit(const VectorSpaceVector<double> &V,
+ const bool omit_zeroing_entries)
+ {
+ // Check that casting will work.
+ Assert(dynamic_cast<const Vector *>(&V)!=NULL, ExcVectorTypeNotCompatible());
+
+ // Downcast V. If fails, throws an exception.
+ const Vector &down_V = dynamic_cast<const Vector &>(V);
+
+ reinit(down_V.locally_owned_elements(), down_V.get_mpi_communicator(),
+ omit_zeroing_entries);
+ }
+
+
+
Vector &Vector::operator= (const Vector &V)
{
// Distinguish three cases:
+ Vector &Vector::operator= (const double s)
+ {
+ Assert(s==0., ExcMessage("Only 0 can be assigned to a vector."));
+ vector->PutScalar(s);
+
+ return *this;
+ }
+
+
+
void Vector::import(const ReadWriteVector<double> &V,
VectorOperation::values operation,
std::shared_ptr<const CommunicationPatternBase> communication_pattern)
LinearAlgebra::CUDAWrappers::Vector<double> a;
LinearAlgebra::CUDAWrappers::Vector<double> b(size);
LinearAlgebra::CUDAWrappers::Vector<double> c(b);
+ LinearAlgebra::CUDAWrappers::Vector<double> d;
+ d.reinit(c);
AssertThrow(a.size()==0, ExcMessage("Vector has the wrong size."));
AssertThrow(b.size()==size, ExcMessage("Vector has the wrong size."));
AssertThrow(c.size()==size, ExcMessage("Vector has the wrong size."));
+ AssertThrow(d.size()==size, ExcMessage("Vector has the wrong size."));
a.reinit(size);
AssertThrow(a.size()==size, ExcMessage("Vector has the wrong size."));
c.import(read_write_1, VectorOperation::insert);
const double val = b*c;
AssertThrow(val==328350., ExcMessage("Problem in operator *."));
+
+ b = 0.;
+ read_write_3.import(b, VectorOperation::insert);
+ for (unsigned int i=0; i<size; ++i)
+ AssertThrow(read_write_3[i] == 0.,ExcMessage("Problem in operator =."));
}
int main(int argc, char **argv)