XC Open source finite element analysis program
MatrizPtrBase.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 //MatrizPtrBase.h
28 //Matriz de puntos
29 
30 #ifndef MATRIZPTRBASE_H
31 #define MATRIZPTRBASE_H
32 
33 #include "xc_utils/src/nucleo/EntCmd.h"
34 #include "xc_basic/src/matrices/matrizT.h"
35 #include <vector>
36 #include "boost/any.hpp"
37 #include "boost/lexical_cast.hpp"
38 
39 
40 #include "xc_basic/src/matrices/m_int.h"
41 
42 namespace XC{
43 
44 
46 //
48 template <class T>
49 class MatrizPtrBase: public MatrizT<T *,std::vector<T *> >, public EntCmd
50  {
51  public:
52  typedef MatrizT<T *,std::vector<T *> > m_ptr;
53  typedef typename m_ptr::iterator iterator;
54  typedef typename m_ptr::const_iterator const_iterator;
55  typedef typename m_ptr::value_type value_type;
56  typedef typename m_ptr::reference reference;
57  typedef typename m_ptr::const_reference const_reference;
58  protected:
59 
60 
62  MatrizPtrBase(const size_t &f=0,const size_t &c=0)
63  : m_ptr(f,c,nullptr), EntCmd() {}
64  public:
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> getTagsObjsFila(const size_t &);
71  std::vector<int> getTagsObjsColumna(const size_t &);
72  std::vector<int> getTagsObjsInterioresFila(const size_t &);
73  std::vector<int> getTagsObjsInterioresColumna(const size_t &);
74  std::vector<int> getTagsInteriorObjs(void);
75  std::vector<int> getTagsObjs(void);
76  };
77 
79 template <class T>
80 void XC::MatrizPtrBase<T>::dim(const size_t &nRows,const size_t &nCols)
81  { this->resize(nRows,nCols,nullptr); }
82 
84 template <class T>
85 bool MatrizPtrBase<T>::Null(void) const
86  {
87  if(this->empty())
88  return true;
89  else
90  return (this->operator()(1,1)== nullptr);
91  }
92 
94 template <class T>
95 bool MatrizPtrBase<T>::HasNull(void) const
96  {
97  bool retval= false;
98  if(Null())
99  retval= true;
100  else
101  {
102  const size_t nfilas= this->getNumFilas();
103  const size_t ncols= this->getNumCols();
104  for(size_t j= 1;j<=nfilas;j++)
105  for(size_t k= 1;k<=ncols;k++)
106  if(this->operator()(j,k)== nullptr)
107  {
108  retval= true;
109  break;
110  }
111  }
112  return retval;
113  }
114 
117 template <class T>
118 std::vector<int> XC::MatrizPtrBase<T>::getTagsObjsFila(const size_t &f)
119  {
120  const std::string nmbBlq= nombre_clase()+":objetos_fila:"+boost::lexical_cast<std::string>(f);
121  const size_t numCols= this->getNumCols();
122  std::vector<int> retval(numCols);
123  for(size_t i= 1;i<=numCols;i++)
124  retval[i-1]= (*this)(f,i)->getTag();
125  return retval;
126  }
127 
130 template <class T>
131 std::vector<int> XC::MatrizPtrBase<T>::getTagsObjsColumna(const size_t &c)
132  {
133  const std::string nmbBlq= nombre_clase()+":objetos_columna:"+boost::lexical_cast<std::string>(c);
134  const size_t numFilas= this->getNumFilas();
135  std::vector<int> retval(numFilas);
136  for(size_t i= 1;i<=numFilas;i++)
137  retval[i-1]= (*this)(i,c)->getTag();
138  return retval;
139  }
140 
143 template <class T>
144 std::vector<int> XC::MatrizPtrBase<T>::getTagsObjsInterioresFila(const size_t &f)
145  {
146  const std::string nmbBlq= nombre_clase()+":objetos_interiores_fila:"+boost::lexical_cast<std::string>(f);
147  const size_t numCols= this->getNumCols();
148  std::vector<int> retval(numCols-2);
149  for(size_t i= 2;i<numCols;i++)
150  retval[i-2]= (*this)(f,i)->getTag();
151  return retval;
152  }
153 
156 template <class T>
157 std::vector<int> XC::MatrizPtrBase<T>::getTagsObjsInterioresColumna(const size_t &c)
158  {
159  const std::string nmbBlq= nombre_clase()+":objetos_interiores_columna:"+boost::lexical_cast<std::string>(c);
160  const size_t numFilas= this->getNumFilas();
161  std::vector<int> retval(numFilas-2);
162  for(size_t i= 2;i<numFilas;i++)
163  retval[i-2]= (*this)(i,c)->getTag();
164  return retval;
165  }
166 
169 template <class T>
171  {
172  const size_t numFilas= this->getNumFilas();
173  const size_t numCols= this->getNumCols();
174  std::vector<int> retval((numFilas-1)*(numCols-1));
175  if(numFilas==1)
176  retval= this->getTagsObjsInterioresFila(1);
177  if(numCols==1)
178  retval= this->getTagsObjsInterioresColumna(1);
179  else
180  {
181  m_int tmp(numFilas-2,numCols-2);
182  for(size_t i= 2;i<numFilas;i++)
183  for(size_t j= 2;j<numCols;j++)
184  tmp(i-1,j-1)= (*this)(i,j)->getTag();
185  retval= tmp.getVector();
186  }
187  return retval;
188  }
189 
190 template <class T>
191 std::vector<int> XC::MatrizPtrBase<T>::getTagsObjs(void)
192  {
193  const size_t numFilas= this->getNumFilas();
194  const size_t numCols= this->getNumCols();
195  std::vector<int> retval(numFilas*numCols);
196  m_int tmp(numFilas,numCols);
197  for(size_t i= 1;i<=numFilas;i++)
198  for(size_t j= 1;j<=numCols;j++)
199  tmp(i,j)= (*this)(i,j)->getTag();
200  retval= tmp.getVector();
201  return retval;
202  }
203 
204 } //end of XC namespace
205 
206 #endif
std::vector< int > getTagsInteriorObjs(void)
Asks each of the objects at the interior to execute the code being passed as parameter.
Definition: MatrizPtrBase.h:170
std::vector< int > getTagsObjsFila(const size_t &)
Asks each of the objects in the row to execute the code being passed as parameter.
Definition: MatrizPtrBase.h:118
void dim(const size_t &, const size_t &)
Matrix dimensions.
Definition: MatrizPtrBase.h:80
MatrizPtrBase(const size_t &f=0, const size_t &c=0)
Constructor.
Definition: MatrizPtrBase.h:62
std::vector< int > getTagsObjsColumna(const size_t &)
Asks each of the objects in the column to execute the code being passed as parameter.
Definition: MatrizPtrBase.h:131
std::vector< int > getTagsObjsInterioresFila(const size_t &)
Asks each of the objects at the interior of the row to execute the code being passed as parameter...
Definition: MatrizPtrBase.h:144
Base class for matrices of pointers to nodes, elements and points.
Definition: MatrizPtrBase.h:49
std::vector< int > getTagsObjsInterioresColumna(const size_t &)
Asks each of the objects at the interior of the column to execute the code being passed as parameter...
Definition: MatrizPtrBase.h:157
================================================================================
Definition: ContinuaReprComponent.h:34
bool HasNull(void) const
Returns true if it&#39;s empty or any of the pointers are NULL.
Definition: MatrizPtrBase.h:95
bool Null(void) const
Returns true if it&#39;s empty or the pointers are NULL.
Definition: MatrizPtrBase.h:85