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

This class provides a simple parallel, distributed vector datatype which is specific to libmesh. More...

#include <distributed_vector.h>

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

Public Member Functions

 DistributedVector (const Parallel::Communicator &comm, const ParallelType=AUTOMATIC)
 Dummy-Constructor. More...
 
 DistributedVector (const Parallel::Communicator &comm, const numeric_index_type n, const ParallelType ptype=AUTOMATIC)
 Constructor. More...
 
 DistributedVector (const Parallel::Communicator &comm, const numeric_index_type n, const numeric_index_type n_local, const ParallelType ptype=AUTOMATIC)
 Constructor. More...
 
 DistributedVector (const Parallel::Communicator &comm, const numeric_index_type N, const numeric_index_type n_local, const std::vector< numeric_index_type > &ghost, const ParallelType ptype=AUTOMATIC)
 Constructor. More...
 
DistributedVectoroperator= (const DistributedVector &)
 Copy assignment operator. More...
 
 DistributedVector (DistributedVector &&)=default
 The 5 special functions can be defaulted for this class, as it does not manage any memory itself. More...
 
 DistributedVector (const DistributedVector &)=default
 
DistributedVectoroperator= (DistributedVector &&)=default
 
virtual ~DistributedVector ()=default
 
virtual void close () override
 Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across processors. More...
 
virtual void clear () override
 Restores the NumericVector<T> to a pristine state. More...
 
virtual void zero () override
 Set all entries to zero. More...
 
virtual std::unique_ptr< NumericVector< T > > zero_clone () const override
 
virtual std::unique_ptr< NumericVector< T > > clone () const override
 
virtual void init (const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
 Change the dimension of the vector to N. More...
 
virtual void init (const numeric_index_type N, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
 Call init() with n_local = N. More...
 
virtual void init (const numeric_index_type N, const numeric_index_type n_local, const std::vector< numeric_index_type > &ghost, const bool fast=false, const ParallelType=AUTOMATIC) override
 Create a vector that holds tha local indices plus those specified in the ghost argument. More...
 
virtual void init (const NumericVector< T > &other, const bool fast=false) override
 Creates a vector that has the same dimension and storage type as other, including ghost dofs. More...
 
virtual NumericVector< T > & operator= (const T s) override
 Sets all entries of the vector to the value s. More...
 
virtual NumericVector< T > & operator= (const NumericVector< T > &v) override
 This looks like a copy assignment operator, but note that, unlike normal copy assignment operators, it is pure virtual. More...
 
virtual NumericVector< T > & operator= (const std::vector< T > &v) override
 Sets (*this)(i) = v(i) for each entry of the vector. More...
 
virtual Real min () const override
 
virtual Real max () const override
 
virtual T sum () const override
 
virtual Real l1_norm () const override
 
virtual Real l2_norm () const override
 
virtual Real linfty_norm () const override
 
virtual numeric_index_type size () const override
 
virtual numeric_index_type local_size () const override
 
virtual numeric_index_type first_local_index () const override
 
virtual numeric_index_type last_local_index () const override
 
virtual T operator() (const numeric_index_type i) const override
 
virtual NumericVector< T > & operator+= (const NumericVector< T > &v) override
 Adds v to *this, $ \vec{u} \leftarrow \vec{u} + \vec{v} $. More...
 
virtual NumericVector< T > & operator-= (const NumericVector< T > &v) override
 Subtracts v from *this, $ \vec{u} \leftarrow \vec{u} - \vec{v} $. More...
 
virtual NumericVector< T > & operator/= (const NumericVector< T > &v) override
 Computes the pointwise division of this vector's entries by another's, $ u_i \leftarrow \frac{u_i}{v_i} \, \forall i$. More...
 
virtual void reciprocal () override
 Computes the pointwise reciprocal, $ u_i \leftarrow \frac{1}{u_i} \, \forall i$. More...
 
virtual void conjugate () override
 Negates the imaginary component of each entry in the vector. More...
 
virtual void set (const numeric_index_type i, const T value) override
 Sets v(i) = value. More...
 
virtual void add (const numeric_index_type i, const T value) override
 Adds value to each entry of the vector. More...
 
virtual void add (const T s) override
 Adds s to each entry of the vector, $ u_i \leftarrow u_i + s $. More...
 
virtual void add (const NumericVector< T > &V) override
 Adds v to this, $ \vec{u} \leftarrow \vec{u} + \vec{v} $. More...
 
virtual void add (const T a, const NumericVector< T > &v) override
 Vector addition with a scalar multiple, $ \vec{u} \leftarrow \vec{u} + a\vec{v} $. More...
 
virtual void add_vector (const NumericVector< T > &, const SparseMatrix< T > &) override
 Computes $ \vec{u} \leftarrow \vec{u} + A \vec{v} $, i.e. More...
 
virtual void add_vector_transpose (const NumericVector< T > &, const SparseMatrix< T > &) override
 Computes $ \vec{u} \leftarrow \vec{u} + A^T \vec{v} $, i.e. More...
 
virtual void scale (const T factor) override
 Scale each element of the vector by the given factor. More...
 
virtual void abs () override
 Sets $ u_i \leftarrow |u_i| $ for each entry in the vector. More...
 
virtual T dot (const NumericVector< T > &V) const override
 
virtual void localize (std::vector< T > &v_local) const override
 Creates a copy of the global vector in the local vector v_local. More...
 
virtual void localize (NumericVector< T > &v_local) const override
 Same, but fills a NumericVector<T> instead of a std::vector. More...
 
virtual void localize (NumericVector< T > &v_local, const std::vector< numeric_index_type > &send_list) const override
 Creates a local vector v_local containing only information relevant to this processor, as defined by the send_list. More...
 
virtual void localize (std::vector< T > &v_local, const std::vector< numeric_index_type > &indices) const override
 
Fill in the local std::vector "v_local" with the global indices given in "indices". More...
 
virtual void localize (const numeric_index_type first_local_idx, const numeric_index_type last_local_idx, const std::vector< numeric_index_type > &send_list) override
 Updates a local vector with selected values from neighboring processors, as defined by send_list. More...
 
virtual void localize_to_one (std::vector< T > &v_local, const processor_id_type proc_id=0) const override
 Creates a local copy of the global vector in v_local only on processor proc_id. More...
 
virtual void pointwise_mult (const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
 Computes $ u_i \leftarrow u_i v_i $ (summation not implied) i.e. More...
 
virtual void swap (NumericVector< T > &v) override
 Swaps the contents of this with v. More...
 
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
 
virtual void get (const std::vector< numeric_index_type > &index, T *values) const
 Access multiple components at once. More...
 
void get (const std::vector< numeric_index_type > &index, std::vector< T > &values) const
 Access multiple components at once. More...
 
NumericVector< T > & operator*= (const T a)
 Scales the vector by a, $ \vec{u} \leftarrow a\vec{u} $. More...
 
NumericVector< T > & operator/= (const T a)
 Scales the vector by 1/a, $ \vec{u} \leftarrow \frac{1}{a}\vec{u} $. More...
 
virtual void add_vector (const T *v, const std::vector< numeric_index_type > &dof_indices)
 Computes $ \vec{u} \leftarrow \vec{u} + \vec{v} $, where v is a pointer and each dof_indices[i] specifies where to add value v[i]. More...
 
void add_vector (const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Computes $ \vec{u} \leftarrow \vec{u} + \vec{v} $, where v is a std::vector and each dof_indices[i] specifies where to add value v[i]. More...
 
virtual void add_vector (const NumericVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Computes $ \vec{u} \leftarrow \vec{u} + \vec{v} $, where v is a NumericVector and each dof_indices[i] specifies where to add value v(i). More...
 
void add_vector (const DenseVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Computes $ \vec{u} \leftarrow \vec{u} + \vec{v} $, where v is a DenseVector and each dof_indices[i] specifies where to add value v(i). More...
 
void add_vector (const NumericVector< T > &v, const ShellMatrix< T > &A)
 Computes $ \vec{u} \leftarrow \vec{u} + A \vec{v} $, i.e. More...
 
virtual void insert (const T *v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
void insert (const std::vector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
virtual void insert (const NumericVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
void insert (const DenseVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
void insert (const DenseSubVector< T > &v, const std::vector< numeric_index_type > &dof_indices)
 Inserts the entries of v in *this at the locations specified by v. More...
 
virtual int compare (const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
 
virtual int local_relative_compare (const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
 
virtual int global_relative_compare (const NumericVector< T > &other_vector, const Real threshold=TOLERANCE) const
 
virtual void print (std::ostream &os=libMesh::out) const
 Prints the local contents of the vector, by default to libMesh::out. More...
 
template<>
void print (std::ostream &os) const
 
virtual void print_global (std::ostream &os=libMesh::out) const
 Prints the global contents of the vector, by default to libMesh::out. More...
 
template<>
void print_global (std::ostream &os) const
 
virtual void print_matlab (const std::string &="") const
 Print the contents of the vector in Matlab's sparse matrix format. More...
 
virtual void create_subvector (NumericVector< T > &, const std::vector< numeric_index_type > &) const
 Fills in subvector from this vector using the indices in rows. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

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

Protected Types

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

Protected Member Functions

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

Protected Attributes

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

Static Protected Attributes

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

Private Attributes

std::vector< T > _values
 Actual vector datatype to hold vector entries. More...
 
numeric_index_type _global_size
 The global vector size. More...
 
numeric_index_type _local_size
 The local vector size. More...
 
numeric_index_type _first_local_index
 The first component stored locally. More...
 
numeric_index_type _last_local_index
 The last component (+1) stored locally. More...
 

Detailed Description

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

This class provides a simple parallel, distributed vector datatype which is specific to libmesh.

Offers some collective communication capabilities.

Note
The class will sill function without MPI, but only on one processor. All overridden virtual functions are documented in numeric_vector.h.
Author
Benjamin S. Kirk
Date
2003

Definition at line 52 of file distributed_vector.h.

Member Typedef Documentation

◆ Counts

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

Data structure to log the information.

The log is identified by the class name.

Definition at line 117 of file reference_counter.h.

Constructor & Destructor Documentation

◆ DistributedVector() [1/6]

template<typename T >
libMesh::DistributedVector< T >::DistributedVector ( const Parallel::Communicator comm,
const ParallelType  ptype = AUTOMATIC 
)
explicit

Dummy-Constructor.

Dimension=0

Definition at line 260 of file distributed_vector.h.

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

261  :
262  NumericVector<T>(comm_in, ptype),
263  _global_size (0),
264  _local_size (0),
267 {
268  this->_type = ptype;
269 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
numeric_index_type _global_size
The global vector size.
ParallelType _type
Type of vector.
numeric_index_type _local_size
The local vector size.
numeric_index_type _first_local_index
The first component stored locally.

◆ DistributedVector() [2/6]

template<typename T >
libMesh::DistributedVector< T >::DistributedVector ( const Parallel::Communicator comm,
const numeric_index_type  n,
const ParallelType  ptype = AUTOMATIC 
)
explicit

Constructor.

Set dimension to n and initialize all elements with zero.

Definition at line 275 of file distributed_vector.h.

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

278  : NumericVector<T>(comm_in, ptype)
279 {
280  this->init(n, n, false, ptype);
281 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
Change the dimension of the vector to N.

◆ DistributedVector() [3/6]

template<typename T >
libMesh::DistributedVector< T >::DistributedVector ( const Parallel::Communicator comm,
const numeric_index_type  n,
const numeric_index_type  n_local,
const ParallelType  ptype = AUTOMATIC 
)

Constructor.

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

Definition at line 287 of file distributed_vector.h.

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

291  : NumericVector<T>(comm_in, ptype)
292 {
293  this->init(n, n_local, false, ptype);
294 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
Change the dimension of the vector to N.

◆ DistributedVector() [4/6]

template<typename T >
libMesh::DistributedVector< T >::DistributedVector ( const Parallel::Communicator comm,
const numeric_index_type  N,
const numeric_index_type  n_local,
const std::vector< numeric_index_type > &  ghost,
const ParallelType  ptype = AUTOMATIC 
)

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 300 of file distributed_vector.h.

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

305  : NumericVector<T>(comm_in, ptype)
306 {
307  this->init(n, n_local, ghost, false, ptype);
308 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
Change the dimension of the vector to N.

◆ DistributedVector() [5/6]

template<typename T>
libMesh::DistributedVector< T >::DistributedVector ( DistributedVector< T > &&  )
default

The 5 special functions can be defaulted for this class, as it does not manage any memory itself.

◆ DistributedVector() [6/6]

template<typename T>
libMesh::DistributedVector< T >::DistributedVector ( const DistributedVector< T > &  )
default

◆ ~DistributedVector()

template<typename T>
virtual libMesh::DistributedVector< T >::~DistributedVector ( )
virtualdefault

Member Function Documentation

◆ abs()

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

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

Implements libMesh::NumericVector< T >.

◆ add() [1/4]

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

Adds value to each entry of the vector.

Implements libMesh::NumericVector< T >.

Definition at line 579 of file distributed_vector.h.

References libMesh::initialized().

580 {
581  libmesh_assert (this->initialized());
582  libmesh_assert_equal_to (_values.size(), _local_size);
583  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
584  libmesh_assert_less (i, size());
585  libmesh_assert_less (i-first_local_index(), local_size());
586 
587  _values[i - _first_local_index] += value;
588 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
virtual numeric_index_type local_size() const override
virtual numeric_index_type size() const override
numeric_index_type _local_size
The local vector size.
virtual numeric_index_type first_local_index() const override
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ add() [2/4]

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

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

Implements libMesh::NumericVector< T >.

◆ add() [3/4]

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

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

Equivalent to calling operator+=().

Implements libMesh::NumericVector< T >.

◆ add() [4/4]

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

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

Equivalent to calling operator+=().

Implements libMesh::NumericVector< T >.

◆ add_vector() [1/6]

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

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

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

Implements libMesh::NumericVector< T >.

Definition at line 191 of file distributed_vector.h.

193  { libmesh_not_implemented(); }

◆ add_vector() [2/6]

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

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

This should be overridden in subclasses for efficiency.

Reimplemented in libMesh::PetscVector< T >, and libMesh::EpetraVector< T >.

◆ add_vector() [3/6]

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

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

Definition at line 829 of file numeric_vector.h.

831 {
832  libmesh_assert(v.size() == dof_indices.size());
833  if (!v.empty())
834  this->add_vector(&v[0], dof_indices);
835 }
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i]...

◆ add_vector() [4/6]

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

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

◆ add_vector() [5/6]

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

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

Definition at line 841 of file numeric_vector.h.

843 {
844  libmesh_assert(v.size() == dof_indices.size());
845  if (!v.empty())
846  this->add_vector(&v(0), dof_indices);
847 }
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i]...

◆ add_vector() [6/6]

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

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

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

◆ add_vector_transpose()

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

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

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

Implements libMesh::NumericVector< T >.

Definition at line 195 of file distributed_vector.h.

197  { libmesh_not_implemented(); }

◆ build()

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

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

◆ clear()

template<typename T >
void libMesh::DistributedVector< T >::clear ( )
overridevirtual

Restores the NumericVector<T> to a pristine state.

Reimplemented from libMesh::NumericVector< T >.

Definition at line 442 of file distributed_vector.h.

443 {
444  _values.clear();
445 
446  _global_size =
447  _local_size =
449  _last_local_index = 0;
450 
451 
452  this->_is_closed = this->_is_initialized = false;
453 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
bool _is_initialized
true once init() has been called.
numeric_index_type _global_size
The global vector size.
numeric_index_type _local_size
The local vector size.
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.
bool _is_closed
Flag which tracks whether the vector&#39;s values are consistent on all processors after insertion or add...

◆ clone()

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

Implements libMesh::NumericVector< T >.

Definition at line 485 of file distributed_vector.h.

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

486 {
487  NumericVector<T> * cloned_vector = new DistributedVector<T>(this->comm());
488  cloned_vector->init(*this, true);
489  *cloned_vector = *this;
490  return std::unique_ptr<NumericVector<T>>(cloned_vector);
491 }
const Parallel::Communicator & comm() const

◆ close()

template<typename T >
void libMesh::DistributedVector< T >::close ( )
overridevirtual

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

Implements libMesh::NumericVector< T >.

Definition at line 431 of file distributed_vector.h.

References libMesh::initialized().

432 {
433  libmesh_assert (this->initialized());
434 
435  this->_is_closed = true;
436 }
virtual bool initialized() const
bool _is_closed
Flag which tracks whether the vector&#39;s values are consistent on all processors after insertion or add...

◆ closed()

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

Definition at line 159 of file numeric_vector.h.

159 { return _is_closed; }
bool _is_closed
Flag which tracks whether the vector&#39;s values are consistent on all processors after insertion or add...

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited

◆ compare()

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

◆ conjugate()

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

Negates the imaginary component of each entry in the vector.

Implements libMesh::NumericVector< T >.

◆ create_subvector()

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

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

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

Reimplemented in libMesh::PetscVector< T >, and libMesh::EpetraVector< T >.

Definition at line 686 of file numeric_vector.h.

688  {
689  libmesh_not_implemented();
690  }

◆ disable_print_counter_info()

static void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

◆ dot()

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

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

Implements libMesh::NumericVector< T >.

◆ el()

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

Definition at line 340 of file numeric_vector.h.

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

◆ enable_print_counter_info()

static void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

◆ first_local_index()

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

Implements libMesh::NumericVector< T >.

Definition at line 523 of file distributed_vector.h.

References libMesh::initialized().

524 {
525  libmesh_assert (this->initialized());
526  libmesh_assert_equal_to (_values.size(), _local_size);
527  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
528 
529  return _first_local_index;
530 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
numeric_index_type _local_size
The local vector size.
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ get() [1/2]

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

Access multiple components at once.

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

Reimplemented in libMesh::PetscVector< T >.

Definition at line 800 of file numeric_vector.h.

802 {
803  const std::size_t num = index.size();
804  for (std::size_t i=0; i<num; i++)
805  {
806  values[i] = (*this)(index[i]);
807  }
808 }

◆ get() [2/2]

template<typename T>
void libMesh::NumericVector< T >::get ( const std::vector< numeric_index_type > &  index,
std::vector< T > &  values 
) const
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 814 of file numeric_vector.h.

816 {
817  const std::size_t num = index.size();
818  values.resize(num);
819  if (!num)
820  return;
821 
822  this->get(index, &values[0]);
823 }

◆ get_info()

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

Gets a string containing the reference information.

◆ global_relative_compare()

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

◆ increment_constructor_count()

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

Increments the construction counter.

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

Definition at line 181 of file reference_counter.h.

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

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

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ increment_destructor_count()

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

Increments the destruction counter.

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

Definition at line 194 of file reference_counter.h.

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

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

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ init() [1/4]

template<typename T >
void libMesh::DistributedVector< T >::init ( const numeric_index_type  ,
const numeric_index_type  ,
const bool  = false,
const ParallelType  = AUTOMATIC 
)
overridevirtual

Change the dimension of the vector to N.

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

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

Implements libMesh::NumericVector< T >.

Definition at line 314 of file distributed_vector.h.

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

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

318 {
319  // This function must be run on all processors at once
320  parallel_object_only();
321 
322  libmesh_assert_less_equal (n_local, n);
323 
324  if (ptype == AUTOMATIC)
325  {
326  if (n == n_local)
327  this->_type = SERIAL;
328  else
329  this->_type = PARALLEL;
330  }
331  else
332  this->_type = ptype;
333 
334  libmesh_assert ((this->_type==SERIAL && n==n_local) ||
335  this->_type==PARALLEL);
336 
337  // Clear the data structures if already initialized
338  if (this->initialized())
339  this->clear();
340 
341  // Initialize data structures
342  _values.resize(n_local);
343  _local_size = n_local;
344  _global_size = n;
345 
346  _first_local_index = 0;
347 
348 #ifdef LIBMESH_HAVE_MPI
349 
350  std::vector<numeric_index_type> local_sizes (this->n_processors(), 0);
351 
352  local_sizes[this->processor_id()] = n_local;
353 
354  this->comm().sum(local_sizes);
355 
356  // _first_local_index is the sum of _local_size
357  // for all processor ids less than ours
358  for (processor_id_type p=0; p!=this->processor_id(); p++)
359  _first_local_index += local_sizes[p];
360 
361 
362 # ifdef DEBUG
363  // Make sure all the local sizes sum up to the global
364  // size, otherwise there is big trouble!
365  numeric_index_type dbg_sum=0;
366 
367  for (processor_id_type p=0; p!=this->n_processors(); p++)
368  dbg_sum += local_sizes[p];
369 
370  libmesh_assert_equal_to (dbg_sum, n);
371 
372 # endif
373 
374 #else
375 
376  // No other options without MPI!
377  if (n != n_local)
378  libmesh_error_msg("ERROR: MPI is required for n != n_local!");
379 
380 #endif
381 
383 
384  // Set the initialized flag
385  this->_is_initialized = true;
386 
387  // Zero the components unless directed otherwise
388  if (!fast)
389  this->zero();
390 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
uint8_t processor_id_type
Definition: id_types.h:99
const Parallel::Communicator & comm() const
bool _is_initialized
true once init() has been called.
numeric_index_type _global_size
The global vector size.
virtual void zero() override
Set all entries to zero.
processor_id_type n_processors() const
dof_id_type numeric_index_type
Definition: id_types.h:92
void sum(T &r) const
Take a local variable and replace it with the sum of it&#39;s values on all processors.
ParallelType _type
Type of vector.
numeric_index_type _local_size
The local vector size.
virtual void clear() override
Restores the NumericVector<T> to a pristine state.
std::vector< T > _values
Actual vector datatype to hold vector entries.
processor_id_type processor_id() const
numeric_index_type _first_local_index
The first component stored locally.

◆ init() [2/4]

template<typename T >
void libMesh::DistributedVector< T >::init ( const numeric_index_type  ,
const bool  = false,
const ParallelType  = AUTOMATIC 
)
overridevirtual

Call init() with n_local = N.

Implements libMesh::NumericVector< T >.

Definition at line 420 of file distributed_vector.h.

References libMesh::TriangleWrapper::init().

423 {
424  this->init(n,n,fast,ptype);
425 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
Change the dimension of the vector to N.

◆ init() [3/4]

template<typename T >
void libMesh::DistributedVector< T >::init ( const numeric_index_type  ,
const numeric_index_type  ,
const std::vector< numeric_index_type > &  ,
const bool  = false,
const ParallelType  = AUTOMATIC 
)
overridevirtual

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

Implements libMesh::NumericVector< T >.

Definition at line 395 of file distributed_vector.h.

References libMesh::TriangleWrapper::init().

400 {
401  // TODO: we shouldn't ignore the ghost sparsity pattern
402  this->init(n, n_local, fast, ptype);
403 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
Change the dimension of the vector to N.

◆ init() [4/4]

template<class T >
void libMesh::DistributedVector< T >::init ( const NumericVector< T > &  other,
const bool  fast = false 
)
overridevirtual

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

Implements libMesh::NumericVector< T >.

Definition at line 410 of file distributed_vector.h.

References libMesh::TriangleWrapper::init(), libMesh::NumericVector< T >::local_size(), libMesh::NumericVector< T >::size(), and libMesh::NumericVector< T >::type().

412 {
413  this->init(other.size(),other.local_size(),fast,other.type());
414 }
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
Change the dimension of the vector to N.

◆ initialized()

template<typename T>
virtual bool libMesh::NumericVector< T >::initialized ( ) const
virtualinherited
Returns
true if the vector has been initialized, false otherwise.

Definition at line 143 of file numeric_vector.h.

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

143 { return _is_initialized; }
bool _is_initialized
true once init() has been called.

◆ insert() [1/5]

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

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

Reimplemented in libMesh::PetscVector< T >, and libMesh::EpetraVector< T >.

◆ insert() [2/5]

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

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

Definition at line 853 of file numeric_vector.h.

855 {
856  libmesh_assert(v.size() == dof_indices.size());
857  if (!v.empty())
858  this->insert(&v[0], dof_indices);
859 }
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
Inserts the entries of v in *this at the locations specified by v.

◆ insert() [3/5]

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

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

◆ insert() [4/5]

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

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

Definition at line 865 of file numeric_vector.h.

867 {
868  libmesh_assert(v.size() == dof_indices.size());
869  if (!v.empty())
870  this->insert(&v(0), dof_indices);
871 }
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
Inserts the entries of v in *this at the locations specified by v.

◆ insert() [5/5]

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

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

Definition at line 877 of file numeric_vector.h.

879 {
880  libmesh_assert(v.size() == dof_indices.size());
881  if (!v.empty())
882  this->insert(&v(0), dof_indices);
883 }
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
Inserts the entries of v in *this at the locations specified by v.

◆ l1_norm()

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

Implements libMesh::NumericVector< T >.

◆ l2_norm()

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

Implements libMesh::NumericVector< T >.

◆ last_local_index()

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

Implements libMesh::NumericVector< T >.

Definition at line 536 of file distributed_vector.h.

References libMesh::initialized().

537 {
538  libmesh_assert (this->initialized());
539  libmesh_assert_equal_to (_values.size(), _local_size);
540  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
541 
542  return _last_local_index;
543 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
numeric_index_type _local_size
The local vector size.
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ linfty_norm()

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

Implements libMesh::NumericVector< T >.

◆ local_relative_compare()

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

◆ local_size()

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

Implements libMesh::NumericVector< T >.

Definition at line 510 of file distributed_vector.h.

References libMesh::initialized().

511 {
512  libmesh_assert (this->initialized());
513  libmesh_assert_equal_to (_values.size(), _local_size);
514  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
515 
516  return _local_size;
517 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
numeric_index_type _local_size
The local vector size.
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ localize() [1/5]

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

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

Implements libMesh::NumericVector< T >.

◆ localize() [2/5]

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

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

Implements libMesh::NumericVector< T >.

◆ localize() [3/5]

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

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

Implements libMesh::NumericVector< T >.

◆ localize() [4/5]

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


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

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

Example:

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

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

Implements libMesh::NumericVector< T >.

◆ localize() [5/5]

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

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

Implements libMesh::NumericVector< T >.

◆ localize_to_one()

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

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

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

Implements libMesh::NumericVector< T >.

◆ max()

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

Implements libMesh::NumericVector< T >.

Definition at line 617 of file distributed_vector.h.

References libMesh::initialized(), libMesh::libmesh_real(), std::max(), and libMesh::Real.

618 {
619  // This function must be run on all processors at once
620  parallel_object_only();
621 
622  libmesh_assert (this->initialized());
623  libmesh_assert_equal_to (_values.size(), _local_size);
624  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
625 
626  Real local_max = _values.size() ?
627  libmesh_real(_values[0]) : -std::numeric_limits<Real>::max();
628  for (numeric_index_type i = 1; i < _values.size(); ++i)
629  local_max = std::max(libmesh_real(_values[i]), local_max);
630 
631  this->comm().max(local_max);
632 
633  return local_max;
634 }
T libmesh_real(T a)
virtual Real max() const override
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
const Parallel::Communicator & comm() const
long double max(long double a, double b)
dof_id_type numeric_index_type
Definition: id_types.h:92
numeric_index_type _local_size
The local vector size.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ min()

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

Implements libMesh::NumericVector< T >.

Definition at line 594 of file distributed_vector.h.

References libMesh::initialized(), libMesh::libmesh_real(), std::max(), std::min(), and libMesh::Real.

595 {
596  // This function must be run on all processors at once
597  parallel_object_only();
598 
599  libmesh_assert (this->initialized());
600  libmesh_assert_equal_to (_values.size(), _local_size);
601  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
602 
603  Real local_min = _values.size() ?
604  libmesh_real(_values[0]) : std::numeric_limits<Real>::max();
605  for (numeric_index_type i = 1; i < _values.size(); ++i)
606  local_min = std::min(libmesh_real(_values[i]), local_min);
607 
608  this->comm().min(local_min);
609 
610  return local_min;
611 }
T libmesh_real(T a)
virtual Real max() const override
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
void min(T &r) const
Take a local variable and replace it with the minimum of it&#39;s values on all processors.
const Parallel::Communicator & comm() const
dof_id_type numeric_index_type
Definition: id_types.h:92
numeric_index_type _local_size
The local vector size.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< T > _values
Actual vector datatype to hold vector entries.
long double min(long double a, double b)
numeric_index_type _first_local_index
The first component stored locally.

◆ n_objects()

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

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

Definition at line 83 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

84  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ n_processors()

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

Definition at line 93 of file parallel_object.h.

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

Referenced by libMesh::MeshBase::partition().

94  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ operator()()

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

Implements libMesh::NumericVector< T >.

Definition at line 549 of file distributed_vector.h.

References libMesh::initialized().

550 {
551  libmesh_assert (this->initialized());
552  libmesh_assert_equal_to (_values.size(), _local_size);
553  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
554  libmesh_assert ( ((i >= first_local_index()) &&
555  (i < last_local_index())) );
556 
557  return _values[i - _first_local_index];
558 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
virtual numeric_index_type last_local_index() const override
numeric_index_type _local_size
The local vector size.
virtual numeric_index_type first_local_index() const override
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ operator*=()

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

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

Equivalent to u.scale(a)

Returns
A reference to *this.

Definition at line 385 of file numeric_vector.h.

385 { this->scale(a); return *this; }
virtual void scale(const T factor)=0
Scale each element of the vector by the given factor.

◆ operator+=()

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

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

Equivalent to u.add(1, v).

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

◆ operator-=()

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

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

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

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

◆ operator/=() [1/2]

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

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

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

◆ operator/=() [2/2]

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

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

Equivalent to u.scale(1./a)

Returns
A reference to *this.

Definition at line 394 of file numeric_vector.h.

394 { this->scale(1./a); return *this; }
virtual void scale(const T factor)=0
Scale each element of the vector by the given factor.

◆ operator=() [1/5]

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

Copy assignment operator.

We cannot default this (although it essentially implements the default behavior) because the compiler-generated default attempts to automatically call the base class (NumericVector) copy assignment operator, which we have chosen to make pure virtual for other design reasons.

◆ operator=() [2/5]

template<typename T>
DistributedVector& libMesh::DistributedVector< T >::operator= ( DistributedVector< T > &&  )
default

◆ operator=() [3/5]

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

Sets all entries of the vector to the value s.

Returns
A reference to *this.

Implements libMesh::NumericVector< T >.

◆ operator=() [4/5]

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

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

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

Returns
A reference to *this as the base type.

Implements libMesh::NumericVector< T >.

◆ operator=() [5/5]

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

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

Returns
A reference to *this as the base type.

Implements libMesh::NumericVector< T >.

◆ pointwise_mult()

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

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

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

Implements libMesh::NumericVector< T >.

◆ print() [1/2]

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

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

Definition at line 910 of file numeric_vector.h.

911 {
912  libmesh_assert (this->initialized());
913  os << "Size\tglobal = " << this->size()
914  << "\t\tlocal = " << this->local_size() << std::endl;
915 
916  os << "#\tValue" << std::endl;
917  for (numeric_index_type i=this->first_local_index(); i<this->last_local_index(); i++)
918  os << i << "\t" << (*this)(i) << std::endl;
919 }
virtual bool initialized() const
virtual numeric_index_type size() const =0
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual numeric_index_type first_local_index() const =0
virtual numeric_index_type local_size() const =0
virtual numeric_index_type last_local_index() const =0

◆ print() [2/2]

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

Definition at line 892 of file numeric_vector.h.

893 {
894  libmesh_assert (this->initialized());
895  os << "Size\tglobal = " << this->size()
896  << "\t\tlocal = " << this->local_size() << std::endl;
897 
898  // std::complex<>::operator<<() is defined, but use this form
899  os << "#\tReal part\t\tImaginary part" << std::endl;
900  for (numeric_index_type i=this->first_local_index(); i<this->last_local_index(); i++)
901  os << i << "\t"
902  << (*this)(i).real() << "\t\t"
903  << (*this)(i).imag() << std::endl;
904 }
virtual bool initialized() const
virtual numeric_index_type size() const =0
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual numeric_index_type first_local_index() const =0
virtual numeric_index_type local_size() const =0
virtual numeric_index_type last_local_index() const =0

◆ print_global() [1/2]

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

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

Definition at line 947 of file numeric_vector.h.

948 {
949  libmesh_assert (this->initialized());
950 
951  std::vector<T> v(this->size());
952  this->localize(v);
953 
954  // Right now we only want one copy of the output
955  if (this->processor_id())
956  return;
957 
958  os << "Size\tglobal = " << this->size() << std::endl;
959  os << "#\tValue" << std::endl;
960  for (numeric_index_type i=0; i!=v.size(); i++)
961  os << i << "\t" << v[i] << std::endl;
962 }
virtual bool initialized() const
virtual numeric_index_type size() const =0
dof_id_type numeric_index_type
Definition: id_types.h:92
processor_id_type processor_id() const
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.

◆ print_global() [2/2]

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

Definition at line 925 of file numeric_vector.h.

926 {
927  libmesh_assert (this->initialized());
928 
929  std::vector<Complex> v(this->size());
930  this->localize(v);
931 
932  // Right now we only want one copy of the output
933  if (this->processor_id())
934  return;
935 
936  os << "Size\tglobal = " << this->size() << std::endl;
937  os << "#\tReal part\t\tImaginary part" << std::endl;
938  for (numeric_index_type i=0; i!=v.size(); i++)
939  os << i << "\t"
940  << v[i].real() << "\t\t"
941  << v[i].imag() << std::endl;
942 }
virtual bool initialized() const
virtual numeric_index_type size() const =0
dof_id_type numeric_index_type
Definition: id_types.h:92
processor_id_type processor_id() const
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.

◆ print_info()

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

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

◆ print_matlab()

template<typename T>
virtual void libMesh::NumericVector< T >::print_matlab ( const std::string &  = "") const
virtualinherited

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

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

Reimplemented in libMesh::PetscVector< T >.

Definition at line 675 of file numeric_vector.h.

676  {
677  libmesh_not_implemented();
678  }

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited

◆ reciprocal()

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

Computes the pointwise reciprocal, $ u_i \leftarrow \frac{1}{u_i} \, \forall i$.

Implements libMesh::NumericVector< T >.

◆ scale()

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

Scale each element of the vector by the given factor.

Implements libMesh::NumericVector< T >.

◆ set()

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

Sets v(i) = value.

Implements libMesh::NumericVector< T >.

Definition at line 564 of file distributed_vector.h.

References libMesh::initialized().

565 {
566  libmesh_assert (this->initialized());
567  libmesh_assert_equal_to (_values.size(), _local_size);
568  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
569  libmesh_assert_less (i, size());
570  libmesh_assert_less (i-first_local_index(), local_size());
571 
572  _values[i - _first_local_index] = value;
573 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
virtual numeric_index_type local_size() const override
virtual numeric_index_type size() const override
numeric_index_type _local_size
The local vector size.
virtual numeric_index_type first_local_index() const override
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ size()

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

Implements libMesh::NumericVector< T >.

Definition at line 497 of file distributed_vector.h.

References libMesh::initialized().

498 {
499  libmesh_assert (this->initialized());
500  libmesh_assert_equal_to (_values.size(), _local_size);
501  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
502 
503  return _global_size;
504 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
numeric_index_type _global_size
The global vector size.
numeric_index_type _local_size
The local vector size.
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ subset_l1_norm()

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

◆ subset_l2_norm()

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

◆ subset_linfty_norm()

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

◆ sum()

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

Implements libMesh::NumericVector< T >.

◆ swap()

template<typename T >
void libMesh::DistributedVector< T >::swap ( NumericVector< T > &  v)
overridevirtual

Swaps the contents of this with v.

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

Reimplemented from libMesh::NumericVector< T >.

Definition at line 639 of file distributed_vector.h.

References libMesh::DistributedVector< T >::_first_local_index, libMesh::DistributedVector< T >::_global_size, libMesh::DistributedVector< T >::_last_local_index, libMesh::DistributedVector< T >::_local_size, libMesh::DistributedVector< T >::_values, and swap().

640 {
641  DistributedVector<T> & v = cast_ref<DistributedVector<T> &>(other);
642 
643  std::swap(_global_size, v._global_size);
644  std::swap(_local_size, v._local_size);
645  std::swap(_first_local_index, v._first_local_index);
646  std::swap(_last_local_index, v._last_local_index);
647 
648  // This should be O(1) with any reasonable STL implementation
649  std::swap(_values, v._values);
650 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
numeric_index_type _global_size
The global vector size.
numeric_index_type _local_size
The local vector size.
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ type() [1/2]

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

Definition at line 148 of file numeric_vector.h.

Referenced by libMesh::EpetraVector< T >::EpetraVector(), libMesh::DistributedVector< T >::init(), libMesh::EigenSparseVector< T >::init(), libMesh::LaspackVector< T >::init(), and libMesh::EpetraVector< T >::init().

148 { return _type; }
ParallelType _type
Type of vector.

◆ type() [2/2]

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

Definition at line 153 of file numeric_vector.h.

153 { return _type; }
ParallelType _type
Type of vector.

◆ zero()

template<typename T >
void libMesh::DistributedVector< T >::zero ( )
overridevirtual

Set all entries to zero.

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

Implements libMesh::NumericVector< T >.

Definition at line 459 of file distributed_vector.h.

References libMesh::initialized().

460 {
461  libmesh_assert (this->initialized());
462  libmesh_assert_equal_to (_values.size(), _local_size);
463  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
464 
465  std::fill (_values.begin(),
466  _values.end(),
467  0.);
468 }
numeric_index_type _last_local_index
The last component (+1) stored locally.
virtual bool initialized() const
numeric_index_type _local_size
The local vector size.
std::vector< T > _values
Actual vector datatype to hold vector entries.
numeric_index_type _first_local_index
The first component stored locally.

◆ zero_clone()

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

Implements libMesh::NumericVector< T >.

Definition at line 474 of file distributed_vector.h.

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

475 {
476  NumericVector<T> * cloned_vector = new DistributedVector<T>(this->comm());
477  cloned_vector->init(*this);
478  return std::unique_ptr<NumericVector<T>>(cloned_vector);
479 }
const Parallel::Communicator & comm() const

Member Data Documentation

◆ _communicator

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

◆ _counts

Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter
staticprotectedinherited

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

Definition at line 141 of file reference_counter.h.

◆ _first_local_index

template<typename T>
numeric_index_type libMesh::DistributedVector< T >::_first_local_index
private

The first component stored locally.

Definition at line 247 of file distributed_vector.h.

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

◆ _global_size

template<typename T>
numeric_index_type libMesh::DistributedVector< T >::_global_size
private

The global vector size.

Definition at line 237 of file distributed_vector.h.

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

◆ _is_closed

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

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

Definition at line 706 of file numeric_vector.h.

Referenced by libMesh::NumericVector< Number >::closed(), libMesh::EpetraVector< T >::EpetraVector(), and libMesh::PetscVector< T >::PetscVector().

◆ _is_initialized

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

◆ _last_local_index

template<typename T>
numeric_index_type libMesh::DistributedVector< T >::_last_local_index
private

The last component (+1) stored locally.

Definition at line 252 of file distributed_vector.h.

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

◆ _local_size

template<typename T>
numeric_index_type libMesh::DistributedVector< T >::_local_size
private

The local vector size.

Definition at line 242 of file distributed_vector.h.

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

◆ _mutex

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

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

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

The number of objects.

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

Definition at line 130 of file reference_counter.h.

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

◆ _type

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

◆ _values

template<typename T>
std::vector<T> libMesh::DistributedVector< T >::_values
private

Actual vector datatype to hold vector entries.

Definition at line 232 of file distributed_vector.h.

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


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