41 #include <EpetraExt_MultiVectorOut.h> 44 #include <lifev/core/LifeV.hpp> 45 #include <lifev/core/array/VectorEpetra.hpp> 68 ASSERT (M_epetraMap->map(M_mapType).get()!=0,
"Error! The stored MapEpetra does not have valid map pointer.\n");
70 M_epetraVector.reset(
new vector_type ( *M_epetraMap->map (M_mapType) ) );
80 ASSERT (M_epetraMap->map(M_mapType).get()!=0,
"Error! The stored MapEpetra does not have valid map pointer.\n");
82 M_epetraVector.reset(
new vector_type ( *M_epetraMap->map (M_mapType) ) );
90 if (vector.epetraVectorPtr().get()!=0)
91 M_epetraVector.reset(
new vector_type ( vector.epetraVector() ) );
99 ASSERT (M_epetraMap->map(M_mapType).get()!=0,
"Error! The stored MapEpetra does not have valid map pointer.\n");
101 M_epetraVector.reset(
new vector_type ( *M_epetraMap->map ( M_mapType ) ) );
112 ASSERT (M_epetraMap->map(M_mapType).get()!=0,
"Error! The stored MapEpetra does not have valid map pointer.\n");
114 M_epetraVector.reset(
new vector_type ( *M_epetraMap->map ( M_mapType ) ) );
118 *M_epetraVector = vector.epetraVector();
127 M_epetraVector->Export ( vector.epetraVector(), M_epetraMap->importer(), combineMode );
130 M_epetraVector->Import ( vector.epetraVector(), M_epetraMap->exporter(), combineMode );
136 const std::shared_ptr<MapEpetra> map,
143 ASSERT (M_epetraMap->map(M_mapType).get()!=0,
"Error! The stored MapEpetra does not have valid map pointer.\n");
145 assert ( M_epetraMap->map ( mapType )->SameAs (vector.Map() ) );
147 M_epetraVector.reset(
new vector_type ( *M_epetraMap->map ( mapType ) ) );
148 M_epetraVector->Update (1., vector, 0.);
155 ASSERT (vector.map().map(M_mapType).get()!=0,
"Error! The stored MapEpetra does not have valid map pointer.\n");
157 M_epetraMap = vector.M_epetraMap->createRootMap ( reduceToProc );
159 M_epetraVector.reset(
new vector_type ( *M_epetraMap->map (M_mapType) ) );
170 Int lrow = blockMap().LID (
static_cast<EpetraInt_Type> (row));
172 #ifdef HAVE_LIFEV_DEBUG 175 std::cout << M_epetraVector->Comm().MyPID() <<
" " << row <<
" " << lrow << std::endl;
176 ERROR_MSG (
"VectorEpetra::operator [] ERROR : !! lrow < 0\n" );
180 return (*M_epetraVector) [0][lrow];
186 Int lrow = blockMap().LID (
static_cast<EpetraInt_Type> (row));
188 #ifdef HAVE_LIFEV_DEBUG 191 std::cout << M_epetraVector->Comm().MyPID() <<
" " << row <<
" " << lrow << std::endl;
192 ERROR_MSG (
"VectorEpetra::operator () ERROR : !! lrow < 0\n" );
197 return ( (*M_epetraVector) [0][lrow]);
223 if ( blockMap().SameAs ( vector.blockMap() ) )
225 *M_epetraVector = vector.epetraVector();
232 if ( M_epetraMap.get() && vector.M_epetraMap.get() &&
233 M_epetraMap->mapsAreSimilar ( *vector.M_epetraMap ) )
241 M_epetraVector->Export (vector.epetraVector(), M_epetraMap->importer(), M_combineMode);
244 M_epetraVector->Import (vector.epetraVector(), M_epetraMap->exporter(), M_combineMode);
253 return Export (vector.epetraVector(), M_combineMode);
256 return Import (vector.epetraVector(), M_combineMode);
262 std::cout <<
"Tentative of export import from two repeated vectors based on different maps." 266 vectorUnique.Export ( vector.epetraVector(), M_combineMode );
267 M_epetraVector->Import ( vectorUnique.epetraVector(), M_epetraMap->exporter(), M_combineMode );
277 Epetra_FEVector
const* feVec (
dynamic_cast<Epetra_FEVector
const*> (&vector) );
284 return Export ( *feVec, M_combineMode );
286 return Import ( *feVec, M_combineMode );
295 M_epetraVector->PutScalar (scalar);
303 if (
this->blockMap().SameAs ( vector.blockMap() ) )
305 M_epetraVector->Update ( 1., vector.epetraVector(), 1. );
310 M_epetraVector->Update ( 1., vCopy.epetraVector(), 1. );
319 if (
this->blockMap().SameAs ( vector.blockMap() ) )
321 M_epetraVector->Update ( -1., vector.epetraVector(), 1. );
326 M_epetraVector->Update ( -1., vCopy.epetraVector(), 1. );
335 if (
this->blockMap().SameAs ( vector.blockMap() ) )
337 M_epetraVector->Multiply ( 1.0, vector.epetraVector(), *M_epetraVector, 0.0 );
342 M_epetraVector->Multiply ( 1.0, vectorCopy.epetraVector(), *M_epetraVector, 0.0 );
351 if (
this->blockMap().SameAs ( vector.blockMap() ) )
353 M_epetraVector->ReciprocalMultiply ( 1.0, vector.epetraVector(), *M_epetraVector, 0.0 );
358 M_epetraVector->ReciprocalMultiply ( 1.0, vectorCopy.epetraVector(), *M_epetraVector, 0.0 );
369 MyVectorCopy
+= vector;
379 MyVectorCopy
-= vector;
389 MyVectorCopy
*= vector;
399 MyVectorCopy
/= vector;
408 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
409 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
411 (*M_epetraVector) [i][j] += scalar;
428 M_epetraVector->Scale ( scalar );
446 MyVectorCopy
+= scalar;
456 MyVectorCopy
-= scalar;
466 MyVectorCopy
*= scalar;
476 MyVectorCopy
/= scalar;
484 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
487 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
488 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
490 comparisonVector.epetraVector() [i][j] = (*M_epetraVector) [i][j] == scalar ?
true :
false;
493 return comparisonVector;
499 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
502 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
503 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
505 comparisonVector.epetraVector() [i][j] = (*M_epetraVector) [i][j] != scalar ?
true :
false;
508 return comparisonVector;
514 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
517 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
518 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
520 comparisonVector.epetraVector() [i][j] = (*M_epetraVector) [i][j] < scalar ?
true :
false;
523 return comparisonVector;
529 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
532 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
533 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
535 comparisonVector.epetraVector() [i][j] = (*M_epetraVector) [i][j] > scalar ?
true :
false;
538 return comparisonVector;
544 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
547 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
548 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
550 comparisonVector.epetraVector() [i][j] = (*M_epetraVector) [i][j] <= scalar ?
true :
false;
553 return comparisonVector;
559 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
562 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
563 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
565 comparisonVector.epetraVector() [i][j] = (*M_epetraVector) [i][j] >= scalar ?
true :
false;
568 return comparisonVector;
574 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
577 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
578 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
580 comparisonVector.epetraVector() [i][j] = (*M_epetraVector) [i][j] && vector.epetraVector() [i][j];
583 return comparisonVector;
589 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
592 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
593 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
595 comparisonVector.epetraVector() [i][j] = (*M_epetraVector) [i][j] || vector.epetraVector() [i][j];
598 return comparisonVector;
604 VectorEpetra comparisonVector ( *M_epetraMap, M_mapType );
607 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
608 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
610 comparisonVector.epetraVector() [i][j] = ! (*M_epetraVector) [i][j];
613 return comparisonVector;
622 return blockMap().LID (
static_cast<EpetraInt_Type> (row) ) >= 0;
627 Int lrow = blockMap().LID (
static_cast<EpetraInt_Type> (row) );
629 if ( lrow < 0 && blockMap().Comm().NumProc() == 1 )
631 std::cout << M_epetraVector->Comm().MyPID() <<
" " << row <<
" " << lrow << std::endl;
632 ERROR_MSG (
"VectorEpetra::globalToLocalRowId ERROR : !! lrow < 0\n" );
646 (*M_epetraVector) [0][lrow] = value;
652 ASSERT ( rowsVector.size() == valuesVector.size(),
"Error: rowsVector and valuesVector should have the same size" );
653 ASSERT ( M_mapType == Unique,
"Error: Vector must have a unique map" );
658 const Epetra_Comm& Comm ( M_epetraVector->Comm() );
659 Int numProcs ( Comm.NumProc() );
660 Int MyPID ( Comm.MyPID() );
670 for (
Int p (0); p < numProcs; p++ )
672 Int sizeVec (
static_cast<Int> ( rowsVector.size() ) );
673 if ( sizeVec !=
static_cast<Int> ( valuesVector.size() ) )
676 ERROR_MSG (
"diagonalize: vectors must be of the same size\n" );
679 Comm.Broadcast (&sizeVec, 1, p);
683 r = &rowsVector.front();
684 datum = &valuesVector.front();
688 r =
new Int [sizeVec];
692 Comm.Broadcast (r, sizeVec, p);
693 Comm.Broadcast (datum, sizeVec, p);
696 for (i = 0; i < sizeVec; ++i)
715 return M_epetraVector->SumIntoGlobalValues ( 1, &GID, &value );
722 Int numMyEntries = vector.M_epetraVector->MyLength ();
723 const Int* gids = vector.blockMap().MyGlobalElements();
726 for (
Int i = 0; i < numMyEntries; ++i )
738 Int numMyEntries = vector.M_epetraVector->MyLength ();
739 const Int* globalIDs = vector.blockMap().MyGlobalElements();
742 for (
Int i (0); i < numMyEntries; ++i )
767 return subset ( vector.epetraVector(), map, offset1, offset2 );
777 const Int* gids = map.map (M_mapType)->MyGlobalElements();
778 const UInt numMyEntries = map.map (M_mapType)->NumMyElements();
784 for (
UInt i = 0; i < numMyEntries; ++i )
786 lid1 = vector.Map().LID (
static_cast<EpetraInt_Type> (gids[i] + offset1) );
787 lid2 = blockMap().LID (
static_cast<EpetraInt_Type> (gids[i] + offset2) );
788 ASSERT ( ( lid2 >= 0 ) && ( lid1 >= 0 ),
"VectorEpetra::subset ERROR : !! lid < 0\n" );
789 (*M_epetraVector) [0][lid2] = vector[column][lid1];
798 M_epetraVector->MeanValue (result);
805 M_epetraVector->Norm1 (&result);
825 M_epetraVector->Norm1 (&result);
833 M_epetraVector->Norm2 (&result);
853 M_epetraVector->Norm2 ( &result );
860 M_epetraVector->NormInf (&result);
867 M_epetraVector->NormInf (result);
873 M_epetraVector->NormInf (&result);
880 M_epetraVector->MinValue (&result);
888 M_epetraVector->MaxValue (&result);
895 M_epetraVector->MinValue (result);
901 M_epetraVector->MaxValue (result);
907 M_epetraVector->MinValue (&result);
913 M_epetraVector->MaxValue (&result);
919 M_epetraVector->Abs ( *M_epetraVector );
925 vector.M_epetraVector->Abs ( *M_epetraVector );
931 for ( Int i (0); i < M_epetraVector->NumVectors(); ++i )
933 for ( Int j (0); j < M_epetraVector->MyLength(); ++j )
935 (*M_epetraVector) [i][j] = std::sqrt ( (*M_epetraVector) [i][j] );
945 M_epetraVector->Dot ( vector.epetraVector(), &scalarProduct );
947 return scalarProduct;
953 M_epetraVector->Dot ( vector.epetraVector(), &scalarProduct );
956 void VectorEpetra::matrixMarket ( std::string
const& fileName,
const bool headers )
const 959 std::string name = fileName;
960 std::string desc =
"Created by LifeV";
965 unique.spy (fileName);
969 name = fileName +
".mtx";
971 EpetraExt::MultiVectorToMatrixMarketFile ( name.c_str(),
981 std::string name = fileName;
983 Int me = M_epetraVector->Comm().MyPID();
988 unique.spy ( fileName );
993 std::ostringstream myStream;
995 name = fileName +
".m";
997 EpetraExt::MultiVectorToMatlabFile ( name.c_str(), *M_epetraVector );
1005 if ( redVec.M_epetraVector->Comm().MyPID() )
1010 const Real* Values = redVec.epetraVector() [0];
1011 for ( Int i = 0; i < redVec.M_epetraVector->GlobalLength () ; ++i )
1013 output << Values[i] << std::endl;
1020 for ( i = 0; i < M_epetraVector->NumVectors(); ++i )
1021 for ( j = 0; j < M_epetraVector->MyLength(); ++j )
1023 (*M_epetraVector) [i][j] = f ( (*M_epetraVector) [i][j]);
1040 setCombineMode (Add);
1046 M_epetraMap.reset (
new MapEpetra ( map ) );
1047 M_epetraVector.reset (
new vector_type ( *M_epetraMap->map (M_mapType) ) );
1056 if ( M_epetraVector.get() )
1058 return M_epetraVector->GlobalLength();
1069 if ( &vector == &
this->epetraVector() )
1074 if ( blockMap().SameAs (vector.Map() ) )
1076 *M_epetraVector = vector;
1082 Epetra_Export reducedExport ( blockMap(), vector.Map() );
1083 M_epetraVector->Import ( vector, reducedExport, combineMode );
1091 if ( &vector == &
this->epetraVector() )
1096 if ( blockMap().SameAs (vector.Map() ) )
1098 *M_epetraVector = vector;
1104 Epetra_Import reducedImport ( vector.Map(), blockMap() );
1105 M_epetraVector->Export (vector, reducedImport, combineMode);
1123 return VectorCopy
+= scalar;
1131 return VectorCopy
+= scalar;
1139 return VectorCopy
*= scalar;
VectorEpetra & operator-=(const data_type &scalar)
Subtraction operator.
bool isGlobalIDPresent(const UInt row) const
Access operators.
VectorEpetra - The Epetra Vector format Wrapper.
VectorEpetra operator*(const VectorEpetra::data_type &scalar, const VectorEpetra &vector)
void normInf(Real *result) const
Compute and store the norm inf in the given pointed variable.
void minValue(Real *result) const
Compute and store the minimum value of the vector in the given pointed variable.
Epetra_CombineMode combineMode_Type
VectorEpetra operator-(const VectorEpetra::data_type &scalar, const VectorEpetra &vector)
const VectorEpetra operator*(const data_type &scalar) const
Multiplication operator.
VectorEpetra & operator+=(const data_type &scalar)
Addition operator.
VectorEpetra operator>=(const Real &scalar) const
Greater than or equal to operator.
const VectorEpetra operator-(const VectorEpetra &vector) const
Subtraction operator.
VectorEpetra(const VectorEpetra &vector, const MapEpetraType &mapType)
Copy constructor.
VectorEpetra & subset(const Epetra_MultiVector &vector, const MapEpetra &map, const UInt offset1, const UInt offset2, const UInt column=0)
Set the current vector to a subset of vector with an offset.
VectorEpetra & subset(const VectorEpetra &vector, const UInt offset=0)
Set the current vector to a subset of the given vector with an offset.
data_type & operator()(const UInt row)
Access operators.
const VectorEpetra operator+(const data_type &scalar) const
Operations with scalar values (do not modify the vector of the class)
VectorEpetra & add(const VectorEpetra &vector, const Int offset=0)
Add a vector to the current vector with an offset.
data_type dot(const VectorEpetra &vector) const
Compute the scalar product of two vectors.
vectorPtr_Type M_epetraVector
void abs(void)
Replace the vector with his absolute value.
VectorEpetra & Export(const Epetra_FEVector &vector, combineMode_Type combineMode)
Export the value of a vector.
bool setCoefficient(const UInt row, const data_type &value, UInt offset=0)
Look for the given global row and set its value.
void abs(VectorEpetra &vector)
Compute the absolute value of a vector and store it in an other vector.
VectorEpetra & Import(const Epetra_FEVector &vector, combineMode_Type combineMode)
Import the value of a vector.
Int globalToLocalRowId(const UInt row) const
Return the local Id of a global row.
Real norm1() const
Compute and return the norm 1.
int32_type Int
Generic integer data.
void dot(const VectorEpetra &vector, data_type &scalarProduct)
Compute the scalar product of two vectors and store the result in a given variable.
void maxValue(Real &result) const
Compute and store the maximum value of the vector in the given variable.
MapEpetraType mapType() const
Return the map type of the vector (Unique or Repeated)
const data_type & operator[](const UInt row) const
Access operators.
VectorEpetra(const MapEpetra &map, const MapEpetraType &mapType=Unique, const combineMode_Type combineMode=Add)
Constructor - Using Maps.
void updateInverseJacobian(const UInt &iQuadPt)
VectorEpetra & operator/=(const data_type &scalar)
Division operator.
const VectorEpetra operator-(const data_type &scalar) const
Subtraction operator.
VectorEpetra operator!(void) const
Logical NOT operator.
VectorEpetra operator-(const VectorEpetra &vector)
void apply(const std::function< Real(Real)> &f)
VectorEpetra & operator*=(const VectorEpetra &vector)
Multiplication operator.
void setCombineMode(combineMode_Type combineMode)
Sets the combine mode for the import/export operations.
VectorEpetra operator &&(const VectorEpetra &vector) const
Logical AND operator.
VectorEpetra operator||(const VectorEpetra &vector) const
Logical OR operator.
VectorEpetra & operator+=(const VectorEpetra &vector)
Addition operator.
Epetra_Import const & importer()
Getter for the Epetra_Import.
Real normInf() const
Compute and return the norm inf.
VectorEpetra(const MapEpetraType &mapType=Unique, const combineMode_Type combineMode=Add)
Empty Constructor.
void norm2(Real *result) const
Compute and store the norm 2 in the given pointed variable.
VectorEpetra operator>(const Real &scalar) const
Greater than operator.
VectorEpetra & replace(const VectorEpetra &vector, const Int &offset)
Replace part of the vector with a given vector.
const VectorEpetra operator+(const VectorEpetra &vector) const
Addition operator.
const MapEpetra & map() const
Return the MapEpetra of the vector.
void sqrt()
Apply the square root to of each element in the vector.
Int setCoefficients(std::vector< Int > &rowsVector, std::vector< Real > &valuesVector)
Set the row of the vector to the given value.
VectorEpetra operator+(const VectorEpetra::data_type &scalar, const VectorEpetra &vector)
void norm1(Real *result) const
Compute and store the norm 1 in the given pointed variable.
VectorEpetra & operator-=(const VectorEpetra &vector)
Subtraction operator.
VectorEpetra & operator=(data_type scalar)
Affectation operator.
vector_type & epetraVector()
Return the VectorEpetra in the wrapper.
Real minValue() const
Compute and return the minimum value in the vector.
Real maxValue() const
Compute and return the maximum value in the vector.
Int size() const
Return the size of the vector.
double Real
Generic real data.
const VectorEpetra operator/(const data_type &scalar) const
Division operator.
VectorEpetra(const VectorEpetra &vector, const Int &reduceToProc)
Copy constructor.
VectorEpetra(const std::shared_ptr< MapEpetra > &mapPtr, const MapEpetraType &mapType=Unique, const combineMode_Type combineMode=Add)
Constructor - Using Maps.
void setDefaultCombineMode()
Sets the combine mode for the import/export operations to default.
VectorEpetra & operator=(const Epetra_MultiVector &vector)
Affectation operator.
void norm2(Real &result) const
Compute and store the norm 2 in the given variable.
const VectorEpetra operator/(const VectorEpetra &vector) const
Division operator.
void maxValue(Real *result) const
Compute and store the maximum value of the vector in the given pointed variable.
VectorEpetra & operator*=(const data_type &scalar)
Multiplication operator.
const vector_type & epetraVector() const
Return the VectorEpetra in the wrapper.
void meanValue(Real *result) const
Compute the mean value of the vector components and store it in the given variable.
VectorEpetra operator==(const Real &scalar) const
Equality operator.
void norm1(Real &result) const
Compute and store the norm 1 in the given variable.
VectorEpetra(const VectorEpetra &vector)
Copy constructor.
VectorEpetra(const Epetra_MultiVector &vector, const std::shared_ptr< MapEpetra > map, const MapEpetraType &mapType, const combineMode_Type combineMode=Add)
Copy constructor.
VectorEpetra & operator=(const VectorEpetra &vector)
Affectation operator.
Int sumIntoGlobalValues(const Int GID, const Real value)
insert a global value
void setMap(const MapEpetra &map)
Sets the map to use for the epetra vector.
void normInf(Real &result) const
Compute and store the norm inf in the given variable.
combineMode_Type M_combineMode
VectorEpetra operator!=(const Real &scalar) const
Inequality operator.
VectorEpetra & subset(const VectorEpetra &vector, const MapEpetra &map, const UInt offset1, const UInt offset2)
Set the current vector to a subset of vector with an offset.
void showMe(std::ostream &output=std::cout) const
Print the contents of the vector.
const VectorEpetra operator*(const VectorEpetra &vector) const
Multiplication operator.
VectorEpetra(const VectorEpetra &vector, const MapEpetraType &mapType, const combineMode_Type &combineMode)
Copy constructor.
int EpetraInt_Type
Epetra int type (can be int or long long, accordingly to release notes)
const data_type & operator()(const UInt row) const
Access operators.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
void minValue(Real &result) const
Compute and store the minimum value of the vector in the given variable.
data_type & operator[](const UInt row)
Access operators.
VectorEpetra & operator/=(const VectorEpetra &vector)
Division operator.
Real norm2() const
Compute and return the norm 2.