libMesh::PetscVector< T > Class Template Reference

NumericVector interface to PETSc Vec. More...

#include <petsc_vector.h>

Inheritance diagram for libMesh::PetscVector< T >:

Public Member Functions

 PetscVector (const Parallel::Communicator &comm_in, const ParallelType type=AUTOMATIC)
 
 PetscVector (const Parallel::Communicator &comm_in, const numeric_index_type n, const ParallelType type=AUTOMATIC)
 
 PetscVector (const Parallel::Communicator &comm_in, const numeric_index_type n, const numeric_index_type n_local, const ParallelType type=AUTOMATIC)
 
 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)
 
 PetscVector (Vec v, const Parallel::Communicator &comm_in LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
 
 ~PetscVector ()
 
virtual void close () libmesh_override
 
virtual void clear () libmesh_override
 
virtual void zero () libmesh_override
 
virtual UniquePtr< NumericVector< T > > zero_clone () const libmesh_override
 
virtual UniquePtr< NumericVector< T > > clone () const libmesh_override
 
virtual void init (const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) libmesh_override
 
virtual void init (const numeric_index_type N, const bool fast=false, const ParallelType type=AUTOMATIC) libmesh_override
 
virtual void init (const numeric_index_type, const numeric_index_type, const std::vector< numeric_index_type > &, const bool=false, const ParallelType=AUTOMATIC) libmesh_override
 
virtual void init (const NumericVector< T > &other, const bool fast=false) libmesh_override
 
virtual NumericVector< T > & operator= (const T s) libmesh_override
 
virtual NumericVector< T > & operator= (const NumericVector< T > &V) libmesh_override
 
PetscVector< T > & operator= (const PetscVector< T > &V)
 
virtual NumericVector< T > & operator= (const std::vector< T > &v) libmesh_override
 
virtual Real min () const libmesh_override
 
virtual Real max () const libmesh_override
 
virtual T sum () const libmesh_override
 
virtual Real l1_norm () const libmesh_override
 
virtual Real l2_norm () const libmesh_override
 
virtual Real linfty_norm () const libmesh_override
 
virtual numeric_index_type size () const libmesh_override
 
virtual numeric_index_type local_size () const libmesh_override
 
virtual numeric_index_type first_local_index () const libmesh_override
 
virtual numeric_index_type last_local_index () const libmesh_override
 
numeric_index_type map_global_to_local_index (const numeric_index_type i) const
 
virtual T operator() (const numeric_index_type i) const libmesh_override
 
virtual void get (const std::vector< numeric_index_type > &index, T *values) const libmesh_override
 
PetscScalar * get_array ()
 
const PetscScalar * get_array_read () const
 
void restore_array ()
 
virtual NumericVector< T > & operator+= (const NumericVector< T > &V) libmesh_override
 
virtual NumericVector< T > & operator-= (const NumericVector< T > &V) libmesh_override
 
virtual void reciprocal () libmesh_override
 
virtual void conjugate () libmesh_override
 
virtual void set (const numeric_index_type i, const T value) libmesh_override
 
virtual void add (const numeric_index_type i, const T value) libmesh_override
 
virtual void add (const T s) libmesh_override
 
virtual void add (const NumericVector< T > &V) libmesh_override
 
virtual void add (const T a, const NumericVector< T > &v) libmesh_override
 
virtual void add_vector (const T *v, const std::vector< numeric_index_type > &dof_indices) libmesh_override
 
virtual void add_vector (const NumericVector< T > &V, const SparseMatrix< T > &A) libmesh_override
 
virtual void add_vector_transpose (const NumericVector< T > &V, const SparseMatrix< T > &A_trans) libmesh_override
 
void add_vector_conjugate_transpose (const NumericVector< T > &V, const SparseMatrix< T > &A_trans)
 
virtual void insert (const T *v, const std::vector< numeric_index_type > &dof_indices) libmesh_override
 
virtual void scale (const T factor) libmesh_override
 
virtual NumericVector< T > & operator/= (NumericVector< T > &v) libmesh_override
 
virtual void abs () libmesh_override
 
virtual T dot (const NumericVector< T > &) const libmesh_override
 
indefinite_dot (const NumericVector< T > &) const
 
virtual void localize (std::vector< T > &v_local) const libmesh_override
 
virtual void localize (NumericVector< T > &v_local) const libmesh_override
 
virtual void localize (NumericVector< T > &v_local, const std::vector< numeric_index_type > &send_list) const libmesh_override
 
virtual void localize (std::vector< T > &v_local, const std::vector< numeric_index_type > &indices) const libmesh_override
 
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) libmesh_override
 
virtual void localize_to_one (std::vector< T > &v_local, const processor_id_type proc_id=0) const libmesh_override
 
virtual void pointwise_mult (const NumericVector< T > &vec1, const NumericVector< T > &vec2) libmesh_override
 
virtual void print_matlab (const std::string &name="") const libmesh_override
 
virtual void create_subvector (NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows) const libmesh_override
 
virtual void swap (NumericVector< T > &v) libmesh_override
 
Vec vec ()
 
template<>
void localize_to_one (std::vector< Real > &v_local, const processor_id_type 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
 
NumericVector< T > & operator*= (const T a)
 
NumericVector< T > & operator/= (const T a)
 
void add_vector (const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 
virtual void add_vector (const NumericVector< T > &V, const std::vector< numeric_index_type > &dof_indices)
 
void add_vector (const DenseVector< T > &V, const std::vector< numeric_index_type > &dof_indices)
 
void add_vector (const NumericVector< T > &v, const ShellMatrix< T > &a)
 
void insert (const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 
virtual void insert (const NumericVector< T > &V, const std::vector< numeric_index_type > &dof_indices)
 
void insert (const DenseVector< T > &V, const std::vector< numeric_index_type > &dof_indices)
 
void insert (const DenseSubVector< T > &V, const std::vector< numeric_index_type > &dof_indices)
 
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
 
template<>
void print (std::ostream &os) const
 
virtual void print_global (std::ostream &os=libMesh::out) const
 
template<>
void print_global (std::ostream &os) const
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static UniquePtr< NumericVector< T > > build (const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
 
static UniquePtr< NumericVector< T > > build (const SolverPackage solver_package=libMesh::default_solver_package())
 
static std::string get_info ()
 
static void print_info (std::ostream &out=libMesh::out)
 
static unsigned int n_objects ()
 
static void enable_print_counter_info ()
 
static void disable_print_counter_info ()
 

Protected Types

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

Protected Member Functions

void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

bool _is_closed
 
bool _is_initialized
 
ParallelType _type
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 
static Threads::atomic< unsigned int > _n_objects
 
static Threads::spin_mutex _mutex
 
static bool _enable_print_counter = true
 

Private Types

typedef LIBMESH_BEST_UNORDERED_MAP< numeric_index_type, numeric_index_typeGlobalToLocalMap
 

Private Member Functions

void _get_array (bool read_only) const
 
void _restore_array () const
 

Private Attributes

Vec _vec
 
std::atomic< bool > _array_is_present
 
bool _array_is_present
 
numeric_index_type _first
 
numeric_index_type _last
 
numeric_index_type _local_size
 
Vec _local_form
 
const PetscScalar * _read_only_values
 
PetscScalar * _values
 
std::mutex _petsc_vector_mutex
 
Threads::spin_mutex _petsc_vector_mutex
 
GlobalToLocalMap _global_to_local_map
 
bool _destroy_vec_on_exit
 
bool _values_manually_retrieved
 
bool _values_read_only
 

Detailed Description

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

NumericVector interface to PETSc Vec.

Petsc vector. Provides a nice interface to the Petsc C-based data structures for parallel vectors.

Author
Benjamin S. Kirk
Date
2002

Definition at line 64 of file petsc_vector.h.

Member Typedef Documentation

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 110 of file reference_counter.h.

template<typename T>
typedef LIBMESH_BEST_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 628 of file petsc_vector.h.

Constructor & Destructor Documentation

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

Dummy-Constructor. Dimension=0

Definition at line 661 of file petsc_vector.h.

References libMesh::NumericVector< T >::_type.

Referenced by libMesh::PetscVector< T >::PetscVector().

661  :
662  NumericVector<T>(comm_in, ptype),
663  _array_is_present(false),
664  _first(0),
665  _last(0),
669  _destroy_vec_on_exit(true),
671  _values_read_only(false)
672 {
673  this->_type = ptype;
674 }
numeric_index_type _last
Definition: petsc_vector.h:566
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:598
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:634
numeric_index_type _first
Definition: petsc_vector.h:559
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 680 of file petsc_vector.h.

References libMesh::PetscVector< T >::init().

682  :
683  NumericVector<T>(comm_in, ptype),
684  _array_is_present(false),
688  _destroy_vec_on_exit(true),
690  _values_read_only(false)
691 {
692  this->init(n, n, false, ptype);
693 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) libmesh_override
Definition: petsc_vector.h:835
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:598
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:634
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 699 of file petsc_vector.h.

References libMesh::PetscVector< T >::init().

702  :
703  NumericVector<T>(comm_in, ptype),
704  _array_is_present(false),
708  _destroy_vec_on_exit(true),
710  _values_read_only(false)
711 {
712  this->init(n, n_local, false, ptype);
713 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) libmesh_override
Definition: petsc_vector.h:835
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:598
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:634
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 719 of file petsc_vector.h.

References libMesh::PetscVector< T >::_array_is_present, libMesh::PetscVector< T >::_destroy_vec_on_exit, libMesh::PetscVector< T >::_global_to_local_map, libMesh::NumericVector< T >::_is_closed, libMesh::NumericVector< T >::_is_initialized, libMesh::PetscVector< T >::_local_form, libMesh::NumericVector< T >::_type, libMesh::PetscVector< T >::_values, libMesh::PetscVector< T >::_values_manually_retrieved, libMesh::PetscVector< T >::_values_read_only, libMesh::PetscVector< T >::_vec, libMesh::AUTOMATIC, libMesh::GHOSTED, ierr, libMesh::PetscVector< T >::init(), libmesh_nullptr, libMesh::PARALLEL, libMesh::PetscVector< T >::PetscVector(), and libMesh::SERIAL.

723  :
724  NumericVector<T>(comm_in, ptype),
725  _array_is_present(false),
729  _destroy_vec_on_exit(true),
731  _values_read_only(false)
732 {
733  this->init(n, n_local, ghost, false, ptype);
734 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) libmesh_override
Definition: petsc_vector.h:835
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:598
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:634
template<typename T>
libMesh::PetscVector< T >::PetscVector ( Vec  v,
const Parallel::Communicator &comm_in  LIBMESH_CAN_DEFAULT_TO_COMMWORLD 
)

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.

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

Destructor, deallocates memory. Made virtual to allow for derived classes to behave properly.

Definition at line 826 of file petsc_vector.h.

References libMesh::PetscVector< T >::clear().

827 {
828  this->clear ();
829 }
virtual void clear() libmesh_override

Member Function Documentation

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 1327 of file petsc_vector.C.

References libMesh::GHOSTED, ierr, libMesh::initialized(), and libMesh::libmesh_assert().

Referenced by libMesh::PetscVector< T >::get(), libMesh::PetscVector< T >::get_array(), libMesh::PetscVector< T >::get_array_read(), and libMesh::PetscVector< T >::operator()().

1328 {
1329  libmesh_assert (this->initialized());
1330 
1331 #ifdef LIBMESH_HAVE_CXX11_THREAD
1332  std::atomic_thread_fence(std::memory_order_acquire);
1333 #else
1334  Threads::spin_mutex::scoped_lock lock(_petsc_vector_mutex);
1335 #endif
1336 
1337  // If the values have already been retrieved and we're currently
1338  // trying to get a non-read only view (ie read/write) and the
1339  // values are currently read only... then we need to restore
1340  // the array first... and then retrieve it again.
1341  if (_array_is_present && !read_only && _values_read_only)
1342  _restore_array();
1343 
1344  // If we already have a read/write array - and we're trying
1345  // to get a read only array - let's just use the read write
1346  if (_array_is_present && read_only && !_values_read_only)
1348 
1349  if (!_array_is_present)
1350  {
1351 #ifdef LIBMESH_HAVE_CXX11_THREAD
1352  std::lock_guard<std::mutex> lock(_petsc_vector_mutex);
1353 #endif
1354  if (!_array_is_present)
1355  {
1356  PetscErrorCode ierr=0;
1357  if(this->type() != GHOSTED)
1358  {
1359 #if PETSC_VERSION_LESS_THAN(3,2,0)
1360  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1361  // have an older PETSc than that, we'll do an ugly
1362  // const_cast and call VecGetArray() instead.
1363  ierr = VecGetArray(_vec, const_cast<PetscScalar **>(&_values));
1364  _values_read_only = false;
1365 #else
1366  if (read_only)
1367  {
1368  ierr = VecGetArrayRead(_vec, &_read_only_values);
1369  _values_read_only = true;
1370  }
1371  else
1372  {
1373  ierr = VecGetArray(_vec, &_values);
1374  _values_read_only = false;
1375  }
1376 #endif
1377  LIBMESH_CHKERR(ierr);
1378  _local_size = this->local_size();
1379  }
1380  else
1381  {
1382  ierr = VecGhostGetLocalForm (_vec,&_local_form);
1383  LIBMESH_CHKERR(ierr);
1384 
1385 #if PETSC_VERSION_LESS_THAN(3,2,0)
1386  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1387  // have an older PETSc than that, we'll do an ugly
1388  // const_cast and call VecGetArray() instead.
1389  ierr = VecGetArray(_local_form, const_cast<PetscScalar **>(&_values));
1390  _values_read_only = false;
1391 #else
1392  if (read_only)
1393  {
1394  ierr = VecGetArrayRead(_local_form, &_read_only_values);
1395  _values_read_only = true;
1396  }
1397  else
1398  {
1399  ierr = VecGetArray(_local_form, &_values);
1400  _values_read_only = false;
1401  }
1402 #endif
1403  LIBMESH_CHKERR(ierr);
1404 
1405  PetscInt my_local_size = 0;
1406  ierr = VecGetLocalSize(_local_form, &my_local_size);
1407  LIBMESH_CHKERR(ierr);
1408  _local_size = static_cast<numeric_index_type>(my_local_size);
1409  }
1410 
1411  { // cache ownership range
1412  PetscInt petsc_first=0, petsc_last=0;
1413  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1414  LIBMESH_CHKERR(ierr);
1415  _first = static_cast<numeric_index_type>(petsc_first);
1416  _last = static_cast<numeric_index_type>(petsc_last);
1417  }
1418 #ifdef LIBMESH_HAVE_CXX11_THREAD
1419  std::atomic_thread_fence(std::memory_order_release);
1420  _array_is_present.store(true, std::memory_order_relaxed);
1421 #else
1422  _array_is_present = true;
1423 #endif
1424  }
1425  }
1426 }
numeric_index_type _local_size
Definition: petsc_vector.h:571
numeric_index_type _last
Definition: petsc_vector.h:566
PetscScalar * _values
Definition: petsc_vector.h:598
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
libmesh_assert(j)
std::mutex _petsc_vector_mutex
Definition: petsc_vector.h:606
const PetscScalar * _read_only_values
Definition: petsc_vector.h:588
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
PetscErrorCode ierr
virtual numeric_index_type local_size() const libmesh_override
ParallelType type() const
numeric_index_type _first
Definition: petsc_vector.h:559
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 1431 of file petsc_vector.C.

References libMesh::GHOSTED, ierr, libMesh::initialized(), libMesh::libmesh_assert(), and libmesh_nullptr.

Referenced by libMesh::PetscVector< T >::add(), libMesh::PetscVector< T >::clear(), libMesh::PetscVector< T >::close(), libMesh::PetscVector< T >::create_subvector(), libMesh::PetscVector< T >::init(), libMesh::PetscVector< T >::max(), libMesh::PetscVector< T >::min(), libMesh::PetscVector< T >::operator=(), libMesh::PetscVector< T >::restore_array(), and libMesh::PetscVector< T >::zero().

1432 {
1434  libmesh_error_msg("PetscVector values were manually retrieved but are being automatically restored!");
1435 
1436 #ifdef LIBMESH_HAVE_CXX11_THREAD
1437  std::atomic_thread_fence(std::memory_order_acquire);
1438 #else
1439  Threads::spin_mutex::scoped_lock lock(_petsc_vector_mutex);
1440 #endif
1441 
1442  libmesh_assert (this->initialized());
1443  if (_array_is_present)
1444  {
1445 #ifdef LIBMESH_HAVE_CXX11_THREAD
1446  std::lock_guard<std::mutex> lock(_petsc_vector_mutex);
1447 #endif
1448 
1449  if (_array_is_present)
1450  {
1451  PetscErrorCode ierr=0;
1452  if(this->type() != GHOSTED)
1453  {
1454 #if PETSC_VERSION_LESS_THAN(3,2,0)
1455  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1456  // have an older PETSc than that, we'll do an ugly
1457  // const_cast and call VecRestoreArray() instead.
1458  ierr = VecRestoreArray (_vec, const_cast<PetscScalar **>(&_values));
1459 #else
1460  if (_values_read_only)
1461  ierr = VecRestoreArrayRead (_vec, &_read_only_values);
1462  else
1463  ierr = VecRestoreArray (_vec, &_values);
1464 #endif
1465 
1466  LIBMESH_CHKERR(ierr);
1468  }
1469  else
1470  {
1471 #if PETSC_VERSION_LESS_THAN(3,2,0)
1472  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1473  // have an older PETSc than that, we'll do an ugly
1474  // const_cast and call VecRestoreArray() instead.
1475  ierr = VecRestoreArray (_local_form, const_cast<PetscScalar **>(&_values));
1476 #else
1477  if (_values_read_only)
1478  ierr = VecRestoreArrayRead (_local_form, &_read_only_values);
1479  else
1480  ierr = VecRestoreArray (_local_form, &_values);
1481 #endif
1482  LIBMESH_CHKERR(ierr);
1484  ierr = VecGhostRestoreLocalForm (_vec,&_local_form);
1485  LIBMESH_CHKERR(ierr);
1487  _local_size = 0;
1488  }
1489 #ifdef LIBMESH_HAVE_CXX11_THREAD
1490  std::atomic_thread_fence(std::memory_order_release);
1491  _array_is_present.store(false, std::memory_order_relaxed);
1492 #else
1493  _array_is_present = false;
1494 #endif
1495  }
1496  }
1497 }
numeric_index_type _local_size
Definition: petsc_vector.h:571
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:598
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
libmesh_assert(j)
std::mutex _petsc_vector_mutex
Definition: petsc_vector.h:606
const PetscScalar * _read_only_values
Definition: petsc_vector.h:588
PetscErrorCode ierr
ParallelType type() const
template<typename T >
void libMesh::PetscVector< T >::abs ( )
virtual

v = abs(v)... that is, each entry in v is replaced by its absolute value.

Implements libMesh::NumericVector< T >.

Definition at line 418 of file petsc_vector.C.

References libMesh::GHOSTED, and ierr.

419 {
420  this->_restore_array();
421 
422  PetscErrorCode ierr = 0;
423 
424  if(this->type() != GHOSTED)
425  {
426  ierr = VecAbs(_vec);
427  LIBMESH_CHKERR(ierr);
428  }
429  else
430  {
431  Vec loc_vec;
432  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
433  LIBMESH_CHKERR(ierr);
434 
435  ierr = VecAbs(loc_vec);
436  LIBMESH_CHKERR(ierr);
437 
438  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
439  LIBMESH_CHKERR(ierr);
440  }
441 }
void _restore_array() const
PetscErrorCode ierr
ParallelType type() const
template<typename T >
void libMesh::PetscVector< T >::add ( const numeric_index_type  i,
const T  value 
)
virtual

v(i) += value

Implements libMesh::NumericVector< T >.

Definition at line 180 of file petsc_vector.C.

References ierr.

181 {
182  this->_restore_array();
183  libmesh_assert_less (i, size());
184 
185  PetscErrorCode ierr=0;
186  PetscInt i_val = static_cast<PetscInt>(i);
187  PetscScalar petsc_value = static_cast<PetscScalar>(value);
188 
189  ierr = VecSetValues (_vec, 1, &i_val, &petsc_value, ADD_VALUES);
190  LIBMESH_CHKERR(ierr);
191 
192  this->_is_closed = false;
193 }
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
PetscErrorCode ierr
template<typename T >
void libMesh::PetscVector< T >::add ( const T  s)
virtual

$U(0-LIBMESH_DIM)+=s$. Addition of s to all components. Note that s is a scalar and not a vector.

Implements libMesh::NumericVector< T >.

Definition at line 300 of file petsc_vector.C.

301 {
302  this->_get_array(false);
303 
304  for (numeric_index_type i=0; i<_local_size; i++)
305  _values[i] += v_in;
306 }
void _get_array(bool read_only) const
numeric_index_type _local_size
Definition: petsc_vector.h:571
PetscScalar * _values
Definition: petsc_vector.h:598
dof_id_type numeric_index_type
Definition: id_types.h:92
template<typename T >
void libMesh::PetscVector< T >::add ( const NumericVector< T > &  V)
virtual

$ U+=V $ . Simple vector addition, equal to the operator +=.

Implements libMesh::NumericVector< T >.

Definition at line 311 of file petsc_vector.C.

312 {
313  this->add (1., v);
314 }
virtual void add(const numeric_index_type i, const T value) libmesh_override
Definition: petsc_vector.C:180
template<typename T >
void libMesh::PetscVector< T >::add ( const T  a,
const NumericVector< T > &  v 
)
virtual

$ U+=a*V $ . Simple vector addition, equal to the operator +=.

Implements libMesh::NumericVector< T >.

Definition at line 319 of file petsc_vector.C.

References libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, libMesh::GHOSTED, ierr, and libMesh::PetscVector< T >::size().

320 {
321  this->_restore_array();
322 
323  PetscErrorCode ierr = 0;
324  PetscScalar a = static_cast<PetscScalar>(a_in);
325 
326  // Make sure the NumericVector passed in is really a PetscVector
327  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
328  v->_restore_array();
329 
330  libmesh_assert_equal_to (this->size(), v->size());
331 
332  if(this->type() != GHOSTED)
333  {
334  ierr = VecAXPY(_vec, a, v->_vec);
335  LIBMESH_CHKERR(ierr);
336  }
337  else
338  {
339  Vec loc_vec;
340  Vec v_loc_vec;
341  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
342  LIBMESH_CHKERR(ierr);
343  ierr = VecGhostGetLocalForm (v->_vec,&v_loc_vec);
344  LIBMESH_CHKERR(ierr);
345 
346  ierr = VecAXPY(loc_vec, a, v_loc_vec);
347  LIBMESH_CHKERR(ierr);
348 
349  ierr = VecGhostRestoreLocalForm (v->_vec,&v_loc_vec);
350  LIBMESH_CHKERR(ierr);
351  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
352  LIBMESH_CHKERR(ierr);
353  }
354 }
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
PetscErrorCode ierr
ParallelType type() const
template<typename T >
void libMesh::PetscVector< T >::add_vector ( const T *  v,
const std::vector< numeric_index_type > &  dof_indices 
)
virtual

$ U+=v $ where v is a pointer and each dof_indices[i] specifies where to add value v[i]

Reimplemented from libMesh::NumericVector< T >.

Definition at line 198 of file petsc_vector.C.

References ierr.

200 {
201  // If we aren't adding anything just return
202  if(dof_indices.empty())
203  return;
204 
205  this->_restore_array();
206 
207  PetscErrorCode ierr=0;
208  const PetscInt * i_val = reinterpret_cast<const PetscInt *>(&dof_indices[0]);
209  const PetscScalar * petsc_value = static_cast<const PetscScalar *>(v);
210 
211  ierr = VecSetValues (_vec, cast_int<PetscInt>(dof_indices.size()),
212  i_val, petsc_value, ADD_VALUES);
213  LIBMESH_CHKERR(ierr);
214 
215  this->_is_closed = false;
216 }
void _restore_array() const
PetscErrorCode ierr
template<typename T >
void libMesh::PetscVector< T >::add_vector ( const NumericVector< T > &  V,
const SparseMatrix< T > &  A 
)
virtual

$U+=A*V$, add the product of a SparseMatrix A and a NumericVector V to this, where this=U.

Implements libMesh::NumericVector< T >.

Definition at line 221 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, A, and ierr.

223 {
224  this->_restore_array();
225  // Make sure the data passed in are really of Petsc types
226  const PetscVector<T> * V = cast_ptr<const PetscVector<T> *>(&V_in);
227  const PetscMatrix<T> * A = cast_ptr<const PetscMatrix<T> *>(&A_in);
228 
229  PetscErrorCode ierr=0;
230 
231  A->close();
232 
233  // The const_cast<> is not elegant, but it is required since PETSc
234  // is not const-correct.
235  ierr = MatMultAdd(const_cast<PetscMatrix<T> *>(A)->mat(), V->_vec, _vec, _vec);
236  LIBMESH_CHKERR(ierr);
237 }
void _restore_array() const
PetscErrorCode ierr
static PetscErrorCode Mat * A
template<typename T>
void libMesh::NumericVector< T >::add_vector ( const std::vector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

$ U+=v $ where v is a std::vector and each dof_indices[i] specifies where to add value v[i]

Definition at line 840 of file numeric_vector.h.

References libMesh::NumericVector< T >::add_vector(), and libMesh::libmesh_assert().

842 {
843  libmesh_assert(v.size() == dof_indices.size());
844  if (!v.empty())
845  this->add_vector(&v[0], dof_indices);
846 }
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
libmesh_assert(j)
template<typename T>
void libMesh::NumericVector< T >::add_vector ( const NumericVector< T > &  V,
const std::vector< numeric_index_type > &  dof_indices 
)
virtualinherited

$ U+=v $ where v is a NumericVector and each dof_indices[i] specifies where to add value v(i)

Definition at line 394 of file numeric_vector.C.

References libMesh::NumericVector< T >::size().

396 {
397  int n = dof_indices.size();
398  libmesh_assert_equal_to(v.size(), static_cast<unsigned>(n));
399  for (int i=0; i<n; i++)
400  this->add (dof_indices[i], v(i));
401 }
virtual void add(const numeric_index_type i, const T value)=0
template<typename T>
void libMesh::NumericVector< T >::add_vector ( const DenseVector< T > &  V,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

$ U+=v $ where v is a DenseVector and each dof_indices[i] specifies where to add value v(i)

Definition at line 852 of file numeric_vector.h.

References libMesh::NumericVector< T >::add_vector(), libMesh::DenseVector< T >::empty(), libMesh::libmesh_assert(), and libMesh::DenseVector< T >::size().

854 {
855  libmesh_assert(v.size() == dof_indices.size());
856  if (!v.empty())
857  this->add_vector(&v(0), dof_indices);
858 }
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
libmesh_assert(j)
template<typename T>
void libMesh::NumericVector< T >::add_vector ( const NumericVector< T > &  v,
const ShellMatrix< T > &  a 
)
inherited

$U+=A*V$, add the product of a ShellMatrix A and a NumericVector V to this, where this=U.

Definition at line 406 of file numeric_vector.C.

References libMesh::ShellMatrix< T >::vector_mult_add().

408 {
409  a.vector_mult_add(*this,v);
410 }
template<typename T >
void libMesh::PetscVector< T >::add_vector_conjugate_transpose ( const NumericVector< T > &  V,
const SparseMatrix< T > &  A_trans 
)

$U+=A^H*V$, add the product of the conjugate-transpose of SparseMatrix A_trans and a NumericVector V to this, where this=U.

Definition at line 263 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, A, and ierr.

265 {
266  libmesh_error_msg("MatMultHermitianTranspose was introduced in PETSc 3.1.0," \
267  << "No one has made it backwards compatible with older " \
268  << "versions of PETSc so far.");
269 }
template<typename T >
void libMesh::PetscVector< T >::add_vector_transpose ( const NumericVector< T > &  V,
const SparseMatrix< T > &  A_trans 
)
virtual

$U+=A^T*V$, add the product of the transpose of SparseMatrix A_trans and a NumericVector V to this, where this=U.

Implements libMesh::NumericVector< T >.

Definition at line 242 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, A, and ierr.

244 {
245  this->_restore_array();
246  // Make sure the data passed in are really of Petsc types
247  const PetscVector<T> * V = cast_ptr<const PetscVector<T> *>(&V_in);
248  const PetscMatrix<T> * A = cast_ptr<const PetscMatrix<T> *>(&A_in);
249 
250  PetscErrorCode ierr=0;
251 
252  A->close();
253 
254  // The const_cast<> is not elegant, but it is required since PETSc
255  // is not const-correct.
256  ierr = MatMultTransposeAdd(const_cast<PetscMatrix<T> *>(A)->mat(), V->_vec, _vec, _vec);
257  LIBMESH_CHKERR(ierr);
258 }
void _restore_array() const
PetscErrorCode ierr
static PetscErrorCode Mat * A
template<typename T >
UniquePtr< 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 46 of file numeric_vector.C.

References libMesh::AUTOMATIC, libMesh::EIGEN_SOLVERS, libMesh::LASPACK_SOLVERS, libMesh::PETSC_SOLVERS, and libMesh::TRILINOS_SOLVERS.

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::System::add_vector(), libMesh::NumericVector< T >::build(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::System::calculate_norm(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::EquationSystems::get_solution(), and libMesh::System::project_vector().

47 {
48  // Build the appropriate vector
49  switch (solver_package)
50  {
51 
52 #ifdef LIBMESH_HAVE_LASPACK
53  case LASPACK_SOLVERS:
54  return UniquePtr<NumericVector<T> >(new LaspackVector<T>(comm, AUTOMATIC));
55 #endif
56 
57 #ifdef LIBMESH_HAVE_PETSC
58  case PETSC_SOLVERS:
59  return UniquePtr<NumericVector<T> >(new PetscVector<T>(comm, AUTOMATIC));
60 #endif
61 
62 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
63  case TRILINOS_SOLVERS:
64  return UniquePtr<NumericVector<T> >(new EpetraVector<T>(comm, AUTOMATIC));
65 #endif
66 
67 #ifdef LIBMESH_HAVE_EIGEN
68  case EIGEN_SOLVERS:
69  return UniquePtr<NumericVector<T> >(new EigenSparseVector<T>(comm, AUTOMATIC));
70 #endif
71 
72  default:
73  return UniquePtr<NumericVector<T> >(new DistributedVector<T>(comm, AUTOMATIC));
74  }
75 
76  libmesh_error_msg("We'll never get here!");
77  return UniquePtr<NumericVector<T> >();
78 }
EIGEN_SOLVERS
Definition: libmesh.C:260
TRILINOS_SOLVERS
Definition: libmesh.C:258
LASPACK_SOLVERS
Definition: libmesh.C:262
const Parallel::Communicator & comm() const
template<typename T >
UniquePtr< NumericVector< T > > libMesh::NumericVector< T >::build ( const SolverPackage  solver_package = libMesh::default_solver_package())
staticinherited

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

Definition at line 84 of file numeric_vector.C.

References libMesh::NumericVector< T >::build(), and libMesh::CommWorld.

85 {
86  libmesh_deprecated();
87  return NumericVector<T>::build(CommWorld, solver_package);
88 }
static UniquePtr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Parallel::FakeCommunicator CommWorld
Definition: libmesh.C:206
template<typename T >
void libMesh::PetscVector< T >::clear ( )
inlinevirtual
Returns
the PetscVector<T> to a pristine state.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1045 of file petsc_vector.h.

References libMesh::PetscVector< T >::_destroy_vec_on_exit, libMesh::PetscVector< T >::_global_to_local_map, libMesh::NumericVector< T >::_is_closed, libMesh::NumericVector< T >::_is_initialized, libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, ierr, and libMesh::NumericVector< T >::initialized().

Referenced by libMesh::PetscVector< T >::init(), and libMesh::PetscVector< T >::~PetscVector().

1046 {
1047  parallel_object_only();
1048 
1049  if (this->initialized())
1050  this->_restore_array();
1051 
1052  if ((this->initialized()) && (this->_destroy_vec_on_exit))
1053  {
1054  PetscErrorCode ierr=0;
1055 
1056  ierr = LibMeshVecDestroy(&_vec);
1057  LIBMESH_CHKERR(ierr);
1058  }
1059 
1060  this->_is_closed = this->_is_initialized = false;
1061 
1062  _global_to_local_map.clear();
1063 }
virtual bool initialized() const
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:634
void _restore_array() const
PetscErrorCode ierr
template<typename T >
UniquePtr< NumericVector< T > > libMesh::PetscVector< T >::clone ( ) const
inlinevirtual

Creates a copy of this vector and returns it in an UniquePtr.

Implements libMesh::NumericVector< T >.

Definition at line 1117 of file petsc_vector.h.

References libMesh::ParallelObject::comm(), libMesh::NumericVector< T >::init(), and libMesh::NumericVector< T >::type().

1118 {
1119  NumericVector<T> * cloned_vector = new PetscVector<T>(this->comm(), this->type());
1120  cloned_vector->init(*this, true);
1121  *cloned_vector = *this;
1122  return UniquePtr<NumericVector<T> >(cloned_vector);
1123 }
const Parallel::Communicator & comm() const
ParallelType type() const
template<typename T >
void libMesh::PetscVector< T >::close ( )
inlinevirtual

Call the assemble functions

Implements libMesh::NumericVector< T >.

Definition at line 1017 of file petsc_vector.h.

References libMesh::NumericVector< T >::_is_closed, libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, libMesh::GHOSTED, ierr, and libMesh::NumericVector< T >::type().

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::SlepcEigenSolver< T >::get_eigenpair(), libMesh::PetscVector< T >::localize(), and libMesh::PetscLinearSolver< T >::solve().

1018 {
1019  parallel_object_only();
1020 
1021  this->_restore_array();
1022 
1023  PetscErrorCode ierr=0;
1024 
1025  ierr = VecAssemblyBegin(_vec);
1026  LIBMESH_CHKERR(ierr);
1027  ierr = VecAssemblyEnd(_vec);
1028  LIBMESH_CHKERR(ierr);
1029 
1030  if(this->type() == GHOSTED)
1031  {
1032  ierr = VecGhostUpdateBegin(_vec,INSERT_VALUES,SCATTER_FORWARD);
1033  LIBMESH_CHKERR(ierr);
1034  ierr = VecGhostUpdateEnd(_vec,INSERT_VALUES,SCATTER_FORWARD);
1035  LIBMESH_CHKERR(ierr);
1036  }
1037 
1038  this->_is_closed = true;
1039 }
void _restore_array() const
PetscErrorCode ierr
ParallelType type() const
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
a reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_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::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshTools::bounding_box(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::DistributedVector< T >::clone(), libMesh::EigenSparseVector< T >::clone(), libMesh::LaspackVector< T >::clone(), libMesh::EpetraVector< T >::clone(), libMesh::PetscVector< T >::clone(), libMesh::EpetraVector< T >::close(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), 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::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::EpetraVector< T >::EpetraVector(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), libMesh::LocationMap< T >::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TopologyMap::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::DistributedVector< T >::init(), libMesh::EpetraVector< T >::init(), libMesh::PetscVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), 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::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), 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::DistributedVector< T >::max(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), libMesh::DistributedVector< T >::min(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), 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::Partitioner::partition(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), libMesh::MeshTools::processor_bounding_box(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshTools::subdomain_bounding_box(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::DistributedVector< T >::zero_clone(), libMesh::LaspackVector< T >::zero_clone(), libMesh::EigenSparseVector< T >::zero_clone(), libMesh::EpetraVector< T >::zero_clone(), and libMesh::PetscVector< T >::zero_clone().

88  { return _communicator; }
const Parallel::Communicator & _communicator
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. When differences occur, the return value contains the first index i where the difference (a[i]-b[i]) exceeded the threshold. When no threshold is given, the libMesh TOLERANCE is used.

Definition at line 116 of file numeric_vector.C.

References std::abs(), libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::initialized(), libMesh::initialized(), libMesh::NumericVector< T >::last_local_index(), libMesh::libmesh_assert(), and std::max().

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

118 {
119  libmesh_assert (this->initialized());
120  libmesh_assert (other_vector.initialized());
121  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
122  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());
123 
124  int first_different_i = std::numeric_limits<int>::max();
126 
127  do
128  {
129  if ( std::abs( (*this)(i) - other_vector(i) ) > threshold )
130  first_different_i = i;
131  else
132  i++;
133  }
134  while (first_different_i==std::numeric_limits<int>::max()
135  && i<last_local_index());
136 
137  // Find the correct first differing index in parallel
138  this->comm().min(first_different_i);
139 
140  if (first_different_i == std::numeric_limits<int>::max())
141  return -1;
142 
143  return first_different_i;
144 }
double abs(double a)
virtual numeric_index_type last_local_index() const =0
virtual bool initialized() const
long double max(long double a, double b)
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
const Parallel::Communicator & comm() const
virtual numeric_index_type first_local_index() const =0
template<typename T >
void libMesh::PetscVector< T >::conjugate ( )
virtual

Replace each entry v_i = real(v_i) + imag(v_i) of this vector by its complex conjugate, real(v_i) - imag(v_i)

Implements libMesh::NumericVector< T >.

Definition at line 168 of file petsc_vector.C.

References ierr.

169 {
170  PetscErrorCode ierr = 0;
171 
172  // We just call the PETSc VecConjugate
173  ierr = VecConjugate(_vec);
174  LIBMESH_CHKERR(ierr);
175 }
PetscErrorCode ierr
template<typename T >
void libMesh::PetscVector< T >::create_subvector ( NumericVector< T > &  subvector,
const std::vector< numeric_index_type > &  rows 
) const
virtual

Creates a "subvector" from this vector using the rows indices of the "rows" array.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1238 of file petsc_vector.C.

References libMesh::NumericVector< T >::_is_initialized, libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, libMesh::MeshTools::Generation::Private::idx(), ierr, libMesh::NumericVector< T >::initialized(), libMesh::Utility::iota(), libMesh::numeric_petsc_cast(), and PETSC_USE_POINTER.

1240 {
1241  this->_restore_array();
1242 
1243  // PETSc data structures
1244  IS parent_is, subvector_is;
1245  VecScatter scatter;
1246  PetscErrorCode ierr = 0;
1247 
1248  // Make sure the passed in subvector is really a PetscVector
1249  PetscVector<T> * petsc_subvector = cast_ptr<PetscVector<T> *>(&subvector);
1250 
1251  // If the petsc_subvector is already initialized, we assume that the
1252  // user has already allocated the *correct* amount of space for it.
1253  // If not, we use the appropriate PETSc routines to initialize it.
1254  if (!petsc_subvector->initialized())
1255  {
1256  // Initialize the petsc_subvector to have enough space to hold
1257  // the entries which will be scattered into it. Note: such an
1258  // init() function (where we let PETSc decide the number of local
1259  // entries) is not currently offered by the PetscVector
1260  // class. Should we differentiate here between sequential and
1261  // parallel vector creation based on this->n_processors() ?
1262  ierr = VecCreateMPI(this->comm().get(),
1263  PETSC_DECIDE, // n_local
1264  cast_int<PetscInt>(rows.size()), // n_global
1265  &(petsc_subvector->_vec));
1266  LIBMESH_CHKERR(ierr);
1267 
1268  ierr = VecSetFromOptions (petsc_subvector->_vec);
1269  LIBMESH_CHKERR(ierr);
1270 
1271  // Mark the subvector as initialized
1272  petsc_subvector->_is_initialized = true;
1273  }
1274  else
1275  {
1276  petsc_subvector->_restore_array();
1277  }
1278 
1279  // Use iota to fill an array with entries [0,1,2,3,4,...rows.size()]
1280  std::vector<PetscInt> idx(rows.size());
1281  Utility::iota (idx.begin(), idx.end(), 0);
1282 
1283  // Construct index sets
1284  ierr = ISCreateLibMesh(this->comm().get(),
1285  rows.size(),
1286  numeric_petsc_cast(&rows[0]),
1288  &parent_is);
1289  LIBMESH_CHKERR(ierr);
1290 
1291  ierr = ISCreateLibMesh(this->comm().get(),
1292  rows.size(),
1293  &idx[0],
1295  &subvector_is);
1296  LIBMESH_CHKERR(ierr);
1297 
1298  // Construct the scatter object
1299  ierr = VecScatterCreate(this->_vec,
1300  parent_is,
1301  petsc_subvector->_vec,
1302  subvector_is,
1303  &scatter); LIBMESH_CHKERR(ierr);
1304 
1305  // Actually perform the scatter
1306  ierr = VecScatterBegin(scatter,
1307  this->_vec,
1308  petsc_subvector->_vec,
1309  INSERT_VALUES,
1310  SCATTER_FORWARD); LIBMESH_CHKERR(ierr);
1311 
1312  ierr = VecScatterEnd(scatter,
1313  this->_vec,
1314  petsc_subvector->_vec,
1315  INSERT_VALUES,
1316  SCATTER_FORWARD); LIBMESH_CHKERR(ierr);
1317 
1318  // Clean up
1319  ierr = LibMeshISDestroy(&parent_is); LIBMESH_CHKERR(ierr);
1320  ierr = LibMeshISDestroy(&subvector_is); LIBMESH_CHKERR(ierr);
1321  ierr = LibMeshVecScatterDestroy(&scatter); LIBMESH_CHKERR(ierr);
1322 }
unsigned int size() const
Definition: parallel.h:679
void iota(ForwardIter first, ForwardIter last, T value)
Definition: utility.h:58
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
void _restore_array() const
PetscErrorCode ierr
const Parallel::Communicator & comm() const
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited
template<typename T >
T libMesh::PetscVector< T >::dot ( const NumericVector< T > &  V) const
virtual

Computes the dot product, p = U.V. Use complex-conjugate of V in the complex-valued case.

Implements libMesh::NumericVector< T >.

Definition at line 444 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, and ierr.

445 {
446  this->_restore_array();
447 
448  // Error flag
449  PetscErrorCode ierr = 0;
450 
451  // Return value
452  PetscScalar value=0.;
453 
454  // Make sure the NumericVector passed in is really a PetscVector
455  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&V);
456 
457  // 2.3.x (at least) style. Untested for previous versions.
458  ierr = VecDot(this->_vec, v->_vec, &value);
459  LIBMESH_CHKERR(ierr);
460 
461  return static_cast<T>(value);
462 }
void _restore_array() const
PetscErrorCode ierr
template<typename T>
virtual T libMesh::NumericVector< T >::el ( const numeric_index_type  i) const
inlinevirtualinherited
Returns
the element U(i)

Definition at line 345 of file numeric_vector.h.

345 { return (*this)(i); }
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.

References libMesh::ReferenceCounter::_enable_print_counter.

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

101 {
102  _enable_print_counter = true;
103  return;
104 }
template<typename T >
numeric_index_type libMesh::PetscVector< T >::first_local_index ( ) const
inlinevirtual
Returns
the index of the first vector element actually stored on this processor

Implements libMesh::NumericVector< T >.

Definition at line 1166 of file petsc_vector.h.

References libMesh::PetscVector< T >::_array_is_present, libMesh::PetscVector< T >::_first, libMesh::PetscVector< T >::_vec, ierr, libMesh::NumericVector< T >::initialized(), and libMesh::libmesh_assert().

1167 {
1168  libmesh_assert (this->initialized());
1169 
1170  numeric_index_type first = 0;
1171 
1172  if(_array_is_present) // Can we use cached values?
1173  first = _first;
1174  else
1175  {
1176  PetscErrorCode ierr=0;
1177  PetscInt petsc_first=0, petsc_last=0;
1178  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1179  LIBMESH_CHKERR(ierr);
1180  first = static_cast<numeric_index_type>(petsc_first);
1181  }
1182 
1183  return first;
1184 }
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
numeric_index_type _first
Definition: petsc_vector.h:559
template<typename T >
void libMesh::PetscVector< T >::get ( const std::vector< numeric_index_type > &  index,
T *  values 
) const
inlinevirtual

Access multiple components at once. values will not be reallocated; it should already have enough space. Overloaded method that should be faster (probably much faster) than calling operator() individually for each index.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1294 of file petsc_vector.h.

References libMesh::PetscVector< T >::_get_array(), libMesh::PetscVector< T >::_local_size, libMesh::PetscVector< T >::_read_only_values, libMesh::GHOSTED, libMesh::PetscVector< T >::map_global_to_local_index(), and libMesh::NumericVector< T >::type().

1296 {
1297  this->_get_array(true);
1298 
1299  const std::size_t num = index.size();
1300 
1301  for(std::size_t i=0; i<num; i++)
1302  {
1303  const numeric_index_type local_index = this->map_global_to_local_index(index[i]);
1304 #ifndef NDEBUG
1305  if(this->type() == GHOSTED)
1306  {
1307  libmesh_assert_less (local_index, _local_size);
1308  }
1309 #endif
1310  values[i] = static_cast<T>(_read_only_values[local_index]);
1311  }
1312 }
void _get_array(bool read_only) const
numeric_index_type _local_size
Definition: petsc_vector.h:571
const PetscScalar * _read_only_values
Definition: petsc_vector.h:588
numeric_index_type map_global_to_local_index(const numeric_index_type i) const
dof_id_type numeric_index_type
Definition: id_types.h:92
ParallelType type() const
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 825 of file numeric_vector.h.

827 {
828  const std::size_t num = index.size();
829  values.resize(num);
830  if (!num)
831  return;
832 
833  this->get(index, &values[0]);
834 }
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 extremely advanced interface. In general you should avoid using it!

Definition at line 1317 of file petsc_vector.h.

References libMesh::PetscVector< T >::_get_array(), libMesh::PetscVector< T >::_values, and libMesh::PetscVector< T >::_values_manually_retrieved.

1318 {
1320  _get_array(false);
1321 
1322  return _values;
1323 }
void _get_array(bool read_only) const
PetscScalar * _values
Definition: petsc_vector.h:598
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 extremely advanced interface. In general you should avoid using it!

Definition at line 1328 of file petsc_vector.h.

References libMesh::PetscVector< T >::_get_array(), libMesh::PetscVector< T >::_read_only_values, and libMesh::PetscVector< T >::_values_manually_retrieved.

1329 {
1331  _get_array(true);
1332 
1333  return _read_only_values;
1334 }
void _get_array(bool read_only) const
const PetscScalar * _read_only_values
Definition: petsc_vector.h:588
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

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

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

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 (Counts::iterator it = _counts.begin();
59  it != _counts.end(); ++it)
60  {
61  const std::string name(it->first);
62  const unsigned int creations = it->second.first;
63  const unsigned int destructions = it->second.second;
64 
65  oss << "| " << name << " reference count information:\n"
66  << "| Creations: " << creations << '\n'
67  << "| Destructions: " << destructions << '\n';
68  }
69 
70  oss << " ---------------------------------------------------------------------------- \n";
71 
72  return oss.str();
73 
74 #else
75 
76  return "";
77 
78 #endif
79 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
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 local relative threshold. When differences occur, the return value contains the first index where the difference (a[i]-b[i])/max_j(a[j],b[j]) exceeded the threshold. When no threshold is given, the libMesh TOLERANCE is used.

Definition at line 181 of file numeric_vector.C.

References std::abs(), libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::initialized(), libMesh::initialized(), libMesh::NumericVector< T >::last_local_index(), libMesh::libmesh_assert(), libMesh::NumericVector< T >::linfty_norm(), std::max(), and libMesh::Real.

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

183 {
184  libmesh_assert (this->initialized());
185  libmesh_assert (other_vector.initialized());
186  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
187  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());
188 
189  int first_different_i = std::numeric_limits<int>::max();
191 
192  const Real my_norm = this->linfty_norm();
193  const Real other_norm = other_vector.linfty_norm();
194  const Real abs_threshold = std::max(my_norm, other_norm) * threshold;
195 
196  do
197  {
198  if ( std::abs( (*this)(i) - other_vector(i) ) > abs_threshold )
199  first_different_i = i;
200  else
201  i++;
202  }
203  while (first_different_i==std::numeric_limits<int>::max()
204  && i<last_local_index());
205 
206  // Find the correct first differing index in parallel
207  this->comm().min(first_different_i);
208 
209  if (first_different_i == std::numeric_limits<int>::max())
210  return -1;
211 
212  return first_different_i;
213 }
double abs(double a)
virtual numeric_index_type last_local_index() const =0
virtual bool initialized() const
long double max(long double a, double b)
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual Real linfty_norm() const =0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
virtual numeric_index_type first_local_index() const =0
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 160 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

161 {
162  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
163  std::pair<unsigned int, unsigned int> & p = _counts[name];
164 
165  p.first++;
166 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
spin_mutex spin_mtx
Definition: threads.C:29
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 173 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

174 {
175  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
176  std::pair<unsigned int, unsigned int> & p = _counts[name];
177 
178  p.second++;
179 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
spin_mutex spin_mtx
Definition: threads.C:29
template<typename T >
T libMesh::PetscVector< T >::indefinite_dot ( const NumericVector< T > &  V) const

Computes the dot product, p = U.V. Do not use complex-conjugate of V in the complex-valued case.

Definition at line 465 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, and ierr.

466 {
467  this->_restore_array();
468 
469  // Error flag
470  PetscErrorCode ierr = 0;
471 
472  // Return value
473  PetscScalar value=0.;
474 
475  // Make sure the NumericVector passed in is really a PetscVector
476  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&V);
477 
478  // 2.3.x (at least) style. Untested for previous versions.
479  ierr = VecTDot(this->_vec, v->_vec, &value);
480  LIBMESH_CHKERR(ierr);
481 
482  return static_cast<T>(value);
483 }
void _restore_array() const
PetscErrorCode ierr
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  type = AUTOMATIC 
)
inlinevirtual

Change the dimension of the vector to N. The reserved memory for this vector remains unchanged if possible, to make things faster, but this may waste some memory, so take this in the back of your head. However, if N==0 all memory is freed, i.e. 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 cited 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 835 of file petsc_vector.h.

References libMesh::NumericVector< T >::_is_closed, libMesh::NumericVector< T >::_is_initialized, libMesh::NumericVector< T >::_type, libMesh::PetscVector< T >::_vec, libMesh::AUTOMATIC, libMesh::PetscVector< T >::clear(), libMesh::ParallelObject::comm(), ierr, libMesh::NumericVector< T >::initialized(), libMesh::libmesh_assert(), libMesh::PARALLEL, libMesh::SERIAL, and libMesh::PetscVector< T >::zero().

Referenced by libMesh::PetscVector< T >::init(), libMesh::PetscVector< T >::localize(), and libMesh::PetscVector< T >::PetscVector().

839 {
840  parallel_object_only();
841 
842  PetscErrorCode ierr=0;
843  PetscInt petsc_n=static_cast<PetscInt>(n);
844  PetscInt petsc_n_local=static_cast<PetscInt>(n_local);
845 
846 
847  // Clear initialized vectors
848  if (this->initialized())
849  this->clear();
850 
851  if (ptype == AUTOMATIC)
852  {
853  if (n == n_local)
854  this->_type = SERIAL;
855  else
856  this->_type = PARALLEL;
857  }
858  else
859  this->_type = ptype;
860 
861  libmesh_assert ((this->_type==SERIAL && n==n_local) ||
862  this->_type==PARALLEL);
863 
864  // create a sequential vector if on only 1 processor
865  if (this->_type == SERIAL)
866  {
867  ierr = VecCreateSeq (PETSC_COMM_SELF, petsc_n, &_vec);
868  CHKERRABORT(PETSC_COMM_SELF,ierr);
869 
870  ierr = VecSetFromOptions (_vec);
871  CHKERRABORT(PETSC_COMM_SELF,ierr);
872  }
873  // otherwise create an MPI-enabled vector
874  else if (this->_type == PARALLEL)
875  {
876 #ifdef LIBMESH_HAVE_MPI
877  libmesh_assert_less_equal (n_local, n);
878  ierr = VecCreateMPI (this->comm().get(), petsc_n_local, petsc_n,
879  &_vec);
880  LIBMESH_CHKERR(ierr);
881 #else
882  libmesh_assert_equal_to (n_local, n);
883  ierr = VecCreateSeq (PETSC_COMM_SELF, petsc_n, &_vec);
884  CHKERRABORT(PETSC_COMM_SELF,ierr);
885 #endif
886 
887  ierr = VecSetFromOptions (_vec);
888  LIBMESH_CHKERR(ierr);
889  }
890  else
891  libmesh_error_msg("Unsupported type " << this->_type);
892 
893  this->_is_initialized = true;
894  this->_is_closed = true;
895 
896 
897  if (fast == false)
898  this->zero ();
899 }
virtual void zero() libmesh_override
virtual bool initialized() const
libmesh_assert(j)
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual void clear() libmesh_override
template<typename T >
void libMesh::PetscVector< T >::init ( const numeric_index_type  N,
const bool  fast = false,
const ParallelType  type = AUTOMATIC 
)
inlinevirtual
template<typename T>
virtual void libMesh::PetscVector< T >::init ( const numeric_index_type  ,
const numeric_index_type  ,
const std::vector< numeric_index_type > &  ,
const bool  = false,
const ParallelType  = AUTOMATIC 
)
virtual

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

Implements libMesh::NumericVector< T >.

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

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

Implements libMesh::NumericVector< T >.

Definition at line 978 of file petsc_vector.h.

References libMesh::PetscVector< T >::_global_to_local_map, libMesh::NumericVector< T >::_is_closed, libMesh::NumericVector< T >::_is_initialized, libMesh::PetscVector< T >::_restore_array(), libMesh::NumericVector< T >::_type, libMesh::PetscVector< T >::_vec, libMesh::PetscVector< T >::clear(), ierr, libMesh::NumericVector< T >::initialized(), and libMesh::PetscVector< T >::zero().

980 {
981  parallel_object_only();
982 
983  // Clear initialized vectors
984  if (this->initialized())
985  this->clear();
986 
987  const PetscVector<T> & v = cast_ref<const PetscVector<T> &>(other);
988 
989  // Other vector should restore array.
990  if(v.initialized())
991  {
992  v._restore_array();
993  }
994 
995  this->_global_to_local_map = v._global_to_local_map;
996 
997  // Even if we're initializeing sizes based on an uninitialized or
998  // unclosed vector, *this* vector is being initialized now and is
999  // initially closed.
1000  this->_is_closed = true; // v._is_closed;
1001  this->_is_initialized = true; // v._is_initialized;
1002 
1003  this->_type = v._type;
1004 
1005  // We want to have a valid Vec, even if it's initially of size zero
1006  PetscErrorCode ierr = VecDuplicate (v._vec, &this->_vec);
1007  LIBMESH_CHKERR(ierr);
1008 
1009  if (fast == false)
1010  this->zero ();
1011 }
virtual void zero() libmesh_override
virtual bool initialized() const
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:634
PetscErrorCode ierr
virtual void clear() libmesh_override
template<typename T>
virtual bool libMesh::NumericVector< T >::initialized ( ) const
inlinevirtualinherited
Returns
true if the vector has been initialized, false otherwise.

Definition at line 132 of file numeric_vector.h.

Referenced by libMesh::DistributedVector< T >::add(), libMesh::EigenSparseVector< T >::add(), libMesh::LaspackVector< T >::add(), libMesh::ImplicitSystem::assemble(), libMesh::LaspackVector< T >::clear(), libMesh::EpetraVector< T >::clear(), libMesh::PetscVector< T >::clear(), libMesh::DistributedVector< T >::close(), libMesh::EigenSparseVector< T >::close(), libMesh::LaspackVector< T >::close(), libMesh::EpetraVector< T >::close(), libMesh::NumericVector< T >::compare(), libMesh::PetscVector< T >::create_subvector(), libMesh::DistributedVector< T >::first_local_index(), libMesh::LaspackVector< T >::first_local_index(), libMesh::EigenSparseVector< T >::first_local_index(), libMesh::EpetraVector< T >::first_local_index(), libMesh::PetscVector< T >::first_local_index(), libMesh::NumericVector< T >::global_relative_compare(), libMesh::DistributedVector< T >::init(), libMesh::EigenSparseVector< T >::init(), libMesh::PetscVector< T >::init(), libMesh::DistributedVector< T >::last_local_index(), libMesh::EigenSparseVector< T >::last_local_index(), libMesh::LaspackVector< T >::last_local_index(), libMesh::EpetraVector< T >::last_local_index(), libMesh::PetscVector< T >::last_local_index(), libMesh::NumericVector< T >::local_relative_compare(), libMesh::DistributedVector< T >::local_size(), libMesh::LaspackVector< T >::local_size(), libMesh::EigenSparseVector< T >::local_size(), libMesh::EpetraVector< T >::local_size(), libMesh::PetscVector< T >::local_size(), libMesh::PetscVector< T >::map_global_to_local_index(), libMesh::DistributedVector< T >::max(), libMesh::EpetraVector< T >::max(), libMesh::DistributedVector< T >::min(), libMesh::EpetraVector< T >::min(), libMesh::DistributedVector< T >::operator()(), libMesh::EigenSparseVector< T >::operator()(), libMesh::LaspackVector< T >::operator()(), libMesh::EpetraVector< T >::operator()(), libMesh::NumericVector< T >::print(), libMesh::NumericVector< T >::print_global(), libMesh::DistributedVector< T >::set(), libMesh::LaspackVector< T >::set(), libMesh::EigenSparseVector< T >::set(), libMesh::DistributedVector< T >::size(), libMesh::LaspackVector< T >::size(), libMesh::EigenSparseVector< T >::size(), libMesh::EpetraVector< T >::size(), libMesh::PetscVector< T >::size(), libMesh::DistributedVector< T >::zero(), libMesh::LaspackVector< T >::zero(), libMesh::EigenSparseVector< T >::zero(), libMesh::EpetraVector< T >::zero(), and libMesh::LaspackVector< T >::~LaspackVector().

132 { return _is_initialized; }
template<typename T >
void libMesh::PetscVector< T >::insert ( const T *  v,
const std::vector< numeric_index_type > &  dof_indices 
)
virtual

$ U=v $ where v is a T[] or T * and you want to specify WHERE to insert it

Reimplemented from libMesh::NumericVector< T >.

Definition at line 359 of file petsc_vector.C.

References ierr, and libMesh::numeric_petsc_cast().

361 {
362  if (dof_indices.empty())
363  return;
364 
365  this->_restore_array();
366 
367  PetscErrorCode ierr=0;
368  PetscInt * idx_values = numeric_petsc_cast(&dof_indices[0]);
369  ierr = VecSetValues (_vec, dof_indices.size(), idx_values, v, INSERT_VALUES);
370  LIBMESH_CHKERR(ierr);
371 
372  this->_is_closed = false;
373 }
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
void _restore_array() const
PetscErrorCode ierr
template<typename T>
void libMesh::NumericVector< T >::insert ( const std::vector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

$ U=v $ where v is a std::vector<T> and you want to specify WHERE to insert it

Definition at line 864 of file numeric_vector.h.

References libMesh::NumericVector< T >::insert(), and libMesh::libmesh_assert().

866 {
867  libmesh_assert(v.size() == dof_indices.size());
868  if (!v.empty())
869  this->insert(&v[0], dof_indices);
870 }
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
libmesh_assert(j)
template<typename T>
void libMesh::NumericVector< T >::insert ( const NumericVector< T > &  V,
const std::vector< numeric_index_type > &  dof_indices 
)
virtualinherited

$U=V$, where U and V are type NumericVector<T> and you want to specify WHERE to insert the NumericVector<T> V

Definition at line 104 of file numeric_vector.C.

References libMesh::NumericVector< T >::size().

106 {
107  libmesh_assert_equal_to (V.size(), dof_indices.size());
108 
109  for (numeric_index_type i=0; i<dof_indices.size(); i++)
110  this->set (dof_indices[i], V(i));
111 }
dof_id_type numeric_index_type
Definition: id_types.h:92
template<typename T>
void libMesh::NumericVector< T >::insert ( const DenseVector< T > &  V,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

$ U=V $ where U and V are type DenseVector<T> and you want to specify WHERE to insert the DenseVector<T> V

Definition at line 876 of file numeric_vector.h.

References libMesh::DenseVector< T >::empty(), libMesh::NumericVector< T >::insert(), libMesh::libmesh_assert(), and libMesh::DenseVector< T >::size().

878 {
879  libmesh_assert(v.size() == dof_indices.size());
880  if (!v.empty())
881  this->insert(&v(0), dof_indices);
882 }
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
libmesh_assert(j)
template<typename T>
void libMesh::NumericVector< T >::insert ( const DenseSubVector< T > &  V,
const std::vector< numeric_index_type > &  dof_indices 
)
inlineinherited

$ U=V $ where V is a DenseSubVector<T> and you want to specify WHERE to insert it

Definition at line 888 of file numeric_vector.h.

References libMesh::DenseSubVector< T >::empty(), libMesh::NumericVector< T >::insert(), libMesh::libmesh_assert(), and libMesh::DenseSubVector< T >::size().

890 {
891  libmesh_assert(v.size() == dof_indices.size());
892  if (!v.empty())
893  this->insert(&v(0), dof_indices);
894 }
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
libmesh_assert(j)
template<typename T >
Real libMesh::PetscVector< T >::l1_norm ( ) const
virtual
Returns
the $l_1$-norm of the vector, i.e. the sum of the absolute values.

Implements libMesh::NumericVector< T >.

Definition at line 57 of file petsc_vector.C.

References libMesh::closed(), ierr, libMesh::libmesh_assert(), and libMesh::Real.

58 {
59  this->_restore_array();
60  libmesh_assert(this->closed());
61 
62  PetscErrorCode ierr=0;
63  PetscReal value=0.;
64 
65  ierr = VecNorm (_vec, NORM_1, &value);
66  LIBMESH_CHKERR(ierr);
67 
68  return static_cast<Real>(value);
69 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PetscErrorCode ierr
template<typename T >
Real libMesh::PetscVector< T >::l2_norm ( ) const
virtual
Returns
the $l_2$-norm of the vector, i.e. the square root of the sum of the squares of the elements.

Implements libMesh::NumericVector< T >.

Definition at line 74 of file petsc_vector.C.

References libMesh::closed(), ierr, libMesh::libmesh_assert(), and libMesh::Real.

75 {
76  this->_restore_array();
77  libmesh_assert(this->closed());
78 
79  PetscErrorCode ierr=0;
80  PetscReal value=0.;
81 
82  ierr = VecNorm (_vec, NORM_2, &value);
83  LIBMESH_CHKERR(ierr);
84 
85  return static_cast<Real>(value);
86 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PetscErrorCode ierr
template<typename T >
numeric_index_type libMesh::PetscVector< T >::last_local_index ( ) const
inlinevirtual
Returns
the index of the last vector element actually stored on this processor

Implements libMesh::NumericVector< T >.

Definition at line 1190 of file petsc_vector.h.

References libMesh::PetscVector< T >::_array_is_present, libMesh::PetscVector< T >::_last, libMesh::PetscVector< T >::_vec, ierr, libMesh::NumericVector< T >::initialized(), and libMesh::libmesh_assert().

1191 {
1192  libmesh_assert (this->initialized());
1193 
1194  numeric_index_type last = 0;
1195 
1196  if(_array_is_present) // Can we use cached values?
1197  last = _last;
1198  else
1199  {
1200  PetscErrorCode ierr=0;
1201  PetscInt petsc_first=0, petsc_last=0;
1202  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1203  LIBMESH_CHKERR(ierr);
1204  last = static_cast<numeric_index_type>(petsc_last);
1205  }
1206 
1207  return last;
1208 }
numeric_index_type _last
Definition: petsc_vector.h:566
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
template<typename T >
Real libMesh::PetscVector< T >::linfty_norm ( ) const
virtual
Returns
the maximum absolute value of the elements of this vector, which is the $l_\infty$-norm of a vector.

Implements libMesh::NumericVector< T >.

Definition at line 92 of file petsc_vector.C.

References libMesh::closed(), ierr, libMesh::libmesh_assert(), and libMesh::Real.

93 {
94  this->_restore_array();
95  libmesh_assert(this->closed());
96 
97  PetscErrorCode ierr=0;
98  PetscReal value=0.;
99 
100  ierr = VecNorm (_vec, NORM_INFINITY, &value);
101  LIBMESH_CHKERR(ierr);
102 
103  return static_cast<Real>(value);
104 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PetscErrorCode ierr
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. When differences occur, the return value contains the first index where the difference (a[i]-b[i])/max(a[i],b[i]) exceeded the threshold. When no threshold is given, the libMesh TOLERANCE is used.

Definition at line 148 of file numeric_vector.C.

References std::abs(), libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::initialized(), libMesh::initialized(), libMesh::NumericVector< T >::last_local_index(), libMesh::libmesh_assert(), and std::max().

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

150 {
151  libmesh_assert (this->initialized());
152  libmesh_assert (other_vector.initialized());
153  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
154  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());
155 
156  int first_different_i = std::numeric_limits<int>::max();
158 
159  do
160  {
161  if ( std::abs( (*this)(i) - other_vector(i) ) > threshold *
162  std::max(std::abs((*this)(i)), std::abs(other_vector(i))))
163  first_different_i = i;
164  else
165  i++;
166  }
167  while (first_different_i==std::numeric_limits<int>::max()
168  && i<last_local_index());
169 
170  // Find the correct first differing index in parallel
171  this->comm().min(first_different_i);
172 
173  if (first_different_i == std::numeric_limits<int>::max())
174  return -1;
175 
176  return first_different_i;
177 }
double abs(double a)
virtual numeric_index_type last_local_index() const =0
virtual bool initialized() const
long double max(long double a, double b)
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
const Parallel::Communicator & comm() const
virtual numeric_index_type first_local_index() const =0
template<typename T >
numeric_index_type libMesh::PetscVector< T >::local_size ( ) const
inlinevirtual
Returns
the local size of the vector (index_stop-index_start)

Implements libMesh::NumericVector< T >.

Definition at line 1149 of file petsc_vector.h.

References libMesh::PetscVector< T >::_vec, ierr, libMesh::NumericVector< T >::initialized(), and libMesh::libmesh_assert().

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

1150 {
1151  libmesh_assert (this->initialized());
1152 
1153  PetscErrorCode ierr=0;
1154  PetscInt petsc_size=0;
1155 
1156  ierr = VecGetLocalSize(_vec, &petsc_size);
1157  LIBMESH_CHKERR(ierr);
1158 
1159  return static_cast<numeric_index_type>(petsc_size);
1160 }
virtual bool initialized() const
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
template<typename T >
void libMesh::PetscVector< T >::localize ( std::vector< T > &  v_local) const
virtual

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

Implements libMesh::NumericVector< T >.

Definition at line 907 of file petsc_vector.C.

References ierr.

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

908 {
909  this->_restore_array();
910 
911  // This function must be run on all processors at once
912  parallel_object_only();
913 
914  PetscErrorCode ierr=0;
915  const PetscInt n = this->size();
916  const PetscInt nl = this->local_size();
917  PetscScalar * values;
918 
919  v_local.clear();
920  v_local.resize(n, 0.);
921 
922  ierr = VecGetArray (_vec, &values);
923  LIBMESH_CHKERR(ierr);
924 
926 
927  for (PetscInt i=0; i<nl; i++)
928  v_local[i+ioff] = static_cast<T>(values[i]);
929 
930  ierr = VecRestoreArray (_vec, &values);
931  LIBMESH_CHKERR(ierr);
932 
933  this->comm().sum(v_local);
934 }
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual numeric_index_type local_size() const libmesh_override
virtual numeric_index_type first_local_index() const libmesh_override
template<typename T >
void libMesh::PetscVector< T >::localize ( NumericVector< T > &  v_local) const
virtual

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

Implements libMesh::NumericVector< T >.

Definition at line 638 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, libMesh::PetscVector< T >::close(), libMesh::GHOSTED, libMesh::MeshTools::Generation::Private::idx(), ierr, libMesh::Utility::iota(), libMesh::libmesh_assert(), PETSC_USE_POINTER, libMesh::PetscVector< T >::size(), and libMesh::NumericVector< T >::type().

639 {
640  this->_restore_array();
641 
642  // Make sure the NumericVector passed in is really a PetscVector
643  PetscVector<T> * v_local = cast_ptr<PetscVector<T> *>(&v_local_in);
644 
645  libmesh_assert(v_local);
646  libmesh_assert_equal_to (v_local->size(), this->size());
647 
648  PetscErrorCode ierr = 0;
649  const PetscInt n = this->size();
650 
651  IS is;
652  VecScatter scatter;
653 
654  // Create idx, idx[i] = i;
655  std::vector<PetscInt> idx(n); Utility::iota (idx.begin(), idx.end(), 0);
656 
657  // Create the index set & scatter object
658  ierr = ISCreateLibMesh(this->comm().get(), n, &idx[0], PETSC_USE_POINTER, &is);
659  LIBMESH_CHKERR(ierr);
660 
661  ierr = VecScatterCreate(_vec, is,
662  v_local->_vec, is,
663  &scatter);
664  LIBMESH_CHKERR(ierr);
665 
666  // Perform the scatter
667  ierr = VecScatterBegin(scatter, _vec, v_local->_vec,
668  INSERT_VALUES, SCATTER_FORWARD);
669  LIBMESH_CHKERR(ierr);
670 
671  ierr = VecScatterEnd (scatter, _vec, v_local->_vec,
672  INSERT_VALUES, SCATTER_FORWARD);
673  LIBMESH_CHKERR(ierr);
674 
675  // Clean up
676  ierr = LibMeshISDestroy (&is);
677  LIBMESH_CHKERR(ierr);
678 
679  ierr = LibMeshVecScatterDestroy(&scatter);
680  LIBMESH_CHKERR(ierr);
681 
682  // Make sure ghost dofs are up to date
683  if (v_local->type() == GHOSTED)
684  v_local->close();
685 }
void iota(ForwardIter first, ForwardIter last, T value)
Definition: utility.h:58
libmesh_assert(j)
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
PetscErrorCode ierr
const Parallel::Communicator & comm() const
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
template<typename T >
void libMesh::PetscVector< T >::localize ( NumericVector< T > &  v_local,
const std::vector< numeric_index_type > &  send_list 
) const
virtual

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 690 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, libMesh::PetscVector< T >::close(), libMesh::GHOSTED, libMesh::MeshTools::Generation::Private::idx(), ierr, libMesh::libmesh_assert(), libMesh::PARALLEL, PETSC_USE_POINTER, libMesh::PetscVector< T >::size(), and libMesh::NumericVector< T >::type().

692 {
693  // FIXME: Workaround for a strange bug at large-scale.
694  // If we have ghosting, PETSc lets us just copy the solution, and
695  // doing so avoids a segfault?
696  if (v_local_in.type() == GHOSTED &&
697  this->type() == PARALLEL)
698  {
699  v_local_in = *this;
700  return;
701  }
702 
703  // Normal code path begins here
704 
705  this->_restore_array();
706 
707  // Make sure the NumericVector passed in is really a PetscVector
708  PetscVector<T> * v_local = cast_ptr<PetscVector<T> *>(&v_local_in);
709 
710  libmesh_assert(v_local);
711  libmesh_assert_equal_to (v_local->size(), this->size());
712  libmesh_assert_less_equal (send_list.size(), v_local->size());
713 
714  PetscErrorCode ierr=0;
715  const numeric_index_type n_sl =
716  cast_int<numeric_index_type>(send_list.size());
717 
718  IS is;
719  VecScatter scatter;
720 
721  std::vector<PetscInt> idx(n_sl + this->local_size());
722 
723  for (numeric_index_type i=0; i<n_sl; i++)
724  idx[i] = static_cast<PetscInt>(send_list[i]);
725  for (numeric_index_type i = 0; i != this->local_size(); ++i)
726  idx[n_sl+i] = i + this->first_local_index();
727 
728  // Create the index set & scatter object
729  if (idx.empty())
730  ierr = ISCreateLibMesh(this->comm().get(),
731  n_sl+this->local_size(), PETSC_NULL, PETSC_USE_POINTER, &is);
732  else
733  ierr = ISCreateLibMesh(this->comm().get(),
734  n_sl+this->local_size(), &idx[0], PETSC_USE_POINTER, &is);
735  LIBMESH_CHKERR(ierr);
736 
737  ierr = VecScatterCreate(_vec, is,
738  v_local->_vec, is,
739  &scatter);
740  LIBMESH_CHKERR(ierr);
741 
742 
743  // Perform the scatter
744  ierr = VecScatterBegin(scatter, _vec, v_local->_vec,
745  INSERT_VALUES, SCATTER_FORWARD);
746  LIBMESH_CHKERR(ierr);
747 
748  ierr = VecScatterEnd (scatter, _vec, v_local->_vec,
749  INSERT_VALUES, SCATTER_FORWARD);
750  LIBMESH_CHKERR(ierr);
751 
752  // Clean up
753  ierr = LibMeshISDestroy (&is);
754  LIBMESH_CHKERR(ierr);
755 
756  ierr = LibMeshVecScatterDestroy(&scatter);
757  LIBMESH_CHKERR(ierr);
758 
759  // Make sure ghost dofs are up to date
760  if (v_local->type() == GHOSTED)
761  v_local->close();
762 }
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual numeric_index_type local_size() const libmesh_override
ParallelType type() const
virtual numeric_index_type first_local_index() const libmesh_override
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
template<typename T >
void libMesh::PetscVector< T >::localize ( std::vector< T > &  v_local,
const std::vector< numeric_index_type > &  indices 
) const
virtual

Fill in the local std::vector "v_local" with the global indices given in "indices". See numeric_vector.h for more details.

Implements libMesh::NumericVector< T >.

Definition at line 767 of file petsc_vector.C.

References ierr, libMesh::numeric_petsc_cast(), and PETSC_USE_POINTER.

769 {
770  // Error code used to check the status of all PETSc function calls.
771  PetscErrorCode ierr = 0;
772 
773  // Create a sequential destination Vec with the right number of entries on each proc.
774  Vec dest;
775  ierr = VecCreateSeq(PETSC_COMM_SELF, indices.size(), &dest);
776  LIBMESH_CHKERR(ierr);
777 
778  // Create an IS using the libmesh routine. PETSc does not own the
779  // IS memory in this case, it is automatically cleaned up by the
780  // std::vector destructor.
781  IS is;
782  ierr = ISCreateLibMesh(this->comm().get(),
783  indices.size(),
784  numeric_petsc_cast(&indices[0]),
786  &is);
787  LIBMESH_CHKERR(ierr);
788 
789  // Create the VecScatter object. "NULL" means "use the identity IS".
790  VecScatter scatter;
791  ierr = VecScatterCreate(_vec,
792  /*src is=*/is,
793  /*dest vec=*/dest,
794  /*dest is=*/NULL,
795  &scatter);
796  LIBMESH_CHKERR(ierr);
797 
798  // Do the scatter
799  ierr = VecScatterBegin(scatter, _vec, dest, INSERT_VALUES, SCATTER_FORWARD);
800  LIBMESH_CHKERR(ierr);
801 
802  ierr = VecScatterEnd(scatter, _vec, dest, INSERT_VALUES, SCATTER_FORWARD);
803  LIBMESH_CHKERR(ierr);
804 
805  // Get access to the values stored in dest.
806  PetscScalar * values;
807  ierr = VecGetArray (dest, &values);
808  LIBMESH_CHKERR(ierr);
809 
810  // Store values into the provided v_local. Make sure there is enough
811  // space reserved and then clear out any existing entries before
812  // inserting.
813  v_local.reserve(indices.size());
814  v_local.clear();
815  v_local.insert(v_local.begin(), values, values+indices.size());
816 
817  // We are done using it, so restore the array.
818  ierr = VecRestoreArray (dest, &values);
819  LIBMESH_CHKERR(ierr);
820 
821  // Clean up PETSc data structures.
822  ierr = LibMeshVecScatterDestroy(&scatter);
823  LIBMESH_CHKERR(ierr);
824 
825  ierr = LibMeshISDestroy (&is);
826  LIBMESH_CHKERR(ierr);
827 
828  ierr = LibMeshVecDestroy(&dest);
829  LIBMESH_CHKERR(ierr);
830 }
unsigned int size() const
Definition: parallel.h:679
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
PetscErrorCode ierr
const Parallel::Communicator & comm() const
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 
)
virtual

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

Implements libMesh::NumericVector< T >.

Definition at line 835 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, libMesh::PetscVector< T >::close(), libMesh::MeshTools::Generation::Private::idx(), ierr, libMesh::PetscVector< T >::init(), libMesh::Utility::iota(), libmesh_nullptr, libMesh::PetscVector< T >::localize(), libMesh::n_processors(), libMesh::PARALLEL, and PETSC_USE_POINTER.

838 {
839  this->_restore_array();
840 
841  libmesh_assert_less_equal (send_list.size(), this->size());
842  libmesh_assert_less_equal (last_local_idx+1, this->size());
843 
844  const numeric_index_type my_size = this->size();
845  const numeric_index_type my_local_size = (last_local_idx - first_local_idx + 1);
846  PetscErrorCode ierr=0;
847 
848  // Don't bother for serial cases
849  // if ((first_local_idx == 0) &&
850  // (my_local_size == my_size))
851  // But we do need to stay in sync for degenerate cases
852  if (this->n_processors() == 1)
853  return;
854 
855 
856  // Build a parallel vector, initialize it with the local
857  // parts of (*this)
858  PetscVector<T> parallel_vec(this->comm(), PARALLEL);
859 
860  parallel_vec.init (my_size, my_local_size, true, PARALLEL);
861 
862 
863  // Copy part of *this into the parallel_vec
864  {
865  IS is;
866  VecScatter scatter;
867 
868  // Create idx, idx[i] = i+first_local_idx;
869  std::vector<PetscInt> idx(my_local_size);
870  Utility::iota (idx.begin(), idx.end(), first_local_idx);
871 
872  // Create the index set & scatter object
873  ierr = ISCreateLibMesh(this->comm().get(), my_local_size,
874  my_local_size ? &idx[0] : libmesh_nullptr, PETSC_USE_POINTER, &is);
875  LIBMESH_CHKERR(ierr);
876 
877  ierr = VecScatterCreate(_vec, is,
878  parallel_vec._vec, is,
879  &scatter);
880  LIBMESH_CHKERR(ierr);
881 
882  ierr = VecScatterBegin(scatter, _vec, parallel_vec._vec,
883  INSERT_VALUES, SCATTER_FORWARD);
884  LIBMESH_CHKERR(ierr);
885 
886  ierr = VecScatterEnd (scatter, _vec, parallel_vec._vec,
887  INSERT_VALUES, SCATTER_FORWARD);
888  LIBMESH_CHKERR(ierr);
889 
890  // Clean up
891  ierr = LibMeshISDestroy (&is);
892  LIBMESH_CHKERR(ierr);
893 
894  ierr = LibMeshVecScatterDestroy(&scatter);
895  LIBMESH_CHKERR(ierr);
896  }
897 
898  // localize like normal
899  parallel_vec.close();
900  parallel_vec.localize (*this, send_list);
901  this->close();
902 }
processor_id_type n_processors() const
const class libmesh_nullptr_t libmesh_nullptr
void iota(ForwardIter first, ForwardIter last, T value)
Definition: utility.h:58
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
virtual void close() libmesh_override
PetscErrorCode ierr
const Parallel::Communicator & comm() const
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
template<typename T>
virtual void libMesh::PetscVector< T >::localize_to_one ( std::vector< T > &  v_local,
const processor_id_type  proc_id = 0 
) const
virtual

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 >.

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

Definition at line 942 of file petsc_vector.C.

References libMesh::ctx, ierr, libMesh::n_processors(), and libMesh::processor_id().

944 {
945  this->_restore_array();
946 
947  PetscErrorCode ierr=0;
948  const PetscInt n = size();
949  const PetscInt nl = local_size();
950  PetscScalar * values;
951 
952 
953  // only one processor
954  if (n_processors() == 1)
955  {
956  v_local.resize(n);
957 
958  ierr = VecGetArray (_vec, &values);
959  LIBMESH_CHKERR(ierr);
960 
961  for (PetscInt i=0; i<n; i++)
962  v_local[i] = static_cast<Real>(values[i]);
963 
964  ierr = VecRestoreArray (_vec, &values);
965  LIBMESH_CHKERR(ierr);
966  }
967 
968  // otherwise multiple processors
969  else
970  {
971  if(pid == 0) // optimized version for localizing to 0
972  {
973  Vec vout;
974  VecScatter ctx;
975 
976  ierr = VecScatterCreateToZero(_vec, &ctx, &vout);
977  LIBMESH_CHKERR(ierr);
978 
979  ierr = VecScatterBegin(ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
980  LIBMESH_CHKERR(ierr);
981  ierr = VecScatterEnd(ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
982  LIBMESH_CHKERR(ierr);
983 
984  if(processor_id() == 0)
985  {
986  v_local.resize(n);
987 
988  ierr = VecGetArray (vout, &values);
989  LIBMESH_CHKERR(ierr);
990 
991  for (PetscInt i=0; i<n; i++)
992  v_local[i] = static_cast<Real>(values[i]);
993 
994  ierr = VecRestoreArray (vout, &values);
995  LIBMESH_CHKERR(ierr);
996  }
997 
998  ierr = LibMeshVecScatterDestroy(&ctx);
999  LIBMESH_CHKERR(ierr);
1000  ierr = LibMeshVecDestroy(&vout);
1001  LIBMESH_CHKERR(ierr);
1002 
1003  }
1004  else
1005  {
1006  v_local.resize(n);
1007 
1008  numeric_index_type ioff = this->first_local_index();
1009  std::vector<Real> local_values (n, 0.);
1010 
1011  {
1012  ierr = VecGetArray (_vec, &values);
1013  LIBMESH_CHKERR(ierr);
1014 
1015  for (PetscInt i=0; i<nl; i++)
1016  local_values[i+ioff] = static_cast<Real>(values[i]);
1017 
1018  ierr = VecRestoreArray (_vec, &values);
1019  LIBMESH_CHKERR(ierr);
1020  }
1021 
1022 
1023  MPI_Reduce (&local_values[0], &v_local[0], n, MPI_REAL, MPI_SUM,
1024  pid, this->comm().get());
1025  }
1026  }
1027 }
processor_id_type n_processors() const
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
PetscErrorCode Vec Mat Mat void * ctx
virtual numeric_index_type size() const libmesh_override
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual numeric_index_type local_size() const libmesh_override
virtual numeric_index_type first_local_index() const libmesh_override
processor_id_type processor_id() const
template<>
void libMesh::PetscVector< Complex >::localize_to_one ( std::vector< Complex > &  v_local,
const processor_id_type  pid 
) const

Definition at line 1036 of file petsc_vector.C.

References ierr.

1038 {
1039  this->_restore_array();
1040 
1041  PetscErrorCode ierr=0;
1042  const PetscInt n = size();
1043  const PetscInt nl = local_size();
1044  PetscScalar * values;
1045 
1046 
1047  v_local.resize(n);
1048 
1049 
1050  for (PetscInt i=0; i<n; i++)
1051  v_local[i] = 0.;
1052 
1053  // only one processor
1054  if (n == nl)
1055  {
1056  ierr = VecGetArray (_vec, &values);
1057  LIBMESH_CHKERR(ierr);
1058 
1059  for (PetscInt i=0; i<n; i++)
1060  v_local[i] = static_cast<Complex>(values[i]);
1061 
1062  ierr = VecRestoreArray (_vec, &values);
1063  LIBMESH_CHKERR(ierr);
1064  }
1065 
1066  // otherwise multiple processors
1067  else
1068  {
1069  numeric_index_type ioff = this->first_local_index();
1070 
1071  /* in here the local values are stored, acting as send buffer for MPI
1072  * initialize to zero, since we collect using MPI_SUM
1073  */
1074  std::vector<Real> real_local_values(n, 0.);
1075  std::vector<Real> imag_local_values(n, 0.);
1076 
1077  {
1078  ierr = VecGetArray (_vec, &values);
1079  LIBMESH_CHKERR(ierr);
1080 
1081  // provide my local share to the real and imag buffers
1082  for (PetscInt i=0; i<nl; i++)
1083  {
1084  real_local_values[i+ioff] = static_cast<Complex>(values[i]).real();
1085  imag_local_values[i+ioff] = static_cast<Complex>(values[i]).imag();
1086  }
1087 
1088  ierr = VecRestoreArray (_vec, &values);
1089  LIBMESH_CHKERR(ierr);
1090  }
1091 
1092  /* have buffers of the real and imaginary part of v_local.
1093  * Once MPI_Reduce() collected all the real and imaginary
1094  * parts in these std::vector<Real>, the values can be
1095  * copied to v_local
1096  */
1097  std::vector<Real> real_v_local(n);
1098  std::vector<Real> imag_v_local(n);
1099 
1100  // collect entries from other proc's in real_v_local, imag_v_local
1101  MPI_Reduce (&real_local_values[0], &real_v_local[0], n,
1102  MPI_REAL, MPI_SUM,
1103  pid, this->comm().get());
1104 
1105  MPI_Reduce (&imag_local_values[0], &imag_v_local[0], n,
1106  MPI_REAL, MPI_SUM,
1107  pid, this->comm().get());
1108 
1109  // copy real_v_local and imag_v_local to v_local
1110  for (PetscInt i=0; i<n; i++)
1111  v_local[i] = Complex(real_v_local[i], imag_v_local[i]);
1112  }
1113 }
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
std::complex< Real > Complex
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual numeric_index_type local_size() const libmesh_override
virtual numeric_index_type first_local_index() const libmesh_override
template<typename T >
numeric_index_type libMesh::PetscVector< T >::map_global_to_local_index ( const numeric_index_type  i) const
inline

Maps the global index i to the corresponding global index. 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 1214 of file petsc_vector.h.

References libMesh::PetscVector< T >::_array_is_present, libMesh::PetscVector< T >::_first, libMesh::PetscVector< T >::_global_to_local_map, libMesh::PetscVector< T >::_last, libMesh::PetscVector< T >::_vec, end, ierr, libMesh::NumericVector< T >::initialized(), and libMesh::libmesh_assert().

Referenced by libMesh::PetscVector< T >::get(), and libMesh::PetscVector< T >::operator()().

1215 {
1216  libmesh_assert (this->initialized());
1217 
1218  numeric_index_type first=0;
1219  numeric_index_type last=0;
1220 
1221  if(_array_is_present) // Can we use cached values?
1222  {
1223  first = _first;
1224  last = _last;
1225  }
1226  else
1227  {
1228  PetscErrorCode ierr=0;
1229  PetscInt petsc_first=0, petsc_last=0;
1230  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1231  LIBMESH_CHKERR(ierr);
1232  first = static_cast<numeric_index_type>(petsc_first);
1233  last = static_cast<numeric_index_type>(petsc_last);
1234  }
1235 
1236 
1237  if((i>=first) && (i<last))
1238  {
1239  return i-first;
1240  }
1241 
1242  GlobalToLocalMap::const_iterator it = _global_to_local_map.find(i);
1243 #ifndef NDEBUG
1244  const GlobalToLocalMap::const_iterator end = _global_to_local_map.end();
1245  if (it == end)
1246  {
1247  std::ostringstream error_message;
1248  error_message << "No index " << i << " in ghosted vector.\n"
1249  << "Vector contains [" << first << ',' << last << ")\n";
1250  GlobalToLocalMap::const_iterator b = _global_to_local_map.begin();
1251  if (b == end)
1252  {
1253  error_message << "And empty ghost array.\n";
1254  }
1255  else
1256  {
1257  error_message << "And ghost array {" << b->first;
1258  for (++b; b != end; ++b)
1259  error_message << ',' << b->first;
1260  error_message << "}\n";
1261  }
1262 
1263  libmesh_error_msg(error_message.str());
1264  }
1265  libmesh_assert (it != _global_to_local_map.end());
1266 #endif
1267  return it->second+last-first;
1268 }
numeric_index_type _last
Definition: petsc_vector.h:566
IterBase * end
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
libmesh_assert(j)
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:634
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
numeric_index_type _first
Definition: petsc_vector.h:559
template<typename T >
Real libMesh::PetscVector< T >::max ( ) const
inlinevirtual
Returns
the maximum element in the vector. In case of complex numbers, this returns the maximum Real part.

Implements libMesh::NumericVector< T >.

Definition at line 1369 of file petsc_vector.h.

References libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, ierr, and libMesh::Real.

1370 {
1371  parallel_object_only();
1372 
1373  this->_restore_array();
1374 
1375  PetscErrorCode ierr=0;
1376  PetscInt index=0;
1377  PetscReal returnval=0.;
1378 
1379  ierr = VecMax (_vec, &index, &returnval);
1380  LIBMESH_CHKERR(ierr);
1381 
1382  // this return value is correct: VecMax returns a PetscReal
1383  return static_cast<Real>(returnval);
1384 }
void _restore_array() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PetscErrorCode ierr
template<typename T >
Real libMesh::PetscVector< T >::min ( ) const
inlinevirtual
Returns
the minimum element in the vector. In case of complex numbers, this returns the minimum Real part.

Implements libMesh::NumericVector< T >.

Definition at line 1348 of file petsc_vector.h.

References libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, ierr, and libMesh::Real.

1349 {
1350  parallel_object_only();
1351 
1352  this->_restore_array();
1353 
1354  PetscErrorCode ierr=0;
1355  PetscInt index=0;
1356  PetscReal returnval=0.;
1357 
1358  ierr = VecMin (_vec, &index, &returnval);
1359  LIBMESH_CHKERR(ierr);
1360 
1361  // this return value is correct: VecMin returns a PetscReal
1362  return static_cast<Real>(returnval);
1363 }
void _restore_array() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PetscErrorCode ierr
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
Returns
the number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::MeshCommunication::broadcast(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::get_solution(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), 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::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::MeshTools::processor_bounding_box(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

94  { return cast_int<processor_id_type>(_communicator.size()); }
unsigned int size() const
Definition: parallel.h:679
const Parallel::Communicator & _communicator
template<typename T >
T libMesh::PetscVector< T >::operator() ( const numeric_index_type  i) const
inlinevirtual

Access components, returns U(i).

Implements libMesh::NumericVector< T >.

Definition at line 1274 of file petsc_vector.h.

References libMesh::PetscVector< T >::_get_array(), libMesh::PetscVector< T >::_local_size, libMesh::PetscVector< T >::_read_only_values, libMesh::GHOSTED, libMesh::PetscVector< T >::map_global_to_local_index(), and libMesh::NumericVector< T >::type().

1275 {
1276  this->_get_array(true);
1277 
1278  const numeric_index_type local_index = this->map_global_to_local_index(i);
1279 
1280 #ifndef NDEBUG
1281  if(this->type() == GHOSTED)
1282  {
1283  libmesh_assert_less (local_index, _local_size);
1284  }
1285 #endif
1286 
1287  return static_cast<T>(_read_only_values[local_index]);
1288 }
void _get_array(bool read_only) const
numeric_index_type _local_size
Definition: petsc_vector.h:571
const PetscScalar * _read_only_values
Definition: petsc_vector.h:588
numeric_index_type map_global_to_local_index(const numeric_index_type i) const
dof_id_type numeric_index_type
Definition: id_types.h:92
ParallelType type() const
template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator*= ( const T  a)
inlineinherited

Multiplication operator. Equivalent to U.scale(a)

Definition at line 381 of file numeric_vector.h.

381 { this->scale(a); return *this; }
virtual void scale(const T factor)=0
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator+= ( const NumericVector< T > &  V)
virtual

Addition operator. Fast equivalent to U.add(1, V).

Implements libMesh::NumericVector< T >.

Definition at line 111 of file petsc_vector.C.

References libMesh::closed(), and libMesh::libmesh_assert().

112 {
113  this->_restore_array();
114  libmesh_assert(this->closed());
115 
116  this->add(1., v);
117 
118  return *this;
119 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
virtual void add(const numeric_index_type i, const T value) libmesh_override
Definition: petsc_vector.C:180
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator-= ( const NumericVector< T > &  V)
virtual

Subtraction operator. Fast equivalent to U.add(-1, V).

Implements libMesh::NumericVector< T >.

Definition at line 125 of file petsc_vector.C.

References libMesh::closed(), and libMesh::libmesh_assert().

126 {
127  this->_restore_array();
128  libmesh_assert(this->closed());
129 
130  this->add(-1., v);
131 
132  return *this;
133 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
virtual void add(const numeric_index_type i, const T value) libmesh_override
Definition: petsc_vector.C:180
template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator/= ( const T  a)
inlineinherited

Division operator. Equivalent to U.scale(1./a)

Definition at line 387 of file numeric_vector.h.

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

387 { this->scale(1./a); return *this; }
virtual void scale(const T factor)=0
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator/= ( NumericVector< T > &  v)
virtual

Pointwise Division operator. ie divide every entry in this vector by the entry in v

Implements libMesh::NumericVector< T >.

Definition at line 405 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec, and ierr.

406 {
407  PetscErrorCode ierr = 0;
408 
409  const PetscVector<T> * v_vec = cast_ptr<const PetscVector<T> *>(&v);
410 
411  ierr = VecPointwiseDivide(_vec, _vec, v_vec->_vec);
412  LIBMESH_CHKERR(ierr);
413 
414  return *this;
415 }
PetscErrorCode ierr
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const T  s)
virtual

$U(0-N) = s$: fill all components.

Implements libMesh::NumericVector< T >.

Definition at line 488 of file petsc_vector.C.

References libMesh::closed(), libMesh::GHOSTED, ierr, and libMesh::libmesh_assert().

489 {
490  this->_restore_array();
491  libmesh_assert(this->closed());
492 
493  PetscErrorCode ierr = 0;
494  PetscScalar s = static_cast<PetscScalar>(s_in);
495 
496  if (this->size() != 0)
497  {
498  if(this->type() != GHOSTED)
499  {
500  ierr = VecSet(_vec, s);
501  LIBMESH_CHKERR(ierr);
502  }
503  else
504  {
505  Vec loc_vec;
506  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
507  LIBMESH_CHKERR(ierr);
508 
509  ierr = VecSet(loc_vec, s);
510  LIBMESH_CHKERR(ierr);
511 
512  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
513  LIBMESH_CHKERR(ierr);
514  }
515  }
516 
517  return *this;
518 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
PetscErrorCode ierr
ParallelType type() const
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const NumericVector< T > &  V)
virtual

$U = V$: copy all components.

Implements libMesh::NumericVector< T >.

Definition at line 524 of file petsc_vector.C.

525 {
526  // Make sure the NumericVector passed in is really a PetscVector
527  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
528 
529  *this = *v;
530 
531  return *this;
532 }
template<typename T >
PetscVector< T > & libMesh::PetscVector< T >::operator= ( const PetscVector< T > &  V)

$U = V$: copy all components.

Definition at line 538 of file petsc_vector.C.

References libMesh::PetscVector< T >::_restore_array(), libMesh::NumericVector< T >::_type, libMesh::PetscVector< T >::_vec, libMesh::NumericVector< T >::closed(), libMesh::GHOSTED, ierr, libMesh::libmesh_assert(), libMesh::PetscVector< T >::local_size(), libMesh::PARALLEL, libMesh::SERIAL, libMesh::PetscVector< T >::size(), and libMesh::NumericVector< T >::type().

539 {
540  this->_restore_array();
541  v._restore_array();
542 
543  libmesh_assert_equal_to (this->size(), v.size());
544  libmesh_assert_equal_to (this->local_size(), v.local_size());
545  libmesh_assert (v.closed());
546 
547  PetscErrorCode ierr = 0;
548 
549  if (((this->type()==PARALLEL) && (v.type()==GHOSTED)) ||
550  ((this->type()==GHOSTED) && (v.type()==PARALLEL)) ||
551  ((this->type()==GHOSTED) && (v.type()==SERIAL)) ||
552  ((this->type()==SERIAL) && (v.type()==GHOSTED)))
553  {
554  /* Allow assignment of a ghosted to a parallel vector since this
555  causes no difficulty. See discussion in libmesh-devel of
556  June 24, 2010. */
557  ierr = VecCopy (v._vec, this->_vec);
558  LIBMESH_CHKERR(ierr);
559  }
560  else
561  {
562  /* In all other cases, we assert that both vectors are of equal
563  type. */
564  libmesh_assert_equal_to (this->_type, v._type);
565 
566  if (v.size() != 0)
567  {
568  if(this->type() != GHOSTED)
569  {
570  ierr = VecCopy (v._vec, this->_vec);
571  LIBMESH_CHKERR(ierr);
572  }
573  else
574  {
575  Vec loc_vec;
576  Vec v_loc_vec;
577  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
578  LIBMESH_CHKERR(ierr);
579  ierr = VecGhostGetLocalForm (v._vec,&v_loc_vec);
580  LIBMESH_CHKERR(ierr);
581 
582  ierr = VecCopy (v_loc_vec, loc_vec);
583  LIBMESH_CHKERR(ierr);
584 
585  ierr = VecGhostRestoreLocalForm (v._vec,&v_loc_vec);
586  LIBMESH_CHKERR(ierr);
587  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
588  LIBMESH_CHKERR(ierr);
589  }
590  }
591  }
592 
593  close();
594 
595  return *this;
596 }
libmesh_assert(j)
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
virtual void close() libmesh_override
PetscErrorCode ierr
virtual numeric_index_type local_size() const libmesh_override
ParallelType type() const
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const std::vector< T > &  v)
virtual

$U = V$: copy all components.

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 602 of file petsc_vector.C.

References libMesh::GHOSTED.

603 {
604  this->_get_array(false);
605 
610  if (this->size() == v.size())
611  {
614  for (numeric_index_type i=0; i<last-first; i++)
615  _values[i] = static_cast<PetscScalar>(v[first + i]);
616  }
617 
622  else
623  {
624  for (numeric_index_type i=0; i<_local_size; i++)
625  _values[i] = static_cast<PetscScalar>(v[i]);
626  }
627 
628  // Make sure ghost dofs are up to date
629  if (this->type() == GHOSTED)
630  this->close();
631 
632  return *this;
633 }
void _get_array(bool read_only) const
numeric_index_type _local_size
Definition: petsc_vector.h:571
PetscScalar * _values
Definition: petsc_vector.h:598
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual numeric_index_type size() const libmesh_override
virtual void close() libmesh_override
ParallelType type() const
virtual numeric_index_type first_local_index() const libmesh_override
virtual numeric_index_type last_local_index() const libmesh_override
template<typename T >
void libMesh::PetscVector< T >::pointwise_mult ( const NumericVector< T > &  vec1,
const NumericVector< T > &  vec2 
)
virtual

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

Implements libMesh::NumericVector< T >.

Definition at line 1120 of file petsc_vector.C.

References libMesh::GHOSTED, and ierr.

1122 {
1123  this->_restore_array();
1124 
1125  PetscErrorCode ierr = 0;
1126 
1127  // Convert arguments to PetscVector*.
1128  const PetscVector<T> * vec1_petsc = cast_ptr<const PetscVector<T> *>(&vec1);
1129  const PetscVector<T> * vec2_petsc = cast_ptr<const PetscVector<T> *>(&vec2);
1130 
1131  // Call PETSc function.
1132 
1133  if(this->type() != GHOSTED)
1134  {
1135  ierr = VecPointwiseMult(this->vec(),
1136  const_cast<PetscVector<T> *>(vec1_petsc)->vec(),
1137  const_cast<PetscVector<T> *>(vec2_petsc)->vec());
1138  LIBMESH_CHKERR(ierr);
1139  }
1140  else
1141  {
1142  Vec loc_vec;
1143  Vec v1_loc_vec;
1144  Vec v2_loc_vec;
1145  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
1146  LIBMESH_CHKERR(ierr);
1147  ierr = VecGhostGetLocalForm (const_cast<PetscVector<T> *>(vec1_petsc)->vec(),&v1_loc_vec);
1148  LIBMESH_CHKERR(ierr);
1149  ierr = VecGhostGetLocalForm (const_cast<PetscVector<T> *>(vec2_petsc)->vec(),&v2_loc_vec);
1150  LIBMESH_CHKERR(ierr);
1151 
1152  ierr = VecPointwiseMult(loc_vec,v1_loc_vec,v2_loc_vec);
1153  LIBMESH_CHKERR(ierr);
1154 
1155  ierr = VecGhostRestoreLocalForm (const_cast<PetscVector<T> *>(vec1_petsc)->vec(),&v1_loc_vec);
1156  LIBMESH_CHKERR(ierr);
1157  ierr = VecGhostRestoreLocalForm (const_cast<PetscVector<T> *>(vec2_petsc)->vec(),&v2_loc_vec);
1158  LIBMESH_CHKERR(ierr);
1159  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
1160  LIBMESH_CHKERR(ierr);
1161  }
1162 }
void _restore_array() const
PetscErrorCode ierr
ParallelType type() const
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 921 of file numeric_vector.h.

References libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::initialized(), libMesh::NumericVector< T >::last_local_index(), libMesh::libmesh_assert(), libMesh::NumericVector< T >::local_size(), and libMesh::NumericVector< T >::size().

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

922 {
923  libmesh_assert (this->initialized());
924  os << "Size\tglobal = " << this->size()
925  << "\t\tlocal = " << this->local_size() << std::endl;
926 
927  os << "#\tValue" << std::endl;
928  for (numeric_index_type i=this->first_local_index(); i<this->last_local_index(); i++)
929  os << i << "\t" << (*this)(i) << std::endl;
930 }
virtual numeric_index_type size() const =0
virtual numeric_index_type last_local_index() const =0
virtual bool initialized() const
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual numeric_index_type local_size() const =0
virtual numeric_index_type first_local_index() const =0
template<>
void libMesh::NumericVector< Complex >::print ( std::ostream &  os) const
inlineinherited

Definition at line 903 of file numeric_vector.h.

References libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::initialized(), libMesh::NumericVector< T >::last_local_index(), libMesh::libmesh_assert(), libMesh::NumericVector< T >::local_size(), and libMesh::NumericVector< T >::size().

904 {
905  libmesh_assert (this->initialized());
906  os << "Size\tglobal = " << this->size()
907  << "\t\tlocal = " << this->local_size() << std::endl;
908 
909  // std::complex<>::operator<<() is defined, but use this form
910  os << "#\tReal part\t\tImaginary part" << std::endl;
911  for (numeric_index_type i=this->first_local_index(); i<this->last_local_index(); i++)
912  os << i << "\t"
913  << (*this)(i).real() << "\t\t"
914  << (*this)(i).imag() << std::endl;
915 }
virtual numeric_index_type size() const =0
virtual numeric_index_type last_local_index() const =0
virtual bool initialized() const
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual numeric_index_type local_size() const =0
virtual numeric_index_type first_local_index() const =0
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 958 of file numeric_vector.h.

References libMesh::NumericVector< T >::initialized(), libMesh::libmesh_assert(), libMesh::NumericVector< T >::localize(), libMesh::ParallelObject::processor_id(), and libMesh::NumericVector< T >::size().

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

959 {
960  libmesh_assert (this->initialized());
961 
962  std::vector<T> v(this->size());
963  this->localize(v);
964 
965  // Right now we only want one copy of the output
966  if (this->processor_id())
967  return;
968 
969  os << "Size\tglobal = " << this->size() << std::endl;
970  os << "#\tValue" << std::endl;
971  for (numeric_index_type i=0; i!=v.size(); i++)
972  os << i << "\t" << v[i] << std::endl;
973 }
virtual numeric_index_type size() const =0
virtual bool initialized() const
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual void localize(std::vector< T > &v_local) const =0
processor_id_type processor_id() const
template<>
void libMesh::NumericVector< Complex >::print_global ( std::ostream &  os) const
inlineinherited

Definition at line 936 of file numeric_vector.h.

References libMesh::NumericVector< T >::initialized(), libMesh::libmesh_assert(), libMesh::NumericVector< T >::localize(), libMesh::ParallelObject::processor_id(), and libMesh::NumericVector< T >::size().

937 {
938  libmesh_assert (this->initialized());
939 
940  std::vector<Complex> v(this->size());
941  this->localize(v);
942 
943  // Right now we only want one copy of the output
944  if (this->processor_id())
945  return;
946 
947  os << "Size\tglobal = " << this->size() << std::endl;
948  os << "#\tReal part\t\tImaginary part" << std::endl;
949  for (numeric_index_type i=0; i!=v.size(); i++)
950  os << i << "\t"
951  << v[i].real() << "\t\t"
952  << v[i].imag() << std::endl;
953 }
virtual numeric_index_type size() const =0
virtual bool initialized() const
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual void localize(std::vector< T > &v_local) const =0
processor_id_type processor_id() const
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

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

Definition at line 88 of file reference_counter.C.

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

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

89 {
91 }
static std::string get_info()
template<typename T >
void libMesh::PetscVector< T >::print_matlab ( const std::string &  name = "") const
virtual

Print the contents of the vector in Matlab format. Optionally prints the matrix 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 1167 of file petsc_vector.C.

References libMesh::closed(), ierr, and libMesh::libmesh_assert().

1168 {
1169  this->_restore_array();
1170  libmesh_assert (this->closed());
1171 
1172  PetscErrorCode ierr=0;
1173  PetscViewer petsc_viewer;
1174 
1175 
1176  ierr = PetscViewerCreate (this->comm().get(),
1177  &petsc_viewer);
1178  LIBMESH_CHKERR(ierr);
1179 
1184  if (name != "")
1185  {
1186  ierr = PetscViewerASCIIOpen( this->comm().get(),
1187  name.c_str(),
1188  &petsc_viewer);
1189  LIBMESH_CHKERR(ierr);
1190 
1191 #if PETSC_VERSION_LESS_THAN(3,7,0)
1192  ierr = PetscViewerSetFormat (petsc_viewer,
1193  PETSC_VIEWER_ASCII_MATLAB);
1194 #else
1195  ierr = PetscViewerPushFormat (petsc_viewer,
1196  PETSC_VIEWER_ASCII_MATLAB);
1197 #endif
1198 
1199  LIBMESH_CHKERR(ierr);
1200 
1201  ierr = VecView (_vec, petsc_viewer);
1202  LIBMESH_CHKERR(ierr);
1203  }
1204 
1208  else
1209  {
1210 
1211 #if PETSC_VERSION_LESS_THAN(3,7,0)
1212  ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
1213  PETSC_VIEWER_ASCII_MATLAB);
1214 #else
1215  ierr = PetscViewerPushFormat (PETSC_VIEWER_STDOUT_WORLD,
1216  PETSC_VIEWER_ASCII_MATLAB);
1217 #endif
1218 
1219  LIBMESH_CHKERR(ierr);
1220 
1221  ierr = VecView (_vec, PETSC_VIEWER_STDOUT_WORLD);
1222  LIBMESH_CHKERR(ierr);
1223  }
1224 
1225 
1229  ierr = LibMeshPetscViewerDestroy (&petsc_viewer);
1230  LIBMESH_CHKERR(ierr);
1231 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
PetscErrorCode ierr
const Parallel::Communicator & comm() const
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
the rank of this processor in the group.

Definition at line 99 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::rank().

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshRefinement::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::MeshCommunication::broadcast(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::ParmetisPartitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DofMap::build_sparsity(), 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::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::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::EnsightIO::EnsightIO(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), 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::MeshBase::get_info(), 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::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::EquationSystems::get_solution(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), 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::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), 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::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MetisPartitioner::partition_range(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NumericVector< T >::print_global(), 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::ExodusII_IO_Helper::read_elem_num_map(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshTools::total_weight(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::XdrIO::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_elements(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), 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::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

100  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
unsigned int rank() const
Definition: parallel.h:677
template<typename T >
void libMesh::PetscVector< T >::reciprocal ( )
virtual

Replace each entry v_i of this vector by its reciprocal, 1/v_i.

Implements libMesh::NumericVector< T >.

Definition at line 156 of file petsc_vector.C.

References ierr.

157 {
158  PetscErrorCode ierr = 0;
159 
160  // VecReciprocal has been in PETSc since at least 2.3.3 days
161  ierr = VecReciprocal(_vec);
162  LIBMESH_CHKERR(ierr);
163 }
PetscErrorCode ierr
template<typename T >
void libMesh::PetscVector< T >::restore_array ( )
inline

Restore the data array.

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

Definition at line 1338 of file petsc_vector.h.

References libMesh::PetscVector< T >::_restore_array(), and libMesh::PetscVector< T >::_values_manually_retrieved.

1339 {
1340  // Note _values_manually_retrieved needs to be set to false
1341  // BEFORE calling _restore_array()!
1343  _restore_array();
1344 }
void _restore_array() const
template<typename T >
void libMesh::PetscVector< T >::scale ( const T  factor)
virtual

Scale each element of the vector by the given factor.

Implements libMesh::NumericVector< T >.

Definition at line 378 of file petsc_vector.C.

References libMesh::GHOSTED, and ierr.

379 {
380  this->_restore_array();
381 
382  PetscErrorCode ierr = 0;
383  PetscScalar factor = static_cast<PetscScalar>(factor_in);
384 
385  if(this->type() != GHOSTED)
386  {
387  ierr = VecScale(_vec, factor);
388  LIBMESH_CHKERR(ierr);
389  }
390  else
391  {
392  Vec loc_vec;
393  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
394  LIBMESH_CHKERR(ierr);
395 
396  ierr = VecScale(loc_vec, factor);
397  LIBMESH_CHKERR(ierr);
398 
399  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
400  LIBMESH_CHKERR(ierr);
401  }
402 }
void _restore_array() const
PetscErrorCode ierr
ParallelType type() const
template<typename T >
void libMesh::PetscVector< T >::set ( const numeric_index_type  i,
const T  value 
)
virtual

v(i) = value

Implements libMesh::NumericVector< T >.

Definition at line 138 of file petsc_vector.C.

References ierr.

139 {
140  this->_restore_array();
141  libmesh_assert_less (i, size());
142 
143  PetscErrorCode ierr=0;
144  PetscInt i_val = static_cast<PetscInt>(i);
145  PetscScalar petsc_value = static_cast<PetscScalar>(value);
146 
147  ierr = VecSetValues (_vec, 1, &i_val, &petsc_value, INSERT_VALUES);
148  LIBMESH_CHKERR(ierr);
149 
150  this->_is_closed = false;
151 }
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
PetscErrorCode ierr
template<typename T >
numeric_index_type libMesh::PetscVector< T >::size ( ) const
inlinevirtual
Returns
dimension of the vector. This function was formerly called n(), but was renamed to get the PetscVector<T> class closer to the C++ standard library's std::vector container.

Implements libMesh::NumericVector< T >.

Definition at line 1129 of file petsc_vector.h.

References libMesh::PetscVector< T >::_vec, ierr, libMesh::NumericVector< T >::initialized(), and libMesh::libmesh_assert().

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

1130 {
1131  libmesh_assert (this->initialized());
1132 
1133  PetscErrorCode ierr=0;
1134  PetscInt petsc_size=0;
1135 
1136  if (!this->initialized())
1137  return 0;
1138 
1139  ierr = VecGetSize(_vec, &petsc_size);
1140  LIBMESH_CHKERR(ierr);
1141 
1142  return static_cast<numeric_index_type>(petsc_size);
1143 }
virtual bool initialized() const
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
template<class T >
Real libMesh::NumericVector< T >::subset_l1_norm ( const std::set< numeric_index_type > &  indices) const
virtualinherited
Returns
the $l_1$-norm of the vector, i.e. the sum of the absolute values for the specified entries in the vector.

Note that the indices must necessary live on this processor.

Definition at line 323 of file numeric_vector.C.

References std::abs(), and libMesh::Real.

Referenced by libMesh::NumericVector< Number >::closed(), and libMesh::System::discrete_var_norm().

324 {
325  const NumericVector<T> & v = *this;
326 
327  std::set<numeric_index_type>::const_iterator it = indices.begin();
328  const std::set<numeric_index_type>::const_iterator it_end = indices.end();
329 
330  Real norm = 0;
331 
332  for(; it!=it_end; ++it)
333  norm += std::abs(v(*it));
334 
335  this->comm().sum(norm);
336 
337  return norm;
338 }
double abs(double a)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
template<class T >
Real libMesh::NumericVector< T >::subset_l2_norm ( const std::set< numeric_index_type > &  indices) const
virtualinherited
Returns
the $l_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 that the indices must necessary live on this processor.

Definition at line 341 of file numeric_vector.C.

References libMesh::TensorTools::norm_sq(), and libMesh::Real.

Referenced by libMesh::NumericVector< Number >::closed(), and libMesh::System::discrete_var_norm().

342 {
343  const NumericVector<T> & v = *this;
344 
345  std::set<numeric_index_type>::const_iterator it = indices.begin();
346  const std::set<numeric_index_type>::const_iterator it_end = indices.end();
347 
348  Real norm = 0;
349 
350  for(; it!=it_end; ++it)
351  norm += TensorTools::norm_sq(v(*it));
352 
353  this->comm().sum(norm);
354 
355  return std::sqrt(norm);
356 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
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 $l_\infty$-norm of a vector.

Note that the indices must necessary live on this processor.

Definition at line 359 of file numeric_vector.C.

References std::abs(), and libMesh::Real.

Referenced by libMesh::NumericVector< Number >::closed(), and libMesh::System::discrete_var_norm().

360 {
361  const NumericVector<T> & v = *this;
362 
363  std::set<numeric_index_type>::const_iterator it = indices.begin();
364  const std::set<numeric_index_type>::const_iterator it_end = indices.end();
365 
366  Real norm = 0;
367 
368  for(; it!=it_end; ++it)
369  {
370  Real value = std::abs(v(*it));
371  if(value > norm)
372  norm = value;
373  }
374 
375  this->comm().max(norm);
376 
377  return norm;
378 }
double abs(double a)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
template<typename T >
T libMesh::PetscVector< T >::sum ( ) const
virtual
Returns
the sum of values in a vector

Implements libMesh::NumericVector< T >.

Definition at line 41 of file petsc_vector.C.

References libMesh::closed(), ierr, and libMesh::libmesh_assert().

42 {
43  this->_restore_array();
44  libmesh_assert(this->closed());
45 
46  PetscErrorCode ierr=0;
47  PetscScalar value=0.;
48 
49  ierr = VecSum (_vec, &value);
50  LIBMESH_CHKERR(ierr);
51 
52  return static_cast<T>(value);
53 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
PetscErrorCode ierr
template<typename T >
void libMesh::PetscVector< T >::swap ( NumericVector< T > &  v)
inlinevirtual

Swaps the raw PETSc vector context pointers.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1390 of file petsc_vector.h.

References libMesh::PetscVector< T >::_array_is_present, libMesh::PetscVector< T >::_destroy_vec_on_exit, libMesh::PetscVector< T >::_global_to_local_map, libMesh::PetscVector< T >::_local_form, libMesh::PetscVector< T >::_values, libMesh::PetscVector< T >::_vec, swap(), and libMesh::NumericVector< T >::swap().

Referenced by libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_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(), and DMlibMeshJacobian().

1391 {
1392  parallel_object_only();
1393 
1394  NumericVector<T>::swap(other);
1395 
1396  PetscVector<T> & v = cast_ref<PetscVector<T> &>(other);
1397 
1398  std::swap(_vec, v._vec);
1399  std::swap(_destroy_vec_on_exit, v._destroy_vec_on_exit);
1400  std::swap(_global_to_local_map, v._global_to_local_map);
1401 
1402 #ifdef LIBMESH_HAVE_CXX11_THREAD
1403  // Only truly atomic for v... but swap() doesn't really need to be thread safe!
1404  _array_is_present = v._array_is_present.exchange(_array_is_present);
1405 #else
1406  std::swap(_array_is_present, v._array_is_present);
1407 #endif
1408 
1409  std::swap(_local_form, v._local_form);
1410  std::swap(_values, v._values);
1411 }
PetscScalar * _values
Definition: petsc_vector.h:598
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:549
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:634
virtual void swap(NumericVector< T > &v)
void swap(Iterator &lhs, Iterator &rhs)
template<typename T>
ParallelType& libMesh::NumericVector< T >::type ( )
inlineinherited
Returns
the type (SERIAL, PARALLEL, GHOSTED) of the vector.

Definition at line 142 of file numeric_vector.h.

142 { return _type; }
template<typename T >
void libMesh::PetscVector< T >::zero ( )
inlinevirtual

Set all entries to zero. Equivalent to v = 0, but more obvious and faster.

Implements libMesh::NumericVector< T >.

Definition at line 1069 of file petsc_vector.h.

References libMesh::PetscVector< T >::_restore_array(), libMesh::PetscVector< T >::_vec, libMesh::NumericVector< T >::closed(), libMesh::GHOSTED, ierr, libMesh::libmesh_assert(), and libMesh::NumericVector< T >::type().

Referenced by libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::PetscVector< T >::init(), and libMesh::TaoOptimizationSolver< T >::solve().

1070 {
1071  parallel_object_only();
1072 
1073  libmesh_assert(this->closed());
1074 
1075  this->_restore_array();
1076 
1077  PetscErrorCode ierr=0;
1078 
1079  PetscScalar z=0.;
1080 
1081  if(this->type() != GHOSTED)
1082  {
1083  ierr = VecSet (_vec, z);
1084  LIBMESH_CHKERR(ierr);
1085  }
1086  else
1087  {
1088  /* Vectors that include ghost values require a special
1089  handling. */
1090  Vec loc_vec;
1091  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
1092  LIBMESH_CHKERR(ierr);
1093 
1094  ierr = VecSet (loc_vec, z);
1095  LIBMESH_CHKERR(ierr);
1096 
1097  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
1098  LIBMESH_CHKERR(ierr);
1099  }
1100 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
PetscErrorCode ierr
ParallelType type() const
template<typename T >
UniquePtr< NumericVector< T > > libMesh::PetscVector< T >::zero_clone ( ) const
inlinevirtual

Creates a vector which has the same type, size and partitioning as this vector, but whose data is all zero. Returns it in an UniquePtr.

Implements libMesh::NumericVector< T >.

Definition at line 1106 of file petsc_vector.h.

References libMesh::ParallelObject::comm(), libMesh::NumericVector< T >::init(), and libMesh::NumericVector< T >::type().

1107 {
1108  NumericVector<T> * cloned_vector = new PetscVector<T>(this->comm(), this->type());
1109  cloned_vector->init(*this);
1110  return UniquePtr<NumericVector<T> >(cloned_vector);
1111 }
const Parallel::Communicator & comm() const
ParallelType type() const

Member Data Documentation

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 549 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::first_local_index(), libMesh::PetscVector< T >::last_local_index(), libMesh::PetscVector< T >::map_global_to_local_index(), libMesh::PetscVector< T >::PetscVector(), and libMesh::PetscVector< T >::swap().

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

Definition at line 551 of file petsc_vector.h.

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited
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 640 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::clear(), libMesh::PetscVector< T >::PetscVector(), and libMesh::PetscVector< T >::swap().

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 134 of file reference_counter.h.

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

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

First local index.

Only valid when _array_is_present

Definition at line 559 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::first_local_index(), and libMesh::PetscVector< T >::map_global_to_local_index().

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 634 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::clear(), libMesh::PetscVector< T >::init(), libMesh::PetscVector< T >::map_global_to_local_index(), libMesh::PetscVector< T >::PetscVector(), and libMesh::PetscVector< T >::swap().

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

Last local index.

Only valid when _array_is_present

Definition at line 566 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::last_local_index(), and libMesh::PetscVector< T >::map_global_to_local_index().

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 578 of file petsc_vector.h.

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

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

Size of the local values from _get_array()

Definition at line 571 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::get(), and libMesh::PetscVector< T >::operator()().

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

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 128 of file reference_counter.h.

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 123 of file reference_counter.h.

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

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 606 of file petsc_vector.h.

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

Definition at line 608 of file petsc_vector.h.

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 588 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::get(), libMesh::PetscVector< T >::get_array_read(), and libMesh::PetscVector< T >::operator()().

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 598 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::get_array(), libMesh::PetscVector< T >::PetscVector(), and libMesh::PetscVector< T >::swap().

template<typename T>
bool libMesh::PetscVector< T >::_values_manually_retrieved
mutableprivate
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 651 of file petsc_vector.h.

Referenced by libMesh::PetscVector< T >::PetscVector().


The documentation for this class was generated from the following files: