xc
MovableDeque.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 //MovableDeque
29 
30 
31 #ifndef MovableDeque_h
32 #define MovableDeque_h
33 
34 #include "MovablePointerContainer.h"
35 #include "MovableID.h"
36 #include <deque>
37 #include "utility/tagged/TaggedObject.h"
38 #include "Communicator.h"
39 
40 namespace XC {
41 
43 //
45 template <class T>
47  {
48  protected:
49  typedef std::deque<T *> deque_objects;
50  typedef typename deque_objects::const_iterator const_iterator;
51  typedef typename deque_objects::iterator iterator;
52  deque_objects objects;
53 
54  int sendData(Communicator &);
55  int recvData(const Communicator &);
56  public:
57  MovableDeque(const deque_objects &deque,T *(FEM_ObjectBroker::*pF)(int));
58  const deque_objects &getDeque(void) const
59  { return objects; }
60 
61  };
62 
63 
65 template <class T>
66 XC::MovableDeque<T>::MovableDeque(const deque_objects &deque,T *(FEM_ObjectBroker::*pF)(int))
67  : MovablePointerContainer<T>(0,pF), objects(deque) {}
68 
70 template <class T>
72  {
73  const size_t sz= objects.size();
74  this->setDbTagDataPos(0,sz);
75  int res= 0;
76  if(sz>0)
77  {
78  DbTagData dbTags(sz);
79  ID classTags(sz);
80  for(size_t i= 0;i<sz;i++)
81  {
82  T *obj= objects[i];
83  if(obj)
84  {
85  classTags(i)= obj->getClassTag();
86  res+= comm.sendMovable(*obj,dbTags,CommMetaData(i));
87  }
88  else
89  std::cerr << "MovableDeque::sendData; found null"
90  << " pointer in position: " << i << std::endl;
91  }
92  DbTagData &dbTagData= this->getDbTagData();
93  res+= dbTags.send(dbTagData,comm,CommMetaData(1));
94  res+= comm.sendID(classTags,dbTagData,CommMetaData(2));
95  }
96  return res;
97  }
98 
100 template <class T>
102  {
103  const size_t sz= this->getDbTagDataPos(0);
104  int res= 0;
105  if(sz>0)
106  {
107  DbTagData &dbTagData= this->getDbTagData();
108  DbTagData dbTags(sz);
109  res+= dbTags.receive(dbTagData,comm,CommMetaData(1));
110  ID classTags(sz);
111  res+= comm.receiveID(classTags,dbTagData,CommMetaData(2));
112  T *tmp= nullptr;
113  for(size_t i= 0;i<sz;i++)
114  {
115  const int dbTag= dbTags.getDbTagDataPos(i);
116  tmp= this->getBrokedObject(dbTag,classTags(i),comm);
117  if(tmp)
118  {
119  res+= tmp->recvSelf(comm);
120  objects[i]= tmp;
121  }
122  else
123  std::cerr << "Error in MovableDeque::recvData i= "
124  << i << std::endl;
125  }
126  }
127  return res;
128  }
129 
130 
131 template <class T>
132 int sendDeque(const std::deque<T *> &m,Communicator &comm,DbTagData &dt,const CommMetaData &meta)
133  {
134  MovableDeque<T> mm(m,nullptr);
135  return comm.sendMovable(mm,dt,meta);
136  }
137 
138 template <class T>
139 int receiveDeque(std::deque<T *> &v,const Communicator &comm,DbTagData &dt,const CommMetaData &meta,T *(FEM_ObjectBroker::*ptrFunc)(int))
140  {
141  MovableDeque<T> mm(v,ptrFunc);
142  int res= comm.receiveMovable(mm,dt,meta);
143  v= mm.getDeque();
144  return res;
145  }
146 
147 } // end of XC namespace
148 
149 #endif
150 
int sendMovable(MovableObject &, DbTagData &, const CommMetaData &)
Sends a movable object through the communicator argument.
Definition: Communicator.cc:1163
Communication parameters between processes.
Definition: Communicator.h:66
int sendData(Communicator &)
Send members through the communicator argument.
Definition: MovableDeque.h:71
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
int receiveMovable(MovableObject &, DbTagData &, const CommMetaData &) const
Receives a movable object trhrough the communicator argument.
Definition: Communicator.cc:1174
Vector that stores the dbTags of the class members.
Definition: DbTagData.h:44
Template class for maps that can move between processes.
Definition: MovablePointerContainer.h:43
FEM_ObjectBroker is is an object broker class for the finite element method.
Definition: FEM_ObjectBroker.h:151
Vector of integers.
Definition: ID.h:95
Data about the index, size,,...
Definition: CommMetaData.h:39
T * getBrokedObject(const int &, const int &, const Communicator &)
Returns an empty object of the class identified by classTag.
Definition: MovablePointerContainer.h:75
int receive(DbTagData &, const Communicator &, const CommMetaData &)
Receive the object.
Definition: DbTagData.cc:106
Template class for maps that can move between processes.
Definition: MovableDeque.h:46
int sendID(const ID &, const int &)
Sends vector.
Definition: Communicator.cc:73
MovableDeque(const deque_objects &deque, T *(FEM_ObjectBroker::*pF)(int))
Constructor.
Definition: MovableDeque.h:66
const int & getDbTagDataPos(const int &i) const
Returns the data at the i-th position.
Definition: DistributedBase.cc:53
void setDbTagDataPos(const int &i, const int &v)
Sets the data at the i-th position.
Definition: DistributedBase.cc:57
DbTagData & getDbTagData(void) const
Returns a vector to store the dbTags of the class members.
Definition: MovablePointerContainer.h:67
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
int receiveID(ID &v, const int &) const
Receives el vector.
Definition: Communicator.cc:80
int recvData(const Communicator &)
Receives members through the communicator argument.
Definition: MovableDeque.h:101