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