Galeri Package Browser (Single Doxygen Collection)
Version of the Day
test
VerySimple
cxx_main.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_Vector.h"
53
#include "Epetra_CrsMatrix.h"
54
#include "Epetra_LinearProblem.h"
55
#include "Teuchos_ParameterList.hpp"
56
57
using namespace
Galeri
;
58
59
// =========== //
60
// main driver //
61
// =========== //
62
63
int
main
(
int
argc,
char
* argv[])
64
{
65
#ifdef HAVE_MPI
66
MPI_Init(&argc, &argv);
67
Epetra_MpiComm Comm(MPI_COMM_WORLD);
68
#else
69
Epetra_SerialComm Comm;
70
#endif
71
72
// Here we create the linear problem
73
//
74
// Matrix * LHS = RHS
75
//
76
// with Matrix arising from a 5-point formula discretization.
77
78
Epetra_Map* Map = 0;
79
Epetra_RowMatrix* Matrix = 0;
80
81
Teuchos::ParameterList GaleriList;
82
// dimension of the problem is nx x ny
83
GaleriList.set(
"nx"
, 10 * Comm.NumProc());
84
GaleriList.set(
"ny"
, 10);
85
// total number of processors is mx x my
86
GaleriList.set(
"mx"
, Comm.NumProc());
87
GaleriList.set(
"my"
, 1);
88
89
try
90
{
91
Map = CreateMap(
"Cartesian2D"
, Comm, GaleriList);
92
Matrix = CreateCrsMatrix(
"Laplace2D"
, Map, GaleriList);
93
Epetra_Vector ExactSolution(*Map); ExactSolution.Random();
94
Epetra_Vector LHS(*Map); LHS.PutScalar(0.0);
95
Epetra_Vector RHS(*Map);
96
97
Matrix->Multiply(
false
, ExactSolution, RHS);
98
99
Epetra_LinearProblem Problem(Matrix, &LHS, &RHS);
100
101
// at this point any object that understand Epetra_LinearProblem can be
102
// used, for example AztecOO, Amesos. IFPACK and ML can be used to define a
103
// preconditioner for Matrix. Here we use a simple solver, based on
104
// LAPACK, that is meant for simple testing only.
105
106
Solve(Problem);
107
108
// and we compute the norm of the true residual.
109
double
ResidualNorm = ComputeNorm(Matrix, &LHS, &RHS);
110
111
if
(Comm.MyPID() == 0)
112
cout << ResidualNorm << endl;
113
114
delete
Map;
115
delete
Matrix;
116
}
117
catch
(Galeri::Exception& rhs)
118
{
119
if
(Comm.MyPID() == 0)
120
rhs.Print();
121
exit(EXIT_FAILURE);
122
}
123
124
#ifdef HAVE_MPI
125
MPI_Finalize();
126
#endif
127
128
return
(EXIT_SUCCESS);
129
}
main
int main(int argc, char *argv[])
Definition:
cxx_main.cpp:63
Galeri
Generated by
1.8.14