20 #include "libmesh/libmesh_config.h"
22 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
25 #include "libmesh/trilinos_epetra_matrix.h"
26 #include "libmesh/trilinos_epetra_vector.h"
27 #include "libmesh/dof_map.h"
28 #include "libmesh/dense_matrix.h"
29 #include "libmesh/parallel.h"
30 #include "libmesh/sparsity_pattern.h"
31 #include "libmesh/int_range.h"
51 (sparsity_pattern.size());
55 const numeric_index_type n_l = this->_dof_map->n_dofs_on_processor(this->processor_id());
61 libmesh_assert_equal_to (n, m);
62 libmesh_assert_equal_to (n_l, m_l);
68 this->comm().sum (summed_m_l);
69 this->comm().sum (summed_n_l);
71 libmesh_assert_equal_to (m, summed_m_l);
72 libmesh_assert_equal_to (n, summed_n_l);
77 _map =
new Epetra_Map (static_cast<int>(m),
80 Epetra_MpiComm (this->comm().
get()));
82 libmesh_assert_equal_to (static_cast<numeric_index_type>(_map->NumGlobalPoints()), m);
83 libmesh_assert_equal_to (static_cast<numeric_index_type>(_map->MaxAllGID()+1), m);
85 const std::vector<numeric_index_type> & n_nz = this->_dof_map->get_n_nz();
86 const std::vector<numeric_index_type> & n_oz = this->_dof_map->get_n_oz();
89 libmesh_assert_equal_to (n_nz.size(), n_l);
90 libmesh_assert_equal_to (n_oz.size(), n_l);
93 std::vector<int> n_nz_tot; n_nz_tot.reserve(n_nz.size());
96 n_nz_tot.push_back(std::min(n_nz[i] + n_oz[i], n));
101 _graph =
new Epetra_CrsGraph(Copy, *_map, n_nz_tot.data());
106 _graph->InsertGlobalIndices(_graph->GRID(i),
107 cast_int<numeric_index_type>(sparsity_pattern[i].size()),
108 const_cast<int *>(reinterpret_cast<const int *>(sparsity_pattern[i].
data())));
110 _graph->FillComplete();
120 template <
typename T>
129 if ((m==0) || (n==0))
146 libmesh_assert_equal_to (n, m);
147 libmesh_assert_equal_to (n_l, m_l);
153 this->comm().sum (summed_m_l);
154 this->comm().sum (summed_n_l);
156 libmesh_assert_equal_to (m, summed_m_l);
157 libmesh_assert_equal_to (n, summed_n_l);
162 _map =
new Epetra_Map (static_cast<int>(m),
165 Epetra_MpiComm (this->comm().
get()));
167 libmesh_assert_equal_to (static_cast<numeric_index_type>(_map->NumGlobalPoints()), m);
168 libmesh_assert_equal_to (static_cast<numeric_index_type>(_map->MaxAllGID()+1), m);
170 _mat =
new Epetra_FECrsMatrix (Copy, *_map, nnz + noz);
176 template <
typename T>
190 _mat =
new Epetra_FECrsMatrix (Copy, *_graph);
195 template <
typename T>
205 template <
typename T>
218 template <
typename T>
225 return static_cast<Real>(_mat->NormOne());
230 template <
typename T>
238 return static_cast<Real>(_mat->NormInf());
243 template <
typename T>
245 const std::vector<numeric_index_type> & rows,
246 const std::vector<numeric_index_type> & cols)
253 libmesh_assert_equal_to (rows.size(), m);
254 libmesh_assert_equal_to (cols.size(), n);
266 template <
typename T>
273 _mat->ExtractDiagonalCopy(*(epetra_dest->
vec()));
278 template <
typename T>
288 if (&epetra_dest !=
this)
289 libmesh_not_implemented();
297 template <
typename T>
300 _destroy_mat_on_exit(true),
301 _use_transpose(false)
307 template <
typename T>
309 const Parallel::Communicator & comm) :
311 _destroy_mat_on_exit(false),
312 _use_transpose(false)
321 template <
typename T>
329 template <
typename T>
334 _mat->GlobalAssemble();
339 template <
typename T>
344 return static_cast<numeric_index_type>(_mat->NumGlobalRows());
349 template <
typename T>
354 return static_cast<numeric_index_type>(_mat->NumGlobalCols());
359 template <
typename T>
365 return static_cast<numeric_index_type>(_map->MinMyGID());
370 template <
typename T>
376 return static_cast<numeric_index_type>(_map->MaxMyGID())+1;
381 template <
typename T>
389 epetra_i = static_cast<int>(i),
390 epetra_j = static_cast<int>(j);
392 T epetra_value =
value;
395 _mat->ReplaceGlobalValues (epetra_i, 1, &epetra_value, &epetra_j);
397 _mat->InsertGlobalValues (epetra_i, 1, &epetra_value, &epetra_j);
402 template <
typename T>
410 epetra_i = static_cast<int>(i),
411 epetra_j = static_cast<int>(j);
413 T epetra_value =
value;
415 _mat->SumIntoGlobalValues (epetra_i, 1, &epetra_value, &epetra_j);
420 template <
typename T>
422 const std::vector<numeric_index_type> & dof_indices)
424 this->add_matrix (dm, dof_indices, dof_indices);
429 template <
typename T>
432 #ifdef LIBMESH_TRILINOS_HAVE_EPETRAEXT
437 libmesh_assert_equal_to (this->m(), X_in.
m());
438 libmesh_assert_equal_to (this->n(), X_in.
n());
441 cast_ptr<const EpetraMatrix<T> *> (&X_in);
443 EpetraExt::MatrixMatrix::Add (*X->_mat,
false, a_in, *_mat, 1.);
445 libmesh_error_msg(
"ERROR: EpetraExt is required for EpetraMatrix::add()!");
452 template <
typename T>
459 libmesh_assert_greater_equal (i, this->row_start());
460 libmesh_assert_less (i, this->row_stop());
467 _mat->ExtractMyRowView (i-this->row_start(),
474 int * index = std::lower_bound (row_indices, row_indices+row_length, j);
476 libmesh_assert_less (*index, row_length);
477 libmesh_assert_equal_to (static_cast<numeric_index_type>(row_indices[*index]), j);
481 return values[*index];
487 template <
typename T>
493 return this->_mat->Filled();
497 template <
typename T>
508 template <
typename T>
526 #endif // LIBMESH_TRILINOS_HAVE_EPETRA