$extrastylesheet
libMesh::PetscVector< T > Class Template Reference

#include <petsc_vector.h>

Inheritance diagram for libMesh::PetscVector< T >:

List of all members.

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 ()
void close ()
void clear ()
void zero ()
virtual UniquePtr
< NumericVector< T > > 
zero_clone () const
UniquePtr< NumericVector< T > > clone () const
void init (const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC)
void init (const numeric_index_type N, const bool fast=false, const ParallelType type=AUTOMATIC)
virtual void init (const numeric_index_type, const numeric_index_type, const std::vector< numeric_index_type > &, const bool=false, const ParallelType=AUTOMATIC)
virtual void init (const NumericVector< T > &other, const bool fast=false)
NumericVector< T > & operator= (const T s)
NumericVector< T > & operator= (const NumericVector< T > &V)
PetscVector< T > & operator= (const PetscVector< T > &V)
NumericVector< T > & operator= (const std::vector< T > &v)
Real min () const
Real max () const
sum () const
Real l1_norm () const
Real l2_norm () const
Real linfty_norm () const
numeric_index_type size () const
numeric_index_type local_size () const
numeric_index_type first_local_index () const
numeric_index_type last_local_index () const
numeric_index_type map_global_to_local_index (const numeric_index_type i) const
operator() (const numeric_index_type i) const
virtual void get (const std::vector< numeric_index_type > &index, T *values) const
NumericVector< T > & operator+= (const NumericVector< T > &V)
NumericVector< T > & operator-= (const NumericVector< T > &V)
virtual void reciprocal ()
virtual void conjugate ()
void set (const numeric_index_type i, const T value)
void add (const numeric_index_type i, const T value)
void add (const T s)
void add (const NumericVector< T > &V)
void add (const T a, const NumericVector< T > &v)
void add_vector (const T *v, const std::vector< numeric_index_type > &dof_indices)
void add_vector (const NumericVector< T > &V, const SparseMatrix< T > &A)
void add_vector_transpose (const NumericVector< T > &V, const SparseMatrix< T > &A_trans)
void add_vector_conjugate_transpose (const NumericVector< T > &V, const SparseMatrix< T > &A_trans)
virtual void insert (const T *v, const std::vector< numeric_index_type > &dof_indices)
void scale (const T factor)
virtual NumericVector< T > & operator/= (NumericVector< T > &v)
virtual void abs ()
virtual T dot (const NumericVector< T > &) const
virtual T indefinite_dot (const NumericVector< T > &) const
void localize (std::vector< T > &v_local) const
void localize (NumericVector< T > &v_local) const
void localize (NumericVector< T > &v_local, const std::vector< numeric_index_type > &send_list) const
void localize (const numeric_index_type first_local_idx, const numeric_index_type last_local_idx, const std::vector< numeric_index_type > &send_list)
void localize_to_one (std::vector< T > &v_local, const processor_id_type proc_id=0) const
virtual void pointwise_mult (const NumericVector< T > &vec1, const NumericVector< T > &vec2)
virtual void print_matlab (const std::string &name="") const
virtual void create_subvector (NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows) const
virtual void swap (NumericVector< T > &v)
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_type
GlobalToLocalMap

Private Member Functions

void _get_array (void) const
void _restore_array (void) const

Private Attributes

Vec _vec
bool _array_is_present
numeric_index_type _first
numeric_index_type _last
numeric_index_type _local_size
Vec _local_form
PetscScalar * _values
GlobalToLocalMap _global_to_local_map
bool _destroy_vec_on_exit

Friends

std::ostream & operator<< (std::ostream &os, const NumericVector< T > &v)

Detailed Description

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

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

Author:
Benjamin S. Kirk, 2002

Definition at line 63 of file petsc_vector.h.


Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts [protected, inherited]

Data structure to log the information. The log is identified by the class name.

Definition at line 113 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 579 of file petsc_vector.h.


Constructor & Destructor Documentation

template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator comm_in,
const ParallelType  type = AUTOMATIC 
) [inline, explicit]

Dummy-Constructor. Dimension=0

Definition at line 601 of file petsc_vector.h.

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

  : NumericVector<T>(comm_in, ptype),
    _array_is_present(false),
    _first(0),
    _last(0),
    _local_form(NULL),
    _values(NULL),
    _global_to_local_map(),
    _destroy_vec_on_exit(true)
{
  this->_type = ptype;
}
template<typename T >
libMesh::PetscVector< T >::PetscVector ( const Parallel::Communicator comm_in,
const numeric_index_type  n,
const ParallelType  type = AUTOMATIC 
) [inline, explicit]

Constructor. Set dimension to n and initialize all elements with zero.

Definition at line 618 of file petsc_vector.h.

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

  : NumericVector<T>(comm_in, ptype),
    _array_is_present(false),
    _local_form(NULL),
    _values(NULL),
    _global_to_local_map(),
    _destroy_vec_on_exit(true)
{
  this->init(n, n, false, ptype);
}
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 635 of file petsc_vector.h.

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

  : NumericVector<T>(comm_in, ptype),
    _array_is_present(false),
    _local_form(NULL),
    _values(NULL),
    _global_to_local_map(),
    _destroy_vec_on_exit(true)
{
  this->init(n, n_local, false, ptype);
}
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 653 of file petsc_vector.h.

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

  : NumericVector<T>(comm_in, ptype),
    _array_is_present(false),
    _local_form(NULL),
    _values(NULL),
    _global_to_local_map(),
    _destroy_vec_on_exit(true)
{
  this->init(n, n_local, ghost, false, ptype);
}
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 758 of file petsc_vector.h.

{
  this->clear ();
}

Member Function Documentation

template<typename T >
void libMesh::PetscVector< T >::_get_array ( void  ) const [inline, private]

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

Definition at line 1311 of file petsc_vector.h.

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

{
  libmesh_assert (this->initialized());
  if(!_array_is_present)
    {
      PetscErrorCode ierr=0;
      if(this->type() != GHOSTED)
        {
          ierr = VecGetArray(_vec, &_values);
          LIBMESH_CHKERRABORT(ierr);
        }
      else
        {
          ierr = VecGhostGetLocalForm (_vec,&_local_form);
          LIBMESH_CHKERRABORT(ierr);
          ierr = VecGetArray(_local_form, &_values);
          LIBMESH_CHKERRABORT(ierr);
#ifndef NDEBUG
          PetscInt my_local_size = 0;
          ierr = VecGetLocalSize(_local_form, &my_local_size);
          LIBMESH_CHKERRABORT(ierr);
          _local_size = static_cast<numeric_index_type>(my_local_size);
#endif
        }

      { // cache ownership range
        PetscInt petsc_first=0, petsc_last=0;
        ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
        LIBMESH_CHKERRABORT(ierr);
        _first = static_cast<numeric_index_type>(petsc_first);
        _last = static_cast<numeric_index_type>(petsc_last);
      }

      _array_is_present = true;
    }
}
template<typename T >
void libMesh::PetscVector< T >::_restore_array ( void  ) const [inline, private]

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

Definition at line 1352 of file petsc_vector.h.

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

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

{
  libmesh_assert (this->initialized());
  if(_array_is_present)
    {
      PetscErrorCode ierr=0;
      if(this->type() != GHOSTED)
        {
          ierr = VecRestoreArray (_vec, &_values);
          LIBMESH_CHKERRABORT(ierr);
          _values = NULL;
        }
      else
        {
          ierr = VecRestoreArray (_local_form, &_values);
          LIBMESH_CHKERRABORT(ierr);
          _values = NULL;
          ierr = VecGhostRestoreLocalForm (_vec,&_local_form);
          LIBMESH_CHKERRABORT(ierr);
          _local_form = NULL;
#ifndef NDEBUG
          _local_size = 0;
#endif
        }
      _array_is_present = false;
    }
}
template<typename T >
void libMesh::PetscVector< T >::abs ( ) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 502 of file petsc_vector.C.

References libMesh::GHOSTED.

{
  this->_restore_array();

  PetscErrorCode ierr = 0;

  if(this->type() != GHOSTED)
    {
      ierr = VecAbs(_vec);
      LIBMESH_CHKERRABORT(ierr);
    }
  else
    {
      Vec loc_vec;
      ierr = VecGhostGetLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);

      ierr = VecAbs(loc_vec);
      LIBMESH_CHKERRABORT(ierr);

      ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
    }
}
template<typename T >
void libMesh::PetscVector< T >::add ( const numeric_index_type  i,
const T  value 
) [virtual]

v(i) += value

Implements libMesh::NumericVector< T >.

Definition at line 182 of file petsc_vector.C.

References libMesh::ierr.

{
  this->_restore_array();
  libmesh_assert_less (i, size());

  PetscErrorCode ierr=0;
  PetscInt i_val = static_cast<PetscInt>(i);
  PetscScalar petsc_value = static_cast<PetscScalar>(value);

  ierr = VecSetValues (_vec, 1, &i_val, &petsc_value, ADD_VALUES);
  LIBMESH_CHKERRABORT(ierr);

  this->_is_closed = false;
}
template<typename T >
void libMesh::PetscVector< T >::add ( const T  s) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 302 of file petsc_vector.C.

References libMesh::GHOSTED.

{
  this->_restore_array();

  PetscErrorCode ierr=0;
  PetscScalar* values;
  const PetscScalar v = static_cast<PetscScalar>(v_in);

  if(this->type() != GHOSTED)
    {
      const PetscInt n   = static_cast<PetscInt>(this->local_size());
      const PetscInt fli = static_cast<PetscInt>(this->first_local_index());

      for (PetscInt i=0; i<n; i++)
        {
          ierr = VecGetArray (_vec, &values);
          LIBMESH_CHKERRABORT(ierr);

          PetscInt ig = fli + i;

          PetscScalar value = (values[i] + v);

          ierr = VecRestoreArray (_vec, &values);
          LIBMESH_CHKERRABORT(ierr);

          ierr = VecSetValues (_vec, 1, &ig, &value, INSERT_VALUES);
          LIBMESH_CHKERRABORT(ierr);
        }
    }
  else
    {
      /* Vectors that include ghost values require a special
         handling.  */
      Vec loc_vec;
      ierr = VecGhostGetLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);

      PetscInt n=0;
      ierr = VecGetSize(loc_vec, &n);
      LIBMESH_CHKERRABORT(ierr);

      for (PetscInt i=0; i<n; i++)
        {
          ierr = VecGetArray (loc_vec, &values);
          LIBMESH_CHKERRABORT(ierr);

          PetscScalar value = (values[i] + v);

          ierr = VecRestoreArray (loc_vec, &values);
          LIBMESH_CHKERRABORT(ierr);

          ierr = VecSetValues (loc_vec, 1, &i, &value, INSERT_VALUES);
          LIBMESH_CHKERRABORT(ierr);
        }

      ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
    }

  this->_is_closed = false;
}
template<typename T >
void libMesh::PetscVector< T >::add ( const NumericVector< T > &  V) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 367 of file petsc_vector.C.

{
  this->add (1., v);
}
template<typename T >
void libMesh::PetscVector< T >::add ( const T  a,
const NumericVector< T > &  v 
) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 375 of file petsc_vector.C.

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

{
  this->_restore_array();

  PetscErrorCode ierr = 0;
  PetscScalar a = static_cast<PetscScalar>(a_in);

  // Make sure the NumericVector passed in is really a PetscVector
  const PetscVector<T>* v = cast_ptr<const PetscVector<T>*>(&v_in);
  v->_restore_array();

  libmesh_assert_equal_to (this->size(), v->size());

  if(this->type() != GHOSTED)
    {
#if PETSC_VERSION_LESS_THAN(2,3,0)
      // 2.2.x & earlier style
      ierr = VecAXPY(&a, v->_vec, _vec);
      LIBMESH_CHKERRABORT(ierr);
#else
      // 2.3.x & later style
      ierr = VecAXPY(_vec, a, v->_vec);
      LIBMESH_CHKERRABORT(ierr);
#endif
    }
  else
    {
      Vec loc_vec;
      Vec v_loc_vec;
      ierr = VecGhostGetLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
      ierr = VecGhostGetLocalForm (v->_vec,&v_loc_vec);
      LIBMESH_CHKERRABORT(ierr);

#if PETSC_VERSION_LESS_THAN(2,3,0)
      // 2.2.x & earlier style
      ierr = VecAXPY(&a, v_loc_vec, loc_vec);
      LIBMESH_CHKERRABORT(ierr);
#else
      // 2.3.x & later style
      ierr = VecAXPY(loc_vec, a, v_loc_vec);
      LIBMESH_CHKERRABORT(ierr);
#endif

      ierr = VecGhostRestoreLocalForm (v->_vec,&v_loc_vec);
      LIBMESH_CHKERRABORT(ierr);
      ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
    }
}
template<typename T >
void libMesh::PetscVector< T >::add_vector ( const T *  v,
const std::vector< numeric_index_type > &  dof_indices 
) [virtual]

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

Reimplemented from libMesh::NumericVector< T >.

Definition at line 200 of file petsc_vector.C.

References libMesh::ierr.

{
  // If we aren't adding anything just return
  if(dof_indices.empty())
    return;

  this->_restore_array();

  PetscErrorCode ierr=0;
  const PetscInt * i_val = reinterpret_cast<const PetscInt*>(&dof_indices[0]);
  const PetscScalar * petsc_value = static_cast<const PetscScalar*>(v);

  ierr = VecSetValues (_vec, cast_int<PetscInt>(dof_indices.size()),
                       i_val, petsc_value, ADD_VALUES);
  LIBMESH_CHKERRABORT(ierr);

  this->_is_closed = false;
}
template<typename T >
void libMesh::PetscVector< T >::add_vector ( const NumericVector< T > &  V,
const SparseMatrix< T > &  A 
) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 223 of file petsc_vector.C.

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

{
  this->_restore_array();
  // Make sure the data passed in are really of Petsc types
  const PetscVector<T>* V = cast_ptr<const PetscVector<T>*>(&V_in);
  const PetscMatrix<T>* A = cast_ptr<const PetscMatrix<T>*>(&A_in);

  PetscErrorCode ierr=0;

  A->close();

  // The const_cast<> is not elegant, but it is required since PETSc
  // is not const-correct.
  ierr = MatMultAdd(const_cast<PetscMatrix<T>*>(A)->mat(), V->_vec, _vec, _vec);
  LIBMESH_CHKERRABORT(ierr);
}
template<typename T>
void libMesh::NumericVector< T >::add_vector ( const std::vector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
) [inline, inherited]

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

Definition at line 806 of file numeric_vector.h.

References libMesh::libmesh_assert().

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

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

Definition at line 395 of file numeric_vector.C.

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

{
  int n = dof_indices.size();
  libmesh_assert_equal_to(v.size(), static_cast<unsigned>(n));
  for (int i=0; i<n; i++)
    this->add (dof_indices[i], v(i));
}
template<typename T>
void libMesh::NumericVector< T >::add_vector ( const DenseVector< T > &  V,
const std::vector< numeric_index_type > &  dof_indices 
) [inline, inherited]

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

Definition at line 818 of file numeric_vector.h.

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

{
  libmesh_assert(v.size() == dof_indices.size());
  if (!v.empty())
    this->add_vector(&v(0), dof_indices);
}
template<typename T>
void libMesh::NumericVector< T >::add_vector ( const NumericVector< T > &  v,
const ShellMatrix< T > &  a 
) [inherited]

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

Definition at line 407 of file numeric_vector.C.

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

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

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

Definition at line 265 of file petsc_vector.C.

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

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

Implements libMesh::NumericVector< T >.

Definition at line 244 of file petsc_vector.C.

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

{
  this->_restore_array();
  // Make sure the data passed in are really of Petsc types
  const PetscVector<T>* V = cast_ptr<const PetscVector<T>*>(&V_in);
  const PetscMatrix<T>* A = cast_ptr<const PetscMatrix<T>*>(&A_in);

  PetscErrorCode ierr=0;

  A->close();

  // The const_cast<> is not elegant, but it is required since PETSc
  // is not const-correct.
  ierr = MatMultTransposeAdd(const_cast<PetscMatrix<T>*>(A)->mat(), V->_vec, _vec, _vec);
  LIBMESH_CHKERRABORT(ierr);
}
template<typename T >
UniquePtr< NumericVector< T > > libMesh::NumericVector< T >::build ( const Parallel::Communicator comm,
const SolverPackage  solver_package = libMesh::default_solver_package() 
) [static, inherited]

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::NumericVector< T >::build(), and libMesh::ExactErrorEstimator::estimate_error().

{
  // Build the appropriate vector
  switch (solver_package)
    {

#ifdef LIBMESH_HAVE_LASPACK
    case LASPACK_SOLVERS:
      return UniquePtr<NumericVector<T> >(new LaspackVector<T>(comm, AUTOMATIC));
#endif

#ifdef LIBMESH_HAVE_PETSC
    case PETSC_SOLVERS:
      return UniquePtr<NumericVector<T> >(new PetscVector<T>(comm, AUTOMATIC));
#endif

#ifdef LIBMESH_HAVE_TRILINOS
    case TRILINOS_SOLVERS:
      return UniquePtr<NumericVector<T> >(new EpetraVector<T>(comm, AUTOMATIC));
#endif

#ifdef LIBMESH_HAVE_EIGEN
    case EIGEN_SOLVERS:
      return UniquePtr<NumericVector<T> >(new EigenSparseVector<T>(comm, AUTOMATIC));
#endif

    default:
      return UniquePtr<NumericVector<T> >(new DistributedVector<T>(comm, AUTOMATIC));
    }

  libmesh_error_msg("We'll never get here!");
  return UniquePtr<NumericVector<T> >();
}
template<typename T >
UniquePtr< NumericVector< T > > libMesh::NumericVector< T >::build ( const SolverPackage  solver_package = libMesh::default_solver_package()) [static, inherited]

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

Definition at line 84 of file numeric_vector.C.

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

{
  libmesh_deprecated();
  return NumericVector<T>::build(CommWorld, solver_package);
}
template<typename T >
void libMesh::PetscVector< T >::clear ( ) [inline, virtual]
Returns:
the PetscVector<T> to a pristine state.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 975 of file petsc_vector.h.

References libMesh::libMeshPrivateData::_is_initialized, and libMesh::initialized().

{
  if (this->initialized())
    this->_restore_array();

  if ((this->initialized()) && (this->_destroy_vec_on_exit))
    {
      PetscErrorCode ierr=0;

      ierr = LibMeshVecDestroy(&_vec);
      LIBMESH_CHKERRABORT(ierr);
    }

  this->_is_closed = this->_is_initialized = false;

  _global_to_local_map.clear();
}
template<typename T >
UniquePtr< NumericVector< T > > libMesh::PetscVector< T >::clone ( ) const [inline, virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 1055 of file petsc_vector.h.

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

{
  NumericVector<T>* cloned_vector = new PetscVector<T>(this->comm(), this->type());
  cloned_vector->init(*this, true);
  *cloned_vector = *this;
  return UniquePtr<NumericVector<T> >(cloned_vector);
}
template<typename T >
void libMesh::PetscVector< T >::close ( ) [inline, virtual]

Call the assemble functions

Implements libMesh::NumericVector< T >.

Definition at line 949 of file petsc_vector.h.

References libMesh::GHOSTED.

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

{
  this->_restore_array();

  PetscErrorCode ierr=0;

  ierr = VecAssemblyBegin(_vec);
  LIBMESH_CHKERRABORT(ierr);
  ierr = VecAssemblyEnd(_vec);
  LIBMESH_CHKERRABORT(ierr);

  if(this->type() == GHOSTED)
    {
      ierr = VecGhostUpdateBegin(_vec,INSERT_VALUES,SCATTER_FORWARD);
      LIBMESH_CHKERRABORT(ierr);
      ierr = VecGhostUpdateEnd(_vec,INSERT_VALUES,SCATTER_FORWARD);
      LIBMESH_CHKERRABORT(ierr);
    }

  this->_is_closed = true;
}
template<typename T>
virtual bool libMesh::NumericVector< T >::closed ( ) const [inline, virtual, inherited]
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const [inline, inherited]
Returns:
a reference to the Parallel::Communicator object used by this mesh.

Definition at line 86 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_residual(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::MetisPartitioner::_do_partition(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::UnstructuredMesh::all_second_order(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::MeshTools::bounding_box(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::MeshRefinement::coarsen_elements(), 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::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshSetSystem_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), 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::CondensedEigenSystem::get_eigenpair(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::LocationMap< T >::init(), libMesh::TimeSolver::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::ParallelMesh::libmesh_assert_valid_parallel_flags(), libMesh::MeshTools::libmesh_assert_valid_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), libMesh::ParallelMesh::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::ParallelMesh::parallel_max_elem_id(), libMesh::ParallelMesh::parallel_max_node_id(), libMesh::ParallelMesh::parallel_n_elem(), libMesh::ParallelMesh::parallel_n_nodes(), libMesh::Partitioner::partition(), 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::System::project_vector(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::MeshRefinement::refine_elements(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::NameBasedIO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::LegacyXdrIO::write_mesh(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), and libMesh::DivaIO::write_stream().

  { return _communicator; }
template<typename T>
int libMesh::NumericVector< T >::compare ( const NumericVector< T > &  other_vector,
const Real  threshold = TOLERANCE 
) const [virtual, inherited]
Returns:
-1 when this is equivalent to other_vector, up to the given threshold. When differences occur, the return value contains the first index i where the difference (a[i]-b[i]) exceeded the threshold. When no threshold is given, the libMesh TOLERANCE is used.

Definition at line 116 of file numeric_vector.C.

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

{
  libmesh_assert (this->initialized());
  libmesh_assert (other_vector.initialized());
  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());

  int first_different_i = std::numeric_limits<int>::max();
  numeric_index_type i = first_local_index();

  do
    {
      if ( std::abs( (*this)(i) - other_vector(i) ) > threshold )
        first_different_i = i;
      else
        i++;
    }
  while (first_different_i==std::numeric_limits<int>::max()
         && i<last_local_index());

  // Find the correct first differing index in parallel
  this->comm().min(first_different_i);

  if (first_different_i == std::numeric_limits<int>::max())
    return -1;

  return first_different_i;
}
template<typename T >
void libMesh::PetscVector< T >::conjugate ( ) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 170 of file petsc_vector.C.

References libMesh::ierr.

{
  PetscErrorCode ierr = 0;

  // We just call the PETSc VecConjugate
  ierr = VecConjugate(_vec);
  LIBMESH_CHKERRABORT(ierr);
}
template<typename T >
void libMesh::PetscVector< T >::create_subvector ( NumericVector< T > &  subvector,
const std::vector< numeric_index_type > &  rows 
) const [virtual]

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

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1327 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(), libMesh::NumericVector< T >::initialized(), libMesh::Utility::iota(), libMesh::numeric_petsc_cast(), and PETSC_USE_POINTER.

{
  this->_restore_array();

  // PETSc data structures
  IS parent_is, subvector_is;
  VecScatter scatter;
  PetscErrorCode ierr = 0;

  // Make sure the passed in subvector is really a PetscVector
  PetscVector<T>* petsc_subvector = cast_ptr<PetscVector<T>*>(&subvector);

  // If the petsc_subvector is already initialized, we assume that the
  // user has already allocated the *correct* amount of space for it.
  // If not, we use the appropriate PETSc routines to initialize it.
  if (!petsc_subvector->initialized())
    {
      // Initialize the petsc_subvector to have enough space to hold
      // the entries which will be scattered into it.  Note: such an
      // init() function (where we let PETSc decide the number of local
      // entries) is not currently offered by the PetscVector
      // class.  Should we differentiate here between sequential and
      // parallel vector creation based on this->n_processors() ?
      ierr = VecCreateMPI(this->comm().get(),
                          PETSC_DECIDE,                    // n_local
                          cast_int<PetscInt>(rows.size()), // n_global
                          &(petsc_subvector->_vec));
      LIBMESH_CHKERRABORT(ierr);

      ierr = VecSetFromOptions (petsc_subvector->_vec);
      LIBMESH_CHKERRABORT(ierr);

      // Mark the subvector as initialized
      petsc_subvector->_is_initialized = true;
    }
  else
    {
      petsc_subvector->_restore_array();
    }

  // Use iota to fill an array with entries [0,1,2,3,4,...rows.size()]
  std::vector<PetscInt> idx(rows.size());
  Utility::iota (idx.begin(), idx.end(), 0);

  // Construct index sets
  ierr = ISCreateLibMesh(this->comm().get(),
                         rows.size(),
                         numeric_petsc_cast(&rows[0]),
                         PETSC_USE_POINTER,
                         &parent_is);
  LIBMESH_CHKERRABORT(ierr);

  ierr = ISCreateLibMesh(this->comm().get(),
                         rows.size(),
                         &idx[0],
                         PETSC_USE_POINTER,
                         &subvector_is);
  LIBMESH_CHKERRABORT(ierr);

  // Construct the scatter object
  ierr = VecScatterCreate(this->_vec,
                          parent_is,
                          petsc_subvector->_vec,
                          subvector_is,
                          &scatter); LIBMESH_CHKERRABORT(ierr);

  // Actually perform the scatter
#if PETSC_VERSION_LESS_THAN(2,3,3)
  ierr = VecScatterBegin(this->_vec,
                         petsc_subvector->_vec,
                         INSERT_VALUES,
                         SCATTER_FORWARD,
                         scatter); LIBMESH_CHKERRABORT(ierr);

  ierr = VecScatterEnd(this->_vec,
                       petsc_subvector->_vec,
                       INSERT_VALUES,
                       SCATTER_FORWARD,
                       scatter); LIBMESH_CHKERRABORT(ierr);
#else
  // API argument order change in PETSc 2.3.3
  ierr = VecScatterBegin(scatter,
                         this->_vec,
                         petsc_subvector->_vec,
                         INSERT_VALUES,
                         SCATTER_FORWARD); LIBMESH_CHKERRABORT(ierr);

  ierr = VecScatterEnd(scatter,
                       this->_vec,
                       petsc_subvector->_vec,
                       INSERT_VALUES,
                       SCATTER_FORWARD); LIBMESH_CHKERRABORT(ierr);
#endif

  // Clean up
  ierr = LibMeshISDestroy(&parent_is);       LIBMESH_CHKERRABORT(ierr);
  ierr = LibMeshISDestroy(&subvector_is);    LIBMESH_CHKERRABORT(ierr);
  ierr = LibMeshVecScatterDestroy(&scatter); LIBMESH_CHKERRABORT(ierr);

}
template<typename T >
T libMesh::PetscVector< T >::dot ( const NumericVector< T > &  V) const [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 528 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec.

{
  this->_restore_array();

  // Error flag
  PetscErrorCode ierr = 0;

  // Return value
  PetscScalar value=0.;

  // Make sure the NumericVector passed in is really a PetscVector
  const PetscVector<T>* v = cast_ptr<const PetscVector<T>*>(&V);

  // 2.3.x (at least) style.  Untested for previous versions.
  ierr = VecDot(this->_vec, v->_vec, &value);
  LIBMESH_CHKERRABORT(ierr);

  return static_cast<T>(value);
}
template<typename T>
virtual T libMesh::NumericVector< T >::el ( const numeric_index_type  i) const [inline, virtual, inherited]
Returns:
the element U(i)

Definition at line 344 of file numeric_vector.h.

{ return (*this)(i); }

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

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

{
  _enable_print_counter = true;
  return;
}
template<typename T >
numeric_index_type libMesh::PetscVector< T >::first_local_index ( ) const [inline, virtual]
Returns:
the index of the first vector element actually stored on this processor

Implements libMesh::NumericVector< T >.

Definition at line 1104 of file petsc_vector.h.

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

{
  libmesh_assert (this->initialized());

  numeric_index_type first = 0;

  if(_array_is_present) // Can we use cached values?
    first = _first;
  else
    {
      PetscErrorCode ierr=0;
      PetscInt petsc_first=0, petsc_last=0;
      ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
      LIBMESH_CHKERRABORT(ierr);
      first = static_cast<numeric_index_type>(petsc_first);
    }

  return first;
}
template<typename T >
void libMesh::PetscVector< T >::get ( const std::vector< numeric_index_type > &  index,
T *  values 
) const [inline, virtual]

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

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1232 of file petsc_vector.h.

References libMesh::GHOSTED.

{
  this->_get_array();

  const std::size_t num = index.size();

  for(std::size_t i=0; i<num; i++)
    {
      const numeric_index_type local_index = this->map_global_to_local_index(index[i]);
#ifndef NDEBUG
      if(this->type() == GHOSTED)
        {
          libmesh_assert_less (local_index, _local_size);
        }
#endif
      values[i] = static_cast<T>(_values[local_index]);
    }
}
template<typename T>
void libMesh::NumericVector< T >::get ( const std::vector< numeric_index_type > &  index,
std::vector< T > &  values 
) const [inline, inherited]

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 792 of file numeric_vector.h.

{
  const std::size_t num = index.size();
  values.resize(num);
  if (!num)
    return;

  this->get(index, &values[0]);
}
std::string libMesh::ReferenceCounter::get_info ( ) [static, inherited]

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

{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)

  std::ostringstream oss;

  oss << '\n'
      << " ---------------------------------------------------------------------------- \n"
      << "| Reference count information                                                |\n"
      << " ---------------------------------------------------------------------------- \n";

  for (Counts::iterator it = _counts.begin();
       it != _counts.end(); ++it)
    {
      const std::string name(it->first);
      const unsigned int creations    = it->second.first;
      const unsigned int destructions = it->second.second;

      oss << "| " << name << " reference count information:\n"
          << "|  Creations:    " << creations    << '\n'
          << "|  Destructions: " << destructions << '\n';
    }

  oss << " ---------------------------------------------------------------------------- \n";

  return oss.str();

#else

  return "";

#endif
}
template<typename T>
int libMesh::NumericVector< T >::global_relative_compare ( const NumericVector< T > &  other_vector,
const Real  threshold = TOLERANCE 
) const [virtual, inherited]
Returns:
-1 when this is equivalent to other_vector, up to the given local relative threshold. When differences occur, the return value contains the first index where the difference (a[i]-b[i])/max_j(a[j],b[j]) exceeded the threshold. When no threshold is given, the libMesh TOLERANCE is used.

Definition at line 181 of file numeric_vector.C.

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

{
  libmesh_assert (this->initialized());
  libmesh_assert (other_vector.initialized());
  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());

  int first_different_i = std::numeric_limits<int>::max();
  numeric_index_type i = first_local_index();

  const Real my_norm = this->linfty_norm();
  const Real other_norm = other_vector.linfty_norm();
  const Real abs_threshold = std::max(my_norm, other_norm) * threshold;

  do
    {
      if ( std::abs( (*this)(i) - other_vector(i) ) > abs_threshold )
        first_different_i = i;
      else
        i++;
    }
  while (first_different_i==std::numeric_limits<int>::max()
         && i<last_local_index());

  // Find the correct first differing index in parallel
  this->comm().min(first_different_i);

  if (first_different_i == std::numeric_limits<int>::max())
    return -1;

  return first_different_i;
}
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name) [inline, protected, inherited]

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

Definition at line 163 of file reference_counter.h.

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

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

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.first++;
}
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name) [inline, protected, inherited]

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

Definition at line 176 of file reference_counter.h.

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

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

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.second++;
}
template<typename T >
T libMesh::PetscVector< T >::indefinite_dot ( const NumericVector< T > &  V) const [virtual]

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

Definition at line 549 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec.

{
  this->_restore_array();

  // Error flag
  PetscErrorCode ierr = 0;

  // Return value
  PetscScalar value=0.;

  // Make sure the NumericVector passed in is really a PetscVector
  const PetscVector<T>* v = cast_ptr<const PetscVector<T>*>(&V);

  // 2.3.x (at least) style.  Untested for previous versions.
  ierr = VecTDot(this->_vec, v->_vec, &value);
  LIBMESH_CHKERRABORT(ierr);

  return static_cast<T>(value);
}
template<typename T >
void libMesh::PetscVector< T >::init ( const numeric_index_type  N,
const numeric_index_type  n_local,
const bool  fast = false,
const ParallelType  type = AUTOMATIC 
) [inline, virtual]

Change the dimension of the vector to N. The reserved memory for this vector remains unchanged if possible, to make things faster, but this may waste some memory, so take this in the back of your head. However, if N==0 all memory is freed, i.e. if you want to resize the vector and release the memory not needed, you have to first call init(0) and then init(N). This cited behaviour is analogous to that of the STL containers.

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

Implements libMesh::NumericVector< T >.

Definition at line 767 of file petsc_vector.h.

References libMesh::libMeshPrivateData::_is_initialized, libMesh::AUTOMATIC, libMesh::initialized(), libMesh::libmesh_assert(), libMesh::PARALLEL, libMesh::SERIAL, and libMesh::zero.

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

{
  PetscErrorCode ierr=0;
  PetscInt petsc_n=static_cast<PetscInt>(n);
  PetscInt petsc_n_local=static_cast<PetscInt>(n_local);


  // Clear initialized vectors
  if (this->initialized())
    this->clear();

  if (ptype == AUTOMATIC)
    {
      if (n == n_local)
        this->_type = SERIAL;
      else
        this->_type = PARALLEL;
    }
  else
    this->_type = ptype;

  libmesh_assert ((this->_type==SERIAL && n==n_local) ||
                  this->_type==PARALLEL);

  // create a sequential vector if on only 1 processor
  if (this->_type == SERIAL)
    {
      ierr = VecCreateSeq (PETSC_COMM_SELF, petsc_n, &_vec);
      CHKERRABORT(PETSC_COMM_SELF,ierr);

      ierr = VecSetFromOptions (_vec);
      CHKERRABORT(PETSC_COMM_SELF,ierr);
    }
  // otherwise create an MPI-enabled vector
  else if (this->_type == PARALLEL)
    {
#ifdef LIBMESH_HAVE_MPI
      libmesh_assert_less_equal (n_local, n);
      ierr = VecCreateMPI (this->comm().get(), petsc_n_local, petsc_n,
                           &_vec);
      LIBMESH_CHKERRABORT(ierr);
#else
      libmesh_assert_equal_to (n_local, n);
      ierr = VecCreateSeq (PETSC_COMM_SELF, petsc_n, &_vec);
      CHKERRABORT(PETSC_COMM_SELF,ierr);
#endif

      ierr = VecSetFromOptions (_vec);
      LIBMESH_CHKERRABORT(ierr);
    }
  else
    libmesh_error_msg("Unsupported type " << this->_type);

  this->_is_initialized = true;
  this->_is_closed = true;


  if (fast == false)
    this->zero ();
}
template<typename T >
void libMesh::PetscVector< T >::init ( const numeric_index_type  N,
const bool  fast = false,
const ParallelType  type = AUTOMATIC 
) [inline, virtual]

call init with n_local = N,

Implements libMesh::NumericVector< T >.

Definition at line 835 of file petsc_vector.h.

References libMesh::TriangleWrapper::init().

{
  this->init(n,n,fast,ptype);
}
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 
) [inline, virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 906 of file petsc_vector.h.

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

{
  // Clear initialized vectors
  if (this->initialized())
    this->clear();

  const PetscVector<T>& v = cast_ref<const PetscVector<T>&>(other);

  // Other vector should restore array.
  if(v.initialized())
    {
      v._restore_array();
    }

  this->_global_to_local_map = v._global_to_local_map;

  // Even if we're initializeing sizes based on an uninitialized or
  // unclosed vector, *this* vector is being initialized now and is
  // initially closed.
  this->_is_closed      = true; // v._is_closed;
  this->_is_initialized = true; // v._is_initialized;

  this->_type = v._type;

  // We want to have a valid Vec, even if it's initially of size zero

//  if (v.size() != 0)
//    {
      PetscErrorCode ierr = 0;

      ierr = VecDuplicate (v._vec, &this->_vec);
      LIBMESH_CHKERRABORT(ierr);
//    }

  if (fast == false)
    this->zero ();
}
template<typename T>
virtual bool libMesh::NumericVector< T >::initialized ( ) const [inline, virtual, inherited]
template<typename T >
void libMesh::PetscVector< T >::insert ( const T *  v,
const std::vector< numeric_index_type > &  dof_indices 
) [virtual]

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

Reimplemented from libMesh::NumericVector< T >.

Definition at line 429 of file petsc_vector.C.

References libMesh::numeric_petsc_cast().

{
  if (dof_indices.empty())
    return;

  this->_restore_array();

  PetscErrorCode ierr=0;
  PetscInt *idx_values = numeric_petsc_cast(&dof_indices[0]);
  ierr = VecSetValues (_vec, dof_indices.size(), idx_values, v, INSERT_VALUES);
  LIBMESH_CHKERRABORT(ierr);

  this->_is_closed = false;
}
template<typename T>
void libMesh::NumericVector< T >::insert ( const std::vector< T > &  v,
const std::vector< numeric_index_type > &  dof_indices 
) [inline, inherited]

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

Definition at line 830 of file numeric_vector.h.

References libMesh::libmesh_assert().

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

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

Definition at line 104 of file numeric_vector.C.

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

{
  libmesh_assert_equal_to (V.size(), dof_indices.size());

  for (numeric_index_type i=0; i<dof_indices.size(); i++)
    this->set (dof_indices[i], V(i));
}
template<typename T>
void libMesh::NumericVector< T >::insert ( const DenseVector< T > &  V,
const std::vector< numeric_index_type > &  dof_indices 
) [inline, inherited]

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

Definition at line 842 of file numeric_vector.h.

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

{
  libmesh_assert(v.size() == dof_indices.size());
  if (!v.empty())
    this->insert(&v(0), dof_indices);
}
template<typename T>
void libMesh::NumericVector< T >::insert ( const DenseSubVector< T > &  V,
const std::vector< numeric_index_type > &  dof_indices 
) [inline, inherited]

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

Definition at line 854 of file numeric_vector.h.

References libMesh::DenseVectorBase< T >::empty(), libMesh::libmesh_assert(), and libMesh::DenseVectorBase< T >::size().

{
  libmesh_assert(v.size() == dof_indices.size());
  if (!v.empty())
    this->insert(&v(0), dof_indices);
}
template<typename T >
Real libMesh::PetscVector< T >::l1_norm ( ) const [virtual]
Returns:
the $l_1$-norm of the vector, i.e. the sum of the absolute values.

Implements libMesh::NumericVector< T >.

Definition at line 59 of file petsc_vector.C.

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

{
  this->_restore_array();
  libmesh_assert(this->closed());

  PetscErrorCode ierr=0;
  PetscReal value=0.;

  ierr = VecNorm (_vec, NORM_1, &value);
  LIBMESH_CHKERRABORT(ierr);

  return static_cast<Real>(value);
}
template<typename T >
Real libMesh::PetscVector< T >::l2_norm ( ) const [virtual]
Returns:
the $l_2$-norm of the vector, i.e. the square root of the sum of the squares of the elements.

Implements libMesh::NumericVector< T >.

Definition at line 76 of file petsc_vector.C.

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

{
  this->_restore_array();
  libmesh_assert(this->closed());

  PetscErrorCode ierr=0;
  PetscReal value=0.;

  ierr = VecNorm (_vec, NORM_2, &value);
  LIBMESH_CHKERRABORT(ierr);

  return static_cast<Real>(value);
}
template<typename T >
numeric_index_type libMesh::PetscVector< T >::last_local_index ( ) const [inline, virtual]
Returns:
the index of the last vector element actually stored on this processor

Implements libMesh::NumericVector< T >.

Definition at line 1128 of file petsc_vector.h.

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

{
  libmesh_assert (this->initialized());

  numeric_index_type last = 0;

  if(_array_is_present) // Can we use cached values?
    last = _last;
  else
    {
      PetscErrorCode ierr=0;
      PetscInt petsc_first=0, petsc_last=0;
      ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
      LIBMESH_CHKERRABORT(ierr);
      last = static_cast<numeric_index_type>(petsc_last);
    }

  return last;
}
template<typename T >
Real libMesh::PetscVector< T >::linfty_norm ( ) const [virtual]
Returns:
the maximum absolute value of the elements of this vector, which is the $l_\infty$-norm of a vector.

Implements libMesh::NumericVector< T >.

Definition at line 94 of file petsc_vector.C.

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

{
  this->_restore_array();
  libmesh_assert(this->closed());

  PetscErrorCode ierr=0;
  PetscReal value=0.;

  ierr = VecNorm (_vec, NORM_INFINITY, &value);
  LIBMESH_CHKERRABORT(ierr);

  return static_cast<Real>(value);
}
template<typename T>
int libMesh::NumericVector< T >::local_relative_compare ( const NumericVector< T > &  other_vector,
const Real  threshold = TOLERANCE 
) const [virtual, inherited]
Returns:
-1 when this is equivalent to other_vector, up to the given local relative threshold. When differences occur, the return value contains the first index where the difference (a[i]-b[i])/max(a[i],b[i]) exceeded the threshold. When no threshold is given, the libMesh TOLERANCE is used.

Definition at line 148 of file numeric_vector.C.

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

{
  libmesh_assert (this->initialized());
  libmesh_assert (other_vector.initialized());
  libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
  libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());

  int first_different_i = std::numeric_limits<int>::max();
  numeric_index_type i = first_local_index();

  do
    {
      if ( std::abs( (*this)(i) - other_vector(i) ) > threshold *
           std::max(std::abs((*this)(i)), std::abs(other_vector(i))))
        first_different_i = i;
      else
        i++;
    }
  while (first_different_i==std::numeric_limits<int>::max()
         && i<last_local_index());

  // Find the correct first differing index in parallel
  this->comm().min(first_different_i);

  if (first_different_i == std::numeric_limits<int>::max())
    return -1;

  return first_different_i;
}
template<typename T >
numeric_index_type libMesh::PetscVector< T >::local_size ( ) const [inline, virtual]
Returns:
the local size of the vector (index_stop-index_start)

Implements libMesh::NumericVector< T >.

Definition at line 1087 of file petsc_vector.h.

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

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

{
  libmesh_assert (this->initialized());

  PetscErrorCode ierr=0;
  PetscInt petsc_size=0;

  ierr = VecGetLocalSize(_vec, &petsc_size);
  LIBMESH_CHKERRABORT(ierr);

  return static_cast<numeric_index_type>(petsc_size);
}
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 997 of file petsc_vector.C.

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

{
  this->_restore_array();

  // This function must be run on all processors at once
  parallel_object_only();

  PetscErrorCode ierr=0;
  const PetscInt n = this->size();
  const PetscInt nl = this->local_size();
  PetscScalar *values;

  v_local.clear();
  v_local.resize(n, 0.);

  ierr = VecGetArray (_vec, &values);
  LIBMESH_CHKERRABORT(ierr);

  numeric_index_type ioff = first_local_index();

  for (PetscInt i=0; i<nl; i++)
    v_local[i+ioff] = static_cast<T>(values[i]);

  ierr = VecRestoreArray (_vec, &values);
  LIBMESH_CHKERRABORT(ierr);

  this->comm().sum(v_local);
}
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 753 of file petsc_vector.C.

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

{
  this->_restore_array();

  // Make sure the NumericVector passed in is really a PetscVector
  PetscVector<T>* v_local = cast_ptr<PetscVector<T>*>(&v_local_in);

  libmesh_assert(v_local);
  libmesh_assert_equal_to (v_local->size(), this->size());

  PetscErrorCode ierr = 0;
  const PetscInt n = this->size();

  IS is;
  VecScatter scatter;

  // Create idx, idx[i] = i;
  std::vector<PetscInt> idx(n); Utility::iota (idx.begin(), idx.end(), 0);

  // Create the index set & scatter object
  ierr = ISCreateLibMesh(this->comm().get(), n, &idx[0], PETSC_USE_POINTER, &is);
  LIBMESH_CHKERRABORT(ierr);

  ierr = VecScatterCreate(_vec,          is,
                          v_local->_vec, is,
                          &scatter);
  LIBMESH_CHKERRABORT(ierr);

  // Perform the scatter
#if PETSC_VERSION_LESS_THAN(2,3,3)

  ierr = VecScatterBegin(_vec, v_local->_vec, INSERT_VALUES,
                         SCATTER_FORWARD, scatter);
  LIBMESH_CHKERRABORT(ierr);

  ierr = VecScatterEnd  (_vec, v_local->_vec, INSERT_VALUES,
                         SCATTER_FORWARD, scatter);
  LIBMESH_CHKERRABORT(ierr);
#else
  // API argument order change in PETSc 2.3.3
  ierr = VecScatterBegin(scatter, _vec, v_local->_vec,
                         INSERT_VALUES, SCATTER_FORWARD);
  LIBMESH_CHKERRABORT(ierr);

  ierr = VecScatterEnd  (scatter, _vec, v_local->_vec,
                         INSERT_VALUES, SCATTER_FORWARD);
  LIBMESH_CHKERRABORT(ierr);
#endif

  // Clean up
  ierr = LibMeshISDestroy (&is);
  LIBMESH_CHKERRABORT(ierr);

  ierr = LibMeshVecScatterDestroy(&scatter);
  LIBMESH_CHKERRABORT(ierr);

  // Make sure ghost dofs are up to date
  if (v_local->type() == GHOSTED)
    v_local->close();
}
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 817 of file petsc_vector.C.

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

{
  // FIXME: Workaround for a strange bug at large-scale.
  // If we have ghosting, PETSc lets us just copy the solution, and
  // doing so avoids a segfault?
  if (v_local_in.type() == GHOSTED &&
      this->type() == PARALLEL)
    {
      v_local_in = *this;
      return;
    }

  // Normal code path begins here

  this->_restore_array();

  // Make sure the NumericVector passed in is really a PetscVector
  PetscVector<T>* v_local = cast_ptr<PetscVector<T>*>(&v_local_in);

  libmesh_assert(v_local);
  libmesh_assert_equal_to (v_local->size(), this->size());
  libmesh_assert_less_equal (send_list.size(), v_local->size());

  PetscErrorCode ierr=0;
  const numeric_index_type n_sl =
    cast_int<numeric_index_type>(send_list.size());

  IS is;
  VecScatter scatter;

  std::vector<PetscInt> idx(n_sl + this->local_size());

  for (numeric_index_type i=0; i<n_sl; i++)
    idx[i] = static_cast<PetscInt>(send_list[i]);
  for (numeric_index_type i = 0; i != this->local_size(); ++i)
    idx[n_sl+i] = i + this->first_local_index();

  // Create the index set & scatter object
  if (idx.empty())
    ierr = ISCreateLibMesh(this->comm().get(),
                           n_sl+this->local_size(), PETSC_NULL, PETSC_USE_POINTER, &is);
  else
    ierr = ISCreateLibMesh(this->comm().get(),
                           n_sl+this->local_size(), &idx[0], PETSC_USE_POINTER, &is);
  LIBMESH_CHKERRABORT(ierr);

  ierr = VecScatterCreate(_vec,          is,
                          v_local->_vec, is,
                          &scatter);
  LIBMESH_CHKERRABORT(ierr);


  // Perform the scatter
#if PETSC_VERSION_LESS_THAN(2,3,3)

  ierr = VecScatterBegin(_vec, v_local->_vec, INSERT_VALUES,
                         SCATTER_FORWARD, scatter);
  LIBMESH_CHKERRABORT(ierr);

  ierr = VecScatterEnd  (_vec, v_local->_vec, INSERT_VALUES,
                         SCATTER_FORWARD, scatter);
  LIBMESH_CHKERRABORT(ierr);

#else

  // API argument order change in PETSc 2.3.3
  ierr = VecScatterBegin(scatter, _vec, v_local->_vec,
                         INSERT_VALUES, SCATTER_FORWARD);
  LIBMESH_CHKERRABORT(ierr);

  ierr = VecScatterEnd  (scatter, _vec, v_local->_vec,
                         INSERT_VALUES, SCATTER_FORWARD);
  LIBMESH_CHKERRABORT(ierr);

#endif


  // Clean up
  ierr = LibMeshISDestroy (&is);
  LIBMESH_CHKERRABORT(ierr);

  ierr = LibMeshVecScatterDestroy(&scatter);
  LIBMESH_CHKERRABORT(ierr);

  // Make sure ghost dofs are up to date
  if (v_local->type() == GHOSTED)
    v_local->close();
}
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 909 of file petsc_vector.C.

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

{
  this->_restore_array();

  libmesh_assert_less_equal (send_list.size(), this->size());
  libmesh_assert_less_equal (last_local_idx+1, this->size());

  const numeric_index_type my_size       = this->size();
  const numeric_index_type my_local_size = (last_local_idx - first_local_idx + 1);
  PetscErrorCode ierr=0;

  // Don't bother for serial cases
  //  if ((first_local_idx == 0) &&
  //      (my_local_size == my_size))
  // But we do need to stay in sync for degenerate cases
  if (this->n_processors() == 1)
    return;


  // Build a parallel vector, initialize it with the local
  // parts of (*this)
  PetscVector<T> parallel_vec(this->comm(), PARALLEL);

  parallel_vec.init (my_size, my_local_size, true, PARALLEL);


  // Copy part of *this into the parallel_vec
  {
    IS is;
    VecScatter scatter;

    // Create idx, idx[i] = i+first_local_idx;
    std::vector<PetscInt> idx(my_local_size);
    Utility::iota (idx.begin(), idx.end(), first_local_idx);

    // Create the index set & scatter object
    ierr = ISCreateLibMesh(this->comm().get(), my_local_size,
                           my_local_size ? &idx[0] : NULL, PETSC_USE_POINTER, &is);
    LIBMESH_CHKERRABORT(ierr);

    ierr = VecScatterCreate(_vec,              is,
                            parallel_vec._vec, is,
                            &scatter);
    LIBMESH_CHKERRABORT(ierr);

    // Perform the scatter
#if PETSC_VERSION_LESS_THAN(2,3,3)

    ierr = VecScatterBegin(_vec, parallel_vec._vec, INSERT_VALUES,
                           SCATTER_FORWARD, scatter);
    LIBMESH_CHKERRABORT(ierr);

    ierr = VecScatterEnd  (_vec, parallel_vec._vec, INSERT_VALUES,
                           SCATTER_FORWARD, scatter);
    LIBMESH_CHKERRABORT(ierr);

#else

    // API argument order change in PETSc 2.3.3
    ierr = VecScatterBegin(scatter, _vec, parallel_vec._vec,
                           INSERT_VALUES, SCATTER_FORWARD);
    LIBMESH_CHKERRABORT(ierr);

    ierr = VecScatterEnd  (scatter, _vec, parallel_vec._vec,
                           INSERT_VALUES, SCATTER_FORWARD);
    LIBMESH_CHKERRABORT(ierr);

#endif

    // Clean up
    ierr = LibMeshISDestroy (&is);
    LIBMESH_CHKERRABORT(ierr);

    ierr = LibMeshVecScatterDestroy(&scatter);
    LIBMESH_CHKERRABORT(ierr);
  }

  // localize like normal
  parallel_vec.close();
  parallel_vec.localize (*this, send_list);
  this->close();
}
template<typename T>
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 1032 of file petsc_vector.C.

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

{
  this->_restore_array();

  PetscErrorCode ierr=0;
  const PetscInt n  = size();
  const PetscInt nl = local_size();
  PetscScalar *values;


  // only one processor
  if (n_processors() == 1)
    {
      v_local.resize(n);

      ierr = VecGetArray (_vec, &values);
      LIBMESH_CHKERRABORT(ierr);

      for (PetscInt i=0; i<n; i++)
        v_local[i] = static_cast<Real>(values[i]);

      ierr = VecRestoreArray (_vec, &values);
      LIBMESH_CHKERRABORT(ierr);
    }

  // otherwise multiple processors
  else
    {
      if(pid == 0) // optimized version for localizing to 0
        {
          Vec vout;
          VecScatter ctx;

          ierr = VecScatterCreateToZero(_vec, &ctx, &vout);
          LIBMESH_CHKERRABORT(ierr);

          ierr = VecScatterBegin(ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
          LIBMESH_CHKERRABORT(ierr);
          ierr = VecScatterEnd(ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
          LIBMESH_CHKERRABORT(ierr);

          if(processor_id() == 0)
            {
              v_local.resize(n);

              ierr = VecGetArray (vout, &values);
              LIBMESH_CHKERRABORT(ierr);

              for (PetscInt i=0; i<n; i++)
                v_local[i] = static_cast<Real>(values[i]);

              ierr = VecRestoreArray (vout, &values);
              LIBMESH_CHKERRABORT(ierr);
            }

          ierr = LibMeshVecScatterDestroy(&ctx);
          LIBMESH_CHKERRABORT(ierr);
          ierr = LibMeshVecDestroy(&vout);
          LIBMESH_CHKERRABORT(ierr);

        }
      else
        {
          v_local.resize(n);

          numeric_index_type ioff = this->first_local_index();
          std::vector<Real> local_values (n, 0.);

          {
            ierr = VecGetArray (_vec, &values);
            LIBMESH_CHKERRABORT(ierr);

            for (PetscInt i=0; i<nl; i++)
              local_values[i+ioff] = static_cast<Real>(values[i]);

            ierr = VecRestoreArray (_vec, &values);
            LIBMESH_CHKERRABORT(ierr);
          }


          MPI_Reduce (&local_values[0], &v_local[0], n, MPI_REAL, MPI_SUM,
                      pid, this->comm().get());
        }
    }
}
template<>
void libMesh::PetscVector< Complex >::localize_to_one ( std::vector< Complex > &  v_local,
const processor_id_type  pid 
) const

Definition at line 1126 of file petsc_vector.C.

{
  this->_restore_array();

  PetscErrorCode ierr=0;
  const PetscInt n  = size();
  const PetscInt nl = local_size();
  PetscScalar *values;


  v_local.resize(n);


  for (PetscInt i=0; i<n; i++)
    v_local[i] = 0.;

  // only one processor
  if (n == nl)
    {
      ierr = VecGetArray (_vec, &values);
      LIBMESH_CHKERRABORT(ierr);

      for (PetscInt i=0; i<n; i++)
        v_local[i] = static_cast<Complex>(values[i]);

      ierr = VecRestoreArray (_vec, &values);
      LIBMESH_CHKERRABORT(ierr);
    }

  // otherwise multiple processors
  else
    {
      numeric_index_type ioff = this->first_local_index();

      /* in here the local values are stored, acting as send buffer for MPI
       * initialize to zero, since we collect using MPI_SUM
       */
      std::vector<Real> real_local_values(n, 0.);
      std::vector<Real> imag_local_values(n, 0.);

      {
        ierr = VecGetArray (_vec, &values);
        LIBMESH_CHKERRABORT(ierr);

        // provide my local share to the real and imag buffers
        for (PetscInt i=0; i<nl; i++)
          {
            real_local_values[i+ioff] = static_cast<Complex>(values[i]).real();
            imag_local_values[i+ioff] = static_cast<Complex>(values[i]).imag();
          }

        ierr = VecRestoreArray (_vec, &values);
        LIBMESH_CHKERRABORT(ierr);
      }

      /* have buffers of the real and imaginary part of v_local.
       * Once MPI_Reduce() collected all the real and imaginary
       * parts in these std::vector<Real>, the values can be
       * copied to v_local
       */
      std::vector<Real> real_v_local(n);
      std::vector<Real> imag_v_local(n);

      // collect entries from other proc's in real_v_local, imag_v_local
      MPI_Reduce (&real_local_values[0], &real_v_local[0], n,
                  MPI_REAL, MPI_SUM,
                  pid, this->comm().get());

      MPI_Reduce (&imag_local_values[0], &imag_v_local[0], n,
                  MPI_REAL, MPI_SUM,
                  pid, this->comm().get());

      // copy real_v_local and imag_v_local to v_local
      for (PetscInt i=0; i<n; i++)
        v_local[i] = Complex(real_v_local[i], imag_v_local[i]);
    }
}
template<typename T >
numeric_index_type libMesh::PetscVector< T >::map_global_to_local_index ( const numeric_index_type  i) const [inline]

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

Definition at line 1152 of file petsc_vector.h.

References end, libMesh::initialized(), and libMesh::libmesh_assert().

{
  libmesh_assert (this->initialized());

  numeric_index_type first=0;
  numeric_index_type last=0;

  if(_array_is_present) // Can we use cached values?
    {
      first = _first;
      last = _last;
    }
  else
    {
      PetscErrorCode ierr=0;
      PetscInt petsc_first=0, petsc_last=0;
      ierr = VecGetOwnershipRange (_vec, &petsc_first, &petsc_last);
      LIBMESH_CHKERRABORT(ierr);
      first = static_cast<numeric_index_type>(petsc_first);
      last = static_cast<numeric_index_type>(petsc_last);
    }


  if((i>=first) && (i<last))
    {
      return i-first;
    }

  GlobalToLocalMap::const_iterator it = _global_to_local_map.find(i);
#ifndef NDEBUG
  const GlobalToLocalMap::const_iterator end = _global_to_local_map.end();
  if (it == end)
    {
      std::ostringstream error_message;
      error_message << "No index " << i << " in ghosted vector.\n"
                    << "Vector contains [" << first << ',' << last << ")\n";
      GlobalToLocalMap::const_iterator b = _global_to_local_map.begin();
      if (b == end)
        {
          error_message << "And empty ghost array.\n";
        }
      else
        {
          error_message << "And ghost array {" << b->first;
          for (++b; b != end; ++b)
            error_message << ',' << b->first;
          error_message << "}\n";
        }

      libmesh_error_msg(error_message.str());
    }
  libmesh_assert (it != _global_to_local_map.end());
#endif
  return it->second+last-first;
}
template<typename T >
Real libMesh::PetscVector< T >::max ( ) const [inline, virtual]
Returns:
the maximum element in the vector. In case of complex numbers, this returns the maximum Real part.

Implements libMesh::NumericVector< T >.

Definition at line 1274 of file petsc_vector.h.

References libMesh::Real.

{
  this->_restore_array();

  PetscErrorCode ierr=0;
  PetscInt index=0;
  PetscReal returnval=0.;

  ierr = VecMax (_vec, &index, &returnval);
  LIBMESH_CHKERRABORT(ierr);

  // this return value is correct: VecMax returns a PetscReal
  return static_cast<Real>(returnval);
}
template<typename T >
Real libMesh::PetscVector< T >::min ( ) const [inline, virtual]
Returns:
the minimum element in the vector. In case of complex numbers, this returns the minimum Real part.

Implements libMesh::NumericVector< T >.

Definition at line 1255 of file petsc_vector.h.

References libMesh::Real.

{
  this->_restore_array();

  PetscErrorCode ierr=0;
  PetscInt index=0;
  PetscReal returnval=0.;

  ierr = VecMin (_vec, &index, &returnval);
  LIBMESH_CHKERRABORT(ierr);

  // this return value is correct: VecMin returns a PetscReal
  return static_cast<Real>(returnval);
}
static unsigned int libMesh::ReferenceCounter::n_objects ( ) [inline, static, inherited]

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

Definition at line 79 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

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

  { return _n_objects; }
Returns:
the number of processors in the group.

Definition at line 92 of file parallel_object.h.

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

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::ParallelMesh::add_elem(), libMesh::ParallelMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::ParallelMesh::assign_unique_ids(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::ParallelMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::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::MeshTools::processor_bounding_box(), libMesh::System::project_vector(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::System::read_serialized_vector(), libMesh::Partitioner::repartition(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::BoundaryInfo::sync(), libMesh::ParallelMesh::update_parallel_id_counts(), libMesh::CheckpointIO::write(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::System::write_parallel_data(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

  { return cast_int<processor_id_type>(_communicator.size()); }
template<typename T >
T libMesh::PetscVector< T >::operator() ( const numeric_index_type  i) const [inline, virtual]

Access components, returns U(i).

Implements libMesh::NumericVector< T >.

Definition at line 1212 of file petsc_vector.h.

References libMesh::GHOSTED.

{
  this->_get_array();

  const numeric_index_type local_index = this->map_global_to_local_index(i);

#ifndef NDEBUG
  if(this->type() == GHOSTED)
    {
      libmesh_assert_less (local_index, _local_size);
    }
#endif

  return static_cast<T>(_values[local_index]);
}
template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator*= ( const T  a) [inline, inherited]

Multiplication operator. Equivalent to U.scale(a)

Definition at line 378 of file numeric_vector.h.

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

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

Implements libMesh::NumericVector< T >.

Definition at line 113 of file petsc_vector.C.

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

{
  this->_restore_array();
  libmesh_assert(this->closed());

  this->add(1., v);

  return *this;
}
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator-= ( const NumericVector< T > &  V) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 127 of file petsc_vector.C.

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

{
  this->_restore_array();
  libmesh_assert(this->closed());

  this->add(-1., v);

  return *this;
}
template<typename T>
NumericVector<T>& libMesh::NumericVector< T >::operator/= ( const T  a) [inline, inherited]

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

Definition at line 384 of file numeric_vector.h.

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

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

Implements libMesh::NumericVector< T >.

Definition at line 489 of file petsc_vector.C.

References libMesh::PetscVector< T >::_vec.

{
  PetscErrorCode ierr = 0;

  const PetscVector<T>* v_vec = cast_ptr<const PetscVector<T>*>(&v);

  ierr = VecPointwiseDivide(_vec, _vec, v_vec->_vec);
  LIBMESH_CHKERRABORT(ierr);

  return *this;
}
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const T  s) [virtual]

Change the dimension to that of the vector V. The same applies as for the other init function.

The elements of V are not copied, i.e. this function is the same as calling init(V.size(),fast). $U(0-N) = s$: fill all components.

Implements libMesh::NumericVector< T >.

Definition at line 572 of file petsc_vector.C.

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

{
  this->_restore_array();
  libmesh_assert(this->closed());

  PetscErrorCode ierr = 0;
  PetscScalar s = static_cast<PetscScalar>(s_in);

  if (this->size() != 0)
    {
      if(this->type() != GHOSTED)
        {
#if PETSC_VERSION_LESS_THAN(2,3,0)
          // 2.2.x & earlier style
          ierr = VecSet(&s, _vec);
          LIBMESH_CHKERRABORT(ierr);
#else
          // 2.3.x & later style
          ierr = VecSet(_vec, s);
          LIBMESH_CHKERRABORT(ierr);
#endif
        }
      else
        {
          Vec loc_vec;
          ierr = VecGhostGetLocalForm (_vec,&loc_vec);
          LIBMESH_CHKERRABORT(ierr);

#if PETSC_VERSION_LESS_THAN(2,3,0)
          // 2.2.x & earlier style
          ierr = VecSet(&s, loc_vec);
          LIBMESH_CHKERRABORT(ierr);
#else
          // 2.3.x & later style
          ierr = VecSet(loc_vec, s);
          LIBMESH_CHKERRABORT(ierr);
#endif

          ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
          LIBMESH_CHKERRABORT(ierr);
        }
    }

  return *this;
}
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const NumericVector< T > &  V) [virtual]

$U = V$: copy all components.

Implements libMesh::NumericVector< T >.

Definition at line 622 of file petsc_vector.C.

{
  // Make sure the NumericVector passed in is really a PetscVector
  const PetscVector<T>* v = cast_ptr<const PetscVector<T>*>(&v_in);

  *this = *v;

  return *this;
}
template<typename T >
PetscVector< T > & libMesh::PetscVector< T >::operator= ( const PetscVector< T > &  V)

$U = V$: copy all components.

Definition at line 636 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, libMesh::libmesh_assert(), libMesh::PetscVector< T >::local_size(), libMesh::PARALLEL, libMesh::SERIAL, libMesh::PetscVector< T >::size(), and libMesh::NumericVector< T >::type().

{
  this->_restore_array();
  v._restore_array();

  libmesh_assert_equal_to (this->size(), v.size());
  libmesh_assert_equal_to (this->local_size(), v.local_size());
  libmesh_assert (v.closed());

  PetscErrorCode ierr = 0;

  if (((this->type()==PARALLEL) && (v.type()==GHOSTED)) ||
      ((this->type()==GHOSTED) && (v.type()==PARALLEL)) ||
      ((this->type()==GHOSTED) && (v.type()==SERIAL))   ||
      ((this->type()==SERIAL) && (v.type()==GHOSTED)))
    {
      /* Allow assignment of a ghosted to a parallel vector since this
         causes no difficulty.  See discussion in libmesh-devel of
         June 24, 2010.  */
      ierr = VecCopy (v._vec, this->_vec);
      LIBMESH_CHKERRABORT(ierr);
    }
  else
    {
      /* In all other cases, we assert that both vectors are of equal
         type.  */
      libmesh_assert_equal_to (this->_type, v._type);

      if (v.size() != 0)
        {
          if(this->type() != GHOSTED)
            {
              ierr = VecCopy (v._vec, this->_vec);
              LIBMESH_CHKERRABORT(ierr);
            }
          else
            {
              Vec loc_vec;
              Vec v_loc_vec;
              ierr = VecGhostGetLocalForm (_vec,&loc_vec);
              LIBMESH_CHKERRABORT(ierr);
              ierr = VecGhostGetLocalForm (v._vec,&v_loc_vec);
              LIBMESH_CHKERRABORT(ierr);

              ierr = VecCopy (v_loc_vec, loc_vec);
              LIBMESH_CHKERRABORT(ierr);

              ierr = VecGhostRestoreLocalForm (v._vec,&v_loc_vec);
              LIBMESH_CHKERRABORT(ierr);
              ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
              LIBMESH_CHKERRABORT(ierr);
            }
        }
    }

  close();

  return *this;
}
template<typename T >
NumericVector< T > & libMesh::PetscVector< T >::operator= ( const std::vector< T > &  v) [virtual]

$U = V$: copy all components.

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

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

Implements libMesh::NumericVector< T >.

Definition at line 700 of file petsc_vector.C.

References libMesh::GHOSTED.

{
  this->_restore_array();

  const numeric_index_type nl   = this->local_size();
  const numeric_index_type ioff = this->first_local_index();
  PetscErrorCode ierr=0;
  PetscScalar* values;

  if (this->size() == v.size())
    {
      ierr = VecGetArray (_vec, &values);
      LIBMESH_CHKERRABORT(ierr);

      for (numeric_index_type i=0; i<nl; i++)
        values[i] =  static_cast<PetscScalar>(v[i+ioff]);

      ierr = VecRestoreArray (_vec, &values);
      LIBMESH_CHKERRABORT(ierr);
    }

  else
    {
      libmesh_assert_equal_to (this->local_size(), v.size());

      ierr = VecGetArray (_vec, &values);
      LIBMESH_CHKERRABORT(ierr);

      for (numeric_index_type i=0; i<nl; i++)
        values[i] = static_cast<PetscScalar>(v[i]);

      ierr = VecRestoreArray (_vec, &values);
      LIBMESH_CHKERRABORT(ierr);
    }

  // Make sure ghost dofs are up to date
  if (this->type() == GHOSTED)
    this->close();

  return *this;
}
template<typename T >
void libMesh::PetscVector< T >::pointwise_mult ( const NumericVector< T > &  vec1,
const NumericVector< T > &  vec2 
) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 1210 of file petsc_vector.C.

References libMesh::GHOSTED.

{
  this->_restore_array();

  PetscErrorCode ierr = 0;

  // Convert arguments to PetscVector*.
  const PetscVector<T>* vec1_petsc = cast_ptr<const PetscVector<T>*>(&vec1);
  const PetscVector<T>* vec2_petsc = cast_ptr<const PetscVector<T>*>(&vec2);

  // Call PETSc function.

#if PETSC_VERSION_LESS_THAN(2,3,1)

  libmesh_error_msg("This method has been developed with PETSc 2.3.1.  " \
                    << "No one has made it backwards compatible with older " \
                    << "versions of PETSc so far; however, it might work " \
                    << "without any change with some older version.");

#else

  if(this->type() != GHOSTED)
    {
      ierr = VecPointwiseMult(this->vec(),
                              const_cast<PetscVector<T>*>(vec1_petsc)->vec(),
                              const_cast<PetscVector<T>*>(vec2_petsc)->vec());
      LIBMESH_CHKERRABORT(ierr);
    }
  else
    {
      Vec loc_vec;
      Vec v1_loc_vec;
      Vec v2_loc_vec;
      ierr = VecGhostGetLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
      ierr = VecGhostGetLocalForm (const_cast<PetscVector<T>*>(vec1_petsc)->vec(),&v1_loc_vec);
      LIBMESH_CHKERRABORT(ierr);
      ierr = VecGhostGetLocalForm (const_cast<PetscVector<T>*>(vec2_petsc)->vec(),&v2_loc_vec);
      LIBMESH_CHKERRABORT(ierr);

      ierr = VecPointwiseMult(loc_vec,v1_loc_vec,v2_loc_vec);
      LIBMESH_CHKERRABORT(ierr);

      ierr = VecGhostRestoreLocalForm (const_cast<PetscVector<T>*>(vec1_petsc)->vec(),&v1_loc_vec);
      LIBMESH_CHKERRABORT(ierr);
      ierr = VecGhostRestoreLocalForm (const_cast<PetscVector<T>*>(vec2_petsc)->vec(),&v2_loc_vec);
      LIBMESH_CHKERRABORT(ierr);
      ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
    }

#endif

}
template<typename T >
void libMesh::NumericVector< T >::print ( std::ostream &  os = libMesh::out) const [inline, virtual, inherited]

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

Definition at line 887 of file numeric_vector.h.

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

{
  libmesh_assert (this->initialized());
  os << "Size\tglobal =  " << this->size()
     << "\t\tlocal =  " << this->local_size() << std::endl;

  os << "#\tValue" << std::endl;
  for (numeric_index_type i=this->first_local_index(); i<this->last_local_index(); i++)
    os << i << "\t" << (*this)(i) << std::endl;
}
template<>
void libMesh::NumericVector< Complex >::print ( std::ostream &  os) const [inline, inherited]

Definition at line 869 of file numeric_vector.h.

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

{
  libmesh_assert (this->initialized());
  os << "Size\tglobal =  " << this->size()
     << "\t\tlocal =  " << this->local_size() << std::endl;

  // std::complex<>::operator<<() is defined, but use this form
  os << "#\tReal part\t\tImaginary part" << std::endl;
  for (numeric_index_type i=this->first_local_index(); i<this->last_local_index(); i++)
    os << i << "\t"
       << (*this)(i).real() << "\t\t"
       << (*this)(i).imag() << std::endl;
}
template<typename T >
void libMesh::NumericVector< T >::print_global ( std::ostream &  os = libMesh::out) const [inline, virtual, inherited]

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

Definition at line 924 of file numeric_vector.h.

References libMesh::initialized(), libMesh::libmesh_assert(), and libMesh::processor_id().

{
  libmesh_assert (this->initialized());

  std::vector<T> v(this->size());
  this->localize(v);

  // Right now we only want one copy of the output
  if (this->processor_id())
    return;

  os << "Size\tglobal =  " << this->size() << std::endl;
  os << "#\tValue" << std::endl;
  for (numeric_index_type i=0; i!=v.size(); i++)
    os << i << "\t" << v[i] << std::endl;
}
template<>
void libMesh::NumericVector< Complex >::print_global ( std::ostream &  os) const [inline, inherited]

Definition at line 902 of file numeric_vector.h.

References libMesh::initialized(), libMesh::libmesh_assert(), and libMesh::processor_id().

{
  libmesh_assert (this->initialized());

  std::vector<Complex> v(this->size());
  this->localize(v);

  // Right now we only want one copy of the output
  if (this->processor_id())
    return;

  os << "Size\tglobal =  " << this->size() << std::endl;
  os << "#\tReal part\t\tImaginary part" << std::endl;
  for (numeric_index_type i=0; i!=v.size(); i++)
    os << i << "\t"
       << v[i].real() << "\t\t"
       << v[i].imag() << std::endl;
}
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out) [static, inherited]

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

template<typename T >
void libMesh::PetscVector< T >::print_matlab ( const std::string &  name = "") const [virtual]

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

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

Otherwise the matrix will be dumped to the screen.

Destroy the viewer.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 1269 of file petsc_vector.C.

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

{
  this->_restore_array();
  libmesh_assert (this->closed());

  PetscErrorCode ierr=0;
  PetscViewer petsc_viewer;


  ierr = PetscViewerCreate (this->comm().get(),
                            &petsc_viewer);
  LIBMESH_CHKERRABORT(ierr);

  if (name != "")
    {
      ierr = PetscViewerASCIIOpen( this->comm().get(),
                                   name.c_str(),
                                   &petsc_viewer);
      LIBMESH_CHKERRABORT(ierr);

      ierr = PetscViewerSetFormat (petsc_viewer,
                                   PETSC_VIEWER_ASCII_MATLAB);
      LIBMESH_CHKERRABORT(ierr);

      ierr = VecView (_vec, petsc_viewer);
      LIBMESH_CHKERRABORT(ierr);
    }

  else
    {
      ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
                                   PETSC_VIEWER_ASCII_MATLAB);
      LIBMESH_CHKERRABORT(ierr);

      ierr = VecView (_vec, PETSC_VIEWER_STDOUT_WORLD);
      LIBMESH_CHKERRABORT(ierr);
    }


  ierr = LibMeshPetscViewerDestroy (&petsc_viewer);
  LIBMESH_CHKERRABORT(ierr);
}
Returns:
the rank of this processor in the group.

Definition at line 98 of file parallel_object.h.

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

Referenced by libMesh::MetisPartitioner::_do_partition(), libMesh::EquationSystems::_read_impl(), libMesh::SerialMesh::active_local_elements_begin(), libMesh::ParallelMesh::active_local_elements_begin(), libMesh::SerialMesh::active_local_elements_end(), libMesh::ParallelMesh::active_local_elements_end(), libMesh::SerialMesh::active_local_subdomain_elements_begin(), libMesh::ParallelMesh::active_local_subdomain_elements_begin(), libMesh::SerialMesh::active_local_subdomain_elements_end(), libMesh::ParallelMesh::active_local_subdomain_elements_end(), libMesh::SerialMesh::active_not_local_elements_begin(), libMesh::ParallelMesh::active_not_local_elements_begin(), libMesh::SerialMesh::active_not_local_elements_end(), libMesh::ParallelMesh::active_not_local_elements_end(), libMesh::ParallelMesh::add_elem(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::ParallelMesh::add_node(), libMesh::UnstructuredMesh::all_second_order(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::ParallelMesh::assign_unique_ids(), 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::DofMap::build_sparsity(), libMesh::ParallelMesh::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::ExodusII_IO_Helper::create(), libMesh::ParallelMesh::delete_elem(), libMesh::ParallelMesh::delete_node(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DofMap::end_dof(), libMesh::DofMap::end_old_dof(), libMesh::EnsightIO::EnsightIO(), libMesh::SerialMesh::facelocal_elements_begin(), libMesh::ParallelMesh::facelocal_elements_begin(), libMesh::SerialMesh::facelocal_elements_end(), libMesh::ParallelMesh::facelocal_elements_end(), libMesh::MeshFunction::find_element(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::DofMap::first_dof(), libMesh::DofMap::first_old_dof(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::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::Nemesis_IO_Helper::get_ss_param_global(), 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::ParallelMesh::insert_elem(), libMesh::SparsityPattern::Build::join(), libMesh::DofMap::last_dof(), libMesh::MeshTools::libmesh_assert_valid_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_procids< Node >(), libMesh::SerialMesh::local_elements_begin(), libMesh::ParallelMesh::local_elements_begin(), libMesh::SerialMesh::local_elements_end(), libMesh::ParallelMesh::local_elements_end(), libMesh::SerialMesh::local_level_elements_begin(), libMesh::ParallelMesh::local_level_elements_begin(), libMesh::SerialMesh::local_level_elements_end(), libMesh::ParallelMesh::local_level_elements_end(), libMesh::SerialMesh::local_nodes_begin(), libMesh::ParallelMesh::local_nodes_begin(), libMesh::SerialMesh::local_nodes_end(), libMesh::ParallelMesh::local_nodes_end(), libMesh::SerialMesh::local_not_level_elements_begin(), libMesh::ParallelMesh::local_not_level_elements_begin(), libMesh::SerialMesh::local_not_level_elements_end(), libMesh::ParallelMesh::local_not_level_elements_end(), 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::DofMap::n_local_dofs(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::SerialMesh::not_local_elements_begin(), libMesh::ParallelMesh::not_local_elements_begin(), libMesh::SerialMesh::not_local_elements_end(), libMesh::ParallelMesh::not_local_elements_end(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::ParallelMesh::ParallelMesh(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::System::project_vector(), 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::System::read_header(), libMesh::System::read_legacy_data(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::System::read_serialized_data(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::MeshData::read_xdr(), libMesh::SerialMesh::semilocal_elements_begin(), libMesh::ParallelMesh::semilocal_elements_begin(), libMesh::SerialMesh::semilocal_elements_end(), libMesh::ParallelMesh::semilocal_elements_end(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::BoundaryInfo::sync(), libMesh::MeshTools::total_weight(), libMesh::ParallelMesh::update_parallel_id_counts(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::ExodusII_IO::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::System::write_header(), 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::ExodusII_IO_Helper::write_nodesets(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::System::write_parallel_data(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::System::write_serialized_data(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

  { return cast_int<processor_id_type>(_communicator.rank()); }
template<typename T >
void libMesh::PetscVector< T >::reciprocal ( ) [virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 158 of file petsc_vector.C.

References libMesh::ierr.

{
  PetscErrorCode ierr = 0;

  // VecReciprocal has been in PETSc since at least 2.3.3 days
  ierr = VecReciprocal(_vec);
  LIBMESH_CHKERRABORT(ierr);
}
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 448 of file petsc_vector.C.

References libMesh::GHOSTED.

{
  this->_restore_array();

  PetscErrorCode ierr = 0;
  PetscScalar factor = static_cast<PetscScalar>(factor_in);

  if(this->type() != GHOSTED)
    {
#if PETSC_VERSION_LESS_THAN(2,3,0)
      // 2.2.x & earlier style
      ierr = VecScale(&factor, _vec);
      LIBMESH_CHKERRABORT(ierr);
#else
      // 2.3.x & later style
      ierr = VecScale(_vec, factor);
      LIBMESH_CHKERRABORT(ierr);
#endif
    }
  else
    {
      Vec loc_vec;
      ierr = VecGhostGetLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);

#if PETSC_VERSION_LESS_THAN(2,3,0)
      // 2.2.x & earlier style
      ierr = VecScale(&factor, loc_vec);
      LIBMESH_CHKERRABORT(ierr);
#else
      // 2.3.x & later style
      ierr = VecScale(loc_vec, factor);
      LIBMESH_CHKERRABORT(ierr);
#endif

      ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
    }
}
template<typename T >
void libMesh::PetscVector< T >::set ( const numeric_index_type  i,
const T  value 
) [virtual]

v(i) = value

Implements libMesh::NumericVector< T >.

Definition at line 140 of file petsc_vector.C.

References libMesh::ierr.

{
  this->_restore_array();
  libmesh_assert_less (i, size());

  PetscErrorCode ierr=0;
  PetscInt i_val = static_cast<PetscInt>(i);
  PetscScalar petsc_value = static_cast<PetscScalar>(value);

  ierr = VecSetValues (_vec, 1, &i_val, &petsc_value, INSERT_VALUES);
  LIBMESH_CHKERRABORT(ierr);

  this->_is_closed = false;
}
template<typename T >
numeric_index_type libMesh::PetscVector< T >::size ( ) const [inline, virtual]
Returns:
dimension of the vector. This function was formerly called n(), but was renamed to get the PetscVector<T> class closer to the C++ standard library's std::vector container.

Implements libMesh::NumericVector< T >.

Definition at line 1067 of file petsc_vector.h.

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

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

{
  libmesh_assert (this->initialized());

  PetscErrorCode ierr=0;
  PetscInt petsc_size=0;

  if (!this->initialized())
    return 0;

  ierr = VecGetSize(_vec, &petsc_size);
  LIBMESH_CHKERRABORT(ierr);

  return static_cast<numeric_index_type>(petsc_size);
}
template<class T >
Real libMesh::NumericVector< T >::subset_l1_norm ( const std::set< numeric_index_type > &  indices) const [virtual, inherited]
Returns:
the $l_1$-norm of the vector, i.e. the sum of the absolute values for the specified entries in the vector.

Note that the indices must necessary live on this processor.

Definition at line 324 of file numeric_vector.C.

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

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

{
  const NumericVector<T> & v = *this;

  std::set<numeric_index_type>::const_iterator it = indices.begin();
  const std::set<numeric_index_type>::const_iterator it_end = indices.end();

  Real norm = 0;

  for(; it!=it_end; ++it)
    norm += std::abs(v(*it));

  this->comm().sum(norm);

  return norm;
}
template<class T >
Real libMesh::NumericVector< T >::subset_l2_norm ( const std::set< numeric_index_type > &  indices) const [virtual, inherited]
Returns:
the $l_2$-norm of the vector, i.e. the square root of the sum of the squares of the elements for the specified entries in the vector.

Note that the indices must necessary live on this processor.

Definition at line 342 of file numeric_vector.C.

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

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

{
  const NumericVector<T> & v = *this;

  std::set<numeric_index_type>::const_iterator it = indices.begin();
  const std::set<numeric_index_type>::const_iterator it_end = indices.end();

  Real norm = 0;

  for(; it!=it_end; ++it)
    norm += TensorTools::norm_sq(v(*it));

  this->comm().sum(norm);

  return std::sqrt(norm);
}
template<class T >
Real libMesh::NumericVector< T >::subset_linfty_norm ( const std::set< numeric_index_type > &  indices) const [virtual, inherited]
Returns:
the maximum absolute value of the specified entries of this vector, which is the $l_\infty$-norm of a vector.

Note that the indices must necessary live on this processor.

Definition at line 360 of file numeric_vector.C.

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

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

{
  const NumericVector<T> & v = *this;

  std::set<numeric_index_type>::const_iterator it = indices.begin();
  const std::set<numeric_index_type>::const_iterator it_end = indices.end();

  Real norm = 0;

  for(; it!=it_end; ++it)
    {
      Real value = std::abs(v(*it));
      if(value > norm)
        norm = value;
    }

  this->comm().max(norm);

  return norm;
}
template<typename T >
T libMesh::PetscVector< T >::sum ( ) const [virtual]
Returns:
the sum of values in a vector

Implements libMesh::NumericVector< T >.

Definition at line 43 of file petsc_vector.C.

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

{
  this->_restore_array();
  libmesh_assert(this->closed());

  PetscErrorCode ierr=0;
  PetscScalar value=0.;

  ierr = VecSum (_vec, &value);
  LIBMESH_CHKERRABORT(ierr);

  return static_cast<T>(value);
}
template<typename T >
void libMesh::PetscVector< T >::swap ( NumericVector< T > &  v) [inline, virtual]
template<typename T>
ParallelType& libMesh::NumericVector< T >::type ( ) [inline, inherited]
Returns:
the type (SERIAL, PARALLEL, GHOSTED) of the vector.

Definition at line 141 of file numeric_vector.h.

{ return _type; }
template<typename T>
Vec libMesh::PetscVector< T >::vec ( ) [inline]

Returns the raw PETSc vector context pointer. Note this is generally not required in user-level code. Just don't do anything crazy like calling LibMeshVecDestroy()!

Definition at line 509 of file petsc_vector.h.

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

Referenced by libMesh::PetscPreconditioner< T >::apply(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::PetscMatrix< T >::get_diagonal(), libMesh::SlepcEigenSolver< T >::get_eigenpair(), libMesh::PetscDiffSolver::solve(), and libMesh::PetscLinearSolver< T >::solve().

{ libmesh_assert (_vec); return _vec; }
template<typename T >
void libMesh::PetscVector< T >::zero ( ) [inline, virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 997 of file petsc_vector.h.

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

{
  libmesh_assert(this->closed());

  this->_restore_array();

  PetscErrorCode ierr=0;

  PetscScalar z=0.;

  if(this->type() != GHOSTED)
    {
#if PETSC_VERSION_LESS_THAN(2,3,0)
      // 2.2.x & earlier style
      ierr = VecSet (&z, _vec);
      LIBMESH_CHKERRABORT(ierr);
#else
      // 2.3.x & newer
      ierr = VecSet (_vec, z);
      LIBMESH_CHKERRABORT(ierr);
#endif
    }
  else
    {
      /* Vectors that include ghost values require a special
         handling.  */
      Vec loc_vec;
      ierr = VecGhostGetLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
#if PETSC_VERSION_LESS_THAN(2,3,0)
      // 2.2.x & earlier style
      ierr = VecSet (&z, loc_vec);
      LIBMESH_CHKERRABORT(ierr);
#else
      // 2.3.x & newer
      ierr = VecSet (loc_vec, z);
      LIBMESH_CHKERRABORT(ierr);
#endif
      ierr = VecGhostRestoreLocalForm (_vec,&loc_vec);
      LIBMESH_CHKERRABORT(ierr);
    }
}
template<typename T >
UniquePtr< NumericVector< T > > libMesh::PetscVector< T >::zero_clone ( ) const [inline, virtual]

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

Implements libMesh::NumericVector< T >.

Definition at line 1044 of file petsc_vector.h.

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

{
  NumericVector<T>* cloned_vector = new PetscVector<T>(this->comm(), this->type());
  cloned_vector->init(*this);
  return UniquePtr<NumericVector<T> >(cloned_vector);
}

Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
const NumericVector< T > &  v 
) [friend, inherited]

Same as above but allows you to use stream syntax.

Definition at line 633 of file numeric_vector.h.

  {
    v.print_global(os);
    return os;
  }

Member Data Documentation

template<typename T>
bool libMesh::PetscVector< T >::_array_is_present [mutable, private]

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

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

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

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

bool libMesh::ReferenceCounter::_enable_print_counter = true [static, protected, inherited]

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

Definition at line 137 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 [mutable, private]

First local index.

Only valid when _array_is_present

Definition at line 533 of file petsc_vector.h.

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

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

template<typename T>
bool libMesh::NumericVector< T >::_is_closed [protected, inherited]
template<typename T>
numeric_index_type libMesh::PetscVector< T >::_last [mutable, private]

Last local index.

Only valid when _array_is_present

Definition at line 540 of file petsc_vector.h.

template<typename T>
Vec libMesh::PetscVector< T >::_local_form [mutable, private]

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

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

template<typename T>
numeric_index_type libMesh::PetscVector< T >::_local_size [mutable, private]

Size of the local form, for being used in assertations. The contents of this field are only valid if the vector is ghosted and _array_is_present is true.

Definition at line 548 of file petsc_vector.h.

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 131 of file reference_counter.h.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects [static, protected, inherited]

The number of objects. Print the reference count information when the number returns to 0.

Definition at line 126 of file reference_counter.h.

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

template<typename T>
PetscScalar* libMesh::PetscVector< T >::_values [mutable, private]

Pointer to the actual Petsc array of the values of the vector. This pointer is only valid if _array_is_present is true.

Definition at line 562 of file petsc_vector.h.

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


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