Ifpack Package Browser (Single Doxygen Collection)
Development
test
HIPS
test/HIPS/cxx_main.cpp
Go to the documentation of this file.
1
2
/*@HEADER
3
// ***********************************************************************
4
//
5
// Ifpack: Object-Oriented Algebraic Preconditioner Package
6
// Copyright (2002) Sandia Corporation
7
//
8
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9
// license for use of this work by or on behalf of the U.S. Government.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39
//
40
// ***********************************************************************
41
//@HEADER
42
*/
43
44
#include "
Ifpack_ConfigDefs.h
"
45
46
#include "Epetra_ConfigDefs.h"
47
#ifdef HAVE_MPI
48
#include "mpi.h"
49
#include "Epetra_MpiComm.h"
50
#else
51
#include "Epetra_SerialComm.h"
52
#endif
53
#include "Epetra_Comm.h"
54
#include "Epetra_Map.h"
55
#include "Epetra_Time.h"
56
#include "Epetra_BlockMap.h"
57
#include "Epetra_MultiVector.h"
58
#include "Epetra_Vector.h"
59
#include "Epetra_Export.h"
60
#include "AztecOO.h"
61
#include "Galeri_Maps.h"
62
#include "Galeri_CrsMatrices.h"
63
#include "
Ifpack_CrsRiluk.h
"
64
#include "
Ifpack.h
"
65
#include "Teuchos_RefCountPtr.hpp"
66
67
#include "
Ifpack_HIPS.h
"
68
69
extern
"C"
{
70
#include "hips.h"
71
};
72
73
// function for fancy output
74
75
std::string
toString
(
const
int
& x) {
76
char
s[100];
77
sprintf(s,
"%d"
, x);
78
return
std::string(s);
79
}
80
81
std::string
toString
(
const
double
& x) {
82
char
s[100];
83
sprintf(s,
"%g"
, x);
84
return
std::string(s);
85
}
86
87
// main driver
88
89
int
main
(
int
argc,
char
*argv[]) {
90
91
#ifdef HAVE_MPI
92
MPI_Init(&argc,&argv);
93
Epetra_MpiComm
Comm (MPI_COMM_WORLD);
94
#else
95
Epetra_SerialComm
Comm;
96
#endif
97
98
int
ierr=HIPS_Initialize(1);
99
HIPS_ExitOnError(ierr);
100
101
int
MyPID = Comm.
MyPID
();
102
bool
verbose
=
false
;
103
if
(MyPID==0)
verbose
=
true
;
104
105
Teuchos::ParameterList
GaleriList;
106
int
nx = 100;
107
GaleriList.
set
(
"nx"
, nx);
108
GaleriList.
set
(
"ny"
, nx * Comm.
NumProc
());
109
// GaleriList.set("ny", nx);
110
GaleriList.
set
(
"mx"
, 1);
111
GaleriList.
set
(
"my"
, Comm.
NumProc
());
112
113
Teuchos::RefCountPtr<Epetra_Map> Map =
Teuchos::rcp
( Galeri::CreateMap(
"Cartesian2D"
, Comm, GaleriList) );
114
Teuchos::RefCountPtr<Epetra_CrsMatrix>
A
=
Teuchos::rcp
( Galeri::CreateCrsMatrix(
"Laplace2D"
, &*Map, GaleriList) );
115
Teuchos::RefCountPtr<Epetra_MultiVector> LHS =
Teuchos::rcp
(
new
Epetra_MultiVector
(*Map, 1) );
116
Teuchos::RefCountPtr<Epetra_MultiVector>
RHS
=
Teuchos::rcp
(
new
Epetra_MultiVector
(*Map, 1) );
117
LHS->PutScalar(0.0);
RHS
->Random();
118
119
// ============================ //
120
// Construct ILU preconditioner //
121
// ---------------------------- //
122
123
Teuchos::RefCountPtr<Ifpack_HIPS> RILU;
124
125
RILU =
Teuchos::rcp
(
new
Ifpack_HIPS(&*
A
) );
126
127
Teuchos::ParameterList
List;
128
List.
set
(
"hips: id"
,0);
129
List.
set
(
"hips: setup output"
,2);
130
List.
set
(
"hips: iteration output"
,0);
131
List.
set
(
"hips: drop tolerance"
,5e-3);
132
List.
set
(
"hips: graph symmetric"
,1);
133
RILU->SetParameters(List);
134
135
136
RILU->Initialize();
137
RILU->Compute();
138
139
// Here we create an AztecOO object
140
LHS->PutScalar(0.0);
141
142
int
Niters = 50;
143
144
AztecOO solver;
145
solver.SetUserMatrix(&*
A
);
146
solver.SetLHS(&*LHS);
147
solver.SetRHS(&*
RHS
);
148
solver.SetAztecOption(AZ_solver,AZ_gmres);
149
solver.SetPrecOperator(&*RILU);
150
solver.SetAztecOption(AZ_output, 1);
151
solver.Iterate(Niters, 1.0e-8);
152
153
int
OldIters = solver.NumIters();
154
155
156
HIPS_Finalize();
157
158
#ifdef HAVE_MPI
159
MPI_Finalize() ;
160
#endif
161
162
return
(EXIT_SUCCESS);
163
}
RHS
#define RHS(a)
Definition:
MatGenFD.c:60
Ifpack_HIPS.h
toString
std::string toString(const int &x)
Definition:
test/HIPS/cxx_main.cpp:75
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Epetra_SerialComm::MyPID
int MyPID() const
Ifpack_CrsRiluk.h
Epetra_SerialComm::NumProc
int NumProc() const
Teuchos::ParameterList::set
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Ifpack_ConfigDefs.h
Epetra_MpiComm
Epetra_SerialComm
verbose
bool verbose
Definition:
test/CompareWithAztecOO/cxx_main.cpp:66
Ifpack.h
Epetra_MultiVector
A
Teuchos::ParameterList
main
int main(int argc, char *argv[])
Definition:
test/HIPS/cxx_main.cpp:89
Generated by
1.8.16