BJvector.cppGo to the documentation of this file.00001 00002 // $Revision: 1.1 $ 00003 // $Date: 2001/08/23 16:45:47 $ 00004 // $Source: /usr/local/cvs/OpenSees/SRC/nDarray/BJvector.cpp,v $ 00005 00006 00007 //############################################################################ 00008 //# # 00009 //# /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/~~\ # 00010 //# | |____| # 00011 //# | | # 00012 //# | | # 00013 //# | B A S E | # 00014 //# | | # 00015 //# | | # 00016 //# | C L A S S E S | # 00017 //# | | # 00018 //# | | # 00019 //# | C + + S O U R C E | # 00020 //# | | # 00021 //# | | # 00022 //# | | # 00023 //# | | # 00024 //# | | # 00025 //# /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/ | # 00026 //# | | | # 00027 //# \_________________________________________\__/ # 00028 //# # 00029 //# # 00030 //############################################################################ 00031 // 00032 // "C makes it easy to shoot yourself in the foot, C++ makes it harder, 00033 // but when you do, it blows away your whole leg" -- Bjarne Stroustrup 00034 // 00036 //################################################################################ 00037 //# COPY-YES (C): :-)) # 00038 //# PROJECT: Object Oriented Finite Element Program # 00039 //# PURPOSE: # 00040 //# CLASS: Vector class # 00041 //# # 00042 //# VERSION: # 00043 //# LANGUAGE: C++.ver >= 2.0 ( Borland C++ ver=3.00, SUN C++ ver=2.1 ) # 00044 //# TARGET OS: DOS || UNIX || . . . # 00045 //# DESIGNER(S): Boris Jeremic ( with help from ARKoenig in JOOP ) # 00046 //# PROGRAMMER(S): Boris Jeremic ( with help from ARKoenig in JOOP ) # 00047 //# # 00048 //# # 00049 //# DATE: Nov. 14. 1992. # 00050 //# UPDATE HISTORY: 05 - __ avgust '93. derived class from BJmatrix class # 00051 //# which is derived from # 00052 //# nDarray class # 00053 //# August 22-29 '94 choped to separate files and worked on # 00054 //# const and & issues # 00055 //# August 30-31 '94 added use_def_dim to full the CC # 00056 //# resolved problem with temoraries for # 00057 //# operators + and - ( +=, -= ) # 00058 //# # 00059 //# # 00060 //# # 00061 //# # 00062 //################################################################################ 00063 //*/ 00064 00065 // All of this inheritance idioms are after 00066 // Jim Coplien : "Advanced C++ programing styles and idioms". 00067 00068 #ifndef VECTOR_CC 00069 #define VECTOR_CC 00070 00071 // #include "basics.hh" 00072 // #include "ndarray.hh" 00073 #include "BJvector.h" 00074 00075 //############################################################################## 00076 BJvector::BJvector(int order_n, double initvalue): 00077 BJmatrix( 2, order_n, 1, initvalue) { } // default constructor 00078 // rank 2 ^ just to be consistent with rank of BJmatrix 00079 //############################################################################## 00080 BJvector::BJvector(int order_n, double *initval): 00081 BJmatrix(2, order_n, 1, initval) { } 00082 //rank 2 ^ just to be consistent with rank of BJmatrix 00083 00084 //############################################################################## 00085 BJvector::BJvector( const nDarray & x): 00086 BJmatrix( x ) { } // copy-initializer 00087 00088 00089 00090 //.... // IT IS NOT INHERITED so must be defined in all derived classes 00091 //.... // See ARM page 277. 00092 //.... //############################################################################## 00093 //.... BJvector::~BJvector() 00094 //.... { 00095 //.... if (reference_count(-1) == 0) // if reference count goes to 0 00096 //.... { 00097 //.... // DEallocate memory of the actual nDarray 00098 //.... // delete [pc_nDarray_rep->pc_nDarray_rep->total_numb] pc_nDarray_rep->pd_nDdata; 00099 //.... // nema potrebe za brojem clanova koji se brisu## see ELLIS & STROUSTRUP $18.3 00100 //.... // and note on the p.65($5.3.4) 00101 //.... // and the page 276 ($12.4) 00102 //.... delete [] data(); 00103 //.... delete [] dim(); 00104 //.... delete pc_nDarray_rep; 00105 //.... } 00106 //.... } 00107 00108 00109 00110 00111 //############################################################################# 00112 BJvector& BJvector::operator=( const BJvector & rval) 00113 { 00114 rval.pc_nDarray_rep->n++; // we're adding another reference. 00115 // rval.reference_count(+1); // tell the rval it has another reference 00116 // /* It is important to increment the reference_counter in the new 00117 // BJtensor before decrementing the reference_counter in the 00118 // old BJtensor_rep to ensure proper operation when assigning a 00119 // BJtensor_rep to itself ( after ARKoenig JOOP May/June '90 ) */ 00120 // clean up current value; 00121 if( reference_count(-1) == 0) // if nobody else is referencing us. 00122 { 00123 delete [] data(); 00124 delete [] dim(); 00125 delete pc_nDarray_rep; 00126 } 00127 // connect to new value 00128 pc_nDarray_rep = rval.pc_nDarray_rep; // point at the rval nDarray_rep 00129 return *this; 00130 } 00131 00132 //..//############################################################################# 00133 //..BJvector& BJvector::operator=( const BJmatrix & rval) 00134 //..{ 00135 //.. rval.pc_nDarray_rep->n++; // we're adding another reference. 00136 //..// rval.reference_count(+1); // tell the rval it has another reference 00137 //..// /* It is important to increment the reference_counter in the new 00138 //..// BJtensor before decrementing the reference_counter in the 00139 //..// old BJtensor_rep to ensure proper operation when assigning a 00140 //..// BJtensor_rep to itself ( after ARKoenig JOOP May/June '90 ) */ 00141 //.. 00142 //.. // clean up current value; 00143 //.. if( reference_count(-1) == 0) // if nobody else is referencing us. 00144 //.. { 00145 //.. delete [] data(); 00146 //.. delete [] dim(); 00147 //.. delete pc_nDarray_rep; 00148 //.. } 00149 //.. 00150 //..// set back rank to 1 for BJvector instead of 2 as in BJmatrix case 00151 //.. rval.pc_nDarray_rep->nDarray_rank = 1; 00152 //..// rval.rank(1); 00153 //..// connect to new value 00154 //.. pc_nDarray_rep = rval.pc_nDarray_rep; // point at the rval nDarray_rep 00155 //.. return *this; 00156 //..} 00157 //.. 00158 //..//############################################################################# 00159 //..BJvector& BJvector::operator=( const nDarray & rval) 00160 //..{ 00161 //.. rval.pc_nDarray_rep->n++; // we're adding another reference. 00162 //..// rval.reference_count(+1); // tell the rval it has another reference 00163 //..// /* It is important to increment the reference_counter in the new 00164 //..// BJtensor before decrementing the reference_counter in the 00165 //..// old BJtensor_rep to ensure proper operation when assigning a 00166 //..// BJtensor_rep to itself ( after ARKoenig JOOP May/June '90 ) */ 00167 //.. 00168 //.. // clean up current value; 00169 //.. if( reference_count(-1) == 0) // if nobody else is referencing us. 00170 //.. { 00171 //.. delete [] data(); 00172 //.. delete [] dim(); 00173 //.. delete pc_nDarray_rep; 00174 //.. } 00175 //.. 00176 //.. // connect to new value 00177 //.. pc_nDarray_rep = rval.pc_nDarray_rep; // point at the rval nDarray_rep 00178 //.. return *this; 00179 //..} 00180 //.. 00181 00182 //####### //############################################################################# 00183 //####### // I had to overload the operator* from BJmatrix class 00184 //####### // because in the case of BJvectors s*sT and so on 00185 //####### BJmatrix BJvector::operator*( BJvector & arg) 00186 //####### { 00187 //####### // if( cols() != arg.rows()) 00188 //####### // error("# rows of second mat must equal " 00189 //####### // "# cols of first for multiply#"); 00190 //####### BJmatrix result(rows(),arg.cols()); 00191 //####### for( int row=0 ; row<rows() ; row++ ) 00192 //####### for( int col=0 ; col<arg.cols() ; col++ ) 00193 //####### { 00194 //####### double sum = 0; 00195 //####### for( int i=0 ; i<cols() ; i++ ) 00196 //####### sum += mval(row,i)*arg.mval(i,col); 00197 //####### result.mval(row,col) = sum; 00198 //####### } 00199 //####### return result; // Returning a local variable? 00200 //####### // copy-initializer happens before the destructor, 00201 //####### // so reference count is 2 when destructor is called, 00202 //####### // thus destructor doesn't free the memory. 00203 //####### } 00204 //####### 00205 //....//############################################################################# 00206 //....BJvector BJvector::operator*( double arg) 00207 //.... { 00208 //.... BJvector result(rows()); 00209 //.... for ( int i=0 ; i<rows() ; i++ ) 00210 //.... result.val(i) = cval(i) * arg; 00211 //.... return result; 00212 //.... } 00213 00214 00215 00216 //############################################################################## 00217 // 00218 // CODE BOUND checking routine ( slower but safer ) 00219 // 00220 double BJvector::cval(int subscript, ... ) const 00221 { 00222 return (this->BJmatrix::cval(subscript,1)); 00223 } 00224 double & BJvector::val(int subscript, ... ) 00225 { 00226 return (this->BJmatrix::val(subscript,1)); 00227 } 00228 00229 #endif |