MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OneToAllMsg.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 "OneToAllMsg.h"
12 
13 // Initializing static variables
15 vector< OneToAllMsg* > OneToAllMsg::msg_;
16 
17 OneToAllMsg::OneToAllMsg( Eref e1, Element* e2, unsigned int msgIndex )
18  :
19  Msg(
20  ObjId( managerId_, (msgIndex != 0) ? msgIndex: msg_.size() ),
21  e1.element(), e2
22  ),
23  i1_( e1.dataIndex() )
24 {
25  if ( msgIndex == 0 ) {
26  msg_.push_back( this );
27  } else {
28  if ( msg_.size() <= msgIndex )
29  msg_.resize( msgIndex + 1 );
30  msg_[ msgIndex ] = this;
31  }
32 }
33 
35 {
36  assert( mid_.dataIndex < msg_.size() );
37  msg_[ mid_.dataIndex ] = 0; // ensure deleted ptr isn't reused.
38 }
39 
40 Eref OneToAllMsg::firstTgt( const Eref& src ) const
41 {
42  if ( src.element() == e1_ )
43  return Eref( e2_, 0 );
44  else if ( src.element() == e2_ )
45  return Eref( e1_, i1_ );
46  return Eref( 0, 0 );
47 }
48 
49 void OneToAllMsg::sources( vector< vector < Eref > >& v ) const
50 {
51  // Same single source for all targets.
52  v.clear();
53  vector< Eref > temp( 1, Eref( e1_, i1_ ) );
54  v.assign( e2_->numData(), temp );
55 }
56 
57 void OneToAllMsg::targets( vector< vector< Eref > >& v ) const
58 {
59  v.clear();
60  v.resize( e1_->numData() );
61  v[i1_].resize( 1, Eref( e2_, ALLDATA ) );
62 }
63 
65 {
67 }
68 
70 {
71  if ( f.element() == e1() ) {
72  if ( f.dataIndex == i1_ )
73  return ObjId( e2()->id(), 0 );
74  } else if ( f.element() == e2() ) {
75  return ObjId( e1()->id(), i1_ );
76  }
77 
78  return ObjId( 0, BADINDEX );
79 }
80 
81 Msg* OneToAllMsg::copy( Id origSrc, Id newSrc, Id newTgt,
82  FuncId fid, unsigned int b, unsigned int n ) const
83 {
84  const Element* orig = origSrc.element();
85  if ( n <= 1 ) {
86  OneToAllMsg* ret = 0;
87  if ( orig == e1() ) {
88  ret = new OneToAllMsg(
89  Eref( newSrc.element(), i1_ ), newTgt.element(), 0 );
90  ret->e1()->addMsgAndFunc( ret->mid(), fid, b );
91  } else if ( orig == e2() ) {
92  ret = new OneToAllMsg(
93  Eref( newTgt.element(), i1_ ), newSrc.element(), 0 );
94  ret->e2()->addMsgAndFunc( ret->mid(), fid, b );
95  } else {
96  assert( 0 );
97  }
98  return ret;
99  } else {
100  // Here we need a SliceMsg which goes from one 2-d array to another.
101  cout << "Error: OneToAllMsg::copy: SliceToSliceMsg not yet implemented\n";
102  return 0;
103  }
104 }
105 
107 // Here we set up the MsgManager portion of the class.
109 
111 {
113  // Field definitions.
116  "i1",
117  "DataId of source Element.",
120  );
121 
122  static Finfo* msgFinfos[] = {
123  &i1, // value
124  };
125 
126  static Dinfo< short > dinfo;
127  static Cinfo msgCinfo (
128  "OneToAllMsg", // name
129  Msg::initCinfo(), // base class
130  msgFinfos,
131  sizeof( msgFinfos ) / sizeof( Finfo* ), // num Fields
132  &dinfo
133  );
134 
135  return &msgCinfo;
136 }
137 
139 
144 {
145  return i1_;
146 }
147 
149 {
150  i1_ = i1;
151  e1()->markRewired();
152  e2()->markRewired();
153 }
154 
156 unsigned int OneToAllMsg::numMsg()
157 {
158  return msg_.size();
159 }
160 
162 char* OneToAllMsg::lookupMsg( unsigned int index )
163 {
164  assert( index < msg_.size() );
165  return reinterpret_cast< char* >( msg_[index] );
166 }
void markRewired()
Definition: Element.cpp:706
static char * lookupMsg(unsigned int index)
Static function for Msg access.
Element * e2() const
Definition: Msg.h:68
ObjId mid() const
Definition: Msg.h:106
Id managerId() const
Definition: OneToAllMsg.cpp:64
DataId getI1() const
Return the first DataId.
Eref firstTgt(const Eref &src) const
Definition: OneToAllMsg.cpp:40
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
void setI1(DataId i1)
Definition: Dinfo.h:60
void addMsgAndFunc(ObjId mid, FuncId fid, BindIndex bindIndex)
Definition: Element.cpp:128
Definition: ObjId.h:20
Element * element() const
Definition: Eref.h:42
DataId i1_
Definition: OneToAllMsg.h:49
static const Cinfo * initCinfo()
Setup function for Element-style access to Msg fields.
Msg * copy(Id origSrc, Id newSrc, Id newTgt, FuncId fid, unsigned int b, unsigned int n) const
Definition: OneToAllMsg.cpp:81
const unsigned int ALLDATA
Used by ObjId and Eref.
Definition: consts.cpp:22
static Id managerId_
Definition: OneToAllMsg.h:50
static char dataIndex[]
Definition: mfield.cpp:406
OneToAllMsg(Eref e1, Element *e2, unsigned int msgIndex)
Definition: OneToAllMsg.cpp:17
static const Cinfo * assignmentMsgCinfo
static const Cinfo * msgCinfo
Definition: Msg.cpp:233
Definition: Eref.h:26
static vector< OneToAllMsg * > msg_
Definition: OneToAllMsg.h:51
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
Element * element() const
Definition: ObjId.cpp:124
ObjId findOtherEnd(ObjId end) const
Definition: OneToAllMsg.cpp:69
Definition: Id.h:17
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181
void sources(vector< vector< Eref > > &v) const
Definition: OneToAllMsg.cpp:49
unsigned int FuncId
Definition: header.h:42
const unsigned int BADINDEX
Used by ObjId and Eref.
Definition: consts.cpp:25
unsigned int DataId
Definition: header.h:47
Definition: Cinfo.h:18
static const Cinfo * initCinfo()
Definition: Msg.cpp:165
void targets(vector< vector< Eref > > &v) const
Definition: OneToAllMsg.cpp:57
static unsigned int numMsg()
Assign the first DataId.
unsigned int dataIndex
Definition: ObjId.h:99
Definition: Finfo.h:12