OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 - 2013 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 "oofemcfg.h"
39 #include "contextioresulttype.h"
40 #include "contextmode.h"
41 
42 #include <initializer_list>
43 #include <vector>
44 #include <iosfwd>
45 
46 namespace oofem {
47 class IntArray;
48 class FloatMatrix;
49 class DataStream;
50 
82 class OOFEM_EXPORT FloatArray
83 {
84 protected:
86  std::vector< double > values;
87 
88 public:
90 
91  std::vector< double > :: iterator begin() { return this->values.begin(); }
92  std::vector< double > :: iterator end() { return this->values.end(); }
93  std::vector< double > :: const_iterator begin() const { return this->values.begin(); }
94  std::vector< double > :: const_iterator end() const { return this->values.end(); }
96 
98  FloatArray(int n = 0) : values(n) { }
100  FloatArray(double) = delete;
102  FloatArray(const FloatArray &src) : values(src.values) { }
104  FloatArray(FloatArray &&src) : values(std::move(src.values)) { }
106  inline FloatArray(std :: initializer_list< double >list) : values(list) { }
108  virtual ~FloatArray() {};
109 
111  FloatArray &operator = (const FloatArray &src) { values = src.values; return *this; }
113  FloatArray &operator = (FloatArray &&src) { values = std::move(src.values); return *this; }
115  inline FloatArray &operator = (std :: initializer_list< double >list) { values = list; return *this; }
116 
118  void push_back(const double &iVal) {values.push_back(iVal);}
119 
121  bool isFinite() const;
122 
128 #ifdef DEBUG
129  double &at(int i);
130 #else
131  inline double &at(int i) { return values [ i - 1 ]; }
132 #endif
133 
138 #ifdef DEBUG
139  double at(int i) const;
140 #else
141  inline double at(int i) const { return values [ i - 1 ]; }
142 #endif
143 
149 #ifdef DEBUG
150  double &operator() (int i);
151  double &operator[] (int i);
152 #else
153  inline double &operator() (int i) {
154  return values [ i ];
155  };
156  inline double &operator[] (int i) {
157  return values [ i ];
158  };
159 #endif
160 
165 #ifdef DEBUG
166  const double &operator() (int i) const;
167  const double &operator[] (int i) const;
168 #else
169  inline const double &operator() (int i) const { return values [ i ]; }
170  inline const double &operator[] (int i) const { return values [ i ]; }
171 #endif
172 
177  void checkBounds(int i) const;
183  void checkSizeTowards(const IntArray &loc);
188  void reserve(int s);
196  void resizeWithValues(int s, int allocChunk = 0);
201  void resize(int s);
206  void clear() { this->values.clear(); }
212  void hardResize(int s);
216  bool containsOnlyZeroes() const;
218  int giveSize() const { return (int)this->values.size(); }
220  bool isNotEmpty() const { return !this->values.empty(); }
222  bool isEmpty() const { return this->values.empty(); }
227  void negated();
231  virtual void printYourself() const;
236  virtual void printYourself(const std::string &name) const;
242  virtual void printYourselfToFile(const std::string filename, const bool showDimensions=true) const;
246  virtual void pY() const;
248  void zero();
253  void append(const FloatArray &a);
258  void append(double a);
263  void beProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray);
268  void beTProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray);
275  void beVectorProductOf(const FloatArray &v1, const FloatArray &v2);
281  void beScaled(double s, const FloatArray &b);
288  void add(const FloatArray &src);
297  void add(double factor, const FloatArray &b);
305  void plusProduct(const FloatMatrix &b, const FloatArray &s, double dV);
310  void add(double offset);
316  void subtract(const FloatArray &src);
321  void times(double s);
327  void beMaxOf(const FloatArray &a, const FloatArray &b);
333  void beMinOf(const FloatArray &a, const FloatArray &b);
339  void beDifferenceOf(const FloatArray &a, const FloatArray &b);
346  void beDifferenceOf(const FloatArray &a, const FloatArray &b, int n);
353  void beSubArrayOf(const FloatArray &src, const IntArray &indx);
361  void addSubVector(const FloatArray &src, int si);
370  void assemble(const FloatArray &fe, const IntArray &loc);
376  void assembleSquared(const FloatArray &fe, const IntArray &loc);
384  void copySubVector(const FloatArray &src, int si);
389  double distance(const FloatArray &x) const;
391  double distance(const FloatArray *x) const { return this->distance(* x); }
392 
399  double distance(const FloatArray &iP1, const FloatArray &iP2, double &oXi, double &oXiUnbounded) const;
400  double distance_square(const FloatArray &iP1, const FloatArray &iP2, double &oXi, double &oXiUnbounded) const;
401 
406  double distance_square(const FloatArray &x) const;
407 
410  int giveIndexMinElem(void);
411 
414  int giveIndexMaxElem(void);
415 
420  double dotProduct(const FloatArray &x) const;
421 
427  double dotProduct(const FloatArray &x, int size) const;
428 
434  double normalize();
439  double computeNorm() const;
440 
445  double computeSquaredNorm() const;
450  double sum() const;
455  double product() const;
456 
464  void rotatedWith(FloatMatrix &r, char mode);
469  inline const double *givePointer() const { return values.data(); }
470  inline double *givePointer() { return values.data(); }
476  void beVectorForm(const FloatMatrix &aMatrix);
483  void beSymVectorForm(const FloatMatrix &aMatrix);
484  void beSymVectorFormOfStrain(const FloatMatrix &aMatrix);
485 
490  void changeComponentOrder();
491 
496  void power(const double exponent);
497 
501  void beColumnOf(const FloatMatrix &mat, int col);
502 
503  contextIOResultType storeYourself(DataStream &stream) const;
504  contextIOResultType restoreYourself(DataStream &stream);
505  int givePackSize(DataStream &buff) const;
506 
507  friend std :: ostream &operator << ( std :: ostream & out, const FloatArray & x );
508 
509  friend class FloatMatrix;
510 
512 
513  FloatArray &operator = ( const double & );
516 
517 #ifdef BOOST_PYTHON
518  void __setitem__(int i, double val) { this->values[i] = val; }
519  double __getitem__(int i) { return this->values[i]; }
520  void beCopyOf(const FloatArray &src) { this->operator = ( src ); }
521 #endif
522 };
523 
524 const FloatArray ZeroVector = {0.0,0.0,0.0};
525 
527 
528 FloatArray &operator *= ( FloatArray & x, const double & a );
530 FloatArray operator *( const double & a, const FloatArray & x );
531 FloatArray operator *( const FloatArray & x, const double & a );
532 FloatArray operator + ( const FloatArray & x, const FloatArray & y );
533 FloatArray operator - ( const FloatArray & x, const FloatArray & y );
534 FloatArray &operator += ( FloatArray & x, const FloatArray & y );
535 FloatArray &operator -= ( FloatArray & x, const FloatArray & y );
536 
537 double norm(const FloatArray &x);
538 double dot(const FloatArray &x, const FloatArray &y);
540 } // end namespace oofem
541 #endif // floatarray_h
double distance(const FloatArray *x) const
Definition: floatarray.h:391
std::vector< double > values
Stored values.
Definition: floatarray.h:86
FloatArray & operator*=(FloatArray &x, const double &a)
Vector multiplication by scalar.
Definition: floatarray.C:934
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
void clear()
Clears receiver (zero size).
Definition: floatarray.h:206
FloatArray(int n=0)
Constructor for sized array. Data is zeroed.
Definition: floatarray.h:98
FloatArray & operator-=(FloatArray &x, const FloatArray &y)
Definition: floatarray.C:974
double at(int i) const
Coefficient access function.
Definition: floatarray.h:141
Class implementing an array of integers.
Definition: intarray.h:61
std::vector< double >::const_iterator begin() const
Definition: floatarray.h:93
FloatArray(const FloatArray &src)
Copy constructor. Creates the array from another array.
Definition: floatarray.h:102
FloatArray(std::initializer_list< double >list)
Initializer list constructor.
Definition: floatarray.h:106
std::vector< double >::const_iterator end() const
Definition: floatarray.h:94
std::ostream & operator<<(std::ostream &out, const Dictionary &r)
Definition: dictionary.C:253
FloatArray(FloatArray &&src)
Move constructor. Creates the array from another array.
Definition: floatarray.h:104
bool isEmpty() const
Returns true if receiver is empty.
Definition: floatarray.h:222
Class representing vector of real numbers.
Definition: floatarray.h:82
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
double norm(const FloatArray &x)
Definition: floatarray.C:985
virtual ~FloatArray()
Destructor.
Definition: floatarray.h:108
const FloatArray ZeroVector
Definition: floatarray.h:524
const double * givePointer() const
Gives the pointer to the raw data, breaking encapsulation.
Definition: floatarray.h:469
std::vector< double >::iterator end()
Definition: floatarray.h:92
FloatArray operator*(const double &a, const FloatArray &x)
Definition: floatarray.C:940
FloatArray operator-(const FloatArray &x, const FloatArray &y)
Definition: floatarray.C:961
double * givePointer()
Definition: floatarray.h:470
void push_back(const double &iVal)
Add one element.
Definition: floatarray.h:118
FloatArray & operator+=(FloatArray &x, const FloatArray &y)
Definition: floatarray.C:968
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.
bool isNotEmpty() const
Returns true if receiver is not empty.
Definition: floatarray.h:220
FloatArray operator+(const FloatArray &x, const FloatArray &y)
Definition: floatarray.C:954
double dot(const FloatArray &x, const FloatArray &y)
Definition: floatarray.C:980
std::vector< double >::iterator begin()
Definition: floatarray.h:91

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