24 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA 34 #include <Epetra_LocalMap.h> 35 #include <Epetra_Comm.h> 36 #include <Epetra_Map.h> 37 #include <Epetra_BlockMap.h> 38 #include <Epetra_Import.h> 39 #include <Epetra_Export.h> 40 #include <Epetra_Util.h> 41 #include <Epetra_IntSerialDenseVector.h> 42 #include <Epetra_SerialDenseVector.h> 43 #include <Epetra_Vector.h> 52 libmesh_assert(this->
closed());
54 const unsigned int nl = _vec->MyLength();
58 T * values = _vec->Values();
60 for (
unsigned int i=0; i<nl; i++)
63 this->comm().sum(sum);
71 libmesh_assert(this->
closed());
83 libmesh_assert(this->
closed());
95 libmesh_assert(this->
closed());
99 _vec->NormInf(&
value);
104 template <
typename T>
108 libmesh_assert(this->
closed());
117 template <
typename T>
121 libmesh_assert(this->
closed());
129 template <
typename T>
133 libmesh_assert(this->
closed());
134 libmesh_assert_equal_to(size(), v.
size());
138 _vec->ReciprocalMultiply(1.0, *v_vec._vec, *_vec, 0.0);
146 template <
typename T>
149 int i =
static_cast<int> (i_in);
152 libmesh_assert_less (i_in, this->size());
154 ReplaceGlobalValues(1, &i, &
value);
156 this->_is_closed =
false;
161 template <
typename T>
170 const unsigned int nl = _vec->MyLength();
172 T * values = _vec->Values();
174 for (
unsigned int i=0; i<nl; i++)
178 libmesh_error_msg(
"Error, divide by zero in DistributedVector<T>::reciprocal()!");
180 values[i] = 1. / values[i];
189 template <
typename T>
197 template <
typename T>
200 int i =
static_cast<int> (i_in);
203 libmesh_assert_less (i_in, this->size());
205 SumIntoGlobalValues(1, &i, &
value);
207 this->_is_closed =
false;
212 template <
typename T>
214 const std::vector<numeric_index_type> & dof_indices)
218 SumIntoGlobalValues (cast_int<numeric_index_type>(dof_indices.size()),
226 template <
typename T>
234 std::unique_ptr<NumericVector<T>> temp = v->
zero_clone();
236 A->mat()->Multiply(
false, *v->
_vec, *temp_v->
_vec);
243 template <
typename T>
247 libmesh_not_implemented();
252 template <
typename T>
255 const unsigned int nl = _vec->MyLength();
257 T * values = _vec->Values();
259 for (
unsigned int i=0; i<nl; i++)
262 this->_is_closed =
false;
266 template <
typename T>
273 template <
typename T>
278 libmesh_assert_equal_to (this->size(), v->
size());
280 _vec->Update(a_in,*v->
_vec, 1.);
285 template <
typename T>
287 const std::vector<numeric_index_type> & dof_indices)
291 ReplaceGlobalValues (cast_int<numeric_index_type>(dof_indices.size()),
298 template <
typename T>
301 _vec->Scale(factor_in);
304 template <
typename T>
311 template <
typename T>
318 _vec->Dot(*v->
_vec, &result);
324 template <
typename T>
331 _vec->Multiply(1.0, *v1->
_vec, *v2->_vec, 0.0);
335 template <
typename T>
339 _vec->PutScalar(s_in);
346 template <
typename T>
355 libmesh_not_implemented();
361 template <
typename T>
365 T * values = _vec->Values();
371 if (this->size() == v.size())
373 const unsigned int nl=this->local_size();
374 const unsigned int fli=this->first_local_index();
376 for (
unsigned int i=0;i<nl;i++)
386 libmesh_assert_equal_to (v.size(), this->local_size());
388 const unsigned int nl=this->local_size();
390 for (
unsigned int i=0;i<nl;i++)
399 template <
typename T>
404 Epetra_Map rootMap = Epetra_Util::Create_Root_Map( *_map, -1);
405 v_local->
_vec->ReplaceMap(rootMap);
407 Epetra_Import importer(v_local->
_vec->Map(), *_map);
408 v_local->
_vec->Import(*_vec, importer, Insert);
413 template <
typename T>
415 const std::vector<numeric_index_type> & )
const 418 this->localize(v_local_in);
435 template <
typename T>
437 const std::vector<numeric_index_type> & indices)
const 442 Epetra_LocalMap import_map(static_cast<int>(indices.size()),
448 int * import_map_global_elements = import_map.MyGlobalElements();
449 for (
int i=0; i<import_map.NumMyElements(); ++i)
450 import_map_global_elements[i] = indices[i];
453 Epetra_Vector import_vector(import_map);
456 Epetra_Import import_object(import_map, *_map);
459 import_vector.Import(*_vec, import_object, Insert);
463 T * values = import_vector.Values();
464 int import_vector_length = import_vector.MyLength();
467 v_local.resize(import_vector_length);
468 for (
int i=0; i<import_vector_length; ++i)
469 v_local[i] = values[i];
474 template <
typename T>
477 const std::vector<numeric_index_type> & send_list)
480 libmesh_assert_equal_to (this->size(), this->local_size());
481 libmesh_assert_greater (last_local_idx, first_local_idx);
482 libmesh_assert_less_equal (send_list.size(), this->size());
483 libmesh_assert_less (last_local_idx, this->size());
485 const unsigned int my_size = this->size();
486 const unsigned int my_local_size = (last_local_idx - first_local_idx + 1);
489 if ((first_local_idx == 0) &&
490 (my_local_size == my_size))
497 parallel_vec.
init (my_size, my_local_size,
true,
PARALLEL);
501 parallel_vec.
set(i,this->el(i));
504 parallel_vec.
close();
505 parallel_vec.
localize (*
this, send_list);
511 template <
typename T>
515 parallel_object_only();
517 const unsigned int n = this->size();
518 const unsigned int nl = this->local_size();
520 libmesh_assert(this->_vec);
526 for (
unsigned int i=0; i<nl; i++)
527 v_local.push_back((*this->_vec)[i]);
529 this->comm().allgather (v_local);
534 template <
typename T>
539 parallel_object_only();
541 const unsigned int n = this->size();
542 const unsigned int nl = this->local_size();
544 libmesh_assert_less (pid, this->n_processors());
545 libmesh_assert(this->_vec);
552 for (
unsigned int i=0; i<nl; i++)
553 v_local.push_back((*this->_vec)[i]);
555 this->comm().gather (pid, v_local);
560 template <
typename T>
562 const std::vector<numeric_index_type> & )
const 564 libmesh_not_implemented();
576 template <
typename T>
579 const double * values)
581 return( inputValues( numIDs, GIDs, values,
true) );
585 template <
typename T>
587 const Epetra_SerialDenseVector & values)
589 if (GIDs.Length() != values.Length()) {
593 return( inputValues( GIDs.Length(), GIDs.Values(), values.Values(),
true) );
597 template <
typename T>
600 const int * numValuesPerID,
601 const double * values)
603 return( inputValues( numIDs, GIDs, numValuesPerID, values,
true) );
607 template <
typename T>
610 const double * values)
612 return( inputValues( numIDs, GIDs, values,
false) );
616 template <
typename T>
618 const Epetra_SerialDenseVector & values)
620 if (GIDs.Length() != values.Length()) {
624 return( inputValues( GIDs.Length(), GIDs.Values(), values.Values(),
false) );
628 template <
typename T>
631 const int * numValuesPerID,
632 const double * values)
634 return( inputValues( numIDs, GIDs, numValuesPerID, values,
false) );
638 template <
typename T>
641 const double * values,
645 libmesh_assert(last_edit == 0 || last_edit == 2);
648 libmesh_assert(last_edit == 0 || last_edit == 1);
655 for (
int i=0; i<numIDs; ++i) {
656 if (_vec->Map().MyGID(GIDs[i])) {
658 _vec->SumIntoGlobalValue(GIDs[i], 0, 0, values[i]);
661 _vec->ReplaceGlobalValue(GIDs[i], 0, 0, values[i]);
665 if (!ignoreNonLocalEntries_) {
666 EPETRA_CHK_ERR( inputNonlocalValue(GIDs[i], values[i], accumulate) );
675 template <
typename T>
678 const int * numValuesPerID,
679 const double * values,
683 libmesh_assert(last_edit == 0 || last_edit == 2);
686 libmesh_assert(last_edit == 0 || last_edit == 1);
691 for (
int i=0; i<numIDs; ++i) {
692 int numValues = numValuesPerID[i];
693 if (_vec->Map().MyGID(GIDs[i])) {
695 for (
int j=0; j<numValues; ++j) {
696 _vec->SumIntoGlobalValue(GIDs[i], j, 0, values[offset+j]);
700 for (
int j=0; j<numValues; ++j) {
701 _vec->ReplaceGlobalValue(GIDs[i], j, 0, values[offset+j]);
706 if (!ignoreNonLocalEntries_) {
707 EPETRA_CHK_ERR( inputNonlocalValues(GIDs[i], numValues,
708 &(values[offset]), accumulate) );
718 template <
typename T>
721 int insertPoint = -1;
724 int offset = Epetra_Util_binary_search(GID, nonlocalIDs_, numNonlocalIDs_,
731 nonlocalCoefs_[offset][0] +=
value;
734 nonlocalCoefs_[offset][0] =
value;
743 int tmp1 = numNonlocalIDs_;
744 int tmp2 = allocatedNonlocalLength_;
745 int tmp3 = allocatedNonlocalLength_;
746 EPETRA_CHK_ERR( Epetra_Util_insert(GID, insertPoint, nonlocalIDs_,
749 EPETRA_CHK_ERR( Epetra_Util_insert(1, insertPoint, nonlocalElementSize_,
751 double * values =
new double[1];
753 EPETRA_CHK_ERR( Epetra_Util_insert(values, insertPoint, nonlocalCoefs_,
754 numNonlocalIDs_, allocatedNonlocalLength_) );
761 template <
typename T>
764 const double * values,
767 int insertPoint = -1;
770 int offset = Epetra_Util_binary_search(GID, nonlocalIDs_, numNonlocalIDs_,
776 if (numValues != nonlocalElementSize_[offset]) {
777 libMesh::err <<
"Epetra_FEVector ERROR: block-size for GID " << GID <<
" is " 778 << numValues<<
" which doesn't match previously set block-size of " 779 << nonlocalElementSize_[offset] << std::endl;
784 for (
int j=0; j<numValues; ++j) {
785 nonlocalCoefs_[offset][j] += values[j];
789 for (
int j=0; j<numValues; ++j) {
790 nonlocalCoefs_[offset][j] = values[j];
800 int tmp1 = numNonlocalIDs_;
801 int tmp2 = allocatedNonlocalLength_;
802 int tmp3 = allocatedNonlocalLength_;
803 EPETRA_CHK_ERR( Epetra_Util_insert(GID, insertPoint, nonlocalIDs_,
806 EPETRA_CHK_ERR( Epetra_Util_insert(numValues, insertPoint, nonlocalElementSize_,
808 double * newvalues =
new double[numValues];
809 for (
int j=0; j<numValues; ++j) {
810 newvalues[j] = values[j];
812 EPETRA_CHK_ERR( Epetra_Util_insert(newvalues, insertPoint, nonlocalCoefs_,
813 numNonlocalIDs_, allocatedNonlocalLength_) );
820 template <
typename T>
829 if (_vec->Map().Comm().NumProc() < 2 || ignoreNonLocalEntries_) {
838 Epetra_BlockMap sourceMap(-1, numNonlocalIDs_,
839 nonlocalIDs_, nonlocalElementSize_,
840 _vec->Map().IndexBase(), _vec->Map().Comm());
844 Epetra_MultiVector nonlocalVector(sourceMap, 1);
847 for (i=0; i<numNonlocalIDs_; ++i) {
848 for (j=0; j<nonlocalElementSize_[i]; ++j) {
849 nonlocalVector.ReplaceGlobalValue(nonlocalIDs_[i], j, 0,
850 nonlocalCoefs_[i][j]);
854 Epetra_Export exporter(sourceMap, _vec->Map());
856 EPETRA_CHK_ERR( _vec->Export(nonlocalVector, exporter, mode) );
858 destroyNonlocalData();
865 template <
typename T>
868 (*_vec) = *(source.
_vec);
870 destroyNonlocalData();
875 nonlocalIDs_ =
new int[allocatedNonlocalLength_];
876 nonlocalElementSize_ =
new int[allocatedNonlocalLength_];
877 nonlocalCoefs_ =
new double *[allocatedNonlocalLength_];
878 for (
int i=0; i<numNonlocalIDs_; ++i) {
880 nonlocalCoefs_[i] =
new double[elemSize];
882 nonlocalElementSize_[i] = elemSize;
883 for (
int j=0; j<elemSize; ++j) {
892 template <
typename T>
895 if (allocatedNonlocalLength_ > 0) {
896 delete [] nonlocalIDs_;
897 delete [] nonlocalElementSize_;
898 nonlocalIDs_ =
nullptr;
899 nonlocalElementSize_ =
nullptr;
900 for (
int i=0; i<numNonlocalIDs_; ++i) {
901 delete [] nonlocalCoefs_[i];
903 delete [] nonlocalCoefs_;
904 nonlocalCoefs_ =
nullptr;
906 allocatedNonlocalLength_ = 0;
918 #endif // LIBMESH_TRILINOS_HAVE_EPETRA
virtual NumericVector< T > & operator/=(const NumericVector< T > &v) override
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
int allocatedNonlocalLength_
virtual void reciprocal() override
virtual void add(const numeric_index_type i, const T value) override
virtual void close() override
virtual std::unique_ptr< NumericVector< T > > zero_clone() const override
virtual numeric_index_type size() const =0
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
uint8_t processor_id_type
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices) override
int inputNonlocalValues(int GID, int numValues, const double *values, bool accumulate)
virtual void conjugate() override
int * nonlocalElementSize_
virtual T sum() const override
int GlobalAssemble(Epetra_CombineMode mode=Add)
virtual numeric_index_type size() const override
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
int ReplaceGlobalValues(int numIDs, const int *GIDs, const double *values)
int inputValues(int numIDs, const int *GIDs, const double *values, bool accumulate)
dof_id_type numeric_index_type
virtual NumericVector< T > & operator+=(const NumericVector< T > &v) override
virtual Real l1_norm() const override
virtual void abs() override
virtual NumericVector< T > & operator-=(const NumericVector< T > &v) override
int inputNonlocalValue(int GID, double value, bool accumulate)
virtual Real linfty_norm() const override
OStreamProxy err(std::cerr)
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
void destroyNonlocalData()
virtual void localize(std::vector< T > &v_local) const override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual T dot(const NumericVector< T > &v) const override
int SumIntoGlobalValues(int numIDs, const int *GIDs, const double *values)
static PetscErrorCode Mat * A
virtual Real l2_norm() const override
virtual void create_subvector(NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows) const override
void FEoperatorequals(const EpetraVector &source)
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
long double min(long double a, double b)
EpetraVector & operator=(const EpetraVector &)=delete