OOFEM 3.0
Loading...
Searching...
No Matches
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 - 2025 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
55namespace oofem {
57
58IMLSolver :: IMLSolver(Domain *d, EngngModel *m) : SparseLinearSystemNM(d, m),
59 lhs(nullptr),
60 solverType(IML_ST_CG),
61 precondType(IML_VoidPrec),
62 precondInit(true)
63{}
64
65
66void
67IMLSolver :: initializeFrom(InputRecord &ir)
68{
69 int val = 0;
71 solverType = ( IMLSolverType ) val;
72
73 tol = 1.e-5;
75 maxite = 200;
77 val = 0;
80
81 // create preconditioner
82 if ( precondType == IML_DiagPrec ) {
83 M = std::make_unique<DiagPreconditioner>();
84 } else if ( precondType == IML_VoidPrec ) {
85 M = std::make_unique<VoidPreconditioner>();
86 } else if ( precondType == IML_ILU_CompRowPrec ) {
87 M = std::make_unique<CompRow_ILUPreconditioner>();
88 } else if ( precondType == IML_ILU_CompColPrec ) {
89 M = std::make_unique<CompCol_ILUPreconditioner>();
90 } else if ( precondType == IML_ICPrec ) {
91 M = std::make_unique<CompCol_ICPreconditioner>();
92 } else {
93 throw ValueInputException(ir, _IFT_IMLSolver_lsprecond, "unknown preconditioner type");
94 }
95
96 // initialize precond attributes
97 return M->initializeFrom(ir);
98}
99
100
102IMLSolver :: solve(SparseMtrx &A, FloatArray &b, FloatArray &x)
103{
104 int result;
105
106 if ( x.giveSize() != b.giveSize() ) {
107 OOFEM_ERROR("size mismatch");
108 }
109
110 // check preconditioner
111 if ( M ) {
112 if ( precondInit || lhs != &A || this->lhsVersion != A.giveVersion() ) {
113 M->init(A);
114 }
115 } else {
116 OOFEM_ERROR("preconditioner creation error");
117 }
118
119 lhs = &A;
120 this->lhsVersion = A.giveVersion();
121
122#ifdef TIME_REPORT
123 Timer timer;
124 timer.startTimer();
125#endif
126
127 int mi = this->maxite;
128 double t = this->tol;
129 if ( solverType == IML_ST_CG ) {
130 result = CG(* lhs, x, b, * M, mi, t);
131 OOFEM_LOG_INFO("CG(%s): flag=%d, nite %d, achieved tol. %g\n", M->giveClassName(), result, mi, t);
132 } else if ( solverType == IML_ST_GMRES ) {
133 int restart = 100;
134 FloatMatrix H(restart + 1, restart); // storage for upper Hesenberg
135 result = GMRES(* lhs, x, b, * M, H, restart, mi, t);
136 OOFEM_LOG_INFO("GMRES(%s): flag=%d, nite %d, achieved tol. %g\n", M->giveClassName(), result, mi, t);
137 } else {
138 OOFEM_ERROR("unknown lsover type");
139 }
140
141#ifdef TIME_REPORT
142 timer.stopTimer();
143 OOFEM_LOG_INFO( "IMLSolver info: user time consumed by solution: %.2fs\n", timer.getUtime() );
144#endif
145
146 return (result == 0)?CR_CONVERGED:CR_DIVERGED_ITS;
147}
148} // end namespace oofem
#define REGISTER_SparseLinSolver(class, type)
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
IMLSolverType
Solver type.
Definition imlsolver.h:68
bool precondInit
Precond. init flag.
Definition imlsolver.h:83
SparseMtrx * lhs
Last mapped Lhs matrix.
Definition imlsolver.h:73
IMLPrecondType precondType
IML Preconditioner type.
Definition imlsolver.h:81
std::unique_ptr< Preconditioner > M
Preconditioner.
Definition imlsolver.h:77
double tol
Tolerance of residual.
Definition imlsolver.h:88
IMLPrecondType
Preconditioner type.
Definition imlsolver.h:70
int maxite
Max number of iterations.
Definition imlsolver.h:90
SparseMtrx::SparseMtrxVersionType lhsVersion
Last mapped matrix version.
Definition imlsolver.h:75
IMLSolverType solverType
IML Solver type.
Definition imlsolver.h:79
SparseMtrxVersionType giveVersion()
Return receiver version.
Definition sparsemtrx.h:94
double getUtime()
Returns total user time elapsed in seconds.
Definition timer.C:105
void startTimer()
Definition timer.C:69
void stopTimer()
Definition timer.C:77
#define OOFEM_ERROR(...)
Definition error.h:79
#define _IFT_IMLSolver_stype
Definition imlsolver.h:49
#define _IFT_IMLSolver_lsiter
Definition imlsolver.h:51
#define _IFT_IMLSolver_lstol
Definition imlsolver.h:50
#define _IFT_IMLSolver_lsprecond
Definition imlsolver.h:52
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
#define OOFEM_LOG_INFO(...)
Definition logger.h:143
@ CR_DIVERGED_ITS

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011