void
VectorBase::swap(VectorBase &v)
{
- const PetscErrorCode ierr = VecSwap(vector, v.vector);
- AssertThrow(ierr == 0, ExcPETScError(ierr));
+ std::swap(this->vector, v.vector);
+ std::swap(this->ghosted, v.ghosted);
+ std::swap(this->last_action, v.last_action);
+ // missing swap for IndexSet
+ IndexSet t(this->ghost_indices);
+ this->ghost_indices = v.ghost_indices;
+ v.ghost_indices = t;
}
Assert(v_one.ghost_elements() == v_one_from_vec.ghost_elements(),
ExcInternalError());
-
+ // Test swap
+ IndexSet local_active_2(numproc * 4);
+ local_active_2.add_range(myid * 4, myid * 4 + 4);
+ PETScWrappers::MPI::Vector vs1(local_active, MPI_COMM_WORLD);
+ PETScWrappers::MPI::Vector vs2(local_active_2,
+ local_relevant,
+ MPI_COMM_WORLD);
+ vs1.swap(vs2);
+ Assert(vs1.size() == numproc * 4, ExcInternalError());
+ Assert(vs2.size() == numproc * 2, ExcInternalError());
+ Assert(vs1.locally_owned_size() == 4, ExcInternalError());
+ Assert(vs2.locally_owned_size() == 2, ExcInternalError());
+ Assert(vs1.has_ghost_elements() == true, ExcInternalError());
+ Assert(vs2.has_ghost_elements() == false, ExcInternalError());
+ Assert(vs1.ghost_elements() == v_one.ghost_elements(), ExcInternalError());
+
+ // Now BlockVectors
PETScWrappers::MPI::BlockVector vb, v;
vb.reinit(2);
v.reinit(2);
ExcInternalError());
}
+ // Test swap
+ auto old_v_vb2 = vb2.petsc_vector();
+ auto old_v_vb = vb.petsc_vector();
+ vb.swap(vb2);
+ Assert(vb.petsc_vector() == old_v_vb2, ExcInternalError());
+ Assert(vb2.petsc_vector() == old_v_vb, ExcInternalError());
+
// done
if (myid == 0)
deallog << "OK" << std::endl;