16 #include <deal.II/lac/trilinos_sparse_matrix.h> 18 #ifdef DEAL_II_WITH_TRILINOS 20 # include <deal.II/base/utilities.h> 21 # include <deal.II/lac/sparse_matrix.h> 22 # include <deal.II/lac/trilinos_sparsity_pattern.h> 23 # include <deal.II/lac/sparsity_pattern.h> 24 # include <deal.II/lac/dynamic_sparsity_pattern.h> 25 # include <deal.II/lac/sparsity_tools.h> 26 # include <deal.II/lac/la_parallel_vector.h> 28 #ifdef DEAL_II_WITH_CXX11 29 # include <deal.II/lac/trilinos_precondition.h> 32 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
33 # include <Epetra_Export.h> 34 # include <ml_epetra_utils.h> 35 # include <ml_struct.h> 36 # include <Teuchos_RCP.hpp> 37 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
39 DEAL_II_NAMESPACE_OPEN
45 #ifndef DEAL_II_WITH_64BIT_INDICES 50 int n_global_elements (
const Epetra_BlockMap &map)
52 return map.NumGlobalElements();
55 int min_my_gid(
const Epetra_BlockMap &map)
57 return map.MinMyGID();
60 int max_my_gid(
const Epetra_BlockMap &map)
62 return map.MaxMyGID();
65 int n_global_cols(
const Epetra_CrsGraph &graph)
67 return graph.NumGlobalCols();
70 int global_column_index(
const Epetra_CrsMatrix &matrix,
int i)
72 return matrix.GCID(i);
75 int global_row_index(
const Epetra_CrsMatrix &matrix,
int i)
77 return matrix.GRID(i);
84 long long int n_global_elements (
const Epetra_BlockMap &map)
86 return map.NumGlobalElements64();
89 long long int min_my_gid(
const Epetra_BlockMap &map)
91 return map.MinMyGID64();
94 long long int max_my_gid(
const Epetra_BlockMap &map)
96 return map.MaxMyGID64();
99 long long int n_global_cols(
const Epetra_CrsGraph &graph)
101 return graph.NumGlobalCols64();
104 long long int global_column_index(
const Epetra_CrsMatrix &matrix,
int i)
106 return matrix.GCID64(i);
109 long long int global_row_index(
const Epetra_CrsMatrix &matrix,
int i)
111 return matrix.GRID64(i);
128 if ((this->
a_row == matrix->m())
140 TrilinosWrappers::types::int_type colnums =
matrix->
n();
153 ExtractGlobalRowCopy((TrilinosWrappers::types::int_type)this->
a_row,
156 reinterpret_cast<TrilinosWrappers::types::int_type *>(&((*
colnum_cache)[0])));
184 column_space_map (new Epetra_Map (0, 0,
186 matrix (new Epetra_FECrsMatrix(View, *column_space_map,
187 *column_space_map, 0)),
199 column_space_map (new Epetra_Map (input_map)),
200 matrix (new Epetra_FECrsMatrix(Copy, *column_space_map,
209 const std::vector<unsigned int> &n_entries_per_row)
211 column_space_map (new Epetra_Map (input_map)),
212 matrix (new Epetra_FECrsMatrix
213 (Copy, *column_space_map,
214 (int *)const_cast<unsigned int *>(&(n_entries_per_row[0])),
223 const Epetra_Map &input_col_map,
226 column_space_map (new Epetra_Map (input_col_map)),
227 matrix (new Epetra_FECrsMatrix(Copy, input_row_map,
236 const Epetra_Map &input_col_map,
237 const std::vector<unsigned int> &n_entries_per_row)
239 column_space_map (new Epetra_Map (input_col_map)),
240 matrix (new Epetra_FECrsMatrix(Copy, input_row_map,
241 (int *)const_cast<unsigned int *>(&(n_entries_per_row[0])),
251 const unsigned int n_max_entries_per_row)
264 matrix (new Epetra_FECrsMatrix(Copy,
268 n_max_entries_per_row,
278 const std::vector<unsigned int> &n_entries_per_row)
282 matrix (new Epetra_FECrsMatrix(Copy,
286 (int *)const_cast<unsigned int *>(&(n_entries_per_row[0])),
295 const MPI_Comm &communicator,
296 const unsigned int n_max_entries_per_row)
298 column_space_map (new Epetra_Map(parallel_partitioning.
299 make_trilinos_map(communicator, false))),
300 matrix (new Epetra_FECrsMatrix(Copy,
302 n_max_entries_per_row,
311 const MPI_Comm &communicator,
312 const std::vector<unsigned int> &n_entries_per_row)
314 column_space_map (new Epetra_Map(parallel_partitioning.
315 make_trilinos_map(communicator, false))),
316 matrix (new Epetra_FECrsMatrix(Copy,
318 (int *)const_cast<unsigned int *>(&(n_entries_per_row[0])),
327 const IndexSet &col_parallel_partitioning,
328 const MPI_Comm &communicator,
331 column_space_map (new Epetra_Map(col_parallel_partitioning.
332 make_trilinos_map(communicator, false))),
333 matrix (new Epetra_FECrsMatrix(Copy,
334 row_parallel_partitioning.
335 make_trilinos_map(communicator, false),
336 n_max_entries_per_row,
345 const IndexSet &col_parallel_partitioning,
346 const MPI_Comm &communicator,
347 const std::vector<unsigned int> &n_entries_per_row)
349 column_space_map (new Epetra_Map(col_parallel_partitioning.
350 make_trilinos_map(communicator, false))),
351 matrix (new Epetra_FECrsMatrix(Copy,
352 row_parallel_partitioning.
353 make_trilinos_map(communicator, false),
354 (int *)const_cast<unsigned int *>(&(n_entries_per_row[0])),
364 column_space_map (new Epetra_Map (sparsity_pattern.domain_partitioner())),
365 matrix (new Epetra_FECrsMatrix(Copy,
366 sparsity_pattern.trilinos_sparsity_pattern(),
372 ExcMessage(
"The Trilinos sparsity pattern has not been compressed."));
395 bool needs_deep_copy =
400 if (!needs_deep_copy)
402 const std::pair<size_type, size_type>
410 const int row_local =
411 matrix->RowMap().LID(static_cast<TrilinosWrappers::types::int_type>(row));
413 int n_entries, rhs_n_entries;
414 TrilinosScalar *value_ptr, *rhs_value_ptr;
415 int *index_ptr, *rhs_index_ptr;
416 int ierr = rhs.
matrix->ExtractMyRowView (row_local, rhs_n_entries,
417 rhs_value_ptr, rhs_index_ptr);
421 ierr =
matrix->ExtractMyRowView (row_local, n_entries, value_ptr,
425 if (n_entries != rhs_n_entries ||
426 std::memcmp(static_cast<void *>(index_ptr),
427 static_cast<void *>(rhs_index_ptr),
428 sizeof(
int)*n_entries) != 0)
430 needs_deep_copy =
true;
434 for (
int i=0; i<n_entries; ++i)
435 value_ptr[i] = rhs_value_ptr[i];
460 template <
typename SparsityPatternType>
462 reinit_matrix (
const Epetra_Map &input_row_map,
463 const Epetra_Map &input_col_map,
464 const SparsityPatternType &sparsity_pattern,
465 const bool exchange_data,
466 std_cxx11::shared_ptr<Epetra_Map> &column_space_map,
467 std_cxx11::shared_ptr<Epetra_FECrsMatrix> &matrix,
468 std_cxx11::shared_ptr<Epetra_CrsMatrix> &nonlocal_matrix,
469 std_cxx11::shared_ptr<Epetra_Export> &nonlocal_matrix_exporter)
473 nonlocal_matrix.reset();
474 nonlocal_matrix_exporter.reset();
476 if (input_row_map.Comm().MyPID() == 0)
479 static_cast<size_type
>(n_global_elements(input_row_map)));
481 static_cast<size_type
>(n_global_elements(input_col_map)));
484 column_space_map.reset (
new Epetra_Map (input_col_map));
493 trilinos_sparsity.
reinit (input_row_map, input_col_map,
494 sparsity_pattern, exchange_data);
495 matrix.reset (
new Epetra_FECrsMatrix
496 (Copy, trilinos_sparsity.trilinos_sparsity_pattern(),
false));
501 const size_type first_row = min_my_gid(input_row_map),
502 last_row = max_my_gid(input_row_map)+1;
503 std::vector<int> n_entries_per_row(last_row-first_row);
505 for (size_type row=first_row; row<last_row; ++row)
506 n_entries_per_row[row-first_row] = sparsity_pattern.row_length(row);
522 std_cxx11::shared_ptr<Epetra_CrsGraph> graph;
523 if (input_row_map.Comm().NumProc() > 1)
524 graph.reset (
new Epetra_CrsGraph (Copy, input_row_map,
525 &n_entries_per_row[0],
true));
527 graph.reset (
new Epetra_CrsGraph (Copy, input_row_map, input_col_map,
528 &n_entries_per_row[0],
true));
535 std::vector<TrilinosWrappers::types::int_type> row_indices;
537 for (size_type row=first_row; row<last_row; ++row)
539 const int row_length = sparsity_pattern.row_length(row);
543 row_indices.resize (row_length, -1);
545 typename SparsityPatternType::iterator p = sparsity_pattern.begin(row);
546 for (size_type col=0; p != sparsity_pattern.end(row); ++p, ++col)
547 row_indices[col] = p->column();
549 graph->Epetra_CrsGraph::InsertGlobalIndices (row, row_length,
557 graph->FillComplete(input_col_map, input_row_map);
558 graph->OptimizeStorage();
562 static_cast<size_type>(n_global_cols(*graph)));
566 matrix.reset (
new Epetra_FECrsMatrix(Copy, *graph,
false));
578 class Epetra_CrsGraphMod :
public Epetra_CrsGraph
581 Epetra_CrsGraphMod (
const Epetra_Map &row_map,
582 const int *n_entries_per_row)
584 Epetra_CrsGraph(Copy, row_map, n_entries_per_row, true)
587 void SetIndicesAreGlobal()
589 this->Epetra_CrsGraph::SetIndicesAreGlobal(
true);
598 reinit_matrix (
const Epetra_Map &input_row_map,
599 const Epetra_Map &input_col_map,
601 const bool exchange_data,
602 std_cxx11::shared_ptr<Epetra_Map> &column_space_map,
603 std_cxx11::shared_ptr<Epetra_FECrsMatrix> &matrix,
604 std_cxx11::shared_ptr<Epetra_CrsMatrix> &nonlocal_matrix,
605 std_cxx11::shared_ptr<Epetra_Export> &nonlocal_matrix_exporter)
608 nonlocal_matrix.reset();
609 nonlocal_matrix_exporter.reset();
612 static_cast<size_type>(n_global_elements(input_row_map)));
614 static_cast<size_type>(n_global_elements(input_col_map)));
616 column_space_map.reset (
new Epetra_Map (input_col_map));
620 if (relevant_rows.size() == 0)
622 relevant_rows.
set_size(n_global_elements(input_row_map));
623 relevant_rows.add_range(0, n_global_elements(input_row_map));
625 relevant_rows.compress();
626 Assert(relevant_rows.n_elements() >=
static_cast<unsigned int>(input_row_map.NumMyElements()),
627 ExcMessage(
"Locally relevant rows of sparsity pattern must contain " 628 "all locally owned rows"));
633 bool have_ghost_rows =
false;
635 std::vector<::types::global_dof_index> indices;
636 relevant_rows.fill_index_vector(indices);
637 Epetra_Map relevant_map (TrilinosWrappers::types::int_type(-1),
638 TrilinosWrappers::types::int_type(relevant_rows.n_elements()),
639 (indices.empty() ? 0 :
640 reinterpret_cast<TrilinosWrappers::types::int_type *
>(&indices[0])),
641 0, input_row_map.Comm());
642 if (relevant_map.SameAs(input_row_map))
643 have_ghost_rows =
false;
645 have_ghost_rows =
true;
648 const unsigned int n_rows = relevant_rows.n_elements();
649 std::vector<TrilinosWrappers::types::int_type> ghost_rows;
650 std::vector<int> n_entries_per_row(input_row_map.NumMyElements());
651 std::vector<int> n_entries_per_ghost_row;
652 for (
unsigned int i=0, own=0; i<n_rows; ++i)
654 const TrilinosWrappers::types::int_type global_row =
655 relevant_rows.nth_index_in_set(i);
656 if (input_row_map.MyGID(global_row))
657 n_entries_per_row[own++] = sparsity_pattern.
row_length(global_row);
658 else if (sparsity_pattern.
row_length(global_row) > 0)
660 ghost_rows.push_back(global_row);
661 n_entries_per_ghost_row.push_back(sparsity_pattern.
row_length(global_row));
665 Epetra_Map off_processor_map(-1, ghost_rows.size(),
666 (ghost_rows.size()>0)?(&ghost_rows[0]):NULL,
667 0, input_row_map.Comm());
669 std_cxx11::shared_ptr<Epetra_CrsGraph> graph;
670 std_cxx11::shared_ptr<Epetra_CrsGraphMod> nonlocal_graph;
671 if (input_row_map.Comm().NumProc() > 1)
673 graph.reset (
new Epetra_CrsGraph (Copy, input_row_map,
674 (n_entries_per_row.size()>0)?(&n_entries_per_row[0]):NULL,
675 exchange_data ? false :
true));
676 if (have_ghost_rows ==
true)
677 nonlocal_graph.reset (
new Epetra_CrsGraphMod (off_processor_map,
678 &n_entries_per_ghost_row[0]));
681 graph.reset (
new Epetra_CrsGraph (Copy, input_row_map, input_col_map,
682 (n_entries_per_row.size()>0)?(&n_entries_per_row[0]):NULL,
686 std::vector<TrilinosWrappers::types::int_type> row_indices;
688 for (
unsigned int i=0; i<n_rows; ++i)
690 const TrilinosWrappers::types::int_type global_row =
691 relevant_rows.nth_index_in_set(i);
692 const int row_length = sparsity_pattern.
row_length(global_row);
696 row_indices.resize (row_length, -1);
697 for (
int col=0; col < row_length; ++col)
698 row_indices[col] = sparsity_pattern.
column_number(global_row, col);
700 if (input_row_map.MyGID(global_row))
701 graph->InsertGlobalIndices (global_row, row_length, &row_indices[0]);
705 nonlocal_graph->InsertGlobalIndices (global_row, row_length,
711 if (nonlocal_graph.get() != 0)
717 nonlocal_graph->SetIndicesAreGlobal();
718 Assert(nonlocal_graph->IndicesAreGlobal() ==
true,
720 nonlocal_graph->FillComplete(input_col_map, input_row_map);
721 nonlocal_graph->OptimizeStorage();
726 Epetra_Export exporter(nonlocal_graph->RowMap(), input_row_map);
727 int ierr = graph->Export(*nonlocal_graph, exporter, Add);
732 nonlocal_matrix.reset (
new Epetra_CrsMatrix(Copy, *nonlocal_graph));
735 graph->FillComplete(input_col_map, input_row_map);
736 graph->OptimizeStorage();
739 n_global_cols(*graph)));
741 matrix.reset (
new Epetra_FECrsMatrix(Copy, *graph,
false));
747 template <
typename SparsityPatternType>
751 const Epetra_Map rows (static_cast<TrilinosWrappers::types::int_type>(sparsity_pattern.n_rows()),
754 const Epetra_Map columns (static_cast<TrilinosWrappers::types::int_type>(sparsity_pattern.n_cols()),
758 reinit_matrix (rows, columns, sparsity_pattern,
false,
765 template <
typename SparsityPatternType>
768 const SparsityPatternType &sparsity_pattern,
769 const bool exchange_data)
771 reinit_matrix (input_map, input_map, sparsity_pattern, exchange_data,
781 template <
typename SparsityPatternType>
784 const IndexSet &col_parallel_partitioning,
785 const SparsityPatternType &sparsity_pattern,
786 const MPI_Comm &communicator,
787 const bool exchange_data)
793 reinit_matrix (row_map, col_map, sparsity_pattern, exchange_data,
805 template <
typename SparsityPatternType>
808 const Epetra_Map &col_map,
809 const SparsityPatternType &sparsity_pattern,
810 const bool exchange_data)
812 reinit_matrix (row_map, col_map, sparsity_pattern, exchange_data,
834 matrix.reset (
new Epetra_FECrsMatrix
851 if (
this == &sparse_matrix)
857 matrix.reset (
new Epetra_FECrsMatrix
872 template <
typename number>
875 const IndexSet &col_parallel_partitioning,
876 const ::SparseMatrix<number> &dealii_sparse_matrix,
877 const MPI_Comm &communicator,
878 const double drop_tolerance,
879 const bool copy_values,
880 const ::SparsityPattern *use_this_sparsity)
882 if (copy_values ==
false)
886 if (use_this_sparsity == 0)
887 reinit (row_parallel_partitioning, col_parallel_partitioning,
888 dealii_sparse_matrix.get_sparsity_pattern(),
889 communicator,
false);
891 reinit (row_parallel_partitioning, col_parallel_partitioning,
892 *use_this_sparsity, communicator,
false);
896 const size_type n_rows = dealii_sparse_matrix.m();
901 const ::SparsityPattern &sparsity_pattern =
902 (use_this_sparsity!=0)? *use_this_sparsity :
903 dealii_sparse_matrix.get_sparsity_pattern();
909 reinit (row_parallel_partitioning, col_parallel_partitioning,
910 sparsity_pattern, communicator,
false);
919 std::vector<size_type> row_indices (maximum_row_length);
920 std::vector<TrilinosScalar> values (maximum_row_length);
924 if (row_parallel_partitioning.
is_element(row) ==
true)
927 sparsity_pattern.begin(row);
928 typename ::SparseMatrix<number>::const_iterator it =
929 dealii_sparse_matrix.begin(row);
931 if (sparsity_pattern.n_rows() == sparsity_pattern.n_cols())
935 if (std::fabs(it->value()) > drop_tolerance)
937 values[col] = it->value();
938 row_indices[col++] = it->column();
944 while (it != dealii_sparse_matrix.end(row) &&
945 select_index != sparsity_pattern.end(row))
947 while (select_index->
column() < it->column() &&
948 select_index != sparsity_pattern.end(row))
950 while (it->column() < select_index->
column() &&
951 it != dealii_sparse_matrix.end(row))
954 if (it == dealii_sparse_matrix.end(row))
956 if (std::fabs(it->value()) > drop_tolerance)
958 values[col] = it->value();
959 row_indices[col++] = it->column();
964 set (row, col,
reinterpret_cast<size_type *
>(&row_indices[0]),
972 template <
typename number>
975 const double drop_tolerance,
976 const bool copy_values,
977 const ::SparsityPattern *use_this_sparsity)
979 reinit (complete_index_set(dealii_sparse_matrix.m()),
980 complete_index_set(dealii_sparse_matrix.n()),
981 dealii_sparse_matrix, MPI_COMM_SELF, drop_tolerance,
982 copy_values, use_this_sparsity);
987 template <
typename number>
990 const ::SparseMatrix<number> &dealii_sparse_matrix,
991 const double drop_tolerance,
992 const bool copy_values,
993 const ::SparsityPattern *use_this_sparsity)
996 MPI_COMM_SELF, drop_tolerance, copy_values, use_this_sparsity);
1001 template <
typename number>
1004 const Epetra_Map &input_col_map,
1005 const ::SparseMatrix<number> &dealii_sparse_matrix,
1006 const double drop_tolerance,
1007 const bool copy_values,
1008 const ::SparsityPattern *use_this_sparsity)
1011 dealii_sparse_matrix, MPI_COMM_SELF,
1012 drop_tolerance, copy_values, use_this_sparsity);
1019 const bool copy_values)
1021 Assert (input_matrix.Filled()==
true,
1022 ExcMessage(
"Input CrsMatrix has not called FillComplete()!"));
1026 const Epetra_CrsGraph *graph = &input_matrix.Graph();
1031 matrix.reset (
new Epetra_FECrsMatrix(Copy, *graph,
false));
1035 if (copy_values ==
true)
1039 const TrilinosScalar *in_values = input_matrix[0];
1040 TrilinosScalar *values = (*matrix)[0];
1041 const size_type my_nonzeros = input_matrix.NumMyNonzeros();
1042 std::memcpy (&values[0], &in_values[0],
1043 my_nonzeros*
sizeof (TrilinosScalar));
1071 ExcMessage(
"Operation and argument to compress() do not match"));
1095 ierr =
matrix->OptimizeStorage ();
1126 const TrilinosScalar new_diag_value)
1133 matrix->LRID(static_cast<TrilinosWrappers::types::int_type>(row));
1136 TrilinosScalar *values;
1139 const int ierr =
matrix->ExtractMyRowView(local_row, num_entries,
1140 values, col_indices);
1146 int *diag_find = std::find(col_indices,col_indices+num_entries,local_row);
1147 int diag_index = (int)(diag_find - col_indices);
1149 for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
1150 if (diag_index != j || new_diag_value == 0)
1153 if (diag_find && std::fabs(values[diag_index]) == 0.0 &&
1154 new_diag_value != 0.0)
1155 values[diag_index] = new_diag_value;
1163 const TrilinosScalar new_diag_value)
1165 for (
size_type row=0; row<rows.size(); ++row)
1177 int trilinos_i =
matrix->LRID(static_cast<TrilinosWrappers::types::int_type>(i)),
1178 trilinos_j =
matrix->LCID(static_cast<TrilinosWrappers::types::int_type>(j));
1179 TrilinosScalar value = 0.;
1187 if (trilinos_i == -1)
1201 int nnz_present =
matrix->NumMyEntries(trilinos_i);
1204 TrilinosScalar *values;
1210 int ierr =
matrix->ExtractMyRowView(trilinos_i, nnz_extracted,
1211 values, col_indices);
1215 Assert (nnz_present == nnz_extracted,
1222 int *el_find = std::find(col_indices, col_indices + nnz_present, trilinos_j);
1224 int local_col_index = (int)(el_find - col_indices);
1234 if (local_col_index == nnz_present)
1239 value = values[local_col_index];
1253 int trilinos_i =
matrix->LRID(static_cast<TrilinosWrappers::types::int_type>(i)),
1254 trilinos_j =
matrix->LCID(static_cast<TrilinosWrappers::types::int_type>(j));
1255 TrilinosScalar value = 0.;
1264 if ((trilinos_i == -1 ) || (trilinos_j == -1))
1275 int nnz_present =
matrix->NumMyEntries(trilinos_i);
1278 TrilinosScalar *values;
1283 int ierr =
matrix->ExtractMyRowView(trilinos_i, nnz_extracted,
1284 values, col_indices);
1288 Assert (nnz_present == nnz_extracted,
1294 int *el_find = std::find(col_indices, col_indices + nnz_present, trilinos_j);
1296 int local_col_index = (int)(el_find - col_indices);
1306 if (local_col_index == nnz_present)
1309 value = values[local_col_index];
1346 int local_row =
matrix->LRID(static_cast<TrilinosWrappers::types::int_type>(row));
1353 int ierr =
matrix->NumMyRowEntries (local_row, ncols);
1364 const std::vector<size_type> &col_indices,
1366 const bool elide_zero_values)
1368 Assert (row_indices.size() == values.
m(),
1370 Assert (col_indices.size() == values.
n(),
1373 for (
size_type i=0; i<row_indices.size(); ++i)
1374 set (row_indices[i], col_indices.size(), &col_indices[0], &values(i,0),
1382 const std::vector<size_type> &col_indices,
1383 const std::vector<TrilinosScalar> &values,
1384 const bool elide_zero_values)
1386 Assert (col_indices.size() == values.size(),
1389 set (row, col_indices.size(), &col_indices[0], &values[0],
1399 const TrilinosScalar *values,
1400 const bool elide_zero_values)
1415 TrilinosWrappers::types::int_type *col_index_ptr;
1416 TrilinosScalar *col_value_ptr;
1417 TrilinosWrappers::types::int_type n_columns;
1419 TrilinosScalar short_val_array[100];
1420 TrilinosWrappers::types::int_type short_index_array[100];
1421 std::vector<TrilinosScalar> long_val_array;
1422 std::vector<TrilinosWrappers::types::int_type> long_index_array;
1428 if (elide_zero_values ==
false)
1430 col_index_ptr = (TrilinosWrappers::types::int_type *)col_indices;
1431 col_value_ptr =
const_cast<TrilinosScalar *
>(values);
1440 long_val_array.resize(n_cols);
1441 long_index_array.resize(n_cols);
1442 col_index_ptr = &long_index_array[0];
1443 col_value_ptr = &long_val_array[0];
1447 col_index_ptr = &short_index_array[0];
1448 col_value_ptr = &short_val_array[0];
1454 const double value = values[j];
1458 col_index_ptr[n_columns] = col_indices[j];
1459 col_value_ptr[n_columns] = value;
1476 if (
matrix->RowMap().MyGID(static_cast<TrilinosWrappers::types::int_type>(row)) ==
true)
1478 if (
matrix->Filled() ==
false)
1480 ierr =
matrix->Epetra_CrsMatrix::InsertGlobalValues(
1481 static_cast<TrilinosWrappers::types::int_type>(row),
1482 static_cast<int>(n_columns),const_cast<double *>(col_value_ptr),
1492 ierr =
matrix->Epetra_CrsMatrix::ReplaceGlobalValues(row, n_columns,
1506 if (
matrix->Filled() ==
false)
1508 ierr =
matrix->InsertGlobalValues (1,
1509 (TrilinosWrappers::types::int_type *)&row,
1510 n_columns, col_index_ptr,
1512 Epetra_FECrsMatrix::ROW_MAJOR);
1517 ierr =
matrix->ReplaceGlobalValues (1,
1518 (TrilinosWrappers::types::int_type *)&row,
1519 n_columns, col_index_ptr,
1521 Epetra_FECrsMatrix::ROW_MAJOR);
1538 const bool elide_zero_values)
1540 Assert (indices.size() == values.
m(),
1544 for (
size_type i=0; i<indices.size(); ++i)
1545 add (indices[i], indices.size(), &indices[0], &values(i,0),
1553 const std::vector<size_type> &col_indices,
1555 const bool elide_zero_values)
1557 Assert (row_indices.size() == values.
m(),
1559 Assert (col_indices.size() == values.
n(),
1562 for (
size_type i=0; i<row_indices.size(); ++i)
1563 add (row_indices[i], col_indices.size(), &col_indices[0],
1564 &values(i,0), elide_zero_values);
1571 const std::vector<size_type> &col_indices,
1572 const std::vector<TrilinosScalar> &values,
1573 const bool elide_zero_values)
1575 Assert (col_indices.size() == values.size(),
1578 add (row, col_indices.size(), &col_indices[0], &values[0],
1588 const TrilinosScalar *values,
1589 const bool elide_zero_values,
1599 matrix->RowMap(),
false);
1606 TrilinosWrappers::types::int_type *col_index_ptr;
1607 TrilinosScalar *col_value_ptr;
1608 TrilinosWrappers::types::int_type n_columns;
1610 double short_val_array[100];
1611 TrilinosWrappers::types::int_type short_index_array[100];
1612 std::vector<TrilinosScalar> long_val_array;
1613 std::vector<TrilinosWrappers::types::int_type> long_index_array;
1618 if (elide_zero_values ==
false)
1620 col_index_ptr = (TrilinosWrappers::types::int_type *)col_indices;
1621 col_value_ptr =
const_cast<TrilinosScalar *
>(values);
1634 long_val_array.resize(n_cols);
1635 long_index_array.resize(n_cols);
1636 col_index_ptr = &long_index_array[0];
1637 col_value_ptr = &long_val_array[0];
1641 col_index_ptr = &short_index_array[0];
1642 col_value_ptr = &short_val_array[0];
1648 const double value = values[j];
1653 col_index_ptr[n_columns] = col_indices[j];
1654 col_value_ptr[n_columns] = value;
1671 if (
matrix->RowMap().MyGID(static_cast<TrilinosWrappers::types::int_type>(row)) ==
true)
1673 ierr =
matrix->Epetra_CrsMatrix::SumIntoGlobalValues(row, n_columns,
1684 ExcMessage(
"Attempted to write into off-processor matrix row " 1685 "that has not be specified as being writable upon " 1701 ierr =
matrix->SumIntoGlobalValues (1,
1702 (TrilinosWrappers::types::int_type *)&row, n_columns,
1705 Epetra_FECrsMatrix::ROW_MAJOR);
1711 std::cout <<
"------------------------------------------" 1713 std::cout <<
"Got error " << ierr <<
" in row " << row
1714 <<
" of proc " <<
matrix->RowMap().Comm().MyPID()
1715 <<
" when trying to add the columns:" << std::endl;
1716 for (TrilinosWrappers::types::int_type i=0; i<n_columns; ++i)
1717 std::cout << col_index_ptr[i] <<
" ";
1718 std::cout << std::endl << std::endl;
1719 std::cout <<
"Matrix row " 1720 << (
matrix->RowMap().MyGID(static_cast<TrilinosWrappers::types::int_type>(row)) ==
false ?
"(nonlocal part)" :
"")
1721 <<
" has the following indices:" << std::endl;
1722 std::vector<TrilinosWrappers::types::int_type> indices;
1723 const Epetra_CrsGraph *graph =
1725 matrix->RowMap().MyGID(static_cast<TrilinosWrappers::types::int_type>(row)) ==
false) ?
1728 indices.resize(graph->NumGlobalIndices(static_cast<TrilinosWrappers::types::int_type>(row)));
1730 graph->ExtractGlobalRowCopy(static_cast<TrilinosWrappers::types::int_type>(row),
1731 indices.size(), n_indices, &indices[0]);
1732 AssertDimension(static_cast<unsigned int>(n_indices), indices.size());
1734 for (TrilinosWrappers::types::int_type i=0; i<n_indices; ++i)
1735 std::cout << indices[i] <<
" ";
1736 std::cout << std::endl << std::endl;
1752 const int ierr =
matrix->PutScalar(d);
1771 ExcMessage(
"Can only add matrices with same distribution of rows"));
1773 ExcMessage(
"Addition of matrices only allowed if matrices are " 1774 "filled, i.e., compress() has been called"));
1776 const std::pair<size_type, size_type>
1778 const bool same_col_map =
matrix->ColMap().SameAs(rhs.
matrix->ColMap());
1782 const int row_local =
1783 matrix->RowMap().LID(static_cast<TrilinosWrappers::types::int_type>(row));
1789 int n_entries, rhs_n_entries;
1790 TrilinosScalar *value_ptr, *rhs_value_ptr;
1791 int *index_ptr, *rhs_index_ptr;
1792 int ierr = rhs.
matrix->ExtractMyRowView (row_local, rhs_n_entries,
1793 rhs_value_ptr, rhs_index_ptr);
1797 ierr =
matrix->ExtractMyRowView (row_local, n_entries, value_ptr,
1800 bool expensive_checks = (n_entries != rhs_n_entries || !same_col_map);
1801 if (!expensive_checks)
1805 expensive_checks = std::memcmp(static_cast<void *>(index_ptr),
1806 static_cast<void *>(rhs_index_ptr),
1807 sizeof(
int)*n_entries) != 0;
1808 if (!expensive_checks)
1809 for (
int i=0; i<n_entries; ++i)
1810 value_ptr[i] += rhs_value_ptr[i] * factor;
1816 if (expensive_checks)
1818 for (
int i=0; i<rhs_n_entries; ++i)
1820 if (rhs_value_ptr[i] == 0.)
1822 const TrilinosWrappers::types::int_type rhs_global_col =
1823 global_column_index(*rhs.
matrix, rhs_index_ptr[i]);
1824 int local_col =
matrix->ColMap().LID(rhs_global_col);
1826 index_ptr+n_entries,
1828 Assert(local_index != index_ptr + n_entries &&
1829 *local_index == local_col,
1830 ExcMessage(
"Adding the entries from the other matrix " 1831 "failed, because the sparsity pattern " 1832 "of that matrix includes more elements than the " 1833 "calling matrix, which is not allowed."));
1834 value_ptr[local_index-index_ptr] += factor * rhs_value_ptr[i];
1852 if (!
matrix->UseTranspose())
1854 ierr =
matrix->SetUseTranspose (
true);
1859 ierr =
matrix->SetUseTranspose (
false);
1869 const int ierr =
matrix->Scale (a);
1883 const TrilinosScalar factor = 1./a;
1885 const int ierr =
matrix->Scale (factor);
1898 return matrix->NormOne();
1907 return matrix->NormInf();
1916 return matrix->NormFrobenius();
1925 template <
typename VectorType>
1927 void check_vector_map_equality(
const Epetra_CrsMatrix &,
1934 void check_vector_map_equality(
const Epetra_CrsMatrix &m,
1939 ExcMessage (
"Column map of matrix does not fit with vector map!"));
1941 ExcMessage (
"Row map of matrix does not fit with vector map!"));
1950 template <
typename VectorType>
1953 const VectorType &src)
const 1960 internal::SparseMatrix::check_vector_map_equality(*
matrix, src, dst);
1961 const size_type dst_local_size = dst.end() - dst.begin();
1963 const size_type src_local_size = src.end() - src.begin();
1966 Epetra_MultiVector tril_dst (View,
matrix->RangeMap(), dst.begin(),
1968 Epetra_MultiVector tril_src (View,
matrix->DomainMap(),
1969 const_cast<TrilinosScalar *
>(src.begin()),
1972 const int ierr =
matrix->Multiply (
false, tril_src, tril_dst);
1979 template <
typename VectorType>
1982 const VectorType &src)
const 1987 internal::SparseMatrix::check_vector_map_equality(*
matrix, dst, src);
1988 const size_type dst_local_size = dst.end() - dst.begin();
1990 const size_type src_local_size = src.end() - src.begin();
1993 Epetra_MultiVector tril_dst (View,
matrix->DomainMap(), dst.begin(),
1995 Epetra_MultiVector tril_src (View,
matrix->RangeMap(),
1996 const_cast<double *
>(src.begin()),
1999 const int ierr =
matrix->Multiply (
true, tril_src, tril_dst);
2006 template <
typename VectorType>
2009 const VectorType &src)
const 2019 temp_vector.
reinit(dst.end()-dst.begin(),
true);
2022 vmult (temp_vector,
static_cast<const ::Vector<TrilinosScalar>&
>(src_view));
2023 if (dst_view.size() > 0)
2024 dst_view += temp_vector;
2029 template <
typename VectorType>
2032 const VectorType &src)
const 2042 temp_vector.
reinit(dst.end()-dst.begin(),
true);
2045 Tvmult (temp_vector,
static_cast<const ::Vector<TrilinosScalar>&
>(src_view));
2046 if (dst_view.size() > 0)
2047 dst_view += temp_vector;
2059 temp_vector.
reinit(v,
true);
2061 vmult (temp_vector, v);
2062 return temp_vector*v;
2075 temp_vector.
reinit(v,
true);
2077 vmult (temp_vector, v);
2078 return u*temp_vector;
2099 typedef ::types::global_dof_index size_type;
2105 const bool transpose_left)
2107 #ifdef DEAL_II_WITH_64BIT_INDICES 2110 const bool use_vector = (V.
size() == inputright.
m() ? true :
false);
2111 if (transpose_left ==
false)
2113 Assert (inputleft.
n() == inputright.
m(),
2116 ExcMessage (
"Parallel partitioning of A and B does not fit."));
2120 Assert (inputleft.
m() == inputright.
m(),
2123 ExcMessage (
"Parallel partitioning of A and B does not fit."));
2134 Teuchos::RCP<Epetra_CrsMatrix> mod_B;
2135 if (use_vector ==
false)
2137 mod_B = Teuchos::rcp(const_cast<Epetra_CrsMatrix *>
2143 mod_B = Teuchos::rcp(
new Epetra_CrsMatrix
2149 ExcMessage (
"Parallel distribution of matrix B and vector V " 2150 "does not match."));
2153 for (
int i=0; i<local_N; ++i)
2156 double *new_data, *B_data;
2157 mod_B->ExtractMyRowView (i, N_entries, new_data);
2160 for (TrilinosWrappers::types::int_type j=0; j<N_entries; ++j)
2161 new_data[j] = value * B_data[j];
2171 ML_Comm_Create(&comm);
2173 const Epetra_MpiComm *epcomm =
dynamic_cast<const Epetra_MpiComm *
>(&(inputleft.
trilinos_matrix().Comm()));
2175 if (epcomm) ML_Comm_Set_UsrComm(comm,epcomm->Comm());
2177 ML_Operator *A_ = ML_Operator_Create(comm);
2178 ML_Operator *B_ = ML_Operator_Create(comm);
2179 ML_Operator *C_ = ML_Operator_Create(comm);
2182 if (transpose_left ==
false)
2183 ML_Operator_WrapEpetraCrsMatrix
2192 ExcMessage(
"Matrix must be partitioned contiguously between procs."));
2193 for (
unsigned int i=0; i<inputleft.
local_size(); ++i)
2195 int num_entries, * indices;
2199 #ifndef DEAL_II_WITH_64BIT_INDICES 2201 for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
2202 sparsity_transposed.add (inputleft.
trilinos_matrix().ColMap().GID(indices[j]),
2206 for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
2207 sparsity_transposed.add (inputleft.
trilinos_matrix().ColMap().GID64(indices[j]),
2212 sparsity_transposed.compress();
2213 transposed_mat.
reinit (sparsity_transposed);
2214 for (
unsigned int i=0; i<inputleft.
local_size(); ++i)
2216 int num_entries, * indices;
2221 #ifndef DEAL_II_WITH_64BIT_INDICES 2223 for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
2228 for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
2234 ML_Operator_WrapEpetraCrsMatrix
2235 (const_cast<Epetra_CrsMatrix *>(&transposed_mat.trilinos_matrix()),
2238 ML_Operator_WrapEpetraCrsMatrix(mod_B.get(),B_,
false);
2248 ML_Operator *Btmp, *Ctmp, *Ctmp2, *tptr;
2249 ML_CommInfoOP *getrow_comm;
2251 TrilinosWrappers::types::int_type N_input_vector = B_->invec_leng;
2252 getrow_comm = B_->getrow->pre_comm;
2253 if ( getrow_comm != NULL)
2254 for (TrilinosWrappers::types::int_type i = 0; i < getrow_comm->N_neighbors; i++)
2255 for (TrilinosWrappers::types::int_type j = 0; j < getrow_comm->neighbors[i].N_send; j++)
2256 AssertThrow (getrow_comm->neighbors[i].send_list[j] < N_input_vector,
2259 ML_create_unique_col_id(N_input_vector, &(B_->getrow->loc_glob_map),
2260 getrow_comm, &max_per_proc, B_->comm);
2261 B_->getrow->use_loc_glob_map = ML_YES;
2262 if (A_->getrow->pre_comm != NULL)
2263 ML_exchange_rows( B_, &Btmp, A_->getrow->pre_comm);
2267 ML_matmat_mult(A_, Btmp , &Ctmp);
2271 ML_free(B_->getrow->loc_glob_map);
2272 B_->getrow->loc_glob_map = NULL;
2273 B_->getrow->use_loc_glob_map = ML_NO;
2274 if (A_->getrow->pre_comm != NULL)
2277 while ( (tptr!= NULL) && (tptr->sub_matrix != B_))
2278 tptr = tptr->sub_matrix;
2279 if (tptr != NULL) tptr->sub_matrix = NULL;
2280 ML_RECUR_CSR_MSRdata_Destroy(Btmp);
2281 ML_Operator_Destroy(&Btmp);
2285 if (A_->getrow->post_comm != NULL)
2286 ML_exchange_rows(Ctmp, &Ctmp2, A_->getrow->post_comm);
2290 ML_back_to_csrlocal(Ctmp2, C_, max_per_proc);
2292 ML_RECUR_CSR_MSRdata_Destroy (Ctmp);
2293 ML_Operator_Destroy (&Ctmp);
2295 if (A_->getrow->post_comm != NULL)
2297 ML_RECUR_CSR_MSRdata_Destroy(Ctmp2);
2298 ML_Operator_Destroy (&Ctmp2);
2303 Epetra_CrsMatrix *C_mat;
2304 ML_Operator2EpetraCrsMatrix(C_, C_mat);
2305 C_mat->FillComplete(mod_B->DomainMap(),
2309 C_mat->OptimizeStorage();
2314 ML_Operator_Destroy (&A_);
2315 ML_Operator_Destroy (&B_);
2316 ML_Operator_Destroy (&C_);
2317 ML_Comm_Destroy (&comm);
2327 #ifdef DEAL_II_WITH_64BIT_INDICES 2330 internals::perform_mmult (*
this, B, C, V,
false);
2340 #ifdef DEAL_II_WITH_64BIT_INDICES 2343 internals::perform_mmult (*
this, B, C, V,
true);
2361 const bool print_detailed_trilinos_information)
const 2363 if (print_detailed_trilinos_information ==
true)
2371 for (
int i=0; i<
matrix->NumMyRows(); ++i)
2373 matrix->ExtractMyRowView (i, num_entries, values, indices);
2374 for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
2375 out <<
"(" << global_row_index(*
matrix,i) <<
"," 2376 << global_column_index(*
matrix,indices[j]) <<
") " 2377 << values[j] << std::endl;
2389 size_type static_memory =
sizeof(*this) +
sizeof (*matrix)
2390 +
sizeof(*
matrix->Graph().DataPtr());
2391 return ((
sizeof(TrilinosScalar)+
sizeof(TrilinosWrappers::types::int_type))*
2400 return matrix->DomainMap();
2408 return matrix->RangeMap();
2432 #ifdef DEAL_II_WITH_MPI 2434 const Epetra_MpiComm *mpi_comm
2435 =
dynamic_cast<const Epetra_MpiComm *
>(&
matrix->RangeMap().Comm());
2437 return mpi_comm->Comm();
2440 return MPI_COMM_SELF;
2447 #ifdef DEAL_II_WITH_CXX11 2455 #ifndef DEAL_II_WITH_MPI 2457 make_serial_Epetra_map (
const IndexSet &serial_partitioning)
2460 return Epetra_Map(TrilinosWrappers::types::int_type(serial_partitioning.
size()),
2461 TrilinosWrappers::types::int_type(serial_partitioning.
n_elements()),
2462 0, Epetra_SerialComm());
2471 : use_transpose (false),
2472 #ifdef DEAL_II_WITH_MPI
2473 communicator (MPI_COMM_SELF),
2474 domain_map (
IndexSet().make_trilinos_map(communicator.Comm())),
2475 range_map (
IndexSet().make_trilinos_map(communicator.Comm()))
2484 ExcMessage(
"Uninitialized TrilinosPayload::vmult called" 2485 "(Default constructor)"));
2491 ExcMessage(
"Uninitialized TrilinosPayload::Tvmult called" 2492 "(Default constructor)"));
2498 ExcMessage(
"Uninitialized TrilinosPayload::inv_vmult called" 2499 "(Default constructor)"));
2505 ExcMessage(
"Uninitialized TrilinosPayload::inv_Tvmult called" 2506 "(Default constructor)"));
2514 : use_transpose (matrix_exemplar.trilinos_matrix().UseTranspose()),
2515 #ifdef DEAL_II_WITH_MPI
2516 communicator (matrix_exemplar.get_mpi_communicator()),
2517 domain_map (matrix_exemplar.locally_owned_domain_indices().make_trilinos_map(communicator.Comm())),
2518 range_map (matrix_exemplar.locally_owned_range_indices().make_trilinos_map(communicator.Comm()))
2520 domain_map (
internal::make_serial_Epetra_map(matrix_exemplar.locally_owned_domain_indices())),
2521 range_map (
internal::make_serial_Epetra_map(matrix_exemplar.locally_owned_range_indices()))
2524 vmult = [&matrix_exemplar,&matrix](
Range &tril_dst,
const Domain &tril_src)
2529 internal::check_vector_map_equality(matrix_exemplar.
trilinos_matrix(),
2532 internal::check_vector_map_equality(matrix.trilinos_matrix(),
2534 matrix.trilinos_matrix().UseTranspose());
2536 const int ierr = matrix.trilinos_matrix().Apply (tril_src, tril_dst);
2545 internal::check_vector_map_equality(matrix_exemplar.
trilinos_matrix(),
2548 internal::check_vector_map_equality(matrix.trilinos_matrix(),
2550 !matrix.trilinos_matrix().UseTranspose());
2552 Epetra_CrsMatrix &tril_mtrx_non_const =
const_cast<Epetra_CrsMatrix &
>(matrix.trilinos_matrix());
2553 tril_mtrx_non_const.SetUseTranspose(!matrix.trilinos_matrix().UseTranspose());
2554 const int ierr = matrix.trilinos_matrix().Apply (tril_src, tril_dst);
2556 tril_mtrx_non_const.SetUseTranspose(!matrix.trilinos_matrix().UseTranspose());
2562 ExcMessage(
"Uninitialized TrilinosPayload::inv_vmult called" 2563 "(Matrix constructor with matrix exemplar)"));
2569 ExcMessage(
"Uninitialized TrilinosPayload::inv_Tvmult called" 2570 "(Matrix constructor with matrix exemplar)"));
2578 : use_transpose (matrix_exemplar.trilinos_matrix().UseTranspose()),
2579 #ifdef DEAL_II_WITH_MPI
2580 communicator (matrix_exemplar.get_mpi_communicator()),
2581 domain_map (matrix_exemplar.locally_owned_domain_indices().make_trilinos_map(communicator.Comm())),
2582 range_map (matrix_exemplar.locally_owned_range_indices().make_trilinos_map(communicator.Comm()))
2584 domain_map (
internal::make_serial_Epetra_map(matrix_exemplar.locally_owned_domain_indices())),
2585 range_map (
internal::make_serial_Epetra_map(matrix_exemplar.locally_owned_range_indices()))
2588 vmult = [&matrix_exemplar,&preconditioner](
Range &tril_dst,
const Domain &tril_src)
2593 internal::check_vector_map_equality(matrix_exemplar.
trilinos_matrix(),
2600 const int ierr = preconditioner.
trilinos_operator().ApplyInverse (tril_src,tril_dst);
2604 Tvmult = [&matrix_exemplar,&preconditioner](
Domain &tril_dst,
const Range &tril_src)
2609 internal::check_vector_map_equality(matrix_exemplar.
trilinos_matrix(),
2617 const int ierr = preconditioner.
trilinos_operator().ApplyInverse (tril_src,tril_dst);
2627 internal::check_vector_map_equality(matrix_exemplar.
trilinos_matrix(),
2634 const int ierr = preconditioner.
trilinos_operator().ApplyInverse (tril_src,tril_dst);
2643 internal::check_vector_map_equality(matrix_exemplar.
trilinos_matrix(),
2651 const int ierr = preconditioner.
trilinos_operator().ApplyInverse (tril_src,tril_dst);
2661 : use_transpose (preconditioner_exemplar.trilinos_operator().UseTranspose()),
2662 #ifdef DEAL_II_WITH_MPI
2663 communicator (preconditioner_exemplar.get_mpi_communicator()),
2664 domain_map (preconditioner_exemplar.locally_owned_domain_indices().make_trilinos_map(communicator.Comm())),
2665 range_map (preconditioner_exemplar.locally_owned_range_indices().make_trilinos_map(communicator.Comm()))
2667 domain_map (
internal::make_serial_Epetra_map(preconditioner_exemplar.locally_owned_domain_indices())),
2668 range_map (
internal::make_serial_Epetra_map(preconditioner_exemplar.locally_owned_range_indices()))
2671 vmult = [&preconditioner_exemplar,&preconditioner](
Range &tril_dst,
const Domain &tril_src)
2676 internal::check_vector_map_equality(preconditioner_exemplar.
trilinos_operator(),
2687 Tvmult = [&preconditioner_exemplar,&preconditioner](
Domain &tril_dst,
const Range &tril_src)
2692 internal::check_vector_map_equality(preconditioner_exemplar.
trilinos_operator(),
2705 inv_vmult = [&preconditioner_exemplar,&preconditioner](
Domain &tril_dst,
const Range &tril_src)
2710 internal::check_vector_map_equality(preconditioner_exemplar.
trilinos_operator(),
2717 const int ierr = preconditioner.
trilinos_operator().ApplyInverse (tril_src,tril_dst);
2726 internal::check_vector_map_equality(preconditioner_exemplar.
trilinos_operator(),
2734 const int ierr = preconditioner.
trilinos_operator().ApplyInverse (tril_src,tril_dst);
2743 : vmult (payload.vmult),
2744 Tvmult (payload.Tvmult),
2745 inv_vmult (payload.inv_vmult),
2746 inv_Tvmult (payload.inv_Tvmult),
2747 use_transpose (payload.use_transpose),
2748 communicator (payload.communicator),
2749 domain_map (payload.domain_map),
2750 range_map (payload.range_map)
2759 : use_transpose (false),
2760 communicator (first_op.communicator),
2761 domain_map (second_op.domain_map),
2762 range_map (first_op.range_map)
2779 const Range &tril_src)
2781 tril_dst = tril_src;
2785 const Range &tril_src)
2787 tril_dst = tril_src;
2791 const Range &tril_src)
2793 tril_dst = tril_src;
2797 const Range &tril_src)
2799 tril_dst = tril_src;
2815 const int ierr = tril_dst.PutScalar(0.0);
2823 const int ierr = tril_dst.PutScalar(0.0);
2833 const int ierr = tril_dst.PutScalar(0.0);
2843 const int ierr = tril_dst.PutScalar(0.0);
2882 #ifdef DEAL_II_WITH_MPI 2885 return MPI_COMM_SELF;
2949 return "TrilinosPayload";
3004 ExcMessage(
"Operators are set to work on incompatible IndexSets."));
3006 ExcMessage(
"Operators are set to work on incompatible IndexSets."));
3011 return_op.vmult = [first_op, second_op](Range &tril_dst,
3012 const Domain &tril_src)
3017 GVMVectorType *i = vector_memory.
alloc();
3021 i->reinit(
IndexSet(first_op_init_map),
3026 const size_type i_local_size = i->end() - i->begin();
3027 AssertDimension (i_local_size, static_cast<size_type>(first_op_init_map.NumMyPoints()));
3029 AssertDimension (i_local_size, static_cast<size_type>(second_op_init_map.NumMyPoints()));
3030 (void)second_op_init_map;
3031 Intermediate tril_int (View, first_op_init_map,
3032 const_cast<TrilinosScalar *>(i->begin()),
3037 second_op.
Apply(tril_src, tril_int);
3038 first_op.
Apply(tril_src, tril_dst);
3039 const int ierr = tril_dst.Update (1.0, tril_int, 1.0);
3042 vector_memory.
free(i);
3045 return_op.Tvmult = [first_op, second_op](Domain &tril_dst,
3046 const Range &tril_src)
3051 GVMVectorType *i = vector_memory.
alloc();
3057 const_cast<TrilinosPayload &
>(first_op).transpose();
3058 const_cast<TrilinosPayload &
>(second_op).transpose();
3062 i->reinit(
IndexSet(first_op_init_map),
3067 const size_type i_local_size = i->end() - i->begin();
3068 AssertDimension (i_local_size, static_cast<size_type>(first_op_init_map.NumMyPoints()));
3070 AssertDimension (i_local_size, static_cast<size_type>(second_op_init_map.NumMyPoints()));
3071 (void)second_op_init_map;
3072 Intermediate tril_int (View, first_op_init_map,
3073 const_cast<TrilinosScalar *>(i->begin()),
3078 second_op.
Apply(tril_src, tril_int);
3079 first_op.
Apply(tril_src, tril_dst);
3080 const int ierr = tril_dst.Update (1.0, tril_int, 1.0);
3084 const_cast<TrilinosPayload &
>(first_op).transpose();
3085 const_cast<TrilinosPayload &
>(second_op).transpose();
3087 vector_memory.
free(i);
3090 return_op.inv_vmult = [first_op, second_op](Domain &tril_dst,
3091 const Range &tril_src)
3096 GVMVectorType *i = vector_memory.
alloc();
3100 i->reinit(
IndexSet(first_op_init_map),
3105 const size_type i_local_size = i->end() - i->begin();
3106 AssertDimension (i_local_size, static_cast<size_type>(first_op_init_map.NumMyPoints()));
3108 AssertDimension (i_local_size, static_cast<size_type>(second_op_init_map.NumMyPoints()));
3109 (void)second_op_init_map;
3110 Intermediate tril_int (View, first_op_init_map,
3111 const_cast<TrilinosScalar *>(i->begin()),
3118 const int ierr = tril_dst.Update (1.0, tril_int, 1.0);
3121 vector_memory.
free(i);
3124 return_op.inv_Tvmult = [first_op, second_op](Range &tril_dst,
3125 const Domain &tril_src)
3130 GVMVectorType *i = vector_memory.
alloc();
3136 const_cast<TrilinosPayload &
>(first_op).transpose();
3137 const_cast<TrilinosPayload &
>(second_op).transpose();
3141 i->reinit(
IndexSet(first_op_init_map),
3146 const size_type i_local_size = i->end() - i->begin();
3147 AssertDimension (i_local_size, static_cast<size_type>(first_op_init_map.NumMyPoints()));
3149 AssertDimension (i_local_size, static_cast<size_type>(second_op_init_map.NumMyPoints()));
3150 (void)second_op_init_map;
3151 Intermediate tril_int (View, first_op_init_map,
3152 const_cast<TrilinosScalar *>(i->begin()),
3159 const int ierr = tril_dst.Update (1.0, tril_int, 1.0);
3163 const_cast<TrilinosPayload &
>(first_op).transpose();
3164 const_cast<TrilinosPayload &
>(second_op).transpose();
3166 vector_memory.
free(i);
3174 TrilinosPayload operator*(
const TrilinosPayload &first_op,
3175 const TrilinosPayload &second_op)
3182 AssertThrow(first_op.locally_owned_domain_indices() == second_op.locally_owned_range_indices(),
3183 ExcMessage(
"Operators are set to work on incompatible IndexSets."));
3185 TrilinosPayload return_op (first_op, second_op);
3188 return_op.vmult = [first_op, second_op](Range &tril_dst,
3189 const Domain &tril_src)
3194 GVMVectorType *i = vector_memory.
alloc();
3197 const Epetra_Map &first_op_init_map = first_op.OperatorDomainMap();
3198 i->reinit(
IndexSet(first_op_init_map),
3199 first_op.get_mpi_communicator(),
3203 const size_type i_local_size = i->end() - i->begin();
3204 AssertDimension (i_local_size, static_cast<size_type>(first_op_init_map.NumMyPoints()));
3205 const Epetra_Map &second_op_init_map = second_op.OperatorRangeMap();
3206 AssertDimension (i_local_size, static_cast<size_type>(second_op_init_map.NumMyPoints()));
3207 (void)second_op_init_map;
3208 Intermediate tril_int (View, first_op_init_map,
3209 const_cast<TrilinosScalar *>(i->begin()),
3214 second_op.Apply(tril_src, tril_int);
3215 first_op.Apply(tril_int, tril_dst);
3217 vector_memory.
free(i);
3220 return_op.Tvmult = [first_op, second_op](Domain &tril_dst,
3221 const Range &tril_src)
3226 GVMVectorType *i = vector_memory.
alloc();
3232 const_cast<TrilinosPayload &
>(first_op).transpose();
3233 const_cast<TrilinosPayload &
>(second_op).transpose();
3236 const Epetra_Map &first_op_init_map = first_op.OperatorRangeMap();
3237 i->reinit(
IndexSet(first_op_init_map),
3238 first_op.get_mpi_communicator(),
3242 const size_type i_local_size = i->end() - i->begin();
3243 AssertDimension (i_local_size, static_cast<size_type>(first_op_init_map.NumMyPoints()));
3244 const Epetra_Map &second_op_init_map = second_op.OperatorDomainMap();
3245 AssertDimension (i_local_size, static_cast<size_type>(second_op_init_map.NumMyPoints()));
3246 (void)second_op_init_map;
3247 Intermediate tril_int (View, first_op_init_map,
3248 const_cast<TrilinosScalar *>(i->begin()),
3252 first_op.Apply(tril_src, tril_int);
3253 second_op.Apply(tril_int, tril_dst);
3256 const_cast<TrilinosPayload &
>(first_op).transpose();
3257 const_cast<TrilinosPayload &
>(second_op).transpose();
3259 vector_memory.
free(i);
3262 return_op.inv_vmult = [first_op, second_op](Domain &tril_dst,
3263 const Range &tril_src)
3268 GVMVectorType *i = vector_memory.
alloc();
3271 const Epetra_Map &first_op_init_map = first_op.OperatorRangeMap();
3272 i->reinit(
IndexSet(first_op_init_map),
3273 first_op.get_mpi_communicator(),
3277 const size_type i_local_size = i->end() - i->begin();
3278 AssertDimension (i_local_size, static_cast<size_type>(first_op_init_map.NumMyPoints()));
3279 const Epetra_Map &second_op_init_map = second_op.OperatorDomainMap();
3280 AssertDimension (i_local_size, static_cast<size_type>(second_op_init_map.NumMyPoints()));
3281 (void)second_op_init_map;
3282 Intermediate tril_int (View, first_op_init_map,
3283 const_cast<TrilinosScalar *>(i->begin()),
3288 first_op.ApplyInverse(tril_src, tril_int);
3289 second_op.ApplyInverse(tril_int, tril_dst);
3291 vector_memory.
free(i);
3294 return_op.inv_Tvmult = [first_op, second_op](Range &tril_dst,
3295 const Domain &tril_src)
3300 GVMVectorType *i = vector_memory.
alloc();
3306 const_cast<TrilinosPayload &
>(first_op).transpose();
3307 const_cast<TrilinosPayload &
>(second_op).transpose();
3310 const Epetra_Map &first_op_init_map = first_op.OperatorDomainMap();
3311 i->reinit(
IndexSet(first_op_init_map),
3312 first_op.get_mpi_communicator(),
3316 const size_type i_local_size = i->end() - i->begin();
3317 AssertDimension (i_local_size, static_cast<size_type>(first_op_init_map.NumMyPoints()));
3318 const Epetra_Map &second_op_init_map = second_op.OperatorRangeMap();
3319 AssertDimension (i_local_size, static_cast<size_type>(second_op_init_map.NumMyPoints()));
3320 (void)second_op_init_map;
3321 Intermediate tril_int (View, first_op_init_map,
3322 const_cast<TrilinosScalar *>(i->begin()),
3329 second_op.ApplyInverse(tril_src, tril_int);
3330 first_op.ApplyInverse(tril_int, tril_dst);
3333 const_cast<TrilinosPayload &
>(first_op).transpose();
3334 const_cast<TrilinosPayload &
>(second_op).transpose();
3336 vector_memory.
free(i);
3346 #endif // DEAL_II_WITH_CXX11 3350 #include "trilinos_sparse_matrix.inst" 3364 const ::SparsityPattern &,
3373 const ::SparsityPattern &,
3383 const ::SparsityPattern &,
3395 const VectorBase &)
const;
3401 const MPI::Vector &)
const;
3404 const ::Vector<double> &)
const;
3407 const ::LinearAlgebra::distributed::Vector<double> &)
const;
3410 const VectorBase &)
const;
3416 const MPI::Vector &)
const;
3419 const ::Vector<double> &)
const;
3422 const ::LinearAlgebra::distributed::Vector<double> &)
const;
3425 const VectorBase &)
const;
3431 const MPI::Vector &)
const;
3434 const ::Vector<double> &)
const;
3437 const ::LinearAlgebra::distributed::Vector<double> &)
const;
3440 const VectorBase &)
const;
3446 const MPI::Vector &)
const;
3449 const ::Vector<double> &)
const;
3452 const ::LinearAlgebra::distributed::Vector<double> &)
const;
3456 DEAL_II_NAMESPACE_CLOSE
3458 #endif // DEAL_II_WITH_TRILINOS std_cxx11::shared_ptr< std::vector< TrilinosScalar > > value_cache
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
types::global_dof_index size_type
TrilinosScalar frobenius_norm() const
std_cxx11::shared_ptr< std::vector< size_type > > colnum_cache
#define AssertDimension(dim1, dim2)
virtual const Epetra_Map & OperatorRangeMap() const
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
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
void vmult_add(VectorType &dst, const VectorType &src) const
MPI_Comm get_mpi_communicator() const
Epetra_CombineMode last_action
const Epetra_FECrsGraph & trilinos_sparsity_pattern() const
void set(const size_type i, const size_type j, const number value)
::types::global_dof_index size_type
#define AssertIndexRange(index, range)
TrilinosScalar residual(VectorBase &dst, const VectorBase &x, const VectorBase &b) const
virtual const char * Label() const
std::pair< size_type, size_type > local_range() const
std_cxx11::shared_ptr< Epetra_CrsGraph > nonlocal_graph
TrilinosScalar operator()(const size_type i, const size_type j) const
virtual bool UseTranspose() const
void reinit(const VectorBase &v, const bool omit_zeroing_entries=false)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
const Epetra_Comm & comm_self()
static ::ExceptionBase & ExcTrilinosError(int arg1)
IndexSet locally_owned_range_indices() const
virtual void reinit(const SparsityPattern &sparsity)
const Epetra_Map & col_partitioner() const 1
static ::ExceptionBase & ExcDivideByZero()
Epetra_MultiVector VectorType
void clear_rows(const std::vector< size_type > &rows, const TrilinosScalar new_diag_value=0)
void Tvmult(VectorType &dst, const VectorType &src) const
SparseMatrix & operator=(const double d)
std_cxx11::shared_ptr< Epetra_FECrsMatrix > matrix
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
SparseMatrix & operator*=(const TrilinosScalar factor)
virtual const Epetra_Map & OperatorDomainMap() const
virtual const Epetra_Comm & Comm() const
virtual int ApplyInverse(const VectorType &Y, VectorType &X) const
bool in_local_range(const size_type index) const
static ::ExceptionBase & ExcMessage(std::string arg1)
std_cxx11::shared_ptr< Epetra_CrsMatrix > nonlocal_matrix
TrilinosPayload null_payload() const
void add(const size_type i, const size_type j, const TrilinosScalar value)
virtual VectorType * alloc()
std::function< void(VectorType &, const VectorType &)> Tvmult
#define Assert(cond, exc)
std_cxx11::shared_ptr< Epetra_Map > column_space_map
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void Tmmult(SparseMatrix &C, const SparseMatrix &B, const VectorBase &V=VectorBase()) const
virtual int SetUseTranspose(bool UseTranspose)
const Epetra_Map & vector_partitioner() const
size_type memory_consumption() const
const IndexSet & row_index_set() const
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
void mmult(SparseMatrix &C, const SparseMatrix &B, const VectorBase &V=VectorBase()) const
virtual void free(const VectorType *const)
const Epetra_Map & domain_partitioner() const 1
virtual ~TrilinosPayload()
const Epetra_CrsMatrix & trilinos_matrix() const
Epetra_Operator & trilinos_operator() const
const Epetra_Map & range_partitioner() const 1
void vmult(VectorType &dst, const VectorType &src) const
std::function< void(VectorType &, const VectorType &)> inv_vmult
size_type n_nonzero_elements() const
MPI_Comm get_mpi_communicator() const
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
static ::ExceptionBase & ExcNotQuadratic()
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
const Epetra_Map & domain_partitioner() const 1
void reinit(const SparsityPatternType &sparsity_pattern)
TrilinosScalar matrix_norm_square(const VectorBase &v) const
size_type row_length(const size_type row) const
TrilinosScalar linfty_norm() const
std::function< void(VectorType &, const VectorType &)> vmult
void copy_from(const SparseMatrix &source)
SparseMatrix & operator/=(const TrilinosScalar factor)
virtual int Apply(const VectorType &X, VectorType &Y) const
std::pair< size_type, size_type > local_range() const
const Epetra_MultiVector & trilinos_vector() const
IndexSet locally_owned_domain_indices() const
TrilinosPayload transpose_payload() const
static ::ExceptionBase & ExcNotImplemented()
virtual double NormInf() const
TrilinosScalar matrix_scalar_product(const VectorBase &u, const VectorBase &v) const
static ::ExceptionBase & ExcMatrixNotCompressed()
const Epetra_CrsGraph & trilinos_sparsity_pattern() const
bool is_element(const size_type index) const
void reinit(const size_type n, const bool omit_zeroing_entries=false)
void compress(::VectorOperation::values operation)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
void set(const size_type i, const size_type j, const TrilinosScalar value)
TrilinosPayload identity_payload() const
size_type n_elements() const
#define AssertIsFinite(number)
virtual bool HasNormInf() const
unsigned int local_size() const
real_type l2_norm() const
TrilinosScalar l1_norm() const
void compress(::VectorOperation::values)
std::function< void(VectorType &, const VectorType &)> inv_Tvmult
static ::ExceptionBase & ExcInternalError()
const Epetra_Map & row_partitioner() const 1
Epetra_MpiComm communicator
std_cxx11::shared_ptr< Epetra_Export > nonlocal_matrix_exporter