Go to the documentation of this file.
18 #ifndef LIBMESH_TRILINOS_EPETRA_VECTOR_H
19 #define LIBMESH_TRILINOS_EPETRA_VECTOR_H
22 #include "libmesh/libmesh_common.h"
24 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
27 #include "libmesh/numeric_vector.h"
28 #include "libmesh/parallel.h"
29 #include "libmesh/auto_ptr.h"
32 #include "libmesh/ignore_warnings.h"
33 #include <Epetra_CombineMode.h>
34 #include <Epetra_Map.h>
35 #include <Epetra_MultiVector.h>
36 #include <Epetra_Vector.h>
37 #include <Epetra_MpiComm.h>
38 #include "libmesh/restore_warnings.h"
45 class Epetra_IntSerialDenseVector;
46 class Epetra_SerialDenseVector;
52 template <
typename T>
class SparseMatrix;
99 const std::vector<numeric_index_type> & ghost,
110 const Parallel::Communicator &
comm);
123 virtual void close ()
override;
125 virtual void clear ()
override;
127 virtual void zero ()
override;
129 virtual std::unique_ptr<NumericVector<T>>
zero_clone ()
const override;
131 virtual std::unique_ptr<NumericVector<T>>
clone ()
const override;
135 const bool fast=
false,
139 const bool fast=
false,
144 const std::vector<numeric_index_type> & ghost,
145 const bool fast =
false,
149 const bool fast =
false)
override;
157 virtual Real min ()
const override;
159 virtual Real max ()
const override;
161 virtual T
sum ()
const override;
195 virtual void add (
const T s)
override;
208 const std::vector<numeric_index_type> & dof_indices)
override;
222 virtual void insert (
const T * v,
223 const std::vector<numeric_index_type> & dof_indices)
override;
225 virtual void scale (
const T factor)
override;
227 virtual void abs()
override;
231 virtual void localize (std::vector<T> & v_local)
const override;
236 const std::vector<numeric_index_type> & send_list)
const override;
238 virtual void localize (std::vector<T> & v_local,
239 const std::vector<numeric_index_type> & indices)
const override;
243 const std::vector<numeric_index_type> & send_list)
override;
252 const std::vector<numeric_index_type> & rows)
const override;
276 std::unique_ptr<Epetra_Map>
_map;
295 const double * values);
308 const Epetra_SerialDenseVector & values);
316 const double * values);
329 const Epetra_SerialDenseVector & values);
333 const int * numValuesPerID,
334 const double * values);
338 const int * numValuesPerID,
339 const double * values);
362 const double * values,
367 const int * numValuesPerID,
368 const double * values,
377 const double * values,
407 template <
typename T>
412 _destroy_vec_on_exit(true),
416 nonlocalIDs_(nullptr),
417 nonlocalElementSize_(nullptr),
419 allocatedNonlocalLength_(0),
420 nonlocalCoefs_(nullptr),
422 ignoreNonLocalEntries_(false)
429 template <
typename T>
435 _destroy_vec_on_exit(true),
439 nonlocalIDs_(nullptr),
440 nonlocalElementSize_(nullptr),
442 allocatedNonlocalLength_(0),
443 nonlocalCoefs_(nullptr),
445 ignoreNonLocalEntries_(false)
453 template <
typename T>
460 _destroy_vec_on_exit(true),
464 nonlocalIDs_(nullptr),
465 nonlocalElementSize_(nullptr),
467 allocatedNonlocalLength_(0),
468 nonlocalCoefs_(nullptr),
470 ignoreNonLocalEntries_(false)
472 this->
init(n, n_local,
false,
type);
478 template <
typename T>
481 const Parallel::Communicator & comm) :
483 _destroy_vec_on_exit(false),
487 nonlocalIDs_(nullptr),
488 nonlocalElementSize_(nullptr),
490 allocatedNonlocalLength_(0),
491 nonlocalCoefs_(nullptr),
493 ignoreNonLocalEntries_(false)
502 _map = libmesh_make_unique<Epetra_Map>
503 (
_vec->GlobalLength(),
506 Epetra_MpiComm (this->
comm().
get()));
519 template <
typename T>
524 const std::vector<numeric_index_type> & ghost,
527 _destroy_vec_on_exit(true),
531 nonlocalIDs_(nullptr),
532 nonlocalElementSize_(nullptr),
534 allocatedNonlocalLength_(0),
535 nonlocalCoefs_(nullptr),
537 ignoreNonLocalEntries_(false)
539 this->
init(n, n_local, ghost,
false,
type);
555 template <
typename T>
564 template <
typename T>
595 _map = libmesh_make_unique<Epetra_Map>
596 (static_cast<int>(n),
599 Epetra_MpiComm (this->comm().
get()));
601 _vec =
new Epetra_Vector(*_map);
603 myFirstID_ = _vec->Map().MinMyGID();
604 myNumIDs_ = _vec->Map().NumMyElements();
609 _vec->ExtractView(&myCoefs_, &dummy);
612 this->_is_closed =
true;
620 template <
typename T>
624 const std::vector<numeric_index_type> & ,
629 this->
init(n, n_local, fast, type);
634 template <
typename T>
640 this->
init(n,n,fast,type);
645 template <
typename T>
652 unsigned char global_last_edit = last_edit;
653 this->comm().max(global_last_edit);
656 if (global_last_edit == 1)
657 this->GlobalAssemble(Insert);
658 else if (global_last_edit == 2)
659 this->GlobalAssemble(Add);
663 this->_is_closed =
true;
669 template <
typename T>
676 if (this->_destroy_vec_on_exit)
691 template <
typename T>
698 _vec->PutScalar(0.0);
703 template <
typename T>
708 cloned_vector->
init(*
this);
709 return std::unique_ptr<NumericVector<T>>(cloned_vector);
714 template <
typename T>
719 cloned_vector->
init(*
this,
true);
720 *cloned_vector = *
this;
721 return std::unique_ptr<NumericVector<T>>(cloned_vector);
726 template <
typename T>
732 return _vec->GlobalLength();
737 template <
typename T>
743 return _vec->MyLength();
746 template <
typename T>
752 return _vec->Map().MinMyGID();
757 template <
typename T>
763 return _vec->Map().MaxMyGID()+1;
767 template <
typename T>
773 (i < this->last_local_index())) );
775 return (*_vec)[i-this->first_local_index()];
780 template <
typename T>
788 _vec->MinValue(&
value);
795 template <
typename T>
803 _vec->MaxValue(&
value);
810 template <
typename T>
838 return reinterpret_cast<int *>(const_cast<numeric_index_type *>(p));
844 #endif // #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
845 #endif // LIBMESH_TRILINOS_EPETRA_VECTOR_H
virtual NumericVector< T > & operator*=(const NumericVector< T > &v) override
Computes the component-wise multiplication of this vector's entries by another's, .
virtual std::unique_ptr< NumericVector< T > > zero_clone() const override
virtual numeric_index_type last_local_index() const override
int allocatedNonlocalLength_
virtual NumericVector< T > & operator-=(const NumericVector< T > &v) override
Subtracts v from *this, .
int * nonlocalElementSize_
void destroyNonlocalData()
int inputValues(int numIDs, const int *GIDs, const double *values, bool accumulate)
void FEoperatorequals(const EpetraVector &source)
int SumIntoGlobalValues(int numIDs, const int *GIDs, const double *values)
Accumulate values into the vector, adding them to any values that already exist for the specified ind...
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v.
virtual void create_subvector(NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows) const override
Fills in subvector from this vector using the indices in rows.
virtual void conjugate() override
Negates the imaginary component of each entry in the vector.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void zero() override
Set all entries to zero.
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
const Parallel::Communicator & comm() const
virtual void scale(const T factor) override
Scale each element of the vector by the given factor.
int ReplaceGlobalValues(int numIDs, const int *GIDs, const double *values)
Copy values into the vector overwriting any values that already exist for the specified indices.
bool _is_initialized
true once init() has been called.
virtual void localize(std::vector< T > &v_local) const override
Creates a copy of the global vector in the local vector v_local.
bool _is_closed
Flag which tracks whether the vector's values are consistent on all processors after insertion or add...
int GlobalAssemble(Epetra_CombineMode mode=Add)
Gather any overlapping/shared data into the non-overlapping partitioning defined by the Map that was ...
virtual Real min() const override
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices) override
Inserts the entries of v in *this at the locations specified by v.
virtual Real linfty_norm() const override
virtual void reciprocal() override
Computes the component-wise reciprocal, .
virtual numeric_index_type size() const =0
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
This class provides a nice interface to the Trilinos Epetra_Vector object.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
Change the dimension of the vector to n.
ParallelType _type
Type of vector.
unsigned char last_edit
Keep track of whether the last write operation on this vector was nothing (0) or a sum (1) or an add ...
virtual void clear() override
Restores the NumericVector<T> to a pristine state.
int inputNonlocalValues(int GID, int numValues, const double *values, bool accumulate)
virtual NumericVector< T > & operator/=(const NumericVector< T > &v) override
Computes the component-wise division of this vector's entries by another's, .
bool ignoreNonLocalEntries_
virtual void set(const numeric_index_type i, const T value) override
Sets v(i) = value.
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
int inputNonlocalValue(int GID, double value, bool accumulate)
EpetraVector(const Parallel::Communicator &comm, const ParallelType type=AUTOMATIC)
Dummy-Constructor.
uint8_t processor_id_type
virtual T dot(const NumericVector< T > &v) const override
EpetraVector & operator=(const EpetraVector &)=delete
virtual void swap(NumericVector< T > &v) override
Swaps the contents of this with v.
Epetra_Vector * _vec
Actual Epetra vector datatype to hold vector entries.
virtual Real l1_norm() const override
virtual numeric_index_type local_size() const =0
virtual Real max() const override
virtual numeric_index_type local_size() const override
static PetscErrorCode Mat * A
virtual numeric_index_type size() const override
dof_id_type numeric_index_type
virtual Real l2_norm() const override
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
bool initialized()
Checks that library initialization has been done.
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
const Elem & get(const ElemType type_in)
bool _is_initialized
Flag that tells if init() has been called.
virtual std::unique_ptr< NumericVector< T > > clone() const override
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
virtual void abs() override
Sets for each entry in the vector.
int * numeric_trilinos_cast(const numeric_index_type *p)
void setIgnoreNonLocalEntries(bool flag)
Set whether or not non-local data values should be ignored.
virtual NumericVector< T > & operator+=(const NumericVector< T > &v) override
Adds v to *this, .
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.
bool _destroy_vec_on_exit
This boolean value should only be set to false for the constructor which takes a Epetra Vec object.
ParallelType
Defines an enum for parallel data structure types.
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
Access multiple components at once.
virtual void add(const numeric_index_type i, const T value) override
Adds value to each entry of the vector.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual T operator()(const numeric_index_type i) const override
virtual numeric_index_type first_local_index() const override
std::unique_ptr< Epetra_Map > _map
Holds the distributed Map.
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices) override
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i].
virtual T sum() const override
ParallelType type() const
bool closed()
Checks that the library has been closed.