From 6913214d1bf2318551ed1afc28c848f32f7d1aa9 Mon Sep 17 00:00:00 2001 From: Sebastian Kinnewig Date: Tue, 23 Jul 2024 10:19:05 +0200 Subject: [PATCH] Allow the assignment onto vectors with one-to-one map. --- .../lac/trilinos_tpetra_vector.templates.h | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/include/deal.II/lac/trilinos_tpetra_vector.templates.h b/include/deal.II/lac/trilinos_tpetra_vector.templates.h index 0a3cd3ffed..4650e8e28a 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.templates.h @@ -383,26 +383,40 @@ namespace LinearAlgebra } else if (size() == V.size()) { - // We expect the origin vector to have a one-to-one map, otherwise - // we can not call Import - Assert(V.vector->getMap()->isOneToOne(), - ExcMessage( - "You are trying to map one vector distributed " - "between processors, where some elements belong " - "to multiple processors, onto another distribution " - "pattern, where some elements belong to multiple " - "processors. It is unclear how to deal with elements " - "in the vector belonging to multiple processors. " - "Therefore, compress() must be called on this " - "vector first.")); - - Teuchos::RCP> importer = - Tpetra::createImport(V.vector->getMap(), vector->getMap()); - - // Since we are distributing the vector from a one-to-one map - // we can always use the VectorOperation::insert / Tpetra::INSERT - // here. - vector->doImport(*V.vector, *importer, Tpetra::INSERT); + // We expect that at least one vector has a one-to-one map, otherwise + // we can neither call Import nor Export. + if (V.vector->getMap()->isOneToOne()) + { + Teuchos::RCP> + importer = + Tpetra::createImport(V.vector->getMap(), vector->getMap()); + + // Since we are distributing the vector from a one-to-one map + // we can always use the VectorOperation::insert / Tpetra::INSERT + // here. + vector->doImport(*V.vector, *importer, Tpetra::INSERT); + } + else if (vector->getMap()->isOneToOne()) + { + Teuchos::RCP> + exporter = + Tpetra::createExport(V.vector->getMap(), vector->getMap()); + + vector->doExport(*V.vector, *exporter, Tpetra::INSERT); + } + else + { + Assert(false, + ExcMessage( + "You are trying to map one vector distributed " + "between processors, where some elements belong " + "to multiple processors, onto another distribution " + "pattern, where some elements belong to multiple " + "processors. It is unclear how to deal with elements " + "in the vector belonging to multiple processors. " + "Therefore, compress() must be called on this " + "vector first.")); + } } else { -- 2.39.5