Galeri Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VbrMatrix.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_VbrMatrices.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"
21 #include "Epetra_VbrMatrix.h"
23 
24 using namespace Galeri;
25 
26 // =========== //
27 // main driver //
28 // =========== //
29 
30 int main(int argc, char* argv[])
31 {
32 #ifdef HAVE_MPI
33  MPI_Init(&argc, &argv);
34  Epetra_MpiComm Comm(MPI_COMM_WORLD);
35 #else
36  Epetra_SerialComm Comm;
37 #endif
38 
39  // pointer to the map to be created
40  Epetra_Map* Map;
41  // pointer to the CrsMatrix to be created
42  Epetra_CrsMatrix* CrsMatrix;
43  // pointer to the VbrMatrix to be created
44  Epetra_VbrMatrix* VbrMatrix;
45  // container for parameters
46  Teuchos::ParameterList GaleriList;
47  // here we specify the global dimension of the problem
48  GaleriList.set("n", 2 * Comm.NumProc());
49 
50  try
51  {
52  // Creates a simple linear map; for more details on the map creation
53  // refer to the documentation
54  Map = CreateMap("Linear", Comm, GaleriList);
55 
56  // Creates a diagonal matrix with 1's on the diagonal
57  CrsMatrix = CreateCrsMatrix("Diag", Map, GaleriList);
58 
59  // at this point we can create the VbrMatrix. Each block of the Vbr will
60  // be 2 x 2. (Any positive value is accepted, like 1.)
61  VbrMatrix = CreateVbrMatrix(CrsMatrix, 2);
62 
63  // print out the matrix
64  cout << *VbrMatrix;
65 
66  // To created objects must be free'd using delete
67  delete Map;
68  delete CrsMatrix;
69  delete VbrMatrix;
70  }
71  catch (Exception& rhs)
72  {
73  if (Comm.MyPID() == 0)
74  {
75  cerr << "Caught exception: ";
76  rhs.Print();
77  }
78  }
79 
80 #ifdef HAVE_MPI
81  MPI_Finalize();
82 #endif
83 
84  return(EXIT_SUCCESS);
85 }
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