1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/*
*_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME *
* FILE NAME: virtualmatrix.cpp *
* AUTHORS: See Author List *
* GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab *
* Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/
#include "virtualmatrix.h"
#include "matrixfun.h"
#include <cstdlib>
using namespace std;
VirtualMatrix::VirtualMatrix(){
numrows = numcols = 0;
}
VirtualMatrix::~VirtualMatrix(){
}
int VirtualMatrix::GetNumRows() const {
return numrows;
}
int VirtualMatrix::GetNumCols() const {
return numcols;
}
double& VirtualMatrix::operator() (int i, int j){ // array access
return operator_2int(i,j);
}
double VirtualMatrix::Get(int i, int j) const{
return Get_2int(i,j);
}
void VirtualMatrix::Set(int i, int j, double value){
Set_2int(i,j,value);
}
double VirtualMatrix::BasicGet(int i, int j) const{
return BasicGet_2int(i,j);
}
void VirtualMatrix::BasicSet(int i, int j, double value){
BasicSet_2int(i,j,value);
}
void VirtualMatrix::BasicIncrement(int i, int j, double value){
BasicIncrement_2int(i,j,value);
}
double& VirtualMatrix::operator() (int i){
return operator_1int(i);
}
double VirtualMatrix::Get(int i) const{
return Get_1int(i);
}
void VirtualMatrix::Set(int i, double value){
Set_1int(i, value);
}
double VirtualMatrix::BasicGet(int i) const{
return BasicGet_1int(i);
}
void VirtualMatrix::BasicSet(int i, double value){
BasicSet_1int(i, value);
}
void VirtualMatrix::BasicIncrement(int i, double value){
BasicIncrement_1int(i, value);
}
double& VirtualMatrix::operator_1int (int i) {
cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
exit(0);
return *(new double);
}
double VirtualMatrix::Get_1int(int i) const {
cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
exit(0);
return 0.0;
}
void VirtualMatrix::Set_1int(int i, double value){
cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
exit(0);
}
double VirtualMatrix::BasicGet_1int(int i) const {
cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
exit(0);
return 0.0;
}
void VirtualMatrix::BasicSet_1int(int i, double value) {
cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
exit(0);
}
void VirtualMatrix::BasicIncrement_1int(int i, double value){
cerr << "Error: single dimensional access is not defined for matrices of type " << GetType() << endl;
exit(0);
}
void VirtualMatrix::Zeros(){
Const(0.0);
}
void VirtualMatrix::Ones(){
Const(1.0);
}
ostream& VirtualMatrix::WriteData(ostream& c) const {
cerr << "Error: no output definition for matrices of type " << GetType() << endl;
exit(0);
}
istream& VirtualMatrix::ReadData(istream& c){
cerr << "Error: no input definition for matrices of type " << GetType() << endl;
exit(0);
}
//
// operators and functions
//
ostream& operator<< (ostream& c, const VirtualMatrix& A){ //output
c << A.GetType() << ' ';
A.WriteData(c);
c << endl;
return c;
}
istream& operator>> (istream& c, VirtualMatrix& A){ //input
VirtualMatrix* vm;
int matrixtype;
c >> matrixtype;
if( MatrixType(matrixtype) == A.GetType() ) A.ReadData(c);
else{
// issue a warning?
cerr << "Warning: During matrix read expected type " << A.GetType() << " and got type " << matrixtype << endl;
vm = NewMatrix(matrixtype);
if(!vm){
cerr << "Error: unable to instantiate matrix of type " << matrixtype << endl;
exit(0);
}
vm->ReadData(c);
A.AssignVM(*vm);
delete vm;
}
return c;
}
|