MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Element.h
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2013 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 #ifndef _ELEMENT_H
10 #define _ELEMENT_H
11 
12 class SrcFinfo;
13 class FuncOrder;
14 
20 class Element
21 {
22 public:
34  Element( Id id, const Cinfo* c, const string& name );
35 
39  virtual ~Element();
40 
44  virtual Element* copyElement( Id newParent, Id newId,
45  unsigned int n, bool toGlobal ) const = 0;
47  // Information access fields
49 
53  const string& getName() const;
54 
58  void setName( const string& val );
59 
61  virtual unsigned int numData() const = 0;
62 
64  virtual unsigned int numLocalData() const = 0;
65 
67  virtual unsigned int localDataStart() const = 0;
68 
70  virtual unsigned int numField( unsigned int rawIndex ) const = 0;
71 
76  virtual unsigned int totNumLocalField() const = 0;
77 
79  virtual unsigned int getNode( unsigned int dataIndex ) const = 0;
80 
82  virtual unsigned int startDataIndex( unsigned int nodeNum ) const = 0;
83 
87  virtual unsigned int rawIndex( unsigned int dataIndex ) const = 0;
88 
92  Id id() const;
93 
98  virtual bool hasFields() const = 0;
99 
101  virtual bool isGlobal() const = 0;
102 
105  virtual unsigned int getNumOnNode( unsigned int node ) const = 0;
106 
112  int getTick() const;
113 
122  void setTick( int t );
123 
128  void innerSetTick( unsigned int tick );
129 
131  // data access stuff
133 
149  virtual char* data( unsigned int rawIndex,
150  unsigned int fieldIndex = 0 ) const = 0;
151 
156  virtual void resize( unsigned int newNumData ) = 0;
157 
162  virtual void resizeField(
163  unsigned int rawIndex, unsigned int newNumField ) = 0;
164 
166 
167 
173  void addMsg( ObjId mid );
174 
178  void dropMsg( ObjId mid );
179 
183  void clearBinding( BindIndex b );
184 
189  void addMsgAndFunc( ObjId mid, FuncId fid, BindIndex bindIndex );
190 
196  const vector< MsgFuncBinding >* getMsgAndFunc( BindIndex b ) const;
197 
202  bool hasMsgs( BindIndex b ) const;
203 
207  void showFields() const;
208 
212  void showMsg() const;
213 
217  void digestMessages();
218 
223  void putTargetsInDigest(
224  unsigned int srcNum, const MsgFuncBinding& mfb,
225  const FuncOrder& fo,
226  vector< vector< bool > >& targetNodes
227  );
232  unsigned int srcNum, vector< vector< bool > >& targetNodes );
233 
237  const Cinfo* cinfo() const;
238 
246  static void destroyElementTree( const vector< Id >& tree );
247 
252  void markAsDoomed();
253  bool isDoomed() const;
254 
259  void markRewired();
260 
264  void printMsgDigest( unsigned int srcIndex, unsigned int dataIndex ) const;
265 
270  void dropAllMsgsFromSrc( Id src );
272  // Utility functions for message traversal
274 
280  const vector< MsgDigest >& msgDigest( unsigned int index );
281 
286  unsigned int findBinding( MsgFuncBinding b ) const;
287 
291  const vector< ObjId >& msgIn() const;
292 
298  ObjId findCaller( FuncId fid ) const;
299 
304  unsigned int getInputMsgs( vector< ObjId >& caller, FuncId fid)
305  const;
306 
311  unsigned int getNeighbors( vector< Id >& ret, const Finfo* finfo )
312  const;
313 
320  unsigned int getFieldsOfOutgoingMsg(
321  ObjId mid, vector< pair< BindIndex, FuncId > >& ret ) const;
322 
330  unsigned int getMsgTargetAndFunctions( DataId srcDataId,
331  const SrcFinfo* finfo ,
332  vector< ObjId >& tgt,
333  vector< string >& func
334  ) const;
335 
343  unsigned int getMsgSourceAndSender( FuncId fid,
344  vector< ObjId >& src,
345  vector< string >& sender
346  ) const;
347 
352  vector< ObjId > getMsgTargets( DataId srcDataId,
353  const SrcFinfo* finfo ) const;
354 
359  void clearAllMsgs();
360 
369  virtual void zombieSwap( const Cinfo* zCinfo );
370 
372  void replaceCinfo( const Cinfo* newCinfo );
373 
379  unsigned int getInputsWithTgtIndex(
380  vector< pair< Id, unsigned int> >& ret, const DestFinfo* finfo)
381  const;
382 
383 private:
388  unsigned int getOutputs( vector< Id >& ret, const SrcFinfo* finfo )
389  const;
390 
395  unsigned int getInputs( vector< Id >& ret, const DestFinfo* finfo )
396  const;
397 
398 
399  string name_;
400 
401  Id id_;
402 
406  const Cinfo* cinfo_;
407 
412  vector< ObjId > m_;
413 
423  vector< vector < MsgFuncBinding > > msgBinding_;
424 
437  vector< vector < MsgDigest > > msgDigest_;
438 
440  int tick_;
441 
444 
446  bool isDoomed_;
447 };
448 
449 #endif // _ELEMENT_H
void markRewired()
Definition: Element.cpp:706
const vector< ObjId > & msgIn() const
Definition: Element.cpp:387
void putOffNodeTargetsInDigest(unsigned int srcNum, vector< vector< bool > > &targetNodes)
Definition: Element.cpp:517
void setName(const string &val)
Definition: Element.cpp:61
vector< ObjId > getMsgTargets(DataId srcDataId, const SrcFinfo *finfo) const
Definition: Element.cpp:856
unsigned int getOutputs(vector< Id > &ret, const SrcFinfo *finfo) const
Definition: Element.cpp:749
unsigned short BindIndex
Definition: header.h:62
void clearBinding(BindIndex b)
Definition: Element.cpp:136
void markAsDoomed()
Definition: Element.cpp:696
unsigned int getMsgTargetAndFunctions(DataId srcDataId, const SrcFinfo *finfo, vector< ObjId > &tgt, vector< string > &func) const
Definition: Element.cpp:772
unsigned int getInputsWithTgtIndex(vector< pair< Id, unsigned int > > &ret, const DestFinfo *finfo) const
Definition: Element.cpp:918
void printMsgDigest(unsigned int srcIndex, unsigned int dataIndex) const
Definition: Element.cpp:711
virtual void zombieSwap(const Cinfo *zCinfo)
virtual func, this base version must be called by all derived classes
Definition: Element.cpp:159
void addMsgAndFunc(ObjId mid, FuncId fid, BindIndex bindIndex)
Definition: Element.cpp:128
Definition: ObjId.h:20
unsigned int getMsgSourceAndSender(FuncId fid, vector< ObjId > &src, vector< string > &sender) const
Definition: Element.cpp:828
void dropMsg(ObjId mid)
Definition: Element.cpp:113
void innerSetTick(unsigned int tick)
Definition: Element.cpp:191
Id id() const
Definition: Element.cpp:71
bool isRewired_
True if messages have been changed and need to digestMessages.
Definition: Element.h:443
unsigned int getInputs(vector< Id > &ret, const DestFinfo *finfo) const
Definition: Element.cpp:887
int getTick() const
Definition: Element.cpp:186
unsigned int getFieldsOfOutgoingMsg(ObjId mid, vector< pair< BindIndex, FuncId > > &ret) const
Definition: Element.cpp:1009
virtual Element * copyElement(Id newParent, Id newId, unsigned int n, bool toGlobal) const =0
void showFields() const
Definition: Element.cpp:623
bool hasMsgs(BindIndex b) const
Definition: Element.cpp:307
Id id_
Name of the Element.
Definition: Element.h:401
const vector< MsgDigest > & msgDigest(unsigned int index)
Definition: Element.cpp:289
virtual unsigned int getNumOnNode(unsigned int node) const =0
static char dataIndex[]
Definition: mfield.cpp:406
virtual ~Element()
Definition: Element.cpp:31
vector< ObjId > m_
Definition: Element.h:412
ObjId findCaller(FuncId fid) const
Definition: Element.cpp:350
virtual unsigned int numField(unsigned int rawIndex) const =0
Returns number of field entries for specified data.
string name_
Definition: Element.h:399
void digestMessages()
Definition: Element.cpp:569
virtual bool hasFields() const =0
const vector< MsgFuncBinding > * getMsgAndFunc(BindIndex b) const
Definition: Element.cpp:300
const Cinfo * cinfo() const
Definition: Element.cpp:66
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
void addMsg(ObjId mid)
Definition: Element.cpp:79
virtual bool isGlobal() const =0
True if there is a copy of every dataEntry on all nodes.
virtual unsigned int localDataStart() const =0
Returns index of first data entry on this node.
const Cinfo * cinfo_
Stores the unique identifier for Element.
Definition: Element.h:406
virtual unsigned int numLocalData() const =0
Returns number of local data entries on this node.
vector< vector< MsgDigest > > msgDigest_
Definition: Element.h:437
virtual unsigned int totNumLocalField() const =0
unsigned int getInputMsgs(vector< ObjId > &caller, FuncId fid) const
Definition: Element.cpp:984
void showMsg() const
Definition: Element.cpp:313
Element(Id id, const Cinfo *c, const string &name)
Definition: Element.cpp:17
void putTargetsInDigest(unsigned int srcNum, const MsgFuncBinding &mfb, const FuncOrder &fo, vector< vector< bool > > &targetNodes)
Definition: Element.cpp:466
static char name[]
Definition: mfield.cpp:401
static void destroyElementTree(const vector< Id > &tree)
Definition: Element.cpp:676
virtual char * data(unsigned int rawIndex, unsigned int fieldIndex=0) const =0
void dropAllMsgsFromSrc(Id src)
Definition: Element.cpp:197
Definition: Id.h:17
void setTick(int t)
Definition: Element.cpp:251
unsigned int getNeighbors(vector< Id > &ret, const Finfo *finfo) const
Definition: Element.cpp:949
virtual unsigned int rawIndex(unsigned int dataIndex) const =0
virtual unsigned int getNode(unsigned int dataIndex) const =0
Returns node number of specified dataIndex.
vector< vector< MsgFuncBinding > > msgBinding_
Definition: Element.h:423
unsigned int FuncId
Definition: header.h:42
bool isDoomed() const
Definition: Element.cpp:701
void clearAllMsgs()
Used upon ending of MOOSE session, to rapidly clear out messages.
Definition: Element.cpp:150
int tick_
Returns tick on which element is scheduled. -1 for disabled.
Definition: Element.h:440
const string & getName() const
Definition: Element.cpp:56
virtual void resizeField(unsigned int rawIndex, unsigned int newNumField)=0
void replaceCinfo(const Cinfo *newCinfo)
Support function for zombieSwap, replaces Cinfo.
Definition: Element.cpp:740
unsigned int DataId
Definition: header.h:47
unsigned int findBinding(MsgFuncBinding b) const
Definition: Element.cpp:374
Definition: Cinfo.h:18
virtual unsigned int startDataIndex(unsigned int nodeNum) const =0
Returns start dataIndex on specified node.
virtual void resize(unsigned int newNumData)=0
bool isDoomed_
True if the element is marked for destruction.
Definition: Element.h:446
Definition: Finfo.h:12