xc
nDarray_rep.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // XC program; finite element analysis code
4 // for structural analysis and design.
5 //
6 // Copyright (C) Luis C. Pérez Tato
7 //
8 // This program derives from OpenSees <http://opensees.berkeley.edu>
9 // developed by the «Pacific earthquake engineering research center».
10 //
11 // Except for the restrictions that may arise from the copyright
12 // of the original program (see copyright_opensees.txt)
13 // XC is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // This software is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program.
26 // If not, see <http://www.gnu.org/licenses/>.
27 //----------------------------------------------------------------------------
28 //#############################################################################
29 // #
30 // #
31 // /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/~~\ #
32 // | |____| #
33 // | | #
34 // | | #
35 // | | #
36 // | | #
37 // | B A S E C L A S S E S | #
38 // | | #
39 // | | #
40 // | | #
41 // | | #
42 // | C + + H E A D E R | #
43 // | | #
44 // | | #
45 // | | #
46 // | | #
47 // /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/ | #
48 // \_________________________________________\__/ #
49 // #
50 // #
51 //#############################################################################
52 //#############################################################################
54 //################################################################################
55 //# COPYRIGHT (C): :-)) #
56 //# PROJECT: Object Oriented Finite Element Program #
57 //# PURPOSE: #
58 //# CLASS: nDarray #
59 //# #
60 //# VERSION: #
61 //# LANGUAGE: C++.ver >= 2.0 ( Borland C++ ver=3.10, SUN C++ ver=2.1 ) #
62 //# TARGET OS: DOS || UNIX || . . . #
63 //# DESIGNER(S): Boris Jeremic #
64 //# PROGRAMMER(S): Boris Jeremic #
65 //# #
66 //# #
67 //# DATE: May 28. - July 20 '93 #
68 //# UPDATE HISTORY: july 8. '93. BJtensor02 - BJtensor multiplication #
69 //# inner and outer products #
70 //# December 23 1993 print from the base class, operator==,#
71 //# macheps . . . #
72 //# August 22-29 '94 choped to separate files and worked on#
73 //# const and & issues #
74 //# August 30-31 '94 added use_def_dim to full the CC #
75 //# resolved problem with temoraries for #
76 //# operators + and - ( +=, -= ) #
77 //# January 16 '95 fixed the memory leakage introduced #
78 //# by previous work on +=, -+. I was #
79 //# by mistake decreasing #
80 //# this->pc_nDarray_rep->total_numb--; #
81 //# inststead of #
82 //# this->pc_nDarray_rep->n--; #
83 //# 28June2004 added val4 for efficiency still #
84 //# to be worked on #
85 //# #
86 //# #
87 //# #
88 //# #
89 //#############################################################################
90 //*/
91 
92 #ifndef NDARRAY_REP_HH
93 #define NDARRAY_REP_HH
94 
95 #include "utility/matrix/nDarray/basics.h"
96 #include <boost/python.hpp>
97 #include <iostream>
98 
99 // forward reference
100 namespace XC {
101 class BJtensor;
102 class BJmatrix;
103 class BJvector;
104 
105 
106 class stresstensor;
107 class straintensor;
108 
109 
113  {
114  public:
115  friend class nDarray;
116  friend class BJtensor;
117  friend class BJmatrix;
118 // friend class skyBJmatrix;
119  friend class stiffness_matrix;
120  friend class BJvector;
121  friend class stressstraintensor;
122  friend class stresstensor;
123  friend class straintensor;
124 
125  friend class Cosseratstresstensor;
126  friend class Cosseratstraintensor;
127 
128  private:
129  std::vector<double> pd_nDdata; // nD array as 1D array
130  size_t total_numb; // total number of elements in nDarray
131  std::vector<int> dim; // array of dimensions in each rank direction
132  // for example, if get_get_nDarray_rank() = 3 :
133  // dim[0] = dimension in direction 1
134  // dim[1] = dimension in direction 2
135  // dim[2] = dimension in direction 3 */
136 
137  inline int get_nDarray_rank(void) const
138  { return dim.size(); } // 0 -> scalar
139  // 1 -> BJvector
140  // 2 -> BJmatrix
141  // * -> ******** */
142  inline size_t get_index(int first, int second) const
143  { return (first - 1)*dim[1]+second - 1; }
144  inline size_t get_index(int first, int second, int third) const
145  { return ((first - 1)*dim[1]+second - 1)*dim[2]+third - 1; }
146  inline size_t get_index(int first, int second, int third, int fourth) const
147  {
148  return (((first - 1)*dim[1]+second - 1)*dim[2]+third - 1)*dim[3]+fourth - 1;
149  }
150  public:
151  nDarray_rep(void)
152  : pd_nDdata(), total_numb(), dim() {}
153  void init_dim(const size_t &, const int &default_dim= 1);
154  void init_dim(const std::vector<int> &pdim);
155  inline void clear_dim(void)
156  { dim.clear(); }
157  inline bool equal_dim(const std::vector<int> &rval) const
158  { return (dim==rval); }
159  void init_data(void);
160  void init_data(const double &);
161  void init_data(const double *);
162  void init_data(const std::vector<double> &);
163  void init_data(const boost::python::list &);
164  void reset_data_to(const double &);
165  inline const std::vector<double> &get_data(void) const
166  { return pd_nDdata; }
167  inline std::vector<double> &get_data(void)
168  { return pd_nDdata; }
169  inline double *get_data_ptr(void)
170  { return pd_nDdata.data(); }
171  inline const double *get_data_ptr(void) const
172  { return pd_nDdata.data(); }
173  bool equal_data(const std::vector<double> &other_data) const;
174  inline const double &val(const size_t &where) const
175  { return pd_nDdata[where]; }
176  inline double &val(const size_t &where)
177  { return pd_nDdata[where]; }
178  inline void clear_data(void)
179  { pd_nDdata.clear(); }
180 
181  inline void clear(void)
182  {
183  clear_data();
184  clear_dim();
185  }
186  void sum_data(const std::vector<double> &);
187  void substract_data(const std::vector<double> &);
188  void neg(void);
189  double sum(void) const;
190  bool operator==(const nDarray_rep &rval) const;
191  inline const double &operator()(int first) const
192  {
193  if(get_nDarray_rank()==0)
194  return (pd_nDdata[0]);
195  return val(static_cast<size_t>(first - 1));
196  }
197  inline double &operator()(int first)
198  {
199  if(get_nDarray_rank()==0)
200  return (pd_nDdata[0]);
201  return val(static_cast<size_t>(first - 1));
202  }
203  inline const double &operator()(int first, int second) const
204  {
205  const size_t i= get_index(first, second);
206  return val(i);
207  }
208  inline double &operator()(int first, int second)
209  {
210  const size_t i= get_index(first, second);
211  return val(i);
212  }
213  inline const double &operator()(int first, int second, int third) const
214  {
215  //assert(get_nDarray_rank()==3);
216  const size_t i= get_index(first, second, third);
217  return val(i);
218  }
219  inline double &operator()(int first, int second, int third)
220  {
221  const size_t i= get_index(first, second, third);
222  return val(i);
223  }
224  inline const double &operator()(int first, int second, int third, int fourth) const
225  {
226  //assert(get_nDarray_rank()==4);
227  const size_t i= get_index(first, second, third, fourth);
228  return val(i);
229  }
230  inline double &operator()(int first, int second, int third, int fourth)
231  {
232  const size_t i= get_index(first, second, third, fourth);
233  return val(i);
234  }
235  void print(std::ostream &os) const;
236  };
237 
238 std::ostream& operator<<(std::ostream &, const nDarray_rep &);
239 
240 } // end of XC namespace
241 
242 
243 #endif
244 
void init_data(void)
Initialize data vector.
Definition: nDarray_rep.cc:139
Base class for strain and stress tensors.
Definition: stress_strain_tensor.h:41
Stress tensor.
Definition: stresst.h:70
Boris Jeremic tensor class.
Definition: BJtensor.h:112
Boris Jeremic vector class.
Definition: BJvector.h:102
n-dimensional array.
Definition: nDarray.h:106
Stress tensor of a Cosserat material.
Definition: Cosseratstresst.h:66
Storage of n-dimensional array data.
Definition: nDarray_rep.h:112
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
Boris Jeremic matrix class.
Definition: BJmatrix.h:104
Strain tensor of a Cosserat material.
Definition: Cosseratstraint.h:70
Strain tensor.
Definition: straint.h:68
void init_dim(const size_t &, const int &default_dim=1)
Initialize dimensions vector.
Definition: nDarray_rep.cc:118