Galeri Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CrsMatrix.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Galeri: Finite Element and Matrix Generation Package
5 // Copyright (2006) ETHZ/Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions about Galeri? Contact Marzio Sala (marzio.sala _AT_ gmail.com)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #include "Galeri_Maps.h"
43 #include "Galeri_CrsMatrices.h"
44 #include "Galeri_Utils.h"
45 #ifdef HAVE_MPI
46 #include "Epetra_MpiComm.h"
47 #include "mpi.h"
48 #else
49 #include "Epetra_SerialComm.h"
50 #endif
51 #include "Epetra_Map.h"
52 #include "Epetra_CrsMatrix.h"
54 
55 using namespace Galeri;
56 
57 // =========== //
58 // main driver //
59 // =========== //
60 
61 int main(int argc, char* argv[])
62 {
63 #ifdef HAVE_MPI
64  MPI_Init(&argc, &argv);
65  Epetra_MpiComm Comm(MPI_COMM_WORLD);
66 #else
67  Epetra_SerialComm Comm;
68 #endif
69 
70  // pointer to the map to be created
71  Epetra_Map* Map;
72  // pointer to the matrix to be created
73  Epetra_CrsMatrix* Matrix;
74  // container for parameters
75  Teuchos::ParameterList GaleriList;
76  // here we specify the global dimension of the problem
77  int nx = 5 * Comm.NumProc();
78  int ny = 5 * Comm.NumProc();
79  GaleriList.set("nx", nx);
80  GaleriList.set("ny", ny);
81 
82  try
83  {
84  // Creates a simple linear map; for more details on the map creation
85  // refer to the documentation
86 #ifndef GALERI_TEST_USE_LONGLONG_GO
87  Map = CreateMap("Cartesian2D", Comm, GaleriList);
88 #else
89  Map = CreateMap64("Cartesian2D", Comm, GaleriList);
90 #endif
91 
92  // Creates a diagonal matrix with 1's on the diagonal
93  Matrix = CreateCrsMatrix("Biharmonic2D", Map, GaleriList);
94 
95  // print out the matrix
96  //cout << *Matrix;
97 
98  int GID = -1; // set GID to the global node to use to compute
99  // the stencil, or put -1 to automatically select it.
100  PrintStencil2D(Matrix, nx, ny, GID);
101 
102  // To created objects must be free'd using delete
103  delete Map;
104  delete Matrix;
105  }
106  catch (Exception& rhs)
107  {
108  if (Comm.MyPID() == 0)
109  {
110  cerr << "Caught exception: ";
111  rhs.Print();
112  }
113  }
114 
115 #ifdef HAVE_MPI
116  MPI_Finalize();
117 #endif
118 
119  return(EXIT_SUCCESS);
120 }
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int MyPID() const
virtual void Print(std::ostream &os) const
int NumProc() const
int main(int argc, char *argv[])
Definition: CrsMatrix.cpp:61