xc
BJmatrix.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 // $Revision: 1.1 $
29 // $Date: 2001/08/23 16:45:50 $
30 // $Source: /usr/local/cvs/OpenSees/SRC/nDarray/BJmatrix.h,v $
31 
32 //#############################################################################
33 // #
34 // #
35 // /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/~~\ #
36 // | |____| #
37 // | | #
38 // | | #
39 // | | #
40 // | | #
41 // | B A S E C L A S S E S | #
42 // | | #
43 // | | #
44 // | | #
45 // | | #
46 // | C + + H E A D E R | #
47 // | | #
48 // | | #
49 // | | #
50 // | | #
51 // /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/ | #
52 // \_________________________________________\__/ #
53 // #
54 // #
55 //#############################################################################
56 //#############################################################################
58 //############################################################################
59 //# COPYRIGHT (C): :-)) #
60 //# PROJECT: Object Oriented Finite Element Program #
61 //# PURPOSE: #
62 //# CLASS: BJmatrix #
63 //# #
64 //# VERSION: #
65 //# LANGUAGE: C++.ver >= 2.0 ( Borland C++ ver=3.10, SUN C++ ver=2.1 ) #
66 //# TARGET OS: DOS || UNIX || . . . #
67 //# DESIGNER(S): Boris Jeremic #
68 //# PROGRAMMER(S): Boris Jeremic #
69 //# #
70 //# #
71 //# DATE: November '92 #
72 //# UPDATE HISTORY: 05 - 07 avgust '93. redefined as derived class from #
73 //# nDarray class #
74 //# january 06 '93 added BJmatrix2tensor_1, BJmatrix2tensor_2#
75 //# August 22-29 '94 choped to separate files and worked on #
76 //# const and & issues #
77 //# August 30-31 '94 added use_def_dim to full the CC #
78 //# resolved problem with temoraries for #
79 //# operators + and - ( +=, -= ) #
80 //# #
81 //# #
82 //# #
83 //# #
84 //# #
85 //############################################################################
86 //*/
87 //
88 
89 // MATRIX.hhH: fully functional BJmatrix class based on
90 // design in chapter 9. ( Bruce Eckel: " Using C++ " )
91 // improved a lot by Boris Jeremic
92 #ifndef BJMATRIX_HH
93 #define BJMATRIX_HH
94 
95 #include "utility/matrix/nDarray/nDarray.h"
96 
97 //class vector;
98 
99 
100 namespace XC {
104 class BJmatrix: public nDarray
105  {
106  friend class BJvector; // explanation why this one should be a friend
107  // instead of inheriting all data through protected
108  // construct -> see in J. Coplien "Advanced C++ ..."
109  // page 96.
110 
111 
112  private:
113  void error(const std::string &msg1,const std::string &msg2 = ""); // private function
114 
115  public:
116  BJmatrix(int mrows = 1, int columns = 1, double initval = 0.0);
117  BJmatrix(int mrows, int columns, double *initvalues);
118  BJmatrix(int mrows, int columns, const std::vector<double> &);
119  BJmatrix(int mrows, int columns, const boost::python::list &);
120  BJmatrix(const boost::python::list &l);
121 
122  BJmatrix(const std::string &flag, int dimension ); // create an ident BJmatrix
123  BJmatrix(const std::string &matfile); // read from a "standard" BJmatrix file
124  BJmatrix(const std::string &matfile,const std::string &outfile); // read from a flat BJmatrix file
125  // and write test output to another mat file
126  BJmatrix(const BJmatrix &x); // copy-initializer
127  explicit BJmatrix(const nDarray &x);
128 
129 //-- ~BJmatrix( );
130 
131  int rows( void ) const; // rows in BJmatrix
132  int cols( void ) const; // cols in BJmatrix
133 
134  BJmatrix & operator=(const BJmatrix & rval); // BJmatrix assignment
135 
136 // Write a "standard" BJmatrix file:
137  void write_standard(const std::string &filename,const std::string &msg = "");
138 
139 
140  BJmatrix operator*( BJmatrix &); // BJmatrix multiplication
141  BJmatrix operator*( double rval); // scalar multiplication
142 //.... vector operator*( vector &); // vector multiplication
143 // vector operator*( double ); // vector multiplication
144 
145 //-----//forwarding definition
146 //----- virtual vector operator*( double ); // scalar multiplication
147 
148 // this is COUPLING between ordinary BJmatrix and SKYMATRIX
149 // it will be useful in multiplying vectors with skyBJmatrix
150 //#### BJmatrix operator*(const skyBJmatrix & rval); // BJutility/matrix/skyBJmatrix multiplication
151 //#### double & val(int row, int col); // element selection;
152 
153 //####// this one is the same as mval except that it is more convenient
154 //####// to overload operator (row,col).
155 //####// THE ROW AND COL COUNTER STARTS FROM 1 ( NOT FROM 0 )
156 //#### double & operator( )(int row, int col);
157 // can be used to read or write an element.
158 
159  BJmatrix transpose( ); // transpose a square BJmatrix
160  double determinant( );
161  BJmatrix inverse( );
162  double mmin( ); // find minimum element in the BJmatrix
163  double mmax( ); // find maximum element in the BJmatrix
164  double mean( ); // average all the elements of the BJmatrix
165  double sum( ); // sum all the elements in BJmatrix
166  double variance( ); // statistical variance of all elements
167 
168  BJtensor BJmatrix2BJtensor_1( ); // convert BJmatrix back to 4th order BJtensor
169  // I_ijkl scheme
170  BJtensor BJmatrix2BJtensor_2( ); // convert BJmatrix back to 4th order BJtensor
171  // I_ikjl scheme
172  BJtensor BJmatrix2BJtensor_22( ); // convert BJmatrix back to 2th order BJtensor
173 
174  BJtensor BJmatrix2BJtensor_3( ); // convert BJmatrix back to 4th order BJtensor
175  // I_iljk scheme
176 
177 //####
178 //####// Compress columns and rows
179 //#### BJmatrix compress_col(int col1, int col2, int to_col);
180 //#### BJmatrix compress_row(int row1, int row2, int to_row);
181 //####
182 
183  private: // functions used by inverse() and determinant()
184  void switch_columns(int col1, int co12);
185  void copy_column(BJmatrix & m, int from_col, int to_col);
186  BJmatrix scale( ); // scale a BJmatrix (used in L-U decomposition)
187  void deepcopy(BJmatrix & from, BJmatrix & to); // make an image
188  BJmatrix lu_decompose(BJmatrix & indx, int & d );
189  // Returns the L-U decomposition of a BJmatrix
190  void lu_back_subst(BJmatrix & indx, BJmatrix & b);
191  // Uses L-U decomposition for BJmatrix inverse
192 
193  double & mval (int row, int col); // I am still keeping mval
194  // operator for compatibility
195  // with old BJmatrix class members
196  // and they start from 0 ###
197  // used by BJmatrix functions which KNOW they aren't
198  // exceeding the boundaries
199 
200  public:
201 // Tiejun Li Jan 2000
202  double *BJmatrixtoarray(int &);
203 
204  void Output(std::ostream &s) const;
205  friend std::ostream &operator<<(std::ostream &, const BJmatrix &);
206  friend std::string to_string(const BJmatrix &);
207  inline std::string toString(void) const
208  { return to_string(*this); }
209 
210 
211 // // prebacen u nDarray 14 oktobra 1996
212 // public:
213 // BJvector eigenvalues(void);
214 // BJmatrix eigenvectors(void);
215 
216 // // from Numerical recipes in C
217 // private:
218 // void tqli(double * d, double * e, int n, double ** z);
219 // void tred2(double ** a, int n, double * d, double * e);
220 // void eigsrt(double * d, double ** v, int n);
221  };
222 
223  std::ostream &operator<<(std::ostream &, const BJmatrix &);
224  std::string to_string(const BJmatrix &);
225 } // end of XC namespace
226 #endif
Boris Jeremic tensor class.
Definition: BJtensor.h:112
Definition: bimap.h:34
void Output(std::ostream &s) const
Write to the argument stream.
Definition: BJmatrix.cpp:982
Definition: bimap.h:33
Boris Jeremic vector class.
Definition: BJvector.h:102
n-dimensional array.
Definition: nDarray.h:242
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
Boris Jeremic matrix class.
Definition: BJmatrix.h:104
BJmatrix(int mrows=1, int columns=1, double initval=0.0)
Constructor.
Definition: BJmatrix.cpp:80