From c36fe5b95c8c586a318ed0bd5b048c834b885f88 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Thu, 5 Nov 2009 20:57:45 +0000 Subject: [PATCH] Implement an improved = operator for distributed vectors that can handle different Epetra_Maps. git-svn-id: https://svn.dealii.org/trunk@20043 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/source/trilinos_vector.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/deal.II/lac/source/trilinos_vector.cc b/deal.II/lac/source/trilinos_vector.cc index 923cccdf64..f984ce003f 100644 --- a/deal.II/lac/source/trilinos_vector.cc +++ b/deal.II/lac/source/trilinos_vector.cc @@ -205,7 +205,17 @@ namespace TrilinosWrappers Vector & Vector::operator = (const Vector &v) { - if (local_range() == v.local_range()) + // distinguish three cases. First case: both + // vectors have the same layout (just need to + // copy the local data). Second case: vectors + // have the same size, but different + // layout. The calling vector has a wider + // local range than the input vector, and the + // input vector has a 1-to-1 map (need to + // import data). The third case means that we + // have to rebuild the calling vector. + if (size() == v.size() && + local_range() == v.local_range()) { Assert (vector->Map().SameAs(v.vector->Map()) == true, ExcMessage ("The Epetra maps in the assignment operator =" @@ -217,6 +227,14 @@ namespace TrilinosWrappers last_action = Zero; } + else if (size() == v.size() && local_range().first<=v.local_range().first && + local_range().second>=v.local_range().second && + v.vector->Map().UniqueGIDs()) + { + Epetra_Import data_exchange (vector->Map(), v.vector->Map()); + const int ierr = vector->Import(*v.vector, data_exchange, Insert); + AssertThrow (ierr == 0, ExcTrilinosError(ierr)); + } else { vector.reset(); -- 2.39.5