From: Wolfgang Bangerth Date: Thu, 20 Apr 2023 01:00:10 +0000 (-0600) Subject: Deal with a circular dependency problem. X-Git-Tag: v9.5.0-rc1~309^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F15113%2Fhead;p=dealii.git Deal with a circular dependency problem. We can't ask a default-created vector for its MPI communicator if we only later initialize it. --- diff --git a/include/deal.II/sundials/n_vector.templates.h b/include/deal.II/sundials/n_vector.templates.h index 696fc8c64b..2918ee4ce4 100644 --- a/include/deal.II/sundials/n_vector.templates.h +++ b/include/deal.II/sundials/n_vector.templates.h @@ -76,7 +76,7 @@ namespace SUNDIALS * * @note This constructor is intended for the N_VClone() call of SUNDIALS. */ - NVectorContent(); + NVectorContent(const MPI_Comm comm); /** * Non-const access to the stored vector. Only allowed if a constructor @@ -361,9 +361,9 @@ namespace SUNDIALS template - NVectorContent::NVectorContent() + NVectorContent::NVectorContent(const MPI_Comm comm) : vector(typename VectorMemory::Pointer(mem)) - , comm(get_mpi_communicator_from_vector(*vector)) + , comm(comm) , is_const(false) {} @@ -565,14 +565,17 @@ namespace SUNDIALS { N_Vector v = clone_empty(w); - // the corresponding delete is called in destroy() - auto cloned = new NVectorContent(); auto *w_dealii = unwrap_nvector_const(w); - // reinit the cloned vector based on the layout of the source vector - cloned->get()->reinit(*w_dealii); - v->content = cloned; + // Create the vector; the corresponding delete is called in destroy() + auto cloned = new NVectorContent( + get_mpi_communicator_from_vector(*w_dealii)); + // Then also copy the structure and values: + *cloned->get() = *w_dealii; + + // Finally set the cloned object in 'v': + v->content = cloned; return v; }