XC Open source finite element analysis program
nDarray.h
1 //----------------------------------------------------------------------------
2 // XC program; finite element analysis code
3 // for structural analysis and design.
4 //
5 // Copyright (C) Luis Claudio Pérez Tato
6 //
7 // This program derives from OpenSees <http://opensees.berkeley.edu>
8 // developed by the «Pacific earthquake engineering research center».
9 //
10 // Except for the restrictions that may arise from the copyright
11 // of the original program (see copyright_opensees.txt)
12 // XC is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program.
25 // If not, see <http://www.gnu.org/licenses/>.
26 //----------------------------------------------------------------------------
27 //#############################################################################
28 // #
29 // #
30 // /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/~~\ #
31 // | |____| #
32 // | | #
33 // | | #
34 // | | #
35 // | | #
36 // | B A S E C L A S S E S | #
37 // | | #
38 // | | #
39 // | | #
40 // | | #
41 // | C + + H E A D E R | #
42 // | | #
43 // | | #
44 // | | #
45 // | | #
46 // /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/ | #
47 // \_________________________________________\__/ #
48 // #
49 // #
50 //#############################################################################
51 //#############################################################################
53 //################################################################################
54 //# COPYRIGHT (C): :-)) #
55 //# PROJECT: Object Oriented Finite Element Program #
56 //# PURPOSE: #
57 //# CLASS: nDarray #
58 //# #
59 //# VERSION: #
60 //# LANGUAGE: C++.ver >= 2.0 ( Borland C++ ver=3.10, SUN C++ ver=2.1 ) #
61 //# TARGET OS: DOS || UNIX || . . . #
62 //# DESIGNER(S): Boris Jeremic #
63 //# PROGRAMMER(S): Boris Jeremic #
64 //# #
65 //# #
66 //# DATE: May 28. - July 20 '93 #
67 //# UPDATE HISTORY: july 8. '93. BJtensor02 - BJtensor multiplication #
68 //# inner and outer products #
69 //# December 23 1993 print from the base class, operator==, #
70 //# macheps . . . #
71 //# August 22-29 '94 choped to separate files and worked on #
72 //# const and & issues #
73 //# August 30-31 '94 added use_def_dim to full the CC #
74 //# resolved problem with temoraries for #
75 //# operators + and - ( +=, -= ) #
76 //# January 16 '95 fixed the memory leakage introduced #
77 //# by previous work on +=, -+. I was #
78 //# by mistake decreasing #
79 //# this->pc_nDarray_rep->total_numb--; #
80 //# inststead of #
81 //# this->pc_nDarray_rep->n--; #
82 //# 28June2004 added val4 for efficiency still #
83 //# to be worked on #
84 //# #
85 //# #
86 //# #
87 //# #
88 //################################################################################
89 //*/
90 
91 #ifndef NDARRAY_HH
92 #define NDARRAY_HH
93 
94 #include "utility/matrix/nDarray/basics.h"
95 #include <string>
96 
97 // forward reference
98 namespace XC {
99 class BJtensor;
100 class BJmatrix;
101 class BJvector;
102 
103 //class stiffness_BJmatrix;
104 
105 //class Material_Model;
106 //class Elastic;
107 //class Drucker_Prager;
108 //class von_Mises;
109 //class MRS_Lade_cone;
110 //class Parabolic;
111 //
112 class stresstensor;
113 class straintensor;
114 
115 
116 
117 
119 //
121  {
122  public:
123  friend class nDarray;
124  friend class BJtensor;
125  friend class BJmatrix;
126 // friend class skyBJmatrix;
127  friend class stiffness_matrix;
128  friend class BJvector;
129  friend class stresstensor;
130  friend class straintensor;
131 
132  friend class Cosseratstresstensor;
133  friend class Cosseratstraintensor;
134 
135  private:
136  double *pd_nDdata; // nD array as 1D array
137  int nDarray_rank;
138  // 0 -> scalar
139  // 1 -> BJvector
140  // 2 -> BJmatrix
141  // * -> ******** */
142  long int total_numb; // total number of elements in nDarray
143  int *dim; // array of dimensions in each rank direction
144  // for example, if nDarray_rank = 3 :
145  // dim[0] = dimension in direction 1
146  // dim[1] = dimension in direction 2
147  // dim[2] = dimension in direction 3 */
148  int n; // reference count
149  public:
150 // overloading operator new and delete in nDarray_rep class ########
151  void * operator new(size_t s); // see C++ reference manual by
152  void operator delete(void *); // by ELLIS and STROUSTRUP page 283.
153  // and ECKEL page 529.
154  };
155 
157 //
158 class nDarray
159  {
160 // public:
161  private:
162  friend class BJtensor;
163  friend class BJmatrix;
164  friend class BJvector;
165  friend class stiffness_matrix;
166 
167  friend class stresstensor;
168  friend class straintensor;
169 
170  friend class Cosseratstresstensor;
171  friend class Cosseratstraintensor;
172 
173 //.. no need friend class GaussPoint;
174  // explanation why this one should be a friend instead
175  // of inheriting all data through protected construct
176  // see in J. Coplien "Advanced C++..." page 96.
177 
178  private:
179  nDarray_rep * pc_nDarray_rep;
180 
181  public:
182  nDarray(int rank_of_nDarray=1, double initval=0.0);// default constructor
183  nDarray(int rank_of_nDarray, const int *pdim, double *values);
184  nDarray(int rank_of_nDarray, const int *pdim, double initvalue);
185 //..// for skyBJmatrix --v
186 //.. nDarray(int dim);
187 //.. nDarray(int dim, double* initvalue);
188 
189 // special case for BJmatrix and BJvector . . .
190  nDarray(int rank_of_nDarray, int rows, int cols, double *values);
191  nDarray(int rank_of_nDarray, int rows, int cols, double initvalue);
192 
193 // special case when I don't want any initialization at all##
194  explicit nDarray(const std::string &){};
195 
196  nDarray(const std::string &flag, int rank_of_nDarray, const int *pdim); // create a unit nDarray
197  nDarray(const nDarray &x); // copy-initializer
198  virtual ~nDarray(void);
199 
200 //##############################################################################
201 // copy only data because everything else has already been defined
202 // WATCH OUT IT HAS TO BE DEFINED BEFORE THIS FUNCTIONS IS CALLED
203 // use "from" and initialize already allocated nDarray from "from" values
204  void Initialize(const nDarray &from ); // initialize data only
205  void Initialize_all(const nDarray &from);// initialize and allocate all
206  // ( dimensions, rank and data )
207  // for BJtensor
208 
209  void Reset_to(double value ); // reset data to "value"
210 
211 //.. double operator( ) (int subscript, ...) const; // same as val
212  // but overloaded (...)
213  // and public !
214 
215 //@@@@@ double operator( )(int first) const; // overloaded for ONE argument
216 //@@@@@ double operator( )(int first,
217 //@@@@@ int second) const; // overloaded for TWO arguments
218 //@@@@@ double operator( )(int first,
219 //@@@@@ int second,
220 //@@@@@ int third) const; // overloaded for THREE arguments
221 //@@@@@ double operator( )(int first,
222 //@@@@@ int second,
223 //@@@@@ int third,
224 //@@@@@ int fourth) const; // overloaded for FOUR arguments
225 //@@@@@
226 //@@@@@ double operator( )(int first,
227 //@@@@@ int second,
228 //@@@@@ int third,
229 //@@@@@ int fourth,
230 //@@@@@ int subscript,
231 //@@@@@ ... ) const; // overloaded for more than FOUR arguments
232 
233 // BJtensor & operator()(char *indices_from_user);// to be defined in BJtensor class
234  const double &val(int subscript, ...) const;
235  double &val(int subscript, ...);
236  const double &val4(int first, int second, int third, int fourth) const; // overloaded for FOUR arguments for operator * for two tensors
237  double &val4(int first, int second, int third, int fourth); // overloaded for FOUR arguments for operator * for two tensors
238 
239 // ..JB.. double & val(int first); // overloaded for ONE argument
240 // ..JB.. double & val(int first,
241 // ..JB.. int second); // overloaded for TWO arguments
242 // ..JB.. double & val(int first,
243 // ..JB.. int second,
244 // ..JB.. int third); // overloaded for THREE arguments
245 // ..JB.. double & val(int first,
246 // ..JB.. int second,
247 // ..JB.. int third,
248 // ..JB.. int fourth); // overloaded for FOUR arguments
249 // ..JB..
250 //.. double & val(int first,
251 //.. int second,
252 //.. int third,
253 //.. int fourth,
254 //.. int subscript,
255 //.. ... ); // overloaded for more than FOUR arguments
256 //..
257  double cval(int subscript, ...) const; // const
258 
259 //..
260 
261 
262 
263  nDarray& operator=(const nDarray &rval); // nDarray assignment
264 
265 //++ nDarray operator+( nDarray & rval); // nDarray addition
266 //....// This is from JOOP May/June 1990 after ARKoenig
267  nDarray& operator+=(const nDarray &); // nDarray addition
268 
269 
270  friend nDarray operator+(const nDarray & , const nDarray & ); // nDarray addition
279 
280 
281 
282 //++ nDarray operator-( nDarray & rval); // nDarray subtraction
283 //....// This is from JOOP May/June 1990 after ARKoenig
284  nDarray &operator-=(const nDarray & ); // nDarray subtraction
285  friend nDarray operator-(const nDarray & , const nDarray & ); // nDarray subtraction
286 
287  nDarray operator+(double rval); // scalar addition
288  nDarray operator-(double rval); // scalar subtraction
289  nDarray operator*(const double rval) const ; // scalar multiplication
290 
291  nDarray operator-(); // Unary minus
292 
293  double sum(void) const; // summ of all the elements
294  double trace(void) const; // trace of a 2-nd BJtensor, BJmatrix
295 
296  nDarray deep_copy(void); // make an image
297 
298  bool operator==(const nDarray &rval); // nDarray comparisson
299  // returns 1 if they are same
300  // returns 0 if they are not
301 
302 // prebacen u nDarray 14 oktobra 1996
303  public:
304  nDarray eigenvalues(void);
305  nDarray eigenvectors(void);
306 
307  nDarray nDsqrt(void);
308 
309 
310  void print(const std::string &name = "t",const std::string &msg = "Hi there#") const;
311  void printshort(const std::string &msg = "Hi there#") const;
312  void mathprint(void) const;
313  // print nDarray with a "name" and the "message"
314 
315  double Frobenius_norm( void ); // return the Frobenius norm of
316  // BJmatrix, BJtensor, BJvector
317  double General_norm( double p ); // return the General p-th norm of
318  // BJmatrix, BJtensor, BJvector
319 
320  int number_of_zeros(void) const; // number of members that are
321  // smaller than sqrt(macheps)
322 //.....//-> the declaration also put in the nDaray_rep class defintion because
323 //.....//-> frienship is not inhereted ( see ARM page 251 or around ).
324 //..... friend BJtensor operator*(BJtensor& lval, BJtensor& rval); // inner/outter product
325 
326  public:
327  int rank(void) const;
328  int dim(int which) const;
329 
330 // from Numerical recipes in C
331  private:
332  void tqli(double * d, double * e, int n, double ** z);
333  void tred2(double ** a, int n, double * d, double * e);
334  void eigsrt(double * d, double ** v, int n);
335 
336  private:
337  double* data(void) const;
338  void set_data_pointer(double* );
339 // int rank(void) const;
340  void rank(int );
341  long int total_number(void) const ;
342  void total_number(long int );
343  int* dim(void) const ;
344  int& get_dim_pointer(void) const ;
345  void set_dim_pointer(int* );
346  // int dim(int which) const;
347  int reference_count(int );
348  void set_reference_count(int );
349 
350 };
351 // GLOBAL
352 nDarray operator*(const double lval,const nDarray &rval); // REVIEWER global *
353 
354 } // end of XC namespace
355 
356 
357 #endif
358 
Definition: Cosseratstraint.h:64
Definition: BJtensor.h:110
Definition: BJvector.h:100
Definition: stresst.h:68
Strain tensor.
Definition: straint.h:67
Definition: Cosseratstresst.h:60
Definition: BJmatrix.h:102
================================================================================
Definition: ContinuaReprComponent.h:34
Definition: nDarray.h:120
Definition: nDarray.h:158