MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OneToOneDataIndexMsg.cpp
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-2010 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 
10 #include "header.h"
11 #include "OneToOneDataIndexMsg.h"
12 
13 // Initializing static variables
15 vector< OneToOneDataIndexMsg* > OneToOneDataIndexMsg::msg_;
16 
18  const Eref& e1, const Eref& e2,
19  unsigned int msgIndex )
20  : Msg( ObjId( managerId_, (msgIndex != 0) ? msgIndex: msg_.size() ),
21  e1.element(), e2.element() )
22 {
23  if ( msgIndex == 0 ) {
24  msg_.push_back( this );
25  } else {
26  if ( msg_.size() <= msgIndex )
27  msg_.resize( msgIndex + 1 );
28  msg_[ msgIndex ] = this;
29  }
30 }
31 
33 {
34  assert( mid_.dataIndex < msg_.size() );
35  msg_[ mid_.dataIndex ] = 0; // ensure deleted ptr isn't reused.
36 }
37 
46 {
47  if ( src.element() == e1_ ) {
48  return Eref( e2_, src.dataIndex(), 0 );
49  } else if ( src.element() == e2_ ) {
50  return Eref( e1_, src.dataIndex() );
51  }
52  return Eref( 0, 0 );
53 }
54 
55 // We don't permit e1 to have fields at this point.
56 void OneToOneDataIndexMsg::sources( vector< vector< Eref > > & v) const
57 {
58  v.resize( 0 );
59  unsigned int n = e1_->numData();
60  if ( n > e2_->numData() )
61  n = e2_->numData();
62  v.resize( e2_->numData() );
63  for ( unsigned int i = 0; i < n; ++i ) {
64  v[i].resize( 1, Eref( e1_, i ) );
65  }
66 }
67 
68 void OneToOneDataIndexMsg::targets( vector< vector< Eref > > & v) const
69 {
70  unsigned int n = e1_->numData();
71  v.resize( e1_->numData() );
72  if ( n > e2_->numData() )
73  n = e2_->numData();
74  for ( unsigned int i = 0; i < n; ++i ) {
75  v[i].resize( 1, Eref( e2_, i ) );
76  }
77 }
78 
80 {
82 }
83 
85 {
86  if ( f.element() == e1() )
87  return ObjId( e2()->id(), f.dataIndex );
88  else if ( f.element() == e2() )
89  return ObjId( e1()->id(), f.dataIndex );
90 
91  return ObjId( 0, BADINDEX );
92 }
93 
94 Msg* OneToOneDataIndexMsg::copy( Id origSrc, Id newSrc, Id newTgt,
95  FuncId fid, unsigned int b, unsigned int n ) const
96 {
97  const Element* orig = origSrc.element();
98  // This works both for 1-copy and for n-copies
99  OneToOneDataIndexMsg* ret = 0;
100  if ( orig == e1() ) {
101  ret = new OneToOneDataIndexMsg( newSrc.eref(), newTgt.eref(), 0 );
102  ret->e1()->addMsgAndFunc( ret->mid(), fid, b );
103  } else if ( orig == e2() ) {
104  ret = new OneToOneDataIndexMsg( newTgt.eref(), newSrc.eref(), 0 );
105  ret->e2()->addMsgAndFunc( ret->mid(), fid, b );
106  } else
107  assert( 0 );
108  // ret->e1()->addMsgAndFunc( ret->mid(), fid, b );
109  return ret;
110 }
111 
114 {
115  return msg_.size();
116 }
117 
119 char* OneToOneDataIndexMsg::lookupMsg( unsigned int index )
120 {
121  assert( index < msg_.size() );
122  return reinterpret_cast< char* >( msg_[index] );
123 }
124 
126 // Here we set up the MsgManager portion of the class.
128 
130 {
132  // Field definitions. Nothing here.
134 
135  static Dinfo< short > dinfo;
136  static Cinfo msgCinfo (
137  "OneToOneDataIndexMsg", // name
138  Msg::initCinfo(), // base class
139  0, // Finfo array
140  0, // Num Fields
141  &dinfo
142  );
143 
144  return &msgCinfo;
145 }
146 
148 
Element * e2() const
Definition: Msg.h:68
ObjId mid() const
Definition: Msg.h:106
static const Cinfo * initCinfo()
Setup function for Element-style access to Msg fields.
ObjId findOtherEnd(ObjId end) const
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Dinfo.h:60
unsigned int dataIndex() const
Definition: Eref.h:50
void addMsgAndFunc(ObjId mid, FuncId fid, BindIndex bindIndex)
Definition: Element.cpp:128
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
Element * element() const
Definition: Eref.h:42
Id id() const
Definition: Element.cpp:71
void sources(vector< vector< Eref > > &v) const
static vector< OneToOneDataIndexMsg * > msg_
void targets(vector< vector< Eref > > &v) const
static const Cinfo * msgCinfo
Definition: Msg.cpp:233
Definition: Eref.h:26
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
Definition: Msg.h:18
Element * e1_
Index of this Msg on the msg_ vector.
Definition: Msg.h:180
ObjId mid_
Definition: Msg.h:178
Element * e1() const
Definition: Msg.h:61
Eref firstTgt(const Eref &src) const
Element * element() const
Definition: ObjId.cpp:124
static unsigned int numMsg()
Msg lookup functions.
Msg * copy(Id origSrc, Id newSrc, Id newTgt, FuncId fid, unsigned int b, unsigned int n) const
Definition: Id.h:17
static char * lookupMsg(unsigned int index)
Static function for Msg access.
OneToOneDataIndexMsg(const Eref &e1, const Eref &e2, unsigned int msgIndex)
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181
unsigned int FuncId
Definition: header.h:42
const unsigned int BADINDEX
Used by ObjId and Eref.
Definition: consts.cpp:25
static const Cinfo * oneToOneMsgCinfo
Definition: Cinfo.h:18
static const Cinfo * initCinfo()
Definition: Msg.cpp:165
unsigned int dataIndex
Definition: ObjId.h:99