16 #include <deal.II/lac/trilinos_index_access.h> 17 #include <deal.II/lac/trilinos_sparse_matrix.h> 19 #ifdef DEAL_II_WITH_TRILINOS 21 # include <deal.II/base/utilities.h> 23 # include <deal.II/lac/dynamic_sparsity_pattern.h> 24 # include <deal.II/lac/la_parallel_vector.h> 25 # include <deal.II/lac/sparse_matrix.h> 26 # include <deal.II/lac/sparsity_pattern.h> 27 # include <deal.II/lac/sparsity_tools.h> 28 # include <deal.II/lac/trilinos_index_access.h> 29 # include <deal.II/lac/trilinos_precondition.h> 30 # include <deal.II/lac/trilinos_sparsity_pattern.h> 32 # include <boost/container/small_vector.hpp> 34 # ifdef DEAL_II_TRILINOS_WITH_EPETRAEXT 35 # include <EpetraExt_MatrixMatrix.h> 37 # include <Epetra_Export.h> 38 # include <Teuchos_RCP.hpp> 39 # include <ml_epetra_utils.h> 40 # include <ml_struct.h> 44 DEAL_II_NAMESPACE_OPEN
50 template <
typename VectorType>
51 typename VectorType::value_type *
57 template <
typename VectorType>
58 const typename VectorType::value_type *
59 begin(
const VectorType &V)
64 template <
typename VectorType>
65 typename VectorType::value_type *
71 template <
typename VectorType>
72 const typename VectorType::value_type *
73 end(
const VectorType &V)
78 # ifdef DEAL_II_WITH_MPI 107 # ifdef DEAL_II_TRILINOS_WITH_TPETRA 108 template <
typename Number>
110 begin(LinearAlgebra::TpetraWrappers::Vector<Number> &V)
112 return V.trilinos_vector().getDataNonConst().get();
115 template <
typename Number>
117 begin(
const LinearAlgebra::TpetraWrappers::Vector<Number> &V)
119 return V.trilinos_vector().getData().get();
122 template <
typename Number>
124 end(LinearAlgebra::TpetraWrappers::Vector<Number> &V)
126 return V.trilinos_vector().getDataNonConst().get() +
127 V.trilinos_vector().getLocalLength();
130 template <
typename Number>
132 end(
const LinearAlgebra::TpetraWrappers::Vector<Number> &V)
134 return V.trilinos_vector().getData().get() +
135 V.trilinos_vector().getLocalLength();
164 TrilinosWrappers::types::int_type colnums =
matrix->
n();
168 std::make_shared<std::vector<TrilinosScalar>>(
matrix->
n());
182 reinterpret_cast<TrilinosWrappers::types::int_type *
>(
210 : column_space_map(new Epetra_Map(0, 0,
Utilities::Trilinos::comm_self()))
212 new Epetra_FECrsMatrix(View, *column_space_map, *column_space_map, 0))
223 : column_space_map(new Epetra_Map(input_map))
224 , matrix(new Epetra_FECrsMatrix(Copy,
227 n_max_entries_per_row),
236 const std::vector<unsigned int> &n_entries_per_row)
237 : column_space_map(new Epetra_Map(input_map))
238 , matrix(new Epetra_FECrsMatrix(Copy,
240 reinterpret_cast<int *>(
241 const_cast<unsigned int *>(
242 n_entries_per_row.data())),
251 const Epetra_Map &input_col_map,
253 : column_space_map(new Epetra_Map(input_col_map))
254 , matrix(new Epetra_FECrsMatrix(Copy,
257 n_max_entries_per_row),
266 const Epetra_Map & input_col_map,
267 const std::vector<unsigned int> &n_entries_per_row)
268 : column_space_map(new Epetra_Map(input_col_map))
269 , matrix(new Epetra_FECrsMatrix(Copy,
271 reinterpret_cast<int *>(
272 const_cast<unsigned int *>(
273 n_entries_per_row.data())),
283 const unsigned int n_max_entries_per_row)
298 matrix(new Epetra_FECrsMatrix(
304 n_max_entries_per_row,
314 const std::vector<unsigned int> &n_entries_per_row)
319 , matrix(new Epetra_FECrsMatrix(
325 reinterpret_cast<int *>(
326 const_cast<unsigned int *>(n_entries_per_row.data())),
335 const MPI_Comm & communicator,
336 const unsigned int n_max_entries_per_row)
337 : column_space_map(new Epetra_Map(
338 parallel_partitioning.make_trilinos_map(communicator, false)))
339 , matrix(new Epetra_FECrsMatrix(Copy,
341 n_max_entries_per_row,
350 const MPI_Comm &communicator,
351 const std::vector<unsigned int> &n_entries_per_row)
352 : column_space_map(new Epetra_Map(
353 parallel_partitioning.make_trilinos_map(communicator, false)))
354 , matrix(new Epetra_FECrsMatrix(Copy,
356 reinterpret_cast<int *>(
357 const_cast<unsigned int *>(
358 n_entries_per_row.data())),
367 const IndexSet &col_parallel_partitioning,
368 const MPI_Comm &communicator,
370 : column_space_map(new Epetra_Map(
371 col_parallel_partitioning.make_trilinos_map(communicator, false)))
372 , matrix(new Epetra_FECrsMatrix(
374 row_parallel_partitioning.make_trilinos_map(communicator, false),
375 n_max_entries_per_row,
384 const IndexSet &col_parallel_partitioning,
385 const MPI_Comm &communicator,
386 const std::vector<unsigned int> &n_entries_per_row)
387 : column_space_map(new Epetra_Map(
388 col_parallel_partitioning.make_trilinos_map(communicator, false)))
389 , matrix(new Epetra_FECrsMatrix(
391 row_parallel_partitioning.make_trilinos_map(communicator, false),
392 reinterpret_cast<int *>(
393 const_cast<unsigned int *>(n_entries_per_row.data())),
402 : column_space_map(new Epetra_Map(sparsity_pattern.domain_partitioner()))
404 new Epetra_FECrsMatrix(Copy,
405 sparsity_pattern.trilinos_sparsity_pattern(),
412 "The Trilinos sparsity pattern has not been compressed."));
419 : column_space_map(std::move(other.column_space_map))
420 , matrix(std::move(other.matrix))
421 , nonlocal_matrix(std::move(other.nonlocal_matrix))
422 , nonlocal_matrix_exporter(std::move(other.nonlocal_matrix_exporter))
423 , last_action(other.last_action)
424 , compressed(other.compressed)
426 other.last_action = Zero;
427 other.compressed =
false;
444 bool needs_deep_copy =
449 if (!needs_deep_copy)
456 const int row_local =
matrix->RowMap().LID(
457 static_cast<TrilinosWrappers::types::int_type>(row));
460 int n_entries, rhs_n_entries;
461 TrilinosScalar *value_ptr, *rhs_value_ptr;
462 int * index_ptr, *rhs_index_ptr;
463 int ierr = rhs.
matrix->ExtractMyRowView(row_local,
470 ierr =
matrix->ExtractMyRowView(row_local,
476 if (n_entries != rhs_n_entries ||
477 std::memcmp(static_cast<void *>(index_ptr),
478 static_cast<void *>(rhs_index_ptr),
479 sizeof(
int) * n_entries) != 0)
481 needs_deep_copy =
true;
485 for (
int i = 0; i < n_entries; ++i)
486 value_ptr[i] = rhs_value_ptr[i];
496 matrix = std_cxx14::make_unique<Epetra_FECrsMatrix>(*rhs.
matrix);
503 std_cxx14::make_unique<Epetra_CrsMatrix>(Copy,
513 template <
typename SparsityPatternType>
515 reinit_matrix(
const Epetra_Map & input_row_map,
516 const Epetra_Map & input_col_map,
517 const SparsityPatternType & sparsity_pattern,
518 const bool exchange_data,
519 std::unique_ptr<Epetra_Map> & column_space_map,
520 std::unique_ptr<Epetra_FECrsMatrix> &matrix,
521 std::unique_ptr<Epetra_CrsMatrix> & nonlocal_matrix,
522 std::unique_ptr<Epetra_Export> & nonlocal_matrix_exporter)
526 nonlocal_matrix.reset();
527 nonlocal_matrix_exporter.reset();
529 if (input_row_map.Comm().MyPID() == 0)
537 column_space_map = std_cxx14::make_unique<Epetra_Map>(input_col_map);
546 trilinos_sparsity.
reinit(input_row_map,
550 matrix = std_cxx14::make_unique<Epetra_FECrsMatrix>(
551 Copy, trilinos_sparsity.trilinos_sparsity_pattern(),
false);
559 std::vector<int> n_entries_per_row(last_row - first_row);
561 for (size_type row = first_row; row < last_row; ++row)
562 n_entries_per_row[row - first_row] = sparsity_pattern.row_length(row);
578 std::unique_ptr<Epetra_CrsGraph> graph;
579 if (input_row_map.Comm().NumProc() > 1)
580 graph = std_cxx14::make_unique<Epetra_CrsGraph>(
581 Copy, input_row_map, n_entries_per_row.data(),
true);
583 graph = std_cxx14::make_unique<Epetra_CrsGraph>(
584 Copy, input_row_map, input_col_map, n_entries_per_row.data(),
true);
591 std::vector<TrilinosWrappers::types::int_type> row_indices;
593 for (size_type row = first_row; row < last_row; ++row)
595 const int row_length = sparsity_pattern.row_length(row);
599 row_indices.resize(row_length, -1);
601 typename SparsityPatternType::iterator p =
602 sparsity_pattern.begin(row);
603 for (size_type col = 0; p != sparsity_pattern.end(row); ++p, ++col)
604 row_indices[col] = p->column();
606 graph->Epetra_CrsGraph::InsertGlobalIndices(row,
615 graph->FillComplete(input_col_map, input_row_map);
616 graph->OptimizeStorage();
624 matrix = std_cxx14::make_unique<Epetra_FECrsMatrix>(Copy, *graph,
false);
636 class Epetra_CrsGraphMod :
public Epetra_CrsGraph
639 Epetra_CrsGraphMod(
const Epetra_Map &row_map,
640 const int * n_entries_per_row)
641 : Epetra_CrsGraph(Copy, row_map, n_entries_per_row, true)
645 SetIndicesAreGlobal()
647 this->Epetra_CrsGraph::SetIndicesAreGlobal(
true);
656 reinit_matrix(
const Epetra_Map & input_row_map,
657 const Epetra_Map & input_col_map,
659 const bool exchange_data,
660 std::unique_ptr<Epetra_Map> & column_space_map,
661 std::unique_ptr<Epetra_FECrsMatrix> &matrix,
662 std::unique_ptr<Epetra_CrsMatrix> & nonlocal_matrix,
663 std::unique_ptr<Epetra_Export> & nonlocal_matrix_exporter)
666 nonlocal_matrix.reset();
667 nonlocal_matrix_exporter.reset();
674 column_space_map = std_cxx14::make_unique<Epetra_Map>(input_col_map);
678 if (relevant_rows.size() == 0)
682 relevant_rows.add_range(
685 relevant_rows.compress();
686 Assert(relevant_rows.n_elements() >=
687 static_cast<unsigned int>(input_row_map.NumMyElements()),
689 "Locally relevant rows of sparsity pattern must contain " 690 "all locally owned rows"));
695 bool have_ghost_rows =
false;
697 std::vector<::types::global_dof_index> indices;
698 relevant_rows.fill_index_vector(indices);
699 Epetra_Map relevant_map(
700 TrilinosWrappers::types::int_type(-1),
701 TrilinosWrappers::types::int_type(relevant_rows.n_elements()),
704 reinterpret_cast<TrilinosWrappers::types::int_type *
>(
707 input_row_map.Comm());
708 if (relevant_map.SameAs(input_row_map))
709 have_ghost_rows =
false;
711 have_ghost_rows =
true;
714 const unsigned int n_rows = relevant_rows.n_elements();
715 std::vector<TrilinosWrappers::types::int_type> ghost_rows;
716 std::vector<int> n_entries_per_row(input_row_map.NumMyElements());
717 std::vector<int> n_entries_per_ghost_row;
718 for (
unsigned int i = 0, own = 0; i < n_rows; ++i)
720 const TrilinosWrappers::types::int_type global_row =
721 relevant_rows.nth_index_in_set(i);
722 if (input_row_map.MyGID(global_row))
723 n_entries_per_row[own++] = sparsity_pattern.
row_length(global_row);
724 else if (sparsity_pattern.
row_length(global_row) > 0)
726 ghost_rows.push_back(global_row);
727 n_entries_per_ghost_row.push_back(
732 Epetra_Map off_processor_map(-1,
734 (ghost_rows.size() > 0) ?
735 (ghost_rows.data()) :
738 input_row_map.Comm());
740 std::unique_ptr<Epetra_CrsGraph> graph;
741 std::unique_ptr<Epetra_CrsGraphMod> nonlocal_graph;
742 if (input_row_map.Comm().NumProc() > 1)
744 graph = std_cxx14::make_unique<Epetra_CrsGraph>(
747 (n_entries_per_row.size() > 0) ? (n_entries_per_row.data()) :
749 exchange_data ?
false :
true);
750 if (have_ghost_rows ==
true)
751 nonlocal_graph = std_cxx14::make_unique<Epetra_CrsGraphMod>(
752 off_processor_map, n_entries_per_ghost_row.data());
755 graph = std_cxx14::make_unique<Epetra_CrsGraph>(
759 (n_entries_per_row.size() > 0) ? (n_entries_per_row.data()) :
nullptr,
763 std::vector<TrilinosWrappers::types::int_type> row_indices;
765 for (
unsigned int i = 0; i < n_rows; ++i)
767 const TrilinosWrappers::types::int_type global_row =
768 relevant_rows.nth_index_in_set(i);
769 const int row_length = sparsity_pattern.
row_length(global_row);
773 row_indices.resize(row_length, -1);
774 for (
int col = 0; col < row_length; ++col)
775 row_indices[col] = sparsity_pattern.
column_number(global_row, col);
777 if (input_row_map.MyGID(global_row))
778 graph->InsertGlobalIndices(global_row,
784 nonlocal_graph->InsertGlobalIndices(global_row,
791 if (nonlocal_graph.get() !=
nullptr)
797 nonlocal_graph->SetIndicesAreGlobal();
798 Assert(nonlocal_graph->IndicesAreGlobal() ==
true,
800 nonlocal_graph->FillComplete(input_col_map, input_row_map);
801 nonlocal_graph->OptimizeStorage();
806 Epetra_Export exporter(nonlocal_graph->RowMap(), input_row_map);
807 int ierr = graph->Export(*nonlocal_graph, exporter, Add);
813 std_cxx14::make_unique<Epetra_CrsMatrix>(Copy, *nonlocal_graph);
816 graph->FillComplete(input_col_map, input_row_map);
817 graph->OptimizeStorage();
822 matrix = std_cxx14::make_unique<Epetra_FECrsMatrix>(Copy, *graph,
false);
828 template <
typename SparsityPatternType>
832 const Epetra_Map rows(static_cast<TrilinosWrappers::types::int_type>(
833 sparsity_pattern.n_rows()),
836 const Epetra_Map columns(static_cast<TrilinosWrappers::types::int_type>(
837 sparsity_pattern.n_cols()),
853 template <
typename SparsityPatternType>
856 const SparsityPatternType &sparsity_pattern,
857 const bool exchange_data)
859 reinit_matrix(input_map,
871 template <
typename SparsityPatternType>
874 const IndexSet & col_parallel_partitioning,
875 const SparsityPatternType &sparsity_pattern,
876 const MPI_Comm & communicator,
877 const bool exchange_data)
883 reinit_matrix(row_map,
900 template <
typename SparsityPatternType>
903 const Epetra_Map & col_map,
904 const SparsityPatternType &sparsity_pattern,
905 const bool exchange_data)
907 reinit_matrix(row_map,
933 matrix = std_cxx14::make_unique<Epetra_FECrsMatrix>(
951 if (
this == &sparse_matrix)
958 matrix = std_cxx14::make_unique<Epetra_FECrsMatrix>(
973 template <
typename number>
976 const IndexSet & row_parallel_partitioning,
977 const IndexSet & col_parallel_partitioning,
978 const ::SparseMatrix<number> &dealii_sparse_matrix,
979 const MPI_Comm & communicator,
980 const double drop_tolerance,
981 const bool copy_values,
982 const ::SparsityPattern * use_this_sparsity)
984 if (copy_values ==
false)
988 if (use_this_sparsity ==
nullptr)
989 reinit(row_parallel_partitioning,
990 col_parallel_partitioning,
991 dealii_sparse_matrix.get_sparsity_pattern(),
995 reinit(row_parallel_partitioning,
996 col_parallel_partitioning,
1003 const size_type n_rows = dealii_sparse_matrix.m();
1008 const ::SparsityPattern &sparsity_pattern =
1009 (use_this_sparsity !=
nullptr) ?
1010 *use_this_sparsity :
1011 dealii_sparse_matrix.get_sparsity_pattern();
1013 if (
matrix.get() ==
nullptr ||
m() != n_rows ||
1016 reinit(row_parallel_partitioning,
1017 col_parallel_partitioning,
1029 std::vector<size_type> row_indices(maximum_row_length);
1030 std::vector<TrilinosScalar> values(maximum_row_length);
1032 for (
size_type row = 0; row < n_rows; ++row)
1034 if (row_parallel_partitioning.
is_element(row) ==
true)
1037 sparsity_pattern.begin(row);
1038 typename ::SparseMatrix<number>::const_iterator it =
1039 dealii_sparse_matrix.begin(row);
1041 if (sparsity_pattern.n_rows() == sparsity_pattern.n_cols())
1045 if (std::fabs(it->value()) > drop_tolerance)
1047 values[col] = it->value();
1048 row_indices[col++] = it->column();
1054 while (it != dealii_sparse_matrix.end(row) &&
1055 select_index != sparsity_pattern.end(row))
1057 while (select_index->column() < it->column() &&
1058 select_index != sparsity_pattern.end(row))
1060 while (it->column() < select_index->column() &&
1061 it != dealii_sparse_matrix.end(row))
1064 if (it == dealii_sparse_matrix.end(row))
1066 if (std::fabs(it->value()) > drop_tolerance)
1068 values[col] = it->value();
1069 row_indices[col++] = it->column();
1076 reinterpret_cast<size_type *
>(row_indices.data()),
1085 template <
typename number>
1088 const ::SparseMatrix<number> &dealii_sparse_matrix,
1089 const double drop_tolerance,
1090 const bool copy_values,
1091 const ::SparsityPattern * use_this_sparsity)
1093 reinit(complete_index_set(dealii_sparse_matrix.m()),
1094 complete_index_set(dealii_sparse_matrix.n()),
1095 dealii_sparse_matrix,
1104 template <
typename number>
1107 const Epetra_Map & input_map,
1108 const ::SparseMatrix<number> &dealii_sparse_matrix,
1109 const double drop_tolerance,
1110 const bool copy_values,
1111 const ::SparsityPattern * use_this_sparsity)
1115 dealii_sparse_matrix,
1124 template <
typename number>
1127 const Epetra_Map & input_row_map,
1128 const Epetra_Map & input_col_map,
1129 const ::SparseMatrix<number> &dealii_sparse_matrix,
1130 const double drop_tolerance,
1131 const bool copy_values,
1132 const ::SparsityPattern * use_this_sparsity)
1136 dealii_sparse_matrix,
1147 const bool copy_values)
1149 Assert(input_matrix.Filled() ==
true,
1150 ExcMessage(
"Input CrsMatrix has not called FillComplete()!"));
1153 std_cxx14::make_unique<Epetra_Map>(input_matrix.DomainMap());
1155 const Epetra_CrsGraph *graph = &input_matrix.Graph();
1160 matrix = std_cxx14::make_unique<Epetra_FECrsMatrix>(Copy, *graph,
false);
1164 if (copy_values ==
true)
1168 const TrilinosScalar *in_values = input_matrix[0];
1169 TrilinosScalar * values = (*matrix)[0];
1170 const size_type my_nonzeros = input_matrix.NumMyNonzeros();
1171 std::memcpy(values, in_values, my_nonzeros *
sizeof(TrilinosScalar));
1195 "compress() can only be called with VectorOperation add, insert, or unknown"));
1203 ExcMessage(
"Operation and argument to compress() do not match"));
1229 ierr =
matrix->OptimizeStorage();
1246 std_cxx14::make_unique<Epetra_Map>(0,
1263 const TrilinosScalar new_diag_value)
1270 matrix->LRID(static_cast<TrilinosWrappers::types::int_type>(row));
1273 TrilinosScalar *values;
1277 matrix->ExtractMyRowView(local_row, num_entries, values, col_indices);
1282 const std::ptrdiff_t diag_index =
1283 std::find(col_indices, col_indices + num_entries, local_row) -
1286 for (TrilinosWrappers::types::int_type j = 0; j < num_entries; ++j)
1287 if (diag_index != j || new_diag_value == 0)
1290 if (diag_index != num_entries && std::fabs(values[diag_index]) == 0.0 &&
1291 new_diag_value != 0.0)
1292 values[diag_index] = new_diag_value;
1300 const TrilinosScalar new_diag_value)
1302 for (
const auto row : rows)
1314 matrix->LRID(static_cast<TrilinosWrappers::types::int_type>(i)),
1316 matrix->LCID(static_cast<TrilinosWrappers::types::int_type>(j));
1317 TrilinosScalar value = 0.;
1325 if (trilinos_i == -1)
1340 int nnz_present =
matrix->NumMyEntries(trilinos_i);
1343 TrilinosScalar *values;
1349 int ierr =
matrix->ExtractMyRowView(trilinos_i,
1356 Assert(nnz_present == nnz_extracted,
1362 const std::ptrdiff_t local_col_index =
1363 std::find(col_indices, col_indices + nnz_present, trilinos_j) -
1374 if (local_col_index == nnz_present)
1379 value = values[local_col_index];
1393 matrix->LRID(static_cast<TrilinosWrappers::types::int_type>(i)),
1395 matrix->LCID(static_cast<TrilinosWrappers::types::int_type>(j));
1396 TrilinosScalar value = 0.;
1405 if ((trilinos_i == -1) || (trilinos_j == -1))
1416 int nnz_present =
matrix->NumMyEntries(trilinos_i);
1419 TrilinosScalar *values;
1424 int ierr =
matrix->ExtractMyRowView(trilinos_i,
1431 Assert(nnz_present == nnz_extracted,
1437 const std::ptrdiff_t local_col_index =
1438 std::find(col_indices, col_indices + nnz_present, trilinos_j) -
1448 if (local_col_index == nnz_present)
1451 value = values[local_col_index];
1489 matrix->LRID(static_cast<TrilinosWrappers::types::int_type>(row));
1497 int ierr =
matrix->NumMyRowEntries(local_row, ncols);
1501 return static_cast<unsigned int>(ncols);
1508 const std::vector<size_type> & col_indices,
1510 const bool elide_zero_values)
1512 Assert(row_indices.size() == values.
m(),
1514 Assert(col_indices.size() == values.
n(),
1517 for (
size_type i = 0; i < row_indices.size(); ++i)
1529 const std::vector<size_type> & col_indices,
1530 const std::vector<TrilinosScalar> &values,
1531 const bool elide_zero_values)
1533 Assert(col_indices.size() == values.size(),
1547 SparseMatrix::set<TrilinosScalar>(
const size_type row,
1548 const size_type n_cols,
1549 const size_type * col_indices,
1550 const TrilinosScalar *values,
1551 const bool elide_zero_values)
1556 if (last_action == Add)
1559 matrix->GlobalAssemble(*column_space_map, matrix->RowMap(),
true);
1564 last_action = Insert;
1566 const TrilinosWrappers::types::int_type *col_index_ptr;
1567 const TrilinosScalar * col_value_ptr;
1568 const TrilinosWrappers::types::int_type trilinos_row = row;
1569 TrilinosWrappers::types::int_type n_columns;
1571 boost::container::small_vector<TrilinosScalar, 200> local_value_array(
1573 boost::container::small_vector<TrilinosWrappers::types::int_type, 200>
1574 local_index_array(n_cols);
1579 if (elide_zero_values ==
false)
1582 reinterpret_cast<const TrilinosWrappers::types::int_type *
>(
1584 col_value_ptr = values;
1591 col_index_ptr = local_index_array.data();
1592 col_value_ptr = local_value_array.data();
1595 for (size_type j = 0; j < n_cols; ++j)
1597 const double value = values[j];
1601 local_index_array[n_columns] = col_indices[j];
1602 local_value_array[n_columns] = value;
1619 if (
matrix->RowMap().MyGID(
1620 static_cast<TrilinosWrappers::types::int_type>(row)) ==
true)
1622 if (
matrix->Filled() ==
false)
1624 ierr =
matrix->Epetra_CrsMatrix::InsertGlobalValues(
1625 row, static_cast<int>(n_columns), col_value_ptr, col_index_ptr);
1634 ierr =
matrix->Epetra_CrsMatrix::ReplaceGlobalValues(row,
1649 if (
matrix->Filled() ==
false)
1651 ierr =
matrix->InsertGlobalValues(1,
1656 Epetra_FECrsMatrix::ROW_MAJOR);
1661 ierr =
matrix->ReplaceGlobalValues(1,
1666 Epetra_FECrsMatrix::ROW_MAJOR);
1674 Assert(ierr <= 0, ExcAccessToNonPresentElement(row, col_index_ptr[0]));
1683 const bool elide_zero_values)
1685 Assert(indices.size() == values.
m(),
1689 for (
size_type i = 0; i < indices.size(); ++i)
1701 const std::vector<size_type> & col_indices,
1703 const bool elide_zero_values)
1705 Assert(row_indices.size() == values.
m(),
1707 Assert(col_indices.size() == values.
n(),
1710 for (
size_type i = 0; i < row_indices.size(); ++i)
1722 const std::vector<size_type> & col_indices,
1723 const std::vector<TrilinosScalar> &values,
1724 const bool elide_zero_values)
1726 Assert(col_indices.size() == values.size(),
1742 const TrilinosScalar *values,
1743 const bool elide_zero_values,
1760 const TrilinosWrappers::types::int_type *col_index_ptr;
1761 const TrilinosScalar * col_value_ptr;
1762 const TrilinosWrappers::types::int_type trilinos_row = row;
1763 TrilinosWrappers::types::int_type n_columns;
1765 boost::container::small_vector<TrilinosScalar, 100> local_value_array(
1767 boost::container::small_vector<TrilinosWrappers::types::int_type, 100>
1768 local_index_array(n_cols);
1773 if (elide_zero_values ==
false)
1776 reinterpret_cast<const TrilinosWrappers::types::int_type *
>(
1778 col_value_ptr = values;
1789 col_index_ptr = local_index_array.data();
1790 col_value_ptr = local_value_array.data();
1795 const double value = values[j];
1800 local_index_array[n_columns] = col_indices[j];
1801 local_value_array[n_columns] = value;
1817 if (
matrix->RowMap().MyGID(
1818 static_cast<TrilinosWrappers::types::int_type>(row)) ==
true)
1820 ierr =
matrix->Epetra_CrsMatrix::SumIntoGlobalValues(row,
1833 static_cast<TrilinosWrappers::types::int_type>(row)) != -1,
1834 ExcMessage(
"Attempted to write into off-processor matrix row " 1835 "that has not be specified as being writable upon " 1853 ierr =
matrix->SumIntoGlobalValues(1,
1858 Epetra_FECrsMatrix::ROW_MAJOR);
1865 std::cout <<
"------------------------------------------" << std::endl;
1866 std::cout <<
"Got error " << ierr <<
" in row " << row <<
" of proc " 1867 <<
matrix->RowMap().Comm().MyPID()
1868 <<
" when trying to add the columns:" << std::endl;
1869 for (TrilinosWrappers::types::int_type i = 0; i < n_columns; ++i)
1870 std::cout << col_index_ptr[i] <<
" ";
1871 std::cout << std::endl << std::endl;
1872 std::cout <<
"Matrix row " 1873 << (
matrix->RowMap().MyGID(
1874 static_cast<TrilinosWrappers::types::int_type>(row)) ==
1878 <<
" has the following indices:" << std::endl;
1879 std::vector<TrilinosWrappers::types::int_type> indices;
1880 const Epetra_CrsGraph * graph =
1883 static_cast<TrilinosWrappers::types::int_type>(row)) ==
false) ?
1887 indices.resize(graph->NumGlobalIndices(row));
1889 graph->ExtractGlobalRowCopy(row,
1895 for (TrilinosWrappers::types::int_type i = 0; i < n_indices; ++i)
1896 std::cout << indices[i] <<
" ";
1897 std::cout << std::endl << std::endl;
1914 const int ierr =
matrix->PutScalar(d);
1932 ExcMessage(
"Can only add matrices with same distribution of rows"));
1934 ExcMessage(
"Addition of matrices only allowed if matrices are " 1935 "filled, i.e., compress() has been called"));
1937 const bool same_col_map =
matrix->ColMap().SameAs(rhs.
matrix->ColMap());
1941 const int row_local =
matrix->RowMap().LID(
1942 static_cast<TrilinosWrappers::types::int_type>(row));
1949 int n_entries, rhs_n_entries;
1950 TrilinosScalar *value_ptr, *rhs_value_ptr;
1951 int * index_ptr, *rhs_index_ptr;
1952 int ierr = rhs.
matrix->ExtractMyRowView(row_local,
1960 matrix->ExtractMyRowView(row_local, n_entries, value_ptr, index_ptr);
1962 bool expensive_checks = (n_entries != rhs_n_entries || !same_col_map);
1963 if (!expensive_checks)
1967 expensive_checks = std::memcmp(static_cast<void *>(index_ptr),
1968 static_cast<void *>(rhs_index_ptr),
1969 sizeof(
int) * n_entries) != 0;
1970 if (!expensive_checks)
1971 for (
int i = 0; i < n_entries; ++i)
1972 value_ptr[i] += rhs_value_ptr[i] * factor;
1978 if (expensive_checks)
1980 for (
int i = 0; i < rhs_n_entries; ++i)
1982 if (rhs_value_ptr[i] == 0.)
1984 const TrilinosWrappers::types::int_type rhs_global_col =
1986 int local_col =
matrix->ColMap().LID(rhs_global_col);
1988 index_ptr + n_entries,
1990 Assert(local_index != index_ptr + n_entries &&
1991 *local_index == local_col,
1993 "Adding the entries from the other matrix " 1994 "failed, because the sparsity pattern " 1995 "of that matrix includes more elements than the " 1996 "calling matrix, which is not allowed."));
1997 value_ptr[local_index - index_ptr] += factor * rhs_value_ptr[i];
2015 if (!
matrix->UseTranspose())
2017 ierr =
matrix->SetUseTranspose(
true);
2022 ierr =
matrix->SetUseTranspose(
false);
2032 const int ierr =
matrix->Scale(a);
2046 const TrilinosScalar factor = 1. / a;
2048 const int ierr =
matrix->Scale(factor);
2061 return matrix->NormOne();
2070 return matrix->NormInf();
2079 return matrix->NormFrobenius();
2086 namespace SparseMatrixImplementation
2088 template <
typename VectorType>
2090 check_vector_map_equality(
const Epetra_CrsMatrix &,
2096 check_vector_map_equality(
const Epetra_CrsMatrix & m,
2102 "Column map of matrix does not fit with vector map!"));
2104 ExcMessage(
"Row map of matrix does not fit with vector map!"));
2113 template <
typename VectorType>
2114 typename std::enable_if<
2115 std::is_same<typename VectorType::value_type, TrilinosScalar>::value>::type
2123 internal::SparseMatrixImplementation::check_vector_map_equality(*
matrix,
2126 const size_type dst_local_size = internal::end(dst) - internal::begin(dst);
2128 const size_type src_local_size = internal::end(src) - internal::begin(src);
2131 Epetra_MultiVector tril_dst(
2132 View,
matrix->RangeMap(), internal::begin(dst), dst_local_size, 1);
2133 Epetra_MultiVector tril_src(View,
2135 const_cast<TrilinosScalar *
>(
2136 internal::begin(src)),
2140 const int ierr =
matrix->Multiply(
false, tril_src, tril_dst);
2147 template <
typename VectorType>
2148 typename std::enable_if<
2149 !std::is_same<typename VectorType::value_type, TrilinosScalar>::value>::type
2157 template <
typename VectorType>
2158 typename std::enable_if<
2159 std::is_same<typename VectorType::value_type, TrilinosScalar>::value>::type
2165 internal::SparseMatrixImplementation::check_vector_map_equality(*
matrix,
2168 const size_type dst_local_size = internal::end(dst) - internal::begin(dst);
2170 const size_type src_local_size = internal::end(src) - internal::begin(src);
2173 Epetra_MultiVector tril_dst(
2174 View,
matrix->DomainMap(), internal::begin(dst), dst_local_size, 1);
2175 Epetra_MultiVector tril_src(View,
2177 const_cast<double *
>(internal::begin(src)),
2181 const int ierr =
matrix->Multiply(
true, tril_src, tril_dst);
2188 template <
typename VectorType>
2189 typename std::enable_if<
2190 !std::is_same<typename VectorType::value_type, TrilinosScalar>::value>::type
2198 template <
typename VectorType>
2206 VectorType tmp_vector;
2207 tmp_vector.reinit(dst,
true);
2208 vmult(tmp_vector, src);
2214 template <
typename VectorType>
2222 VectorType tmp_vector;
2223 tmp_vector.reinit(dst,
true);
2236 temp_vector.
reinit(v,
true);
2238 vmult(temp_vector, v);
2239 return temp_vector * v;
2251 temp_vector.
reinit(v,
true);
2253 vmult(temp_vector, v);
2254 return u * temp_vector;
2282 const bool transpose_left)
2284 const bool use_vector = (V.
size() == inputright.
m() ? true :
false);
2285 if (transpose_left ==
false)
2287 Assert(inputleft.
n() == inputright.
m(),
2291 ExcMessage(
"Parallel partitioning of A and B does not fit."));
2295 Assert(inputleft.
m() == inputright.
m(),
2299 ExcMessage(
"Parallel partitioning of A and B does not fit."));
2310 Teuchos::RCP<Epetra_CrsMatrix> mod_B;
2311 if (use_vector ==
false)
2313 mod_B = Teuchos::rcp(const_cast<Epetra_CrsMatrix *>(
2319 mod_B = Teuchos::rcp(
2325 ExcMessage(
"Parallel distribution of matrix B and vector V " 2326 "does not match."));
2329 for (
int i = 0; i < local_N; ++i)
2332 double *new_data, *B_data;
2333 mod_B->ExtractMyRowView(i, N_entries, new_data);
2338 for (TrilinosWrappers::types::int_type j = 0; j < N_entries; ++j)
2339 new_data[j] = value * B_data[j];
2350 # ifdef DEAL_II_TRILINOS_WITH_EPETRAEXT 2355 const_cast<Epetra_CrsMatrix &
>(
2356 tmp_result.trilinos_matrix()));
2360 result.
reinit(tmp_result.trilinos_matrix());
2370 internals::perform_mmult(*
this, B, C, V,
false);
2380 internals::perform_mmult(*
this, B, C, V,
true);
2398 const bool print_detailed_trilinos_information)
const 2400 if (print_detailed_trilinos_information ==
true)
2408 for (
int i = 0; i <
matrix->NumMyRows(); ++i)
2410 matrix->ExtractMyRowView(i, num_entries, values, indices);
2411 for (TrilinosWrappers::types::int_type j = 0; j < num_entries; ++j)
2415 <<
") " << values[j] << std::endl;
2428 sizeof(*this) +
sizeof(*matrix) +
sizeof(*
matrix->Graph().DataPtr());
2430 (
sizeof(TrilinosScalar) +
sizeof(TrilinosWrappers::types::int_type)) *
2431 matrix->NumMyNonzeros() +
2440 return matrix->DomainMap();
2448 return matrix->RangeMap();
2472 # ifdef DEAL_II_WITH_MPI 2474 const Epetra_MpiComm *mpi_comm =
2475 dynamic_cast<const Epetra_MpiComm *
>(&
matrix->RangeMap().Comm());
2477 return mpi_comm->Comm();
2480 return MPI_COMM_SELF;
2493 # ifndef DEAL_II_WITH_MPI 2495 make_serial_Epetra_map(
const IndexSet &serial_partitioning)
2499 TrilinosWrappers::types::int_type(serial_partitioning.
size()),
2500 TrilinosWrappers::types::int_type(serial_partitioning.
n_elements()),
2502 Epetra_SerialComm());
2507 namespace LinearOperatorImplementation
2510 : use_transpose(false)
2512 # ifdef DEAL_II_WITH_MPI
2513 communicator(MPI_COMM_SELF)
2514 , domain_map(
IndexSet().make_trilinos_map(communicator.Comm()))
2515 , range_map(
IndexSet().make_trilinos_map(communicator.Comm()))
2523 ExcMessage(
"Uninitialized TrilinosPayload::vmult called" 2524 "(Default constructor)"));
2529 ExcMessage(
"Uninitialized TrilinosPayload::Tvmult called" 2530 "(Default constructor)"));
2535 ExcMessage(
"Uninitialized TrilinosPayload::inv_vmult called" 2536 "(Default constructor)"));
2541 ExcMessage(
"Uninitialized TrilinosPayload::inv_Tvmult called" 2542 "(Default constructor)"));
2551 : use_transpose(matrix_exemplar.trilinos_matrix().UseTranspose())
2553 # ifdef DEAL_II_WITH_MPI
2554 communicator(matrix_exemplar.get_mpi_communicator())
2556 matrix_exemplar.locally_owned_domain_indices().make_trilinos_map(
2557 communicator.Comm()))
2559 matrix_exemplar.locally_owned_range_indices().make_trilinos_map(
2560 communicator.Comm()))
2562 domain_map(
internal::make_serial_Epetra_map(
2563 matrix_exemplar.locally_owned_domain_indices()))
2564 , range_map(
internal::make_serial_Epetra_map(
2565 matrix_exemplar.locally_owned_range_indices()))
2568 vmult = [&matrix_exemplar, &matrix](
Range & tril_dst,
2569 const Domain &tril_src) {
2571 Assert(&tril_src != &tril_dst,
2573 Assert(matrix.trilinos_matrix().Filled(),
2575 internal::check_vector_map_equality(
2580 internal::check_vector_map_equality(
2581 matrix.trilinos_matrix(),
2584 matrix.trilinos_matrix().UseTranspose());
2586 const int ierr = matrix.trilinos_matrix().Apply(tril_src, tril_dst);
2590 Tvmult = [&matrix_exemplar, &matrix](
Domain & tril_dst,
2591 const Range &tril_src) {
2593 Assert(&tril_src != &tril_dst,
2595 Assert(matrix.trilinos_matrix().Filled(),
2597 internal::check_vector_map_equality(
2602 internal::check_vector_map_equality(
2603 matrix.trilinos_matrix(),
2606 !matrix.trilinos_matrix().UseTranspose());
2608 Epetra_CrsMatrix &tril_mtrx_non_const =
2609 const_cast<Epetra_CrsMatrix &
>(matrix.trilinos_matrix());
2610 tril_mtrx_non_const.SetUseTranspose(
2611 !matrix.trilinos_matrix().UseTranspose());
2612 const int ierr = matrix.trilinos_matrix().Apply(tril_src, tril_dst);
2614 tril_mtrx_non_const.SetUseTranspose(
2615 !matrix.trilinos_matrix().UseTranspose());
2620 ExcMessage(
"Uninitialized TrilinosPayload::inv_vmult called" 2621 "(Matrix constructor with matrix exemplar)"));
2626 ExcMessage(
"Uninitialized TrilinosPayload::inv_Tvmult called" 2627 "(Matrix constructor with matrix exemplar)"));
2636 : use_transpose(matrix_exemplar.trilinos_matrix().UseTranspose())
2638 # ifdef DEAL_II_WITH_MPI
2639 communicator(matrix_exemplar.get_mpi_communicator())
2641 matrix_exemplar.locally_owned_domain_indices().make_trilinos_map(
2642 communicator.Comm()))
2644 matrix_exemplar.locally_owned_range_indices().make_trilinos_map(
2645 communicator.Comm()))
2647 domain_map(
internal::make_serial_Epetra_map(
2648 matrix_exemplar.locally_owned_domain_indices()))
2649 , range_map(
internal::make_serial_Epetra_map(
2650 matrix_exemplar.locally_owned_range_indices()))
2653 vmult = [&matrix_exemplar, &preconditioner](
Range & tril_dst,
2654 const Domain &tril_src) {
2657 Assert(&tril_src != &tril_dst,
2659 internal::check_vector_map_equality(
2664 internal::check_vector_map_equality(
2675 Tvmult = [&matrix_exemplar, &preconditioner](
Domain & tril_dst,
2676 const Range &tril_src) {
2679 Assert(&tril_src != &tril_dst,
2681 internal::check_vector_map_equality(
2686 internal::check_vector_map_equality(
2702 const Range &tril_src) {
2705 Assert(&tril_src != &tril_dst,
2707 internal::check_vector_map_equality(
2712 internal::check_vector_map_equality(
2724 &preconditioner](
Range & tril_dst,
2725 const Domain &tril_src) {
2728 Assert(&tril_src != &tril_dst,
2730 internal::check_vector_map_equality(
2735 internal::check_vector_map_equality(
2757 preconditioner_exemplar.trilinos_operator().UseTranspose())
2759 # ifdef DEAL_II_WITH_MPI
2760 communicator(preconditioner_exemplar.get_mpi_communicator())
2761 , domain_map(preconditioner_exemplar.locally_owned_domain_indices()
2762 .make_trilinos_map(communicator.Comm()))
2763 , range_map(preconditioner_exemplar.locally_owned_range_indices()
2764 .make_trilinos_map(communicator.Comm()))
2766 domain_map(
internal::make_serial_Epetra_map(
2767 preconditioner_exemplar.locally_owned_domain_indices()))
2768 , range_map(
internal::make_serial_Epetra_map(
2769 preconditioner_exemplar.locally_owned_range_indices()))
2772 vmult = [&preconditioner_exemplar,
2773 &preconditioner](
Range &tril_dst,
const Domain &tril_src) {
2776 Assert(&tril_src != &tril_dst,
2778 internal::check_vector_map_equality(
2783 internal::check_vector_map_equality(
2794 Tvmult = [&preconditioner_exemplar,
2795 &preconditioner](
Domain &tril_dst,
const Range &tril_src) {
2798 Assert(&tril_src != &tril_dst,
2800 internal::check_vector_map_equality(
2805 internal::check_vector_map_equality(
2821 &preconditioner](
Domain &tril_dst,
const Range &tril_src) {
2824 Assert(&tril_src != &tril_dst,
2826 internal::check_vector_map_equality(
2831 internal::check_vector_map_equality(
2843 &preconditioner](
Range & tril_dst,
2844 const Domain &tril_src) {
2847 Assert(&tril_src != &tril_dst,
2849 internal::check_vector_map_equality(
2854 internal::check_vector_map_equality(
2873 : vmult(payload.vmult)
2874 , Tvmult(payload.Tvmult)
2875 , inv_vmult(payload.inv_vmult)
2876 , inv_Tvmult(payload.inv_Tvmult)
2877 , use_transpose(payload.use_transpose)
2878 , communicator(payload.communicator)
2879 , domain_map(payload.domain_map)
2880 , range_map(payload.range_map)
2889 : use_transpose(false)
2892 communicator(first_op.communicator)
2893 , domain_map(second_op.domain_map)
2894 , range_map(first_op.range_map)
2905 tril_dst = tril_src;
2909 tril_dst = tril_src;
2913 tril_dst = tril_src;
2917 tril_dst = tril_src;
2931 const int ierr = tril_dst.PutScalar(0.0);
2937 const int ierr = tril_dst.PutScalar(0.0);
2944 ExcMessage(
"Cannot compute inverse of null operator"));
2946 const int ierr = tril_dst.PutScalar(0.0);
2953 ExcMessage(
"Cannot compute inverse of null operator"));
2955 const int ierr = tril_dst.PutScalar(0.0);
2994 # ifdef DEAL_II_WITH_MPI 2997 return MPI_COMM_SELF;
3059 return "TrilinosPayload";
3117 "Operators are set to work on incompatible IndexSets."));
3121 "Operators are set to work on incompatible IndexSets."));
3126 return_op.vmult = [first_op, second_op](Range & tril_dst,
3127 const Domain &tril_src) {
3135 i->reinit(
IndexSet(first_op_init_map),
3140 const size_type i_local_size = i->end() - i->begin();
3144 (void)second_op_init_map;
3145 Intermediate tril_int(View,
3147 const_cast<TrilinosScalar *>(i->begin()),
3153 second_op.
Apply(tril_src, tril_int);
3154 first_op.
Apply(tril_src, tril_dst);
3155 const int ierr = tril_dst.Update(1.0, tril_int, 1.0);
3159 return_op.Tvmult = [first_op, second_op](Domain & tril_dst,
3160 const Range &tril_src) {
3170 const_cast<TrilinosPayload &
>(first_op).
transpose();
3171 const_cast<TrilinosPayload &
>(second_op).
transpose();
3175 i->reinit(
IndexSet(first_op_init_map),
3180 const size_type i_local_size = i->end() - i->begin();
3184 (void)second_op_init_map;
3185 Intermediate tril_int(View,
3187 const_cast<TrilinosScalar *>(i->begin()),
3193 second_op.
Apply(tril_src, tril_int);
3194 first_op.
Apply(tril_src, tril_dst);
3195 const int ierr = tril_dst.Update(1.0, tril_int, 1.0);
3199 const_cast<TrilinosPayload &
>(first_op).
transpose();
3200 const_cast<TrilinosPayload &
>(second_op).
transpose();
3203 return_op.inv_vmult = [first_op, second_op](Domain & tril_dst,
3204 const Range &tril_src) {
3212 i->reinit(
IndexSet(first_op_init_map),
3217 const size_type i_local_size = i->end() - i->begin();
3221 (void)second_op_init_map;
3222 Intermediate tril_int(View,
3224 const_cast<TrilinosScalar *>(i->begin()),
3232 const int ierr = tril_dst.Update(1.0, tril_int, 1.0);
3236 return_op.inv_Tvmult = [first_op, second_op](Range & tril_dst,
3237 const Domain &tril_src) {
3247 const_cast<TrilinosPayload &
>(first_op).
transpose();
3248 const_cast<TrilinosPayload &
>(second_op).
transpose();
3252 i->reinit(
IndexSet(first_op_init_map),
3257 const size_type i_local_size = i->end() - i->begin();
3261 (void)second_op_init_map;
3262 Intermediate tril_int(View,
3264 const_cast<TrilinosScalar *>(i->begin()),
3272 const int ierr = tril_dst.Update(1.0, tril_int, 1.0);
3276 const_cast<TrilinosPayload &
>(first_op).
transpose();
3277 const_cast<TrilinosPayload &
>(second_op).
transpose();
3285 TrilinosPayload
operator*(
const TrilinosPayload &first_op,
3286 const TrilinosPayload &second_op)
3293 AssertThrow(first_op.locally_owned_domain_indices() ==
3294 second_op.locally_owned_range_indices(),
3296 "Operators are set to work on incompatible IndexSets."));
3298 TrilinosPayload return_op(first_op, second_op);
3301 return_op.vmult = [first_op, second_op](Range & tril_dst,
3302 const Domain &tril_src) {
3309 const Epetra_Map &first_op_init_map = first_op.OperatorDomainMap();
3310 i->reinit(
IndexSet(first_op_init_map),
3311 first_op.get_mpi_communicator(),
3315 const size_type i_local_size = i->end() - i->begin();
3317 const Epetra_Map &second_op_init_map = second_op.OperatorRangeMap();
3319 (void)second_op_init_map;
3320 Intermediate tril_int(View,
3322 const_cast<TrilinosScalar *>(i->begin()),
3328 second_op.Apply(tril_src, tril_int);
3329 first_op.Apply(tril_int, tril_dst);
3332 return_op.Tvmult = [first_op, second_op](Domain & tril_dst,
3333 const Range &tril_src) {
3343 const_cast<TrilinosPayload &
>(first_op).
transpose();
3344 const_cast<TrilinosPayload &
>(second_op).
transpose();
3347 const Epetra_Map &first_op_init_map = first_op.OperatorRangeMap();
3348 i->reinit(
IndexSet(first_op_init_map),
3349 first_op.get_mpi_communicator(),
3353 const size_type i_local_size = i->end() - i->begin();
3355 const Epetra_Map &second_op_init_map = second_op.OperatorDomainMap();
3357 (void)second_op_init_map;
3358 Intermediate tril_int(View,
3360 const_cast<TrilinosScalar *>(i->begin()),
3365 first_op.Apply(tril_src, tril_int);
3366 second_op.Apply(tril_int, tril_dst);
3369 const_cast<TrilinosPayload &
>(first_op).
transpose();
3370 const_cast<TrilinosPayload &
>(second_op).
transpose();
3373 return_op.inv_vmult = [first_op, second_op](Domain & tril_dst,
3374 const Range &tril_src) {
3381 const Epetra_Map &first_op_init_map = first_op.OperatorRangeMap();
3382 i->reinit(
IndexSet(first_op_init_map),
3383 first_op.get_mpi_communicator(),
3387 const size_type i_local_size = i->end() - i->begin();
3389 const Epetra_Map &second_op_init_map = second_op.OperatorDomainMap();
3391 (void)second_op_init_map;
3392 Intermediate tril_int(View,
3394 const_cast<TrilinosScalar *>(i->begin()),
3400 first_op.ApplyInverse(tril_src, tril_int);
3401 second_op.ApplyInverse(tril_int, tril_dst);
3404 return_op.inv_Tvmult = [first_op, second_op](Range & tril_dst,
3405 const Domain &tril_src) {
3415 const_cast<TrilinosPayload &
>(first_op).
transpose();
3416 const_cast<TrilinosPayload &
>(second_op).
transpose();
3419 const Epetra_Map &first_op_init_map = first_op.OperatorDomainMap();
3420 i->reinit(
IndexSet(first_op_init_map),
3421 first_op.get_mpi_communicator(),
3425 const size_type i_local_size = i->end() - i->begin();
3427 const Epetra_Map &second_op_init_map = second_op.OperatorRangeMap();
3429 (void)second_op_init_map;
3430 Intermediate tril_int(View,
3432 const_cast<TrilinosScalar *>(i->begin()),
3440 second_op.ApplyInverse(tril_src, tril_int);
3441 first_op.ApplyInverse(tril_int, tril_dst);
3444 const_cast<TrilinosPayload &
>(first_op).
transpose();
3445 const_cast<TrilinosPayload &
>(second_op).
transpose();
3458 # include "trilinos_sparse_matrix.inst" 3472 const ::SparsityPattern &,
3481 const ::SparsityPattern &,
3491 const ::SparsityPattern &,
3507 const ::Vector<double> &)
const;
3512 const ::LinearAlgebra::distributed::Vector<double> &)
const;
3514 # ifdef DEAL_II_WITH_MPI 3515 # ifdef DEAL_II_TRILINOS_WITH_TPETRA 3518 ::LinearAlgebra::TpetraWrappers::Vector<double> &,
3519 const ::LinearAlgebra::TpetraWrappers::Vector<double> &)
const;
3523 ::LinearAlgebra::TpetraWrappers::Vector<float> &,
3524 const ::LinearAlgebra::TpetraWrappers::Vector<float> &)
const;
3538 const ::Vector<double> &)
const;
3543 const ::LinearAlgebra::distributed::Vector<double> &)
const;
3545 # ifdef DEAL_II_WITH_MPI 3546 # ifdef DEAL_II_TRILINOS_WITH_TPETRA 3549 ::LinearAlgebra::TpetraWrappers::Vector<double> &,
3550 const ::LinearAlgebra::TpetraWrappers::Vector<double> &)
const;
3554 ::LinearAlgebra::TpetraWrappers::Vector<float> &,
3555 const ::LinearAlgebra::TpetraWrappers::Vector<float> &)
const;
3569 const ::Vector<double> &)
const;
3574 const ::LinearAlgebra::distributed::Vector<double> &)
const;
3576 # ifdef DEAL_II_WITH_MPI 3577 # ifdef DEAL_II_TRILINOS_WITH_TPETRA 3580 ::LinearAlgebra::TpetraWrappers::Vector<double> &,
3581 const ::LinearAlgebra::TpetraWrappers::Vector<double> &)
const;
3585 ::LinearAlgebra::TpetraWrappers::Vector<float> &,
3586 const ::LinearAlgebra::TpetraWrappers::Vector<float> &)
const;
3600 const ::Vector<double> &)
const;
3605 const ::LinearAlgebra::distributed::Vector<double> &)
const;
3607 # ifdef DEAL_II_WITH_MPI 3608 # ifdef DEAL_II_TRILINOS_WITH_TPETRA 3611 ::LinearAlgebra::TpetraWrappers::Vector<double> &,
3612 const ::LinearAlgebra::TpetraWrappers::Vector<double> &)
const;
3616 ::LinearAlgebra::TpetraWrappers::Vector<float> &,
3617 const ::LinearAlgebra::TpetraWrappers::Vector<float> &)
const;
3627 DEAL_II_NAMESPACE_CLOSE
3629 #endif // DEAL_II_WITH_TRILINOS TrilinosScalar diag_element(const size_type i) const
Iterator lower_bound(Iterator first, Iterator last, const T &val)
static ::ExceptionBase & ExcTrilinosError(int arg1)
TrilinosScalar el(const size_type i, const size_type j) const
virtual double NormInf() const override
const Epetra_Map & col_partitioner() const
const Epetra_Map & domain_partitioner() const
TrilinosScalar frobenius_norm() const
void mmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
real_type l2_norm() const
#define AssertDimension(dim1, dim2)
TrilinosPayload null_payload() const
virtual int SetUseTranspose(bool UseTranspose) override
Contents is actually a matrix.
static ::ExceptionBase & ExcSourceEqualsDestination()
static ::ExceptionBase & ExcIO()
void clear_row(const size_type row, const TrilinosScalar new_diag_value=0)
size_type column_number(const size_type row, const size_type index) const
const Epetra_Map & range_partitioner() const
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
void vmult_add(VectorType &dst, const VectorType &src) const
Epetra_MultiVector VectorType
std::function< void(VectorType &, const VectorType &)> inv_Tvmult
Epetra_CombineMode last_action
const Epetra_FECrsGraph & trilinos_sparsity_pattern() const
void reinit(const Vector &v, const bool omit_zeroing_entries=false, const bool allow_different_maps=false)
#define AssertIndexRange(index, range)
TrilinosWrappers::types::int_type min_my_gid(const Epetra_BlockMap &map)
std::pair< size_type, size_type > local_range() const
virtual const char * Label() const override
TrilinosScalar operator()(const size_type i, const size_type j) const
std::function< void(VectorType &, const VectorType &)> Tvmult
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
const Epetra_Map & row_partitioner() const
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
SymmetricTensor< rank_, dim, typename ProductType< Number, OtherNumber >::type > operator+(const SymmetricTensor< rank_, dim, Number > &left, const SymmetricTensor< rank_, dim, OtherNumber > &right)
TrilinosScalar residual(MPI::Vector &dst, const MPI::Vector &x, const MPI::Vector &b) const
const Epetra_Comm & comm_self()
static ::ExceptionBase & ExcTrilinosError(int arg1)
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
TrilinosScalar matrix_scalar_product(const MPI::Vector &u, const MPI::Vector &v) const
std::unique_ptr< Epetra_CrsGraph > nonlocal_graph
static ::ExceptionBase & ExcDivideByZero()
LinearAlgebra::distributed::Vector< Number > Vector
void clear_rows(const std::vector< size_type > &rows, const TrilinosScalar new_diag_value=0)
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
std::shared_ptr< std::vector< size_type > > colnum_cache
SparseMatrix & operator*=(const TrilinosScalar factor)
std::unique_ptr< Epetra_FECrsMatrix > matrix
virtual int Apply(const VectorType &X, VectorType &Y) const override
SparseMatrix & operator=(const SparseMatrix &)=delete
TrilinosPayload transpose_payload() const
static ::ExceptionBase & ExcAccessToNonlocalRow(std::size_t arg1)
::types::global_dof_index size_type
virtual void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths) override
bool in_local_range(const size_type index) const
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual const Epetra_Map & OperatorRangeMap() const override
TrilinosPayload identity_payload() const
void add(const size_type i, const size_type j, const TrilinosScalar value)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
std::unique_ptr< Epetra_Export > nonlocal_matrix_exporter
TrilinosWrappers::types::int_type n_global_cols(const Epetra_CrsGraph &graph)
size_type memory_consumption() const
TrilinosWrappers::types::int_type global_row_index(const Epetra_CrsMatrix &matrix, const ::types::global_dof_index i)
const IndexSet & row_index_set() const
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
Epetra_MpiComm communicator
std::function< void(VectorType &, const VectorType &)> inv_vmult
TrilinosScalar matrix_norm_square(const MPI::Vector &v) const
const Epetra_FEVector & trilinos_vector() const
virtual int ApplyInverse(const VectorType &Y, VectorType &X) const override
IndexSet locally_owned_range_indices() const
const Epetra_CrsMatrix & trilinos_matrix() const
SymmetricTensor< rank_, dim, Number > transpose(const SymmetricTensor< rank_, dim, Number > &t)
virtual bool UseTranspose() const override
TrilinosWrappers::types::int_type global_column_index(const Epetra_CrsMatrix &matrix, const ::types::global_dof_index i)
Epetra_Operator & trilinos_operator() const
IndexSet locally_owned_range_indices() const
virtual const Epetra_Map & OperatorDomainMap() const override
size_type n_nonzero_elements() const
std::enable_if< std::is_same< typename VectorType::value_type, TrilinosScalar >::value >::type Tvmult(VectorType &dst, const VectorType &src) const
MPI_Comm get_mpi_communicator() const
static ::ExceptionBase & ExcNotQuadratic()
TrilinosWrappers::types::int_type n_global_elements(const Epetra_BlockMap &map)
void swap(Vector< Number > &u, Vector< Number > &v)
unsigned int row_length(const size_type row) const
void set_size(const size_type size)
void Tvmult_add(VectorType &dst, const VectorType &src) const
unsigned int global_dof_index
std::enable_if< std::is_same< typename VectorType::value_type, TrilinosScalar >::value >::type vmult(VectorType &dst, const VectorType &src) const
void reinit(const SparsityPatternType &sparsity_pattern)
size_type row_length(const size_type row) const
TrilinosScalar linfty_norm() const
const Epetra_BlockMap & trilinos_partitioner() const
void copy_from(const SparseMatrix &source)
const Epetra_Map & domain_partitioner() const
std::function< void(VectorType &, const VectorType &)> vmult
SparseMatrix & operator/=(const TrilinosScalar factor)
TrilinosWrappers::types::int_type max_my_gid(const Epetra_BlockMap &map)
virtual const Epetra_Comm & Comm() const override
std::pair< size_type, size_type > local_range() const
static ::ExceptionBase & ExcNotImplemented()
IndexSet locally_owned_domain_indices() const
static ::ExceptionBase & ExcMatrixNotCompressed()
IndexSet locally_owned_domain_indices() const
const Epetra_CrsGraph & trilinos_sparsity_pattern() const
bool is_element(const size_type index) const
void Tmmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
std::unique_ptr< Epetra_Map > column_space_map
virtual bool HasNormInf() const override
void compress(::VectorOperation::values operation)
const Epetra_MultiVector & trilinos_vector() const
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
std::unique_ptr< Epetra_CrsMatrix > nonlocal_matrix
MPI_Comm get_mpi_communicator() const
void set(const size_type i, const size_type j, const TrilinosScalar value)
size_type n_elements() const
#define AssertIsFinite(number)
unsigned int local_size() const
TrilinosScalar l1_norm() const
static ::ExceptionBase & ExcInternalError()
std::shared_ptr< std::vector< TrilinosScalar > > value_cache