From: Peter Munch Date: Mon, 10 May 2021 08:46:53 +0000 (+0200) Subject: Enable SUNDIALS::KINSOL for LinearAlgebra::distributed::Vector X-Git-Tag: v9.3.0-rc1~101^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=939cc98f48a0f85655753d83ab3e3e8d1ef3b38e;p=dealii.git Enable SUNDIALS::KINSOL for LinearAlgebra::distributed::Vector --- diff --git a/include/deal.II/sundials/copy.h b/include/deal.II/sundials/copy.h index 4a14ae9a5b..afc2ae3b52 100644 --- a/include/deal.II/sundials/copy.h +++ b/include/deal.II/sundials/copy.h @@ -24,6 +24,8 @@ # include # endif # include +# include +# include # include # include @@ -82,6 +84,18 @@ namespace SUNDIALS copy(Vector &dst, const N_Vector &src); void copy(N_Vector &dst, const Vector &src); + + void + copy(LinearAlgebra::distributed::BlockVector &dst, + const N_Vector & src); + void + copy(N_Vector & dst, + const LinearAlgebra::distributed::BlockVector &src); + + void + copy(LinearAlgebra::distributed::Vector &dst, const N_Vector &src); + void + copy(N_Vector &dst, const LinearAlgebra::distributed::Vector &src); } // namespace internal } // namespace SUNDIALS DEAL_II_NAMESPACE_CLOSE diff --git a/source/sundials/copy.cc b/source/sundials/copy.cc index 1c18eef17f..b11b279cc0 100644 --- a/source/sundials/copy.cc +++ b/source/sundials/copy.cc @@ -56,6 +56,77 @@ namespace SUNDIALS return static_cast(length); } + + void + copy(LinearAlgebra::distributed::Vector &dst, const N_Vector &src) + { + const IndexSet is = dst.locally_owned_elements(); + const std::size_t N = is.n_elements(); + AssertDimension(N, N_Vector_length(src)); + dst.zero_out_ghost_values(); + for (std::size_t i = 0; i < N; ++i) + { +# ifdef DEAL_II_WITH_MPI + dst.local_element(i) = NV_Ith_P(src, i); +# else + dst.local_element(i) = NV_Ith_S(src, i); +# endif + } + dst.compress(VectorOperation::insert); + } + + void + copy(N_Vector &dst, const LinearAlgebra::distributed::Vector &src) + { + const IndexSet is = src.locally_owned_elements(); + const std::size_t N = is.n_elements(); + AssertDimension(N, N_Vector_length(dst)); + for (std::size_t i = 0; i < N; ++i) + { +# ifdef DEAL_II_WITH_MPI + NV_Ith_P(dst, i) = src.local_element(i); +# else + NV_Ith_S(dst, i) = src.local_element(i); +# endif + } + } + + void + copy(LinearAlgebra::distributed::BlockVector &dst, + const N_Vector & src) + { + const IndexSet is = dst.locally_owned_elements(); + const std::size_t N = is.n_elements(); + AssertDimension(N, N_Vector_length(src)); + dst.zero_out_ghost_values(); + for (std::size_t i = 0; i < N; ++i) + { +# ifdef DEAL_II_WITH_MPI + dst[is.nth_index_in_set(i)] = NV_Ith_P(src, i); +# else + dst[is.nth_index_in_set(i)] = NV_Ith_S(src, i); +# endif + } + dst.compress(VectorOperation::insert); + } + + void + copy(N_Vector & dst, + const LinearAlgebra::distributed::BlockVector &src) + { + IndexSet is = src.locally_owned_elements(); + const std::size_t N = is.n_elements(); + AssertDimension(N, N_Vector_length(dst)); + for (std::size_t i = 0; i < N; ++i) + { +# ifdef DEAL_II_WITH_MPI + NV_Ith_P(dst, i) = src[is.nth_index_in_set(i)]; +# else + NV_Ith_S(dst, i) = src[is.nth_index_in_set(i)]; +# endif + } + } + # ifdef DEAL_II_WITH_MPI # ifdef DEAL_II_WITH_TRILINOS diff --git a/source/sundials/kinsol.cc b/source/sundials/kinsol.cc index 83327e55f2..ce3cb44077 100644 --- a/source/sundials/kinsol.cc +++ b/source/sundials/kinsol.cc @@ -23,6 +23,8 @@ # include # include +# include +# include # ifdef DEAL_II_WITH_TRILINOS # include # include @@ -612,6 +614,9 @@ namespace SUNDIALS template class KINSOL>; template class KINSOL>; + template class KINSOL>; + template class KINSOL>; + # ifdef DEAL_II_WITH_MPI # ifdef DEAL_II_WITH_TRILINOS