XC Open source finite element analysis program
MovableContainer.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 //MovableContainer
28 
29 
30 #ifndef MovableContainer_h
31 #define MovableContainer_h
32 
33 #include "utility/actor/actor/MovableObject.h"
34 #include <deque>
35 
36 namespace XC {
37 
39 //
41 template <class C>
43  {
44  public:
45  typedef typename C::iterator iterator;
46  typedef typename C::const_iterator const_iterator;
47  typedef typename C::reference reference;
48  typedef typename C::const_reference const_reference;
49  protected:
50  C &contenedor;
51  DbTagData &getDbTagData(void) const;
52  virtual int sendItem(const_reference s,CommParameters &,DbTagData &, const CommMetaData &)= 0;
53  virtual int receiveItem(reference s,const CommParameters &,DbTagData &, const CommMetaData &)= 0;
54  int sendData(CommParameters &);
55  int recvData(const CommParameters &);
56  public:
57  explicit MovableContainer(C &);
58 
59  virtual int sendSelf(CommParameters &);
60  virtual int recvSelf(const CommParameters &);
61  };
62 
64 template <class C>
66  : MovableObject(0), contenedor(v) {}
67 
68 
71 template <class C>
73  {
74  static DbTagData retval(2);
75  return retval;
76  }
77 
79 template <class C>
81  {
82  const size_t sz= contenedor.size();
83  DbTagData &dt= getDbTagData();
84 
85  dt.setDbTagDataPos(0, sz);
86 
87  DbTagData dbTags(sz);
88 
89  int res= 0;
90  int loc= 0;
91  for(const_iterator i= contenedor.begin();i!=contenedor.end();i++)
92  res+= this->sendItem(*i,cp,dbTags,CommMetaData(loc++));
93  res+= dbTags.send(dt,cp,CommMetaData(1));
94  if(res<0)
95  std::cerr << "MovableContainer::sendSelf() - failed to send ID.\n";
96  return res;
97  }
98 
100 template <class C>
102  {
103  DbTagData &dt= getDbTagData();
104  const int sz= dt.getDbTagDataPos(0);
105  contenedor.resize(sz);
106  DbTagData dbTags(sz);
107 
108 
109  int res= dbTags.receive(dt,cp,CommMetaData(1));
110  int loc= 0;
111  for(iterator i= contenedor.begin();i!=contenedor.end();i++)
112  res+= this->receiveItem(*i,cp,dbTags,CommMetaData(loc++));
113  return res;
114  }
115 
117 template <class C>
119  {
120  setDbTag(cp);
121  const int dataTag= getDbTag();
122  this->inicComm(2);
123  int res= sendData(cp);
124 
125  res+= cp.sendIdData(getDbTagData(),dataTag);
126  if(res < 0)
127  std::cerr << "MovableContainer::sendSelf() - failed to send data\n";
128  return res;
129  }
130 
132 template <class C>
134  {
135  this->inicComm(2);
136  const int dataTag= getDbTag();
137  int res= cp.receiveIdData(getDbTagData(),dataTag);
138 
139  if(res<0)
140  std::cerr << "MovableContainer::recvSelf - failed to receive ids.\n";
141  else
142  {
143  res+= recvData(cp);
144  if(res<0)
145  std::cerr << "MovableContainer::recvSelf - failed to receive data.\n";
146  }
147  return res;
148  }
149 
150 
151 } // end of XC namespace
152 
153 #endif
154 
virtual int sendSelf(CommParameters &)
Sends deque through the channel being passed as parameter.
Definition: MovableContainer.h:118
void setDbTag(int dbTag)
Asigna el tag para la database.
Definition: MovableObject.cpp:104
int send(DbTagData &, CommParameters &, const CommMetaData &) const
Sends the object.
Definition: DbTagData.cc:102
void setDbTagDataPos(const size_t &i, const int &v)
Sets the integer in the position being passed as parameter.
Definition: DbTagData.cc:77
int getDbTag(void) const
Returns the tag para la database.
Definition: MovableObject.cpp:92
int sendData(CommParameters &)
Send data through the channel being passed as parameter.
Definition: MovableContainer.h:80
Vector que almacena los dbTags de los miembros de la clase.
Definition: DbTagData.h:43
virtual int recvSelf(const CommParameters &)
Recibe el deque through the channel being passed as parameter.
Definition: MovableContainer.h:133
int receiveIdData(DbTagData &, const int &) const
Recibe el miembro data through the channel being passed as parameter.
Definition: CommParameters.cc:396
DbTagData & getDbTagData(void) const
Returns a vector para almacenar los dbTags de los miembros de la clase.
Definition: MovableContainer.h:72
int sendIdData(const DbTagData &, const int &)
Sends miembro data through the channel being passed as parameter.
Definition: CommParameters.cc:392
Object that can move between processes.
Definition: MovableObject.h:91
const int & getDbTagDataPos(const size_t &i) const
Returns the integer in the position being passed as parameter.
Definition: DbTagData.cc:58
Container that can move between processes.
Definition: MovableContainer.h:42
MovableContainer(C &)
Constructor.
Definition: MovableContainer.h:65
int receive(DbTagData &, const CommParameters &, const CommMetaData &)
Recibe el objeto.
Definition: DbTagData.cc:106
void inicComm(const int &dataSize) const
Initializes communication.
Definition: DistributedBase.cc:57
Communication parameters between processes.
Definition: CommParameters.h:65
================================================================================
Definition: ContinuaReprComponent.h:34
Data about the index, size,,... of the object to transmit.
Definition: CommMetaData.h:38
int recvData(const CommParameters &)
Receive data through the channel being passed as parameter.
Definition: MovableContainer.h:101