From: Sebastian Kinnewig Date: Tue, 23 Jul 2024 08:19:05 +0000 (+0200) Subject: Allow the assignment onto vectors with one-to-one map. X-Git-Tag: v9.6.0-rc1~17^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F17357%2Fhead;p=dealii.git Allow the assignment onto vectors with one-to-one map. --- 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 {