OOFEM 3.0
Loading...
Searching...
No Matches
diagpre.C
Go to the documentation of this file.
1/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
2/* ******** *** SparseLib++ */
3/* ******* ** *** *** *** v. 1.5c */
4/* ***** *** ******** ******** */
5/* ***** *** ******** ******** R. Pozo */
6/* ** ******* *** ** *** *** K. Remington */
7/* ******** ******** A. Lumsdaine */
8/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
9/* */
10/* */
11/* SparseLib++ : Sparse Matrix Library */
12/* */
13/* National Institute of Standards and Technology */
14/* University of Notre Dame */
15/* Authors: R. Pozo, K. Remington, A. Lumsdaine */
16/* */
17/* NOTICE */
18/* */
19/* Permission to use, copy, modify, and distribute this software and */
20/* its documentation for any purpose and without fee is hereby granted */
21/* provided that the above notice appear in all copies and supporting */
22/* documentation. */
23/* */
24/* Neither the Institutions (National Institute of Standards and Technology, */
25/* University of Notre Dame) nor the Authors make any representations about */
26/* the suitability of this software for any purpose. This software is */
27/* provided ``as is'' without expressed or implied warranty. */
28/* */
29/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
30
31#include "diagpre.h"
32#include "sparsemtrx.h"
33
34namespace oofem {
35DiagPreconditioner :: DiagPreconditioner(const SparseMtrx &C, InputRecord &attributes) : Preconditioner(C, attributes),
36 diag( C.giveNumberOfRows() )
37{ }
38
39
40void
41DiagPreconditioner :: init(const SparseMtrx &C)
42{
43 int n = C.giveNumberOfRows();
44
45 diag.resize( n );
46 diag.zero();
47
48 /* Find the diagonal elements */
49 for ( int i = 1; i <= n; i++ ) {
50 double d = C.at(i, i);
51 if ( d == 0 ) {
52 OOFEM_ERROR("failed, zero diagonal detected in equation %d", i);
53 }
54
55 diag.at(i) = 1. / d;
56 }
57}
58
59
60void
61DiagPreconditioner :: solve(const FloatArray &x, FloatArray &y) const
62{
63 y.resize( x.giveSize() );
64 for ( int i = 0; i < x.giveSize(); i++ ) {
65 y[i] = x[i] * diag[i];
66 }
67}
68
69
70void
71DiagPreconditioner :: trans_solve(const FloatArray &x, FloatArray &y) const
72{
73 y.resize( x.giveSize() );
74
75 for ( int i = 0; i < x.giveSize(); i++ ) {
76 y[i] = x[i] * diag[i];
77 }
78}
79} // end namespace oofem
void resize(Index s)
Definition floatarray.C:94
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
Preconditioner(const SparseMtrx &a, InputRecord &attributes)
Definition precond.C:38
virtual double & at(int i, int j)=0
Returns coefficient at position (i,j).
int giveNumberOfRows() const
Returns number of rows of receiver.
Definition sparsemtrx.h:114
#define OOFEM_ERROR(...)
Definition error.h:79

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