xc
Channel.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 /* ****************************************************************** **
28 ** OpenSees - Open System for Earthquake Engineering Simulation **
29 ** Pacific Earthquake Engineering Research Center **
30 ** **
31 ** **
32 ** (C) Copyright 1999, The Regents of the University of California **
33 ** All Rights Reserved. **
34 ** **
35 ** Commercial use of this program without express permission of the **
36 ** University of California, Berkeley, is strictly prohibited. See **
37 ** file 'COPYRIGHT' in main directory for information on usage and **
38 ** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. **
39 ** **
40 ** Developed by: **
41 ** Frank McKenna (fmckenna@ce.berkeley.edu) **
42 ** Gregory L. Fenves (fenves@ce.berkeley.edu) **
43 ** Filip C. Filippou (filippou@ce.berkeley.edu) **
44 ** **
45 ** ****************************************************************** */
46 
47 // $Revision: 1.5 $
48 // $Date: 2005/11/23 18:27:24 $
49 // $Source: /usr/local/cvs/OpenSees/SRC/actor/channel/Channel.h,v $
50 
51 
52 #ifndef Channel_h
53 #define Channel_h
54 
55 // Written: fmk
56 // Created: 11/96
57 // Revision: A
58 //
59 // Purpose: This file contains the class definition for Channel.
60 // Channel is an abstract base class which defines the channel interface.
61 // A channel is a point of communication in a program, a mailbox to/from
62 // which data enters/leaves a program.
63 //
64 // What: "@(#) Channel.h, revA"
65 
66 
67 #include "xc_utils/src/kernel/CommandEntity.h"
68 #include <set>
69 
70 namespace XC {
71 class ChannelAddress;
72 class Message;
73 class MovableObject;
74 class Matrix;
75 class Vector;
76 class ID;
77 class FEM_ObjectBroker;
78 
80 //
91 class Channel: public CommandEntity
92  {
93  private:
94  static int numChannel;
95  int tag;
96  std::set<int> usedDbTags;
97  protected:
98  int sendMovable(int commitTag, MovableObject &);
99  int receiveMovable(int commitTag, MovableObject &, FEM_ObjectBroker &);
100  public:
101  Channel(CommandEntity *owr= nullptr);
102  inline virtual ~Channel(void) {}
103 
104  // methods to set up the channel in an actor space
110  virtual char *addToProgram(void) =0;
111  virtual int setUpConnection(void) =0;
115  virtual int setNextAddress(const ChannelAddress &theAddress) =0;
116  virtual ChannelAddress *getLastSendersAddress(void) =0;
117 
118  virtual bool isDatastore(void) const;
119  virtual int getDbTag(void) const;
120  bool checkDbTag(const int &dbTag);
121  const ID &getUsedTags(void) const;
122  void clearDbTags(void);
123  int getTag(void) const;
124 
125  // methods to send/receive messages and objects on channels.
132  virtual int sendObj(int commitTag, MovableObject &theObj, ChannelAddress *theAddress= nullptr) =0;
138  virtual int recvObj(int commitTag, MovableObject &theObj, FEM_ObjectBroker &theBroker, ChannelAddress *theAddress= nullptr) =0;
139  template <class inputIterator>
140  int sendObjs(int commitTag,const inputIterator &first,const inputIterator &last,ChannelAddress *theAddress= nullptr);
141  template <class inputIterator>
142  int recvObjs(int commitTag,const inputIterator &first,const inputIterator &last, FEM_ObjectBroker &, ChannelAddress *theAddress= nullptr);
143 
153  virtual int sendMsg(int dbTag, int commitTag, const Message &theMsg, ChannelAddress *theAddress= nullptr) =0;
154 
164  virtual int recvMsg(int dbTag, int commitTag, Message &theMsg, ChannelAddress *theAddress= nullptr) =0;
165 
175  virtual int sendMatrix(int dbTag, int commitTag, const Matrix &theMatrix,ChannelAddress *theAddress= nullptr) =0;
176 
186  virtual int recvMatrix(int dbTag, int commitTag, Matrix &theMatrix, ChannelAddress *theAddress= nullptr) =0;
187 
197  virtual int sendVector(int dbTag, int commitTag, const Vector &theVector, ChannelAddress *theAddress= nullptr) =0;
198 
208  virtual int recvVector(int dbTag, int commitTag, Vector &theVector, ChannelAddress *theAddress= nullptr) =0;
209 
219  virtual int sendID(int dbTag, int commitTag,const ID &theID, ChannelAddress *theAddress= nullptr) =0;
220 
230  virtual int recvID(int dbTag, int commitTag,ID &theID, ChannelAddress *theAddress= nullptr) =0;
231  };
232 
234 template <class inputIterator>
235 int Channel::sendObjs(int commitTag,const inputIterator &first,const inputIterator &last,ChannelAddress *theAddress)
236  {
237  int retval= 0;
238  for(inputIterator i= first;i!=last;i++)
239  {
240  retval= sendObj(commitTag,*i,theAddress);
241  if(retval!=0)
242  break;
243  }
244  return retval;
245  }
246 
248 template <class inputIterator>
249 int Channel::recvObjs(int commitTag,const inputIterator &first,const inputIterator &last, FEM_ObjectBroker &ob, ChannelAddress *theAddress)
250  {
251  int retval= 0;
252  for(inputIterator i= first;i!=last;i++)
253  {
254  retval= recvObj(commitTag,*i,ob,theAddress);
255  if(retval!=0)
256  break;
257  }
258  return retval;
259  }
260 
261 } // end of XC namespace
262 
263 #endif
virtual int sendID(int dbTag, int commitTag, const ID &theID, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the ID object theID to another Channel object.
Float vector abstraction.
Definition: Vector.h:93
virtual int recvMsg(int dbTag, int commitTag, Message &theMsg, ChannelAddress *theAddress=nullptr)=0
Invoked to send the data in the Message object theMsg to another Channel object.
virtual int recvMatrix(int dbTag, int commitTag, Matrix &theMatrix, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the Matrix object theMatrix to another Channel object.
virtual int recvVector(int dbTag, int commitTag, Vector &theVector, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the Vector object theVector to another Channel object.
int recvObjs(int commitTag, const inputIterator &first, const inputIterator &last, FEM_ObjectBroker &, ChannelAddress *theAddress=nullptr)
Receive an object sequence.
Definition: Channel.h:249
virtual int sendMsg(int dbTag, int commitTag, const Message &theMsg, ChannelAddress *theAddress=nullptr)=0
A method invoked to send the data in the Message object theMsg to another Channel object...
int getTag(void) const
Return the object tag.
Definition: Channel.cpp:126
Object that can move between processes.
Definition: MovableObject.h:99
void clearDbTags(void)
Reset used database tags set.
Definition: Channel.cpp:122
virtual int recvObj(int commitTag, MovableObject &theObj, FEM_ObjectBroker &theBroker, ChannelAddress *theAddress=nullptr)=0
To receive the object theObj with the commit tag commitTag from a remote Channel whose address is giv...
virtual int sendObj(int commitTag, MovableObject &theObj, ChannelAddress *theAddress=nullptr)=0
To send the object theObj and the commit tag commitTag to a remote Channel whose address is given by ...
virtual char * addToProgram(void)=0
When creating remote actors the channels created in the actor space need to know how to contact the s...
FEM_ObjectBroker is is an object broker class for the finite element method.
Definition: FEM_ObjectBroker.h:145
Vector of integers.
Definition: ID.h:93
int sendMovable(int commitTag, MovableObject &)
Send theObject.
Definition: Channel.cpp:130
virtual int recvID(int dbTag, int commitTag, ID &theID, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the ID object theID to another Channel object.
const ID & getUsedTags(void) const
Return the list of dbTags already used.
Definition: Channel.cpp:95
bool checkDbTag(const int &dbTag)
Check if a dbTag is already used.
Definition: Channel.cpp:107
virtual int sendMatrix(int dbTag, int commitTag, const Matrix &theMatrix, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the Matrix object theMatrix to another Channel object.
virtual int setNextAddress(const ChannelAddress &theAddress)=0
A method invoked to set specify the next address that the next messages to be sent if {sendMessage()}...
int receiveMovable(int commitTag, MovableObject &, FEM_ObjectBroker &)
Receive theObject.
Definition: Channel.cpp:137
Channel is an abstract base class which defines the channel interface.
Definition: Channel.h:91
int sendObjs(int commitTag, const inputIterator &first, const inputIterator &last, ChannelAddress *theAddress=nullptr)
Send the objects on interval [first,last).
Definition: Channel.h:235
Message between processes.
Definition: Message.h:76
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:34
virtual int sendVector(int dbTag, int commitTag, const Vector &theVector, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the Vector object theVector to another Channel object.
Definition: ChannelAddress.h:69
Matrix of floats.
Definition: Matrix.h:108
virtual int getDbTag(void) const
Return next available database tag.
Definition: Channel.cpp:91
virtual bool isDatastore(void) const
Return true if channel is a data store.
Definition: Channel.cpp:81
Channel(CommandEntity *owr=nullptr)
Constructor.
Definition: Channel.cpp:73