17#ifdef DEAL_II_WITH_PETSC
27#ifdef DEAL_II_WITH_PETSC
37# ifdef DEAL_II_HAVE_CXX20
140 ierr = VecGhostUpdateBegin(
vector, INSERT_VALUES, SCATTER_FORWARD);
142 ierr = VecGhostUpdateEnd(
vector, INSERT_VALUES, SCATTER_FORWARD);
166 const bool omit_zeroing_entries)
170 const bool update_size =
182 const PetscErrorCode ierr = VecDestroy(&
vector);
190 if (omit_zeroing_entries ==
false)
207 if (!omit_zeroing_entries)
209 const PetscErrorCode ierr = VecSet(
vector, 0.0);
217 omit_zeroing_entries);
230 const PetscErrorCode ierr = VecDestroy(&
vector);
247 const PetscErrorCode ierr = VecDestroy(&
vector);
257 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
258 const bool make_ghosted)
262 Assert(partitioner->ghost_indices_initialized(),
263 ExcMessage(
"You asked to create a ghosted vector, but the "
264 "partitioner does not provide ghost indices."));
266 this->
reinit(partitioner->locally_owned_range(),
267 partitioner->ghost_indices(),
268 partitioner->get_mpi_communicator());
272 this->
reinit(partitioner->locally_owned_range(),
273 partitioner->get_mpi_communicator());
286 const PetscErrorCode ierr = VecCreateMPI(communicator,
311 std::vector<PetscInt> petsc_ghost_indices(ghostnodes.
n_elements());
312 for (
const auto &index : ghostnodes)
314 petsc_ghost_indices[i] =
static_cast<PetscInt
>(index);
318 PetscErrorCode ierr = VecCreateGhost(communicator,
321 petsc_ghost_indices.size(),
322 petsc_ghost_indices.data(),
340 ierr = VecGhostGetLocalForm(
vector, &l);
344 ierr = VecGetSize(l, &lsize);
347 ierr = VecGhostRestoreLocalForm(
vector, &l);
362 const unsigned int precision,
363 const bool scientific,
364 const bool across)
const
370 const PetscScalar *val;
371 PetscInt nlocal, istart, iend;
373 PetscErrorCode ierr = VecGetArrayRead(
vector, &val);
376 ierr = VecGetLocalSize(
vector, &nlocal);
379 ierr = VecGetOwnershipRange(
vector, &istart, &iend);
383 std::ios::fmtflags old_flags = out.flags();
384 unsigned int old_precision = out.precision(precision);
386 out.precision(precision);
388 out.setf(std::ios::scientific, std::ios::floatfield);
390 out.setf(std::ios::fixed, std::ios::floatfield);
398 for (
unsigned int i = 0;
402 const int mpi_ierr = MPI_Barrier(communicator);
409 out <<
"[Proc" << i <<
" " << istart <<
"-" << iend - 1 <<
"]"
411 for (PetscInt i = 0; i < nlocal; ++i)
412 out << val[i] <<
' ';
416 out <<
"[Proc " << i <<
" " << istart <<
"-" << iend - 1
418 for (PetscInt i = 0; i < nlocal; ++i)
419 out << val[i] << std::endl;
425 out.flags(old_flags);
426 out.precision(old_precision);
430 ierr = VecRestoreArrayRead(
vector, &val);
bool is_ascending_and_one_to_one(const MPI_Comm communicator) const
size_type n_elements() const
void subtract_set(const IndexSet &other)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
virtual void clear() override
Vector & operator=(const Vector &v)
virtual void create_vector(const MPI_Comm comm, const size_type n, const size_type locally_owned_size)
void reinit(const MPI_Comm communicator, const size_type N, const size_type locally_owned_size, const bool omit_zeroing_entries=false)
VectorOperation::values last_action
IndexSet locally_owned_elements() const
MPI_Comm get_mpi_communicator() const
bool has_ghost_elements() const
void acquire_ghost_form()
size_type locally_owned_size() const
void release_ghost_form()
size_type size() const override
#define DEAL_II_NAMESPACE_OPEN
constexpr bool running_in_debug_mode()
#define DEAL_II_NAMESPACE_CLOSE
#define AssertThrowIntegerConversion(index1, index2)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
types::global_dof_index locally_owned_size
T logical_or(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)