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 N, const numeric_index_type n_local, const std::vector< numeric_index_type > &ghost, const bool fast=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
 
virtual NumericVector< T > & operator= (const std::vector< T > &v) libmesh_override
 
PetscVector< T > & operator= (const PetscVector< T > &v)
 
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) libmesh_override
 
void add_vector_conjugate_transpose (const NumericVector< T > &v, const SparseMatrix< T > &A)
 
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 > &v) const libmesh_override
 
indefinite_dot (const NumericVector< T > &v) 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.

This class provides a nice interface to PETSc's Vec object. All overridden virtual functions are documented in numeric_vector.h.

Author
Benjamin S. Kirk
Date
2002

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 119 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 418 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 451 of file petsc_vector.h.

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

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

451  :
452  NumericVector<T>(comm_in, ptype),
453  _array_is_present(false),
454  _first(0),
455  _last(0),
459  _destroy_vec_on_exit(true),
461  _values_read_only(false)
462 {
463  this->_type = ptype;
464 }
numeric_index_type _last
Definition: petsc_vector.h:356
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:388
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:424
numeric_index_type _first
Definition: petsc_vector.h:349
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 470 of file petsc_vector.h.

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

472  :
473  NumericVector<T>(comm_in, ptype),
474  _array_is_present(false),
478  _destroy_vec_on_exit(true),
480  _values_read_only(false)
481 {
482  this->init(n, n, false, ptype);
483 }
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:625
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:388
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:424
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 489 of file petsc_vector.h.

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

492  :
493  NumericVector<T>(comm_in, ptype),
494  _array_is_present(false),
498  _destroy_vec_on_exit(true),
500  _values_read_only(false)
501 {
502  this->init(n, n_local, false, ptype);
503 }
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:625
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:388
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:424
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 509 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.

513  :
514  NumericVector<T>(comm_in, ptype),
515  _array_is_present(false),
519  _destroy_vec_on_exit(true),
521  _values_read_only(false)
522 {
523  this->init(n, n_local, ghost, false, ptype);
524 }
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:625
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:388
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:424
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 616 of file petsc_vector.h.

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

617 {
618  this->clear ();
619 }
virtual void clear() libmesh_override
Definition: petsc_vector.h:835

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 1348 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()().

1349 {
1350  libmesh_assert (this->initialized());
1351 
1352 #ifdef LIBMESH_HAVE_CXX11_THREAD
1353  std::atomic_thread_fence(std::memory_order_acquire);
1354 #else
1355  Threads::spin_mutex::scoped_lock lock(_petsc_vector_mutex);
1356 #endif
1357 
1358  // If the values have already been retrieved and we're currently
1359  // trying to get a non-read only view (ie read/write) and the
1360  // values are currently read only... then we need to restore
1361  // the array first... and then retrieve it again.
1362  if (_array_is_present && !read_only && _values_read_only)
1363  _restore_array();
1364 
1365  // If we already have a read/write array - and we're trying
1366  // to get a read only array - let's just use the read write
1367  if (_array_is_present && read_only && !_values_read_only)
1369 
1370  if (!_array_is_present)
1371  {
1372 #ifdef LIBMESH_HAVE_CXX11_THREAD
1373  std::lock_guard<std::mutex> lock(_petsc_vector_mutex);
1374 #endif
1375  if (!_array_is_present)
1376  {
1377  PetscErrorCode ierr=0;
1378  if (this->type() != GHOSTED)
1379  {
1380 #if PETSC_VERSION_LESS_THAN(3,2,0)
1381  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1382  // have an older PETSc than that, we'll do an ugly
1383  // const_cast and call VecGetArray() instead.
1384  ierr = VecGetArray(_vec, const_cast<PetscScalar **>(&_values));
1385  _values_read_only = false;
1386 #else
1387  if (read_only)
1388  {
1389  ierr = VecGetArrayRead(_vec, &_read_only_values);
1390  _values_read_only = true;
1391  }
1392  else
1393  {
1394  ierr = VecGetArray(_vec, &_values);
1395  _values_read_only = false;
1396  }
1397 #endif
1398  LIBMESH_CHKERR(ierr);
1399  _local_size = this->local_size();
1400  }
1401  else
1402  {
1403  ierr = VecGhostGetLocalForm (_vec,&_local_form);
1404  LIBMESH_CHKERR(ierr);
1405 
1406 #if PETSC_VERSION_LESS_THAN(3,2,0)
1407  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1408  // have an older PETSc than that, we'll do an ugly
1409  // const_cast and call VecGetArray() instead.
1410  ierr = VecGetArray(_local_form, const_cast<PetscScalar **>(&_values));
1411  _values_read_only = false;
1412 #else
1413  if (read_only)
1414  {
1415  ierr = VecGetArrayRead(_local_form, &_read_only_values);
1416  _values_read_only = true;
1417  }
1418  else
1419  {
1420  ierr = VecGetArray(_local_form, &_values);
1421  _values_read_only = false;
1422  }
1423 #endif
1424  LIBMESH_CHKERR(ierr);
1425 
1426  PetscInt my_local_size = 0;
1427  ierr = VecGetLocalSize(_local_form, &my_local_size);
1428  LIBMESH_CHKERR(ierr);
1429  _local_size = static_cast<numeric_index_type>(my_local_size);
1430  }
1431 
1432  { // cache ownership range
1433  PetscInt petsc_first=0, petsc_last=0;
1434  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1435  LIBMESH_CHKERR(ierr);
1436  _first = static_cast<numeric_index_type>(petsc_first);
1437  _last = static_cast<numeric_index_type>(petsc_last);
1438  }
1439 #ifdef LIBMESH_HAVE_CXX11_THREAD
1440  std::atomic_thread_fence(std::memory_order_release);
1441  _array_is_present.store(true, std::memory_order_relaxed);
1442 #else
1443  _array_is_present = true;
1444 #endif
1445  }
1446  }
1447 }
numeric_index_type _local_size
Definition: petsc_vector.h:361
numeric_index_type _last
Definition: petsc_vector.h:356
PetscScalar * _values
Definition: petsc_vector.h:388
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
libmesh_assert(j)
std::mutex _petsc_vector_mutex
Definition: petsc_vector.h:396
const PetscScalar * _read_only_values
Definition: petsc_vector.h:378
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
Definition: petsc_vector.h:939
ParallelType type() const
numeric_index_type _first
Definition: petsc_vector.h:349
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 1452 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().

1453 {
1455  libmesh_error_msg("PetscVector values were manually retrieved but are being automatically restored!");
1456 
1457 #ifdef LIBMESH_HAVE_CXX11_THREAD
1458  std::atomic_thread_fence(std::memory_order_acquire);
1459 #else
1460  Threads::spin_mutex::scoped_lock lock(_petsc_vector_mutex);
1461 #endif
1462 
1463  libmesh_assert (this->initialized());
1464  if (_array_is_present)
1465  {
1466 #ifdef LIBMESH_HAVE_CXX11_THREAD
1467  std::lock_guard<std::mutex> lock(_petsc_vector_mutex);
1468 #endif
1469 
1470  if (_array_is_present)
1471  {
1472  PetscErrorCode ierr=0;
1473  if (this->type() != GHOSTED)
1474  {
1475 #if PETSC_VERSION_LESS_THAN(3,2,0)
1476  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1477  // have an older PETSc than that, we'll do an ugly
1478  // const_cast and call VecRestoreArray() instead.
1479  ierr = VecRestoreArray (_vec, const_cast<PetscScalar **>(&_values));
1480 #else
1481  if (_values_read_only)
1482  ierr = VecRestoreArrayRead (_vec, &_read_only_values);
1483  else
1484  ierr = VecRestoreArray (_vec, &_values);
1485 #endif
1486 
1487  LIBMESH_CHKERR(ierr);
1489  }
1490  else
1491  {
1492 #if PETSC_VERSION_LESS_THAN(3,2,0)
1493  // Vec{Get,Restore}ArrayRead were introduced in PETSc 3.2.0. If you
1494  // have an older PETSc than that, we'll do an ugly
1495  // const_cast and call VecRestoreArray() instead.
1496  ierr = VecRestoreArray (_local_form, const_cast<PetscScalar **>(&_values));
1497 #else
1498  if (_values_read_only)
1499  ierr = VecRestoreArrayRead (_local_form, &_read_only_values);
1500  else
1501  ierr = VecRestoreArray (_local_form, &_values);
1502 #endif
1503  LIBMESH_CHKERR(ierr);
1505  ierr = VecGhostRestoreLocalForm (_vec,&_local_form);
1506  LIBMESH_CHKERR(ierr);
1508  _local_size = 0;
1509  }
1510 #ifdef LIBMESH_HAVE_CXX11_THREAD
1511  std::atomic_thread_fence(std::memory_order_release);
1512  _array_is_present.store(false, std::memory_order_relaxed);
1513 #else
1514  _array_is_present = false;
1515 #endif
1516  }
1517  }
1518 }
numeric_index_type _local_size
Definition: petsc_vector.h:361
const class libmesh_nullptr_t libmesh_nullptr
PetscScalar * _values
Definition: petsc_vector.h:388
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
libmesh_assert(j)
std::mutex _petsc_vector_mutex
Definition: petsc_vector.h:396
const PetscScalar * _read_only_values
Definition: petsc_vector.h:378
PetscErrorCode ierr
ParallelType type() const
template<typename T >
void libMesh::PetscVector< T >::abs ( )
virtual

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

Implements libMesh::NumericVector< T >.

Definition at line 439 of file petsc_vector.C.

References libMesh::GHOSTED, and ierr.

440 {
441  this->_restore_array();
442 
443  PetscErrorCode ierr = 0;
444 
445  if (this->type() != GHOSTED)
446  {
447  ierr = VecAbs(_vec);
448  LIBMESH_CHKERR(ierr);
449  }
450  else
451  {
452  Vec loc_vec;
453  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
454  LIBMESH_CHKERR(ierr);
455 
456  ierr = VecAbs(loc_vec);
457  LIBMESH_CHKERR(ierr);
458 
459  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
460  LIBMESH_CHKERR(ierr);
461  }
462 }
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

Adds value to each entry of the vector.

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
Definition: petsc_vector.h:919
PetscErrorCode ierr
template<typename T >
void libMesh::PetscVector< T >::add ( const T  s)
virtual

Adds s to each entry of the vector, $ u_i \leftarrow u_i + s $

Implements libMesh::NumericVector< T >.

Definition at line 321 of file petsc_vector.C.

322 {
323  this->_get_array(false);
324 
325  for (numeric_index_type i=0; i<_local_size; i++)
326  _values[i] += v_in;
327 }
void _get_array(bool read_only) const
numeric_index_type _local_size
Definition: petsc_vector.h:361
PetscScalar * _values
Definition: petsc_vector.h:388
dof_id_type numeric_index_type
Definition: id_types.h:92
template<typename T >
void libMesh::PetscVector< T >::add ( const NumericVector< T > &  v)
virtual

Adds v to this, $ \vec{u} \leftarrow \vec{u} + \vec{v} $. Equivalent to calling operator+=().

Implements libMesh::NumericVector< T >.

Definition at line 332 of file petsc_vector.C.

333 {
334  this->add (1., v);
335 }
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

Vector addition with a scalar multiple, $ \vec{u} \leftarrow \vec{u} + a\vec{v} $. Equivalent to calling operator+=().

Implements libMesh::NumericVector< T >.

Definition at line 340 of file petsc_vector.C.

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

341 {
342  this->_restore_array();
343 
344  PetscErrorCode ierr = 0;
345  PetscScalar a = static_cast<PetscScalar>(a_in);
346 
347  // Make sure the NumericVector passed in is really a PetscVector
348  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
349  v->_restore_array();
350 
351  libmesh_assert_equal_to (this->size(), v->size());
352 
353  if (this->type() != GHOSTED)
354  {
355  ierr = VecAXPY(_vec, a, v->_vec);
356  LIBMESH_CHKERR(ierr);
357  }
358  else
359  {
360  Vec loc_vec;
361  Vec v_loc_vec;
362  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
363  LIBMESH_CHKERR(ierr);
364  ierr = VecGhostGetLocalForm (v->_vec,&v_loc_vec);
365  LIBMESH_CHKERR(ierr);
366 
367  ierr = VecAXPY(loc_vec, a, v_loc_vec);
368  LIBMESH_CHKERR(ierr);
369 
370  ierr = VecGhostRestoreLocalForm (v->_vec,&v_loc_vec);
371  LIBMESH_CHKERR(ierr);
372  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
373  LIBMESH_CHKERR(ierr);
374  }
375 }
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
Definition: petsc_vector.h:919
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

Computes $ \vec{u} \leftarrow \vec{u} + \vec{v} $, where v is a pointer and each dof_indices[i] specifies where to add value v[i]. This should be overridden in subclasses for efficiency.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 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

Computes $ \vec{u} \leftarrow \vec{u} + A \vec{v} $, i.e. adds the product of a SparseMatrix A and a NumericVector v to this.

Implements libMesh::NumericVector< T >.

Definition at line 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  // We shouldn't close() the matrix for you, as that would potentially modify the state of a const object.
232  if (!A->closed())
233  {
234  libmesh_deprecated();
235  libmesh_warning("Matrix A must be assembled before calling PetscVector::add_vector(v, A).\n"
236  "Please update your code, as this warning will become an error in a future release.");
237  const_cast<PetscMatrix<T> *>(A)->close();
238  }
239 
240  // The const_cast<> is not elegant, but it is required since PETSc
241  // expects a non-const Mat.
242  ierr = MatMultAdd(const_cast<PetscMatrix<T> *>(A)->mat(), v->_vec, _vec, _vec);
243  LIBMESH_CHKERR(ierr);
244 }
void _restore_array() const
virtual void close() libmesh_override
Definition: petsc_vector.h:807
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

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

Definition at line 837 of file numeric_vector.h.

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

839 {
840  libmesh_assert(v.size() == dof_indices.size());
841  if (!v.empty())
842  this->add_vector(&v[0], dof_indices);
843 }
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

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

Definition at line 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

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

Definition at line 849 of file numeric_vector.h.

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

851 {
852  libmesh_assert(v.size() == dof_indices.size());
853  if (!v.empty())
854  this->add_vector(&v(0), dof_indices);
855 }
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

Computes $ \vec{u} \leftarrow \vec{u} + A \vec{v} $, i.e. adds the product of a ShellMatrix A and a NumericVector v to this.

Definition at line 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 
)

$ U \leftarrow U + A^H v $.

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

Definition at line 277 of file petsc_vector.C.

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

279 {
280  libmesh_error_msg("MatMultHermitianTranspose was introduced in PETSc 3.1.0," \
281  << "No one has made it backwards compatible with older " \
282  << "versions of PETSc so far.");
283 }
template<typename T >
void libMesh::PetscVector< T >::add_vector_transpose ( const NumericVector< T > &  v,
const SparseMatrix< T > &  A 
)
virtual

Computes $ \vec{u} \leftarrow \vec{u} + A^T \vec{v} $, i.e. adds the product of the transpose of a SparseMatrix A and a NumericVector v to this.

Implements libMesh::NumericVector< T >.

Definition at line 249 of file petsc_vector.C.

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

251 {
252  this->_restore_array();
253  // Make sure the data passed in are really of Petsc types
254  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
255  const PetscMatrix<T> * A = cast_ptr<const PetscMatrix<T> *>(&A_in);
256 
257  PetscErrorCode ierr=0;
258 
259  // We shouldn't close() the matrix for you, as that would potentially modify the state of a const object.
260  if (!A->closed())
261  {
262  libmesh_deprecated();
263  libmesh_warning("Matrix A must be assembled before calling PetscVector::add_vector_transpose(v, A).\n"
264  "Please update your code, as this warning will become an error in a future release.");
265  const_cast<PetscMatrix<T> *>(A)->close();
266  }
267 
268  // The const_cast<> is not elegant, but it is required since PETSc
269  // expects a non-const Mat.
270  ierr = MatMultTransposeAdd(const_cast<PetscMatrix<T> *>(A)->mat(), v->_vec, _vec, _vec);
271  LIBMESH_CHKERR(ierr);
272 }
void _restore_array() const
virtual void close() libmesh_override
Definition: petsc_vector.h:807
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:262
TRILINOS_SOLVERS
Definition: libmesh.C:260
LASPACK_SOLVERS
Definition: libmesh.C:264
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:
LIBMESH_DISABLE_COMMWORLD is now the default, use the build() method that takes a Parallel::Communicator instead.

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:208
template<typename T >
void libMesh::PetscVector< T >::clear ( )
inlinevirtual

Restores the NumericVector<T> to a pristine state.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 835 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().

836 {
837  parallel_object_only();
838 
839  if (this->initialized())
840  this->_restore_array();
841 
842  if ((this->initialized()) && (this->_destroy_vec_on_exit))
843  {
844  PetscErrorCode ierr=0;
845 
846  ierr = LibMeshVecDestroy(&_vec);
847  LIBMESH_CHKERR(ierr);
848  }
849 
850  this->_is_closed = this->_is_initialized = false;
851 
852  _global_to_local_map.clear();
853 }
virtual bool initialized() const
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:424
void _restore_array() const
PetscErrorCode ierr
template<typename T >
UniquePtr< NumericVector< T > > libMesh::PetscVector< T >::clone ( ) const
inlinevirtual
Returns
A copy of this vector wrapped in a smart pointer.
Note
This must be overridden in the derived classes.

Implements libMesh::NumericVector< T >.

Definition at line 907 of file petsc_vector.h.

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

908 {
909  NumericVector<T> * cloned_vector = new PetscVector<T>(this->comm(), this->type());
910  cloned_vector->init(*this, true);
911  *cloned_vector = *this;
912  return UniquePtr<NumericVector<T> >(cloned_vector);
913 }
const Parallel::Communicator & comm() const
ParallelType type() const
template<typename T >
void libMesh::PetscVector< T >::close ( )
inlinevirtual

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

Implements libMesh::NumericVector< T >.

Definition at line 807 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().

808 {
809  parallel_object_only();
810 
811  this->_restore_array();
812 
813  PetscErrorCode ierr=0;
814 
815  ierr = VecAssemblyBegin(_vec);
816  LIBMESH_CHKERR(ierr);
817  ierr = VecAssemblyEnd(_vec);
818  LIBMESH_CHKERR(ierr);
819 
820  if (this->type() == GHOSTED)
821  {
822  ierr = VecGhostUpdateBegin(_vec,INSERT_VALUES,SCATTER_FORWARD);
823  LIBMESH_CHKERR(ierr);
824  ierr = VecGhostUpdateEnd(_vec,INSERT_VALUES,SCATTER_FORWARD);
825  LIBMESH_CHKERR(ierr);
826  }
827 
828  this->_is_closed = true;
829 }
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::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::MeshTools::create_bounding_box(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::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::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), 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::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::MeshRefinement::uniformly_coarsen(), 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), or the first index where abs(a[i]-b[i]) exceeds the threshold.

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

Negates the imaginary component of each entry in the vector.

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 > &  ,
const std::vector< numeric_index_type > &   
) const
virtual

Fills in subvector from this vector using the indices in rows. Similar to the create_submatrix() routine for the SparseMatrix class, it is currently only implemented for PetscVectors.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1259 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.

1261 {
1262  this->_restore_array();
1263 
1264  // PETSc data structures
1265  IS parent_is, subvector_is;
1266  VecScatter scatter;
1267  PetscErrorCode ierr = 0;
1268 
1269  // Make sure the passed in subvector is really a PetscVector
1270  PetscVector<T> * petsc_subvector = cast_ptr<PetscVector<T> *>(&subvector);
1271 
1272  // If the petsc_subvector is already initialized, we assume that the
1273  // user has already allocated the *correct* amount of space for it.
1274  // If not, we use the appropriate PETSc routines to initialize it.
1275  if (!petsc_subvector->initialized())
1276  {
1277  // Initialize the petsc_subvector to have enough space to hold
1278  // the entries which will be scattered into it. Note: such an
1279  // init() function (where we let PETSc decide the number of local
1280  // entries) is not currently offered by the PetscVector
1281  // class. Should we differentiate here between sequential and
1282  // parallel vector creation based on this->n_processors() ?
1283  ierr = VecCreateMPI(this->comm().get(),
1284  PETSC_DECIDE, // n_local
1285  cast_int<PetscInt>(rows.size()), // n_global
1286  &(petsc_subvector->_vec));
1287  LIBMESH_CHKERR(ierr);
1288 
1289  ierr = VecSetFromOptions (petsc_subvector->_vec);
1290  LIBMESH_CHKERR(ierr);
1291 
1292  // Mark the subvector as initialized
1293  petsc_subvector->_is_initialized = true;
1294  }
1295  else
1296  {
1297  petsc_subvector->_restore_array();
1298  }
1299 
1300  // Use iota to fill an array with entries [0,1,2,3,4,...rows.size()]
1301  std::vector<PetscInt> idx(rows.size());
1302  Utility::iota (idx.begin(), idx.end(), 0);
1303 
1304  // Construct index sets
1305  ierr = ISCreateLibMesh(this->comm().get(),
1306  rows.size(),
1307  numeric_petsc_cast(&rows[0]),
1309  &parent_is);
1310  LIBMESH_CHKERR(ierr);
1311 
1312  ierr = ISCreateLibMesh(this->comm().get(),
1313  rows.size(),
1314  &idx[0],
1316  &subvector_is);
1317  LIBMESH_CHKERR(ierr);
1318 
1319  // Construct the scatter object
1320  ierr = VecScatterCreate(this->_vec,
1321  parent_is,
1322  petsc_subvector->_vec,
1323  subvector_is,
1324  &scatter); LIBMESH_CHKERR(ierr);
1325 
1326  // Actually perform the scatter
1327  ierr = VecScatterBegin(scatter,
1328  this->_vec,
1329  petsc_subvector->_vec,
1330  INSERT_VALUES,
1331  SCATTER_FORWARD); LIBMESH_CHKERR(ierr);
1332 
1333  ierr = VecScatterEnd(scatter,
1334  this->_vec,
1335  petsc_subvector->_vec,
1336  INSERT_VALUES,
1337  SCATTER_FORWARD); LIBMESH_CHKERR(ierr);
1338 
1339  // Clean up
1340  ierr = LibMeshISDestroy(&parent_is); LIBMESH_CHKERR(ierr);
1341  ierr = LibMeshISDestroy(&subvector_is); LIBMESH_CHKERR(ierr);
1342  ierr = LibMeshVecScatterDestroy(&scatter); LIBMESH_CHKERR(ierr);
1343 }
unsigned int size() const
Definition: parallel.h:722
void iota(ForwardIter first, ForwardIter last, T value)
Definition: utility.h:57
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
Returns
$ \vec{u} \cdot \vec{v} $, the dot product of (*this) with the vector v.

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

Implements libMesh::NumericVector< T >.

Definition at line 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_in);
477 
478  // 2.3.x (at least) style. Untested for previous versions.
479  ierr = VecDot(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>
virtual T libMesh::NumericVector< T >::el ( const numeric_index_type  i) const
inlinevirtualinherited
Returns
(*this)(i).

Definition at line 339 of file numeric_vector.h.

339 { 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 101 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

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

102 {
103  _enable_print_counter = true;
104  return;
105 }
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.
Note
The minimum for this index is 0.

Implements libMesh::NumericVector< T >.

Definition at line 956 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().

957 {
958  libmesh_assert (this->initialized());
959 
960  numeric_index_type first = 0;
961 
962  if (_array_is_present) // Can we use cached values?
963  first = _first;
964  else
965  {
966  PetscErrorCode ierr=0;
967  PetscInt petsc_first=0, petsc_last=0;
968  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
969  LIBMESH_CHKERR(ierr);
970  first = static_cast<numeric_index_type>(petsc_first);
971  }
972 
973  return first;
974 }
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
libmesh_assert(j)
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
numeric_index_type _first
Definition: petsc_vector.h:349
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. The default implementation calls operator() for each index, but some implementations may supply faster methods here.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1084 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().

1086 {
1087  this->_get_array(true);
1088 
1089  const std::size_t num = index.size();
1090 
1091  for (std::size_t i=0; i<num; i++)
1092  {
1093  const numeric_index_type local_index = this->map_global_to_local_index(index[i]);
1094 #ifndef NDEBUG
1095  if (this->type() == GHOSTED)
1096  {
1097  libmesh_assert_less (local_index, _local_size);
1098  }
1099 #endif
1100  values[i] = static_cast<T>(_read_only_values[local_index]);
1101  }
1102 }
void _get_array(bool read_only) const
numeric_index_type _local_size
Definition: petsc_vector.h:361
const PetscScalar * _read_only_values
Definition: petsc_vector.h:378
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 822 of file numeric_vector.h.

824 {
825  const std::size_t num = index.size();
826  values.resize(num);
827  if (!num)
828  return;
829 
830  this->get(index, &values[0]);
831 }
template<typename T >
PetscScalar * libMesh::PetscVector< T >::get_array ( )
inline

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

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

Definition at line 1107 of file petsc_vector.h.

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

1108 {
1110  _get_array(false);
1111 
1112  return _values;
1113 }
void _get_array(bool read_only) const
PetscScalar * _values
Definition: petsc_vector.h:388
template<typename T >
const PetscScalar * libMesh::PetscVector< T >::get_array_read ( ) const
inline

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

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

Definition at line 1118 of file petsc_vector.h.

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

1119 {
1121  _get_array(true);
1122 
1123  return _read_only_values;
1124 }
void _get_array(bool read_only) const
const PetscScalar * _read_only_values
Definition: petsc_vector.h:378
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 global relative threshold), or the first index where abs(a[i]-b[i])/max_j(a[j],b[j]) exceeds the threshold.

Definition at line 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 185 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().

186 {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189 
190  p.first++;
191 }
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 198 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().

199 {
200  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
201  std::pair<unsigned int, unsigned int> & p = _counts[name];
202 
203  p.second++;
204 }
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
Returns
The dot product of (*this) with the vector v.
Note
Does not use the complex-conjugate of v in the complex-valued case.

Definition at line 486 of file petsc_vector.C.

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

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

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

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

Implements libMesh::NumericVector< T >.

Definition at line 625 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().

629 {
630  parallel_object_only();
631 
632  PetscErrorCode ierr=0;
633  PetscInt petsc_n=static_cast<PetscInt>(n);
634  PetscInt petsc_n_local=static_cast<PetscInt>(n_local);
635 
636 
637  // Clear initialized vectors
638  if (this->initialized())
639  this->clear();
640 
641  if (ptype == AUTOMATIC)
642  {
643  if (n == n_local)
644  this->_type = SERIAL;
645  else
646  this->_type = PARALLEL;
647  }
648  else
649  this->_type = ptype;
650 
651  libmesh_assert ((this->_type==SERIAL && n==n_local) ||
652  this->_type==PARALLEL);
653 
654  // create a sequential vector if on only 1 processor
655  if (this->_type == SERIAL)
656  {
657  ierr = VecCreateSeq (PETSC_COMM_SELF, petsc_n, &_vec);
658  CHKERRABORT(PETSC_COMM_SELF,ierr);
659 
660  ierr = VecSetFromOptions (_vec);
661  CHKERRABORT(PETSC_COMM_SELF,ierr);
662  }
663  // otherwise create an MPI-enabled vector
664  else if (this->_type == PARALLEL)
665  {
666 #ifdef LIBMESH_HAVE_MPI
667  libmesh_assert_less_equal (n_local, n);
668  ierr = VecCreateMPI (this->comm().get(), petsc_n_local, petsc_n,
669  &_vec);
670  LIBMESH_CHKERR(ierr);
671 #else
672  libmesh_assert_equal_to (n_local, n);
673  ierr = VecCreateSeq (PETSC_COMM_SELF, petsc_n, &_vec);
674  CHKERRABORT(PETSC_COMM_SELF,ierr);
675 #endif
676 
677  ierr = VecSetFromOptions (_vec);
678  LIBMESH_CHKERR(ierr);
679  }
680  else
681  libmesh_error_msg("Unsupported type " << this->_type);
682 
683  this->_is_initialized = true;
684  this->_is_closed = true;
685 
686 
687  if (fast == false)
688  this->zero ();
689 }
virtual void zero() libmesh_override
Definition: petsc_vector.h:859
virtual bool initialized() const
libmesh_assert(j)
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual void clear() libmesh_override
Definition: petsc_vector.h:835
template<typename T >
void libMesh::PetscVector< T >::init ( const numeric_index_type  ,
const bool  = false,
const ParallelType  = 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 768 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().

770 {
771  parallel_object_only();
772 
773  // Clear initialized vectors
774  if (this->initialized())
775  this->clear();
776 
777  const PetscVector<T> & v = cast_ref<const PetscVector<T> &>(other);
778 
779  // Other vector should restore array.
780  if (v.initialized())
781  {
782  v._restore_array();
783  }
784 
785  this->_global_to_local_map = v._global_to_local_map;
786 
787  // Even if we're initializing sizes based on an uninitialized or
788  // unclosed vector, *this* vector is being initialized now and is
789  // initially closed.
790  this->_is_closed = true; // v._is_closed;
791  this->_is_initialized = true; // v._is_initialized;
792 
793  this->_type = v._type;
794 
795  // We want to have a valid Vec, even if it's initially of size zero
796  PetscErrorCode ierr = VecDuplicate (v._vec, &this->_vec);
797  LIBMESH_CHKERR(ierr);
798 
799  if (fast == false)
800  this->zero ();
801 }
virtual void zero() libmesh_override
Definition: petsc_vector.h:859
virtual bool initialized() const
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:424
PetscErrorCode ierr
virtual void clear() libmesh_override
Definition: petsc_vector.h:835
template<typename T>
virtual bool libMesh::NumericVector< T >::initialized ( ) const
inlinevirtualinherited
Returns
true if the vector has been initialized, false otherwise.

Definition at line 135 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().

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

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

Reimplemented from libMesh::NumericVector< T >.

Definition at line 380 of file petsc_vector.C.

References ierr, and libMesh::numeric_petsc_cast().

382 {
383  if (dof_indices.empty())
384  return;
385 
386  this->_restore_array();
387 
388  PetscErrorCode ierr=0;
389  PetscInt * idx_values = numeric_petsc_cast(&dof_indices[0]);
390  ierr = VecSetValues (_vec, dof_indices.size(), idx_values, v, INSERT_VALUES);
391  LIBMESH_CHKERR(ierr);
392 
393  this->_is_closed = false;
394 }
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

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

Definition at line 861 of file numeric_vector.h.

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

863 {
864  libmesh_assert(v.size() == dof_indices.size());
865  if (!v.empty())
866  this->insert(&v[0], dof_indices);
867 }
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

Inserts the entries of v in *this at the locations specified by 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

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

Definition at line 873 of file numeric_vector.h.

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

875 {
876  libmesh_assert(v.size() == dof_indices.size());
877  if (!v.empty())
878  this->insert(&v(0), dof_indices);
879 }
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

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

Definition at line 885 of file numeric_vector.h.

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

887 {
888  libmesh_assert(v.size() == dof_indices.size());
889  if (!v.empty())
890  this->insert(&v(0), dof_indices);
891 }
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 $ \ell_1 $-norm of the vector, i.e. the sum of the absolute values of the entries.

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 $ \ell_2 $-norm of the vector, i.e. the square root of the sum of the squares of the entries.

Implements libMesh::NumericVector< T >.

Definition at line 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+1 of the last vector element actually stored on this processor.
Note
The maximum for this index is size().

Implements libMesh::NumericVector< T >.

Definition at line 980 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().

981 {
982  libmesh_assert (this->initialized());
983 
984  numeric_index_type last = 0;
985 
986  if (_array_is_present) // Can we use cached values?
987  last = _last;
988  else
989  {
990  PetscErrorCode ierr=0;
991  PetscInt petsc_first=0, petsc_last=0;
992  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
993  LIBMESH_CHKERR(ierr);
994  last = static_cast<numeric_index_type>(petsc_last);
995  }
996 
997  return last;
998 }
numeric_index_type _last
Definition: petsc_vector.h:356
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
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 $ \ell_{\infty} $-norm of the vector, i.e. the maximum absolute value of the entries of the vector.

Implements libMesh::NumericVector< T >.

Definition at line 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), or the first index where abs(a[i]-b[i])/max(a[i],b[i]) exceeds the threshold.

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, i.e. index_stop - index_start.

Implements libMesh::NumericVector< T >.

Definition at line 939 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=().

940 {
941  libmesh_assert (this->initialized());
942 
943  PetscErrorCode ierr=0;
944  PetscInt petsc_size=0;
945 
946  ierr = VecGetLocalSize(_vec, &petsc_size);
947  LIBMESH_CHKERR(ierr);
948 
949  return static_cast<numeric_index_type>(petsc_size);
950 }
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 928 of file petsc_vector.C.

References ierr.

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

929 {
930  this->_restore_array();
931 
932  // This function must be run on all processors at once
933  parallel_object_only();
934 
935  PetscErrorCode ierr=0;
936  const PetscInt n = this->size();
937  const PetscInt nl = this->local_size();
938  PetscScalar * values;
939 
940  v_local.clear();
941  v_local.resize(n, 0.);
942 
943  ierr = VecGetArray (_vec, &values);
944  LIBMESH_CHKERR(ierr);
945 
947 
948  for (PetscInt i=0; i<nl; i++)
949  v_local[i+ioff] = static_cast<T>(values[i]);
950 
951  ierr = VecRestoreArray (_vec, &values);
952  LIBMESH_CHKERR(ierr);
953 
954  this->comm().sum(v_local);
955 }
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
Definition: petsc_vector.h:919
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual numeric_index_type local_size() const libmesh_override
Definition: petsc_vector.h:939
virtual numeric_index_type first_local_index() const libmesh_override
Definition: petsc_vector.h:956
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 659 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().

660 {
661  this->_restore_array();
662 
663  // Make sure the NumericVector passed in is really a PetscVector
664  PetscVector<T> * v_local = cast_ptr<PetscVector<T> *>(&v_local_in);
665 
666  libmesh_assert(v_local);
667  libmesh_assert_equal_to (v_local->size(), this->size());
668 
669  PetscErrorCode ierr = 0;
670  const PetscInt n = this->size();
671 
672  IS is;
673  VecScatter scatter;
674 
675  // Create idx, idx[i] = i;
676  std::vector<PetscInt> idx(n); Utility::iota (idx.begin(), idx.end(), 0);
677 
678  // Create the index set & scatter object
679  ierr = ISCreateLibMesh(this->comm().get(), n, &idx[0], PETSC_USE_POINTER, &is);
680  LIBMESH_CHKERR(ierr);
681 
682  ierr = VecScatterCreate(_vec, is,
683  v_local->_vec, is,
684  &scatter);
685  LIBMESH_CHKERR(ierr);
686 
687  // Perform the scatter
688  ierr = VecScatterBegin(scatter, _vec, v_local->_vec,
689  INSERT_VALUES, SCATTER_FORWARD);
690  LIBMESH_CHKERR(ierr);
691 
692  ierr = VecScatterEnd (scatter, _vec, v_local->_vec,
693  INSERT_VALUES, SCATTER_FORWARD);
694  LIBMESH_CHKERR(ierr);
695 
696  // Clean up
697  ierr = LibMeshISDestroy (&is);
698  LIBMESH_CHKERR(ierr);
699 
700  ierr = LibMeshVecScatterDestroy(&scatter);
701  LIBMESH_CHKERR(ierr);
702 
703  // Make sure ghost dofs are up to date
704  if (v_local->type() == GHOSTED)
705  v_local->close();
706 }
void iota(ForwardIter first, ForwardIter last, T value)
Definition: utility.h:57
libmesh_assert(j)
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
Definition: petsc_vector.h:919
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 711 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().

713 {
714  // FIXME: Workaround for a strange bug at large-scale.
715  // If we have ghosting, PETSc lets us just copy the solution, and
716  // doing so avoids a segfault?
717  if (v_local_in.type() == GHOSTED &&
718  this->type() == PARALLEL)
719  {
720  v_local_in = *this;
721  return;
722  }
723 
724  // Normal code path begins here
725 
726  this->_restore_array();
727 
728  // Make sure the NumericVector passed in is really a PetscVector
729  PetscVector<T> * v_local = cast_ptr<PetscVector<T> *>(&v_local_in);
730 
731  libmesh_assert(v_local);
732  libmesh_assert_equal_to (v_local->size(), this->size());
733  libmesh_assert_less_equal (send_list.size(), v_local->size());
734 
735  PetscErrorCode ierr=0;
736  const numeric_index_type n_sl =
737  cast_int<numeric_index_type>(send_list.size());
738 
739  IS is;
740  VecScatter scatter;
741 
742  std::vector<PetscInt> idx(n_sl + this->local_size());
743 
744  for (numeric_index_type i=0; i<n_sl; i++)
745  idx[i] = static_cast<PetscInt>(send_list[i]);
746  for (numeric_index_type i = 0; i != this->local_size(); ++i)
747  idx[n_sl+i] = i + this->first_local_index();
748 
749  // Create the index set & scatter object
750  if (idx.empty())
751  ierr = ISCreateLibMesh(this->comm().get(),
752  n_sl+this->local_size(), PETSC_NULL, PETSC_USE_POINTER, &is);
753  else
754  ierr = ISCreateLibMesh(this->comm().get(),
755  n_sl+this->local_size(), &idx[0], PETSC_USE_POINTER, &is);
756  LIBMESH_CHKERR(ierr);
757 
758  ierr = VecScatterCreate(_vec, is,
759  v_local->_vec, is,
760  &scatter);
761  LIBMESH_CHKERR(ierr);
762 
763 
764  // Perform the scatter
765  ierr = VecScatterBegin(scatter, _vec, v_local->_vec,
766  INSERT_VALUES, SCATTER_FORWARD);
767  LIBMESH_CHKERR(ierr);
768 
769  ierr = VecScatterEnd (scatter, _vec, v_local->_vec,
770  INSERT_VALUES, SCATTER_FORWARD);
771  LIBMESH_CHKERR(ierr);
772 
773  // Clean up
774  ierr = LibMeshISDestroy (&is);
775  LIBMESH_CHKERR(ierr);
776 
777  ierr = LibMeshVecScatterDestroy(&scatter);
778  LIBMESH_CHKERR(ierr);
779 
780  // Make sure ghost dofs are up to date
781  if (v_local->type() == GHOSTED)
782  v_local->close();
783 }
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
Definition: petsc_vector.h:919
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual numeric_index_type local_size() const libmesh_override
Definition: petsc_vector.h:939
ParallelType type() const
virtual numeric_index_type first_local_index() const libmesh_override
Definition: petsc_vector.h:956
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".

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

Example:

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

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

Implements libMesh::NumericVector< T >.

Definition at line 788 of file petsc_vector.C.

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

790 {
791  // Error code used to check the status of all PETSc function calls.
792  PetscErrorCode ierr = 0;
793 
794  // Create a sequential destination Vec with the right number of entries on each proc.
795  Vec dest;
796  ierr = VecCreateSeq(PETSC_COMM_SELF, indices.size(), &dest);
797  LIBMESH_CHKERR(ierr);
798 
799  // Create an IS using the libmesh routine. PETSc does not own the
800  // IS memory in this case, it is automatically cleaned up by the
801  // std::vector destructor.
802  IS is;
803  ierr = ISCreateLibMesh(this->comm().get(),
804  indices.size(),
805  numeric_petsc_cast(&indices[0]),
807  &is);
808  LIBMESH_CHKERR(ierr);
809 
810  // Create the VecScatter object. "NULL" means "use the identity IS".
811  VecScatter scatter;
812  ierr = VecScatterCreate(_vec,
813  /*src is=*/is,
814  /*dest vec=*/dest,
815  /*dest is=*/NULL,
816  &scatter);
817  LIBMESH_CHKERR(ierr);
818 
819  // Do the scatter
820  ierr = VecScatterBegin(scatter, _vec, dest, INSERT_VALUES, SCATTER_FORWARD);
821  LIBMESH_CHKERR(ierr);
822 
823  ierr = VecScatterEnd(scatter, _vec, dest, INSERT_VALUES, SCATTER_FORWARD);
824  LIBMESH_CHKERR(ierr);
825 
826  // Get access to the values stored in dest.
827  PetscScalar * values;
828  ierr = VecGetArray (dest, &values);
829  LIBMESH_CHKERR(ierr);
830 
831  // Store values into the provided v_local. Make sure there is enough
832  // space reserved and then clear out any existing entries before
833  // inserting.
834  v_local.reserve(indices.size());
835  v_local.clear();
836  v_local.insert(v_local.begin(), values, values+indices.size());
837 
838  // We are done using it, so restore the array.
839  ierr = VecRestoreArray (dest, &values);
840  LIBMESH_CHKERR(ierr);
841 
842  // Clean up PETSc data structures.
843  ierr = LibMeshVecScatterDestroy(&scatter);
844  LIBMESH_CHKERR(ierr);
845 
846  ierr = LibMeshISDestroy (&is);
847  LIBMESH_CHKERR(ierr);
848 
849  ierr = LibMeshVecDestroy(&dest);
850  LIBMESH_CHKERR(ierr);
851 }
unsigned int size() const
Definition: parallel.h:722
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 856 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.

859 {
860  this->_restore_array();
861 
862  libmesh_assert_less_equal (send_list.size(), this->size());
863  libmesh_assert_less_equal (last_local_idx+1, this->size());
864 
865  const numeric_index_type my_size = this->size();
866  const numeric_index_type my_local_size = (last_local_idx - first_local_idx + 1);
867  PetscErrorCode ierr=0;
868 
869  // Don't bother for serial cases
870  // if ((first_local_idx == 0) &&
871  // (my_local_size == my_size))
872  // But we do need to stay in sync for degenerate cases
873  if (this->n_processors() == 1)
874  return;
875 
876 
877  // Build a parallel vector, initialize it with the local
878  // parts of (*this)
879  PetscVector<T> parallel_vec(this->comm(), PARALLEL);
880 
881  parallel_vec.init (my_size, my_local_size, true, PARALLEL);
882 
883 
884  // Copy part of *this into the parallel_vec
885  {
886  IS is;
887  VecScatter scatter;
888 
889  // Create idx, idx[i] = i+first_local_idx;
890  std::vector<PetscInt> idx(my_local_size);
891  Utility::iota (idx.begin(), idx.end(), first_local_idx);
892 
893  // Create the index set & scatter object
894  ierr = ISCreateLibMesh(this->comm().get(), my_local_size,
895  my_local_size ? &idx[0] : libmesh_nullptr, PETSC_USE_POINTER, &is);
896  LIBMESH_CHKERR(ierr);
897 
898  ierr = VecScatterCreate(_vec, is,
899  parallel_vec._vec, is,
900  &scatter);
901  LIBMESH_CHKERR(ierr);
902 
903  ierr = VecScatterBegin(scatter, _vec, parallel_vec._vec,
904  INSERT_VALUES, SCATTER_FORWARD);
905  LIBMESH_CHKERR(ierr);
906 
907  ierr = VecScatterEnd (scatter, _vec, parallel_vec._vec,
908  INSERT_VALUES, SCATTER_FORWARD);
909  LIBMESH_CHKERR(ierr);
910 
911  // Clean up
912  ierr = LibMeshISDestroy (&is);
913  LIBMESH_CHKERR(ierr);
914 
915  ierr = LibMeshVecScatterDestroy(&scatter);
916  LIBMESH_CHKERR(ierr);
917  }
918 
919  // localize like normal
920  parallel_vec.close();
921  parallel_vec.localize (*this, send_list);
922  this->close();
923 }
processor_id_type n_processors() const
const class libmesh_nullptr_t libmesh_nullptr
void iota(ForwardIter first, ForwardIter last, T value)
Definition: utility.h:57
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
Definition: petsc_vector.h:919
virtual void close() libmesh_override
Definition: petsc_vector.h:807
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 963 of file petsc_vector.C.

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

965 {
966  this->_restore_array();
967 
968  PetscErrorCode ierr=0;
969  const PetscInt n = size();
970  const PetscInt nl = local_size();
971  PetscScalar * values;
972 
973 
974  // only one processor
975  if (n_processors() == 1)
976  {
977  v_local.resize(n);
978 
979  ierr = VecGetArray (_vec, &values);
980  LIBMESH_CHKERR(ierr);
981 
982  for (PetscInt i=0; i<n; i++)
983  v_local[i] = static_cast<Real>(values[i]);
984 
985  ierr = VecRestoreArray (_vec, &values);
986  LIBMESH_CHKERR(ierr);
987  }
988 
989  // otherwise multiple processors
990  else
991  {
992  if (pid == 0) // optimized version for localizing to 0
993  {
994  Vec vout;
995  VecScatter ctx;
996 
997  ierr = VecScatterCreateToZero(_vec, &ctx, &vout);
998  LIBMESH_CHKERR(ierr);
999 
1000  ierr = VecScatterBegin(ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
1001  LIBMESH_CHKERR(ierr);
1002  ierr = VecScatterEnd(ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
1003  LIBMESH_CHKERR(ierr);
1004 
1005  if (processor_id() == 0)
1006  {
1007  v_local.resize(n);
1008 
1009  ierr = VecGetArray (vout, &values);
1010  LIBMESH_CHKERR(ierr);
1011 
1012  for (PetscInt i=0; i<n; i++)
1013  v_local[i] = static_cast<Real>(values[i]);
1014 
1015  ierr = VecRestoreArray (vout, &values);
1016  LIBMESH_CHKERR(ierr);
1017  }
1018 
1019  ierr = LibMeshVecScatterDestroy(&ctx);
1020  LIBMESH_CHKERR(ierr);
1021  ierr = LibMeshVecDestroy(&vout);
1022  LIBMESH_CHKERR(ierr);
1023 
1024  }
1025  else
1026  {
1027  v_local.resize(n);
1028 
1029  numeric_index_type ioff = this->first_local_index();
1030  std::vector<Real> local_values (n, 0.);
1031 
1032  {
1033  ierr = VecGetArray (_vec, &values);
1034  LIBMESH_CHKERR(ierr);
1035 
1036  for (PetscInt i=0; i<nl; i++)
1037  local_values[i+ioff] = static_cast<Real>(values[i]);
1038 
1039  ierr = VecRestoreArray (_vec, &values);
1040  LIBMESH_CHKERR(ierr);
1041  }
1042 
1043 
1044  MPI_Reduce (&local_values[0], &v_local[0], n, MPI_REAL, MPI_SUM,
1045  pid, this->comm().get());
1046  }
1047  }
1048 }
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
Definition: petsc_vector.h:919
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual numeric_index_type local_size() const libmesh_override
Definition: petsc_vector.h:939
virtual numeric_index_type first_local_index() const libmesh_override
Definition: petsc_vector.h:956
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 1057 of file petsc_vector.C.

References ierr.

1059 {
1060  this->_restore_array();
1061 
1062  PetscErrorCode ierr=0;
1063  const PetscInt n = size();
1064  const PetscInt nl = local_size();
1065  PetscScalar * values;
1066 
1067 
1068  v_local.resize(n);
1069 
1070 
1071  for (PetscInt i=0; i<n; i++)
1072  v_local[i] = 0.;
1073 
1074  // only one processor
1075  if (n == nl)
1076  {
1077  ierr = VecGetArray (_vec, &values);
1078  LIBMESH_CHKERR(ierr);
1079 
1080  for (PetscInt i=0; i<n; i++)
1081  v_local[i] = static_cast<Complex>(values[i]);
1082 
1083  ierr = VecRestoreArray (_vec, &values);
1084  LIBMESH_CHKERR(ierr);
1085  }
1086 
1087  // otherwise multiple processors
1088  else
1089  {
1090  numeric_index_type ioff = this->first_local_index();
1091 
1092  /* in here the local values are stored, acting as send buffer for MPI
1093  * initialize to zero, since we collect using MPI_SUM
1094  */
1095  std::vector<Real> real_local_values(n, 0.);
1096  std::vector<Real> imag_local_values(n, 0.);
1097 
1098  {
1099  ierr = VecGetArray (_vec, &values);
1100  LIBMESH_CHKERR(ierr);
1101 
1102  // provide my local share to the real and imag buffers
1103  for (PetscInt i=0; i<nl; i++)
1104  {
1105  real_local_values[i+ioff] = static_cast<Complex>(values[i]).real();
1106  imag_local_values[i+ioff] = static_cast<Complex>(values[i]).imag();
1107  }
1108 
1109  ierr = VecRestoreArray (_vec, &values);
1110  LIBMESH_CHKERR(ierr);
1111  }
1112 
1113  /* have buffers of the real and imaginary part of v_local.
1114  * Once MPI_Reduce() collected all the real and imaginary
1115  * parts in these std::vector<Real>, the values can be
1116  * copied to v_local
1117  */
1118  std::vector<Real> real_v_local(n);
1119  std::vector<Real> imag_v_local(n);
1120 
1121  // collect entries from other proc's in real_v_local, imag_v_local
1122  MPI_Reduce (&real_local_values[0], &real_v_local[0], n,
1123  MPI_REAL, MPI_SUM,
1124  pid, this->comm().get());
1125 
1126  MPI_Reduce (&imag_local_values[0], &imag_v_local[0], n,
1127  MPI_REAL, MPI_SUM,
1128  pid, this->comm().get());
1129 
1130  // copy real_v_local and imag_v_local to v_local
1131  for (PetscInt i=0; i<n; i++)
1132  v_local[i] = Complex(real_v_local[i], imag_v_local[i]);
1133  }
1134 }
dof_id_type numeric_index_type
Definition: id_types.h:92
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
Definition: petsc_vector.h:919
std::complex< Real > Complex
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual numeric_index_type local_size() const libmesh_override
Definition: petsc_vector.h:939
virtual numeric_index_type first_local_index() const libmesh_override
Definition: petsc_vector.h:956
template<typename T >
numeric_index_type libMesh::PetscVector< T >::map_global_to_local_index ( const numeric_index_type  i) const
inline
Returns
The local index corresponding to global index i.

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

Definition at line 1004 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()().

1005 {
1006  libmesh_assert (this->initialized());
1007 
1008  numeric_index_type first=0;
1009  numeric_index_type last=0;
1010 
1011  if (_array_is_present) // Can we use cached values?
1012  {
1013  first = _first;
1014  last = _last;
1015  }
1016  else
1017  {
1018  PetscErrorCode ierr=0;
1019  PetscInt petsc_first=0, petsc_last=0;
1020  ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
1021  LIBMESH_CHKERR(ierr);
1022  first = static_cast<numeric_index_type>(petsc_first);
1023  last = static_cast<numeric_index_type>(petsc_last);
1024  }
1025 
1026 
1027  if ((i>=first) && (i<last))
1028  {
1029  return i-first;
1030  }
1031 
1032  GlobalToLocalMap::const_iterator it = _global_to_local_map.find(i);
1033 #ifndef NDEBUG
1034  const GlobalToLocalMap::const_iterator end = _global_to_local_map.end();
1035  if (it == end)
1036  {
1037  std::ostringstream error_message;
1038  error_message << "No index " << i << " in ghosted vector.\n"
1039  << "Vector contains [" << first << ',' << last << ")\n";
1040  GlobalToLocalMap::const_iterator b = _global_to_local_map.begin();
1041  if (b == end)
1042  {
1043  error_message << "And empty ghost array.\n";
1044  }
1045  else
1046  {
1047  error_message << "And ghost array {" << b->first;
1048  for (++b; b != end; ++b)
1049  error_message << ',' << b->first;
1050  error_message << "}\n";
1051  }
1052 
1053  libmesh_error_msg(error_message.str());
1054  }
1055  libmesh_assert (it != _global_to_local_map.end());
1056 #endif
1057  return it->second+last-first;
1058 }
numeric_index_type _last
Definition: petsc_vector.h:356
IterBase * end
virtual bool initialized() const
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
libmesh_assert(j)
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:424
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
numeric_index_type _first
Definition: petsc_vector.h:349
template<typename T >
Real libMesh::PetscVector< T >::max ( ) const
inlinevirtual
Returns
The maximum entry in the vector, or the maximum real part in the case of complex numbers.

Implements libMesh::NumericVector< T >.

Definition at line 1159 of file petsc_vector.h.

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

1160 {
1161  parallel_object_only();
1162 
1163  this->_restore_array();
1164 
1165  PetscErrorCode ierr=0;
1166  PetscInt index=0;
1167  PetscReal returnval=0.;
1168 
1169  ierr = VecMax (_vec, &index, &returnval);
1170  LIBMESH_CHKERR(ierr);
1171 
1172  // this return value is correct: VecMax returns a PetscReal
1173  return static_cast<Real>(returnval);
1174 }
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 entry in the vector, or the minimum real part in the case of complex numbers.

Implements libMesh::NumericVector< T >.

Definition at line 1138 of file petsc_vector.h.

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

1139 {
1140  parallel_object_only();
1141 
1142  this->_restore_array();
1143 
1144  PetscErrorCode ierr=0;
1145  PetscInt index=0;
1146  PetscReal returnval=0.;
1147 
1148  ierr = VecMin (_vec, &index, &returnval);
1149  LIBMESH_CHKERR(ierr);
1150 
1151  // this return value is correct: VecMin returns a PetscReal
1152  return static_cast<Real>(returnval);
1153 }
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::MeshTools::create_processor_bounding_box(), 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::MeshRefinement::make_coarsening_compatible(), 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::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_nodes(), 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::MeshRefinement::uniformly_coarsen(), 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:722
const Parallel::Communicator & _communicator
template<typename T >
T libMesh::PetscVector< T >::operator() ( const numeric_index_type  i) const
inlinevirtual
Returns
A copy of the ith entry of the vector.

Implements libMesh::NumericVector< T >.

Definition at line 1064 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().

1065 {
1066  this->_get_array(true);
1067 
1068  const numeric_index_type local_index = this->map_global_to_local_index(i);
1069 
1070 #ifndef NDEBUG
1071  if (this->type() == GHOSTED)
1072  {
1073  libmesh_assert_less (local_index, _local_size);
1074  }
1075 #endif
1076 
1077  return static_cast<T>(_read_only_values[local_index]);
1078 }
void _get_array(bool read_only) const
numeric_index_type _local_size
Definition: petsc_vector.h:361
const PetscScalar * _read_only_values
Definition: petsc_vector.h:378
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

Scales the vector by a, $ \vec{u} \leftarrow a\vec{u} $. Equivalent to u.scale(a)

Returns
A reference to *this.

Definition at line 384 of file numeric_vector.h.

384 { 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

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

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 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

Subtracts v from *this, $ \vec{u} \leftarrow \vec{u} - \vec{v} $. Equivalent to u.add(-1, v).

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 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::PetscVector< T >::operator/= ( NumericVector< T > &  )
virtual

Computes the pointwise division of this vector's entries by another's, $ u_i \leftarrow \frac{u_i}{v_i} \, \forall i$

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 426 of file petsc_vector.C.

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

427 {
428  PetscErrorCode ierr = 0;
429 
430  const PetscVector<T> * v_vec = cast_ptr<const PetscVector<T> *>(&v);
431 
432  ierr = VecPointwiseDivide(_vec, _vec, v_vec->_vec);
433  LIBMESH_CHKERR(ierr);
434 
435  return *this;
436 }
PetscErrorCode ierr
template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator/= ( const T  a)
inlineinherited

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

Returns
A reference to *this.

Definition at line 393 of file numeric_vector.h.

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

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

Sets all entries of the vector to the value s.

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

Definition at line 509 of file petsc_vector.C.

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

510 {
511  this->_restore_array();
512  libmesh_assert(this->closed());
513 
514  PetscErrorCode ierr = 0;
515  PetscScalar s = static_cast<PetscScalar>(s_in);
516 
517  if (this->size() != 0)
518  {
519  if (this->type() != GHOSTED)
520  {
521  ierr = VecSet(_vec, s);
522  LIBMESH_CHKERR(ierr);
523  }
524  else
525  {
526  Vec loc_vec;
527  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
528  LIBMESH_CHKERR(ierr);
529 
530  ierr = VecSet(loc_vec, s);
531  LIBMESH_CHKERR(ierr);
532 
533  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
534  LIBMESH_CHKERR(ierr);
535  }
536  }
537 
538  return *this;
539 }
virtual bool closed() const
libmesh_assert(j)
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
Definition: petsc_vector.h:919
PetscErrorCode ierr
ParallelType type() const
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const NumericVector< T > &  v)
virtual

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

Returns
A reference to *this as the base type.

Implements libMesh::NumericVector< T >.

Definition at line 545 of file petsc_vector.C.

546 {
547  // Make sure the NumericVector passed in is really a PetscVector
548  const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
549 
550  *this = *v;
551 
552  return *this;
553 }
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const std::vector< T > &  v)
virtual

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

Returns
A reference to *this as the base type.

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

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

Implements libMesh::NumericVector< T >.

Definition at line 623 of file petsc_vector.C.

References libMesh::GHOSTED.

624 {
625  this->_get_array(false);
626 
631  if (this->size() == v.size())
632  {
635  for (numeric_index_type i=0; i<last-first; i++)
636  _values[i] = static_cast<PetscScalar>(v[first + i]);
637  }
638 
643  else
644  {
645  for (numeric_index_type i=0; i<_local_size; i++)
646  _values[i] = static_cast<PetscScalar>(v[i]);
647  }
648 
649  // Make sure ghost dofs are up to date
650  if (this->type() == GHOSTED)
651  this->close();
652 
653  return *this;
654 }
void _get_array(bool read_only) const
numeric_index_type _local_size
Definition: petsc_vector.h:361
PetscScalar * _values
Definition: petsc_vector.h:388
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual numeric_index_type size() const libmesh_override
Definition: petsc_vector.h:919
virtual void close() libmesh_override
Definition: petsc_vector.h:807
ParallelType type() const
virtual numeric_index_type first_local_index() const libmesh_override
Definition: petsc_vector.h:956
virtual numeric_index_type last_local_index() const libmesh_override
Definition: petsc_vector.h:980
template<typename T >
PetscVector< T > & libMesh::PetscVector< T >::operator= ( const PetscVector< T > &  v)

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

Returns
A reference to *this as the derived type.

Definition at line 559 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().

560 {
561  this->_restore_array();
562  v._restore_array();
563 
564  libmesh_assert_equal_to (this->size(), v.size());
565  libmesh_assert_equal_to (this->local_size(), v.local_size());
566  libmesh_assert (v.closed());
567 
568  PetscErrorCode ierr = 0;
569 
570  if (((this->type()==PARALLEL) && (v.type()==GHOSTED)) ||
571  ((this->type()==GHOSTED) && (v.type()==PARALLEL)) ||
572  ((this->type()==GHOSTED) && (v.type()==SERIAL)) ||
573  ((this->type()==SERIAL) && (v.type()==GHOSTED)))
574  {
575  /* Allow assignment of a ghosted to a parallel vector since this
576  causes no difficulty. See discussion in libmesh-devel of
577  June 24, 2010. */
578  ierr = VecCopy (v._vec, this->_vec);
579  LIBMESH_CHKERR(ierr);
580  }
581  else
582  {
583  /* In all other cases, we assert that both vectors are of equal
584  type. */
585  libmesh_assert_equal_to (this->_type, v._type);
586 
587  if (v.size() != 0)
588  {
589  if (this->type() != GHOSTED)
590  {
591  ierr = VecCopy (v._vec, this->_vec);
592  LIBMESH_CHKERR(ierr);
593  }
594  else
595  {
596  Vec loc_vec;
597  Vec v_loc_vec;
598  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
599  LIBMESH_CHKERR(ierr);
600  ierr = VecGhostGetLocalForm (v._vec,&v_loc_vec);
601  LIBMESH_CHKERR(ierr);
602 
603  ierr = VecCopy (v_loc_vec, loc_vec);
604  LIBMESH_CHKERR(ierr);
605 
606  ierr = VecGhostRestoreLocalForm (v._vec,&v_loc_vec);
607  LIBMESH_CHKERR(ierr);
608  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
609  LIBMESH_CHKERR(ierr);
610  }
611  }
612  }
613 
614  close();
615 
616  return *this;
617 }
libmesh_assert(j)
void _restore_array() const
virtual numeric_index_type size() const libmesh_override
Definition: petsc_vector.h:919
virtual void close() libmesh_override
Definition: petsc_vector.h:807
PetscErrorCode ierr
virtual numeric_index_type local_size() const libmesh_override
Definition: petsc_vector.h:939
ParallelType type() const
template<typename T >
void libMesh::PetscVector< T >::pointwise_mult ( const NumericVector< T > &  vec1,
const NumericVector< T > &  vec2 
)
virtual

Computes $ u_i \leftarrow u_i v_i $ (summation not implied) i.e. the pointwise (component-wise) product of vec1 and vec2, and stores the result in *this.

Implements libMesh::NumericVector< T >.

Definition at line 1141 of file petsc_vector.C.

References libMesh::GHOSTED, and ierr.

1143 {
1144  this->_restore_array();
1145 
1146  PetscErrorCode ierr = 0;
1147 
1148  // Convert arguments to PetscVector*.
1149  const PetscVector<T> * vec1_petsc = cast_ptr<const PetscVector<T> *>(&vec1);
1150  const PetscVector<T> * vec2_petsc = cast_ptr<const PetscVector<T> *>(&vec2);
1151 
1152  // Call PETSc function.
1153 
1154  if (this->type() != GHOSTED)
1155  {
1156  ierr = VecPointwiseMult(this->vec(),
1157  const_cast<PetscVector<T> *>(vec1_petsc)->vec(),
1158  const_cast<PetscVector<T> *>(vec2_petsc)->vec());
1159  LIBMESH_CHKERR(ierr);
1160  }
1161  else
1162  {
1163  Vec loc_vec;
1164  Vec v1_loc_vec;
1165  Vec v2_loc_vec;
1166  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
1167  LIBMESH_CHKERR(ierr);
1168  ierr = VecGhostGetLocalForm (const_cast<PetscVector<T> *>(vec1_petsc)->vec(),&v1_loc_vec);
1169  LIBMESH_CHKERR(ierr);
1170  ierr = VecGhostGetLocalForm (const_cast<PetscVector<T> *>(vec2_petsc)->vec(),&v2_loc_vec);
1171  LIBMESH_CHKERR(ierr);
1172 
1173  ierr = VecPointwiseMult(loc_vec,v1_loc_vec,v2_loc_vec);
1174  LIBMESH_CHKERR(ierr);
1175 
1176  ierr = VecGhostRestoreLocalForm (const_cast<PetscVector<T> *>(vec1_petsc)->vec(),&v1_loc_vec);
1177  LIBMESH_CHKERR(ierr);
1178  ierr = VecGhostRestoreLocalForm (const_cast<PetscVector<T> *>(vec2_petsc)->vec(),&v2_loc_vec);
1179  LIBMESH_CHKERR(ierr);
1180  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
1181  LIBMESH_CHKERR(ierr);
1182  }
1183 }
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 918 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/=().

919 {
920  libmesh_assert (this->initialized());
921  os << "Size\tglobal = " << this->size()
922  << "\t\tlocal = " << this->local_size() << std::endl;
923 
924  os << "#\tValue" << std::endl;
925  for (numeric_index_type i=this->first_local_index(); i<this->last_local_index(); i++)
926  os << i << "\t" << (*this)(i) << std::endl;
927 }
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 900 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().

901 {
902  libmesh_assert (this->initialized());
903  os << "Size\tglobal = " << this->size()
904  << "\t\tlocal = " << this->local_size() << std::endl;
905 
906  // std::complex<>::operator<<() is defined, but use this form
907  os << "#\tReal part\t\tImaginary part" << std::endl;
908  for (numeric_index_type i=this->first_local_index(); i<this->last_local_index(); i++)
909  os << i << "\t"
910  << (*this)(i).real() << "\t\t"
911  << (*this)(i).imag() << std::endl;
912 }
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 955 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/=().

956 {
957  libmesh_assert (this->initialized());
958 
959  std::vector<T> v(this->size());
960  this->localize(v);
961 
962  // Right now we only want one copy of the output
963  if (this->processor_id())
964  return;
965 
966  os << "Size\tglobal = " << this->size() << std::endl;
967  os << "#\tValue" << std::endl;
968  for (numeric_index_type i=0; i!=v.size(); i++)
969  os << i << "\t" << v[i] << std::endl;
970 }
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 933 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().

934 {
935  libmesh_assert (this->initialized());
936 
937  std::vector<Complex> v(this->size());
938  this->localize(v);
939 
940  // Right now we only want one copy of the output
941  if (this->processor_id())
942  return;
943 
944  os << "Size\tglobal = " << this->size() << std::endl;
945  os << "#\tReal part\t\tImaginary part" << std::endl;
946  for (numeric_index_type i=0; i!=v.size(); i++)
947  os << i << "\t"
948  << v[i].real() << "\t\t"
949  << v[i].imag() << std::endl;
950 }
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  out_stream << ReferenceCounter::get_info();
92 }
static std::string get_info()
template<typename T >
void libMesh::PetscVector< T >::print_matlab ( const std::string &  = "") const
virtual

Print the contents of the vector in Matlab's sparse matrix format. Optionally prints the vector to the file named name. If name is not specified it is dumped to the screen.

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

Otherwise the matrix will be dumped to the screen.

Destroy the viewer.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1188 of file petsc_vector.C.

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

1189 {
1190  this->_restore_array();
1191  libmesh_assert (this->closed());
1192 
1193  PetscErrorCode ierr=0;
1194  PetscViewer petsc_viewer;
1195 
1196 
1197  ierr = PetscViewerCreate (this->comm().get(),
1198  &petsc_viewer);
1199  LIBMESH_CHKERR(ierr);
1200 
1205  if (name != "")
1206  {
1207  ierr = PetscViewerASCIIOpen( this->comm().get(),
1208  name.c_str(),
1209  &petsc_viewer);
1210  LIBMESH_CHKERR(ierr);
1211 
1212 #if PETSC_VERSION_LESS_THAN(3,7,0)
1213  ierr = PetscViewerSetFormat (petsc_viewer,
1214  PETSC_VIEWER_ASCII_MATLAB);
1215 #else
1216  ierr = PetscViewerPushFormat (petsc_viewer,
1217  PETSC_VIEWER_ASCII_MATLAB);
1218 #endif
1219 
1220  LIBMESH_CHKERR(ierr);
1221 
1222  ierr = VecView (_vec, petsc_viewer);
1223  LIBMESH_CHKERR(ierr);
1224  }
1225 
1229  else
1230  {
1231 
1232 #if PETSC_VERSION_LESS_THAN(3,7,0)
1233  ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
1234  PETSC_VIEWER_ASCII_MATLAB);
1235 #else
1236  ierr = PetscViewerPushFormat (PETSC_VIEWER_STDOUT_WORLD,
1237  PETSC_VIEWER_ASCII_MATLAB);
1238 #endif
1239 
1240  LIBMESH_CHKERR(ierr);
1241 
1242  ierr = VecView (_vec, PETSC_VIEWER_STDOUT_WORLD);
1243  LIBMESH_CHKERR(ierr);
1244  }
1245 
1246 
1250  ierr = LibMeshPetscViewerDestroy (&petsc_viewer);
1251  LIBMESH_CHKERR(ierr);
1252 }
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::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::CheckpointIO::read_header(), 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::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::CheckpointIO::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:720
template<typename T >
void libMesh::PetscVector< T >::reciprocal ( )
virtual

Computes the pointwise reciprocal, $ u_i \leftarrow \frac{1}{u_i} \, \forall 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.

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

Definition at line 1128 of file petsc_vector.h.

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

1129 {
1130  // \note \p _values_manually_retrieved needs to be set to \p false
1131  // \e before calling \p _restore_array()!
1133  _restore_array();
1134 }
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 399 of file petsc_vector.C.

References libMesh::GHOSTED, and ierr.

400 {
401  this->_restore_array();
402 
403  PetscErrorCode ierr = 0;
404  PetscScalar factor = static_cast<PetscScalar>(factor_in);
405 
406  if (this->type() != GHOSTED)
407  {
408  ierr = VecScale(_vec, factor);
409  LIBMESH_CHKERR(ierr);
410  }
411  else
412  {
413  Vec loc_vec;
414  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
415  LIBMESH_CHKERR(ierr);
416 
417  ierr = VecScale(loc_vec, factor);
418  LIBMESH_CHKERR(ierr);
419 
420  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
421  LIBMESH_CHKERR(ierr);
422  }
423 }
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

Sets 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
Definition: petsc_vector.h:919
PetscErrorCode ierr
template<typename T >
numeric_index_type libMesh::PetscVector< T >::size ( ) const
inlinevirtual
Returns
The size of the vector.

Implements libMesh::NumericVector< T >.

Definition at line 919 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=().

920 {
921  libmesh_assert (this->initialized());
922 
923  PetscErrorCode ierr=0;
924  PetscInt petsc_size=0;
925 
926  if (!this->initialized())
927  return 0;
928 
929  ierr = VecGetSize(_vec, &petsc_size);
930  LIBMESH_CHKERR(ierr);
931 
932  return static_cast<numeric_index_type>(petsc_size);
933 }
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 $ \ell_1 $-norm of the vector, i.e. the sum of the absolute values for the specified entries in the vector.
Note
The indices must necessarily live on this processor.

Definition at line 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 $ \ell_2 $-norm of the vector, i.e. the square root of the sum of the squares of the elements for the specified entries in the vector.
Note
The indices must necessarily live on this processor.

Definition at line 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 $ \ell_{\infty} $-norm of a vector.
Note
The indices must necessarily 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 all values in the 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 contents of this with v. There should be enough indirection in subclasses to make this an O(1) header-swap operation.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1180 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().

1181 {
1182  parallel_object_only();
1183 
1184  NumericVector<T>::swap(other);
1185 
1186  PetscVector<T> & v = cast_ref<PetscVector<T> &>(other);
1187 
1188  std::swap(_vec, v._vec);
1189  std::swap(_destroy_vec_on_exit, v._destroy_vec_on_exit);
1190  std::swap(_global_to_local_map, v._global_to_local_map);
1191 
1192 #ifdef LIBMESH_HAVE_CXX11_THREAD
1193  // Only truly atomic for v... but swap() doesn't really need to be thread safe!
1194  _array_is_present = v._array_is_present.exchange(_array_is_present);
1195 #else
1196  std::swap(_array_is_present, v._array_is_present);
1197 #endif
1198 
1199  std::swap(_local_form, v._local_form);
1200  std::swap(_values, v._values);
1201 }
PetscScalar * _values
Definition: petsc_vector.h:388
std::atomic< bool > _array_is_present
Definition: petsc_vector.h:339
GlobalToLocalMap _global_to_local_map
Definition: petsc_vector.h:424
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 145 of file numeric_vector.h.

145 { 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 859 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().

860 {
861  parallel_object_only();
862 
863  libmesh_assert(this->closed());
864 
865  this->_restore_array();
866 
867  PetscErrorCode ierr=0;
868 
869  PetscScalar z=0.;
870 
871  if (this->type() != GHOSTED)
872  {
873  ierr = VecSet (_vec, z);
874  LIBMESH_CHKERR(ierr);
875  }
876  else
877  {
878  /* Vectors that include ghost values require a special
879  handling. */
880  Vec loc_vec;
881  ierr = VecGhostGetLocalForm (_vec,&loc_vec);
882  LIBMESH_CHKERR(ierr);
883 
884  ierr = VecSet (loc_vec, z);
885  LIBMESH_CHKERR(ierr);
886 
887  ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
888  LIBMESH_CHKERR(ierr);
889  }
890 }
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
Returns
A smart pointer to a copy of this vector with the same type, size, and partitioning, but with all zero entries.
Note
This must be overridden in the derived classes.

Implements libMesh::NumericVector< T >.

Definition at line 896 of file petsc_vector.h.

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

897 {
898  NumericVector<T> * cloned_vector = new PetscVector<T>(this->comm(), this->type());
899  cloned_vector->init(*this);
900  return UniquePtr<NumericVector<T> >(cloned_vector);
901 }
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 339 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 341 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 430 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 143 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 349 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 424 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 356 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 368 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 361 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 137 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 132 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 396 of file petsc_vector.h.

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

Definition at line 398 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 378 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 388 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 441 of file petsc_vector.h.

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


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