1 /*
2  *_________________________________________________________________________*
3  *      POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE     *
4  *      DESCRIPTION: SEE READ-ME                                           *
5  *      FILE NAME: vect4.cpp                                               *
6  *      AUTHORS: See Author List                                           *
7  *      GRANTS: See Grants List                                            *
8  *      COPYRIGHT: (C) 2005 by Authors as listed in Author's List          *
9  *      LICENSE: Please see License Agreement                              *
10  *      DOWNLOAD: Free at www.rpi.edu/~anderk5                             *
11  *      ADMINISTRATOR: Prof. Kurt Anderson                                 *
12  *                     Computational Dynamics Lab                          *
13  *                     Rensselaer Polytechnic Institute                    *
14  *                     110 8th St. Troy NY 12180                           *
15  *      CONTACT:        anderk5@rpi.edu                                    *
16  *_________________________________________________________________________*/
17 
18 #include "vect4.h"
19 #include <cstdlib>
20 
21 using namespace std;
22 
Vect4()23 Vect4::Vect4(){
24   numrows = 4; numcols = 1;
25 }
~Vect4()26 Vect4::~Vect4(){
27 }
28 
Vect4(const Vect4 & A)29 Vect4::Vect4(const Vect4& A){  // copy constructor
30   numrows = 4; numcols = 1;
31 
32   elements[0] = A.elements[0];
33   elements[1] = A.elements[1];
34   elements[2] = A.elements[2];
35   elements[3] = A.elements[3];
36 }
37 
Vect4(const VirtualMatrix & A)38 Vect4::Vect4(const VirtualMatrix& A){  // copy constructor
39   numrows = 4; numcols = 1;
40 
41   // error check
42   if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){
43     cerr << "illegal matrix size" << endl;
44     exit(0);
45   }
46 
47   for(int i=0;i<4;i++)
48     elements[i] = A.BasicGet(i,0);
49 }
50 
operator_1int(int i)51 double& Vect4::operator_1int (int i){ // array access
52   return elements[i-1];
53 }
54 
Get_1int(int i) const55 double Vect4::Get_1int(int i) const{
56   return elements[i-1];
57 }
58 
Set_1int(int i,double value)59 void Vect4::Set_1int(int i, double value){
60   elements[i-1] = value;
61 }
62 
BasicGet_1int(int i) const63 double Vect4::BasicGet_1int(int i) const{
64   return elements[i];
65 }
66 
BasicSet_1int(int i,double value)67 void Vect4::BasicSet_1int(int i, double value){
68   elements[i] = value;
69 }
70 
BasicIncrement_1int(int i,double value)71 void Vect4::BasicIncrement_1int(int i, double value){
72   elements[i] += value;
73 }
74 
Const(double value)75 void Vect4::Const(double value){
76   elements[0] = value;
77   elements[1] = value;
78   elements[2] = value;
79   elements[3] = value;
80 }
81 
GetType() const82 MatrixType Vect4::GetType() const{
83   return VECT4;
84 }
85 
ReadData(istream & c)86 istream& Vect4::ReadData(istream& c){  //input
87   for(int i=0;i<4;i++)
88     c >> elements[i];
89   return c;
90 }
91 
WriteData(ostream & c) const92 ostream& Vect4::WriteData(ostream& c) const{  //output
93   for(int i=0;i<4;i++)
94     c << elements[i] << ' ';
95   return c;
96 }
97 
AssignVM(const VirtualMatrix & A)98 void Vect4::AssignVM(const VirtualMatrix& A){
99   // error check
100   if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){
101     cerr << "illegal matrix size" << endl;
102     exit(0);
103   }
104 
105   for(int i=0;i<numrows;i++)
106     elements[i] = A.BasicGet(i,0);
107 }
108 
operator =(const Vect4 & A)109 Vect4& Vect4::operator=(const Vect4& A){ // assignment operator
110   elements[0] = A.elements[0];
111   elements[1] = A.elements[1];
112   elements[2] = A.elements[2];
113   elements[3] = A.elements[3];
114   return *this;
115 }
116 
operator =(const VirtualMatrix & A)117 Vect4& Vect4::operator=(const VirtualMatrix& A){ // overloaded =
118   // error check
119   if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){
120     cerr << "illegal matrix size" << endl;
121     exit(0);
122   }
123 
124   for(int i=0;i<numrows;i++)
125     elements[i] = A.BasicGet(i,0);
126   return *this;
127 }
128 
operator *=(double b)129 Vect4& Vect4::operator*=(double b){
130   elements[0] *= b;
131   elements[1] *= b;
132   elements[2] *= b;
133   elements[3] *= b;
134   return *this;
135 }
136 
137