trilinos_helpers.h
Go to the documentation of this file.
1 //LIC// ====================================================================
2 //LIC// This file forms part of oomph-lib, the object-oriented,
3 //LIC// multi-physics finite-element library, available
4 //LIC// at http://www.oomph-lib.org.
5 //LIC//
6 //LIC// Version 1.0; svn revision $LastChangedRevision: 1097 $
7 //LIC//
8 //LIC// $LastChangedDate: 2015-12-17 11:53:17 +0000 (Thu, 17 Dec 2015) $
9 //LIC//
10 //LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11 //LIC//
12 //LIC// This library is free software; you can redistribute it and/or
13 //LIC// modify it under the terms of the GNU Lesser General Public
14 //LIC// License as published by the Free Software Foundation; either
15 //LIC// version 2.1 of the License, or (at your option) any later version.
16 //LIC//
17 //LIC// This library is distributed in the hope that it will be useful,
18 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 //LIC// Lesser General Public License for more details.
21 //LIC//
22 //LIC// You should have received a copy of the GNU Lesser General Public
23 //LIC// License along with this library; if not, write to the Free Software
24 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 //LIC// 02110-1301 USA.
26 //LIC//
27 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28 //LIC//
29 //LIC//====================================================================
30 #ifndef OOMPH_TRILINOS_HELPERS_HEADER
31 #define OOMPH_TRILINOS_HELPERS_HEADER
32 
33 
34 // Config header generated by autoconfig
35 #ifdef HAVE_CONFIG_H
36  #include <oomph-lib-config.h>
37 #endif
38 
39 #ifdef OOMPH_HAS_MPI
40 #include "mpi.h"
41 #endif
42 
43 
44 // trilinos headers
45 #include "Epetra_Map.h"
46 #include "Epetra_LocalMap.h"
47 #include "Epetra_Vector.h"
48 #include "Epetra_CrsMatrix.h"
49 #include "EpetraExt_MatrixMatrix.h"
50 #include "ml_epetra_utils.h"
51 
52 #ifdef OOMPH_HAS_MPI
53 #include "Epetra_MpiComm.h"
54 #else
55 #include "Epetra_SerialComm.h"
56 #endif
57 
58 // oomph-lib headers
59 #include "matrices.h"
60 
61 // mpi includes
62 #ifdef OOMPH_HAS_MPI
63 #include "double_vector.h"
65 #endif
66 
67 namespace oomph
68 {
69 
70 //// forward declaration of oomph-lib compressed row matrix
71 class CRDoubleMatrix;
72 
73 
74 //=============================================================================
75 /// \short Helper namespace for use with the Trilinos Epetra package.
76 /// Contains functions to generate two Epetra containers (Epetra_Vector and
77 /// Epetra_CrsMatrix) and provides access to the trilinos matrix-matrix
78 /// and matrix-vector product routines.
79 //=============================================================================
80 namespace TrilinosEpetraHelpers
81 {
82 
83  // VECTOR METHODS ============================================================
84 
85  /// \short create an Epetra_Vector from an oomph-lib DoubleVector.
86  /// If oomph_vec is NOT distributed (i.e. locally replicated) and
87  /// on more than one processor, then the returned Epetra_Vector will be
88  /// uniformly distributed. If the oomph_vec is distributed then the
89  /// Epetra_Vector returned will have the same distribution as oomp_vec.
90  Epetra_Vector* create_distributed_epetra_vector(const DoubleVector&
91  oomph_vec);
92 
93  /// \short create an Epetra_Vector based on the argument oomph-lib
94  /// LinearAlgebraDistribution
95  /// If dist is NOT distributed and
96  /// on more than one processor, then the returned Epetra_Vector will be
97  /// uniformly distributed. If dist is distributed then the Epetra_Vector
98  /// returned will have the same distribution as dist.
99  /// The coefficient values are not set.
100  Epetra_Vector* create_distributed_epetra_vector
101  (const LinearAlgebraDistribution* dist_pt);
102 
103  /// \short create an Epetra_Vector equivalent of DoubleVector
104  /// The argument DoubleVector must be built.
105  /// The Epetra_Vector will point to, and NOT COPY the underlying data in the
106  /// DoubleVector.
107  /// The oomph-lib DoubleVector and the returned Epetra_Vector will have the
108  /// the same distribution.
109  Epetra_Vector* create_epetra_vector_view_data(DoubleVector& oomph_vec);
110 
111  /// \short Helper function to copy the contents of a Trilinos vector to an
112  /// oomph-lib distributed vector. The distribution of the two vectors must
113  /// be identical
114  void copy_to_oomphlib_vector(const Epetra_Vector* epetra_vec_pt,
115  DoubleVector& oomph_vec);
116 
117  // MATRIX METHODS ============================================================
118 
119  /// \short create an Epetra_CrsMatrix from an oomph-lib CRDoubleMatrix.
120  /// If oomph_matrix_pt is NOT distributed (i.e. locally replicated) and
121  /// on more than one processor, then the returned Epetra_Vector will be
122  /// uniformly distributed. If the oomph_matrix_pt is distributed then the
123  /// Epetra_CrsMatrix returned will have the same distribution as
124  /// oomph_matrix_pt.
125  /// The LinearAlgebraDistribution argument dist_pt should specify the
126  /// distribution of the object this matrix will operate on.
127  Epetra_CrsMatrix* create_distributed_epetra_matrix
128  (const CRDoubleMatrix* oomph_matrix_pt,
129  const LinearAlgebraDistribution* dist_pt);
130 
131  /// \short create and Epetra_CrsMatrix from an oomph-lib CRDoubleMatrix.
132  /// Specialisation for Trilinos AztecOO.
133  /// If oomph_matrix_pt is NOT distributed (i.e. locally replicated) and
134  /// on more than one processor, then the returned Epetra_Vector will be
135  /// uniformly distributed. If the oomph_matrix_pt is distributed then the
136  /// Epetra_CrsMatrix returned will have the same distribution as
137  /// oomph_matrix_pt.
138  /// For AztecOO, the column map is ordered such that the local rows are
139  /// first.
141  (CRDoubleMatrix* oomph_matrix_pt);
142 
143  // MATRIX OPERATION METHODS ==================================================
144 
145  /// \short Function to perform a matrix-vector multiplication on a
146  /// oomph-lib matrix and vector using Trilinos functionality.
147  /// NOTE 1. the matrix and the vectors must have the same communicator.
148  /// NOTE 2. The vector will be returned with the same distribution
149  /// as the matrix, unless a distribution is predefined in the solution
150  /// vector in which case the vector will be returned with that distribution.
151  void multiply(const CRDoubleMatrix* matrix,
152  const DoubleVector& x,
153  DoubleVector &soln);
154 
155  /// \short Function to perform a matrix-matrix multiplication on oomph-lib
156  /// matrices by using Trilinos functionality.
157  /// \b NOTE 1. There are two Trilinos matrix-matrix multiplication methods
158  /// available, using either the EpetraExt::MatrixMatrix class (if use_ml ==
159  /// false) or using ML (Epetra_MatrixMult method)
160  /// \b NOTE 2. the solution matrix (matrix_soln) will be returned with the
161  /// same distribution as matrix1
162  /// \b NOTE 3. All matrices must share the same communicator.
163  void multiply(const CRDoubleMatrix &matrix_1,
164  const CRDoubleMatrix &matrix_2,
165  CRDoubleMatrix &matrix_soln,
166  const bool& use_ml = false);
167 
168  // HELPER METHODS ============================================================
169 
170  /// create an Epetra_Map corresponding to the LinearAlgebraDistribution
171  Epetra_Map* create_epetra_map
172  (const LinearAlgebraDistribution* const dist);
173 }; // end of trilinos epetra helpers namespace
174 } // end of namspace oomph
175 #endif
Epetra_CrsMatrix * create_distributed_epetra_matrix_for_aztecoo(CRDoubleMatrix *oomph_matrix_pt)
create and Epetra_CrsMatrix from an oomph-lib CRDoubleMatrix. Specialisation for Trilinos AztecOO...
void multiply(const CRDoubleMatrix *matrix, const DoubleVector &x, DoubleVector &soln)
Function to perform a matrix-vector multiplication on a oomph-lib matrix and vector using Trilinos fu...
Epetra_CrsMatrix * create_distributed_epetra_matrix(const CRDoubleMatrix *oomph_matrix_pt, const LinearAlgebraDistribution *dist_pt)
create an Epetra_CrsMatrix from an oomph-lib CRDoubleMatrix. If oomph_matrix_pt is NOT distributed (i...
Epetra_Vector * create_epetra_vector_view_data(DoubleVector &oomph_vec)
create an Epetra_Vector equivalent of DoubleVector The argument DoubleVector must be built...
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
Epetra_Map * create_epetra_map(const LinearAlgebraDistribution *const dist)
create an Epetra_Map corresponding to the LinearAlgebraDistribution
Epetra_Vector * create_distributed_epetra_vector(const DoubleVector &oomph_vec)
create an Epetra_Vector from an oomph-lib DoubleVector. If oomph_vec is NOT distributed (i...
A vector in the mathematical sense, initially developed for linear algebra type applications. If MPI then this vector can be distributed - its distribution is described by the LinearAlgebraDistribution object at Distribution_pt. Data is stored in a C-style pointer vector (double*)
Definition: double_vector.h:61
void copy_to_oomphlib_vector(const Epetra_Vector *epetra_vec_pt, DoubleVector &oomph_vec)
Helper function to copy the contents of a Trilinos vector to an oomph-lib distributed vector...
A class for compressed row matrices. This is a distributable object.
Definition: matrices.h:872