OOFEM 3.0
Loading...
Searching...
No Matches
rowcol.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 "rowcol.h"
36#include "intarray.h"
37#include "floatarray.h"
38#include "mathfem.h"
39#include "error.h"
40
41#include <cstdlib>
42#include <algorithm>
43
44namespace oofem {
45
46RowColumn :: RowColumn(int n):
47 number(n),
48 start(n),
49 row(0),
50 column(0),
51 diag(0.)
52{
53}
54
55
56RowColumn :: RowColumn(int n, int start):
57 number(n),
58 start(start),
59 row(n-start),
60 column(n-start),
61 diag(0.)
62{
63}
64
65
66#ifdef DEBUG
67double &RowColumn :: atU(int i)
68{
69 this->checkBounds(i);
70 return column [ i - start ];
71}
72
73double RowColumn :: atU(int i) const
74{
75 this->checkBounds(i);
76 return column [ i - start ];
77}
78
79double &RowColumn :: atL(int i)
80{
81 this->checkBounds(i);
82 return row [ i - start ];
83}
84
85double RowColumn :: atL(int i) const
86{
87 this->checkBounds(i);
88 return row [ i - start ];
89}
90#endif
91
92
93void RowColumn :: checkBounds(int i) const
94{
95 if ( i < start || i >= number ) {
96 OOFEM_ERROR("error in bounds of RowColumn %d (start=%d) : no entry %d", number, start, i);
97 }
98}
99
100
101void RowColumn :: checkSizeTowards(const IntArray &loc)
102{
103 int i, c, first = start;
104
105 int n = loc.giveSize();
106 if ( !n ) {
107 OOFEM_ERROR("0-size location array");
108 }
109
110 // get first non-zero coefficient in loc
111 for ( i = 1; i <= n; i++ ) {
112 if ( ( first = loc.at(i) ) ) {
113 break;
114 }
115 }
116
117 // get min coefficient in loc
118 for ( int j = i + 1; j <= n; j++ ) {
119 if ( ( c = loc.at(j) ) ) {
120 first = min(c, first);
121 }
122 }
123
124 // enlarge the receiver if necessary
125 if ( first < start && first ) {
126 this->growTo(first);
127 }
128}
129
130
131double RowColumn :: dot(const FloatArray &b, char c, int first, int last) const
132// Returns the dot product of the row (c=='R') or the column (c=='C') of
133// the receiver with array 'b', from indices 'first' to 'last'.
134{
135 double answer = 0.;
136 int i = last - first + 1;
137
138 const double *p1;
139 if ( c == 'R' ) {
140 p1 = row.data() + first - start;
141 } else {
142 p1 = column.data() + first - start;
143 }
144
145 // I do the bad practice, because it speed up debug runs significantly / Mikael
146 const double *p2 = b.givePointer() + first-1 ; // bad practice !
147 //int pos = first;
148 while ( i-- ) {
149 answer += *p1++ * *p2++ ;
150 //answer += * p1.at(pos) * b.at(pos++);
151 }
152
153 return answer;
154}
155
156
157void
158RowColumn :: growTo(int newStart)
159{
160# ifdef DEBUG
161 if ( newStart <= 0 || newStart > start ) {
162 OOFEM_ERROR("cannot enlarge RowCol %d (start=%d) to %d", number, start, newStart);
163 }
164# endif
165 int increase = start - newStart;
166 row.resize(this->number-newStart);
167 column.resize(this->number-newStart);
168 if ( this->number - start > 0 ) {
170 std::rotate(row.rbegin(), row.rbegin()+increase, row.rend());
171 std::rotate(column.rbegin(), column.rbegin()+increase, column.rend());
172 }
173 start = newStart;
174}
175
176
177void RowColumn :: printYourself() const
178{
179 printf("Row-column %d : start = %d, diag = %.5f\n col : ",
180 number, start, diag);
181 for ( int i = 0; i < number - start; i++ ) {
182 printf(" % .5f", column [ i ]);
183 }
184
185 printf("\n row : ");
186 for ( int i = 0; i < number - start; i++ ) {
187 printf(" % .5f", row [ i ]);
188 }
189
190 printf("\n");
191}
192
193
194void
195RowColumn :: zero()
196{
197 std::fill(row.begin(), row.end(), 0.);
198 std::fill(column.begin(), column.end(), 0.);
199 diag = 0.;
200}
201
202} // end namespace oofem
int & at(std::size_t i)
Definition intarray.h:104
int giveSize() const
Definition intarray.h:211
double diag
Definition rowcol.h:74
void growTo(int)
Definition rowcol.C:158
std::vector< double > row
Definition rowcol.h:72
std::vector< double > column
Definition rowcol.h:73
#define OOFEM_ERROR(...)
Definition error.h:79
FloatArrayF< N > min(const FloatArrayF< N > &a, const FloatArrayF< N > &b)
FloatArrayF< N > column(const FloatMatrixF< N, M > &mat, std::size_t col)

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