OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 
34 namespace oofem {
36  diag_( C.giveNumberOfRows() )
37 { }
38 
39 
40 void
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 diag = C.at(i, i);
51  if ( diag == 0 ) {
52  OOFEM_ERROR("failed, zero diagonal detected in equation %d", i);
53  }
54 
55  diag_(i - 1) = 1. / diag;
56  }
57 }
58 
59 
60 void
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 
70 void
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
Base class for all matrices stored in sparse format.
Definition: sparsemtrx.h:60
virtual double & at(int i, int j)=0
Returns coefficient at position (i,j).
void trans_solve(const FloatArray &rhs, FloatArray &solution) const
Solves the transposed system.
Definition: diagpre.C:71
virtual void init(const SparseMtrx &a)
Initializes the receiver (constructs the preconditioning matrix M) of given matrix.
Definition: diagpre.C:41
int giveNumberOfRows() const
Returns number of rows of receiver.
Definition: sparsemtrx.h:114
#define OOFEM_ERROR(...)
Definition: error.h:61
DiagPreconditioner()
Constructor. The user should call initializeFrom and init services in this given order to ensure cons...
Definition: diagpre.h:51
const double & diag(int i) const
Definition: diagpre.h:62
Class representing vector of real numbers.
Definition: floatarray.h:82
Abstract class for IML++ compatible preconditioner.
Definition: precond.h:53
void solve(const FloatArray &rhs, FloatArray &solution) const
Solves the linear system.
Definition: diagpre.C:61
Class representing the general Input Record.
Definition: inputrecord.h:101
void zero()
Zeroes all coefficients of receiver.
Definition: floatarray.C:658
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 resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631

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:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011