xc
PtrArrayBase.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 //PtrArrayBase.h
29 //Pointers in a matrix structure.
30 
31 #ifndef PTRARRAYBASE_H
32 #define PTRARRAYBASE_H
33 
34 #include "utility/kernel/CommandEntity.h"
35 #include "utility/matrices/TMatrix.h"
36 #include <vector>
37 #include "boost/any.hpp"
38 #include "boost/lexical_cast.hpp"
39 
40 
41 #include "utility/matrices/m_int.h"
42 
43 namespace XC{
44 
45 
47 //
49 template <class T>
50 class PtrArrayBase: public TMatrix<T *,std::vector<T *> >, public CommandEntity
51  {
52  public:
54  typedef typename m_ptr::iterator iterator;
55  typedef typename m_ptr::const_iterator const_iterator;
56  typedef typename m_ptr::value_type value_type;
57  typedef typename m_ptr::reference reference;
58  typedef typename m_ptr::const_reference const_reference;
59  protected:
61  PtrArrayBase(const size_t &f=0,const size_t &c=0, const value_type &def_value= nullptr)
62  : m_ptr(f,c,def_value), CommandEntity() {}
63  public:
64  virtual bool operator==(const PtrArrayBase<T> &) const;
65  bool Null(void) const;
66  bool HasNull(void) const;
67 
68  void dim(const size_t &, const size_t &);
69 
70  std::vector<int> getRowObjectsTags(const size_t &);
71  std::vector<int> getColumnObjectsTags(const size_t &);
72  std::vector<int> getRowInteriorObjectsTags(const size_t &);
73  std::vector<int> getColumnInteriorObjectsTags(const size_t &);
74  std::vector<int> getTagsInteriorObjs(void);
75  std::vector<int> getTagsObjs(void);
76  };
77 
79 template <class T>
80 void XC::PtrArrayBase<T>::dim(const size_t &nRows,const size_t &numberOfColumns)
81  { this->resize(nRows,numberOfColumns,nullptr); }
82 
84 template <class T>
86  {
87  bool retval= false;
88  if(this==&other)
89  retval= true;
90  else
91  {
92  retval= m_ptr::operator==(other);
93  retval= retval && CommandEntity::operator==(other);
94  }
95  return retval;
96  }
97 
98 
100 template <class T>
101 bool PtrArrayBase<T>::Null(void) const
102  {
103  if(this->empty())
104  return true;
105  else
106  return (this->operator()(1,1)==nullptr);
107  }
108 
110 template <class T>
111 bool PtrArrayBase<T>::HasNull(void) const
112  {
113  bool retval= false;
114  if(Null())
115  retval= true;
116  else
117  {
118  const size_t numberOfRows= this->getNumberOfRows();
119  const size_t numberOfColumns= this->getNumberOfColumns();
120  for(size_t j= 1;j<=numberOfRows;j++)
121  for(size_t k= 1;k<=numberOfColumns;k++)
122  if(this->operator()(j,k)== nullptr)
123  {
124  retval= true;
125  break;
126  }
127  }
128  return retval;
129  }
130 
133 template <class T>
134 std::vector<int> XC::PtrArrayBase<T>::getRowObjectsTags(const size_t &f)
135  {
136  const std::string nmbBlq= getClassName()+":row_objects:"+boost::lexical_cast<std::string>(f);
137  const size_t numCols= this->getNumberOfColumns();
138  std::vector<int> retval(numCols);
139  for(size_t i= 1;i<=numCols;i++)
140  retval[i-1]= (*this)(f,i)->getTag();
141  return retval;
142  }
143 
146 template <class T>
147 std::vector<int> XC::PtrArrayBase<T>::getColumnObjectsTags(const size_t &c)
148  {
149  const std::string nmbBlq= getClassName()+":column_objects:"+boost::lexical_cast<std::string>(c);
150  const size_t n_rows= this->getNumberOfRows();
151  std::vector<int> retval(n_rows);
152  for(size_t i= 1;i<=n_rows;i++)
153  retval[i-1]= (*this)(i,c)->getTag();
154  return retval;
155  }
156 
159 template <class T>
160 std::vector<int> XC::PtrArrayBase<T>::getRowInteriorObjectsTags(const size_t &f)
161  {
162  const std::string nmbBlq= getClassName()+":row_interior_objects:"+boost::lexical_cast<std::string>(f);
163  const size_t numCols= this->getNumberOfColumns();
164  std::vector<int> retval(numCols-2);
165  for(size_t i= 2;i<numCols;i++)
166  retval[i-2]= (*this)(f,i)->getTag();
167  return retval;
168  }
169 
172 template <class T>
173 std::vector<int> XC::PtrArrayBase<T>::getColumnInteriorObjectsTags(const size_t &c)
174  {
175  const std::string nmbBlq= getClassName()+":column_interior_objects:"+boost::lexical_cast<std::string>(c);
176  const size_t n_rows= this->getNumberOfRows();
177  std::vector<int> retval(n_rows-2);
178  for(size_t i= 2;i<n_rows;i++)
179  retval[i-2]= (*this)(i,c)->getTag();
180  return retval;
181  }
182 
185 template <class T>
187  {
188  const size_t n_rows= this->getNumberOfRows();
189  const size_t numCols= this->getNumberOfColumns();
190  std::vector<int> retval((n_rows-1)*(numCols-1));
191  if(n_rows==1)
192  retval= this->getRowInteriorObjectsTags(1);
193  if(numCols==1)
194  retval= this->getColumnInteriorObjectsTags(1);
195  else
196  {
197  m_int tmp(n_rows-2,numCols-2);
198  for(size_t i= 2;i<n_rows;i++)
199  for(size_t j= 2;j<numCols;j++)
200  tmp(i-1,j-1)= (*this)(i,j)->getTag();
201  retval= tmp.getVector();
202  }
203  return retval;
204  }
205 
206 template <class T>
207 std::vector<int> XC::PtrArrayBase<T>::getTagsObjs(void)
208  {
209  const size_t n_rows= this->getNumberOfRows();
210  const size_t numCols= this->getNumberOfColumns();
211  std::vector<int> retval(n_rows*numCols);
212  m_int tmp(n_rows,numCols);
213  for(size_t i= 1;i<=n_rows;i++)
214  for(size_t j= 1;j<=numCols;j++)
215  tmp(i,j)= (*this)(i,j)->getTag();
216  retval= tmp.getVector();
217  return retval;
218  }
219 
220 } //end of XC namespace
221 
222 #endif
bool HasNull(void) const
Returns true if it&#39;s empty or any of the pointers are NULL.
Definition: PtrArrayBase.h:111
Matrix which element type has estructura de anillo respecto a las operaciones + y *...
Definition: ZMatrix.h:37
std::vector< int > getColumnObjectsTags(const size_t &)
Asks each of the objects in the column to execute the code being passed as parameter.
Definition: PtrArrayBase.h:147
std::vector< int > getRowInteriorObjectsTags(const size_t &)
Asks each of the objects at the interior of the row to execute the code being passed as parameter...
Definition: PtrArrayBase.h:160
virtual bool operator==(const TMatrix< T *, std::vector< T * > > &) const
Comparison operator.
Definition: TMatrix.h:209
bool Null(void) const
Returns true if it&#39;s empty or the pointers are NULL.
Definition: PtrArrayBase.h:101
std::vector< int > getRowObjectsTags(const size_t &)
Asks each of the objects in the row to execute the code being passed as parameter.
Definition: PtrArrayBase.h:134
virtual std::string getClassName(void) const
Returns demangled class name.
Definition: EntityWithOwner.cc:90
virtual bool operator==(const EntityWithOwner &) const
Comparison operator.
Definition: EntityWithOwner.cc:86
Objet that can execute python scripts.
Definition: CommandEntity.h:40
void dim(const size_t &, const size_t &)
Matrix dimensions.
Definition: PtrArrayBase.h:80
Definition: TMatrix.h:37
std::vector< int > getColumnInteriorObjectsTags(const size_t &)
Asks each of the objects at the interior of the column to execute the code being passed as parameter...
Definition: PtrArrayBase.h:173
virtual bool operator==(const PtrArrayBase< T > &) const
Comparison operator.
Definition: PtrArrayBase.h:85
std::vector< int > getTagsInteriorObjs(void)
Asks each of the objects at the interior to execute the code being passed as parameter.
Definition: PtrArrayBase.h:186
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
Base class for matrices of pointers to nodes, elements and points.
Definition: PtrArrayBase.h:50
void resize(size_t n_rows, size_t n_columns, T * val)
Assignment operator.
Definition: TMatrix.h:201
PtrArrayBase(const size_t &f=0, const size_t &c=0, const value_type &def_value=nullptr)
Constructor.
Definition: PtrArrayBase.h:61