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 // Galeri: Finite Element and Matrix Generation Package
4 //
5 // Copyright 2006 ETHZ/NTESS and the Galeri contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Galeri_Maps.h"
11 #include "Galeri_CrsMatrices.h"
12 #include "Galeri_Utils.h"
13 #ifdef HAVE_MPI
14 #include "Epetra_MpiComm.h"
15 #include "mpi.h"
16 #else
17 #include "Epetra_SerialComm.h"
18 #endif
19 #include "Epetra_Map.h"
20 #include "Epetra_CrsMatrix.h"
22 
23 using namespace Galeri;
24 
25 // =========== //
26 // main driver //
27 // =========== //
28 
29 int main(int argc, char* argv[])
30 {
31 #ifdef HAVE_MPI
32  MPI_Init(&argc, &argv);
33  Epetra_MpiComm Comm(MPI_COMM_WORLD);
34 #else
35  Epetra_SerialComm Comm;
36 #endif
37 
38  // pointer to the map to be created
39  Epetra_Map* Map;
40  // pointer to the matrix to be created
41  Epetra_CrsMatrix* Matrix;
42  // container for parameters
43  Teuchos::ParameterList GaleriList;
44  // here we specify the global dimension of the problem
45  int nx = 5 * Comm.NumProc();
46  int ny = 5 * Comm.NumProc();
47  GaleriList.set("nx", nx);
48  GaleriList.set("ny", ny);
49 
50  try
51  {
52  // Creates a simple linear map; for more details on the map creation
53  // refer to the documentation
54 #ifndef GALERI_TEST_USE_LONGLONG_GO
55  Map = CreateMap("Cartesian2D", Comm, GaleriList);
56 #else
57  Map = CreateMap64("Cartesian2D", Comm, GaleriList);
58 #endif
59 
60  // Creates a diagonal matrix with 1's on the diagonal
61  Matrix = CreateCrsMatrix("Biharmonic2D", Map, GaleriList);
62 
63  // print out the matrix
64  //cout << *Matrix;
65 
66  int GID = -1; // set GID to the global node to use to compute
67  // the stencil, or put -1 to automatically select it.
68  PrintStencil2D(Matrix, nx, ny, GID);
69 
70  // To created objects must be free'd using delete
71  delete Map;
72  delete Matrix;
73  }
74  catch (Exception& rhs)
75  {
76  if (Comm.MyPID() == 0)
77  {
78  cerr << "Caught exception: ";
79  rhs.Print();
80  }
81  }
82 
83 #ifdef HAVE_MPI
84  MPI_Finalize();
85 #endif
86 
87  return(EXIT_SUCCESS);
88 }
ParameterList & set(std::string const &name, T &&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:29