xc
MovableMap.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 //MovableMap
29 
30 
31 #ifndef MovableMap_h
32 #define MovableMap_h
33 
34 #include "MovablePointerContainer.h"
35 #include "MovableID.h"
36 #include "MovableString.h"
37 #include <string>
38 #include <map>
39 #include "utility/tagged/TaggedObject.h"
40 #include "Communicator.h"
41 
42 namespace XC {
43 
45 //
47 template <class T>
49  {
50  protected:
51  typedef std::map<std::string,T *> map_objects;
52  typedef typename map_objects::iterator iterator;
53  map_objects objects;
54 
55  int sendData(Communicator &);
56  int recvData(const Communicator &);
57  public:
58  MovableMap(const map_objects &map,T *(FEM_ObjectBroker::*pF)(int));
59  const map_objects &getMap(void) const
60  { return objects; }
61 
62  };
63 
64 
66 template <class T>
67 MovableMap<T>::MovableMap(const map_objects &map,T *(FEM_ObjectBroker::*pF)(int))
68  : MovablePointerContainer<T>(0,pF), objects(map) {}
69 
71 template <class T>
73  {
74  const size_t sz= objects.size();
75  this->setDbTagDataPos(0,sz);
76  int res= 0;
77  if(sz>0)
78  {
79  DbTagData labelData(sz);
80  DbTagData dbTags(sz);
81  ID classTags(sz);
82  int loc= 0;
83  for(iterator i=objects.begin();i!=objects.end();i++,loc++)
84  {
85  res+= comm.sendString((*i).first,labelData,CommMetaData(loc));
86  classTags(loc)= (*i).second->getClassTag();
87  res+= comm.sendMovable(*(*i).second,dbTags,CommMetaData(loc));
88  }
89  DbTagData &dbTagData= this->getDbTagData();
90  res+= labelData.send(dbTagData,comm,CommMetaData(1));
91  res+= dbTags.send(dbTagData,comm,CommMetaData(2));
92  res+= comm.sendID(classTags,dbTagData,CommMetaData(3));
93  }
94  return res;
95  }
96 
98 template <class T>
100  {
101  const size_t sz= this->getDbTagDataPos(0);
102  int res= 0;
103  if(sz>0)
104  {
105  DbTagData &dbTagData= this->getDbTagData();
106  DbTagData labelData(sz);
107  int res= labelData.receive(dbTagData,comm,CommMetaData(1));
108  DbTagData dbTags(sz);
109  res+= dbTags.receive(dbTagData,comm,CommMetaData(2));
110  ID classTags(sz);
111  res+= comm.receiveID(classTags,dbTagData,CommMetaData(3));
112  std::string label;
113  T *tmp= nullptr;
114  for(size_t i= 0;i<sz;i++)
115  {
116  res+= comm.receiveString(label,labelData,CommMetaData(i));
117  const int dbTag= dbTags.getDbTagDataPos(i);
118  tmp= this->getBrokedObject(dbTag,classTags(i),comm);
119  if(tmp)
120  {
121  res+= tmp->recvSelf(comm);
122  objects[label]= tmp;
123  }
124  else
125  std::cerr << "Error in MovableMap::recvData label= "
126  << label << std::endl;
127  }
128  }
129  return res;
130  }
131 
132 template <class T>
133 int sendMap(const std::map<std::string,T *> &m,Communicator &comm,DbTagData &dt,const CommMetaData &meta)
134  {
135  MovableMap<T> mm(m,nullptr);
136  return comm.sendMovable(mm,dt,meta);
137  }
138 
139 template <class T>
140 int receiveMap(std::map<std::string,T *> &v,const Communicator &comm,DbTagData &dt,const CommMetaData &meta,T *(FEM_ObjectBroker::*ptrFunc)(int))
141  {
142  MovableMap<T> mm(v,ptrFunc);
143  int res= comm.receiveMovable(mm,dt,meta);
144  v= mm.getMap();
145  return res;
146  }
147 
148 } // end of XC namespace
149 
150 #endif
151 
int sendMovable(MovableObject &, DbTagData &, const CommMetaData &)
Sends a movable object through the communicator argument.
Definition: Communicator.cc:1163
MovableMap(const map_objects &map, T *(FEM_ObjectBroker::*pF)(int))
Constructor.
Definition: MovableMap.h:67
int receiveString(std::string &v, DbTagData &, const CommMetaData &) const
Receives la text string through the communicator argument.
Definition: Communicator.cc:337
Communication parameters between processes.
Definition: Communicator.h:66
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
int sendData(Communicator &)
Send members through the communicator argument.
Definition: MovableMap.h:72
int sendID(const ID &, const int &)
Sends vector.
Definition: Communicator.cc:73
const int & getDbTagDataPos(const int &i) const
Returns the data at the i-th position.
Definition: DistributedBase.cc:53
int sendString(const std::string &, DbTagData &, const CommMetaData &)
Send the text string through the communicator argument.
Definition: Communicator.cc:328
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
Template class for maps that can move between processes.
Definition: MovableMap.h:48
int recvData(const Communicator &)
Receives members through the communicator argument.
Definition: MovableMap.h:99