Carmen Code
 All Classes Files Functions Variables Macros Pages
Vector.h
Go to the documentation of this file.
1 /***************************************************************************
2  Vector.h - description
3  -------------------
4  begin : Thu Jun 7 2001
5  copyright : (C) 2001 by Olivier Roussel & Alexei Tsigulin
6  email : roussel@ict.uni-karlsruhe.de, lpsoft@mail.ru
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
29 class Vector
30 {
31 
32 /*
33 ______________________________________________________________________________________________
34 
35  Constructor and distructor
36 ______________________________________________________________________________________________
37 
38 */
39 
40 
41 public:
52  Vector();
53 
65 Vector(const int n);
66 
79 Vector(const real x, const real y);
80 
94 Vector(const real x, const real y, const real z);
95 
108 Vector(const Vector& V);
109 
114 ~Vector();
115 /*
116 ______________________________________________________________________________________________
117 
118  Set and get
119 ______________________________________________________________________________________________
120 
121 */
122 
123 
141 inline void setValue(const int n, const real a);
142 
148 void setZero();
149 
164 void setDimension(const int n);
165 
183 inline real value(const int n) const;
184 
190 inline int dimension() const;
191 
192 
193 /*
194 ______________________________________________________________________________________________
195 
196  Operators
197 ______________________________________________________________________________________________
198 
199 */
200 
218 bool operator== (const Vector& V ) const;
219 
235 void operator= (const Vector& V );
236 
252 void operator+=(const Vector& V );
253 
270 Vector operator+ (const Vector& V ) const;
271 
287 void operator-=(const Vector& V );
288 
305 Vector operator- (const Vector& V ) const;
306 
321 Vector operator- () const;
322 
338 void operator*=(const real a );
339 
358 Vector operator* (const real a ) const;
359 
375 void operator/=(const real a );
376 
393 Vector operator/ (const real a ) const;
394 
411 real operator* (const Vector& V ) const;
412 
419 Vector operator| (const Vector& V) const;
420 
427 Vector operator^ (const Vector& V) const;
428 
434 bool isNaN() const;
435 
436 /*
437 ______________________________________________________________________________________________
438 
439 PRIVATE VARIABLES
440 ______________________________________________________________________________________________
441 
442 */
443 //parallel modification
444 //private:
445 public:
446  int Columns;
447  /* real *U; // Components */
448  real U[9];
449 };
450 /*
451 ______________________________________________________________________________________________
452 
453 EXTERNAL FUNCTIONS
454 ______________________________________________________________________________________________
455 
456 */
457 
477 Vector operator* (const real a, const Vector& V);
478 
485 Vector abs (const Vector& V);
486 
493 int dim (const Vector& V);
494 
501 real N1(const Vector& V);
502 
509 real N2(const Vector& V);
510 
517 real NMax(const Vector& V);
518 
526 ostream& operator<<(ostream& out, const Vector& V);
527 
528 /*
529 ______________________________________________________________________________________________
530 
531 INLINE FUNCTIONS
532 ______________________________________________________________________________________________
533 
534 */
535 inline int Vector::dimension() const
536 {
537  return Columns;
538 }
539 
540 /*
541 ______________________________________________________________________________________________
542 
543 */
544 
545 inline void Vector::setValue(const int n, const real a)
546 {
547 
548 #ifdef DEBUG
549  if ( n <= 0 || n > Columns)
550  {
551  cout << "Vector.cpp: In method `void Vector::setValue(int, real)':\n";
552  cout << "Vector.cpp: first argument out of range\n";
553  cout << "carmen: *** [Vector.o] Execution error\n";
554  cout << "carmen: abort execution.\n";
555  exit(1);
556  }
557 #endif
558 
559  *(U+n-1) = a;
560 }
561 /*
562 ______________________________________________________________________________________________
563 
564 */
565 inline real Vector::value(const int n) const
566 {
567 
568 #ifdef DEBUG
569 
570  if ( n <= 0 || n > Columns)
571  {
572  cout << "Vector.cpp: In method `void Vector::value(int)':\n";
573  cout << "Vector.cpp: argument out of range\n";
574  cout << "carmen: *** [Vector.o] Execution error\n";
575  cout << "carmen: abort execution.\n";
576  exit(1);
577  }
578 #endif
579 
580  return *(U+n-1);
581 }
582 
Vector operator^(const Vector &V) const
Returns the vectorial product of the current vector and V.
Definition: Vector.cpp:1401
Vector abs(const Vector &V)
Returns the absolute value term by term of the vector.
Definition: Vector.cpp:1484
Vector operator+(const Vector &V) const
Returns the addition of the current vector and V.
Definition: Vector.cpp:624
bool operator==(const Vector &V) const
Compares the current vector to a vector V and returns true if they are equal.
Definition: Vector.cpp:373
Vector operator*(const real a, const Vector &V)
Returns the product of the current vector and a real a.
Definition: Vector.cpp:1462
void operator/=(const real a)
Divides the current vector by a real a.
Definition: Vector.cpp:1108
Vector operator|(const Vector &V) const
Returns the term-by-term product of the current vector and V.
Definition: Vector.cpp:1370
void operator-=(const Vector &V)
Subtracts V to the current vector.
Definition: Vector.cpp:714
void operator*=(const real a)
Multiplies the current vector by a real a.
Definition: Vector.cpp:961
Standard class for every vector in Carmen.
Definition: Vector.h:29
Vector()
Generates a 1D vector equal to zero.
Definition: Vector.cpp:36
int dim(const Vector &V)
Returns the dimension of the vector. Similar to int Vector::dimension().
Definition: Vector.cpp:1473
real NMax(const Vector &V)
Returns the Max-norm of the vector.
Definition: Vector.cpp:1543
Vector operator-() const
Returns the opposite of the current vector.
Definition: Vector.cpp:884
real N2(const Vector &V)
Returns the L2-norm of the vector.
Definition: Vector.cpp:1525
ostream & operator<<(ostream &out, const Vector &V)
Writes the components of the vector V on screen.
Definition: Vector.cpp:1562
Vector operator*(const real a) const
Returns the product of the current vector and a real a.
Definition: Vector.cpp:1031
real U[9]
Definition: Vector.h:448
void setValue(const int n, const real a)
Sets the component n to value a.
Definition: Vector.h:545
~Vector()
Destructor of Vector Class.
Definition: Vector.cpp:216
int dimension() const
Returns the dimension of the vector.
Definition: Vector.h:535
Vector operator/(const real a) const
Returns the division of the current vector by a real a.
Definition: Vector.cpp:1191
void operator+=(const Vector &V)
Adds V to the current vector.
Definition: Vector.cpp:541
real N1(const Vector &V)
Returns the L1-norm of the vector.
Definition: Vector.cpp:1507
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565
bool isNaN() const
Returns true if one of the components of the current vector is not a number.
Definition: Vector.cpp:1437
int Columns
Definition: Vector.h:446
void setZero()
Sets all the components to zero.
Definition: Vector.cpp:228
#define real
Definition: PreProcessor.h:31
void setDimension(const int n)
Sets the dimension of the vector to n and reset values to zero.
Definition: Vector.cpp:298
void operator=(const Vector &V)
Set the current vector to the dimension and the value of V.
Definition: Vector.cpp:461