20 #ifdef DEAL_II_WITH_PETSC
35 # ifdef DEAL_II_HAVE_CXX20
36 static_assert(concepts::is_vector_space_vector<Vector>);
60 const MPI_Comm communicator)
135 ierr = VecGhostUpdateBegin(
vector, INSERT_VALUES, SCATTER_FORWARD);
137 ierr = VecGhostUpdateEnd(
vector, INSERT_VALUES, SCATTER_FORWARD);
159 const bool omit_zeroing_entries)
167 MPI_Allreduce(&k, &k_global, 1, MPI_INT, MPI_LOR, communicator);
182 const PetscErrorCode ierr = VecDestroy(&
vector);
190 if (omit_zeroing_entries ==
false)
204 if (!omit_zeroing_entries)
206 const PetscErrorCode ierr = VecSet(
vector, 0.0);
214 omit_zeroing_entries);
224 const PetscErrorCode ierr = VecDestroy(&
vector);
238 const PetscErrorCode ierr = VecDestroy(&
vector);
248 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
249 const bool make_ghosted)
253 Assert(partitioner->ghost_indices_initialized(),
254 ExcMessage(
"You asked to create a ghosted vector, but the "
255 "partitioner does not provide ghost indices."));
257 this->
reinit(partitioner->locally_owned_range(),
258 partitioner->ghost_indices(),
259 partitioner->get_mpi_communicator());
263 this->
reinit(partitioner->locally_owned_range(),
264 partitioner->get_mpi_communicator());
278 const PetscErrorCode ierr = VecCreateMPI(communicator,
302 const PetscInt *ptr =
303 (ghostindices.size() > 0 ?
304 reinterpret_cast<const PetscInt *
>(ghostindices.data()) :
307 PetscErrorCode ierr = VecCreateGhost(communicator,
329 ierr = VecGhostGetLocalForm(
vector, &
l);
333 ierr = VecGetSize(
l, &lsize);
336 ierr = VecGhostRestoreLocalForm(
vector, &
l);
354 unsigned int num_nonzero =
356 return num_nonzero == 0;
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)
std::vector< size_type > get_index_vector() const
types::global_dof_index size_type
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)
VectorOperation::values last_action
IndexSet locally_owned_elements() const
MPI_Comm get_mpi_communicator() const
bool has_ghost_elements() const
size_type locally_owned_size() const
size_type size() const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotImplemented()
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
VectorType::value_type * begin(VectorType &V)
VectorType::value_type * end(VectorType &V)
T sum(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)