]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Deal with a circular dependency problem. 15113/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 20 Apr 2023 01:00:10 +0000 (19:00 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 20 Apr 2023 01:00:10 +0000 (19:00 -0600)
We can't ask a default-created vector for its MPI communicator
if we only later initialize it.

include/deal.II/sundials/n_vector.templates.h

index 696fc8c64bf5ecb5617b605b6140abe7d4b44de4..2918ee4ce410669007c8d8d4bddcb45ed5a2f736 100644 (file)
@@ -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 <typename VectorType>
-    NVectorContent<VectorType>::NVectorContent()
+    NVectorContent<VectorType>::NVectorContent(const MPI_Comm comm)
       : vector(typename VectorMemory<VectorType>::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<VectorType>();
         auto *w_dealii = unwrap_nvector_const<VectorType>(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<VectorType>(
+          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;
       }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.