libMesh
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
libMesh::PetscVector< T > Class Template Referencefinal

This class provides a nice interface to PETSc's Vec object. More...

#include <petsc_vector.h>

Inheritance diagram for libMesh::PetscVector< T >:
[legend]

Public Member Functions

 PetscVector (const Parallel::Communicator &comm_in, const ParallelType type=AUTOMATIC)
 Dummy-Constructor. More...
 
 PetscVector (const Parallel::Communicator &comm_in, const numeric_index_type n, const ParallelType type=AUTOMATIC)
 Constructor. More...
 
 PetscVector (const Parallel::Communicator &comm_in, const numeric_index_type n, const numeric_index_type n_local, const ParallelType type=AUTOMATIC)
 Constructor. More...
 
 PetscVector (const Parallel::Communicator &comm_in, const numeric_index_type N, const numeric_index_type n_local, const std::vector< numeric_index_type > &ghost, const ParallelType type=AUTOMATIC)
 Constructor. More...
 
 PetscVector (Vec v, const Parallel::Communicator &comm_in)
 Constructor. More...
 
PetscVector< T > & operator= (const PetscVector< T > &v)
 Copy assignment operator. More...
 
 PetscVector (PetscVector &&)=delete
 This class manages a C-style struct (Vec) manually, so we don't want to allow any automatic copy/move functions to be generated, and we can't default the destructor. More...
 
 PetscVector (const PetscVector &)=delete
 
PetscVectoroperator= (PetscVector &&)=delete
 
virtual ~PetscVector ()
 
virtual void close () override
 Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across processors. More...
 
virtual void clear () override
 Restores the NumericVector<T> to a pristine state. More...
 
virtual void zero () override
 Set all entries to zero. More...
 
virtual std::unique_ptr< NumericVector< T > > zero_clone () const override
 
virtual std::unique_ptr< NumericVector< T > > clone () const override
 
virtual void init (const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
 Change the dimension of the vector to n. More...
 
virtual void init (const numeric_index_type N, const bool fast=false, const ParallelType type=AUTOMATIC) override
 Call init() with n_local = N. More...
 
virtual void init (const numeric_index_type N, const numeric_index_type n_local, const std::vector< numeric_index_type > &ghost, const bool fast=false, const ParallelType=AUTOMATIC) override
 Create a vector that holds tha local indices plus those specified in the ghost argument. More...
 
virtual void init (const NumericVector< T > &other, const bool fast=false) override
 Creates a vector that has the same dimension and storage type as other, including ghost dofs. More...
 
virtual NumericVector< T > & operator= (const T s) override
 Sets all entries of the vector to the value s. More...
 
virtual NumericVector< T > & operator= (const NumericVector< T > &v) override
 This looks like a copy assignment operator, but note that, unlike normal copy assignment operators, it is pure virtual. More...
 
virtual NumericVector< T > & operator= (const std::vector< T > &v) override
 Sets (*this)(i) = v(i) for each entry of the vector. More...
 
virtual Real min () const override
 
virtual Real max () const override
 
virtual T sum () const override
 
virtual Real l1_norm () const override
 
virtual Real l2_norm () const override
 
virtual Real linfty_norm () const override
 
virtual numeric_index_type size () const override
 
virtual numeric_index_type local_size () const override
 
virtual numeric_index_type first_local_index () const override
 
virtual numeric_index_type last_local_index () const override
 
numeric_index_type map_global_to_local_index (const numeric_index_type i) const
 
virtual T operator() (const numeric_index_type i) const override
 
virtual void get (const std::vector< numeric_index_type > &index, T *values) const override
 Access multiple components at once. More...
 
PetscScalar * get_array ()
 Get read/write access to the raw PETSc Vector data array. More...
 
const PetscScalar * get_array_read () const
 Get read only access to the raw PETSc Vector data array. More...
 
void restore_array ()
 Restore the data array. More...
 
virtual NumericVector< T > & operator+= (const NumericVector< T > &v) override
 Adds v to *this, \( \vec{u} \leftarrow \vec{u} + \vec{v} \). More...
 
virtual NumericVector< T > & operator-= (const NumericVector< T > &v) override
 Subtracts v from *this, \( \vec{u} \leftarrow \vec{u} - \vec{v} \). More...
 
virtual void reciprocal () override
 Computes the component-wise reciprocal, \( u_i \leftarrow \frac{1}{u_i} \, \forall i\). More...
 
virtual void conjugate () override
 Negates the imaginary component of each entry in the vector. More...
 
virtual void set (const numeric_index_type i, const T value) override
 Sets v(i) = value. More...
 
virtual void add (const numeric_index_type i, const T value) override
 Adds value to each entry of the vector. More...
 
virtual void add (const T s) override
 Adds s to each entry of the vector, \( u_i \leftarrow u_i + s \). More...
 
virtual void add (const NumericVector< T > &v) override
 Adds v to this, \( \vec{u} \leftarrow \vec{u} + \vec{v} \). More...
 
virtual void add (const T a, const NumericVector< T > &v) override
 Vector addition with a scalar multiple, \( \vec{u} \leftarrow \vec{u} + a\vec{v} \). More...
 
virtual void add_vector (const T *v, const std::vector< numeric_index_type > &dof_indices) override
 Computes \( \vec{u} \leftarrow \vec{u} + \vec{v} \), where v is a pointer and each dof_indices[i] specifies where to add value v[i]. More...
 
virtual void add_vector (const NumericVector< T > &v, const SparseMatrix< T > &A) override
 Computes \( \vec{u} \leftarrow \vec{u} + A \vec{v} \), i.e. More...
 
virtual void add_vector_transpose (const NumericVector< T > &v, const SparseMatrix< T > &A) override
 Computes \( \vec{u} \leftarrow \vec{u} + A^T \vec{v} \), i.e. More...
 
void add_vector_conjugate_transpose (const NumericVector< T > &v, const SparseMatrix< T > &A)
 \( U \leftarrow U + A^H v \). More...
 
virtual void insert (const T *v, const std::vector< numeric_index_type > &dof_indices) override
 Inserts the entries of v in *this at the locations specified by v. More...
 
virtual void scale (const T factor) override
 Scale each element of the vector by the given factor. More...
 
virtual NumericVector< T > & operator*= (const NumericVector< T > &v) override
 Computes the component-wise multiplication of this vector's entries by another's, \( u_i \leftarrow u_i v_i \, \forall i\). More...
 
virtual NumericVector< T > & operator/= (const NumericVector< T > &v) override
 Computes the component-wise division of this vector's entries by another's, \( u_i \leftarrow \frac{u_i}{v_i} \, \forall i\). More...
 
virtual void abs () override
 Sets \( u_i \leftarrow |u_i| \) for each entry in the vector. More...
 
virtual T dot (const NumericVector< T > &v) const override
 
indefinite_dot (const NumericVector< T > &v) const
 
virtual void localize (std::vector< T > &v_local) const override
 Creates a copy of the global vector in the local vector v_local. More...
 
virtual void localize (NumericVector< T > &v_local) const override
 Same, but fills a NumericVector<T> instead of a std::vector. More...
 
virtual void localize (NumericVector< T > &v_local, const std::vector< numeric_index_type > &send_list) const override
 Creates a local vector v_local containing only information relevant to this processor, as defined by the send_list. More...
 
virtual void localize (std::vector< T > &v_local, const std::vector< numeric_index_type > &indices) const override
 Fill in the local std::vector "v_local" with the global indices given in "indices". More...
 
virtual void localize (const numeric_index_type first_local_idx, const numeric_index_type last_local_idx, const std::vector< numeric_index_type > &send_list) override
 Updates a local vector with selected values from neighboring processors, as defined by send_list. More...
 
virtual void localize_to_one (std::vector< T > &v_local, const processor_id_type proc_id=0) const override
 Creates a local copy of the global vector in v_local only on processor proc_id. More...
 
virtual void pointwise_mult (const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
 Computes \( u_i \leftarrow u_i v_i \) (summation not implied) i.e. More...
 
virtual void print_matlab (const std::string &name="") const override
 Print the contents of the vector in Matlab's sparse matrix format. More...
 
virtual void create_subvector (NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows) const override
 Fills in subvector from this vector using the indices in rows. More...
 
virtual void swap (NumericVector< T > &v) override
 Swaps the contents of this with v. More...
 
Vec vec ()
 
Vec vec () const
 
template<>
void localize_to_one (std::vector< Real > &v_local, const processor_id_type timpi_mpi_var(pid)) const
 
template<>
void localize_to_one (std::vector< Complex > &v_local, const processor_id_type pid) const
 
virtual bool initialized () const
 
ParallelType type () const
 
ParallelTypetype ()
 
virtual bool closed () const
 
virtual Real subset_l1_norm (const std::set< numeric_index_type > &indices) const
 
virtual Real subset_l2_norm (const std::set< numeric_index_type > &indices) const
 
virtual Real subset_linfty_norm (const std::set< numeric_index_type > &indices) const
 
virtual T el (const numeric_index_type i) const
 
void get (const std::vector< numeric_index_type > &index, std::vector< T > &values) const
 Access multiple components at once. More...
 
NumericVector< T > & operator*= (const T a)
 Scales the vector by a, \( \vec{u} \leftarrow a\vec{u} \). More...
 
NumericVector< T > & operator/= (const T a)
 Scales the vector by 1/a, \( \vec{u} \leftarrow \frac{1}{a}\vec{u} \). More...
 
void add_vector (const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Computes \( \vec{u} \leftarrow \vec{u} + \vec{v} \), where v is a std::vector and each dof_indices[i] specifies where to add value v[i]. More...
 
virtual void add_vector (const NumericVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Computes \( \vec{u} \leftarrow \vec{u} + \vec{v} \), where v is a NumericVector and each dof_indices[i] specifies where to add value v(i). More...
 
void add_vector (const DenseVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Computes \( \vec{u} \leftarrow \vec{u} + \vec{v} \), where v is a DenseVector and each dof_indices[i] specifies where to add value v(i). More...
 
void add_vector (const NumericVector< T > &v, const ShellMatrix< T > &A)
 Computes \( \vec{u} \leftarrow \vec{u} + A \vec{v} \), i.e. More...
 
void insert (const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
virtual void insert (const NumericVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
void insert (const DenseVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
void insert (const DenseSubVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
virtual int compare (const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
 
virtual int local_relative_compare (const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
 
virtual int global_relative_compare (const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
 
virtual void print (std::ostream &os=libMesh::out) const
 Prints the local contents of the vector, by default to libMesh::out. More...
 
template<>
void print (std::ostream &os) const
 
virtual void print_global (std::ostream &os=libMesh::out) const
 Prints the global contents of the vector, by default to libMesh::out. More...
 
template<>
void print_global (std::ostream &os) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static std::unique_ptr< NumericVector< T > > build (const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
 Builds a NumericVector on the processors in communicator comm using the linear solver package specified by solver_package. More...
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Protected Attributes

bool _is_closed
 Flag which tracks whether the vector's values are consistent on all processors after insertion or addition of values has occurred on some or all processors. More...
 
bool _is_initialized
 true once init() has been called. More...
 
ParallelType _type
 Type of vector. More...
 
const Parallel::Communicator & _communicator
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int_n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called. More...
 

Private Types

typedef std::unordered_map< numeric_index_type, numeric_index_typeGlobalToLocalMap
 Type for map that maps global to local ghost cells. More...
 

Private Member Functions

void _get_array (bool read_only) const
 Queries the array (and the local form if the vector is ghosted) from PETSc. More...
 
void _restore_array () const
 Restores the array (and the local form if the vector is ghosted) to PETSc. More...
 

Private Attributes

Vec _vec
 Actual PETSc vector datatype to hold vector entries. More...
 
std::atomic< bool > _array_is_present
 If true, the actual PETSc array of the values of the vector is currently accessible. More...
 
bool _array_is_present
 
numeric_index_type _first
 First local index. More...
 
numeric_index_type _last
 Last local index. More...
 
numeric_index_type _local_size
 Size of the local values from _get_array() More...
 
Vec _local_form
 PETSc vector datatype to hold the local form of a ghosted vector. More...
 
const PetscScalar * _read_only_values
 Pointer to the actual PETSc array of the values of the vector. More...
 
PetscScalar * _values
 Pointer to the actual PETSc array of the values of the vector. More...
 
std::mutex _petsc_vector_mutex
 Mutex for _get_array and _restore_array. More...
 
Threads::spin_mutex _petsc_vector_mutex
 
GlobalToLocalMap _global_to_local_map
 Map that maps global to local ghost cells (will be empty if not in ghost cell mode). More...
 
bool _destroy_vec_on_exit
 This boolean value should only be set to false for the constructor which takes a PETSc Vec object. More...
 
bool _values_manually_retrieved
 Whether or not the data array has been manually retrieved using get_array() or get_array_read() More...
 
bool _values_read_only
 Whether or not the data array is for read only access. More...
 

Detailed Description

template<typename T>
class libMesh::PetscVector< T >

This class provides a nice interface to PETSc's Vec object.

All overridden virtual functions are documented in numeric_vector.h.

Author
Benjamin S. Kirk
Date
2002

NumericVector interface to PETSc Vec.

Definition at line 72 of file petsc_vector.h.

Member Typedef Documentation

◆ Counts

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 117 of file reference_counter.h.

◆ GlobalToLocalMap

template<typename T>
typedef std::unordered_map<numeric_index_type,numeric_index_type> libMesh::PetscVector< T >::GlobalToLocalMap
private

Type for map that maps global to local ghost cells.

Definition at line 433 of file petsc_vector.h.

Constructor & Destructor Documentation

◆ PetscVector() [1/7]

template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator &  comm_in,
const ParallelType  type = AUTOMATIC 
)
inlineexplicit

Dummy-Constructor.

Dimension=0

Definition at line 466 of file petsc_vector.h.

466  :
467  NumericVector<T>(comm_in, ptype),
468  _array_is_present(false),
469  _first(0),
470  _last(0),
471  _local_form(nullptr),
472  _values(nullptr),
474  _destroy_vec_on_exit(true),
476  _values_read_only(false)
477 {
478  this->_type = ptype;
479 }

◆ PetscVector() [2/7]

template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator &  comm_in,
const numeric_index_type  n,
const ParallelType  type = AUTOMATIC 
)
inlineexplicit

Constructor.

Set dimension to n and initialize all elements with zero.

Definition at line 485 of file petsc_vector.h.

487  :
488  NumericVector<T>(comm_in, ptype),
489  _array_is_present(false),
490  _local_form(nullptr),
491  _values(nullptr),
493  _destroy_vec_on_exit(true),
495  _values_read_only(false)
496 {
497  this->init(n, n, false, ptype);
498 }

◆ PetscVector() [3/7]

template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator &  comm_in,
const numeric_index_type  n,
const numeric_index_type  n_local,
const ParallelType  type = AUTOMATIC 
)
inline

Constructor.

Set local dimension to n_local, the global dimension to n, and initialize all elements with zero.

Definition at line 504 of file petsc_vector.h.

507  :
508  NumericVector<T>(comm_in, ptype),
509  _array_is_present(false),
510  _local_form(nullptr),
511  _values(nullptr),
513  _destroy_vec_on_exit(true),
515  _values_read_only(false)
516 {
517  this->init(n, n_local, false, ptype);
518 }

◆ PetscVector() [4/7]

template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator &  comm_in,
const numeric_index_type  N,
const numeric_index_type  n_local,
const std::vector< numeric_index_type > &  ghost,
const ParallelType  type = AUTOMATIC 
)
inline

Constructor.

Set local dimension to n_local, the global dimension to n, but additionally reserve memory for the indices specified by the ghost argument.

Definition at line 524 of file petsc_vector.h.

528  :
529  NumericVector<T>(comm_in, ptype),
530  _array_is_present(false),
531  _local_form(nullptr),
532  _values(nullptr),
534  _destroy_vec_on_exit(true),
536  _values_read_only(false)
537 {
538  this->init(n, n_local, ghost, false, ptype);
539 }

◆ PetscVector() [5/7]

template<typename T >
libMesh::PetscVector< T >::PetscVector ( Vec  v,
const Parallel::Communicator &  comm_in 
)
inline

Constructor.

Creates a PetscVector assuming you already have a valid PETSc Vec object. In this case, v is NOT destroyed by the PetscVector constructor when this object goes out of scope. This allows ownership of v to remain with the original creator, and to simply provide additional functionality with the PetscVector.

Definition at line 547 of file petsc_vector.h.

548  :
549  NumericVector<T>(comm_in, AUTOMATIC),
550  _array_is_present(false),
551  _local_form(nullptr),
552  _values(nullptr),
554  _destroy_vec_on_exit(false),
556  _values_read_only(false)
557 {
558  this->_vec = v;
559  this->_is_closed = true;
560  this->_is_initialized = true;
561 
562  /* We need to ask PETSc about the (local to global) ghost value
563  mapping and create the inverse mapping out of it. */
564  PetscErrorCode ierr=0;
565  PetscInt petsc_local_size=0;
566  ierr = VecGetLocalSize(_vec, &petsc_local_size);
567  LIBMESH_CHKERR(ierr);
568 
569  // Get the vector type from PETSc.
570  // As of PETSc 3.0.0, the VecType #define lost its const-ness, so we
571  // need to have it in the code
572 #if PETSC_VERSION_LESS_THAN(3,0,0) || !PETSC_VERSION_LESS_THAN(3,4,0)
573  // Pre-3.0 and petsc-dev (as of October 2012) use non-const versions
574  VecType ptype;
575 #else
576  const VecType ptype;
577 #endif
578  ierr = VecGetType(_vec, &ptype);
579  LIBMESH_CHKERR(ierr);
580 
581  if ((std::strcmp(ptype,VECSHARED) == 0) || (std::strcmp(ptype,VECMPI) == 0))
582  {
583 #if PETSC_RELEASE_LESS_THAN(3,1,1)
584  ISLocalToGlobalMapping mapping = _vec->mapping;
585 #else
586  ISLocalToGlobalMapping mapping;
587  ierr = VecGetLocalToGlobalMapping(_vec, &mapping);
588  LIBMESH_CHKERR(ierr);
589 #endif
590 
591  // If is a sparsely stored vector, set up our new mapping
592  if (mapping)
593  {
594  const numeric_index_type my_local_size = static_cast<numeric_index_type>(petsc_local_size);
595  const numeric_index_type ghost_begin = static_cast<numeric_index_type>(petsc_local_size);
596 #if PETSC_RELEASE_LESS_THAN(3,4,0)
597  const numeric_index_type ghost_end = static_cast<numeric_index_type>(mapping->n);
598 #else
599  PetscInt n;
600  ierr = ISLocalToGlobalMappingGetSize(mapping, &n);
601  LIBMESH_CHKERR(ierr);
602  const numeric_index_type ghost_end = static_cast<numeric_index_type>(n);
603 #endif
604 #if PETSC_RELEASE_LESS_THAN(3,1,1)
605  const PetscInt * indices = mapping->indices;
606 #else
607  const PetscInt * indices;
608  ierr = ISLocalToGlobalMappingGetIndices(mapping,&indices);
609  LIBMESH_CHKERR(ierr);
610 #endif
611  for (numeric_index_type i=ghost_begin; i<ghost_end; i++)
612  _global_to_local_map[indices[i]] = i-my_local_size;
613  this->_type = GHOSTED;
614 #if !PETSC_RELEASE_LESS_THAN(3,1,1)
615  ierr = ISLocalToGlobalMappingRestoreIndices(mapping, &indices);
616  LIBMESH_CHKERR(ierr);
617 #endif
618  }
619  else
620  this->_type = PARALLEL;
621  }
622  else
623  this->_type = SERIAL;
624 }

◆ PetscVector() [6/7]

template<typename T>
libMesh::PetscVector< T >::PetscVector ( PetscVector< T > &&  )
delete

This class manages a C-style struct (Vec) manually, so we don't want to allow any automatic copy/move functions to be generated, and we can't default the destructor.

◆ PetscVector() [7/7]

template<typename T>
libMesh::PetscVector< T >::PetscVector ( const PetscVector< T > &  )
delete

◆ ~PetscVector()

template<typename T >
libMesh::PetscVector< T >::~PetscVector ( )
inlinevirtual

Definition at line 631 of file petsc_vector.h.

632 {
633  this->clear ();
634 }

Member Function Documentation

◆ _get_array()

template<typename T >
void libMesh::PetscVector< T >::_get_array ( bool  read_only) const
private

Queries the array (and the local form if the vector is ghosted) from PETSc.

Parameters
read_onlyWhether or not a read only copy of the raw data

Definition at line 1374 of file petsc_vector.C.

1375 {
1376  libmesh_assert (this->initialized());
1377 
1378 #ifdef LIBMESH_HAVE_CXX11_THREAD
1379  std::atomic_thread_fence(std::memory_order_acquire);
1380 #else
1381  Threads::spin_mutex::scoped_lock lock(_petsc_vector_mutex);
1382 #endif
1383 
1384  // If the values have already been retrieved and we're currently
1385  // trying to get a non-read only view (ie read/write) and the
1386  // values are currently read only... then we need to restore
1387  // the array first... and then retrieve it again.
1388  if (_array_is_present && !read_only && _values_read_only)
1389  _restore_array();
1390 
1391  // If we already have a read/write array - and we're trying
1392  // to get a read only array - let's just use the read write
1393  if (_array_is_present && read_only && !_values_read_only)
1395 
1396  if (!_array_is_present)
1397  {
1398 #ifdef LIBMESH_HAVE_CXX11_THREAD
1399  std::lock_guard<std::mutex> lock(_petsc_vector_mutex);
1400 #endif
1401  if (!_array_is_present)
1402  {
1403  PetscErrorCode ierr=0;
1404  if (this->type() != GHOSTED)
1405  {
1406 #if PETSC_VERSION_LESS_THAN(3,2,0)
1407  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1408  // have an older PETSc than that, we'll do an ugly
1409  // const_cast and call VecGetArray() instead.
1410  ierr = VecGetArray(_vec, const_cast<PetscScalar **>(&_values));
1411  _values_read_only = false;
1412 #else
1413  if (read_only)
1414  {
1415  ierr = VecGetArrayRead(_vec, &_read_only_values);
1416  _values_read_only = true;
1417  }
1418  else
1419  {
1420  ierr = VecGetArray(_vec, &_values);
1421  _values_read_only = false;
1422  }
1423 #endif
1424  LIBMESH_CHKERR(ierr);
1425  _local_size = this->local_size();
1426  }
1427  else
1428  {
1429  ierr = VecGhostGetLocalForm (_vec,&_local_form);
1430  LIBMESH_CHKERR(ierr);
1431 
1432 #if PETSC_VERSION_LESS_THAN(3,2,0)
1433  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1434  // have an older PETSc than that, we'll do an ugly
1435  // const_cast and call VecGetArray() instead.
1436  ierr = VecGetArray(_local_form, const_cast<PetscScalar **>(&_values));
1437  _values_read_only = false;
1438 #else
1439  if (read_only)
1440  {
1441  ierr = VecGetArrayRead(_local_form, &_read_only_values);
1442  _values_read_only = true;
1443  }
1444  else
1445  {
1446  ierr = VecGetArray(_local_form, &_values);
1447  _values_read_only = false;
1448  }
1449 #endif
1450  LIBMESH_CHKERR(ierr);
1451 
1452  PetscInt my_local_size = 0;
1453  ierr = VecGetLocalSize(_local_form, &my_local_size);
1454  LIBMESH_CHKERR(ierr);
1455  _local_size = static_cast<numeric_index_type>(my_local_size);
1456  }
1457 
1458  { // cache ownership range
1459  PetscInt petsc_first=0, petsc_last=0;
1460  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1461  LIBMESH_CHKERR(ierr);
1462  _first = static_cast<numeric_index_type>(petsc_first);
1463  _last = static_cast<numeric_index_type>(petsc_last);
1464  }
1465 #ifdef LIBMESH_HAVE_CXX11_THREAD
1466  std::atomic_thread_fence(std::memory_order_release);
1467  _array_is_present.store(true, std::memory_order_relaxed);
1468 #else
1469  _array_is_present = true;
1470 #endif
1471  }
1472  }
1473 }

◆ _restore_array()

template<typename T >
void libMesh::PetscVector< T >::_restore_array ( ) const
private

Restores the array (and the local form if the vector is ghosted) to PETSc.

Definition at line 1478 of file petsc_vector.C.

1479 {
1481  libmesh_error_msg("PetscVector values were manually retrieved but are being automatically restored!");
1482 
1483 #ifdef LIBMESH_HAVE_CXX11_THREAD
1484  std::atomic_thread_fence(std::memory_order_acquire);
1485 #else
1486  Threads::spin_mutex::scoped_lock lock(_petsc_vector_mutex);
1487 #endif
1488 
1489  libmesh_assert (this->initialized());
1490  if (_array_is_present)
1491  {
1492 #ifdef LIBMESH_HAVE_CXX11_THREAD
1493  std::lock_guard<std::mutex> lock(_petsc_vector_mutex);
1494 #endif
1495 
1496  if (_array_is_present)
1497  {
1498  PetscErrorCode ierr=0;
1499  if (this->type() != GHOSTED)
1500  {
1501 #if PETSC_VERSION_LESS_THAN(3,2,0)
1502  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1503  // have an older PETSc than that, we'll do an ugly
1504  // const_cast and call VecRestoreArray() instead.
1505  ierr = VecRestoreArray (_vec, const_cast<PetscScalar **>(&_values));
1506 #else
1507  if (_values_read_only)
1508  ierr = VecRestoreArrayRead (_vec, &_read_only_values);
1509  else
1510  ierr = VecRestoreArray (_vec, &_values);
1511 #endif
1512 
1513  LIBMESH_CHKERR(ierr);
1514  _values = nullptr;
1515  }
1516  else
1517  {
1518 #if PETSC_VERSION_LESS_THAN(3,2,0)
1519  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1520  // have an older PETSc than that, we'll do an ugly
1521  // const_cast and call VecRestoreArray() instead.
1522  ierr = VecRestoreArray (_local_form, const_cast<PetscScalar **>(&_values));
1523 #else
1524  if (_values_read_only)
1525  ierr = VecRestoreArrayRead (_local_form, &_read_only_values);
1526  else
1527  ierr = VecRestoreArray (_local_form, &_values);
1528 #endif
1529  LIBMESH_CHKERR(ierr);
1530  _values = nullptr;
1531  ierr = VecGhostRestoreLocalForm (_vec,&_local_form);
1532  LIBMESH_CHKERR(ierr);
1533  _local_form = nullptr;
1534  _local_size = 0;
1535  }
1536 #ifdef LIBMESH_HAVE_CXX11_THREAD
1537  std::atomic_thread_fence(std::memory_order_release);
1538  _array_is_present.store(false, std::memory_order_relaxed);
1539 #else
1540  _array_is_present = false;
1541 #endif
1542  }
1543  }
1544 }

Referenced by libMesh::PetscVector< libMesh::Number >::add(), libMesh::PetscVector< libMesh::Number >::create_subvector(), libMesh::PetscVector< libMesh::Number >::init(), and libMesh::PetscVector< libMesh::Number >::operator=().

◆ abs()

template<typename T >
void libMesh::PetscVector< T >::abs ( )
overridevirtual

Sets \( u_i \leftarrow |u_i| \) for each entry in the vector.

Implements libMesh::NumericVector< T >.

Definition at line 460 of file petsc_vector.C.

461 {
462  this->_restore_array();
463 
464  PetscErrorCode ierr = 0;
465 
466  if (this->type() != GHOSTED)
467  {
468  ierr = VecAbs(_vec);
469  LIBMESH_CHKERR(ierr);
470  }
471  else
472  {
473  Vec loc_vec;
474  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
475  LIBMESH_CHKERR(ierr);
476 
477  ierr = VecAbs(loc_vec);
478  LIBMESH_CHKERR(ierr);
479 
480  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
481  LIBMESH_CHKERR(ierr);
482  }
483 }

◆ add() [1/4]

template<typename T>
void libMesh::PetscVector< T >::add ( const numeric_index_type  i,
const T  value 
)
overridevirtual

Adds value to each entry of the vector.

Implements libMesh::NumericVector< T >.

Definition at line 187 of file petsc_vector.C.

188 {
189  this->_restore_array();
190  libmesh_assert_less (i, size());
191 
192  PetscErrorCode ierr=0;
193  PetscInt i_val = static_cast<PetscInt>(i);
194  PetscScalar petsc_value = PS(value);
195 
196  ierr = VecSetValues (_vec, 1, &i_val, &petsc_value, ADD_VALUES);
197  LIBMESH_CHKERR(ierr);
198 
199  this->_is_closed = false;
200 }

◆ add() [2/4]

template<typename T>
void libMesh::PetscVector< T >::add ( const NumericVector< T > &  v)
overridevirtual

Adds v to this, \( \vec{u} \leftarrow \vec{u} + \vec{v} \).

Equivalent to calling operator+=().

Implements libMesh::NumericVector< T >.

Definition at line 339 of file petsc_vector.C.

340 {
341  this->add (1., v);
342 }

◆ add() [3/4]

template<typename T>
void libMesh::PetscVector< T >::add ( const T  a,
const NumericVector< T > &  v 
)
overridevirtual

Vector addition with a scalar multiple, \( \vec{u} \leftarrow \vec{u} + a\vec{v} \).

Equivalent to calling operator+=().

Implements libMesh::NumericVector< T >.

Definition at line 347 of file petsc_vector.C.

348 {
349  this->_restore_array();
350 
351  PetscErrorCode ierr = 0;
352  PetscScalar a = PS(a_in);
353 
354  // Make sure the NumericVector passed in is really a PetscVector
355  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
356  v->_restore_array();
357 
358  libmesh_assert_equal_to (this->size(), v->size());
359 
360  if (this->type() != GHOSTED)
361  {
362  ierr = VecAXPY(_vec, a, v->_vec);
363  LIBMESH_CHKERR(ierr);
364  }
365  else
366  {
367  Vec loc_vec;
368  Vec v_loc_vec;
369  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
370  LIBMESH_CHKERR(ierr);
371  ierr = VecGhostGetLocalForm (v->_vec,&v_loc_vec);
372  LIBMESH_CHKERR(ierr);
373 
374  ierr = VecAXPY(loc_vec, a, v_loc_vec);
375  LIBMESH_CHKERR(ierr);
376 
377  ierr = VecGhostRestoreLocalForm (v->_vec,&v_loc_vec);
378  LIBMESH_CHKERR(ierr);
379  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
380  LIBMESH_CHKERR(ierr);
381  }
382 }

◆ add() [4/4]

template<typename T>
void libMesh::PetscVector< T >::add ( const T  s)
overridevirtual

Adds s to each entry of the vector, \( u_i \leftarrow u_i + s \).

Implements libMesh::NumericVector< T >.

Definition at line 328 of file petsc_vector.C.

329 {
330  this->_get_array(false);
331 
332  for (numeric_index_type i=0; i<_local_size; i++)
333  _values[i] += PetscScalar(v_in);
334 }

◆ add_vector() [1/6]

template<typename T>
void libMesh::NumericVector< T >::add_vector ( const DenseVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

Computes \( \vec{u} \leftarrow \vec{u} + \vec{v} \), where v is a DenseVector and each dof_indices[i] specifies where to add value v(i).

Definition at line 862 of file numeric_vector.h.

864 {
865  libmesh_assert(v.size() == dof_indices.size());
866  if (!v.empty())
867  this->add_vector(&v(0), dof_indices);
868 }

◆ add_vector() [2/6]

template<typename T>
void libMesh::NumericVector< T >::add_vector ( const NumericVector< T > &  v,
const ShellMatrix< T > &  A 
)
inherited

Computes \( \vec{u} \leftarrow \vec{u} + A \vec{v} \), i.e.

adds the product of a ShellMatrix A and a NumericVector v to this.

Definition at line 385 of file numeric_vector.C.

387 {
388  a.vector_mult_add(*this,v);
389 }

◆ add_vector() [3/6]

template<typename T>
void libMesh::PetscVector< T >::add_vector ( const NumericVector< T > &  v,
const SparseMatrix< T > &  A 
)
overridevirtual

Computes \( \vec{u} \leftarrow \vec{u} + A \vec{v} \), i.e.

adds the product of a SparseMatrix A and a NumericVector v to this.

Implements libMesh::NumericVector< T >.

Definition at line 228 of file petsc_vector.C.

230 {
231  this->_restore_array();
232  // Make sure the data passed in are really of Petsc types
233  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
234  const PetscMatrix<T> * A = cast_ptr<const PetscMatrix<T> *>(&A_in);
235 
236  PetscErrorCode ierr=0;
237 
238  // We shouldn't close() the matrix for you, as that would potentially modify the state of a const object.
239  if (!A->closed())
240  {
241  libmesh_warning("Matrix A must be assembled before calling PetscVector::add_vector(v, A).\n"
242  "Please update your code, as this warning will become an error in a future release.");
243  libmesh_deprecated();
244  const_cast<PetscMatrix<T> *>(A)->close();
245  }
246 
247  // The const_cast<> is not elegant, but it is required since PETSc
248  // expects a non-const Mat.
249  ierr = MatMultAdd(const_cast<PetscMatrix<T> *>(A)->mat(), v->_vec, _vec, _vec);
250  LIBMESH_CHKERR(ierr);
251 }

◆ add_vector() [4/6]

template<typename T>
void libMesh::NumericVector< T >::add_vector ( const NumericVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
virtualinherited

Computes \( \vec{u} \leftarrow \vec{u} + \vec{v} \), where v is a NumericVector and each dof_indices[i] specifies where to add value v(i).

Definition at line 373 of file numeric_vector.C.

375 {
376  const std::size_t n = dof_indices.size();
377  libmesh_assert_equal_to(v.size(), n);
378  for (numeric_index_type i=0; i != n; i++)
379  this->add (dof_indices[i], v(i));
380 }

◆ add_vector() [5/6]

template<typename T>
void libMesh::NumericVector< T >::add_vector ( const std::vector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

Computes \( \vec{u} \leftarrow \vec{u} + \vec{v} \), where v is a std::vector and each dof_indices[i] specifies where to add value v[i].

Definition at line 850 of file numeric_vector.h.

852 {
853  libmesh_assert(v.size() == dof_indices.size());
854  if (!v.empty())
855  this->add_vector(v.data(), dof_indices);
856 }

◆ add_vector() [6/6]

template<typename T>
void libMesh::PetscVector< T >::add_vector ( const T *  v,
const std::vector< numeric_index_type > &  dof_indices 
)
overridevirtual

Computes \( \vec{u} \leftarrow \vec{u} + \vec{v} \), where v is a pointer and each dof_indices[i] specifies where to add value v[i].

This should be overridden in subclasses for efficiency.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 205 of file petsc_vector.C.

207 {
208  // If we aren't adding anything just return
209  if (dof_indices.empty())
210  return;
211 
212  this->_restore_array();
213 
214  PetscErrorCode ierr=0;
215  const PetscInt * i_val = reinterpret_cast<const PetscInt *>(dof_indices.data());
216  const PetscScalar * petsc_value = pPS(v);
217 
218  ierr = VecSetValues (_vec, cast_int<PetscInt>(dof_indices.size()),
219  i_val, petsc_value, ADD_VALUES);
220  LIBMESH_CHKERR(ierr);
221 
222  this->_is_closed = false;
223 }

◆ add_vector_conjugate_transpose()

template<typename T>
void libMesh::PetscVector< T >::add_vector_conjugate_transpose ( const NumericVector< T > &  v,
const SparseMatrix< T > &  A 
)

\( U \leftarrow U + A^H v \).

Adds the product of the conjugate-transpose of SparseMatrix A and a NumericVector v to this.

Definition at line 284 of file petsc_vector.C.

286 {
287  libmesh_error_msg("MatMultHermitianTranspose was introduced in PETSc 3.1.0," \
288  << "No one has made it backwards compatible with older " \
289  << "versions of PETSc so far.");
290 }

◆ add_vector_transpose()

template<typename T>
void libMesh::PetscVector< T >::add_vector_transpose ( const NumericVector< T > &  v,
const SparseMatrix< T > &  A 
)
overridevirtual

Computes \( \vec{u} \leftarrow \vec{u} + A^T \vec{v} \), i.e.

adds the product of the transpose of a SparseMatrix A and a NumericVector v to this.

Implements libMesh::NumericVector< T >.

Definition at line 256 of file petsc_vector.C.

258 {
259  this->_restore_array();
260  // Make sure the data passed in are really of Petsc types
261  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
262  const PetscMatrix<T> * A = cast_ptr<const PetscMatrix<T> *>(&A_in);
263 
264  PetscErrorCode ierr=0;
265 
266  // We shouldn't close() the matrix for you, as that would potentially modify the state of a const object.
267  if (!A->closed())
268  {
269  libmesh_warning("Matrix A must be assembled before calling PetscVector::add_vector_transpose(v, A).\n"
270  "Please update your code, as this warning will become an error in a future release.");
271  libmesh_deprecated();
272  const_cast<PetscMatrix<T> *>(A)->close();
273  }
274 
275  // The const_cast<> is not elegant, but it is required since PETSc
276  // expects a non-const Mat.
277  ierr = MatMultTransposeAdd(const_cast<PetscMatrix<T> *>(A)->mat(), v->_vec, _vec, _vec);
278  LIBMESH_CHKERR(ierr);
279 }

◆ build()

template<typename T >
std::unique_ptr< NumericVector< T > > libMesh::NumericVector< T >::build ( const Parallel::Communicator &  comm,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

Builds a NumericVector on the processors in communicator comm using the linear solver package specified by solver_package.

Definition at line 49 of file numeric_vector.C.

50 {
51  // Build the appropriate vector
52  switch (solver_package)
53  {
54 
55 #ifdef LIBMESH_HAVE_LASPACK
56  case LASPACK_SOLVERS:
57  return libmesh_make_unique<LaspackVector<T>>(comm, AUTOMATIC);
58 #endif
59 
60 #ifdef LIBMESH_HAVE_PETSC
61  case PETSC_SOLVERS:
62  return libmesh_make_unique<PetscVector<T>>(comm, AUTOMATIC);
63 #endif
64 
65 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
66  case TRILINOS_SOLVERS:
67  return libmesh_make_unique<EpetraVector<T>>(comm, AUTOMATIC);
68 #endif
69 
70 #ifdef LIBMESH_HAVE_EIGEN
71  case EIGEN_SOLVERS:
72  return libmesh_make_unique<EigenSparseVector<T>>(comm, AUTOMATIC);
73 #endif
74 
75  default:
76  return libmesh_make_unique<DistributedVector<T>>(comm, AUTOMATIC);
77  }
78 }

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::System::add_vector(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::System::calculate_norm(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), libMesh::DiagonalMatrix< T >::DiagonalMatrix(), libMesh::RBEIMConstruction::enrich_RB_space(), libMesh::RBConstruction::enrich_RB_space(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::RBEIMConstruction::initialize_rb_construction(), main(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::RBEIMConstruction::set_explicit_sys_subvector(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), DiagonalMatrixTest::testNumerics(), SystemsTest::testProjectCubeWithMeshFunction(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::RBEIMConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), and libMesh::RBConstruction::update_residual_terms().

◆ clear()

template<typename T >
void libMesh::PetscVector< T >::clear ( )
inlineoverridevirtual

Restores the NumericVector<T> to a pristine state.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 849 of file petsc_vector.h.

850 {
851  parallel_object_only();
852 
853  if (this->initialized())
854  this->_restore_array();
855 
856  if ((this->initialized()) && (this->_destroy_vec_on_exit))
857  {
858  PetscErrorCode ierr=0;
859 
860  ierr = LibMeshVecDestroy(&_vec);
861  LIBMESH_CHKERR(ierr);
862  }
863 
864  this->_is_closed = this->_is_initialized = false;
865 
866  _global_to_local_map.clear();
867 }

◆ clone()

template<typename T >
std::unique_ptr< NumericVector< T > > libMesh::PetscVector< T >::clone ( ) const
inlineoverridevirtual
Returns
A copy of this vector wrapped in a smart pointer.
Note
This must be overridden in the derived classes.

Implements libMesh::NumericVector< T >.

Definition at line 921 of file petsc_vector.h.

922 {
923  NumericVector<T> * cloned_vector = new PetscVector<T>(this->comm(), this->type());
924  cloned_vector->init(*this, true);
925  *cloned_vector = *this;
926  return std::unique_ptr<NumericVector<T>>(cloned_vector);
927 }

◆ close()

template<typename T >
void libMesh::PetscVector< T >::close ( )
inlineoverridevirtual

Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across processors.

Implements libMesh::NumericVector< T >.

Definition at line 821 of file petsc_vector.h.

822 {
823  parallel_object_only();
824 
825  this->_restore_array();
826 
827  PetscErrorCode ierr=0;
828 
829  ierr = VecAssemblyBegin(_vec);
830  LIBMESH_CHKERR(ierr);
831  ierr = VecAssemblyEnd(_vec);
832  LIBMESH_CHKERR(ierr);
833 
834  if (this->type() == GHOSTED)
835  {
836  ierr = VecGhostUpdateBegin(_vec,INSERT_VALUES,SCATTER_FORWARD);
837  LIBMESH_CHKERR(ierr);
838  ierr = VecGhostUpdateEnd(_vec,INSERT_VALUES,SCATTER_FORWARD);
839  LIBMESH_CHKERR(ierr);
840  }
841 
842  this->_is_closed = true;
843 }

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::SlepcEigenSolver< libMesh::Number >::get_eigenpair(), libMesh::libmesh_petsc_snes_residual(), libMesh::PetscVector< libMesh::Number >::localize(), libMesh::PetscLinearSolver< Number >::solve(), and PetscVectorTest::testGetArray().

◆ closed()

template<typename T>
virtual bool libMesh::NumericVector< T >::closed ( ) const
inlinevirtualinherited
Returns
true if the vector is closed and ready for computation, false otherwise.

Definition at line 171 of file numeric_vector.h.

171 { return _is_closed; }

Referenced by libMesh::DofMap::max_constraint_error(), libMesh::EigenSparseVector< T >::operator=(), libMesh::LaspackVector< T >::operator=(), and libMesh::PetscVector< libMesh::Number >::operator=().

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 94 of file parallel_object.h.

95  { return _communicator; }

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< libMesh::Number >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< libMesh::Number >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::DofMap::add_constraints_to_send_list(), add_cube_convex_hull_to_mesh(), libMesh::PetscDMWrapper::add_dofs_helper(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::ImplicitSystem::add_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::DynaIO::add_spline_constraints(), libMesh::System::add_vector(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::DofMap::attach_matrix(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::PetscDMWrapper::build_section(), libMesh::PetscDMWrapper::build_sf(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::DofMap::create_dof_constraints(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::DTKSolutionTransfer::DTKSolutionTransfer(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::RBEIMConstruction::enrich_RB_space(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::RBConstruction::enrich_RB_space(), libMesh::EpetraVector< T >::EpetraVector(), AssembleOptimization::equality_constraints(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::RBEIMConstruction::evaluate_mesh_function(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_error_tolerance(), libMesh::MeshRefinement::flag_elements_by_mean_stddev(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::DofMap::gather_constraints(), libMesh::MeshfreeInterpolation::gather_remote_data(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), AssembleOptimization::inequality_constraints(), AssembleOptimization::inequality_constraints_jacobian(), libMesh::LocationMap< T >::init(), libMesh::TimeSolver::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::EigenSystem::init_matrices(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::RBEIMConstruction::initialize_rb_construction(), integrate_function(), libMesh::MeshTools::libmesh_assert_consistent_distributed(), libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::libmesh_petsc_preconditioner_apply(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_postcheck(), libMesh::libmesh_petsc_snes_residual(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::FEMSystem::mesh_position_set(), LinearElasticityWithContact::move_mesh(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::DofMap::n_constrained_dofs(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::DofMap::print_dof_constraints(), FEMParameters::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::System::read_legacy_data(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), LinearElasticityWithContact::residual_and_jacobian(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), libMesh::DofMap::scatter_constraints(), libMesh::CheckpointIO::select_split_config(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::RBEIMConstruction::set_explicit_sys_subvector(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::PetscDiffSolver::setup_petsc_data(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::split_mesh(), libMesh::BoundaryInfo::sync(), libMesh::MeshRefinement::test_level_one(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), libMesh::MeshRefinement::test_unflagged(), SystemsTest::testBlockRestrictedVarNDofs(), PointLocatorTest::testLocator(), BoundaryInfoTest::testMesh(), SystemsTest::testProjectCubeWithMeshFunction(), CheckpointIOTest::testSplitter(), libMesh::MeshTools::total_weight(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::RBEIMConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::VTKIO::write_nodal_data(), libMesh::RBEvaluation::write_out_vectors(), libMesh::TransientRBConstruction::write_riesz_representors_to_files(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::TransientRBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBSCMEvaluationSerialization::write_to_file().

◆ compare()

template<typename T>
int libMesh::NumericVector< T >::compare ( const NumericVector< T > &  other_vector,
const Real  threshold = TOLERANCE 
) const
virtualinherited
Returns
-1 when this is equivalent to other_vector (up to the given threshold), or the first index where abs(a[i]-b[i]) exceeds the threshold.

Definition at line 105 of file numeric_vector.C.

107 {
108  libmesh_assert (this->initialized());
109  libmesh_assert (other_vector.initialized());
110  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
111  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());
112 
113  int first_different_i = std::numeric_limits<int>::max();
115 
116  do
117  {
118  if (std::abs((*this)(i) - other_vector(i)) > threshold)
119  first_different_i = i;
120  else
121  i++;
122  }
123  while (first_different_i==std::numeric_limits<int>::max()
124  && i<last_local_index());
125 
126  // Find the correct first differing index in parallel
127  this->comm().min(first_different_i);
128 
129  if (first_different_i == std::numeric_limits<int>::max())
130  return -1;
131 
132  return first_different_i;
133 }

◆ conjugate()

template<typename T >
void libMesh::PetscVector< T >::conjugate ( )
overridevirtual

Negates the imaginary component of each entry in the vector.

Implements libMesh::NumericVector< T >.

Definition at line 175 of file petsc_vector.C.

176 {
177  PetscErrorCode ierr = 0;
178 
179  // We just call the PETSc VecConjugate
180  ierr = VecConjugate(_vec);
181  LIBMESH_CHKERR(ierr);
182 }

◆ create_subvector()

template<typename T>
void libMesh::PetscVector< T >::create_subvector ( NumericVector< T > &  ,
const std::vector< numeric_index_type > &   
) const
overridevirtual

Fills in subvector from this vector using the indices in rows.

Similar to the create_submatrix() routine for the SparseMatrix class, it is currently only implemented for PetscVectors.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1285 of file petsc_vector.C.

1287 {
1288  this->_restore_array();
1289 
1290  // PETSc data structures
1291  IS parent_is, subvector_is;
1292  VecScatter scatter;
1293  PetscErrorCode ierr = 0;
1294 
1295  // Make sure the passed in subvector is really a PetscVector
1296  PetscVector<T> * petsc_subvector = cast_ptr<PetscVector<T> *>(&subvector);
1297 
1298  // If the petsc_subvector is already initialized, we assume that the
1299  // user has already allocated the *correct* amount of space for it.
1300  // If not, we use the appropriate PETSc routines to initialize it.
1301  if (!petsc_subvector->initialized())
1302  {
1303  // Initialize the petsc_subvector to have enough space to hold
1304  // the entries which will be scattered into it. Note: such an
1305  // init() function (where we let PETSc decide the number of local
1306  // entries) is not currently offered by the PetscVector
1307  // class. Should we differentiate here between sequential and
1308  // parallel vector creation based on this->n_processors() ?
1309  ierr = VecCreateMPI(this->comm().get(),
1310  PETSC_DECIDE, // n_local
1311  cast_int<PetscInt>(rows.size()), // n_global
1312  &(petsc_subvector->_vec));
1313  LIBMESH_CHKERR(ierr);
1314 
1315  ierr = VecSetFromOptions (petsc_subvector->_vec);
1316  LIBMESH_CHKERR(ierr);
1317 
1318  // Mark the subvector as initialized
1319  petsc_subvector->_is_initialized = true;
1320  }
1321  else
1322  {
1323  petsc_subvector->_restore_array();
1324  }
1325 
1326  // Use iota to fill an array with entries [0,1,2,3,4,...rows.size()]
1327  std::vector<PetscInt> idx(rows.size());
1328  std::iota (idx.begin(), idx.end(), 0);
1329 
1330  // Construct index sets
1331  ierr = ISCreateLibMesh(this->comm().get(),
1332  cast_int<PetscInt>(rows.size()),
1333  numeric_petsc_cast(rows.data()),
1335  &parent_is);
1336  LIBMESH_CHKERR(ierr);
1337 
1338  ierr = ISCreateLibMesh(this->comm().get(),
1339  cast_int<PetscInt>(rows.size()),
1340  idx.data(),
1342  &subvector_is);
1343  LIBMESH_CHKERR(ierr);
1344 
1345  // Construct the scatter object
1346  ierr = LibMeshVecScatterCreate(this->_vec,
1347  parent_is,
1348  petsc_subvector->_vec,
1349  subvector_is,
1350  &scatter); LIBMESH_CHKERR(ierr);
1351 
1352  // Actually perform the scatter
1353  ierr = VecScatterBegin(scatter,
1354  this->_vec,
1355  petsc_subvector->_vec,
1356  INSERT_VALUES,
1357  SCATTER_FORWARD); LIBMESH_CHKERR(ierr);
1358 
1359  ierr = VecScatterEnd(scatter,
1360  this->_vec,
1361  petsc_subvector->_vec,
1362  INSERT_VALUES,
1363  SCATTER_FORWARD); LIBMESH_CHKERR(ierr);
1364 
1365  // Clean up
1366  ierr = LibMeshISDestroy(&parent_is); LIBMESH_CHKERR(ierr);
1367  ierr = LibMeshISDestroy(&subvector_is); LIBMESH_CHKERR(ierr);
1368  ierr = LibMeshVecScatterDestroy(&scatter); LIBMESH_CHKERR(ierr);
1369 }

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 106 of file reference_counter.C.

107 {
108  _enable_print_counter = false;
109  return;
110 }

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::LibMeshInit::LibMeshInit().

◆ dot()

template<typename T>
T libMesh::PetscVector< T >::dot ( const NumericVector< T > &  v) const
overridevirtual
Returns
\( \vec{u} \cdot \vec{v} \), the dot product of (*this) with the vector v.

Uses the complex-conjugate of v in the complex-valued case.

Implements libMesh::NumericVector< T >.

Definition at line 486 of file petsc_vector.C.

487 {
488  this->_restore_array();
489 
490  // Error flag
491  PetscErrorCode ierr = 0;
492 
493  // Return value
494  PetscScalar value=0.;
495 
496  // Make sure the NumericVector passed in is really a PetscVector
497  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
498 
499  // 2.3.x (at least) style. Untested for previous versions.
500  ierr = VecDot(this->_vec, v->_vec, &value);
501  LIBMESH_CHKERR(ierr);
502 
503  return static_cast<T>(value);
504 }

◆ el()

template<typename T>
virtual T libMesh::NumericVector< T >::el ( const numeric_index_type  i) const
inlinevirtualinherited
Returns
(*this)(i).

Definition at line 352 of file numeric_vector.h.

352 { return (*this)(i); }

◆ enable_print_counter_info()

void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

Definition at line 100 of file reference_counter.C.

101 {
102  _enable_print_counter = true;
103  return;
104 }

References libMesh::ReferenceCounter::_enable_print_counter.

◆ first_local_index()

template<typename T >
numeric_index_type libMesh::PetscVector< T >::first_local_index ( ) const
inlineoverridevirtual
Returns
The index of the first vector element actually stored on this processor.
Note
The minimum for this index is 0.

Implements libMesh::NumericVector< T >.

Definition at line 970 of file petsc_vector.h.

971 {
972  libmesh_assert (this->initialized());
973 
974  numeric_index_type first = 0;
975 
976  if (_array_is_present) // Can we use cached values?
977  first = _first;
978  else
979  {
980  PetscErrorCode ierr=0;
981  PetscInt petsc_first=0, petsc_last=0;
982  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
983  LIBMESH_CHKERR(ierr);
984  first = static_cast<numeric_index_type>(petsc_first);
985  }
986 
987  return first;
988 }

◆ get() [1/2]

template<typename T>
void libMesh::NumericVector< T >::get ( const std::vector< numeric_index_type > &  index,
std::vector< T > &  values 
) const
inlineinherited

Access multiple components at once.

values will be resized, if necessary, and filled. The default implementation calls operator() for each index, but some implementations may supply faster methods here.

Definition at line 835 of file numeric_vector.h.

837 {
838  const std::size_t num = index.size();
839  values.resize(num);
840  if (!num)
841  return;
842 
843  this->get(index, values.data());
844 }

◆ get() [2/2]

template<typename T>
void libMesh::PetscVector< T >::get ( const std::vector< numeric_index_type > &  index,
T *  values 
) const
inlineoverridevirtual

Access multiple components at once.

values will not be reallocated; it should already have enough space. The default implementation calls operator() for each index, but some implementations may supply faster methods here.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1098 of file petsc_vector.h.

1100 {
1101  this->_get_array(true);
1102 
1103  const std::size_t num = index.size();
1104 
1105  for (std::size_t i=0; i<num; i++)
1106  {
1107  const numeric_index_type local_index = this->map_global_to_local_index(index[i]);
1108 #ifndef NDEBUG
1109  if (this->type() == GHOSTED)
1110  {
1111  libmesh_assert_less (local_index, _local_size);
1112  }
1113 #endif
1114  values[i] = static_cast<T>(_read_only_values[local_index]);
1115  }
1116 }

◆ get_array()

template<typename T >
PetscScalar * libMesh::PetscVector< T >::get_array ( )
inline

Get read/write access to the raw PETSc Vector data array.

Note
This is an advanced interface. In general you should avoid using it unless you know what you are doing!

Definition at line 1121 of file petsc_vector.h.

1122 {
1124  _get_array(false);
1125 
1126  return _values;
1127 }

Referenced by PetscVectorTest::testGetArray().

◆ get_array_read()

template<typename T >
const PetscScalar * libMesh::PetscVector< T >::get_array_read ( ) const
inline

Get read only access to the raw PETSc Vector data array.

Note
This is an advanced interface. In general you should avoid using it unless you know what you are doing!

Definition at line 1132 of file petsc_vector.h.

1133 {
1135  _get_array(true);
1136 
1137  return _read_only_values;
1138 }

Referenced by PetscVectorTest::testGetArray().

◆ get_info()

std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (const auto & pr : _counts)
59  {
60  const std::string name(pr.first);
61  const unsigned int creations = pr.second.first;
62  const unsigned int destructions = pr.second.second;
63 
64  oss << "| " << name << " reference count information:\n"
65  << "| Creations: " << creations << '\n'
66  << "| Destructions: " << destructions << '\n';
67  }
68 
69  oss << " ---------------------------------------------------------------------------- \n";
70 
71  return oss.str();
72 
73 #else
74 
75  return "";
76 
77 #endif
78 }

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

Referenced by libMesh::ReferenceCounter::print_info().

◆ global_relative_compare()

template<typename T>
int libMesh::NumericVector< T >::global_relative_compare ( const NumericVector< T > &  other_vector,
const Real  threshold = TOLERANCE 
) const
virtualinherited
Returns
-1 when this is equivalent to other_vector (up to the given global relative threshold), or the first index where abs(a[i]-b[i])/max_j(a[j],b[j]) exceeds the threshold.

Definition at line 170 of file numeric_vector.C.

172 {
173  libmesh_assert (this->initialized());
174  libmesh_assert (other_vector.initialized());
175  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
176  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());
177 
178  int first_different_i = std::numeric_limits<int>::max();
180 
181  const Real my_norm = this->linfty_norm();
182  const Real other_norm = other_vector.linfty_norm();
183  const Real abs_threshold = std::max(my_norm, other_norm) * threshold;
184 
185  do
186  {
187  if (std::abs((*this)(i) - other_vector(i) ) > abs_threshold)
188  first_different_i = i;
189  else
190  i++;
191  }
192  while (first_different_i==std::numeric_limits<int>::max()
193  && i<last_local_index());
194 
195  // Find the correct first differing index in parallel
196  this->comm().min(first_different_i);
197 
198  if (first_different_i == std::numeric_limits<int>::max())
199  return -1;
200 
201  return first_different_i;
202 }

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectedinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 181 of file reference_counter.h.

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectedinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 194 of file reference_counter.h.

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

◆ indefinite_dot()

template<typename T>
T libMesh::PetscVector< T >::indefinite_dot ( const NumericVector< T > &  v) const
Returns
The dot product of (*this) with the vector v.
Note
Does not use the complex-conjugate of v in the complex-valued case.

Definition at line 507 of file petsc_vector.C.

508 {
509  this->_restore_array();
510 
511  // Error flag
512  PetscErrorCode ierr = 0;
513 
514  // Return value
515  PetscScalar value=0.;
516 
517  // Make sure the NumericVector passed in is really a PetscVector
518  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
519 
520  // 2.3.x (at least) style. Untested for previous versions.
521  ierr = VecTDot(this->_vec, v->_vec, &value);
522  LIBMESH_CHKERR(ierr);
523 
524  return static_cast<T>(value);
525 }

◆ init() [1/4]

template<typename T >
void libMesh::PetscVector< T >::init ( const numeric_index_type  n,
const bool  fast = false,
const ParallelType  ptype = AUTOMATIC 
)
inlineoverridevirtual

Call init() with n_local = N.

Implements libMesh::NumericVector< T >.

Definition at line 709 of file petsc_vector.h.

712 {
713  this->init(n,n,fast,ptype);
714 }

◆ init() [2/4]

template<typename T >
void libMesh::PetscVector< T >::init ( const numeric_index_type  n,
const numeric_index_type  n_local,
const bool  fast = false,
const ParallelType  ptype = AUTOMATIC 
)
inlineoverridevirtual

Change the dimension of the vector to n.

The reserved memory for this vector remains unchanged if possible. If n==0, all memory is freed. Therefore, if you want to resize the vector and release the memory not needed, you have to first call init(0) and then init(n). This behaviour is analogous to that of the STL containers.

On fast==false, the vector is filled by zeros.

Implements libMesh::NumericVector< T >.

Definition at line 640 of file petsc_vector.h.

644 {
645  parallel_object_only();
646 
647  PetscErrorCode ierr=0;
648  PetscInt petsc_n=static_cast<PetscInt>(n);
649 
650  // Clear initialized vectors
651  if (this->initialized())
652  this->clear();
653 
654  if (ptype == AUTOMATIC)
655  {
656  if (n == n_local)
657  this->_type = SERIAL;
658  else
659  this->_type = PARALLEL;
660  }
661  else
662  this->_type = ptype;
663 
664  libmesh_assert ((this->_type==SERIAL && n==n_local) ||
665  this->_type==PARALLEL);
666 
667  // create a sequential vector if on only 1 processor
668  if (this->_type == SERIAL)
669  {
670  ierr = VecCreateSeq (PETSC_COMM_SELF, petsc_n, &_vec);
671  CHKERRABORT(PETSC_COMM_SELF,ierr);
672 
673  ierr = VecSetFromOptions (_vec);
674  CHKERRABORT(PETSC_COMM_SELF,ierr);
675  }
676  // otherwise create an MPI-enabled vector
677  else if (this->_type == PARALLEL)
678  {
679 #ifdef LIBMESH_HAVE_MPI
680  PetscInt petsc_n_local=cast_int<PetscInt>(n_local);
681  libmesh_assert_less_equal (n_local, n);
682  ierr = VecCreateMPI (this->comm().get(), petsc_n_local, petsc_n,
683  &_vec);
684  LIBMESH_CHKERR(ierr);
685 #else
686  libmesh_assert_equal_to (n_local, n);
687  ierr = VecCreateSeq (PETSC_COMM_SELF, petsc_n, &_vec);
688  CHKERRABORT(PETSC_COMM_SELF,ierr);
689 #endif
690 
691  ierr = VecSetFromOptions (_vec);
692  LIBMESH_CHKERR(ierr);
693  }
694  else
695  libmesh_error_msg("Unsupported type " << this->_type);
696 
697  this->_is_initialized = true;
698  this->_is_closed = true;
699 
700 
701  if (fast == false)
702  this->zero ();
703 }

Referenced by libMesh::PetscVector< libMesh::Number >::localize().

◆ init() [3/4]

template<typename T>
virtual void libMesh::PetscVector< T >::init ( const numeric_index_type  n,
const numeric_index_type  n_local,
const std::vector< numeric_index_type > &  ghost,
const bool  fast = false,
const  ptype = AUTOMATIC 
)
overridevirtual

Create a vector that holds tha local indices plus those specified in the ghost argument.

Implements libMesh::NumericVector< T >.

◆ init() [4/4]

template<typename T>
void libMesh::PetscVector< T >::init ( const NumericVector< T > &  other,
const bool  fast = false 
)
inlineoverridevirtual

Creates a vector that has the same dimension and storage type as other, including ghost dofs.

Implements libMesh::NumericVector< T >.

Definition at line 782 of file petsc_vector.h.

784 {
785  parallel_object_only();
786 
787  // Clear initialized vectors
788  if (this->initialized())
789  this->clear();
790 
791  const PetscVector<T> & v = cast_ref<const PetscVector<T> &>(other);
792 
793  // Other vector should restore array.
794  if (v.initialized())
795  {
796  v._restore_array();
797  }
798 
799  this->_global_to_local_map = v._global_to_local_map;
800 
801  // Even if we're initializing sizes based on an uninitialized or
802  // unclosed vector, *this* vector is being initialized now and is
803  // initially closed.
804  this->_is_closed = true; // v._is_closed;
805  this->_is_initialized = true; // v._is_initialized;
806 
807  this->_type = v._type;
808 
809  // We want to have a valid Vec, even if it's initially of size zero
810  PetscErrorCode ierr = VecDuplicate (v._vec, &this->_vec);
811  LIBMESH_CHKERR(ierr);
812 
813  if (fast == false)
814  this->zero ();
815 }

◆ initialized()

template<typename T>
virtual bool libMesh::NumericVector< T >::initialized ( ) const
inlinevirtualinherited

◆ insert() [1/5]

template<typename T>
void libMesh::NumericVector< T >::insert ( const DenseSubVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

Inserts the entries of v in *this at the locations specified by v.

Definition at line 898 of file numeric_vector.h.

900 {
901  libmesh_assert(v.size() == dof_indices.size());
902  if (!v.empty())
903  this->insert(&v(0), dof_indices);
904 }

◆ insert() [2/5]

template<typename T>
void libMesh::NumericVector< T >::insert ( const DenseVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

Inserts the entries of v in *this at the locations specified by v.

Definition at line 886 of file numeric_vector.h.

888 {
889  libmesh_assert(v.size() == dof_indices.size());
890  if (!v.empty())
891  this->insert(&v(0), dof_indices);
892 }

◆ insert() [3/5]

template<typename T>
void libMesh::NumericVector< T >::insert ( const NumericVector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
virtualinherited

Inserts the entries of v in *this at the locations specified by v.

Definition at line 93 of file numeric_vector.C.

95 {
96  libmesh_assert_equal_to (V.size(), dof_indices.size());
97 
98  for (auto i : index_range(dof_indices))
99  this->set (dof_indices[i], V(i));
100 }

◆ insert() [4/5]

template<typename T>
void libMesh::NumericVector< T >::insert ( const std::vector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

Inserts the entries of v in *this at the locations specified by v.

Definition at line 874 of file numeric_vector.h.

876 {
877  libmesh_assert(v.size() == dof_indices.size());
878  if (!v.empty())
879  this->insert(v.data(), dof_indices);
880 }

◆ insert() [5/5]

template<typename T>
void libMesh::PetscVector< T >::insert ( const T *  v,
const std::vector< numeric_index_type > &  dof_indices 
)
overridevirtual

Inserts the entries of v in *this at the locations specified by v.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 387 of file petsc_vector.C.

389 {
390  if (dof_indices.empty())
391  return;
392 
393  this->_restore_array();
394 
395  PetscErrorCode ierr=0;
396  PetscInt * idx_values = numeric_petsc_cast(dof_indices.data());
397  ierr = VecSetValues (_vec, cast_int<PetscInt>(dof_indices.size()),
398  idx_values, pPS(v), INSERT_VALUES);
399  LIBMESH_CHKERR(ierr);
400 
401  this->_is_closed = false;
402 }

◆ l1_norm()

template<typename T >
Real libMesh::PetscVector< T >::l1_norm ( ) const
overridevirtual
Returns
The \( \ell_1 \)-norm of the vector, i.e. the sum of the absolute values of the entries.

Implements libMesh::NumericVector< T >.

Definition at line 64 of file petsc_vector.C.

65 {
66  this->_restore_array();
67  libmesh_assert(this->closed());
68 
69  PetscErrorCode ierr=0;
70  PetscReal value=0.;
71 
72  ierr = VecNorm (_vec, NORM_1, &value);
73  LIBMESH_CHKERR(ierr);
74 
75  return static_cast<Real>(value);
76 }

◆ l2_norm()

template<typename T >
Real libMesh::PetscVector< T >::l2_norm ( ) const
overridevirtual
Returns
The \( \ell_2 \)-norm of the vector, i.e. the square root of the sum of the squares of the entries.

Implements libMesh::NumericVector< T >.

Definition at line 81 of file petsc_vector.C.

82 {
83  this->_restore_array();
84  libmesh_assert(this->closed());
85 
86  PetscErrorCode ierr=0;
87  PetscReal value=0.;
88 
89  ierr = VecNorm (_vec, NORM_2, &value);
90  LIBMESH_CHKERR(ierr);
91 
92  return static_cast<Real>(value);
93 }

◆ last_local_index()

template<typename T >
numeric_index_type libMesh::PetscVector< T >::last_local_index ( ) const
inlineoverridevirtual
Returns
The index+1 of the last vector element actually stored on this processor.
Note
The maximum for this index is size().

Implements libMesh::NumericVector< T >.

Definition at line 994 of file petsc_vector.h.

995 {
996  libmesh_assert (this->initialized());
997 
998  numeric_index_type last = 0;
999 
1000  if (_array_is_present) // Can we use cached values?
1001  last = _last;
1002  else
1003  {
1004  PetscErrorCode ierr=0;
1005  PetscInt petsc_first=0, petsc_last=0;
1006  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1007  LIBMESH_CHKERR(ierr);
1008  last = static_cast<numeric_index_type>(petsc_last);
1009  }
1010 
1011  return last;
1012 }

◆ linfty_norm()

template<typename T >
Real libMesh::PetscVector< T >::linfty_norm ( ) const
overridevirtual
Returns
The \( \ell_{\infty} \)-norm of the vector, i.e. the maximum absolute value of the entries of the vector.

Implements libMesh::NumericVector< T >.

Definition at line 99 of file petsc_vector.C.

100 {
101  this->_restore_array();
102  libmesh_assert(this->closed());
103 
104  PetscErrorCode ierr=0;
105  PetscReal value=0.;
106 
107  ierr = VecNorm (_vec, NORM_INFINITY, &value);
108  LIBMESH_CHKERR(ierr);
109 
110  return static_cast<Real>(value);
111 }

◆ local_relative_compare()

template<typename T>
int libMesh::NumericVector< T >::local_relative_compare ( const NumericVector< T > &  other_vector,
const Real  threshold = TOLERANCE 
) const
virtualinherited
Returns
-1 when this is equivalent to other_vector, (up to the given local relative threshold), or the first index where abs(a[i]-b[i])/max(a[i],b[i]) exceeds the threshold.

Definition at line 137 of file numeric_vector.C.

139 {
140  libmesh_assert (this->initialized());
141  libmesh_assert (other_vector.initialized());
142  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
143  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());
144 
145  int first_different_i = std::numeric_limits<int>::max();
147 
148  do
149  {
150  if (std::abs((*this)(i) - other_vector(i)) > threshold *
151  std::max(std::abs((*this)(i)), std::abs(other_vector(i))))
152  first_different_i = i;
153  else
154  i++;
155  }
156  while (first_different_i==std::numeric_limits<int>::max()
157  && i<last_local_index());
158 
159  // Find the correct first differing index in parallel
160  this->comm().min(first_different_i);
161 
162  if (first_different_i == std::numeric_limits<int>::max())
163  return -1;
164 
165  return first_different_i;
166 }

◆ local_size()

template<typename T >
numeric_index_type libMesh::PetscVector< T >::local_size ( ) const
inlineoverridevirtual
Returns
The local size of the vector, i.e. index_stop - index_start.

Implements libMesh::NumericVector< T >.

Definition at line 953 of file petsc_vector.h.

954 {
955  libmesh_assert (this->initialized());
956 
957  PetscErrorCode ierr=0;
958  PetscInt petsc_size=0;
959 
960  ierr = VecGetLocalSize(_vec, &petsc_size);
961  LIBMESH_CHKERR(ierr);
962 
963  return static_cast<numeric_index_type>(petsc_size);
964 }

Referenced by libMesh::PetscVector< libMesh::Number >::operator=().

◆ localize() [1/5]

template<typename T>
void libMesh::PetscVector< T >::localize ( const numeric_index_type  first_local_idx,
const numeric_index_type  last_local_idx,
const std::vector< numeric_index_type > &  send_list 
)
overridevirtual

Updates a local vector with selected values from neighboring processors, as defined by send_list.

Implements libMesh::NumericVector< T >.

Definition at line 874 of file petsc_vector.C.

877 {
878  this->_restore_array();
879 
880  libmesh_assert_less_equal (send_list.size(), this->size());
881  libmesh_assert_less_equal (last_local_idx+1, this->size());
882 
883  const numeric_index_type my_size = this->size();
884  const numeric_index_type my_local_size = (last_local_idx - first_local_idx + 1);
885  PetscErrorCode ierr=0;
886 
887  // Don't bother for serial cases
888  // if ((first_local_idx == 0) &&
889  // (my_local_size == my_size))
890  // But we do need to stay in sync for degenerate cases
891  if (this->n_processors() == 1)
892  return;
893 
894 
895  // Build a parallel vector, initialize it with the local
896  // parts of (*this)
897  PetscVector<T> parallel_vec(this->comm(), PARALLEL);
898 
899  parallel_vec.init (my_size, my_local_size, true, PARALLEL);
900 
901 
902  // Copy part of *this into the parallel_vec
903  {
904  IS is;
905  VecScatter scatter;
906 
907  // Create idx, idx[i] = i+first_local_idx;
908  std::vector<PetscInt> idx(my_local_size);
909  std::iota (idx.begin(), idx.end(), first_local_idx);
910 
911  // Create the index set & scatter object
912  ierr = ISCreateLibMesh(this->comm().get(), my_local_size,
913  my_local_size ? idx.data() : nullptr, PETSC_USE_POINTER, &is);
914  LIBMESH_CHKERR(ierr);
915 
916  ierr = LibMeshVecScatterCreate(_vec, is,
917  parallel_vec._vec, is,
918  &scatter);
919  LIBMESH_CHKERR(ierr);
920 
921  ierr = VecScatterBegin(scatter, _vec, parallel_vec._vec,
922  INSERT_VALUES, SCATTER_FORWARD);
923  LIBMESH_CHKERR(ierr);
924 
925  ierr = VecScatterEnd (scatter, _vec, parallel_vec._vec,
926  INSERT_VALUES, SCATTER_FORWARD);
927  LIBMESH_CHKERR(ierr);
928 
929  // Clean up
930  ierr = LibMeshISDestroy (&is);
931  LIBMESH_CHKERR(ierr);
932 
933  ierr = LibMeshVecScatterDestroy(&scatter);
934  LIBMESH_CHKERR(ierr);
935  }
936 
937  // localize like normal
938  parallel_vec.close();
939  parallel_vec.localize (*this, send_list);
940  this->close();
941 }

◆ localize() [2/5]

template<typename T>
void libMesh::PetscVector< T >::localize ( NumericVector< T > &  v_local) const
overridevirtual

Same, but fills a NumericVector<T> instead of a std::vector.

Implements libMesh::NumericVector< T >.

Definition at line 680 of file petsc_vector.C.

681 {
682  this->_restore_array();
683 
684  // Make sure the NumericVector passed in is really a PetscVector
685  PetscVector<T> * v_local = cast_ptr<PetscVector<T> *>(&v_local_in);
686 
687  libmesh_assert(v_local);
688  libmesh_assert_equal_to (v_local->size(), this->size());
689 
690  PetscErrorCode ierr = 0;
691  const PetscInt n = this->size();
692 
693  IS is;
694  VecScatter scatter;
695 
696  // Create idx, idx[i] = i;
697  std::vector<PetscInt> idx(n);
698  std::iota (idx.begin(), idx.end(), 0);
699 
700  // Create the index set & scatter object
701  ierr = ISCreateLibMesh(this->comm().get(), n, idx.data(), PETSC_USE_POINTER, &is);
702  LIBMESH_CHKERR(ierr);
703 
704  ierr = LibMeshVecScatterCreate(_vec, is,
705  v_local->_vec, is,
706  &scatter);
707  LIBMESH_CHKERR(ierr);
708 
709  // Perform the scatter
710  ierr = VecScatterBegin(scatter, _vec, v_local->_vec,
711  INSERT_VALUES, SCATTER_FORWARD);
712  LIBMESH_CHKERR(ierr);
713 
714  ierr = VecScatterEnd (scatter, _vec, v_local->_vec,
715  INSERT_VALUES, SCATTER_FORWARD);
716  LIBMESH_CHKERR(ierr);
717 
718  // Clean up
719  ierr = LibMeshISDestroy (&is);
720  LIBMESH_CHKERR(ierr);
721 
722  ierr = LibMeshVecScatterDestroy(&scatter);
723  LIBMESH_CHKERR(ierr);
724 
725  // Make sure ghost dofs are up to date
726  if (v_local->type() == GHOSTED)
727  v_local->close();
728 }

◆ localize() [3/5]

template<typename T>
void libMesh::PetscVector< T >::localize ( NumericVector< T > &  v_local,
const std::vector< numeric_index_type > &  send_list 
) const
overridevirtual

Creates a local vector v_local containing only information relevant to this processor, as defined by the send_list.

Implements libMesh::NumericVector< T >.

Definition at line 733 of file petsc_vector.C.

735 {
736  // FIXME: Workaround for a strange bug at large-scale.
737  // If we have ghosting, PETSc lets us just copy the solution, and
738  // doing so avoids a segfault?
739  if (v_local_in.type() == GHOSTED &&
740  this->type() == PARALLEL)
741  {
742  v_local_in = *this;
743  return;
744  }
745 
746  // Normal code path begins here
747 
748  this->_restore_array();
749 
750  // Make sure the NumericVector passed in is really a PetscVector
751  PetscVector<T> * v_local = cast_ptr<PetscVector<T> *>(&v_local_in);
752 
753  libmesh_assert(v_local);
754  libmesh_assert_equal_to (v_local->size(), this->size());
755  libmesh_assert_less_equal (send_list.size(), v_local->size());
756 
757  PetscErrorCode ierr=0;
758  const numeric_index_type n_sl =
759  cast_int<numeric_index_type>(send_list.size());
760 
761  IS is;
762  VecScatter scatter;
763 
764  std::vector<PetscInt> idx(n_sl + this->local_size());
765 
766  for (numeric_index_type i=0; i<n_sl; i++)
767  idx[i] = static_cast<PetscInt>(send_list[i]);
768  for (auto i : IntRange<numeric_index_type>(0, this->local_size()))
769  idx[n_sl+i] = i + this->first_local_index();
770 
771  // Create the index set & scatter object
772  PetscInt * idxptr = idx.empty() ? nullptr : idx.data();
773  ierr = ISCreateLibMesh(this->comm().get(), n_sl+this->local_size(),
774  idxptr, PETSC_USE_POINTER, &is);
775  LIBMESH_CHKERR(ierr);
776 
777  ierr = LibMeshVecScatterCreate(_vec, is,
778  v_local->_vec, is,
779  &scatter);
780  LIBMESH_CHKERR(ierr);
781 
782 
783  // Perform the scatter
784  ierr = VecScatterBegin(scatter, _vec, v_local->_vec,
785  INSERT_VALUES, SCATTER_FORWARD);
786  LIBMESH_CHKERR(ierr);
787 
788  ierr = VecScatterEnd (scatter, _vec, v_local->_vec,
789  INSERT_VALUES, SCATTER_FORWARD);
790  LIBMESH_CHKERR(ierr);
791 
792  // Clean up
793  ierr = LibMeshISDestroy (&is);
794  LIBMESH_CHKERR(ierr);
795 
796  ierr = LibMeshVecScatterDestroy(&scatter);
797  LIBMESH_CHKERR(ierr);
798 
799  // Make sure ghost dofs are up to date
800  if (v_local->type() == GHOSTED)
801  v_local->close();
802 }

◆ localize() [4/5]

template<typename T>
void libMesh::PetscVector< T >::localize ( std::vector< T > &  v_local) const
overridevirtual

Creates a copy of the global vector in the local vector v_local.

Implements libMesh::NumericVector< T >.

Definition at line 946 of file petsc_vector.C.

947 {
948  this->_restore_array();
949 
950  // This function must be run on all processors at once
951  parallel_object_only();
952 
953  PetscErrorCode ierr=0;
954  const PetscInt n = this->size();
955  const PetscInt nl = this->local_size();
956  PetscScalar * values;
957 
958  v_local.clear();
959  v_local.resize(n, 0.);
960 
961  ierr = VecGetArray (_vec, &values);
962  LIBMESH_CHKERR(ierr);
963 
965 
966  for (PetscInt i=0; i<nl; i++)
967  v_local[i+ioff] = static_cast<T>(values[i]);
968 
969  ierr = VecRestoreArray (_vec, &values);
970  LIBMESH_CHKERR(ierr);
971 
972  this->comm().sum(v_local);
973 }

Referenced by libMesh::PetscVector< libMesh::Number >::localize().

◆ localize() [5/5]

template<typename T>
void libMesh::PetscVector< T >::localize ( std::vector< T > &  v_local,
const std::vector< numeric_index_type > &  indices 
) const
overridevirtual

Fill in the local std::vector "v_local" with the global indices given in "indices".

Note
The indices can be different on every processor, and the same index can be localized to more than one processor. The resulting v_local can be shorter than the original, and the entries will be in the order specified by indices.

Example:

*   On 4 procs *this = {a, b, c, d, e, f, g, h, i} is a parallel vector.
*   On each proc, the indices arrays are set up as:
*   proc0, indices = {1,2,4,5}
*   proc1, indices = {2,5,6,8}
*   proc2, indices = {2,3,6,7}
*   proc3, indices = {0,1,2,3}
*
*   After calling this version of localize, the v_local vectors are:
*   proc0, v_local = {b,c,e,f}
*   proc1, v_local = {c,f,g,i}
*   proc2, v_local = {c,d,g,h}
*   proc3, v_local = {a,b,c,d}
* 

This function is useful in parallel I/O routines, when you have a parallel vector of solution values which you want to write a subset of.

Implements libMesh::NumericVector< T >.

Definition at line 807 of file petsc_vector.C.

809 {
810  // Error code used to check the status of all PETSc function calls.
811  PetscErrorCode ierr = 0;
812 
813  // Create a sequential destination Vec with the right number of entries on each proc.
814  Vec dest;
815  ierr = VecCreateSeq(PETSC_COMM_SELF, cast_int<PetscInt>(indices.size()), &dest);
816  LIBMESH_CHKERR(ierr);
817 
818  // Create an IS using the libmesh routine. PETSc does not own the
819  // IS memory in this case, it is automatically cleaned up by the
820  // std::vector destructor.
821  PetscInt * idxptr =
822  indices.empty() ? nullptr : numeric_petsc_cast(indices.data());
823  IS is;
824  ierr = ISCreateLibMesh(this->comm().get(), cast_int<PetscInt>(indices.size()), idxptr,
826  LIBMESH_CHKERR(ierr);
827 
828  // Create the VecScatter object. "PETSC_NULL" means "use the identity IS".
829  VecScatter scatter;
830  ierr = LibMeshVecScatterCreate(_vec,
831  /*src is=*/is,
832  /*dest vec=*/dest,
833  /*dest is=*/PETSC_NULL,
834  &scatter);
835  LIBMESH_CHKERR(ierr);
836 
837  // Do the scatter
838  ierr = VecScatterBegin(scatter, _vec, dest, INSERT_VALUES, SCATTER_FORWARD);
839  LIBMESH_CHKERR(ierr);
840 
841  ierr = VecScatterEnd(scatter, _vec, dest, INSERT_VALUES, SCATTER_FORWARD);
842  LIBMESH_CHKERR(ierr);
843 
844  // Get access to the values stored in dest.
845  PetscScalar * values;
846  ierr = VecGetArray (dest, &values);
847  LIBMESH_CHKERR(ierr);
848 
849  // Store values into the provided v_local. Make sure there is enough
850  // space reserved and then clear out any existing entries before
851  // inserting.
852  v_local.reserve(indices.size());
853  v_local.clear();
854  v_local.insert(v_local.begin(), values, values+indices.size());
855 
856  // We are done using it, so restore the array.
857  ierr = VecRestoreArray (dest, &values);
858  LIBMESH_CHKERR(ierr);
859 
860  // Clean up PETSc data structures.
861  ierr = LibMeshVecScatterDestroy(&scatter);
862  LIBMESH_CHKERR(ierr);
863 
864  ierr = LibMeshISDestroy (&is);
865  LIBMESH_CHKERR(ierr);
866 
867  ierr = LibMeshVecDestroy(&dest);
868  LIBMESH_CHKERR(ierr);
869 }

◆ localize_to_one() [1/3]

template<>
void libMesh::PetscVector< Complex >::localize_to_one ( std::vector< Complex > &  v_local,
const processor_id_type  pid 
) const

Definition at line 1079 of file petsc_vector.C.

1081 {
1082  this->_restore_array();
1083 
1084  PetscErrorCode ierr=0;
1085  const PetscInt n = size();
1086  const PetscInt nl = local_size();
1087  PetscScalar * values;
1088 
1089 
1090  v_local.resize(n);
1091 
1092 
1093  for (PetscInt i=0; i<n; i++)
1094  v_local[i] = 0.;
1095 
1096  // only one processor
1097  if (n_processors() == 1)
1098  {
1099  ierr = VecGetArray (_vec, &values);
1100  LIBMESH_CHKERR(ierr);
1101 
1102  for (PetscInt i=0; i<n; i++)
1103  v_local[i] = static_cast<Complex>(values[i]);
1104 
1105  ierr = VecRestoreArray (_vec, &values);
1106  LIBMESH_CHKERR(ierr);
1107  }
1108 
1109  // otherwise multiple processors
1110  else
1111  {
1112  numeric_index_type ioff = this->first_local_index();
1113 
1114  /* in here the local values are stored, acting as send buffer for MPI
1115  * initialize to zero, since we collect using MPI_SUM
1116  */
1117  std::vector<Real> real_local_values(n, 0.);
1118  std::vector<Real> imag_local_values(n, 0.);
1119 
1120  {
1121  ierr = VecGetArray (_vec, &values);
1122  LIBMESH_CHKERR(ierr);
1123 
1124  // provide my local share to the real and imag buffers
1125  for (PetscInt i=0; i<nl; i++)
1126  {
1127  real_local_values[i+ioff] = static_cast<Complex>(values[i]).real();
1128  imag_local_values[i+ioff] = static_cast<Complex>(values[i]).imag();
1129  }
1130 
1131  ierr = VecRestoreArray (_vec, &values);
1132  LIBMESH_CHKERR(ierr);
1133  }
1134 
1135  /* have buffers of the real and imaginary part of v_local.
1136  * Once MPI_Reduce() collected all the real and imaginary
1137  * parts in these std::vector<Real>, the values can be
1138  * copied to v_local
1139  */
1140  std::vector<Real> real_v_local(n);
1141  std::vector<Real> imag_v_local(n);
1142 
1143  // collect entries from other proc's in real_v_local, imag_v_local
1144  MPI_Reduce (real_local_values.data(),
1145  real_v_local.data(), n,
1146  Parallel::StandardType<Real>(),
1147  Parallel::OpFunction<Real>::sum(),
1148  pid, this->comm().get());
1149 
1150  MPI_Reduce (imag_local_values.data(),
1151  imag_v_local.data(), n,
1152  Parallel::StandardType<Real>(),
1153  Parallel::OpFunction<Real>::sum(),
1154  pid, this->comm().get());
1155 
1156  // copy real_v_local and imag_v_local to v_local
1157  for (PetscInt i=0; i<n; i++)
1158  v_local[i] = Complex(real_v_local[i], imag_v_local[i]);
1159  }
1160 }

◆ localize_to_one() [2/3]

template<>
void libMesh::PetscVector< Real >::localize_to_one ( std::vector< Real > &  v_local,
const processor_id_type   timpi_mpi_varpid 
) const

Definition at line 981 of file petsc_vector.C.

984 {
985  this->_restore_array();
986 
987  PetscErrorCode ierr=0;
988  const PetscInt n = size();
989  PetscScalar * values;
990 
991  // only one processor
992  if (n_processors() == 1)
993  {
994  v_local.resize(n);
995 
996  ierr = VecGetArray (_vec, &values);
997  LIBMESH_CHKERR(ierr);
998 
999  for (PetscInt i=0; i<n; i++)
1000  v_local[i] = static_cast<Real>(values[i]);
1001 
1002  ierr = VecRestoreArray (_vec, &values);
1003  LIBMESH_CHKERR(ierr);
1004  }
1005 
1006  // otherwise multiple processors
1007 #ifdef LIBMESH_HAVE_MPI
1008  else
1009  {
1010  if (pid == 0) // optimized version for localizing to 0
1011  {
1012  Vec vout;
1013  VecScatter ctx;
1014 
1015  ierr = VecScatterCreateToZero(_vec, &ctx, &vout);
1016  LIBMESH_CHKERR(ierr);
1017 
1018  ierr = VecScatterBegin(ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
1019  LIBMESH_CHKERR(ierr);
1020  ierr = VecScatterEnd(ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
1021  LIBMESH_CHKERR(ierr);
1022 
1023  if (processor_id() == 0)
1024  {
1025  v_local.resize(n);
1026 
1027  ierr = VecGetArray (vout, &values);
1028  LIBMESH_CHKERR(ierr);
1029 
1030  for (PetscInt i=0; i<n; i++)
1031  v_local[i] = static_cast<Real>(values[i]);
1032 
1033  ierr = VecRestoreArray (vout, &values);
1034  LIBMESH_CHKERR(ierr);
1035  }
1036 
1037  ierr = LibMeshVecScatterDestroy(&ctx);
1038  LIBMESH_CHKERR(ierr);
1039  ierr = LibMeshVecDestroy(&vout);
1040  LIBMESH_CHKERR(ierr);
1041 
1042  }
1043  else
1044  {
1045  v_local.resize(n);
1046 
1047  numeric_index_type ioff = this->first_local_index();
1048  std::vector<Real> local_values (n, 0.);
1049 
1050  {
1051  ierr = VecGetArray (_vec, &values);
1052  LIBMESH_CHKERR(ierr);
1053 
1054  const PetscInt nl = local_size();
1055  for (PetscInt i=0; i<nl; i++)
1056  local_values[i+ioff] = static_cast<Real>(values[i]);
1057 
1058  ierr = VecRestoreArray (_vec, &values);
1059  LIBMESH_CHKERR(ierr);
1060  }
1061 
1062 
1063  MPI_Reduce (local_values.data(), v_local.data(), n,
1064  Parallel::StandardType<Real>(),
1065  Parallel::OpFunction<Real>::sum(), pid,
1066  this->comm().get());
1067  }
1068  }
1069 #endif // LIBMESH_HAVE_MPI
1070 }

◆ localize_to_one() [3/3]

template<typename T>
virtual void libMesh::PetscVector< T >::localize_to_one ( std::vector< T > &  v_local,
const processor_id_type  proc_id = 0 
) const
overridevirtual

Creates a local copy of the global vector in v_local only on processor proc_id.

By default the data is sent to processor 0. This method is useful for outputting data from one processor.

Implements libMesh::NumericVector< T >.

◆ map_global_to_local_index()

template<typename T >
numeric_index_type libMesh::PetscVector< T >::map_global_to_local_index ( const numeric_index_type  i) const
inline
Returns
The local index corresponding to global index i.

If the index is not a ghost cell, this is done by subtraction the number of the first local index. If it is a ghost cell, it has to be looked up in the map.

Definition at line 1018 of file petsc_vector.h.

1019 {
1020  libmesh_assert (this->initialized());
1021 
1022  numeric_index_type first=0;
1023  numeric_index_type last=0;
1024 
1025  if (_array_is_present) // Can we use cached values?
1026  {
1027  first = _first;
1028  last = _last;
1029  }
1030  else
1031  {
1032  PetscErrorCode ierr=0;
1033  PetscInt petsc_first=0, petsc_last=0;
1034  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1035  LIBMESH_CHKERR(ierr);
1036  first = static_cast<numeric_index_type>(petsc_first);
1037  last = static_cast<numeric_index_type>(petsc_last);
1038  }
1039 
1040 
1041  if ((i>=first) && (i<last))
1042  {
1043  return i-first;
1044  }
1045 
1046  GlobalToLocalMap::const_iterator it = _global_to_local_map.find(i);
1047 #ifndef NDEBUG
1048  const GlobalToLocalMap::const_iterator end = _global_to_local_map.end();
1049  if (it == end)
1050  {
1051  std::ostringstream error_message;
1052  error_message << "No index " << i << " in ghosted vector.\n"
1053  << "Vector contains [" << first << ',' << last << ")\n";
1054  GlobalToLocalMap::const_iterator b = _global_to_local_map.begin();
1055  if (b == end)
1056  {
1057  error_message << "And empty ghost array.\n";
1058  }
1059  else
1060  {
1061  error_message << "And ghost array {" << b->first;
1062  for (++b; b != end; ++b)
1063  error_message << ',' << b->first;
1064  error_message << "}\n";
1065  }
1066 
1067  libmesh_error_msg(error_message.str());
1068  }
1069  libmesh_assert (it != _global_to_local_map.end());
1070 #endif
1071  return it->second+last-first;
1072 }

◆ max()

template<typename T >
Real libMesh::PetscVector< T >::max ( ) const
inlineoverridevirtual
Returns
The maximum entry in the vector, or the maximum real part in the case of complex numbers.

Implements libMesh::NumericVector< T >.

Definition at line 1173 of file petsc_vector.h.

1174 {
1175  parallel_object_only();
1176 
1177  this->_restore_array();
1178 
1179  PetscErrorCode ierr=0;
1180  PetscInt index=0;
1181  PetscReal returnval=0.;
1182 
1183  ierr = VecMax (_vec, &index, &returnval);
1184  LIBMESH_CHKERR(ierr);
1185 
1186  // this return value is correct: VecMax returns a PetscReal
1187  return static_cast<Real>(returnval);
1188 }

◆ min()

template<typename T >
Real libMesh::PetscVector< T >::min ( ) const
inlineoverridevirtual
Returns
The minimum entry in the vector, or the minimum real part in the case of complex numbers.

Implements libMesh::NumericVector< T >.

Definition at line 1152 of file petsc_vector.h.

1153 {
1154  parallel_object_only();
1155 
1156  this->_restore_array();
1157 
1158  PetscErrorCode ierr=0;
1159  PetscInt index=0;
1160  PetscReal returnval=0.;
1161 
1162  ierr = VecMin (_vec, &index, &returnval);
1163  LIBMESH_CHKERR(ierr);
1164 
1165  // this return value is correct: VecMin returns a PetscReal
1166  return static_cast<Real>(returnval);
1167 }

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 83 of file reference_counter.h.

84  { return _n_objects; }

References libMesh::ReferenceCounter::_n_objects.

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
Returns
The number of processors in the group.

Definition at line 100 of file parallel_object.h.

101  { return cast_int<processor_id_type>(_communicator.size()); }

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::DofMap::add_constraints_to_send_list(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::FEMSystem::assembly(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::EnsightIO::EnsightIO(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::partition(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::DofMap::prepare_send_list(), libMesh::DofMap::print_dof_constraints(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::XdrIO::read_header(), libMesh::CheckpointIO::read_nodes(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::System::read_serialized_vector(), libMesh::DistributedMesh::renumber_dof_objects(), OverlappingFunctorTest::run_partitioner_test(), libMesh::DofMap::scatter_constraints(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), CheckpointIOTest::testSplitter(), WriteVecAndScalar::testWrite(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::VTKIO::write_nodal_data(), libMesh::System::write_parallel_data(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

◆ operator()()

template<typename T >
T libMesh::PetscVector< T >::operator() ( const numeric_index_type  i) const
inlineoverridevirtual
Returns
A copy of the ith entry of the vector.

Implements libMesh::NumericVector< T >.

Definition at line 1078 of file petsc_vector.h.

1079 {
1080  this->_get_array(true);
1081 
1082  const numeric_index_type local_index = this->map_global_to_local_index(i);
1083 
1084 #ifndef NDEBUG
1085  if (this->type() == GHOSTED)
1086  {
1087  libmesh_assert_less (local_index, _local_size);
1088  }
1089 #endif
1090 
1091  return static_cast<T>(_read_only_values[local_index]);
1092 }

◆ operator*=() [1/2]

template<typename T>
NumericVector< T > & libMesh::PetscVector< T >::operator*= ( const NumericVector< T > &  v)
overridevirtual

Computes the component-wise multiplication of this vector's entries by another's, \( u_i \leftarrow u_i v_i \, \forall i\).

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 434 of file petsc_vector.C.

435 {
436  PetscErrorCode ierr = 0;
437 
438  const PetscVector<T> * v_vec = cast_ptr<const PetscVector<T> *>(&v);
439 
440  ierr = VecPointwiseMult(_vec, _vec, v_vec->_vec);
441  LIBMESH_CHKERR(ierr);
442 
443  return *this;
444 }

◆ operator*=() [2/2]

template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator*= ( const T  a)
inlineinherited

Scales the vector by a, \( \vec{u} \leftarrow a\vec{u} \).

Equivalent to u.scale(a)

Returns
A reference to *this.

Definition at line 397 of file numeric_vector.h.

397 { this->scale(a); return *this; }

◆ operator+=()

template<typename T>
NumericVector< T > & libMesh::PetscVector< T >::operator+= ( const NumericVector< T > &  v)
overridevirtual

Adds v to *this, \( \vec{u} \leftarrow \vec{u} + \vec{v} \).

Equivalent to u.add(1, v).

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 118 of file petsc_vector.C.

119 {
120  this->_restore_array();
121  libmesh_assert(this->closed());
122 
123  this->add(1., v);
124 
125  return *this;
126 }

◆ operator-=()

template<typename T>
NumericVector< T > & libMesh::PetscVector< T >::operator-= ( const NumericVector< T > &  v)
overridevirtual

Subtracts v from *this, \( \vec{u} \leftarrow \vec{u} - \vec{v} \).

Equivalent to u.add(-1, v).

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 132 of file petsc_vector.C.

133 {
134  this->_restore_array();
135  libmesh_assert(this->closed());
136 
137  this->add(-1., v);
138 
139  return *this;
140 }

◆ operator/=() [1/2]

template<typename T>
NumericVector< T > & libMesh::PetscVector< T >::operator/= ( const NumericVector< T > &  v)
overridevirtual

Computes the component-wise division of this vector's entries by another's, \( u_i \leftarrow \frac{u_i}{v_i} \, \forall i\).

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 447 of file petsc_vector.C.

448 {
449  PetscErrorCode ierr = 0;
450 
451  const PetscVector<T> * v_vec = cast_ptr<const PetscVector<T> *>(&v);
452 
453  ierr = VecPointwiseDivide(_vec, _vec, v_vec->_vec);
454  LIBMESH_CHKERR(ierr);
455 
456  return *this;
457 }

◆ operator/=() [2/2]

template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator/= ( const T  a)
inlineinherited

Scales the vector by 1/a, \( \vec{u} \leftarrow \frac{1}{a}\vec{u} \).

Equivalent to u.scale(1./a)

Returns
A reference to *this.

Definition at line 415 of file numeric_vector.h.

415 { this->scale(1./a); return *this; }

◆ operator=() [1/5]

template<typename T>
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const NumericVector< T > &  v)
overridevirtual

This looks like a copy assignment operator, but note that, unlike normal copy assignment operators, it is pure virtual.

This function should be overridden in derived classes so that they can be copied correctly via references to the base class. This design usually isn't a good idea in general, but in this context it works because we usually don't have a mix of different kinds of NumericVectors active in the library at a single time.

Returns
A reference to *this as the base type.

Implements libMesh::NumericVector< T >.

Definition at line 566 of file petsc_vector.C.

567 {
568  // Make sure the NumericVector passed in is really a PetscVector
569  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
570 
571  *this = *v;
572 
573  return *this;
574 }

◆ operator=() [2/5]

template<typename T>
PetscVector< T > & libMesh::PetscVector< T >::operator= ( const PetscVector< T > &  v)

Copy assignment operator.

Calls VecCopy after performing various checks.

Returns
A reference to *this as the derived type.

Definition at line 580 of file petsc_vector.C.

581 {
582  this->_restore_array();
583  v._restore_array();
584 
585  libmesh_assert_equal_to (this->size(), v.size());
586  libmesh_assert_equal_to (this->local_size(), v.local_size());
587  libmesh_assert (v.closed());
588 
589  PetscErrorCode ierr = 0;
590 
591  if (((this->type()==PARALLEL) && (v.type()==GHOSTED)) ||
592  ((this->type()==GHOSTED) && (v.type()==PARALLEL)) ||
593  ((this->type()==GHOSTED) && (v.type()==SERIAL)) ||
594  ((this->type()==SERIAL) && (v.type()==GHOSTED)))
595  {
596  /* Allow assignment of a ghosted to a parallel vector since this
597  causes no difficulty. See discussion in libmesh-devel of
598  June 24, 2010. */
599  ierr = VecCopy (v._vec, this->_vec);
600  LIBMESH_CHKERR(ierr);
601  }
602  else
603  {
604  /* In all other cases, we assert that both vectors are of equal
605  type. */
606  libmesh_assert_equal_to (this->_type, v._type);
607 
608  if (v.size() != 0)
609  {
610  if (this->type() != GHOSTED)
611  {
612  ierr = VecCopy (v._vec, this->_vec);
613  LIBMESH_CHKERR(ierr);
614  }
615  else
616  {
617  Vec loc_vec;
618  Vec v_loc_vec;
619  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
620  LIBMESH_CHKERR(ierr);
621  ierr = VecGhostGetLocalForm (v._vec,&v_loc_vec);
622  LIBMESH_CHKERR(ierr);
623 
624  ierr = VecCopy (v_loc_vec, loc_vec);
625  LIBMESH_CHKERR(ierr);
626 
627  ierr = VecGhostRestoreLocalForm (v._vec,&v_loc_vec);
628  LIBMESH_CHKERR(ierr);
629  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
630  LIBMESH_CHKERR(ierr);
631  }
632  }
633  }
634 
635  close();
636 
637  return *this;
638 }

◆ operator=() [3/5]

template<typename T>
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const std::vector< T > &  v)
overridevirtual

Sets (*this)(i) = v(i) for each entry of the vector.

Returns
A reference to *this as the base type.

Case 1: The vector is the same size of The global vector. Only add the local components.

Case 2: The vector is the same size as our local piece. Insert directly to the local piece.

Implements libMesh::NumericVector< T >.

Definition at line 644 of file petsc_vector.C.

645 {
646  this->_get_array(false);
647 
652  if (this->size() == v.size())
653  {
656  for (numeric_index_type i=0; i<last-first; i++)
657  _values[i] = PS(v[first + i]);
658  }
659 
664  else
665  {
666  for (numeric_index_type i=0; i<_local_size; i++)
667  _values[i] = PS(v[i]);
668  }
669 
670  // Make sure ghost dofs are up to date
671  if (this->type() == GHOSTED)
672  this->close();
673 
674  return *this;
675 }

◆ operator=() [4/5]

template<typename T>
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const T  s)
overridevirtual

Sets all entries of the vector to the value s.

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 530 of file petsc_vector.C.

531 {
532  this->_restore_array();
533  libmesh_assert(this->closed());
534 
535  PetscErrorCode ierr = 0;
536  PetscScalar s = PS(s_in);
537 
538  if (this->size() != 0)
539  {
540  if (this->type() != GHOSTED)
541  {
542  ierr = VecSet(_vec, s);
543  LIBMESH_CHKERR(ierr);
544  }
545  else
546  {
547  Vec loc_vec;
548  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
549  LIBMESH_CHKERR(ierr);
550 
551  ierr = VecSet(loc_vec, s);
552  LIBMESH_CHKERR(ierr);
553 
554  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
555  LIBMESH_CHKERR(ierr);
556  }
557  }
558 
559  return *this;
560 }

◆ operator=() [5/5]

template<typename T>
PetscVector& libMesh::PetscVector< T >::operator= ( PetscVector< T > &&  )
delete

◆ pointwise_mult()

template<typename T>
void libMesh::PetscVector< T >::pointwise_mult ( const NumericVector< T > &  vec1,
const NumericVector< T > &  vec2 
)
overridevirtual

Computes \( u_i \leftarrow u_i v_i \) (summation not implied) i.e.

the pointwise (component-wise) product of vec1 and vec2, and stores the result in *this.

Implements libMesh::NumericVector< T >.

Definition at line 1167 of file petsc_vector.C.

1169 {
1170  this->_restore_array();
1171 
1172  PetscErrorCode ierr = 0;
1173 
1174  // Convert arguments to PetscVector*.
1175  const PetscVector<T> * vec1_petsc = cast_ptr<const PetscVector<T> *>(&vec1);
1176  const PetscVector<T> * vec2_petsc = cast_ptr<const PetscVector<T> *>(&vec2);
1177 
1178  // Call PETSc function.
1179 
1180  if (this->type() != GHOSTED)
1181  {
1182  ierr = VecPointwiseMult(this->vec(),
1183  const_cast<PetscVector<T> *>(vec1_petsc)->vec(),
1184  const_cast<PetscVector<T> *>(vec2_petsc)->vec());
1185  LIBMESH_CHKERR(ierr);
1186  }
1187  else
1188  {
1189  Vec loc_vec;
1190  Vec v1_loc_vec;
1191  Vec v2_loc_vec;
1192  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
1193  LIBMESH_CHKERR(ierr);
1194  ierr = VecGhostGetLocalForm (const_cast<PetscVector<T> *>(vec1_petsc)->vec(),&v1_loc_vec);
1195  LIBMESH_CHKERR(ierr);
1196  ierr = VecGhostGetLocalForm (const_cast<PetscVector<T> *>(vec2_petsc)->vec(),&v2_loc_vec);
1197  LIBMESH_CHKERR(ierr);
1198 
1199  ierr = VecPointwiseMult(loc_vec,v1_loc_vec,v2_loc_vec);
1200  LIBMESH_CHKERR(ierr);
1201 
1202  ierr = VecGhostRestoreLocalForm (const_cast<PetscVector<T> *>(vec1_petsc)->vec(),&v1_loc_vec);
1203  LIBMESH_CHKERR(ierr);
1204  ierr = VecGhostRestoreLocalForm (const_cast<PetscVector<T> *>(vec2_petsc)->vec(),&v2_loc_vec);
1205  LIBMESH_CHKERR(ierr);
1206  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
1207  LIBMESH_CHKERR(ierr);
1208  }
1209 }

◆ print() [1/2]

template<>
void libMesh::NumericVector< Complex >::print ( std::ostream &  os) const
inlineinherited

Definition at line 913 of file numeric_vector.h.

914 {
915  libmesh_assert (this->initialized());
916  os << "Size\tglobal = " << this->size()
917  << "\t\tlocal = " << this->local_size() << std::endl;
918 
919  // std::complex<>::operator<<() is defined, but use this form
920  os << "#\tReal part\t\tImaginary part" << std::endl;
921  for (auto i : index_range(*this))
922  os << i << "\t"
923  << (*this)(i).real() << "\t\t"
924  << (*this)(i).imag() << std::endl;
925 }

◆ print() [2/2]

template<typename T >
void libMesh::NumericVector< T >::print ( std::ostream &  os = libMesh::out) const
inlinevirtualinherited

Prints the local contents of the vector, by default to libMesh::out.

Definition at line 931 of file numeric_vector.h.

932 {
933  libmesh_assert (this->initialized());
934  os << "Size\tglobal = " << this->size()
935  << "\t\tlocal = " << this->local_size() << std::endl;
936 
937  os << "#\tValue" << std::endl;
938  for (auto i : index_range(*this))
939  os << i << "\t" << (*this)(i) << std::endl;
940 }

◆ print_global() [1/2]

template<>
void libMesh::NumericVector< Complex >::print_global ( std::ostream &  os) const
inlineinherited

Definition at line 946 of file numeric_vector.h.

947 {
948  libmesh_assert (this->initialized());
949 
950  std::vector<Complex> v(this->size());
951  this->localize(v);
952 
953  // Right now we only want one copy of the output
954  if (this->processor_id())
955  return;
956 
957  os << "Size\tglobal = " << this->size() << std::endl;
958  os << "#\tReal part\t\tImaginary part" << std::endl;
959  for (auto i : IntRange<numeric_index_type>(0, v.size()))
960  os << i << "\t"
961  << v[i].real() << "\t\t"
962  << v[i].imag() << std::endl;
963 }

◆ print_global() [2/2]

template<typename T >
void libMesh::NumericVector< T >::print_global ( std::ostream &  os = libMesh::out) const
inlinevirtualinherited

Prints the global contents of the vector, by default to libMesh::out.

Definition at line 968 of file numeric_vector.h.

969 {
970  libmesh_assert (this->initialized());
971 
972  std::vector<T> v(this->size());
973  this->localize(v);
974 
975  // Right now we only want one copy of the output
976  if (this->processor_id())
977  return;
978 
979  os << "Size\tglobal = " << this->size() << std::endl;
980  os << "#\tValue" << std::endl;
981  for (auto i : IntRange<numeric_index_type>(0, v.size()))
982  os << i << "\t" << v[i] << std::endl;
983 }

◆ print_info()

void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

Definition at line 87 of file reference_counter.C.

88 {
90  out_stream << ReferenceCounter::get_info();
91 }

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

◆ print_matlab()

template<typename T >
void libMesh::PetscVector< T >::print_matlab ( const std::string &  = "") const
overridevirtual

Print the contents of the vector in Matlab's sparse matrix format.

Optionally prints the vector to the file named name. If name is not specified it is dumped to the screen.

Create an ASCII file containing the matrix if a filename was provided.

Otherwise the matrix will be dumped to the screen.

Destroy the viewer.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1214 of file petsc_vector.C.

1215 {
1216  this->_restore_array();
1217  libmesh_assert (this->closed());
1218 
1219  PetscErrorCode ierr=0;
1220  PetscViewer petsc_viewer;
1221 
1222 
1223  ierr = PetscViewerCreate (this->comm().get(),
1224  &petsc_viewer);
1225  LIBMESH_CHKERR(ierr);
1226 
1231  if (name != "")
1232  {
1233  ierr = PetscViewerASCIIOpen( this->comm().get(),
1234  name.c_str(),
1235  &petsc_viewer);
1236  LIBMESH_CHKERR(ierr);
1237 
1238 #if PETSC_VERSION_LESS_THAN(3,7,0)
1239  ierr = PetscViewerSetFormat (petsc_viewer,
1240  PETSC_VIEWER_ASCII_MATLAB);
1241 #else
1242  ierr = PetscViewerPushFormat (petsc_viewer,
1243  PETSC_VIEWER_ASCII_MATLAB);
1244 #endif
1245 
1246  LIBMESH_CHKERR(ierr);
1247 
1248  ierr = VecView (_vec, petsc_viewer);
1249  LIBMESH_CHKERR(ierr);
1250  }
1251 
1255  else
1256  {
1257 
1258 #if PETSC_VERSION_LESS_THAN(3,7,0)
1259  ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
1260  PETSC_VIEWER_ASCII_MATLAB);
1261 #else
1262  ierr = PetscViewerPushFormat (PETSC_VIEWER_STDOUT_WORLD,
1263  PETSC_VIEWER_ASCII_MATLAB);
1264 #endif
1265 
1266  LIBMESH_CHKERR(ierr);
1267 
1268  ierr = VecView (_vec, PETSC_VIEWER_STDOUT_WORLD);
1269  LIBMESH_CHKERR(ierr);
1270  }
1271 
1272 
1276  ierr = LibMeshPetscViewerDestroy (&petsc_viewer);
1277  LIBMESH_CHKERR(ierr);
1278 }

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
The rank of this processor in the group.

Definition at line 106 of file parallel_object.h.

107  { return cast_int<processor_id_type>(_communicator.rank()); }

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::FEMSystem::assembly(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::DistributedMesh::clear(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::DofMap::end_dof(), libMesh::DofMap::end_old_dof(), libMesh::EnsightIO::EnsightIO(), libMesh::RBEIMConstruction::evaluate_mesh_function(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::DofMap::first_dof(), libMesh::DofMap::first_old_dof(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::DofMap::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::DofMap::get_local_constraints(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), HeatSystem::init_data(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::DofMap::last_dof(), libMesh::TransientRBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::legacy_write_out_interpolation_points_elem(), libMesh::MeshTools::libmesh_assert_consistent_distributed(), libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), AugmentSparsityOnInterface::mesh_reinit(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::DofMap::n_local_dofs(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::SparsityPattern::Build::operator()(), libMesh::DistributedMesh::own_node(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::DofMap::print_dof_constraints(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::ExodusII_IO_Helper::read_global_values(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::System::read_legacy_data(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::System::read_parallel_data(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::System::read_serialized_data(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::DofMap::scatter_constraints(), libMesh::CheckpointIO::select_split_config(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::LaplaceMeshSmoother::smooth(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), MeshInputTest::testDynaReadElem(), MeshInputTest::testDynaReadPatch(), MeshInputTest::testExodusCopyElementSolution(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), SystemsTest::testProjectMatrix1D(), SystemsTest::testProjectMatrix2D(), SystemsTest::testProjectMatrix3D(), BoundaryInfoTest::testShellFaceConstraints(), CheckpointIOTest::testSplitter(), WriteVecAndScalar::testWrite(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::DTKAdapter::update_variable_values(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_element_values_element_major(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::System::write_header(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::VTKIO::write_nodal_data(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::RBEvaluation::write_out_vectors(), write_output_solvedata(), libMesh::System::write_parallel_data(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::System::write_serialized_data(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), libMesh::ExodusII_IO_Helper::write_sideset_data(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), libMesh::ExodusII_IO_Helper::write_timestep(), and libMesh::ExodusII_IO::write_timestep_discontinuous().

◆ reciprocal()

template<typename T >
void libMesh::PetscVector< T >::reciprocal ( )
overridevirtual

Computes the component-wise reciprocal, \( u_i \leftarrow \frac{1}{u_i} \, \forall i\).

Implements libMesh::NumericVector< T >.

Definition at line 163 of file petsc_vector.C.

164 {
165  PetscErrorCode ierr = 0;
166 
167  // VecReciprocal has been in PETSc since at least 2.3.3 days
168  ierr = VecReciprocal(_vec);
169  LIBMESH_CHKERR(ierr);
170 }

◆ restore_array()

template<typename T >
void libMesh::PetscVector< T >::restore_array ( )
inline

Restore the data array.

Note
This MUST be called after get_array() or get_array_read() and before using any other interface functions on PetscVector.

Definition at line 1142 of file petsc_vector.h.

1143 {
1144  // \note \p _values_manually_retrieved needs to be set to \p false
1145  // \e before calling \p _restore_array()!
1147  _restore_array();
1148 }

Referenced by PetscVectorTest::testGetArray().

◆ scale()

template<typename T>
void libMesh::PetscVector< T >::scale ( const T  factor)
overridevirtual

Scale each element of the vector by the given factor.

Implements libMesh::NumericVector< T >.

Definition at line 407 of file petsc_vector.C.

408 {
409  this->_restore_array();
410 
411  PetscErrorCode ierr = 0;
412  PetscScalar factor = PS(factor_in);
413 
414  if (this->type() != GHOSTED)
415  {
416  ierr = VecScale(_vec, factor);
417  LIBMESH_CHKERR(ierr);
418  }
419  else
420  {
421  Vec loc_vec;
422  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
423  LIBMESH_CHKERR(ierr);
424 
425  ierr = VecScale(loc_vec, factor);
426  LIBMESH_CHKERR(ierr);
427 
428  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
429  LIBMESH_CHKERR(ierr);
430  }
431 }

◆ set()

template<typename T>
void libMesh::PetscVector< T >::set ( const numeric_index_type  i,
const T  value 
)
overridevirtual

Sets v(i) = value.

Implements libMesh::NumericVector< T >.

Definition at line 145 of file petsc_vector.C.

146 {
147  this->_restore_array();
148  libmesh_assert_less (i, size());
149 
150  PetscErrorCode ierr=0;
151  PetscInt i_val = static_cast<PetscInt>(i);
152  PetscScalar petsc_value = PS(value);
153 
154  ierr = VecSetValues (_vec, 1, &i_val, &petsc_value, INSERT_VALUES);
155  LIBMESH_CHKERR(ierr);
156 
157  this->_is_closed = false;
158 }

◆ size()

template<typename T >
numeric_index_type libMesh::PetscVector< T >::size ( ) const
inlineoverridevirtual
Returns
The size of the vector.

Implements libMesh::NumericVector< T >.

Definition at line 933 of file petsc_vector.h.

934 {
935  libmesh_assert (this->initialized());
936 
937  PetscErrorCode ierr=0;
938  PetscInt petsc_size=0;
939 
940  if (!this->initialized())
941  return 0;
942 
943  ierr = VecGetSize(_vec, &petsc_size);
944  LIBMESH_CHKERR(ierr);
945 
946  return static_cast<numeric_index_type>(petsc_size);
947 }

Referenced by libMesh::PetscVector< libMesh::Number >::add(), libMesh::PetscVector< libMesh::Number >::localize(), and libMesh::PetscVector< libMesh::Number >::operator=().

◆ subset_l1_norm()

template<class T >
Real libMesh::NumericVector< T >::subset_l1_norm ( const std::set< numeric_index_type > &  indices) const
virtualinherited
Returns
The \( \ell_1 \)-norm of the vector, i.e. the sum of the absolute values for the specified entries in the vector.
Note
The indices must necessarily live on this processor.

Definition at line 312 of file numeric_vector.C.

313 {
314  const NumericVector<T> & v = *this;
315 
316  Real norm = 0;
317 
318  for (const auto & index : indices)
319  norm += std::abs(v(index));
320 
321  this->comm().sum(norm);
322 
323  return norm;
324 }

Referenced by libMesh::System::discrete_var_norm().

◆ subset_l2_norm()

template<class T >
Real libMesh::NumericVector< T >::subset_l2_norm ( const std::set< numeric_index_type > &  indices) const
virtualinherited
Returns
The \( \ell_2 \)-norm of the vector, i.e. the square root of the sum of the squares of the elements for the specified entries in the vector.
Note
The indices must necessarily live on this processor.

Definition at line 327 of file numeric_vector.C.

328 {
329  const NumericVector<T> & v = *this;
330 
331  Real norm = 0;
332 
333  for (const auto & index : indices)
334  norm += TensorTools::norm_sq(v(index));
335 
336  this->comm().sum(norm);
337 
338  return std::sqrt(norm);
339 }

Referenced by libMesh::System::discrete_var_norm().

◆ subset_linfty_norm()

template<class T >
Real libMesh::NumericVector< T >::subset_linfty_norm ( const std::set< numeric_index_type > &  indices) const
virtualinherited
Returns
The maximum absolute value of the specified entries of this vector, which is the \( \ell_{\infty} \)-norm of a vector.
Note
The indices must necessarily live on this processor.

Definition at line 342 of file numeric_vector.C.

343 {
344  const NumericVector<T> & v = *this;
345 
346  Real norm = 0;
347 
348  for (const auto & index : indices)
349  {
350  Real value = std::abs(v(index));
351  if (value > norm)
352  norm = value;
353  }
354 
355  this->comm().max(norm);
356 
357  return norm;
358 }

Referenced by libMesh::System::discrete_var_norm().

◆ sum()

template<typename T >
T libMesh::PetscVector< T >::sum ( ) const
overridevirtual
Returns
The sum of all values in the vector.

Implements libMesh::NumericVector< T >.

Definition at line 48 of file petsc_vector.C.

49 {
50  this->_restore_array();
51  libmesh_assert(this->closed());
52 
53  PetscErrorCode ierr=0;
54  PetscScalar value=0.;
55 
56  ierr = VecSum (_vec, &value);
57  LIBMESH_CHKERR(ierr);
58 
59  return static_cast<T>(value);
60 }

◆ swap()

template<typename T>
void libMesh::PetscVector< T >::swap ( NumericVector< T > &  v)
inlineoverridevirtual

Swaps the contents of this with v.

There should be enough indirection in subclasses to make this an O(1) header-swap operation.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1194 of file petsc_vector.h.

1195 {
1196  parallel_object_only();
1197 
1198  NumericVector<T>::swap(other);
1199 
1200  PetscVector<T> & v = cast_ref<PetscVector<T> &>(other);
1201 
1202  std::swap(_vec, v._vec);
1203  std::swap(_destroy_vec_on_exit, v._destroy_vec_on_exit);
1204  std::swap(_global_to_local_map, v._global_to_local_map);
1205 
1206 #ifdef LIBMESH_HAVE_CXX11_THREAD
1207  // Only truly atomic for v... but swap() doesn't really need to be thread safe!
1208  _array_is_present = v._array_is_present.exchange(_array_is_present);
1209 #else
1210  std::swap(_array_is_present, v._array_is_present);
1211 #endif
1212 
1213  std::swap(_local_form, v._local_form);
1214  std::swap(_values, v._values);
1215 }

Referenced by libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), DMlibMeshFunction(), DMlibMeshJacobian(), libMesh::libmesh_petsc_snes_jacobian(), and libMesh::libmesh_petsc_snes_residual_helper().

◆ type() [1/2]

template<typename T>
ParallelType& libMesh::NumericVector< T >::type ( )
inlineinherited
Returns
The type (SERIAL, PARALLEL, GHOSTED) of the vector.

Definition at line 165 of file numeric_vector.h.

165 { return _type; }

◆ type() [2/2]

template<typename T>
ParallelType libMesh::NumericVector< T >::type ( ) const
inlineinherited

◆ vec() [1/2]

template<typename T>
Vec libMesh::PetscVector< T >::vec ( )
inline

◆ vec() [2/2]

template<typename T>
Vec libMesh::PetscVector< T >::vec ( ) const
inline

Definition at line 337 of file petsc_vector.h.

337 { libmesh_assert (_vec); return _vec; }

◆ zero()

template<typename T >
void libMesh::PetscVector< T >::zero ( )
inlineoverridevirtual

Set all entries to zero.

Equivalent to v = 0, but more obvious and faster.

Implements libMesh::NumericVector< T >.

Definition at line 873 of file petsc_vector.h.

874 {
875  parallel_object_only();
876 
877  libmesh_assert(this->closed());
878 
879  this->_restore_array();
880 
881  PetscErrorCode ierr=0;
882 
883  PetscScalar z=0.;
884 
885  if (this->type() != GHOSTED)
886  {
887  ierr = VecSet (_vec, z);
888  LIBMESH_CHKERR(ierr);
889  }
890  else
891  {
892  /* Vectors that include ghost values require a special
893  handling. */
894  Vec loc_vec;
895  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
896  LIBMESH_CHKERR(ierr);
897 
898  ierr = VecSet (loc_vec, z);
899  LIBMESH_CHKERR(ierr);
900 
901  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
902  LIBMESH_CHKERR(ierr);
903  }
904 }

Referenced by libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_residual(), and libMesh::TaoOptimizationSolver< T >::solve().

◆ zero_clone()

template<typename T >
std::unique_ptr< NumericVector< T > > libMesh::PetscVector< T >::zero_clone ( ) const
inlineoverridevirtual
Returns
A smart pointer to a copy of this vector with the same type, size, and partitioning, but with all zero entries.
Note
This must be overridden in the derived classes.

Implements libMesh::NumericVector< T >.

Definition at line 910 of file petsc_vector.h.

911 {
912  NumericVector<T> * cloned_vector = new PetscVector<T>(this->comm(), this->type());
913  cloned_vector->init(*this);
914  return std::unique_ptr<NumericVector<T>>(cloned_vector);
915 }

Member Data Documentation

◆ _array_is_present [1/2]

template<typename T>
std::atomic<bool> libMesh::PetscVector< T >::_array_is_present
mutableprivate

If true, the actual PETSc array of the values of the vector is currently accessible.

That means that the members _local_form and _values are valid.

Definition at line 354 of file petsc_vector.h.

Referenced by libMesh::PetscVector< libMesh::Number >::swap().

◆ _array_is_present [2/2]

template<typename T>
bool libMesh::PetscVector< T >::_array_is_present
mutableprivate

Definition at line 356 of file petsc_vector.h.

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _counts

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _destroy_vec_on_exit

template<typename T>
bool libMesh::PetscVector< T >::_destroy_vec_on_exit
private

This boolean value should only be set to false for the constructor which takes a PETSc Vec object.

Definition at line 445 of file petsc_vector.h.

Referenced by libMesh::PetscVector< libMesh::Number >::swap().

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 141 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

◆ _first

template<typename T>
numeric_index_type libMesh::PetscVector< T >::_first
mutableprivate

First local index.

Only valid when _array_is_present

Definition at line 364 of file petsc_vector.h.

◆ _global_to_local_map

template<typename T>
GlobalToLocalMap libMesh::PetscVector< T >::_global_to_local_map
private

Map that maps global to local ghost cells (will be empty if not in ghost cell mode).

Definition at line 439 of file petsc_vector.h.

Referenced by libMesh::PetscVector< libMesh::Number >::init(), and libMesh::PetscVector< libMesh::Number >::swap().

◆ _is_closed

template<typename T>
bool libMesh::NumericVector< T >::_is_closed
protectedinherited

Flag which tracks whether the vector's values are consistent on all processors after insertion or addition of values has occurred on some or all processors.

Definition at line 727 of file numeric_vector.h.

Referenced by libMesh::NumericVector< Number >::closed(), libMesh::EpetraVector< T >::EpetraVector(), libMesh::DistributedVector< T >::localize(), and libMesh::DistributedVector< T >::operator=().

◆ _is_initialized

template<typename T>
bool libMesh::NumericVector< T >::_is_initialized
protectedinherited

◆ _last

template<typename T>
numeric_index_type libMesh::PetscVector< T >::_last
mutableprivate

Last local index.

Only valid when _array_is_present

Definition at line 371 of file petsc_vector.h.

◆ _local_form

template<typename T>
Vec libMesh::PetscVector< T >::_local_form
mutableprivate

PETSc vector datatype to hold the local form of a ghosted vector.

The contents of this field are only valid if the vector is ghosted and _array_is_present is true.

Definition at line 383 of file petsc_vector.h.

Referenced by libMesh::PetscVector< libMesh::Number >::swap().

◆ _local_size

template<typename T>
numeric_index_type libMesh::PetscVector< T >::_local_size
mutableprivate

Size of the local values from _get_array()

Definition at line 376 of file petsc_vector.h.

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 130 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

◆ _petsc_vector_mutex [1/2]

template<typename T>
std::mutex libMesh::PetscVector< T >::_petsc_vector_mutex
mutableprivate

Mutex for _get_array and _restore_array.

This is part of the object to keep down thread contention when reading frmo multiple PetscVectors simultaneously

Definition at line 411 of file petsc_vector.h.

◆ _petsc_vector_mutex [2/2]

template<typename T>
Threads::spin_mutex libMesh::PetscVector< T >::_petsc_vector_mutex
mutableprivate

Definition at line 413 of file petsc_vector.h.

◆ _read_only_values

template<typename T>
const PetscScalar* libMesh::PetscVector< T >::_read_only_values
mutableprivate

Pointer to the actual PETSc array of the values of the vector.

This pointer is only valid if _array_is_present is true. We're using PETSc's VecGetArrayRead() function, which requires a constant PetscScalar *, but _get_array and _restore_array are const member functions, so _values also needs to be mutable (otherwise it is a "const PetscScalar * const" in that context).

Definition at line 393 of file petsc_vector.h.

◆ _type

template<typename T>
ParallelType libMesh::NumericVector< T >::_type
protectedinherited

◆ _values

template<typename T>
PetscScalar* libMesh::PetscVector< T >::_values
mutableprivate

Pointer to the actual PETSc array of the values of the vector.

This pointer is only valid if _array_is_present is true. We're using PETSc's VecGetArrayRead() function, which requires a constant PetscScalar *, but _get_array and _restore_array are const member functions, so _values also needs to be mutable (otherwise it is a "const PetscScalar * const" in that context).

Definition at line 403 of file petsc_vector.h.

Referenced by libMesh::PetscVector< libMesh::Number >::swap().

◆ _values_manually_retrieved

template<typename T>
bool libMesh::PetscVector< T >::_values_manually_retrieved
mutableprivate

Whether or not the data array has been manually retrieved using get_array() or get_array_read()

Definition at line 451 of file petsc_vector.h.

◆ _values_read_only

template<typename T>
bool libMesh::PetscVector< T >::_values_read_only
mutableprivate

Whether or not the data array is for read only access.

Definition at line 456 of file petsc_vector.h.

◆ _vec

template<typename T>
Vec libMesh::PetscVector< T >::_vec
private

The documentation for this class was generated from the following files:
libMesh::NumericVector::add
virtual void add(const numeric_index_type i, const T value)=0
Adds value to each entry of the vector.
libMesh::PetscVector::map_global_to_local_index
numeric_index_type map_global_to_local_index(const numeric_index_type i) const
Definition: petsc_vector.h:1018
libMesh::PETSC_SOLVERS
Definition: enum_solver_package.h:36
libMesh::PARALLEL
Definition: enum_parallel_type.h:36
libMesh::PetscVector::last_local_index
virtual numeric_index_type last_local_index() const override
Definition: petsc_vector.h:994
libMesh::NumericVector::swap
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v.
Definition: numeric_vector.h:989
libMesh::SERIAL
Definition: enum_parallel_type.h:35
libMesh::NumericVector::last_local_index
virtual numeric_index_type last_local_index() const =0
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh::pPS
PetscScalar * pPS(T *ptr)
Definition: petsc_macro.h:174
end
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end.
Definition: variant_filter_iterator.h:343
libMesh::ReferenceCounter::_counts
static Counts _counts
Actually holds the data.
Definition: reference_counter.h:122
std::sqrt
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::PetscVector::init
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
Change the dimension of the vector to n.
Definition: petsc_vector.h:640
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::PetscVector::_first
numeric_index_type _first
First local index.
Definition: petsc_vector.h:364
libMesh::GHOSTED
Definition: enum_parallel_type.h:37
libMesh::ReferenceCounter::_n_objects
static Threads::atomic< unsigned int > _n_objects
The number of objects.
Definition: reference_counter.h:130
libMesh::NumericVector::_is_initialized
bool _is_initialized
true once init() has been called.
Definition: numeric_vector.h:732
libMesh::NumericVector::_is_closed
bool _is_closed
Flag which tracks whether the vector's values are consistent on all processors after insertion or add...
Definition: numeric_vector.h:727
libMesh::ierr
ierr
Definition: petsc_dm_wrapper.C:72
libMesh::ReferenceCounter::get_info
static std::string get_info()
Gets a string containing the reference information.
Definition: reference_counter.C:47
libMesh::PetscVector::_values_manually_retrieved
bool _values_manually_retrieved
Whether or not the data array has been manually retrieved using get_array() or get_array_read()
Definition: petsc_vector.h:451
libMesh::NumericVector::insert
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
Inserts the entries of v in *this at the locations specified by v.
Definition: numeric_vector.C:83
libMesh::NumericVector::closed
virtual bool closed() const
Definition: numeric_vector.h:171
libMesh::NumericVector::size
virtual numeric_index_type size() const =0
PETSC_USE_POINTER
Definition: petsc_macro.h:103
libMesh::NumericVector::_type
ParallelType _type
Type of vector.
Definition: numeric_vector.h:737
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::NumericVector::add_vector
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i].
Definition: numeric_vector.C:363
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::NumericVector::localize
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.
libMesh::PetscVector::close
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
Definition: petsc_vector.h:821
libMesh::numeric_petsc_cast
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
Definition: petsc_vector.h:1228
libMesh::ParallelObject::n_processors
processor_id_type n_processors() const
Definition: parallel_object.h:100
libMesh::PS
PetscScalar PS(T val)
Definition: petsc_macro.h:168
libMesh::NumericVector::initialized
virtual bool initialized() const
Definition: numeric_vector.h:155
libMesh::Utility::iota
void iota(ForwardIter first, ForwardIter last, T value)
Utility::iota is a duplication of the SGI STL extension std::iota.
Definition: utility.h:105
libMesh::Threads::spin_mtx
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:29
libMesh::ParallelObject::processor_id
processor_id_type processor_id() const
Definition: parallel_object.h:106
libMesh::ParallelObject::_communicator
const Parallel::Communicator & _communicator
Definition: parallel_object.h:112
libMesh::MeshTools::Generation::Private::idx
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
A useful inline function which replaces the macros used previously.
Definition: mesh_generation.C:72
libMesh::NumericVector::local_size
virtual numeric_index_type local_size() const =0
A
static PetscErrorCode Mat * A
Definition: petscdmlibmeshimpl.C:1026
libMesh::LASPACK_SOLVERS
Definition: enum_solver_package.h:38
libMesh::PetscVector::first_local_index
virtual numeric_index_type first_local_index() const override
Definition: petsc_vector.h:970
libMesh::PetscVector::zero
virtual void zero() override
Set all entries to zero.
Definition: petsc_vector.h:873
libMesh::PetscVector::_destroy_vec_on_exit
bool _destroy_vec_on_exit
This boolean value should only be set to false for the constructor which takes a PETSc Vec object.
Definition: petsc_vector.h:445
libMesh::is
PetscErrorCode PetscInt const PetscInt IS * is
Definition: petsc_dm_wrapper.C:60
libMesh::PetscVector::_get_array
void _get_array(bool read_only) const
Queries the array (and the local form if the vector is ghosted) from PETSc.
Definition: petsc_vector.C:1374
libMesh::PetscVector::size
virtual numeric_index_type size() const override
Definition: petsc_vector.h:933
libMesh::numeric_index_type
dof_id_type numeric_index_type
Definition: id_types.h:99
libMesh::Complex
std::complex< Real > Complex
Definition: libmesh_common.h:160
libMesh::NumericVector::linfty_norm
virtual Real linfty_norm() const =0
libMesh::TRILINOS_SOLVERS
Definition: enum_solver_package.h:37
libMesh::PetscVector::local_size
virtual numeric_index_type local_size() const override
Definition: petsc_vector.h:953
swap
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
Definition: variant_filter_iterator.h:478
libMesh::PetscVector::_local_size
numeric_index_type _local_size
Size of the local values from _get_array()
Definition: petsc_vector.h:376
libMesh::TensorTools::norm_sq
T norm_sq(std::complex< T > a)
Definition: tensor_tools.h:85
libMesh::PetscVector::add
virtual void add(const numeric_index_type i, const T value) override
Adds value to each entry of the vector.
Definition: petsc_vector.C:187
libMesh::NumericVector::set
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
value
static const bool value
Definition: xdr_io.C:56
libMesh::PetscVector::_values_read_only
bool _values_read_only
Whether or not the data array is for read only access.
Definition: petsc_vector.h:456
libMesh::PetscVector::_restore_array
void _restore_array() const
Restores the array (and the local form if the vector is ghosted) to PETSc.
Definition: petsc_vector.C:1478
libMesh::ctx
void * ctx
Definition: petsc_dm_wrapper.C:71
libMesh::PetscVector::_vec
Vec _vec
Actual PETSc vector datatype to hold vector entries.
Definition: petsc_vector.h:345
libMesh::PetscVector::_values
PetscScalar * _values
Pointer to the actual PETSc array of the values of the vector.
Definition: petsc_vector.h:403
libMesh::PetscVector::_last
numeric_index_type _last
Last local index.
Definition: petsc_vector.h:371
libMesh::NumericVector::scale
virtual void scale(const T factor)=0
Scale each element of the vector by the given factor.
std::norm
MetaPhysicL::DualNumber< T, D > norm(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::AUTOMATIC
Definition: enum_parallel_type.h:34
libMesh::PetscVector::_read_only_values
const PetscScalar * _read_only_values
Pointer to the actual PETSc array of the values of the vector.
Definition: petsc_vector.h:393
libMesh::PetscVector::get
virtual void get(const std::vector< numeric_index_type > &index, T *values) const override
Access multiple components at once.
Definition: petsc_vector.h:1098
libMesh::PetscVector::vec
Vec vec()
Definition: petsc_vector.h:335
libMesh::NumericVector::get
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
Access multiple components at once.
Definition: numeric_vector.h:821
libMesh::PetscVector::clear
virtual void clear() override
Restores the NumericVector<T> to a pristine state.
Definition: petsc_vector.h:849
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::ReferenceCounter::_enable_print_counter
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called.
Definition: reference_counter.h:141
libMesh::PetscVector::_global_to_local_map
GlobalToLocalMap _global_to_local_map
Map that maps global to local ghost cells (will be empty if not in ghost cell mode).
Definition: petsc_vector.h:439
libMesh::NumericVector::type
ParallelType type() const
Definition: numeric_vector.h:160
libMesh::EIGEN_SOLVERS
Definition: enum_solver_package.h:40
libMesh::PetscVector::_petsc_vector_mutex
std::mutex _petsc_vector_mutex
Mutex for _get_array and _restore_array.
Definition: petsc_vector.h:411
libMesh::PetscVector::_array_is_present
std::atomic< bool > _array_is_present
If true, the actual PETSc array of the values of the vector is currently accessible.
Definition: petsc_vector.h:354
std::imag
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
Definition: float128_shims.h:83
libMesh::PetscVector::_local_form
Vec _local_form
PETSc vector datatype to hold the local form of a ghosted vector.
Definition: petsc_vector.h:383
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::NumericVector::first_local_index
virtual numeric_index_type first_local_index() const =0
std::real
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
Definition: float128_shims.h:77