Commit 2b88af11 authored by prudhomm's avatar prudhomm
Browse files

- update doxygen tools

- added SolverPETSC a simple interface to PETSC linear solvers
  by default gmres + ilu
  the matrix format is CSR. MSR should added at some point
- added test_petsc.cpp to see how it works on "finite difference"
  matrices
- ignore some automatically generated files
parent 20bd8758
......@@ -42,4 +42,8 @@ SUBDIRS = admin doc life testsuite
include $(top_srcdir)/admin/Doxyfile.am
apidox-all:
cd life && make apidox
\ No newline at end of file
cd life && make apidox
upload-api:
cd doc/ && scp -r api prudhomm@cmcsforge.epfl.ch:/var/lib/gforge/chroot/home/groups/lifev/htdocs/api-$(VERSION)
\ No newline at end of file
......@@ -80,6 +80,8 @@ dnl aztec
AC_CHECK_AZTEC
dnl petsc
AC_CHECK_PETSC(2.1.6) #
AM_CONDITIONAL(HAVE_PETSC, test "x$petsc_libs" != "x" )
dnl parmetis
AC_CHECK_PARMETIS
......
/*******************************************************************************
Style sheet for kdelibs doxygen documentation.
Copyright (c) Anders Lund <anders@alweb.dk> 2002
This script is made available under the terms of the General Public License.
You should have received a copy of the GNU General Public License
along with this software; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
********************************************************************************/
body {
margin: 0px;
color: black;
background-color: white;
}
a {
color: #0000C0;
}
/* decorative header */
div.header {
background-color: #9bd;
}
div.header table {
padding: 0px;
margin: 0px
}
div.header table tr td h1 {
color: white;
font: bold 20pt courier;
padding-top: 0.5em;
}
/* global lind buttons at bottom of decorative header */
table.links {
float: right;
border:0;
padding-left:1px
}
table.links td a {
color: white
}
table.links td:hover {
background-color:#0C4293;
}
table.links td a:hover {
color: white;
background-color:#0C4293
}
table.links td {
border-left: 1px solid #4A81D5;
padding: 0px 12px 0px 12px;
background-color:#0E4EAF;
font-size:9pt;
/*font-weight: bold;*/
}
/* little gradient below decorative/navigation header */
div#hgrad {
height: 12px;
}
/* contents part of page */
div.text {
margin: 12px
}
/* contents, mostly equivalent to the default doxugen style sheet */
H1 { text-align: center; }
CAPTION { font-weight: bold }
A.qindex {}
A.qindexRef {}
A.el { text-decoration: none; font-weight: bold }
A.elRef { font-weight: bold }
A.code { text-decoration: none; font-weight: normal; color: #4444ee }
A.codeRef { font-weight: normal; color: #4444ee }
A:hover { text-decoration: none; background-color: #ececec }
DL.el { margin-left: -1cm }
DIV.fragment { width: 100%; border: none; background-color: #ffffee; padding: 12px }
DIV.ah { background-color: navy; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px }
TABLE.mdTable { background-color: #f8f8f8; border: .2em solid #d7d7d7; }
TD.mdRow { padding: 8px 20px; }
TD.md { font-weight: bold; }
TD.mdname1 { font-weight: bold; color: #602020; }
TD.mdname { font-weight: bold; color: #602020; width: 600px; }
DIV.groupHeader { margin-left: 16px; margin-top: 12px; margin-bottom: 6px; font-weight: bold }
DIV.groupText { margin-left: 16px; font-style: italic; font-size: smaller }
BODY { background: white }
TD.memItemLeft {
padding: 1px 0px 0px 8px;
margin: 4px;
border: solid .1em white;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #f8f8f8;
}
TD.memItemRight {
padding: 1px 0px 0px 8px;
margin: 4px;
border: solid .1em white;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #f8f8f8;
}
TD.indexkey {
background-color: #e0eef8;
font-weight: bold;
padding-right : 10px;
padding-top : 2px;
padding-left : 10px;
padding-bottom : 2px;
margin-left : 0px;
margin-right : 0px;
margin-top : 2px;
margin-bottom : 2px
}
TD.indexvalue {
background-color: #e0eef8;
font-style: normal;
padding-right : 10px;
padding-top : 2px;
padding-left : 10px;
padding-bottom : 2px;
margin-left : 0px;
margin-right : 0px;
margin-top : 2px;
margin-bottom : 2px
}
SPAN.keyword { color: #008000 }
SPAN.keywordtype { color: #604020 }
SPAN.keywordflow { color: #e08000 }
SPAN.comment { color: #800000 }
SPAN.preprocessor { color: #806020 }
SPAN.stringliteral { color: #002080 }
SPAN.charliteral { color: #008080 }
/* kde decoration at bottom */
div#bottom-nav {
position : relative;
background-color: transparent;
/*width : 100%;*/
/*top: 0px;
left: 0px;
right: 0px;
margin-left: 0px;
margin-right:0px;*/
margin-top: 12px;
height: 50px;
background-image : url('bottom1.png');
background-repeat : repeat-x;
}
/* copyright etc at bottom */
div.bottom {
margin: 12px;
font-size: 9pt;
text-align: right;
}
div.bottom a {
color: #aaaaaa
}
</div>
<div id="bottom-nav">
</div>
<div class="bottom">
This file is part of the documentation for $projectname $projectnumber.
</div>
<div class="bottom" style="color:#cccccc">
Documentation copyright &copy; 2002-2004 the EPFL, INRIA, Politecnico di Milano.<br>
Generated on $datetime by
<a href="http://www.doxygen.org/index.html">doxygen</a> $doxygenversion written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, &copy;&nbsp;1997-2003
</div>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>$title ($projectname)</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>
<div class="header">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td rowspan="2" width="110">
<a href="../../../index.html" title="The API documentation main page"><font color="#ffffff">[<b>Main API</b>]</font></a>
</td>
<td width="95%">
<h1>$projectname API Documentation</h1>
</td>
</tr>
<tr>
<td valign="bottom">
<table class="links" border=0 cellspacing=0>
<tr>
<td><a href="index.html">Overview</a></td>
<td><a href="hierarchy.html" title="Inheritance list, sorted roughly alphabetically">Class&nbsp;Hierarchy</a></td>
<td><a href="classes.html" title="Alphabetical list of classes">Classes</a></td>
<td><a href="annotated.html" title="Classes, structs, unions and interfaces with brief descriptions">Classes&nbsp;(annotated)</a></td>
<td><a href="functions.html" title="Documented class members with links to the classes they belong to">Members</a></td>
<td><a href="namespaces.html" title="All documented namespaces with brief descriptions">Namespaces</a></td>
<td><a href="files.html" title="A list of all documented files with brief descriptions">Source&nbsp;Files</a></td>
</tr>
</table>
</td></tr></table>
</div>
<div id="hgrad"></div>
<div class="text">
</div>
<div id="bottom-nav">
</div>
<div class="bottom">
This file is part of the documentation for Life $projectnumber.
</div>
<div class="bottom" style="color:#cccccc">
Documentation copyright &copy; 2000-2004 EPFL, INRIA, Politecnico di Milano.<br>
Generated on $datetime by
<a href="http://www.doxygen.org/index.html">doxygen</a> $doxygenversion written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, &copy;&nbsp;1997-2001
</div>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>$title ($projectname)</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>
<div class="header">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td rowspan="2" width="92">
<a href="index.html" title="The API documentation main page"><font color="#ffffff">[<b>Main API</b>]</font></a>
</td>
<td width="95%">
<h1>$projectname</h1>
</td>
</tr>
<tr>
<td valign="bottom">
<table class="links" border=0 cellspacing=0>
<tr>
<td><a href="index.html">Home</a></td>
<td><a href="search.html" title="Search page">Search</a></td>
</tr>
</table>
</td></tr></table>
</div>
<div id="hgrad"></div>
<div class="text">
......@@ -25,15 +25,17 @@ SUFFIXES = .cpp .hpp .idl .c .h .f .F .o .moc
INCLUDES = -I$(top_srcdir)/life/lifecore -I$(top_srcdir)/life/lifearray -I$(top_srcdir)/life/lifefem -I$(top_srcdir)/life/lifemesh
#INCLUDES = -I$(top_srcdir)/life/lifecore -I$(top_srcdir)/life/lifearray
include_HEADERS = algebraic_facto.hpp dataAztec.hpp dataNewton.hpp inexactLU.hpp \
linesearch_cubic.hpp linesearch_parabolic.hpp mixed_pattern.hpp newton.hpp \
pattern.hpp picard.hpp saddlePointCG.hpp \
values.hpp
if HAVE_PETSC
PETSC_SRCS = SolverPETSC.cpp
PETSC_HDRS = SolverPETSC.hpp
endif
include_HEADERS = algebraic_facto.hpp dataAztec.hpp dataNewton.hpp inexactLU.hpp linesearch_cubic.hpp linesearch_parabolic.hpp mixed_pattern.hpp newton.hpp pattern.hpp picard.hpp saddlePointCG.hpp values.hpp $(PETSC_HDRS)
lib_LTLIBRARIES = liblifealg.la
liblifealg_la_SOURCES = dataAztec.cpp dataNewton.cpp pattern.cpp values.cpp
liblifealg_la_SOURCES = dataAztec.cpp dataNewton.cpp pattern.cpp values.cpp $(PETSC_SRCS)
liblifealg_la_LIBADD = ../lifecore/liblifecore.la $(aztec_libs)
liblifealg_la_LIBADD = ../lifefem/liblifefem.la ../lifecore/liblifecore.la $(petsc_libs) $(aztec_libs)
include $(top_srcdir)/admin/Doxyfile.am
\ No newline at end of file
include $(top_srcdir)/admin/Doxyfile.am
/* -*- Mode : c++; c-tab-always-indent: t; indent-tabs-mode: nil; -*-
This file is part of the LifeV libraries.
Author: Christophe Prud'homme <christophe.prudhomme@epfl.ch>
Copyright (C) 2004 EPFL, INRIA, Politecnico di Milano
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** \file SolverPETSC.cpp
Implementation file for the LifeV-PETSC interface.
*/
#if defined(__GNUG__)
#pragma implementation
#endif /* __GNUG__ */
#include <SolverPETSC.hpp>
extern "C"
{
#include <petsc.h>
#include <petscmat.h>
#include <petscsles.h>
};
namespace life
{
class SolverPETSC::Private
{
public:
Private()
:
__tolerance( 1e-11 ),
_M_use_A( false ),
_M_use_A_t( false )
{}
double __tolerance;
Mat __A;
Mat __A_t;
SLES __sles;
PC __pc;
KSP __ksp;
mutable bool _M_use_A;
mutable bool _M_use_A_t;
};
SolverPETSC::SolverPETSC( std::string const& __ksp_type,
std::string const& __pc_type,
SMonitorType __monitor )
:
_M_p ( new Private )
{
int ierr = SLESCreate( PETSC_COMM_WORLD, &_M_p->__sles ); //CHKERRQ(ierr);
ierr = SLESGetKSP( _M_p->__sles, & _M_p->__ksp ); //CHKERRQ(ierr);
ierr = SLESGetPC( _M_p->__sles, &_M_p->__pc ); //CHKERRQ(ierr);
ierr = KSPSetType( _M_p->__ksp, const_cast<char*> ( __ksp_type.c_str() ) ); //CHKERRQ(ierr);
//! set the monitor type
switch ( __monitor )
{
case KSP_DEFAULT_MONITOR:
ierr = KSPSetMonitor( _M_p->__ksp, &KSPDefaultMonitor, 0, 0 );
break;
case KSP_TRUE_MONITOR:
ierr = KSPSetMonitor( _M_p->__ksp, &KSPTrueMonitor, 0, 0 );
break;
case KSP_NO_MONITOR:
default:
// do nothing
break;
}
ierr = PCSetType( _M_p->__pc, const_cast<char*> ( __pc_type.c_str() ) ); //CHKERRQ(ierr);
if ( __pc_type == "ilu" )
{
ierr = PCILUSetLevels( _M_p->__pc, 2 ); //CHKERRQ(ierr);
}
if ( __pc_type == "icc" )
{
ierr = PCICCSetLevels( _M_p->__pc, 2 ); //CHKERRQ(ierr);
}
ierr = KSPSetTolerances( _M_p->__ksp, _M_p->__tolerance, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT ); //CHKERRQ(ierr);
ierr = SLESSetFromOptions( _M_p->__sles ); //CHKERRQ(ierr);
}
SolverPETSC::~SolverPETSC()
{
int __ierr;
if ( _M_p->_M_use_A )
{
__ierr = MatDestroy( _M_p->__A ); ////CHKERRQ( __ierr );
}
if ( _M_p->_M_use_A_t )
{
__ierr = MatDestroy( _M_p->__A_t ); ////CHKERRQ( __ierr );
}
}
SolverPETSC*
SolverPETSC::New()
{
return new SolverPETSC;
}
/*!
\brief Gets the last (approximate preconditioned) residual norm that has been computed.
\return last (approximate preconditioned) residual norm
*/
double
SolverPETSC::residualNorm() const
{
double __residual;
KSPGetResidualNorm( _M_p->__ksp, &__residual );
return __residual;
}
PC const& SolverPETSC::preconditioner() const { return _M_p->__pc; }
PC & SolverPETSC::preconditioner() { return _M_p->__pc; }
KSP const& SolverPETSC::krylovSolver() const { return _M_p->__ksp; }
KSP & SolverPETSC::krylovSolver() { return _M_p->__ksp; }
/*!
\brief Sets the relative, absolute, divergence, and maximum iteration tolerances
used by the default KSP convergence testers.
Use PETSC_DEFAULT to retain the default value of any of the tolerances.
See KSPDefaultConverged() for details on the use of these parameters in the default convergence test.
See also KSPSetConvergenceTest() for setting user-defined stopping criteria.
\arg rtol - the relative convergence tolerance (relative decrease in the residual norm)
\arg atol - the absolute convergence tolerance (absolute size of the residual norm)
\arg dtol - the divergence tolerance (amount residual can increase before KSPDefaultConverged() concludes that the method is diverging)
\arg maxits - maximum number of iterations to use
*/
void
SolverPETSC::setTolerances( double __rtol, double __atol, double __dtol, int __maxits )
{
KSPSetTolerances( _M_p->__ksp, __rtol, __atol, __dtol, __maxits );
}
void
SolverPETSC::setMatrix( uint __nrows, uint* __r, uint *__i, double* __v )
{
MatCreateSeqAIJWithArrays(PETSC_COMM_SELF,
__nrows, __nrows,
(int*)__r,
(int*)__i,
__v,
&_M_p->__A );
_M_p->_M_use_A = true;
}
void
SolverPETSC::setMatrixTranspose( uint __nrows, uint* __r, uint *__i, double* __v )
{
MatCreateSeqAIJWithArrays(PETSC_COMM_SELF,
__nrows, __nrows,
(int*)__r,
(int*)__i,
__v,
//const_cast<int*>( __M.getRowIndices() ),
//const_cast<int*>( __M.getMatrixIndices() ),
//const_cast<double*>( __M.getMatrixValues() ),
&_M_p->__A_t );
_M_p->_M_use_A_t = true;
}
//! solve \f[ A X = B \f]
/*!
\param __X the solution
\param __B the right hand side
\return the number of iterations
*/
int
SolverPETSC::solve( array_type& __X, array_type const& __B, MatStructure __ptype )
{
int __rowA;
int __colA;
MatGetSize(_M_p->__A,&__rowA,&__colA); //CHKERRQ(__ierr);
int __iterations;
std::cerr << "[SolverPETSC::solve] Solving primal\n";
Vec __x;
VecCreateSeqWithArray( PETSC_COMM_SELF, __X.size(), &__X[0], &__x );
Vec __b;
VecCreateSeqWithArray( PETSC_COMM_SELF, __B.size(), &__B[0], &__b );
SLESSetOperators( _M_p->__sles, _M_p->__A, _M_p->__A, __ptype ); //CHKERRQ(__ierr);
SLESSolve( _M_p->__sles, __b, __x , &__iterations ); //CHKERRQ(__ierr);
/*
View solver info; we could instead use the option -sles_view to
print this info to the screen at the conclusion of SLESSolve().
*/
SLESView( _M_p->__sles, PETSC_VIEWER_STDOUT_WORLD );
// Petsc won't deallocate the memory so __X and __B contains the informations
VecDestroy( __x );
VecDestroy( __b );
std::cerr << "[SolverPETSC::solve] Solving primal done in " << __iterations << " iterations\n";
return __iterations;
}
int
SolverPETSC::solveTranspose( array_type& __X, array_type const& __B, MatStructure __ptype )
{
int __rowA;
int __colA;
MatGetSize(_M_p->__A_t,&__rowA,&__colA); ////CHKERRQ(__ierr);
int __iterations;
std::cerr << "[SolverPETSC::solveTranspose] Solving transpose\n";
Vec __x;
VecCreateSeqWithArray( PETSC_COMM_SELF, __X.size(), &__X[0], &__x );
Vec __b;
VecCreateSeqWithArray( PETSC_COMM_SELF, __B.size(), &__B[0], &__b );
SLESSetOperators( _M_p->__sles, _M_p->__A_t, _M_p->__A_t, __ptype ); ////CHKERRQ(__ierr);
SLESSolve( _M_p->__sles, __b, __x , &__iterations ); ////CHKERRQ(__ierr);
// Petsc won't deallocate the memory so __X and __B contains the informations
VecDestroy( __x );
VecDestroy( __b );
std::cerr << "[SolverPETSC::solveTranspose] Solving transpose done in " << __iterations << " iterations\n";
return __iterations;
}
}
/* -*- Mode : c++; -*-
This file is part of the LifeV libraries.
Author: Christophe Prud'homme <christophe.prudhomme@epfl.ch>
Copyright (C) 2004 EPFL, INRIA, Politecnico di Milano
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** \file SolverPETSC.hpp
Header file for the LifeV-PETSC interface.
*/
#ifndef __SolverPETSC_H
#define __SolverPETSC_H 1
#include <iostream>
extern "C"
{