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"
31#include "libmesh/ignore_warnings.h"
32#include <Epetra_CombineMode.h>
33#include <Epetra_Map.h>
34#include <Epetra_MultiVector.h>
35#include <Epetra_Vector.h>
36#include <Epetra_MpiComm.h>
37#include "libmesh/restore_warnings.h"
47class Epetra_IntSerialDenseVector;
48class Epetra_SerialDenseVector;
54template <
typename T>
class SparseMatrix;
101 const std::vector<numeric_index_type> & ghost,
125 virtual void close ()
override;
130 virtual void clear () noexcept override;
132 virtual
void zero () override;
140 const
bool fast=false,
144 const
bool fast=false,
150 const
bool fast = false,
154 const
bool fast = false) override;
162 virtual
Real min () const override;
164 virtual
Real max () const override;
166 virtual T
sum () const override;
200 virtual
void add (const T s) override;
227 virtual
void insert (const T * v,
230 virtual
void scale (const T factor) override;
232 virtual
void abs() override;
236 virtual
void localize (
std::vector<T> & v_local) const override;
280 std::unique_ptr<Epetra_Map>
_map;
299 const double * values);
312 const Epetra_SerialDenseVector & values);
320 const double * values);
333 const Epetra_SerialDenseVector & values);
337 const int * numValuesPerID,
338 const double * values);
342 const int * numValuesPerID,
343 const double * values);
367 const double * values,
372 const int * numValuesPerID,
373 const double * values,
382 const double * values,
417 _destroy_vec_on_exit(true),
421 nonlocalIDs_(nullptr),
422 nonlocalElementSize_(nullptr),
424 allocatedNonlocalLength_(0),
425 nonlocalCoefs_(nullptr),
427 ignoreNonLocalEntries_(false)
440 _destroy_vec_on_exit(true),
444 nonlocalIDs_(nullptr),
445 nonlocalElementSize_(nullptr),
447 allocatedNonlocalLength_(0),
448 nonlocalCoefs_(nullptr),
450 ignoreNonLocalEntries_(false)
465 _destroy_vec_on_exit(true),
469 nonlocalIDs_(nullptr),
470 nonlocalElementSize_(nullptr),
472 allocatedNonlocalLength_(0),
473 nonlocalCoefs_(nullptr),
475 ignoreNonLocalEntries_(false)
477 this->
init(n, n_local,
false,
type);
488 _destroy_vec_on_exit(false),
492 nonlocalIDs_(nullptr),
493 nonlocalElementSize_(nullptr),
495 allocatedNonlocalLength_(0),
496 nonlocalCoefs_(nullptr),
498 ignoreNonLocalEntries_(false)
507 _map = std::make_unique<Epetra_Map>
508 (
_vec->GlobalLength(),
511 Epetra_MpiComm (this->
comm().
get()));
529 const std::vector<numeric_index_type> & ghost,
532 _destroy_vec_on_exit(true),
536 nonlocalIDs_(nullptr),
537 nonlocalElementSize_(nullptr),
539 allocatedNonlocalLength_(0),
540 nonlocalCoefs_(nullptr),
542 ignoreNonLocalEntries_(false)
544 this->
init(n, n_local, ghost,
false,
type);
600 _map = std::make_unique<Epetra_Map>
601 (
static_cast<int>(n),
604 Epetra_MpiComm (this->comm().get()));
606 _vec =
new Epetra_Vector(*_map);
608 myFirstID_ = _vec->Map().MinMyGID();
609 myNumIDs_ = _vec->Map().NumMyElements();
614 _vec->ExtractView(&myCoefs_, &dummy);
616 this->_is_initialized =
true;
617 this->_is_closed =
true;
629 const std::vector<numeric_index_type> & ,
634 this->init(n, n_local, fast, type);
645 this->init(n,n,fast,type);
657 unsigned char global_last_edit = last_edit;
658 this->comm().max(global_last_edit);
661 if (global_last_edit == 1)
662 this->GlobalAssemble(Insert);
663 else if (global_last_edit == 2)
664 this->GlobalAssemble(Add);
668 this->_is_closed =
true;
681 if (this->_destroy_vec_on_exit)
691 this->_is_closed = this->_is_initialized =
false;
703 _vec->PutScalar(0.0);
712 std::unique_ptr<NumericVector<T>> cloned_vector =
713 std::make_unique<EpetraVector<T>>(this->comm(),
AUTOMATIC);
714 cloned_vector->init(*
this);
715 return cloned_vector;
724 std::unique_ptr<NumericVector<T>> cloned_vector =
725 std::make_unique<EpetraVector<T>>(this->comm(),
AUTOMATIC);
726 cloned_vector->init(*
this,
true);
727 *cloned_vector = *
this;
728 return cloned_vector;
739 return _vec->GlobalLength();
750 return _vec->MyLength();
759 return _vec->Map().MinMyGID();
770 return _vec->Map().MaxMyGID()+1;
780 (i < this->last_local_index())) );
782 return (*_vec)[i-this->first_local_index()];
795 _vec->MinValue(&
value);
810 _vec->MaxValue(&
value);
825 std::swap(_vec, v.
_vec);
847 return std::numeric_limits<int>::max();
This class provides a nice interface to the Trilinos Epetra_Vector object.
int allocatedNonlocalLength_
EpetraVector(const Parallel::Communicator &comm, const ParallelType type=AUTOMATIC)
Dummy-Constructor.
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 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.
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 Real min() const override
virtual void swap(NumericVector< T > &v) override
Swaps the contents of this with v.
virtual std::unique_ptr< NumericVector< T > > zero_clone() const override
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.
virtual void abs() override
Sets for each entry in the vector.
virtual numeric_index_type local_size() const override
void FEoperatorequals(const EpetraVector &source)
EpetraVector(EpetraVector &&)=delete
This class manages the lifetime of an Epetra_Vector manually, so we don't want to allow any automatic...
virtual numeric_index_type last_local_index() const override
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 ...
int inputNonlocalValue(int GID, double value, bool accumulate)
int inputNonlocalValues(int GID, int numValues, const double *values, bool accumulate)
bool ignoreNonLocalEntries_
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
virtual void add(const numeric_index_type i, const T value) override
Adds value to the vector entry specified by i.
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 void clear() noexcept override
clear() is called from the destructor, so it should not throw.
virtual std::unique_ptr< NumericVector< T > > clone() const override
virtual numeric_index_type size() const override
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
virtual void set(const numeric_index_type i, const T value) override
Sets v(i) = value.
EpetraVector & operator=(const EpetraVector &)=delete
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
virtual T sum() const override
virtual std::size_t max_allowed_id() const override
int inputValues(int numIDs, const int *GIDs, const double *values, bool accumulate)
virtual Real max() const override
void setIgnoreNonLocalEntries(bool flag)
Set whether or not non-local data values should be ignored.
int * nonlocalElementSize_
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.
virtual Real l1_norm() const override
virtual void reciprocal() override
Computes the component-wise reciprocal, .
std::unique_ptr< Epetra_Map > _map
Holds the distributed Map.
virtual T dot(const NumericVector< T > &v) const override
virtual void conjugate() override
Negates the imaginary component of each entry in the vector.
virtual T operator()(const numeric_index_type i) const override
void destroyNonlocalData()
virtual Real linfty_norm() const override
bool _destroy_vec_on_exit
This boolean value should only be set to false for the constructor which takes a Epetra Vec object.
EpetraVector(const EpetraVector &)=delete
virtual void localize(std::vector< T > &v_local) const override
Creates a copy of the global vector in the local vector v_local.
int GlobalAssemble(Epetra_CombineMode mode=Add)
Gather any overlapping/shared data into the non-overlapping partitioning defined by the Map that was ...
virtual void scale(const T factor) override
Scale each element of the vector by the given factor.
virtual numeric_index_type first_local_index() const override
virtual Real l2_norm() const override
virtual void zero() override
Set all entries to zero.
Epetra_Vector * _vec
Actual Epetra vector datatype to hold vector entries.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
Access multiple components at once.
ParallelType type() const
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v.
ParallelType _type
Type of vector.
bool _is_initialized
true once init() has been called.
virtual numeric_index_type size() const =0
bool _is_closed
Flag which tracks whether the vector's values are consistent on all processors after insertion or add...
virtual numeric_index_type local_size() const =0
const Parallel::Communicator & comm() const
The libMesh namespace provides an interface to certain functionality in the library.
ParallelType
Defines an enum for parallel data structure types.
bool closed()
Checks that the library has been closed.
dof_id_type numeric_index_type
bool initialized()
Checks that library initialization has been done.
int * numeric_trilinos_cast(const numeric_index_type *p)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type