*/
operator const Vec &() const;
+ /**
+ * Return a reference to the underlying PETSc type. It can be used to
+ * modify the underlying data, so use it only when you know what you
+ * are doing.
+ */
+ Vec &
+ petsc_vector();
+
/**
* Estimate for the memory consumption (not implemented for this class).
*/
ierr = VecGetSize(locally_stored_elements, &lsize);
AssertThrow(ierr == 0, ExcPETScError(ierr));
- PetscScalar *ptr;
- ierr = VecGetArray(locally_stored_elements, &ptr);
+ const PetscScalar *ptr;
+ ierr = VecGetArrayRead(locally_stored_elements, &ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
for (PetscInt i = 0; i < n_idx; ++i)
}
}
- ierr = VecRestoreArray(locally_stored_elements, &ptr);
+ ierr = VecRestoreArrayRead(locally_stored_elements, &ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
ierr = VecGhostRestoreLocalForm(vector, &locally_stored_elements);
PetscErrorCode ierr = VecGetOwnershipRange(vector, &begin, &end);
AssertThrow(ierr == 0, ExcPETScError(ierr));
- PetscScalar *ptr;
- ierr = VecGetArray(vector, &ptr);
+ const PetscScalar *ptr;
+ ierr = VecGetArrayRead(vector, &ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
for (PetscInt i = 0; i < n_idx; ++i)
*(values_begin + i) = *(ptr + index - begin);
}
- ierr = VecRestoreArray(vector, &ptr);
+ ierr = VecRestoreArrayRead(vector, &ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
}
}
ierr = VecGetSize(locally_stored_elements, &lsize);
AssertThrow(ierr == 0, ExcPETScError(ierr));
- PetscScalar *ptr;
- ierr = VecGetArray(locally_stored_elements, &ptr);
+ const PetscScalar *ptr;
+ ierr = VecGetArrayRead(locally_stored_elements, &ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
PetscScalar value;
value = *(ptr + ghostidx + end - begin);
}
- ierr = VecRestoreArray(locally_stored_elements, &ptr);
+ ierr = VecRestoreArrayRead(locally_stored_elements, &ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
ierr =
// get a representation of the vector and
// loop over all the elements
- PetscScalar * start_ptr;
- PetscErrorCode ierr = VecGetArray(vector, &start_ptr);
+ const PetscScalar *start_ptr;
+ PetscErrorCode ierr = VecGetArrayRead(vector, &start_ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
PetscScalar mean = 0;
// restore the representation of the
// vector
- ierr = VecRestoreArray(vector, &start_ptr);
+ ierr = VecRestoreArrayRead(vector, &start_ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
return mean;
{
// get a representation of the vector and
// loop over all the elements
- PetscScalar * start_ptr;
- PetscErrorCode ierr = VecGetArray(vector, &start_ptr);
+ const PetscScalar *start_ptr;
+ PetscErrorCode ierr = VecGetArrayRead(vector, &start_ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
real_type norm = 0;
// restore the representation of the
// vector
- ierr = VecRestoreArray(vector, &start_ptr);
+ ierr = VecRestoreArrayRead(vector, &start_ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
return norm;
{
// get a representation of the vector and
// loop over all the elements
- PetscScalar * start_ptr;
- PetscErrorCode ierr = VecGetArray(vector, &start_ptr);
+ const PetscScalar *start_ptr;
+ PetscErrorCode ierr = VecGetArrayRead(vector, &start_ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
const PetscScalar *ptr = start_ptr,
// restore the representation of the
// vector
- ierr = VecRestoreArray(vector, &start_ptr);
+ ierr = VecRestoreArrayRead(vector, &start_ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
return flag;
{
// get a representation of the vector and
// loop over all the elements
- PetscScalar * start_ptr;
- PetscErrorCode ierr = VecGetArray(vector, &start_ptr);
+ const PetscScalar *start_ptr;
+ PetscErrorCode ierr = VecGetArrayRead(vector, &start_ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
const PetscScalar *ptr = start_ptr,
// restore the representation of the
// vector
- ierr = VecRestoreArray(vector, &start_ptr);
+ ierr = VecRestoreArrayRead(vector, &start_ptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
return flag;
VectorBase::write_ascii(const PetscViewerFormat format)
{
// TODO[TH]:assert(is_compressed())
+ MPI_Comm comm = PetscObjectComm((PetscObject)vector);
// Set options
PetscErrorCode ierr =
- PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD, format);
+ PetscViewerSetFormat(PETSC_VIEWER_STDOUT_(comm), format);
AssertThrow(ierr == 0, ExcPETScError(ierr));
// Write to screen
- ierr = VecView(vector, PETSC_VIEWER_STDOUT_WORLD);
+ ierr = VecView(vector, PETSC_VIEWER_STDOUT_(comm));
AssertThrow(ierr == 0, ExcPETScError(ierr));
}
// get a representation of the vector and
// loop over all the elements
- PetscScalar * val;
- PetscErrorCode ierr = VecGetArray(vector, &val);
+ const PetscScalar *val;
+ PetscErrorCode ierr = VecGetArrayRead(vector, &val);
AssertThrow(ierr == 0, ExcPETScError(ierr));
// restore the representation of the
// vector
- ierr = VecRestoreArray(vector, &val);
+ ierr = VecRestoreArrayRead(vector, &val);
AssertThrow(ierr == 0, ExcPETScError(ierr));
AssertThrow(out.fail() == false, ExcIO());
}
-
VectorBase::operator const Vec &() const
{
return vector;
}
+ Vec &
+ VectorBase::petsc_vector()
+ {
+ return vector;
+ }
+
+
std::size_t
VectorBase::memory_consumption() const
{