nDarray.hGo to the documentation of this file.00001 //############################################################################# 00002 // # 00003 // # 00004 // /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/~~\ # 00005 // | |____| # 00006 // | | # 00007 // | | # 00008 // | | # 00009 // | | # 00010 // | B A S E C L A S S E S | # 00011 // | | # 00012 // | | # 00013 // | | # 00014 // | | # 00015 // | C + + H E A D E R | # 00016 // | | # 00017 // | | # 00018 // | | # 00019 // | | # 00020 // /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/ | # 00021 // \_________________________________________\__/ # 00022 // # 00023 // # 00024 //############################################################################# 00025 //############################################################################# 00027 //################################################################################ 00028 //# COPYRIGHT (C): :-)) # 00029 //# PROJECT: Object Oriented Finite Element Program # 00030 //# PURPOSE: # 00031 //# CLASS: nDarray # 00032 //# # 00033 //# VERSION: # 00034 //# LANGUAGE: C++.ver >= 2.0 ( Borland C++ ver=3.10, SUN C++ ver=2.1 ) # 00035 //# TARGET OS: DOS || UNIX || . . . # 00036 //# DESIGNER(S): Boris Jeremic # 00037 //# PROGRAMMER(S): Boris Jeremic # 00038 //# # 00039 //# # 00040 //# DATE: May 28. - July 20 '93 # 00041 //# UPDATE HISTORY: july 8. '93. BJtensor02 - BJtensor multiplication # 00042 //# inner and outer products # 00043 //# December 23 1993 print from the base class, operator==, # 00044 //# macheps . . . # 00045 //# August 22-29 '94 choped to separate files and worked on # 00046 //# const and & issues # 00047 //# August 30-31 '94 added use_def_dim to full the CC # 00048 //# resolved problem with temoraries for # 00049 //# operators + and - ( +=, -= ) # 00050 //# January 16 '95 fixed the memory leakage introduced # 00051 //# by previous work on +=, -+. I was # 00052 //# by mistake decreasing # 00053 //# this->pc_nDarray_rep->total_numb--; # 00054 //# inststead of # 00055 //# this->pc_nDarray_rep->n--; # 00056 //# 28June2004 added val4 for efficiency still # 00057 //# to be worked on # 00058 //# # 00059 //# # 00060 //# # 00061 //# # 00062 //################################################################################ 00063 //*/ 00064 00065 #ifndef NDARRAY_HH 00066 #define NDARRAY_HH 00067 00068 #include "basics.h" 00069 00070 // forward reference 00071 class BJtensor; 00072 class BJmatrix; 00073 class BJvector; 00074 00075 //class stiffness_BJmatrix; 00076 00077 //class Material_Model; 00078 //class Elastic; 00079 //class Drucker_Prager; 00080 //class von_Mises; 00081 //class MRS_Lade_cone; 00082 //class Parabolic; 00083 // 00084 class stresstensor; 00085 class straintensor; 00086 00087 00088 00089 00090 class nDarray_rep 00091 { 00092 public: 00093 friend class nDarray; 00094 friend class BJtensor; 00095 friend class BJmatrix; 00096 // friend class skyBJmatrix; 00097 friend class stiffness_matrix; 00098 friend class BJvector; 00099 friend class stresstensor; 00100 friend class straintensor; 00101 00102 friend class Cosseratstresstensor; 00103 friend class Cosseratstraintensor; 00104 00105 private: 00106 double *pd_nDdata; // nD array as 1D array 00107 int nDarray_rank; 00108 // 0 -> scalar 00109 // 1 -> BJvector 00110 // 2 -> BJmatrix 00111 // * -> ******** */ 00112 long int total_numb; // total number of elements in nDarray 00113 int *dim; // array of dimensions in each rank direction 00114 // for example, if nDarray_rank = 3 : 00115 // dim[0] = dimension in direction 1 00116 // dim[1] = dimension in direction 2 00117 // dim[2] = dimension in direction 3 */ 00118 int n; // reference count 00119 public: 00120 // overloading operator new and delete in nDarray_rep class ######## 00121 void * operator new(size_t s); // see C++ reference manual by 00122 void operator delete(void *); // by ELLIS and STROUSTRUP page 283. 00123 // and ECKEL page 529. 00124 }; 00125 00126 00127 class nDarray 00128 { 00129 // public: 00130 private: 00131 friend class BJtensor; 00132 friend class BJmatrix; 00133 friend class BJvector; 00134 friend class stiffness_matrix; 00135 00136 friend class stresstensor; 00137 friend class straintensor; 00138 00139 friend class Cosseratstresstensor; 00140 friend class Cosseratstraintensor; 00141 00142 //.. no need friend class GaussPoint; 00143 // explanation why this one should be a friend instead 00144 // of inheriting all data through protected construct 00145 // see in J. Coplien "Advanced C++..." page 96. 00146 00147 private: 00148 nDarray_rep * pc_nDarray_rep; 00149 00150 public: 00151 nDarray(int rank_of_nDarray=1, double initval=0.0);// default constructor 00152 nDarray(int rank_of_nDarray, const int *pdim, double *values); 00153 nDarray(int rank_of_nDarray, const int *pdim, double initvalue); 00154 //..// for skyBJmatrix --v 00155 //.. nDarray(int dim); 00156 //.. nDarray(int dim, double* initvalue); 00157 00158 // special case for BJmatrix and BJvector . . . 00159 nDarray(int rank_of_nDarray, int rows, int cols, double *values); 00160 nDarray(int rank_of_nDarray, int rows, int cols, double initvalue); 00161 00162 // special case when I don't want any initialization at all## 00163 nDarray(char *){}; 00164 00165 nDarray(const char *flag, int rank_of_nDarray, const int *pdim); // create a unit nDarray 00166 nDarray(const nDarray & x); // copy-initializer 00167 virtual ~nDarray(); 00168 00169 //############################################################################## 00170 // copy only data because everything else has already been defined 00171 // WATCH OUT IT HAS TO BE DEFINED BEFORE THIS FUNCTIONS IS CALLED 00172 // use "from" and initialize already allocated nDarray from "from" values 00173 void Initialize( const nDarray & from ); // initialize data only 00174 void Initialize_all( const nDarray & from );// initialize and allocate all 00175 // ( dimensions, rank and data ) 00176 // for BJtensor 00177 00178 void Reset_to( double value ); // reset data to "value" 00179 00180 //.. double operator( ) (int subscript, ...) const; // same as val 00181 // but overloaded (...) 00182 // and public ! 00183 00184 //@@@@@ double operator( )(int first) const; // overloaded for ONE argument 00185 //@@@@@ double operator( )(int first, 00186 //@@@@@ int second) const; // overloaded for TWO arguments 00187 //@@@@@ double operator( )(int first, 00188 //@@@@@ int second, 00189 //@@@@@ int third) const; // overloaded for THREE arguments 00190 //@@@@@ double operator( )(int first, 00191 //@@@@@ int second, 00192 //@@@@@ int third, 00193 //@@@@@ int fourth) const; // overloaded for FOUR arguments 00194 //@@@@@ 00195 //@@@@@ double operator( )(int first, 00196 //@@@@@ int second, 00197 //@@@@@ int third, 00198 //@@@@@ int fourth, 00199 //@@@@@ int subscript, 00200 //@@@@@ ... ) const; // overloaded for more than FOUR arguments 00201 00202 // BJtensor & operator()(char *indices_from_user);// to be defined in BJtensor class 00203 double & val(int subscript, ...); 00204 double & val4(int first, int second, int third, int fourth); // overloaded for FOUR arguments for operator * for two tensors 00205 00206 // ..JB.. double & val(int first); // overloaded for ONE argument 00207 // ..JB.. double & val(int first, 00208 // ..JB.. int second); // overloaded for TWO arguments 00209 // ..JB.. double & val(int first, 00210 // ..JB.. int second, 00211 // ..JB.. int third); // overloaded for THREE arguments 00212 // ..JB.. double & val(int first, 00213 // ..JB.. int second, 00214 // ..JB.. int third, 00215 // ..JB.. int fourth); // overloaded for FOUR arguments 00216 // ..JB.. 00217 //.. double & val(int first, 00218 //.. int second, 00219 //.. int third, 00220 //.. int fourth, 00221 //.. int subscript, 00222 //.. ... ); // overloaded for more than FOUR arguments 00223 //.. 00224 double cval(int subscript, ...) const; // const 00225 00226 //.. 00227 00228 #ifndef _VC6 00229 friend nDarray operator+(const nDarray & , const nDarray & ); 00230 friend nDarray operator-(const nDarray & , const nDarray & ); // nDarray subtraction 00231 #else 00232 nDarray operator+(const nDarray & ) const; 00233 nDarray operator-(const nDarray & ) const; // nDarray subtraction 00234 #endif 00235 00236 nDarray& operator=( const nDarray & rval); // nDarray assignment 00237 00238 //++ nDarray operator+( nDarray & rval); // nDarray addition 00239 //....// This is from JOOP May/June 1990 after ARKoenig 00240 nDarray& operator +=( const nDarray & ); // nDarray addition 00241 00242 00243 00252 00253 00254 00255 //++ nDarray operator-( nDarray & rval); // nDarray subtraction 00256 //....// This is from JOOP May/June 1990 after ARKoenig 00257 nDarray& operator -=( const nDarray & ); // nDarray subtraction 00258 00259 00260 00261 nDarray operator+( double rval); // scalar addition 00262 nDarray operator-( double rval); // scalar subtraction 00263 nDarray operator*( const double rval) const ; // scalar multiplication 00264 00265 nDarray operator-( ); // Unary minus 00266 00267 double sum() const; // summ of all the elements 00268 double trace( ) const; // trace of a 2-nd BJtensor, BJmatrix 00269 00270 nDarray deep_copy( ); // make an image 00271 00272 int operator==( nDarray & rval); // nDarray comparisson 00273 // returns 1 if they are same 00274 // returns 0 if they are not 00275 00276 // prebacen u nDarray 14 oktobra 1996 00277 public: 00278 nDarray eigenvalues(void); 00279 nDarray eigenvectors(void); 00280 00281 nDarray nDsqrt(void); 00282 00283 00284 void print(char *name = "t", char *msg = "Hi there#") const; 00285 void printshort(char *msg = "Hi there#") const; 00286 void mathprint(void) const; 00287 // print nDarray with a "name" and the "message" 00288 00289 double Frobenius_norm( void ); // return the Frobenius norm of 00290 // BJmatrix, BJtensor, BJvector 00291 double General_norm( double p ); // return the General p-th norm of 00292 // BJmatrix, BJtensor, BJvector 00293 00294 int number_of_zeros(void) const; // number of members that are 00295 // smaller than sqrt(macheps) 00296 //.....//-> the declaration also put in the nDaray_rep class defintion because 00297 //.....//-> frienship is not inhereted ( see ARM page 251 or around ). 00298 //..... friend BJtensor operator*(BJtensor& lval, BJtensor& rval); // inner/outter product 00299 00300 public: 00301 int rank(void) const; 00302 int dim(int which) const; 00303 00304 // from Numerical recipes in C 00305 private: 00306 void tqli(double * d, double * e, int n, double ** z); 00307 void tred2(double ** a, int n, double * d, double * e); 00308 void eigsrt(double * d, double ** v, int n); 00309 00310 private: 00311 double* data(void) const; 00312 void set_data_pointer(double* ); 00313 // int rank(void) const; 00314 void rank(int ); 00315 long int total_number(void) const ; 00316 void total_number(long int ); 00317 int* dim(void) const ; 00318 int& get_dim_pointer(void) const ; 00319 void set_dim_pointer(int* ); 00320 // int dim(int which) const; 00321 int reference_count(int ); 00322 void set_reference_count(int ); 00323 00324 }; 00325 // GLOBAL 00326 nDarray operator*( const double lval, const nDarray & rval); // REVIEWER global * 00327 00328 #endif 00329 00330 |