* change the map, use the
* reinit(const Epetra_Map
* &input_map) function.
- *
- * Since Trilinos only works on
- * doubles, this function is
- * limited to accept only one
- * possible number type in the
- * deal.II vector.
*/
template <typename Number>
Vector &
- operator = (const ::dealii::Vector<Number> &v);
+ operator = (const ::dealii::Vector<Number> &v);
/**
* This reinit function is
{
u.swap (v);
}
-
+
#ifndef DOXYGEN
return *this;
}
+
+ template <typename Number>
+ Vector &
+ Vector::operator = (const ::dealii::Vector<Number> &v)
+ {
+ VectorBase::operator = (v);
+ return *this;
+ }
+
+
#endif
} /* end of namespace MPI */
operator = (const Vector &V);
private:
+ /**
+ * A map indicating the size of the
+ * vector.
+ */
Epetra_LocalMap map;
-
};
* @relates TrilinosWrappers::Vector
* @author Martin Kronbichler, Wolfgang Bangerth, 2008
*/
- inline
- void swap (Vector &u, Vector &v)
- {
- u.swap (v);
- }
+ inline
+ void swap (Vector &u, Vector &v)
+ {
+ u.swap (v);
+ }
#ifndef DOXYGEN
- template <typename number>
- Vector::Vector (const dealii::Vector<number> &v)
- :
+ template <typename number>
+ Vector::Vector (const dealii::Vector<number> &v)
+ :
#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
- map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD))
+ map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD))
#else
- map (v.size(), 0, Epetra_SerialComm())
+ map (v.size(), 0, Epetra_SerialComm())
#endif
- {
- vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map, false));
+ {
+ vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map, false));
- std::vector<int> indices (v.size());
- for (unsigned int i=0; i<v.size(); ++i)
- indices[i] = map.GID(i);
+ std::vector<int> indices (v.size());
+ for (unsigned int i=0; i<v.size(); ++i)
+ indices[i] = map.GID(i);
- const int ierr = vector->ReplaceGlobalValues(v.size(), 0, v.begin(),
- &indices[0]);
- AssertThrow (ierr == 0, ExcTrilinosError());
- }
+ const int ierr = vector->ReplaceGlobalValues(v.size(), 0, v.begin(),
+ &indices[0]);
+ AssertThrow (ierr == 0, ExcTrilinosError());
+ }
- inline
- Vector &
- Vector::operator = (const TrilinosScalar s)
- {
- VectorBase::operator = (s);
+ inline
+ Vector &
+ Vector::operator = (const TrilinosScalar s)
+ {
+ VectorBase::operator = (s);
- return *this;
- }
+ return *this;
+ }
+ template <typename Number>
+ Vector &
+ Vector::operator = (const ::dealii::Vector<Number> &v)
+ {
+ VectorBase::operator = (v);
+ return *this;
+ }
+
#endif
VectorBase &
operator = (const TrilinosScalar s);
+ /**
+ * Another copy function. This
+ * one takes a deal.II vector and
+ * copies it into a
+ * TrilinosWrapper vector. Note
+ * that since we do not provide
+ * any Epetra_map that tells
+ * about the partitioning of the
+ * vector among the MPI
+ * processes, the size of the
+ * TrilinosWrapper vector has to
+ * be the same as the size of the
+ * input vector. In order to
+ * change the map, use the
+ * reinit(const Epetra_Map
+ * &input_map) function.
+ */
+ template <typename Number>
+ VectorBase &
+ operator = (const ::dealii::Vector<Number> &v);
+
/**
* Test for equality. This
* function assumes that the
- template <typename Number>
- Vector &
- Vector::operator = (const ::dealii::Vector<Number> &v)
- {
- Assert (size() == v.size(),
- ExcDimensionMismatch(size(), v.size()));
-
- vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
-
- const int min_my_id = map.MinMyGID();
- const unsigned int size = map.NumMyElements();
-
- Assert (map.MaxLID() == size-1,
- ExcDimensionMismatch(map.MaxLID(), size-1));
-
- std::vector<int> indices (size);
- for (unsigned int i=0; i<size; ++i)
- indices[i] = map.GID(i);
-
-
- const int ierr = vector->ReplaceGlobalValues(size, 0, v.begin()+min_my_id,
- &indices[0]);
- AssertThrow (ierr == 0, ExcTrilinosError());
-
- return *this;
- }
-
-
-
void
Vector::do_data_exchange (const TrilinosWrappers::SparseMatrix &m,
const Vector &v)
return *this;
}
-
-
-
- template <typename Number>
- Vector &
- Vector::operator = (const ::dealii::Vector<Number> &v)
- {
- if (size() != v.size())
- {
- map = LocalMap (v.size(), 0, vector->Comm());
- vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
- }
-
- std::vector<int> indices (v.size());
- for (unsigned int i=0; i<v.size(); ++i)
- indices[i] = map.GID(i);
-
- const int ierr = vector->ReplaceGlobalValues(v.size(), 0, v.begin(),
- &indices[0]);
- AssertThrow (ierr == 0, ExcTrilinosError());
-
- return *this;
- }
-
+
}
DEAL_II_NAMESPACE_CLOSE
}
+ template <typename number>
+ VectorBase &
+ VectorBase::operator = (const ::dealii::Vector<number> &v)
+ {
+ Assert (size() == v.size(),
+ ExcDimensionMismatch(size(), v.size()));
+
+ // this is probably not very efficient
+ // but works. in particular, we could do
+ // better if we know that
+ // number==TrilinosScalar because then we
+ // could elide the copying of elements
+ //
+ // let's hope this isn't a
+ // particularly frequent operation
+ std::pair<unsigned int, unsigned int>
+ local_range = this->local_range ();
+ std::vector<unsigned int> indices (local_range.second -
+ local_range.first);
+ std::vector<TrilinosScalar> values (local_range.second -
+ local_range.first);
+
+ for (unsigned int i=0; i<local_range.second-local_range.first; ++i)
+ {
+ indices[i] = i + local_range.first;
+ values[i] = v(i + local_range.first);
+ }
+
+ set (indices.size(), &indices[0], &values[0]);
+
+ return *this;
+ }
+
+
bool
VectorBase::operator == (const VectorBase &v) const
} /* end of namespace TrilinosWrappers */
+namespace TrilinosWrappers
+{
+#include "trilinos_vector_base.inst"
+}
+
DEAL_II_NAMESPACE_CLOSE
#endif // DEAL_II_USE_TRILINOS
--- /dev/null
+//---------------------------------------------------------------------------
+// $Id: vector.cc 15443 2007-11-05 03:43:52Z bangerth $
+// Version: $Name$
+//
+// Copyright (C) 2008 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------------------------------------------------------
+
+
+for (SCALAR : REAL_SCALARS)
+ {
+ template
+ VectorBase &
+ VectorBase::operator = (const ::dealii::Vector<SCALAR> &v);
+ }