OOFEM 3.0
Loading...
Searching...
No Matches
floatarray.h
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#ifndef floatarray_h
36#define floatarray_h
37
38#include "oofemenv.h"
39#include "contextioresulttype.h"
40#include "contextmode.h"
41#include "error.h"
42#include "numerics.h"
43
44#include <initializer_list>
45#include <vector>
46#include <list>
47#include <iosfwd>
48
49namespace oofem {
50class IntArray;
51class FloatMatrix;
52class DataStream;
53template<std::size_t N> class FloatArrayF;
54
86
87
89#ifdef _USE_EIGEN
90: public VectorXd
91#endif
92{
93#ifdef _USE_EIGEN
94public:
95 OOFEM_EIGEN_DERIVED(FloatArray,VectorXd);
96 FloatArray(int sz): VectorXd(sz) {}
97 void resize(Index s);
98#else
99
100protected:
102 std::vector< double > values;
103
104public:
106
107 std::vector< double > :: iterator begin() { return this->values.begin(); }
108 std::vector< double > :: iterator end() { return this->values.end(); }
109 std::vector< double > :: const_iterator begin() const { return this->values.begin(); }
110 std::vector< double > :: const_iterator end() const { return this->values.end(); }
112
113 static constexpr int Dim = 1;
114 typedef double Scalar;
115
117 FloatArray(int n = 0) : values(n) { }
119 FloatArray(double) = delete;
121 FloatArray(const FloatArray &src) : values(src.values) { }
123 FloatArray(FloatArray &&src) noexcept : values(std::move(src.values)) { }
125 FloatArray &operator = (const FloatArray &src) { values = src.values; return *this; }
127 FloatArray &operator = (FloatArray &&src) noexcept { values = std::move(src.values); return *this; }
128
129
130 inline const double *data() const { return values.data(); }
131 inline double *data() { return values.data(); }
137 inline double &operator() (Index i) { return this->operator[](i); }
138 inline double &operator[] (Index i)
139 {
140 #ifndef NDEBUG
141 checkBounds(i+1);
142 #endif
143 return values [ i ];
144 }
145
150 inline const double &operator() (Index i) const { return this->operator[](i); }
151 inline const double &operator[] (Index i) const {
152 #ifndef NDEBUG
153 checkBounds(i+1);
154 #endif
155 return values [ i ];
156 }
157
161 void resize(Index s);
162 Index size() const { return this->values.size(); }
163#endif
164 void _resize_internal(Index newsize);
166 FloatArray(std :: initializer_list< double >list) { (*this)=fromIniList(list); }
167 static FloatArray fromVector(const std::vector<double>& v);
168 static FloatArray fromList(const std::list<double>& l);
169 static FloatArray fromConcatenated(std::initializer_list<FloatArray> ini);
170 static FloatArray fromIniList(std::initializer_list<double> ini);
171 template< std::size_t N >
172 inline FloatArray( const FloatArrayF<N> &src ) {
173 #ifdef _USE_EIGEN
174 VectorXd::resize(src.size());
175 #else
176 values.resize(src.size());
177 #endif
178 for(Index i=0; i<src.size(); i++) (*this)[i]=src[i];
179 }
180
181 virtual ~FloatArray() {}
182
183
185 inline FloatArray &operator = (std :: initializer_list< double >list) { (*this)=fromIniList(list); return *this; }
187 template< std::size_t N >
188 inline FloatArray &operator = (const FloatArrayF<N> &src){
189 this->resize(src.size()); // FIXME: useless zeroing
190 for(Index i=0; i<src.size(); i++) (*this)[i]=src[i];
191 return *this;
192 }
193
195 bool isAllFinite() const;
196
202 inline double &at(Index i)
203 {
204#ifndef NDEBUG
205 this->checkBounds( i );
206#endif
207 return (*this)[ i - 1 ];
208 }
209
214 inline double at(Index i) const
215 {
216#ifndef NDEBUG
217 this->checkBounds( i );
218#endif
219 return (*this)[ i - 1 ];
220 }
221
228 void checkBounds(Index i) const
229 {
230 if ( i <= 0 ) {
231 OOFEM_ERROR("array error on index : %d <= 0", (int)i);
232 } else if ( i > size()) {
233 OOFEM_ERROR("array error on index : %d > %d", (int)i, (int)this->size());
234 }
235 }
236
241 void checkSizeTowards(const IntArray &loc);
249 void resizeWithValues(Index s, std::size_t allocChunk = 0);
254 void clear() { this->resize(0); }
258 bool containsOnlyZeroes() const;
260 //[[deprecated("use size() instead.")]]
261 Index giveSize() const { return this->size(); }
263 bool isNotEmpty() const { return size()>0; }
265 bool isEmpty() const { return size()==0; }
270 void negated();
274 virtual void printYourself() const;
279 virtual void printYourself(const std::string &name) const;
285 virtual void printYourselfToFile(const std::string filename, const bool showDimensions=true) const;
289 virtual void pY() const;
291 void zero();
296 void beProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray);
301 void beTProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray);
308 void beVectorProductOf(const FloatArray &v1, const FloatArray &v2);
314 void beScaled(double s, const FloatArray &b);
321 void add(const FloatArray &src);
330 void add(double factor, const FloatArray &b);
338 void plusProduct(const FloatMatrix &b, const FloatArray &s, double dV);
343 void add(double offset);
349 void subtract(const FloatArray &src);
354 void times(double s);
360 void beMaxOf(const FloatArray &a, const FloatArray &b);
366 void beMinOf(const FloatArray &a, const FloatArray &b);
372 void beDifferenceOf(const FloatArray &a, const FloatArray &b);
379 void beDifferenceOf(const FloatArray &a, const FloatArray &b, Index n);
386 void beSubArrayOf(const FloatArray &src, const IntArray &indx);
394 void addSubVector(const FloatArray &src, Index si);
403 void assemble(const FloatArray &fe, const IntArray &loc);
409 void assembleSquared(const FloatArray &fe, const IntArray &loc);
417 void copySubVector(const FloatArray &src, int si);
422 double distance(const FloatArray &x) const;
424 double distance(const FloatArray *x) const { return this->distance(* x); }
425
432 double distance(const FloatArray &iP1, const FloatArray &iP2, double &oXi, double &oXiUnbounded) const;
433 double distance_square(const FloatArray &iP1, const FloatArray &iP2, double &oXi, double &oXiUnbounded) const;
434
439 double distance_square(const FloatArray &x) const;
440
443 int giveIndexMinElem(void);
444
447 int giveIndexMaxElem(void);
448
453 double dotProduct(const FloatArray &x) const;
454
460 double dotProduct(const FloatArray &x, Index size) const;
461
467 double normalize_giveNorm();
472 void normalize();
477 double computeNorm() const;
482 double computeSquaredNorm() const;
487 double sum() const;
492 double product() const;
493
501 void rotatedWith(FloatMatrix &r, char mode);
506 inline const double *givePointer() const { return data(); }
507 inline double *givePointer() { return data(); }
513 void beVectorForm(const FloatMatrix &aMatrix);
520 void beSymVectorForm(const FloatMatrix &aMatrix);
521 void beSymVectorFormOfStrain(const FloatMatrix &aMatrix);
522
527 void changeComponentOrder();
528
533 void power(const double exponent);
534
538 void beColumnOf(const FloatMatrix &mat, int col);
539
543 void beRowOf(const FloatMatrix &mat, Index row);
544
545 contextIOResultType storeYourself(DataStream &stream) const;
546 contextIOResultType restoreYourself(DataStream &stream);
547 int givePackSize(DataStream &buff) const;
548
549 friend std :: ostream &operator << ( std :: ostream & out, const FloatArray & x );
550
551 friend class FloatMatrix;
552
554
555
556 FloatArray &operator = ( const double & );
558};
559
560#ifndef _USE_EIGEN
562
563 OOFEM_EXPORT FloatArray &operator *= ( FloatArray & x, const double & a );
564 OOFEM_EXPORT FloatArray operator *( const double & a, const FloatArray & x );
565 OOFEM_EXPORT FloatArray operator *( const FloatArray & x, const double & a );
571#endif
572
573
575
576#ifndef _USE_EIGEN
578 OOFEM_EXPORT FloatArray &operator *= ( FloatArray & x, const double & a );
579 OOFEM_EXPORT FloatArray operator *( const double & a, const FloatArray & x );
580 OOFEM_EXPORT FloatArray operator *( const FloatArray & x, const double & a );
581 //
582 OOFEM_EXPORT FloatArray operator / ( const FloatArray & x, const double & a );
583 OOFEM_EXPORT FloatArray operator / ( const double & a, const FloatArray & x );
584 //
589 OOFEM_EXPORT FloatArray &operator /= ( FloatArray & x, const double & a );
590#endif
591
592
593OOFEM_EXPORT double norm(const FloatArray &x);
594OOFEM_EXPORT double norm_square(const FloatArray &x);
595OOFEM_EXPORT double dot(const FloatArray &x, const FloatArray &y);
596OOFEM_EXPORT double distance(const FloatArray &x, const FloatArray &y);
597OOFEM_EXPORT double distance_square(const FloatArray &x, const FloatArray &y);
598OOFEM_EXPORT bool isfinite(const FloatArray &x);
599OOFEM_EXPORT bool iszero(const FloatArray &x);
600OOFEM_EXPORT double sum(const FloatArray & x);
601OOFEM_EXPORT double product(const FloatArray & x);
603
604
605inline static FloatArray Vec1(const double& a){ return FloatArray::fromIniList({a}); }
606inline static FloatArray Vec2(const double& a, const double& b){ return FloatArray::fromIniList({a,b}); }
607inline static FloatArray Vec3(const double& a, const double& b, const double& c){ return FloatArray::fromIniList({a,b,c}); }
608inline static FloatArray Vec4(const double& a, const double& b, const double& c, const double& d){ return FloatArray::fromIniList({a,b,c,d}); }
609inline static FloatArray Vec5(const double& a, const double& b, const double& c, const double& d, const double& e){ return FloatArray::fromIniList({a,b,c,d,e}); }
610inline static FloatArray Vec6(const double& a, const double& b, const double& c, const double& d, const double& e, const double& f){ return FloatArray::fromIniList({a,b,c,d,e,f}); }
611inline static FloatArray Vec7(const double& a, const double& b, const double& c, const double& d, const double& e, const double& f, const double& g){ return FloatArray::fromIniList({a,b,c,d,e,f,g}); }
612inline static FloatArray Vec8(const double& a, const double& b, const double& c, const double& d, const double& e, const double& f, const double& g, const double& h){ return FloatArray::fromIniList({a,b,c,d,e,f,g,h}); }
613inline static FloatArray Vec9(const double& a, const double& b, const double& c, const double& d, const double& e, const double& f, const double& g, const double& h, const double& i){ return FloatArray::fromIniList({a,b,c,d,e,f,g,h,i}); }
614inline static FloatArray VecX(std::initializer_list<double> ini){ return FloatArray::fromIniList(ini); }
615
617} // end namespace oofem
618#endif // floatarray_h
int size() const
Returns the size of receiver.
Index size() const
Definition floatarray.h:162
static FloatArray fromIniList(std::initializer_list< double > ini)
Definition floatarray.C:138
FloatArray(FloatArray &&src) noexcept
Move constructor. Creates the array from another array.
Definition floatarray.h:123
void resize(Index s)
Definition floatarray.C:94
double & at(Index i)
Definition floatarray.h:202
std::vector< double > values
Stored values.
Definition floatarray.h:102
std::vector< double >::const_iterator end() const
Definition floatarray.h:110
std::vector< double >::iterator begin()
Definition floatarray.h:107
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
std::vector< double >::const_iterator begin() const
Definition floatarray.h:109
double * data()
Definition floatarray.h:131
double & operator[](Index i)
Definition floatarray.h:138
static constexpr int Dim
Definition floatarray.h:113
FloatArray(const FloatArray &src)
Copy constructor. Creates the array from another array.
Definition floatarray.h:121
double at(Index i) const
Definition floatarray.h:214
double * givePointer()
Definition floatarray.h:507
virtual ~FloatArray()
Destructor.
Definition floatarray.h:181
const double * data() const
Definition floatarray.h:130
void checkBounds(Index i) const
Definition floatarray.h:228
FloatArray(std ::initializer_list< double >list)
Initializer list constructor.
Definition floatarray.h:166
FloatArray(double)=delete
Disallow double parameter, which can otherwise give unexpected results.
bool isEmpty() const
Returns true if receiver is empty.
Definition floatarray.h:265
friend class FloatMatrix
Definition floatarray.h:551
FloatArray(const FloatArrayF< N > &src)
Definition floatarray.h:172
const double * givePointer() const
Definition floatarray.h:506
std::vector< double >::iterator end()
Definition floatarray.h:108
double distance(const FloatArray *x) const
Definition floatarray.h:424
FloatArray(int n=0)
Constructor for sized array. Data is zeroed.
Definition floatarray.h:117
bool isNotEmpty() const
Returns true if receiver is not empty.
Definition floatarray.h:263
#define OOFEM_ERROR(...)
Definition error.h:79
static FloatArray Vec2(const double &a, const double &b)
Definition floatarray.h:606
FloatArray operator+(const FloatArray &x, const FloatArray &y)
Definition floatarray.C:978
double norm(const FloatArray &x)
OOFEM_EXPORT FloatArray operator/(const FloatArray &x, const double &a)
static FloatArray VecX(std::initializer_list< double > ini)
Definition floatarray.h:614
static FloatArray Vec9(const double &a, const double &b, const double &c, const double &d, const double &e, const double &f, const double &g, const double &h, const double &i)
Definition floatarray.h:613
double norm_square(const FloatArray &x)
bool iszero(const FloatArray &x)
FloatArray operator-(const FloatArray &x, const FloatArray &y)
Definition floatarray.C:985
FloatArrayF< N > assemble(const FloatArrayF< M > &x, int const (&c)[M])
Assemble components into zero matrix.
static FloatArray Vec6(const double &a, const double &b, const double &c, const double &d, const double &e, const double &f)
Definition floatarray.h:610
FloatArray & operator/=(FloatArray &x, const double &a)
FloatArray & operator+=(FloatArray &x, const FloatArray &y)
Definition floatarray.C:992
int Index
Definition numerics.h:73
static FloatArray Vec5(const double &a, const double &b, const double &c, const double &d, const double &e)
Definition floatarray.h:609
double sum(const FloatArray &x)
static FloatArray Vec8(const double &a, const double &b, const double &c, const double &d, const double &e, const double &f, const double &g, const double &h)
Definition floatarray.h:612
double dot(const FloatArray &x, const FloatArray &y)
bool isfinite(const FloatArray &x)
FloatMatrixF< N, M > zero()
Constructs a zero matrix (this is the default behavior when constructing a matrix,...
FloatArray & operator-=(FloatArray &x, const FloatArray &y)
Definition floatarray.C:998
double product(const FloatArray &x)
FloatArray operator*(const double &a, const FloatArray &x)
Definition floatarray.C:964
FloatArrayF< N > normalize(const FloatArrayF< N > &x)
Normalizes vector (L2 norm).
static FloatArray Vec4(const double &a, const double &b, const double &c, const double &d)
Definition floatarray.h:608
FloatArray & operator*=(FloatArray &x, const double &a)
Vector multiplication by scalar.
Definition floatarray.C:958
static FloatArray Vec7(const double &a, const double &b, const double &c, const double &d, const double &e, const double &f, const double &g)
Definition floatarray.h:611
double distance(const FloatArray &x, const FloatArray &y)
double distance_square(const FloatArray &x, const FloatArray &y)
static FloatArray Vec1(const double &a)
Definition floatarray.h:605
static FloatArray Vec3(const double &a, const double &b, const double &c)
Definition floatarray.h:607
#define OOFEM_EXPORT
Definition oofemcfg.h:7

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