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"
47 class Epetra_IntSerialDenseVector;
48 class Epetra_SerialDenseVector;
54 template <
typename T>
class SparseMatrix;
74 explicit EpetraVector (
const Parallel::Communicator & comm,
75 const ParallelType
type = AUTOMATIC);
84 explicit EpetraVector (
const Parallel::Communicator & comm,
86 const ParallelType
type = AUTOMATIC);
99 const ParallelType
type = AUTOMATIC);
113 const std::vector<numeric_index_type> & ghost,
114 const ParallelType
type = AUTOMATIC);
125 const Parallel::Communicator & comm);
139 virtual void close ()
override;
144 virtual void clear () noexcept override;
149 virtual
void zero () override;
175 const
bool fast=false,
176 const ParallelType
type=AUTOMATIC) override;
186 const
bool fast=false,
187 const ParallelType
type=AUTOMATIC) override;
201 const
bool fast = false,
202 const ParallelType = AUTOMATIC) override;
211 const
bool fast = false) override;
238 virtual
NumericVector<T> & operator= (const std::vector<T> & v) override;
245 virtual
Real min () const override;
252 virtual
Real max () const override;
259 virtual T
sum () const override;
386 virtual
void add (const T s) override;
436 virtual
void insert (const T * v,
444 virtual
void scale (const T factor) override;
449 virtual
void abs() override;
465 virtual
void localize (std::vector<T> & v_local) const override;
489 virtual
void localize (std::vector<T> & v_local,
565 std::unique_ptr<Epetra_Map>
_map;
585 const double * values);
596 const Epetra_SerialDenseVector & values);
609 const double * values);
620 const Epetra_SerialDenseVector & values);
634 const int * numValuesPerID,
635 const double * values);
649 const int * numValuesPerID,
650 const double * values);
692 const double * values,
708 const int * numValuesPerID,
709 const double * values,
737 const double * values,
802 template <
typename T>
805 const ParallelType type) :
807 _destroy_vec_on_exit(true),
811 nonlocalIDs_(nullptr),
812 nonlocalElementSize_(nullptr),
814 allocatedNonlocalLength_(0),
815 nonlocalCoefs_(nullptr),
817 ignoreNonLocalEntries_(false)
824 template <
typename T>
828 const ParallelType type) :
830 _destroy_vec_on_exit(true),
834 nonlocalIDs_(nullptr),
835 nonlocalElementSize_(nullptr),
837 allocatedNonlocalLength_(0),
838 nonlocalCoefs_(nullptr),
840 ignoreNonLocalEntries_(false)
843 this->
init(n, n,
false, type);
848 template <
typename T>
853 const ParallelType type) :
855 _destroy_vec_on_exit(true),
859 nonlocalIDs_(nullptr),
860 nonlocalElementSize_(nullptr),
862 allocatedNonlocalLength_(0),
863 nonlocalCoefs_(nullptr),
865 ignoreNonLocalEntries_(false)
867 this->
init(n, n_local,
false, type);
873 template <
typename T>
876 const Parallel::Communicator & comm) :
878 _destroy_vec_on_exit(false),
882 nonlocalIDs_(nullptr),
883 nonlocalElementSize_(nullptr),
885 allocatedNonlocalLength_(0),
886 nonlocalCoefs_(nullptr),
888 ignoreNonLocalEntries_(false)
892 this->
_type = PARALLEL;
897 _map = std::make_unique<Epetra_Map>
898 (
_vec->GlobalLength(),
901 Epetra_MpiComm (this->comm().
get()));
914 template <
typename T>
919 const std::vector<numeric_index_type> & ghost,
920 const ParallelType type) :
922 _destroy_vec_on_exit(true),
926 nonlocalIDs_(nullptr),
927 nonlocalElementSize_(nullptr),
929 allocatedNonlocalLength_(0),
930 nonlocalCoefs_(nullptr),
932 ignoreNonLocalEntries_(false)
934 this->
init(n, n_local, ghost,
false, type);
949 template <
typename T>
958 template <
typename T>
963 const ParallelType type)
968 if (type == AUTOMATIC)
971 this->_type = SERIAL;
973 this->_type = PARALLEL;
975 else if (type == GHOSTED)
980 this->_type = SERIAL;
986 libmesh_assert ((this->_type==SERIAL && n==my_n_local) ||
987 this->_type==PARALLEL);
989 _map = std::make_unique<Epetra_Map>
990 (
static_cast<int>(n),
993 Epetra_MpiComm (this->comm().get()));
995 _vec =
new Epetra_Vector(*_map);
997 myFirstID_ = _vec->Map().MinMyGID();
998 myNumIDs_ = _vec->Map().NumMyElements();
1003 _vec->ExtractView(&myCoefs_, &dummy);
1006 this->_is_closed =
true;
1007 this->last_edit = 0;
1014 template <
typename T>
1018 const std::vector<numeric_index_type> & ,
1020 const ParallelType type)
1023 this->init(n, n_local, fast, type);
1028 template <
typename T>
1032 const ParallelType type)
1034 this->init(n,n,fast,type);
1039 template <
typename T>
1046 unsigned char global_last_edit = last_edit;
1047 this->comm().max(global_last_edit);
1048 libmesh_assert(!last_edit || last_edit == global_last_edit);
1050 if (global_last_edit == 1)
1051 this->GlobalAssemble(Insert);
1052 else if (global_last_edit == 2)
1053 this->GlobalAssemble(Add);
1055 libmesh_assert(!global_last_edit);
1057 this->_is_closed =
true;
1058 this->last_edit = 0;
1063 template <
typename T>
1070 if (this->_destroy_vec_on_exit)
1085 template <
typename T>
1090 libmesh_assert (this->
closed());
1092 _vec->PutScalar(0.0);
1097 template <
typename T>
1102 cloned_vector->
init(*
this);
1103 return std::unique_ptr<NumericVector<T>>(cloned_vector);
1108 template <
typename T>
1113 cloned_vector->
init(*
this,
true);
1114 *cloned_vector = *
this;
1115 return std::unique_ptr<NumericVector<T>>(cloned_vector);
1120 template <
typename T>
1126 return _vec->GlobalLength();
1131 template <
typename T>
1137 return _vec->MyLength();
1140 template <
typename T>
1146 return _vec->Map().MinMyGID();
1151 template <
typename T>
1157 return _vec->Map().MaxMyGID()+1;
1161 template <
typename T>
1166 libmesh_assert ( ((i >= this->first_local_index()) &&
1167 (i < this->last_local_index())) );
1169 return (*_vec)[i-this->first_local_index()];
1174 template <
typename T>
1182 _vec->MinValue(&value);
1189 template <
typename T>
1197 _vec->MaxValue(&value);
1204 template <
typename T>
1212 std::swap(_vec, v.
_vec);
1229 template <
typename T>
1234 return std::numeric_limits<int>::max();
1249 #endif // #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
1250 #endif // LIBMESH_TRILINOS_EPETRA_VECTOR_H
double ** nonlocalCoefs_
非本地系数的指针数组。
int myFirstID_
保存向量的第一个全局 ID。
bool closed()
Checks that the library has been closed.
此类提供了对Trilinos Epetra_Vector对象的友好接口。所有重写的虚拟函数在numeric_vector.h中都有文档。
virtual T operator()(const numeric_index_type i) const override
获取矢量中索引i处的值。
std::unique_ptr< Epetra_Map > _map
持有分布式映射。
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
计算当前矢量与另一个矢量的逐元素乘积。
int allocatedNonlocalLength_
已分配的非本地长度。
virtual void reciprocal() override
计算当前矢量的逐元素倒数。
virtual numeric_index_type last_local_index() const override
获取矢量的最后一个本地索引。
virtual void add(const numeric_index_type i, const T value) override
将索引i处的值增加value。
virtual void close() override
关闭矢量,使其无法再次修改。
virtual std::unique_ptr< NumericVector< T > > zero_clone() const override
创建零克隆矢量。
double * myCoefs_
保存系数的指针数组。
virtual numeric_index_type size() const =0
获取向量的大小。
Epetra_Vector * _vec
用于保存向量条目的实际 Epetra 向量数据类型。
virtual void localize_to_one(std::vector< T > &v_local, const processor_id_type proc_id=0) const override
将所有值本地化到一个本地矢量中,仅保留一个处理器上的值。
virtual void set(const numeric_index_type i, const T value) override
设置索引i处的值为value。
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices) override
使用特定的自由度索引将一个值数组插入到当前矢量中。
int myNumIDs_
保存向量的全局 ID 数量。
int inputNonlocalValues(int GID, int numValues, const double *values, bool accumulate)
输入非本地值到向量中,覆盖或累积到指定 GID 的已存在的任何值。
bool _is_initialized
在调用 init() 后设置为 true。
virtual void conjugate() override
计算当前矢量的逐元素共轭。
virtual Real max() const override
获取矢量中的最大值。
virtual void zero() override
将所有元素置零。
int * nonlocalElementSize_
非本地元素大小数组。
virtual T sum() const override
计算矢量中所有元素的总和。
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
更改向量的维度为 n 。如果可能的话 ,该向量的保留内存保持不变。 如果 n==0 ,所有内存都将被释放。因此,如果要调整向量的大小并释放不需要的内存, 必须首先调用 init(0) ,然后调用 ini...
int GlobalAssemble(Epetra_CombineMode mode=Add)
将所有重叠/共享数据收集到由 Map 在构造函数中传递给该向量定义的非重叠分区中。 从其他处理器导入的数据以“sumInto”或累积操作存储在拥有处理器上。这是一种集体方法, 每个处理器在任何处理器完成...
virtual numeric_index_type size() const override
获取矢量的全局大小。
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
使用稀疏矩阵A的转置乘积将另一个矢量v添加到当前矢量中。
uint8_t processor_id_type
int ReplaceGlobalValues(int numIDs, const int *GIDs, const double *values)
将值复制到向量中,覆盖指定索引已存在的任何值。
int inputValues(int numIDs, const int *GIDs, const double *values, bool accumulate)
输入值到向量中,覆盖或累积到指定索引的已存在的任何值。
这是一个通用的稀疏矩阵类。该类包含了必须在派生类中覆盖的纯虚拟成员。 使用一个公共的基类允许从不同的求解器包中以不同的格式统一访问稀疏矩阵。
bool _destroy_vec_on_exit
此布尔值只应在接受 Epetra Vec 对象的构造函数中设置为 false。
void setIgnoreNonLocalEntries(bool flag)
设置是否应忽略非本地数据值。
unsigned char last_edit
跟踪上次对此向量的写入操作是“无”(0)还是“累积”(1)还是“添加”(2), 以便我们可以决定如何进行 GlobalAssemble()。
dof_id_type numeric_index_type
bool _is_initialized
Flag that tells if init() has been called.
EpetraVector(const Parallel::Communicator &comm, const ParallelType type=AUTOMATIC)
构造函数。创建一个维度为0的虚拟矢量。
int * nonlocalIDs_
非本地 ID 数组。
virtual Real l1_norm() const override
计算矢量的L1范数。
virtual void abs() override
计算矢量的绝对值。
int inputNonlocalValue(int GID, double value, bool accumulate)
输入非本地值到向量中,覆盖或累积到指定 GID 的已存在的任何值。
bool ignoreNonLocalEntries_
是否忽略非本地数据值。
virtual Real min() const override
获取矢量中的最小值。
virtual Real linfty_norm() const override
计算矢量的L∞范数。
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
初始化矢量。
virtual std::size_t max_allowed_id() const override
获取允许的最大ID大小。
void destroyNonlocalData()
销毁非本地数据。
int numNonlocalIDs_
非本地 ID 数量。
virtual void localize(std::vector< T > &v_local) const override
将当前矢量的值本地化到一个本地矢量中。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void clear() noexceptoverride
清除矢量,析构函数中会调用此函数,因此不应抛出异常。
virtual void swap(NumericVector< T > &v)
交换该向量的内容与向量 v 的内容。子类应提供足够的间接性以使此操作成为 O(1) 的头部交换操作。
virtual T dot(const NumericVector< T > &v) const override
计算当前矢量与另一个矢量的点积。
int SumIntoGlobalValues(int numIDs, const int *GIDs, const double *values)
将值累积到向量中,将它们添加到指定索引已存在的任何值中。
virtual Real l2_norm() const override
计算矢量的L2范数。
virtual numeric_index_type local_size() const =0
获取向量的本地大小,即 index_stop - index_start。
virtual void create_subvector(NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows) const override
创建当前矢量的子矢量,包含指定行的值。
ParallelType type() const
获取向量的类型。
virtual numeric_index_type first_local_index() const override
获取矢量的第一个本地索引。
void FEoperatorequals(const EpetraVector &source)
从另一个 EpetraVector 对象中复制操作符。
virtual void swap(NumericVector< T > &v) override
交换当前矢量与另一个矢量的值。
virtual std::unique_ptr< NumericVector< T > > clone() const override
创建矢量克隆。
bool initialized()
Checks that library initialization has been done.
int * numeric_trilinos_cast(const numeric_index_type *p)
virtual void scale(const T factor) override
缩放矢量的所有元素。
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices) override
使用特定的自由度索引添加一个值数组到当前矢量中。
Epetra_Vector * vec()
返回原始的 Epetra_Vector 指针。
bool _is_closed
用于跟踪向量的值在在一些或全部处理器上进行插入或添加值操作后是否在所有处理器上保持一致的标志。
virtual numeric_index_type local_size() const override
获取矢量的本地大小。
EpetraVector & operator=(const EpetraVector &)=delete