22 #include "libmesh/trilinos_epetra_vector.h" 24 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA 26 #include "libmesh/dense_subvector.h" 27 #include "libmesh/dense_vector.h" 28 #include "libmesh/parallel.h" 29 #include "libmesh/trilinos_epetra_matrix.h" 30 #include "libmesh/utility.h" 33 #include "libmesh/ignore_warnings.h" 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> 44 #include "libmesh/restore_warnings.h" 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);
99 _vec->NormInf(&
value);
104 template <
typename T>
117 template <
typename T>
129 template <
typename T>
134 libmesh_assert_equal_to(size(), v.
size());
138 _vec->Multiply(1.0, *v_vec._vec, *_vec, 0.0);
144 template <
typename T>
149 libmesh_assert_equal_to(size(), v.
size());
153 _vec->ReciprocalMultiply(1.0, *v_vec._vec, *_vec, 0.0);
161 template <
typename T>
164 int i =
static_cast<int> (i_in);
167 libmesh_assert_less (i_in, this->size());
169 std::scoped_lock lock(this->_numeric_vector_mutex);
170 ReplaceGlobalValues(1, &i, &
value);
172 this->_is_closed =
false;
177 template <
typename T>
186 const unsigned int nl = _vec->MyLength();
188 T * values = _vec->Values();
190 for (
unsigned int i=0; i<nl; i++)
193 libmesh_error_msg_if(std::abs(values[i]) < std::numeric_limits<T>::min(),
194 "Error, divide by zero in DistributedVector<T>::reciprocal()!");
196 values[i] = 1. / values[i];
205 template <
typename T>
213 template <
typename T>
216 int i =
static_cast<int> (i_in);
219 libmesh_assert_less (i_in, this->size());
221 std::scoped_lock lock(this->_numeric_vector_mutex);
222 SumIntoGlobalValues(1, &i, &
value);
224 this->_is_closed =
false;
229 template <
typename T>
231 const std::vector<numeric_index_type> & dof_indices)
235 std::scoped_lock lock(this->_numeric_vector_mutex);
236 SumIntoGlobalValues (cast_int<numeric_index_type>(dof_indices.size()),
244 template <
typename T>
252 std::unique_ptr<NumericVector<T>> temp = v->
zero_clone();
254 A->mat()->Multiply(
false, *v->
_vec, *temp_v->
_vec);
261 template <
typename T>
265 libmesh_not_implemented();
270 template <
typename T>
273 const unsigned int nl = _vec->MyLength();
275 T * values = _vec->Values();
277 for (
unsigned int i=0; i<nl; i++)
280 this->_is_closed =
false;
284 template <
typename T>
291 template <
typename T>
296 libmesh_assert_equal_to (this->size(), v->
size());
298 _vec->Update(a_in,*v->
_vec, 1.);
303 template <
typename T>
305 const std::vector<numeric_index_type> & dof_indices)
309 std::scoped_lock lock(this->_numeric_vector_mutex);
310 ReplaceGlobalValues (cast_int<numeric_index_type>(dof_indices.size()),
313 this->_is_closed =
false;
318 template <
typename T>
321 _vec->Scale(factor_in);
324 template <
typename T>
331 template <
typename T>
338 _vec->Dot(*v->
_vec, &result);
344 template <
typename T>
351 _vec->Multiply(1.0, *v1->
_vec, *v2->_vec, 0.0);
355 template <
typename T>
359 _vec->PutScalar(s_in);
366 template <
typename T>
375 libmesh_not_implemented();
381 template <
typename T>
385 T * values = _vec->Values();
391 if (this->size() == v.size())
393 const unsigned int nl=this->local_size();
394 const unsigned int fli=this->first_local_index();
396 for (
unsigned int i=0;i<nl;i++)
406 libmesh_assert_equal_to (v.size(), this->local_size());
408 const unsigned int nl=this->local_size();
410 for (
unsigned int i=0;i<nl;i++)
419 template <
typename T>
424 Epetra_Map rootMap = Epetra_Util::Create_Root_Map( *_map, -1);
425 v_local->
_vec->ReplaceMap(rootMap);
427 Epetra_Import importer(v_local->
_vec->Map(), *_map);
428 v_local->
_vec->Import(*_vec, importer, Insert);
433 template <
typename T>
435 const std::vector<numeric_index_type> & )
const 438 this->localize(v_local_in);
455 template <
typename T>
457 const std::vector<numeric_index_type> & indices)
const 462 Epetra_LocalMap import_map(static_cast<int>(indices.size()),
468 int * import_map_global_elements = import_map.MyGlobalElements();
470 import_map_global_elements[i] = indices[i];
473 Epetra_Vector import_vector(import_map);
476 Epetra_Import import_object(import_map, *_map);
479 import_vector.Import(*_vec, import_object, Insert);
483 T * values = import_vector.Values();
484 int import_vector_length = import_vector.MyLength();
487 v_local.resize(import_vector_length);
488 for (
int i=0; i<import_vector_length; ++i)
489 v_local[i] = values[i];
494 template <
typename T>
497 const std::vector<numeric_index_type> & send_list)
500 libmesh_assert_equal_to (this->size(), this->local_size());
501 libmesh_assert_greater (last_local_idx, first_local_idx);
502 libmesh_assert_less_equal (send_list.size(), this->size());
503 libmesh_assert_less (last_local_idx, this->size());
505 const unsigned int my_size = this->size();
506 const unsigned int my_local_size = (last_local_idx - first_local_idx + 1);
509 if ((first_local_idx == 0) &&
510 (my_local_size == my_size))
517 parallel_vec.
init (my_size, my_local_size,
true,
PARALLEL);
521 parallel_vec.
set(i,this->el(i));
524 parallel_vec.
close();
525 parallel_vec.
localize (*
this, send_list);
531 template <
typename T>
535 parallel_object_only();
537 const unsigned int n = this->size();
538 const unsigned int nl = this->local_size();
546 for (
unsigned int i=0; i<nl; i++)
547 v_local.push_back((*this->_vec)[i]);
549 this->comm().allgather (v_local);
554 template <
typename T>
559 parallel_object_only();
561 const unsigned int n = this->size();
562 const unsigned int nl = this->local_size();
564 libmesh_assert_less (pid, this->n_processors());
572 for (
unsigned int i=0; i<nl; i++)
573 v_local.push_back((*this->_vec)[i]);
575 this->comm().gather (pid, v_local);
587 template <
typename T>
590 const double * values)
592 return( inputValues( numIDs, GIDs, values,
true) );
596 template <
typename T>
598 const Epetra_SerialDenseVector & values)
600 if (GIDs.Length() != values.Length()) {
604 return( inputValues( GIDs.Length(), GIDs.Values(), values.Values(),
true) );
608 template <
typename T>
611 const int * numValuesPerID,
612 const double * values)
614 return( inputValues( numIDs, GIDs, numValuesPerID, values,
true) );
618 template <
typename T>
621 const double * values)
623 return( inputValues( numIDs, GIDs, values,
false) );
627 template <
typename T>
629 const Epetra_SerialDenseVector & values)
631 if (GIDs.Length() != values.Length()) {
635 return( inputValues( GIDs.Length(), GIDs.Values(), values.Values(),
false) );
639 template <
typename T>
642 const int * numValuesPerID,
643 const double * values)
645 return( inputValues( numIDs, GIDs, numValuesPerID, values,
false) );
649 template <
typename T>
652 const double * values,
666 for (
int i=0; i<numIDs; ++i) {
667 if (_vec->Map().MyGID(GIDs[i])) {
669 _vec->SumIntoGlobalValue(GIDs[i], 0, 0, values[i]);
672 _vec->ReplaceGlobalValue(GIDs[i], 0, 0, values[i]);
676 if (!ignoreNonLocalEntries_) {
677 EPETRA_CHK_ERR( inputNonlocalValue(GIDs[i], values[i], accumulate) );
686 template <
typename T>
689 const int * numValuesPerID,
690 const double * values,
702 for (
int i=0; i<numIDs; ++i) {
703 int numValues = numValuesPerID[i];
704 if (_vec->Map().MyGID(GIDs[i])) {
706 for (
int j=0; j<numValues; ++j) {
707 _vec->SumIntoGlobalValue(GIDs[i], j, 0, values[offset+j]);
711 for (
int j=0; j<numValues; ++j) {
712 _vec->ReplaceGlobalValue(GIDs[i], j, 0, values[offset+j]);
717 if (!ignoreNonLocalEntries_) {
718 EPETRA_CHK_ERR( inputNonlocalValues(GIDs[i], numValues,
719 &(values[offset]), accumulate) );
729 template <
typename T>
732 int insertPoint = -1;
735 int offset = Epetra_Util_binary_search(GID, nonlocalIDs_, numNonlocalIDs_,
742 nonlocalCoefs_[offset][0] +=
value;
745 nonlocalCoefs_[offset][0] =
value;
754 int tmp1 = numNonlocalIDs_;
755 int tmp2 = allocatedNonlocalLength_;
756 int tmp3 = allocatedNonlocalLength_;
757 EPETRA_CHK_ERR( Epetra_Util_insert(GID, insertPoint, nonlocalIDs_,
760 EPETRA_CHK_ERR( Epetra_Util_insert(1, insertPoint, nonlocalElementSize_,
762 double * values =
new double[1];
764 EPETRA_CHK_ERR( Epetra_Util_insert(values, insertPoint, nonlocalCoefs_,
765 numNonlocalIDs_, allocatedNonlocalLength_) );
772 template <
typename T>
775 const double * values,
778 int insertPoint = -1;
781 int offset = Epetra_Util_binary_search(GID, nonlocalIDs_, numNonlocalIDs_,
787 if (numValues != nonlocalElementSize_[offset]) {
788 libMesh::err <<
"Epetra_FEVector ERROR: block-size for GID " << GID <<
" is " 789 << numValues<<
" which doesn't match previously set block-size of " 790 << nonlocalElementSize_[offset] << std::endl;
795 for (
int j=0; j<numValues; ++j) {
796 nonlocalCoefs_[offset][j] += values[j];
800 for (
int j=0; j<numValues; ++j) {
801 nonlocalCoefs_[offset][j] = values[j];
811 int tmp1 = numNonlocalIDs_;
812 int tmp2 = allocatedNonlocalLength_;
813 int tmp3 = allocatedNonlocalLength_;
814 EPETRA_CHK_ERR( Epetra_Util_insert(GID, insertPoint, nonlocalIDs_,
817 EPETRA_CHK_ERR( Epetra_Util_insert(numValues, insertPoint, nonlocalElementSize_,
819 double * newvalues =
new double[numValues];
820 for (
int j=0; j<numValues; ++j) {
821 newvalues[j] = values[j];
823 EPETRA_CHK_ERR( Epetra_Util_insert(newvalues, insertPoint, nonlocalCoefs_,
824 numNonlocalIDs_, allocatedNonlocalLength_) );
831 template <
typename T>
840 if (_vec->Map().Comm().NumProc() < 2 || ignoreNonLocalEntries_) {
849 Epetra_BlockMap sourceMap(-1, numNonlocalIDs_,
850 nonlocalIDs_, nonlocalElementSize_,
851 _vec->Map().IndexBase(), _vec->Map().Comm());
855 Epetra_MultiVector nonlocalVector(sourceMap, 1);
858 for (i=0; i<numNonlocalIDs_; ++i) {
859 for (j=0; j<nonlocalElementSize_[i]; ++j) {
860 nonlocalVector.ReplaceGlobalValue(nonlocalIDs_[i], j, 0,
861 nonlocalCoefs_[i][j]);
865 Epetra_Export exporter(sourceMap, _vec->Map());
867 EPETRA_CHK_ERR( _vec->Export(nonlocalVector, exporter, mode) );
869 destroyNonlocalData();
874 #include <libmesh/ignore_warnings.h> 877 template <
typename T>
880 (*_vec) = *(source.
_vec);
882 destroyNonlocalData();
887 nonlocalIDs_ =
new int[allocatedNonlocalLength_];
888 nonlocalElementSize_ =
new int[allocatedNonlocalLength_];
889 nonlocalCoefs_ =
new double *[allocatedNonlocalLength_];
890 for (
int i=0; i<numNonlocalIDs_; ++i) {
892 nonlocalCoefs_[i] =
new double[elemSize];
894 nonlocalElementSize_[i] = elemSize;
895 for (
int j=0; j<elemSize; ++j) {
902 #include <libmesh/restore_warnings.h> 905 template <
typename T>
908 if (allocatedNonlocalLength_ > 0) {
909 delete [] nonlocalIDs_;
910 delete [] nonlocalElementSize_;
911 nonlocalIDs_ =
nullptr;
912 nonlocalElementSize_ =
nullptr;
913 for (
int i=0; i<numNonlocalIDs_; ++i) {
914 delete [] nonlocalCoefs_[i];
916 delete [] nonlocalCoefs_;
917 nonlocalCoefs_ =
nullptr;
919 allocatedNonlocalLength_ = 0;
931 #endif // LIBMESH_TRILINOS_HAVE_EPETRA
virtual NumericVector< T > & operator/=(const NumericVector< T > &v) override
Computes the component-wise division of this vector's entries by another's, .
bool closed()
Checks that the library has been closed.
This class provides a nice interface to the Trilinos Epetra_Vector object.
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
int allocatedNonlocalLength_
virtual void reciprocal() override
Computes the component-wise reciprocal, .
virtual void add(const numeric_index_type i, const T value) override
Adds value to the vector entry specified by i.
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
virtual std::unique_ptr< NumericVector< T > > zero_clone() const override
virtual numeric_index_type size() const =0
Epetra_Vector * _vec
Actual Epetra vector datatype to hold vector entries.
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 set(const numeric_index_type i, const T value) override
Sets v(i) = value.
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
Inserts the entries of v in *this at the locations specified by v.
int inputNonlocalValues(int GID, int numValues, const double *values, bool accumulate)
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.
int * nonlocalElementSize_
virtual T sum() const override
int GlobalAssemble(Epetra_CombineMode mode=Add)
Gather any overlapping/shared data into the non-overlapping partitioning defined by the Map that was ...
virtual numeric_index_type size() const override
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
uint8_t processor_id_type
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...
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
Computes the component-wise multiplication of this vector's entries by another's, ...
virtual NumericVector< T > & operator+=(const NumericVector< T > &v) override
Adds v to *this, .
virtual Real l1_norm() const override
virtual void abs() override
Sets for each entry in the vector.
virtual NumericVector< T > & operator-=(const NumericVector< T > &v) override
Subtracts v from *this, .
int inputNonlocalValue(int GID, double value, bool accumulate)
virtual Real linfty_norm() const override
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.
void destroyNonlocalData()
virtual void localize(std::vector< T > &v_local) const override
Creates a copy of the global vector in the local vector v_local.
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)
Accumulate values into the vector, adding them to any values that already exist for the specified ind...
virtual Real l2_norm() const override
void FEoperatorequals(const EpetraVector &source)
int * numeric_trilinos_cast(const numeric_index_type *p)
virtual void scale(const T factor) override
Scale each element of the vector by the given factor.
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]...
This class provides a nice interface to the Epetra data structures for parallel, sparse matrices...
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
EpetraVector & operator=(const EpetraVector &)=delete