1 /*
2  *_________________________________________________________________________*
3  *      POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE     *
4  *      DESCRIPTION: SEE READ-ME                                           *
5  *      FILE NAME: virtualmatrix.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 
19 #include "virtualmatrix.h"
20 #include "matrixfun.h"
21 #include <cstdlib>
22 
23 using namespace std;
24 
VirtualMatrix()25 VirtualMatrix::VirtualMatrix(){
26   numrows = numcols = 0;
27 }
28 
~VirtualMatrix()29 VirtualMatrix::~VirtualMatrix(){
30 }
31 
GetNumRows() const32 int VirtualMatrix::GetNumRows() const {
33   return numrows;
34 }
35 
GetNumCols() const36 int VirtualMatrix::GetNumCols() const {
37   return numcols;
38 }
39 
operator ()(int i,int j)40 double& VirtualMatrix::operator() (int i, int j){ // array access
41 	return operator_2int(i,j);
42 }
43 
Get(int i,int j) const44 double VirtualMatrix::Get(int i, int j) const{
45 	return Get_2int(i,j);
46 }
47 
Set(int i,int j,double value)48 void VirtualMatrix::Set(int i, int j, double value){
49 	Set_2int(i,j,value);
50 }
51 
BasicGet(int i,int j) const52 double VirtualMatrix::BasicGet(int i, int j) const{
53 	return BasicGet_2int(i,j);
54 }
55 
BasicSet(int i,int j,double value)56 void VirtualMatrix::BasicSet(int i, int j, double value){
57 	BasicSet_2int(i,j,value);
58 }
59 
BasicIncrement(int i,int j,double value)60 void VirtualMatrix::BasicIncrement(int i, int j, double value){
61 	BasicIncrement_2int(i,j,value);
62 }
63 
operator ()(int i)64 double& VirtualMatrix::operator() (int i){
65 	return operator_1int(i);
66 }
67 
Get(int i) const68 double VirtualMatrix::Get(int i) const{
69 	return Get_1int(i);
70 }
71 
Set(int i,double value)72 void VirtualMatrix::Set(int i, double value){
73 	Set_1int(i, value);
74 }
75 
BasicGet(int i) const76 double VirtualMatrix::BasicGet(int i) const{
77 	return BasicGet_1int(i);
78 }
79 
BasicSet(int i,double value)80 void VirtualMatrix::BasicSet(int i, double value){
81 	BasicSet_1int(i, value);
82 }
83 
BasicIncrement(int i,double value)84 void VirtualMatrix::BasicIncrement(int i, double value){
85 	BasicIncrement_1int(i, value);
86 }
87 
operator_1int(int i)88 double& VirtualMatrix::operator_1int (int i) {
89 	cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
90 	exit(0);
91 	return *(new double);
92 }
93 
Get_1int(int i) const94 double VirtualMatrix::Get_1int(int i) const {
95 	cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
96 	exit(0);
97 	return 0.0;
98 }
99 
Set_1int(int i,double value)100 void VirtualMatrix::Set_1int(int i, double value){
101 	cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
102 	exit(0);
103 }
104 
BasicGet_1int(int i) const105 double VirtualMatrix::BasicGet_1int(int i) const {
106 	cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
107 	exit(0);
108 	return 0.0;
109 }
110 
BasicSet_1int(int i,double value)111 void VirtualMatrix::BasicSet_1int(int i, double value) {
112 	cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
113 	exit(0);
114 }
115 
BasicIncrement_1int(int i,double value)116 void VirtualMatrix::BasicIncrement_1int(int i, double value){
117 	cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
118 	exit(0);
119 }
120 
Zeros()121 void VirtualMatrix::Zeros(){
122   Const(0.0);
123 }
124 
Ones()125 void VirtualMatrix::Ones(){
126   Const(1.0);
127 }
128 
WriteData(ostream & c) const129 ostream& VirtualMatrix::WriteData(ostream& c) const {
130   cerr << "Error: no output definition for matrices of type " << GetType() << endl;
131   exit(0);
132 }
133 
ReadData(istream & c)134 istream& VirtualMatrix::ReadData(istream& c){
135 	cerr << "Error: no input definition for matrices of type " << GetType() << endl;
136 	exit(0);
137 }
138 
139 //
140 // operators and functions
141 //
142 
operator <<(ostream & c,const VirtualMatrix & A)143 ostream& operator<< (ostream& c, const VirtualMatrix& A){  //output
144   c << A.GetType() << ' ';
145   A.WriteData(c);
146   c << endl;
147   return c;
148 }
149 
operator >>(istream & c,VirtualMatrix & A)150 istream& operator>> (istream& c, VirtualMatrix& A){  //input
151   VirtualMatrix* vm;
152   int matrixtype;
153   c >> matrixtype;
154 
155   if( MatrixType(matrixtype) == A.GetType() ) A.ReadData(c);
156   else{
157     // issue a warning?
158     cerr << "Warning: During matrix read expected type " << A.GetType() << " and got type " << matrixtype << endl;
159     vm = NewMatrix(matrixtype);
160     if(!vm){
161       cerr << "Error: unable to instantiate matrix of type " << matrixtype << endl;
162       exit(0);
163     }
164     vm->ReadData(c);
165     A.AssignVM(*vm);
166     delete vm;
167   }
168 
169   return c;
170 }
171 
172