XC Open source finite element analysis program
MovableMap.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 //MovableMap
28 
29 
30 #ifndef MovableMap_h
31 #define MovableMap_h
32 
33 #include "MovableObject.h"
34 #include "MovableID.h"
35 #include "MovableString.h"
36 #include <string>
37 #include <map>
38 #include "utility/tagged/TaggedObject.h"
39 #include "CommParameters.h"
40 
41 namespace XC {
42 
44 //
46 template <class T>
48  {
49  protected:
50  typedef std::map<std::string,T *> map_objects;
51  typedef typename map_objects::iterator iterator;
52  map_objects objects;
53  T *(FEM_ObjectBroker::*ptrFunc)(int);
54 
55  DbTagData &getDbTagData(void) const;
56  int sendData(CommParameters &);
57  int recvData(const CommParameters &);
58  public:
59  MovableMap(const map_objects &map,T *(FEM_ObjectBroker::*pF)(int));
60  const map_objects &getMap(void) const
61  { return objects; }
62 
63  int sendSelf(CommParameters &);
64  int recvSelf(const CommParameters &);
65  };
66 
67 
69 template <class T>
70 XC::MovableMap<T>::MovableMap(const map_objects &map,T *(FEM_ObjectBroker::*pF)(int))
71  :MovableObject(0), objects(map), ptrFunc(pF) {}
72 
75 template <class T>
77  {
78  static DbTagData retval(5);
79  return retval;
80  }
81 
83 template <class T>
85  {
86  const size_t sz= objects.size();
87  setDbTagDataPos(0,sz);
88  int res= 0;
89  if(sz>0)
90  {
91  DbTagData labelData(sz);
92  DbTagData dbTags(sz);
93  ID classTags(sz);
94  int loc= 0;
95  for(iterator i=objects.begin();i!=objects.end();i++,loc++)
96  {
97  res+= cp.sendString((*i).first,labelData,CommMetaData(loc));
98  classTags(loc)= (*i).second->getClassTag();
99  res+= cp.sendMovable(*(*i).second,dbTags,CommMetaData(loc));
100  }
101  res+= labelData.send(getDbTagData(),cp,CommMetaData(1));
102  res+= dbTags.send(getDbTagData(),cp,CommMetaData(2));
103  res+= cp.sendID(classTags,getDbTagData(),CommMetaData(3));
104  }
105  return res;
106  }
107 
109 template <class T>
111  {
112  const size_t sz= getDbTagDataPos(0);
113  int res= 0;
114  if(sz>0)
115  {
116  DbTagData labelData(sz);
117  int res= labelData.receive(getDbTagData(),cp,CommMetaData(1));
118  DbTagData dbTags(sz);
119  res+= dbTags.receive(getDbTagData(),cp,CommMetaData(2));
120  ID classTags(sz);
121  res+= cp.receiveID(classTags,getDbTagData(),CommMetaData(3));
122  std::string label;
123  T *tmp= nullptr;
124  for(size_t i= 0;i<sz;i++)
125  {
126  res+= cp.receiveString(label,labelData,CommMetaData(i));
127  const int dbTag= dbTags.getDbTagDataPos(i);
128  tmp= getBrokedMovable(dbTag,classTags(i),cp,ptrFunc);
129  if(tmp)
130  {
131  res+= tmp->recvSelf(cp);
132  objects[label]= tmp;
133  }
134  else
135  std::cerr << "Error en MovableMap::recvData label= "
136  << label << std::endl;
137  }
138  }
139  return res;
140  }
141 
143 template <class T>
145  {
146  inicComm(5);
147  int result= sendData(cp);
148 
149  const int dataTag= getDbTag(cp);
150  result+= cp.sendIdData(getDbTagData(),dataTag);
151  if(result < 0)
152  std::cerr << "MovableMap::sendSelf() - failed to send data\n";
153  return result;
154  }
155 
157 template <class T>
159  {
160  inicComm(5);
161  const int dataTag = getDbTag();
162  int result= cp.receiveIdData(getDbTagData(),dataTag);
163  if(result<0)
164  std::cerr << "MovableMap::recvSelf() - failed to receive data\n";
165  else
166  result+= recvData(cp);
167  return result;
168  }
169 
170 template <class T>
171 int sendMap(const std::map<std::string,T *> &m,CommParameters &cp,DbTagData &dt,const CommMetaData &meta)
172  {
173  MovableMap<T> mm(m,nullptr);
174  return cp.sendMovable(mm,dt,meta);
175  }
176 
177 template <class T>
178 int receiveMap(std::map<std::string,T *> &v,const CommParameters &cp,DbTagData &dt,const CommMetaData &meta,T *(FEM_ObjectBroker::*ptrFunc)(int))
179  {
180  MovableMap<T> mm(v,ptrFunc);
181  int res= cp.receiveMovable(mm,dt,meta);
182  v= mm.getMap();
183  return res;
184  }
185 
186 } // end of XC namespace
187 
188 #endif
189 
int sendMovable(MovableObject &, DbTagData &, const CommMetaData &)
Sends a movable object through the channel being passed as parameter.
Definition: CommParameters.cc:959
int send(DbTagData &, CommParameters &, const CommMetaData &) const
Sends the object.
Definition: DbTagData.cc:102
DbTagData & getDbTagData(void) const
Returns a vector para almacenar los dbTags de los miembros de la clase.
Definition: MovableMap.h:76
int getDbTag(void) const
Returns the tag para la database.
Definition: MovableObject.cpp:92
Vector que almacena los dbTags de los miembros de la clase.
Definition: DbTagData.h:43
int sendID(const ID &, const int &)
Sends vector.
Definition: CommParameters.cc:72
int receiveIdData(DbTagData &, const int &) const
Recibe el miembro data through the channel being passed as parameter.
Definition: CommParameters.cc:396
int sendIdData(const DbTagData &, const int &)
Sends miembro data through the channel being passed as parameter.
Definition: CommParameters.cc:392
int recvData(const CommParameters &)
Receives members through the channel being passed as parameter.
Definition: MovableMap.h:110
FEM_ObjectBroker is is an object broker class for the finite element method. All methods are virtual ...
Definition: FEM_ObjectBroker.h:138
int receiveString(std::string &v, DbTagData &, const CommMetaData &) const
Recibe la cadena de caracteres through the channel being passed as parameter.
Definition: CommParameters.cc:324
int receiveID(ID &v, const int &) const
Recibe el vector.
Definition: CommParameters.cc:79
int sendSelf(CommParameters &)
Envia el objeto through the channel being passed as parameter.
Definition: MovableMap.h:144
Template class for maps that can move between processes.
Definition: MovableMap.h:47
Object that can move between processes.
Definition: MovableObject.h:91
int receiveMovable(MovableObject &, DbTagData &, const CommMetaData &) const
Receives a movable object trhrough the channel being passed as parameter.
Definition: CommParameters.cc:969
const int & getDbTagDataPos(const size_t &i) const
Returns the integer in the position being passed as parameter.
Definition: DbTagData.cc:58
int recvSelf(const CommParameters &)
Receives object through the channel being passed as parameter.
Definition: MovableMap.h:158
int sendString(const std::string &, DbTagData &, const CommMetaData &)
Envía la cadena de caracteres through the channel being passed as parameter.
Definition: CommParameters.cc:316
Definition: ID.h:77
MovableMap(const map_objects &map, T *(FEM_ObjectBroker::*pF)(int))
Constructor.
Definition: MovableMap.h:70
int receive(DbTagData &, const CommParameters &, const CommMetaData &)
Recibe el objeto.
Definition: DbTagData.cc:106
int sendData(CommParameters &)
Send members through the channel being passed as parameter.
Definition: MovableMap.h:84
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
const int & getDbTagDataPos(const int &i) const
Returns the data at the i-th position.
Definition: DistributedBase.cc:49
void setDbTagDataPos(const int &i, const int &v)
Sets the data at the i-th position.
Definition: DistributedBase.cc:53