OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
imlsolver.C
Go to the documentation of this file.
1 /*
2  *
3  * ##### ##### ###### ###### ### ###
4  * ## ## ## ## ## ## ## ### ##
5  * ## ## ## ## #### #### ## # ##
6  * ## ## ## ## ## ## ## ##
7  * ## ## ## ## ## ## ## ##
8  * ##### ##### ## ###### ## ##
9  *
10  *
11  * OOFEM : Object Oriented Finite Element Code
12  *
13  * Copyright (C) 1993 - 2013 Borek Patzak
14  *
15  *
16  *
17  * Czech Technical University, Faculty of Civil Engineering,
18  * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33  */
34 
35 #include <iml/cg.h>
36 #include <iml/gmres.h>
37 
38 #include "imlsolver.h"
39 #include "sparsemtrx.h"
40 #include "floatarray.h"
41 #include "diagpre.h"
42 #include "voidprecond.h"
43 #include "compcol.h"
44 #include "iluprecond.h"
45 #include "icprecond.h"
46 #include "verbose.h"
47 #include "ilucomprowprecond.h"
48 #include "linsystsolvertype.h"
49 #include "classfactory.h"
50 
51 #ifdef TIME_REPORT
52  #include "timer.h"
53 #endif
54 
55 namespace oofem {
57 
59 {
60  Lhs = NULL;
61  M = NULL;
62  solverType = IML_ST_CG;
63  precondType = IML_VoidPrec;
64  precondInit = true;
65 }
66 
67 
69 {
70  delete M;
71 }
72 
75 {
76  IRResultType result; // Required by IR_GIVE_FIELD macro
77 
78  int val;
79 
80  val = 0;
82  solverType = ( IMLSolverType ) val;
83 
84  tol = 1.e-5;
86  maxite = 200;
88  val = 0;
90  precondType = ( IMLPrecondType ) val;
91 
92  // create preconditioner
93  if ( precondType == IML_DiagPrec ) {
94  M = new DiagPreconditioner();
95  } else if ( precondType == IML_VoidPrec ) {
96  M = new VoidPreconditioner();
97  } else if ( precondType == IML_ILU_CompRowPrec ) {
99  } else if ( precondType == IML_ILU_CompColPrec ) {
101  } else if ( precondType == IML_ICPrec ) {
102  M = new CompCol_ICPreconditioner();
103  } else {
104  OOFEM_WARNING("unknown preconditioner type");
105  return IRRT_BAD_FORMAT;
106  }
107 
108  // initialize precond attributes
109  return M->initializeFrom(ir);
110 }
111 
112 
113 NM_Status
115 {
116  int result;
117 
118  if ( x.giveSize() != b.giveSize() ) {
119  OOFEM_ERROR("size mismatch");
120  }
121 
122 
123  // check preconditioner
124  if ( M ) {
125  if ( ( precondInit ) || ( Lhs != &A ) || ( this->lhsVersion != A.giveVersion() ) ) {
126  M->init(A);
127  }
128  } else {
129  OOFEM_ERROR("preconditioner creation error");
130  }
131 
132  Lhs = &A;
133  this->lhsVersion = A.giveVersion();
134 
135 #ifdef TIME_REPORT
136  Timer timer;
137  timer.startTimer();
138 #endif
139 
140 
141  if ( solverType == IML_ST_CG ) {
142  int mi = this->maxite;
143  double t = this->tol;
144  result = CG(* Lhs, x, b, * M, mi, t);
145  OOFEM_LOG_INFO("CG(%s): flag=%d, nite %d, achieved tol. %g\n", M->giveClassName(), result, mi, t);
146  } else if ( solverType == IML_ST_GMRES ) {
147  int mi = this->maxite, restart = 100;
148  double t = this->tol;
149  FloatMatrix H(restart + 1, restart); // storage for upper Hesenberg
150  result = GMRES(* Lhs, x, b, * M, H, restart, mi, t);
151  OOFEM_LOG_INFO("GMRES(%s): flag=%d, nite %d, achieved tol. %g\n", M->giveClassName(), result, mi, t);
152  } else {
153  OOFEM_ERROR("unknown lsover type");
154  }
155 
156 #ifdef TIME_REPORT
157  timer.stopTimer();
158  OOFEM_LOG_INFO( "IMLSolver info: user time consumed by solution: %.2fs\n", timer.getUtime() );
159 #endif
160 
161 
162  //solved = 1;
163  return NM_Success;
164 }
165 } // end namespace oofem
int maxite
Max number of iterations.
Definition: imlsolver.h:87
Implemantation of ILU (Incomplete LU) Preconditioner.
Definition: iluprecond.h:45
virtual NM_Status solve(SparseMtrx &A, FloatArray &b, FloatArray &x)
Solves the given linear system iteratively by method described by IMLSolverType.
Definition: imlsolver.C:114
#define NM_Success
Numerical method exited with success.
Definition: nmstatus.h:47
SparseMtrx::SparseMtrxVersionType lhsVersion
Last mapped matrix version.
Definition: imlsolver.h:72
Class and object Domain.
Definition: domain.h:115
double tol
Tolerance of residual.
Definition: imlsolver.h:85
Base class for all matrices stored in sparse format.
Definition: sparsemtrx.h:60
Preconditioner * M
Preconditioner.
Definition: imlsolver.h:74
IMLPrecondType precondType
IML Preconditioner type.
Definition: imlsolver.h:78
#define _IFT_IMLSolver_stype
Definition: imlsolver.h:46
This base class is an abstraction for all numerical methods solving sparse linear system of equations...
unsigned long NM_Status
Mask defining NumMetod Status; which can be asked after finishing computation by Numerical Method...
Definition: nmstatus.h:44
virtual void init(const SparseMtrx &a)
Initializes the receiver (constructs the preconditioning matrix M) of given matrix.
Definition: precond.h:77
bool precondInit
Precond. init flag.
Definition: imlsolver.h:80
#define OOFEM_LOG_INFO(...)
Definition: logger.h:127
SparseMtrx * Lhs
Last mapped Lhs matrix.
Definition: imlsolver.h:70
#define OOFEM_ERROR(...)
Definition: error.h:61
#define _IFT_IMLSolver_lsprecond
Definition: imlsolver.h:49
IMLSolverType
Solver type.
Definition: imlsolver.h:65
IMLSolverType solverType
IML Solver type.
Definition: imlsolver.h:76
Incomplete Cholesky IC(0) (no fill - up) preconditioner for symmetric, positive definite matrices...
Definition: icprecond.h:44
#define _IFT_IMLSolver_lstol
Definition: imlsolver.h:47
Initializes the variable VERBOSE, in order to get a few intermediate messages on screen: beginning an...
Class representing vector of real numbers.
Definition: floatarray.h:82
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
virtual IRResultType initializeFrom(InputRecord *ir)
Definition: imlsolver.C:74
virtual ~IMLSolver()
Destructor.
Definition: imlsolver.C:68
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
virtual const char * giveClassName() const
Returns the preconditioner name.
Definition: precond.h:113
Implements the solution of linear system of equation in the form using iterative solvers from IML++ ...
Definition: imlsolver.h:61
Class representing the general Input Record.
Definition: inputrecord.h:101
Implementation of diagonal preconditioner.
Definition: diagpre.h:42
REGISTER_SparseLinSolver(IMLSolver, ST_IML)
Definition: imlsolver.C:56
Class implementing single timer, providing wall clock and user time capabilities. ...
Definition: timer.h:46
IMLPrecondType
Preconditioner type.
Definition: imlsolver.h:67
Implemantation of ILU (Incomplete LU) Preconditioner for compressed row sparse matrices.
#define _IFT_IMLSolver_lsiter
Definition: imlsolver.h:48
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
the oofem namespace is to define a context or scope in which all oofem names are defined.
void startTimer()
Definition: timer.C:69
double getUtime()
Returns total user time elapsed in seconds.
Definition: timer.C:105
#define OOFEM_WARNING(...)
Definition: error.h:62
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver from given record. Empty implementation.
Definition: precond.h:115
Class implementing void preconditioner.
Definition: voidprecond.h:46
void stopTimer()
Definition: timer.C:77
SparseMtrxVersionType giveVersion()
Return receiver version.
Definition: sparsemtrx.h:94

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:29 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011