39 #ifndef _EPETRAMATRIX_HPP_ 40 #define _EPETRAMATRIX_HPP_ 42 #include <lifev/core/LifeV.hpp> 45 #include <Epetra_MpiComm.h> 46 #include <Epetra_FECrsMatrix.h> 47 #include <Epetra_FECrsGraph.h> 48 #include <EpetraExt_MatrixMatrix.h> 49 #include <EpetraExt_Transpose_RowMatrix.h> 50 #include <EpetraExt_RowMatrixOut.h> 51 #include <ml_epetra_utils.h> 54 #include <EpetraExt_HDF5.h> 58 #include <lifev/core/array/VectorEpetra.hpp> 76 template <
typename DataType>
100 MatrixEpetra (
const MapEpetra& map,
const Epetra_CrsGraph& graph,
bool ignoreNonLocalValues =
false );
107 MatrixEpetra (
const MapEpetra& map,
const Epetra_FECrsGraph& graph,
bool ignoreNonLocalValues =
false);
239 bool transposeMatrix,
241 bool callFillCompleteOnResult =
true )
const;
275 void diagonalize ( std::vector<UInt> rVec, DataType
const coefficient,
UInt offset = 0 );
294 DataType
const coefficient,
296 std::vector<DataType> datumVector,
316 void matrixMarket ( std::string
const& fileName,
const bool headers =
true );
322 void spy ( std::string
const& fileName );
345 void showMe ( std::ostream& output = std::cout )
const;
371 const std::shared_ptr<
const MapEpetra>& rangeMap );
468 M_epetraCrs->PutScalar (0.);
481 std::vector<Int>
const& rowIndices, std::vector<Int>
const& columnIndices,
482 DataType*
const*
const localValues,
502 std::vector<Int>
const& rowIndices, std::vector<Int>
const& columnIndices,
503 DataType*
const*
const localValues,
516 std::vector<Int>
const& rowIndices,
517 std::vector<Int>
const& columnIndices,
518 DataType*
const*
const localValues,
535 M_epetraCrs->SetUseTranspose ( transpose );
547 return M_epetraCrs->Filled();
603 void restrict (
const std::shared_ptr<MapEpetra>& map,
604 const std::shared_ptr<VectorEpetra>& numeration,
606 std::shared_ptr<MatrixEpetra<DataType> > & matrix_out );
614 template <
typename DType>
619 template <
typename DType>
654 template <
typename DataType>
662 template <
typename DataType>
670 template <
typename DataType>
678 template <
typename DataType>
686 template <
typename DataType>
696 template <
typename DataType>
703 Epetra_Export reducedExport ( M_epetraCrs->Map(), matrix.M_epetraCrs->Map() );
704 M_epetraCrs->Import ( *matrix.M_epetraCrs, reducedExport, Add );
706 if (M_epetraCrs->Filled() )
708 M_domainMap = matrix.getDomainMap().createRootMap (reduceToProc);
709 M_rangeMap = matrix.getRangeMap().createRootMap (reduceToProc);
713 template <
typename DataType>
722 template <
typename DataType>
736 template <
typename DataType>
740 EpetraExt::MatrixMatrix::Add ( *matrix.matrixPtr(),
false, 1., *
this->matrixPtr(), 1. );
745 template <
typename DataType>
749 EpetraExt::MatrixMatrix::Add ( *matrix.matrixPtr(),
false, -1., *
this->matrixPtr(), 1. );
754 template<
typename DataType>
757 M_map = matrix.M_map;
758 M_domainMap = matrix.M_domainMap;
759 M_rangeMap = matrix.M_rangeMap;
760 *M_epetraCrs = * ( matrix.M_epetraCrs );
765 template<
typename DataType>
770 "MatrixEpetra::Operator*: globalAssemble(...) should be called first" );
771 ASSERT_PRE ( vector.map().mapsAreSimilar (*M_domainMap),
772 "MatrixEpetra::Operator*: the map of vec is not the same of domainMap" );
774 "MatrixEpetra::Operator*: the rangeMap is not set" );
777 M_epetraCrs->Apply ( vector.epetraVector(), result.epetraVector() );
783 template<
typename DataType>
787 M_epetraCrs->Scale ( value );
791 template<
typename DataType>
796 return matrix *= scalar;
802 template <
typename DataType>
805 if ( M_epetraCrs->Filled() )
807 Int meanNumEntries =
this->meanNumEntries();
809 M_epetraCrs.reset (
new matrix_type ( Copy, M_epetraCrs->RowMap(), meanNumEntries ) );
811 EpetraExt::MatrixMatrix::Add ( *tmp,
false, 1., *M_epetraCrs, 1. );
819 template <
typename DataType>
822 if ( M_epetraCrs->Filled() )
824 Int meanNumEntries =
this->meanNumEntries();
826 M_epetraCrs.reset (
new matrix_type ( Copy, M_epetraCrs->RowMap(), meanNumEntries ) );
834 for ( Int i (0); i < tmp->NumGlobalRows(); ++i )
836 row = tmp->LRID (
static_cast<EpetraInt_Type> (i) );
842 tmp->ExtractMyRowView ( row, NumEntries, Values, Indices );
844 std::vector<Int> Indices2 ( NumEntries );
845 std::vector<Real> Values2 ( NumEntries );
848 for (Int j (0); j < NumEntries; ++j)
850 if (Values[j] != 0.0)
852 Indices2[NumEntries2] = tmp->GCID (Indices[j]);
853 Values2[NumEntries2] = Values[j];
857 M_epetraCrs->InsertGlobalValues ( i, NumEntries2, &Values2[0], &Indices2[0] );
860 M_epetraCrs->GlobalAssemble();
864 template <
typename DataType>
867 M_epetraCrs.swap ( matrixPtr );
871 template <
typename DataType>
874 M_epetraCrs.swap ( matrix.M_epetraCrs );
877 template <
typename DataType>
879 const MatrixEpetra<DataType>& matrix,
bool transposeMatrix,
880 MatrixEpetra<DataType>& result,
bool callFillCompleteOnResult )
const 882 Int errCode = EpetraExt::MatrixMatrix::Multiply ( *M_epetraCrs, transposeCurrent,
883 *matrix.matrixPtr(), transposeMatrix,
884 *result.matrixPtr(),
false );
885 if (callFillCompleteOnResult)
887 std::shared_ptr<
const MapEpetra> domainMap, rangeMap;
888 if (transposeCurrent)
890 rangeMap = M_domainMap;
894 rangeMap = M_rangeMap;
899 domainMap = matrix.M_rangeMap;
903 domainMap = matrix.M_domainMap;
906 result.globalAssemble (domainMap, rangeMap);
912 template <
typename DataType>
916 "MatrixEpetra<DataType>::Multiply: GlobalAssemble(...) must be called first" );
917 ASSERT_PRE ( transposeCurrent ? vector1.map().mapsAreSimilar (*M_rangeMap) : vector1.map().mapsAreSimilar (*M_domainMap),
918 "MatrixEpetra<DataType>::Multiply: x map is different from M_domainMap (or M_rangeMap if transposeCurrent == true)" );
919 ASSERT_PRE ( transposeCurrent ? vector2.map().mapsAreSimilar (*M_domainMap) : vector2.map().mapsAreSimilar (*M_rangeMap),
920 "MatrixEpetra<DataType>::Multiply: y map is different from M_rangeMap (or M_domainMap if transposeCurrent == true)" );
923 return M_epetraCrs->Multiply ( transposeCurrent, vector1.epetraVector(), vector2.epetraVector() );
926 template <
typename DataType>
930 if ( M_epetraCrs->Filled() )
932 if ( M_epetraCrs->Comm().MyPID() == 0 )
934 std::cout <<
"ERROR: Matrix already filled: cannot add dyadic product!" << std::endl;
940 std::vector<Int> myGlobalElements ( uniqueVector2.size() );
941 for ( UInt i = 0 ; i < myGlobalElements.size() ; ++i )
943 myGlobalElements[i] = i;
947 MapEpetra repeatedMap ( -1,
static_cast< Int > ( myGlobalElements.size() ), &myGlobalElements[0], uniqueVector2.map().commPtr() );
951 repeatedVector2
= uniqueVector2;
954 for ( Int row (0); row < M_epetraCrs->NumMyRows(); ++row )
955 for ( Int column (0); column < M_epetraCrs->NumGlobalCols(); ++column )
957 addToCoefficient ( M_epetraCrs->GRID ( row ), column, uniqueVector1[M_epetraCrs->GRID ( row )] * repeatedVector2[column] );
961 template <
typename DataType>
964 EpetraExt::MatrixMatrix::Add ( *matrix.matrixPtr(),
false, scalar, *
this->matrixPtr(), 1. );
967 template <
typename DataType>
970 ASSERT_PRE (M_epetraCrs->Filled(),
"The transpose can be formed only if the matrix is already filled!");
971 std::shared_ptr<Epetra_FECrsMatrix> transposedFE;
972 transposedFE.reset (
new Epetra_FECrsMatrix (Copy, M_epetraCrs->OperatorDomainMap(), M_epetraCrs->OperatorRangeMap(), 0,
false) );
973 EpetraExt::RowMatrix_Transpose transposer;
974 *
dynamic_cast<Epetra_CrsMatrix*> (& (*transposedFE) ) =
dynamic_cast<Epetra_CrsMatrix&> (transposer (*M_epetraCrs) );
975 transposedFE->FillComplete();
976 std::shared_ptr<MatrixEpetra<DataType> > transposedMatrix (
new MatrixEpetra<DataType> (*M_domainMap) );
977 transposedMatrix->globalAssemble (M_rangeMap, M_domainMap);
978 transposedMatrix->matrixPtr() = transposedFE;
980 return transposedMatrix;
983 template <
typename DataType>
987 const Epetra_Comm& Comm ( M_epetraCrs->Comm() );
988 Int numProcs ( Comm.NumProc() );
989 Int MyPID ( Comm.MyPID() );
1001 for (
Int p (0); p < numProcs; p++ )
1003 Int sizeVec ( rVec.size() );
1005 Comm.Broadcast ( &sizeVec, 1, p );
1013 Ur =
new UInt[sizeVec];
1018 Comm.Broadcast ( r, sizeVec, p );
1020 for ( i = 0; i < sizeVec; i++ )
1022 diagonalize ( Ur[i], coefficient, offset );
1034 template <
typename DataType>
1036 DataType
const coefficient,
1040 if ( !M_epetraCrs->Filled() )
1043 ERROR_MSG (
"if not filled, I do not know how to diagonalize\n" );
1046 const Epetra_Map& rowMap ( M_epetraCrs->RowMap() );
1047 const Epetra_Map& colMap ( M_epetraCrs->ColMap() );
1050 Int myCol = colMap.LID (
static_cast<EpetraInt_Type> (row + offset) );
1053 Int myRow = rowMap.LID (
static_cast<EpetraInt_Type> (row + offset) );
1061 M_epetraCrs->ExtractMyRowView ( myRow, NumEntries, Values, Indices );
1063 for (
Int i (0); i < NumEntries; i++)
1068 DataType coeff ( coefficient );
1069 M_epetraCrs->ReplaceMyValues ( myRow, 1, &coeff, &myCol );
1074 template <
typename DataType>
1076 DataType
const coefficient,
1078 std::vector<DataType> datumVec,
1083 const Epetra_Comm& Comm ( M_epetraCrs->Comm() );
1084 Int numProcs ( Comm.NumProc() );
1085 Int MyPID ( Comm.MyPID() );
1098 Int me = Comm.MyPID();
1100 std::vector<Int> localIDs;
1101 std::vector<Int> remoteIDs;
1103 std::vector<Real> localData;
1104 std::vector<Real> remoteData;
1106 std::map<Int, Real> localBC;
1107 std::map<Int, Real>::iterator im;
1109 const Epetra_Map& rowMap ( M_epetraCrs->RowMap() );
1115 for ( Int ii = 0; ii < (Int) rVec.size(); ++ii )
1117 Int lID = rowMap.LID (
static_cast<EpetraInt_Type> (rVec[ii]) );
1118 if ( ! ( lID < 0 ) )
1121 localIDs.push_back ( rVec[ii] );
1122 localData.push_back ( datumVec[ii] );
1123 localBC.insert ( std::pair<Int, Real> ( rVec[ii], datumVec[ii] ) );
1127 remoteIDs.push_back ( rVec[ii] );
1128 remoteData.push_back ( datumVec[ii] );
1136 Int numIDs = remoteIDs.size();
1138 Int* PIDList =
new Int[numIDs];
1139 Int* LIDList =
new Int[numIDs];
1141 rowMap.RemoteIDList ( numIDs,
1146 std::vector< std::vector<Int> > procToID ( Comm.NumProc() );
1147 std::vector< std::vector<Real> > procToData ( Comm.NumProc() );
1149 for (
Int ii = 0; ii < numIDs; ++ii )
1151 Int pi = PIDList[ii];
1152 procToID[pi].push_back ( remoteIDs[ii] );
1153 procToData[pi].push_back ( remoteData[ii] );
1158 const Epetra_MpiComm* comm =
dynamic_cast<Epetra_MpiComm
const*> ( &Comm );
1160 assert ( comm != 0 );
1162 for ( Int ii = 0; ii < (Int) procToID.size(); ++ii )
1167 length = procToID[ii].size();
1168 MPI_Send ( &length, 1, MPI_INT, ii, 666, comm->Comm() );
1171 MPI_Send ( &procToID[ii][0], length, MPI_INT, ii, 667, comm->Comm() );
1172 MPI_Send ( &procToData[ii][0], length, MPI_DOUBLE, ii, 668, comm->Comm() );
1178 for ( Int ii = 0; ii < (Int) procToID.size(); ++ii )
1184 MPI_Recv ( &length, 1, MPI_INT, ii, 666, comm->Comm(), &status );
1189 Int* bufferID =
new Int[length];
1192 MPI_Recv ( bufferID, length, MPI_INT, ii, 667, comm->Comm(), &status );
1196 Real* bufferData =
new Real[length];
1199 MPI_Recv ( bufferData, length, MPI_DOUBLE, ii, 668, comm->Comm(), &status );
1200 ptrData = bufferData;
1202 for ( Int ii = 0; ii < length; ++ii, ++ptrID, ++ptrData )
1204 localBC.insert ( std::pair<Int, Real>
1205 ( *ptrID, *ptrData ) );
1209 delete[] bufferData;
1219 for ( im = localBC.begin(); im != localBC.end(); ++im )
1221 diagonalize ( im->first, coefficient, rhs, im->second, offset );
1229 for (
Int p (0); p < numProcs; p++ )
1231 Int sizeVec (rVec.size() );
1232 if ( sizeVec != Int (datumVec.size() ) )
1235 ERROR_MSG (
"diagonalize: vectors must be of the same size\n" );
1238 Comm.Broadcast ( &sizeVec, 1, p );
1243 datum = &datumVec.front();
1247 Ur =
new UInt [sizeVec];
1248 datum =
new DataType[sizeVec];
1253 Comm.Broadcast ( r, sizeVec, p );
1254 Comm.Broadcast ( datum, sizeVec, p );
1256 for ( i = 0; i < sizeVec; i++ )
1258 diagonalize ( Ur[i], coefficient, rhs, datum[i], offset );
1271 template <
typename DataType>
1273 DataType
const coefficient,
1279 if ( !M_epetraCrs->Filled() )
1282 ERROR_MSG (
"if not filled, I do not know how to diagonalize\n" );
1285 const Epetra_Map& rowMap ( M_epetraCrs->RowMap() );
1286 const Epetra_Map& colMap ( M_epetraCrs->ColMap() );
1289 Int myCol = colMap.LID (
static_cast<EpetraInt_Type> (row + offset) );
1291 #ifdef EPETRAMATRIX_SYMMETRIC_DIAGONALIZE 1295 for ( Int i (0); i < rowMap.NumMyElements(); i++ )
1299 M_epetraCrs->ReplaceMyValues (i, 1, &zero, &myCol);
1305 Int myRow = rowMap.LID (
static_cast<EpetraInt_Type> (row + offset) );
1313 M_epetraCrs->ExtractMyRowView ( myRow, NumEntries, Values, Indices );
1315 for (
Int i (0); i < NumEntries; i++ )
1320 DataType coeff ( coefficient );
1322 M_epetraCrs->ReplaceMyValues ( myRow, 1, &coeff, &myCol );
1329 template <
typename DataType>
1333 std::string name = fileName;
1334 std::string desc =
"Created by LifeV";
1336 name = fileName +
".mtx";
1338 EpetraExt::RowMatrixToMatrixMarketFile ( name.c_str(),
1346 template <
typename DataType>
1350 std::string name = fileName, uti =
" , ";
1352 Int me = M_epetraCrs->Comm().MyPID();
1353 std::ostringstream myStream;
1355 name = fileName +
".m";
1357 EpetraExt::RowMatrixToMatlabFile ( name.c_str(), *M_epetraCrs );
1421 template <
typename DataType>
1424 output <<
"showMe must be implemented for the MatrixEpetra class" << std::endl;
1427 template <
typename DataType>
1430 if ( !M_epetraCrs->Filled() )
1434 M_domainMap = M_map;
1436 return M_epetraCrs->GlobalAssemble();
1439 template <
typename DataType>
1442 if ( !M_epetraCrs->Filled() )
1446 M_domainMap = M_map;
1448 return M_epetraCrs->FillComplete();
1451 template <
typename DataType>
1453 const std::shared_ptr<
const MapEpetra>& rangeMap )
1456 if ( !M_epetraCrs->Filled() && domainMap->mapsAreSimilar ( *rangeMap) )
1462 M_domainMap = domainMap;
1463 M_rangeMap = rangeMap;
1464 return M_epetraCrs->GlobalAssemble ( *domainMap->map (Unique), *rangeMap->map (Unique) );
1467 template <
typename DataType>
1470 for ( Int i = 0 ; i < Map.map (Unique)->NumMyElements(); ++i )
1472 addToCoefficient ( offset + Map.map (Unique)->GID (i) , offset + Map.map (Unique)->GID (i), entry );
1476 template <
typename DataType>
1479 if ( M_epetraCrs->Filled() )
1481 if ( M_epetraCrs->Comm().MyPID() == 0 )
1483 std::cout <<
"Matrix is already filled, it is impossible to insert the diagonal now" << std::endl;
1495 from = M_epetraCrs->RowMap().MinMyGID ();
1496 to = M_epetraCrs->RowMap().MaxMyGID () + 1;
1499 Int* p = M_epetraCrs->RowMap().MyGlobalElements();
1502 for ( Int i (0); i < M_epetraCrs->RowMap().NumMyElements(); ++i, ++p )
1504 if ( *p < from || *p >= to )
1509 ierr = M_epetraCrs->InsertGlobalValues ( 1, p, 1, p, &value );
1513 std::cerr <<
" error in matrix insertion " << ierr << std::endl;
1518 template <
typename DataType>
1521 insertValueDiagonal ( 1.0, from, to );
1524 template <
typename DataType>
1527 insertValueDiagonal ( 0.0, from, to );
1530 template <
typename DataType>
1533 return M_epetraCrs->NormOne();
1536 template <
typename DataType>
1539 return M_epetraCrs->NormInf();
1542 template <
typename DataType>
1545 return M_epetraCrs->NormFrobenius();
1551 template <
typename DataType>
1554 std::vector<Int>
const& rowIndices, std::vector<Int>
const& columnIndices,
1555 DataType*
const*
const localValues,
1559 ierr = M_epetraCrs->ReplaceGlobalValues ( numRows, &rowIndices[0], numColumns, &columnIndices[0], localValues, format );
1561 if ( ierr < 0 ) std::cout <<
" error in matrix insertion [setCoefficients] " << ierr
1562 <<
" when inserting in (" << rowIndices[0] <<
", " << columnIndices[0] <<
")" << std::endl;
1567 template <
typename DataType>
1572 Int icol ( column );
1574 Int ierr = M_epetraCrs->ReplaceGlobalValues ( 1, &irow, 1, &icol, &localValue );
1577 std::cerr <<
" error in matrix replacement " << ierr << std::endl;
1582 template <
typename DataType>
1587 Int irow =
static_cast<
Int> (row);
1588 Int icol =
static_cast<
Int> (column);
1590 Int ierr = ( M_epetraCrs->Filled() ) ?
1591 M_epetraCrs->SumIntoGlobalValues ( 1, &irow, 1, &icol, &localValue )
1593 M_epetraCrs->InsertGlobalValues ( 1, &irow, 1, &icol, &localValue );
1595 std::stringstream errorMessage;
1596 errorMessage <<
" error in matrix insertion [addToCoefficient] " << ierr
1597 <<
" when inserting " << localValue <<
" in (" << irow <<
", " << icol <<
")" << std::endl;
1598 ASSERT ( ierr >= 0, errorMessage.str() );
1602 template <
typename DataType>
1605 std::vector<Int>
const& rowIndices, std::vector<Int>
const& columnIndices,
1606 DataType*
const*
const localValues,
1609 Int ierr = ( M_epetraCrs->Filled() ) ?
1610 M_epetraCrs->SumIntoGlobalValues ( numRows, &rowIndices[0], numColumns,
1611 &columnIndices[0], localValues, format )
1613 M_epetraCrs->InsertGlobalValues ( numRows, &rowIndices[0], numColumns,
1614 &columnIndices[0], localValues, format );
1616 std::stringstream errorMessage;
1617 errorMessage <<
" error in matrix insertion [addToCoefficients] " << ierr
1618 <<
" when inserting in (" << rowIndices[0] <<
", " << columnIndices[0] <<
")" << std::endl;
1619 ASSERT ( ierr >= 0, errorMessage.str() );
1623 template <
typename DataType>
1626 std::vector<Int>
const& rowIndices, std::vector<Int>
const& columnIndices,
1627 DataType*
const*
const localValues,
1631 #ifdef LIFEV_MT_CRITICAL_UPDATES 1632 #pragma omp critical 1635 ierr = M_epetraCrs->SumIntoGlobalValues ( numRows, &rowIndices[0], numColumns,
1636 &columnIndices[0], localValues, format );
1639 std::stringstream errorMessage;
1640 errorMessage <<
" error in matrix insertion [addToCoefficients] " << ierr
1641 <<
" when inserting in (" << rowIndices[0] <<
", " << columnIndices[0] <<
")" << std::endl;
1642 ASSERT ( ierr >= 0, errorMessage.str() );
1649 template <
typename DataType>
1652 const Int minEntries = M_epetraCrs->MaxNumEntries() / 2;
1653 if ( !M_epetraCrs->NumMyRows() )
1658 Int meanNumEntries = M_epetraCrs->NumMyNonzeros() / M_epetraCrs->NumMyRows();
1659 if ( meanNumEntries < minEntries || meanNumEntries > 2 * minEntries )
1663 return meanNumEntries;
1666 template <
typename DataType>
1669 return M_epetraCrs->Comm().MyPID();
1672 template <
typename DataType>
1675 ASSERT ( M_map.get() != 0,
"MatrixEpetra::getMap: Error: M_map pointer is null" );
1679 template <
typename DataType>
1682 ASSERT ( M_domainMap.get() != 0,
"MatrixEpetra::getdomainMap: Error: M_domainMap pointer is null" );
1683 return *M_domainMap;
1686 template <
typename DataType>
1692 template <
typename DataType>
1695 ASSERT ( M_rangeMap.get() != 0,
"MatrixEpetra::getRangeMap: Error: M_rangeMap pointer is null" );
1699 template <
typename DataType>
1705 template <
typename DType>
1724 EpetraExt::MatrixMatrix::Multiply (*A.matrixPtr(),
false, *P.matrixPtr(),
false, *tmp.matrixPtr(),
true);
1725 EpetraExt::MatrixMatrix::Multiply (*R.matrixPtr(),
false, *tmp.matrixPtr(),
false, * (result->matrixPtr() ),
true);
1727 result->M_domainMap = P.M_domainMap;
1728 result->M_rangeMap = R.M_rangeMap;
1733 template <
typename DType>
1736 typename MatrixEpetra<DType>::matrix_type* result = NULL;
1737 ML_Epetra::ML_Epetra_PtAP (*A.matrixPtr(), *P.matrixPtr(), result,
true);
1739 matrix->M_epetraCrs.reset (result);
1740 matrix->M_domainMap = P.M_domainMap;
1741 matrix->M_rangeMap = P.M_domainMap;
1746 template <
typename DataType>
1748 const std::shared_ptr<VectorEpetra>& numeration,
1750 std::shared_ptr<MatrixEpetra<DataType> > & matrix_out )
1756 int offsetMap = numeration->size();
1757 for(
int i = 0; i < numeration->epetraVector().MyLength(); ++i)
1759 P.addToCoefficient(numeration->blockMap().GID(i) , (*numeration)[numeration->blockMap().GID(i)] , value);
1760 P.addToCoefficient(numeration->blockMap().GID(i) + offset, (*numeration)[numeration->blockMap().GID(i)] + offsetMap , value);
1761 P.addToCoefficient(numeration->blockMap().GID(i) + 2*offset, (*numeration)[numeration->blockMap().GID(i)] + 2*offsetMap, value);
1763 R.addToCoefficient((*numeration)[numeration->blockMap().GID(i)] , numeration->blockMap().GID(i) , value);
1764 R.addToCoefficient((*numeration)[numeration->blockMap().GID(i)] + offsetMap , numeration->blockMap().GID(i) + offset , value);
1765 R.addToCoefficient((*numeration)[numeration->blockMap().GID(i)] + 2*offsetMap, numeration->blockMap().GID(i) + 2*offset, value);
1768 P.globalAssemble( map, M_rangeMap );
1769 R.globalAssemble( M_rangeMap, map );
1773 this->multiply(
false, P,
false, tmp,
false);
1774 tmp.globalAssemble( map, M_rangeMap );
1777 matrix_out.reset(
new MatrixEpetra<DataType> (*map, 50 ));
1778 R.multiply(
false, tmp,
false, *matrix_out,
false);
1779 matrix_out->globalAssemble();
VectorEpetra - The Epetra Vector format Wrapper.
MatrixEpetra & operator*=(const DataType scalar)
Multiplication operator.
void insertZeroDiagonal(Int from=-1, Int to=-2)
insert zeros into the diagonal to ensure the matrix' graph has a entry there
Int fillComplete()
Fill complete of a square matrix with default domain and range map.
void setCoefficient(UInt row, UInt column, DataType localValue)
Set a coefficient of the matrix.
vector_type operator*(const vector_type &vector) const
Matrix-Vector multiplication.
MatrixEpetra & operator=(const MatrixEpetra &matrix)
Assignment operator.
void add(const DataType scalar, const MatrixEpetra &matrix)
Add a multiple of a given matrix: *this += scalar*matrix.
MatrixEpetra(const MapEpetra &map, Int numEntries=50, bool ignoreNonLocalValues=false)
Constructor for square and rectangular matrices.
void showMe(std::ostream &output=std::cout) const
Print the contents of the matrix.
void diagonalize(UInt const row, DataType const coefficient, vector_type &rhs, DataType datum, UInt offset=0)
apply constraint on row "row"
void diagonalize(UInt const entryIndex, DataType const coefficient, UInt offset=0)
Set entry (entryIndex,entryIndex) to coefficient and the rest of the row to zero. ...
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
const boost::shared_ptr< const MapEpetra > & domainMapPtr() const
void sumIntoCoefficients(Int const numRows, Int const numColumns, std::vector< Int > const &rowIndices, std::vector< Int > const &columnIndices, DataType *const *const localValues, Int format=Epetra_FECrsMatrix::COLUMN_MAJOR)
Add a set of values to the corresponding set of coefficient in the closed matrix. ...
Real normInf() const
Compute the norm inf of the global matrix.
Real normFrobenius() const
Compute the frobenius norm of the global matrix.
Epetra_FECrsMatrix matrix_type
MatrixEpetra(const MapEpetra &map, const Epetra_FECrsGraph &graph, bool ignoreNonLocalValues=false)
Constructor from a FE graph.
int32_type Int
Generic integer data.
matrix_ptrtype & matrixPtr()
Return the shared_pointer of the Epetra_FECrsMatrix.
void diagonalize(std::vector< UInt > rVec, DataType const coefficient, UInt offset=0)
Set entries (rVec(i),rVec(i)) to coefficient and the rest of the row entries to zero.
void zero()
set zero in all the matrix entries
matrix_ptrtype M_epetraCrs
VectorEpetra(const MapEpetra &map, const MapEpetraType &mapType=Unique, const combineMode_Type combineMode=Add)
Constructor - Using Maps.
const MapEpetra & domainMap() const
Return the domain MapEpetra of the MatrixEpetra.
void swapCrsMatrix(matrix_ptrtype &matrixPtr)
Swap the given shared pointer with the one of the matrix.
void updateInverseJacobian(const UInt &iQuadPt)
MatrixEpetra & operator+=(const MatrixEpetra &matrix)
Addition operator.
void insertOneDiagonal(Int from=-1, Int to=-2)
insert ones into the diagonal to ensure the matrix' graph has a entry there
Int processorId()
Return the Id of the processor.
void setUseTranspose(const bool &transpose=false)
If set true, transpose of this operator will be applied.
Int globalAssemble(const std::shared_ptr< const MapEpetra > &domainMap, const std::shared_ptr< const MapEpetra > &rangeMap)
Global assemble for rectangular matrices.
const MapEpetra & map() const
Return the row MapEpetra of the MatrixEpetra used in the assembling.
const boost::shared_ptr< const MapEpetra > & rangeMapPtr() const
Epetra_Import const & importer()
Getter for the Epetra_Import.
const MapEpetra & rangeMap() const
Return the range MapEpetra of the MatrixEpetra.
Real norm1() const
Compute the norm 1 of the global matrix.
std::shared_ptr< matrix_type > matrix_ptrtype
void addToCoefficient(UInt const row, UInt const column, DataType const localValue)
Add a value at a coefficient of the matrix.
friend MatrixEpetra< DType > * RAP(const MatrixEpetra< DType > &R, const MatrixEpetra< DType > &A, const MatrixEpetra< DType > &P)
Friend Functions.
void diagonalize(std::vector< UInt > rVec, DataType const coefficient, vector_type &rhs, std::vector< DataType > datumVector, UInt offset=0)
apply constraint on all rows rVec
std::shared_ptr< MapEpetra > M_map
Int multiply(bool transposeCurrent, const MatrixEpetra< DataType > &matrix, bool transposeMatrix, MatrixEpetra< DataType > &result, bool callFillCompleteOnResult=true) const
Multiply the MatrixEpetra by the first given matrix and put the result in the second given matrix...
std::shared_ptr< MatrixEpetra< DataType > > transpose()
Returns a pointer to a new matrix which contains the transpose of the current matrix.
void insertValueDiagonal(const DataType entry, const MapEpetra &Map, const UInt offset=0)
insert the given value into the diagonal
void addDyadicProduct(const vector_type &uniqueVector1, const vector_type &uniqueVector2)
Add to the matrix a dyadic product: , where is the matrix.
MatrixEpetra< DType > * PtAP(const MatrixEpetra< DType > &A, const MatrixEpetra< DType > &P)
void addToCoefficients(Int const numRows, Int const numColumns, std::vector< Int > const &rowIndices, std::vector< Int > const &columnIndices, DataType *const *const localValues, Int format=Epetra_FECrsMatrix::COLUMN_MAJOR)
Add a set of values to the corresponding set of coefficient in the matrix.
std::shared_ptr< const MapEpetra > M_domainMap
void spy(std::string const &fileName)
Save the matrix into a Matlab (.m) file.
void swapCrsMatrix(MatrixEpetra< DataType > &matrix)
Swap the matrix with the one given as argument.
MatrixEpetra(const MapEpetra &map, Int *numEntriesPerRow, bool ignoreNonLocalValues=false)
Constructor for square and rectangular matrices, knowing the number of entries per row...
void openCrsMatrix()
If the matrix has been filled, this function will reopen the Matrix.
std::shared_ptr< vector_type > vectorPtr_Type
Int meanNumEntries() const
Return the mean number of entries in the matrix rows.
double Real
Generic real data.
void restrict(const std::shared_ptr< MapEpetra > &map, const std::shared_ptr< VectorEpetra > &numeration, const UInt &offset, std::shared_ptr< MatrixEpetra< DataType > > &matrix_out)
Restrict the matrix to the dofs contained in the input map.
std::shared_ptr< MapEpetra > mapPtr()
Return the shared_pointer of the Epetra_Map.
Int multiply(bool transposeCurrent, const vector_type &vector1, vector_type &vector2) const
Multiply the first VectorEpetra given as a parameter by the MatrixEpetra and put the result into the ...
MatrixEpetra(const MapEpetra &map, matrix_ptrtype crsMatrixPtr)
Constructs an MatrixEpetra view of an Epetra_FECrsMatrix.
void removeZeros()
This function removes all the zeros in the matrix and add zero on the diagonal.
MatrixEpetra< DType > * RAP(const MatrixEpetra< DType > &R, const MatrixEpetra< DType > &A, const MatrixEpetra< DType > &P)
#define LIFEV_DEPRECATED(func)
const matrix_ptrtype & matrixPtr() const
Return the const shared_pointer of the Epetra_FECrsMatrix.
void matrixMarket(std::string const &fileName, const bool headers=true)
Save the matrix into a MatrixMarket (.mtx) file.
MatrixEpetra(const MatrixEpetra &matrix)
Copy Constructor.
VectorEpetra & operator=(const VectorEpetra &vector)
Affectation operator.
void insertValueDiagonal(const DataType &value, Int from=-1, Int to=-2)
insert the given value into the diagonal
MatrixEpetra(const MatrixEpetra &matrix, const UInt reduceToProc)
Copies the matrix to a matrix which resides only on the processor.
std::shared_ptr< const MapEpetra > M_rangeMap
Shared pointer on the range MapEpetra.
friend MatrixEpetra< DType > * PtAP(const MatrixEpetra< DType > &A, const MatrixEpetra< DType > &P)
PtAP matrix matrix multiplication result = Pt * A * P User is responsible to wrap the row pointer ret...
MatrixEpetra & operator-=(const MatrixEpetra &matrix)
Subtraction operator.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
data_type & operator[](const UInt row)
Access operators.
void setCoefficients(Int const numRows, Int const numColumns, std::vector< Int > const &rowIndices, std::vector< Int > const &columnIndices, DataType *const *const localValues, Int format=Epetra_FECrsMatrix::COLUMN_MAJOR)
Set a set of values to the corresponding set of coefficient in the matrix.
virtual ~MatrixEpetra()
Destructor.
bool filled() const
Return the fill-complete status of the Epetra_FECrsMatrix.
Int globalAssemble()
Global assemble of a square matrix with default domain and range map.
MatrixEpetra operator*(const DataType scalar) const
Multiplication operator.