MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DiagonalMsg Class Reference

#include <DiagonalMsg.h>

+ Inheritance diagram for DiagonalMsg:
+ Collaboration diagram for DiagonalMsg:

Public Member Functions

Msgcopy (Id origSrc, Id newSrc, Id newTgt, FuncId fid, unsigned int b, unsigned int n) const
 
 DiagonalMsg (Element *e1, Element *e2, unsigned int msgIndex)
 
ObjId findOtherEnd (ObjId end) const
 
Eref firstTgt (const Eref &src) const
 
int getStride () const
 
Id managerId () const
 
void setStride (int stride)
 
void sources (vector< vector< Eref > > &v) const
 
void targets (vector< vector< Eref > > &v) const
 
 ~DiagonalMsg ()
 
- Public Member Functions inherited from Msg
Elemente1 () const
 
Elemente2 () const
 
ObjId getAdjacent (ObjId) const
 
vector< string > getDestFieldsOnE1 () const
 
vector< string > getDestFieldsOnE2 () const
 
Id getE1 () const
 
Id getE2 () const
 
vector< string > getSrcFieldsOnE1 () const
 
vector< string > getSrcFieldsOnE2 () const
 
bool isForward (const Element *src) const
 
ObjId mid () const
 
 Msg (ObjId mid, Element *e1, Element *e2)
 Constructor. More...
 
virtual ~Msg ()
 Destructor. More...
 

Static Public Member Functions

static const CinfoinitCinfo ()
 Setup function for Element-style access to Msg fields. More...
 
static char * lookupMsg (unsigned int index)
 Static function for Msg access. More...
 
static unsigned int numMsg ()
 Msg lookup functions. More...
 
- Static Public Member Functions inherited from Msg
static void clearAllMsgs ()
 
static void deleteMsg (ObjId mid)
 
static const MsggetMsg (ObjId m)
 
static const CinfoinitCinfo ()
 
static unsigned int initMsgManagers ()
 
static bool isLastTrump ()
 True when MOOSE has been terminated and is being cleaned up. More...
 
static const MsglastMsg ()
 

Private Attributes

int stride_
 

Static Private Attributes

static Id managerId_
 
static vector< DiagonalMsg * > msg_
 

Friends

unsigned int Msg::initMsgManagers ()
 

Additional Inherited Members

- Protected Attributes inherited from Msg
Elemente1_
 Index of this Msg on the msg_ vector. More...
 
Elemente2_
 Element 1 attached to Msg. More...
 
ObjId mid_
 
- Static Protected Attributes inherited from Msg
static bool lastTrump_ = false
 Flag to indicate termination of program. More...
 
static Id msgManagerId_
 Element 2 attached to Msg. More...
 

Detailed Description

Connects up a series of data entries onto a matching series in a target Element. Inspects each entry, and uses the 'stride_' field to determine which should be its target.

* Suppose we have a stride of +1. Then
* Src:      1   2   3   4   n
* Dest: 2   3   4   5   n+1
*
* Suppose we have a stride of -2. Then
* Src:      1   2   3   4   n
* Dest: -   -   1   2   n-2
* 

Definition at line 28 of file DiagonalMsg.h.

Constructor & Destructor Documentation

DiagonalMsg::DiagonalMsg ( Element e1,
Element e2,
unsigned int  msgIndex 
)

Definition at line 17 of file DiagonalMsg.cpp.

References msg_.

Referenced by copy().

18  : Msg( ObjId( managerId_, (msgIndex != 0) ? msgIndex: msg_.size() ),
19  e1, e2 ),
20  stride_( 1 )
21 {
22  if ( msgIndex == 0 ) {
23  msg_.push_back( this );
24  } else {
25  if ( msg_.size() <= msgIndex )
26  msg_.resize( msgIndex + 1 );
27  msg_[ msgIndex ] = this;
28  }
29 }
Definition: ObjId.h:20
static vector< DiagonalMsg * > msg_
Definition: DiagonalMsg.h:72
static Id managerId_
Definition: DiagonalMsg.h:71
Msg(ObjId mid, Element *e1, Element *e2)
Constructor.
Definition: Msg.cpp:30

+ Here is the caller graph for this function:

DiagonalMsg::~DiagonalMsg ( )

Definition at line 31 of file DiagonalMsg.cpp.

References ObjId::dataIndex, Msg::mid_, and msg_.

32 {
33  assert( mid_.dataIndex < msg_.size() );
34  msg_[ mid_.dataIndex ] = 0; // ensure deleted ptr isn't reused.
35 }
ObjId mid_
Definition: Msg.h:178
static vector< DiagonalMsg * > msg_
Definition: DiagonalMsg.h:72
unsigned int dataIndex
Definition: ObjId.h:99

Member Function Documentation

Msg * DiagonalMsg::copy ( Id  origSrc,
Id  newSrc,
Id  newTgt,
FuncId  fid,
unsigned int  b,
unsigned int  n 
) const
virtual

Make a copy of this Msg. The original msg was on origSrc. The new Msg should go from newSrc to newTgt, and have the function fid, on bindIndex b. The copy may have to be a higher-order Msg type to handle arrays if n > 1. Note that n is not the number of msgs, but the multiplier by which numData will be scaled.

Implements Msg.

Definition at line 113 of file DiagonalMsg.cpp.

References Element::addMsgAndFunc(), DiagonalMsg(), Msg::e1(), Msg::e2(), Id::element(), Msg::mid(), setStride(), and stride_.

115 {
116  const Element* orig = origSrc.element();
117  if ( n <= 1 ) {
118  DiagonalMsg* ret = 0;
119  if ( orig == e1() ) {
120  ret = new DiagonalMsg( newSrc.element(), newTgt.element(), 0 );
121  ret->e1()->addMsgAndFunc( ret->mid(), fid, b );
122  } else if ( orig == e2() ) {
123  ret = new DiagonalMsg( newTgt.element(), newSrc.element(), 0 );
124  ret->e2()->addMsgAndFunc( ret->mid(), fid, b );
125  } else {
126  assert( 0 );
127  }
128  ret->setStride( stride_ );
129  return ret;
130  } else {
131  // Here we need a SliceMsg which goes from one 2-d array to another.
132  cout << "Error: DiagonalMsg::copy: DiagonalSliceMsg not yet implemented\n";
133  return 0;
134  }
135 }
Element * e2() const
Definition: Msg.h:68
ObjId mid() const
Definition: Msg.h:106
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
void addMsgAndFunc(ObjId mid, FuncId fid, BindIndex bindIndex)
Definition: Element.cpp:128
void setStride(int stride)
Definition: DiagonalMsg.cpp:81
Element * e1() const
Definition: Msg.h:61
DiagonalMsg(Element *e1, Element *e2, unsigned int msgIndex)
Definition: DiagonalMsg.cpp:17

+ Here is the call graph for this function:

ObjId DiagonalMsg::findOtherEnd ( ObjId  ) const
virtual

Find the other end of this Msg. In most cases this is a straightforward return of e1 or e2, plus perhaps a DataId. But in some complex msgs we need to figure out DataIds that match with the target. In many-to-one cases we just return the first entry. If no Element match, return ObjId( Id(), DataId::bad() ) If Element e matches but not DataId, return ObjId( e.id(), DataId::bad() )

Implements Msg.

Definition at line 93 of file DiagonalMsg.cpp.

References BADINDEX, ObjId::dataIndex, Msg::e1(), Msg::e2(), Id::element(), Element::id(), ObjId::id, Element::numData(), and stride_.

94 {
95  if ( f.id.element() == e1() ) {
96  int i2 = f.dataIndex + stride_;
97  if ( i2 >= 0 ) {
98  unsigned int ui2 = i2;
99  if ( ui2 < e2()->numData() )
100  return ObjId( e2()->id(), DataId( ui2 ) );
101  }
102  } else if ( f.id.element() == e2() ) {
103  int i1 = f.dataIndex - stride_;
104  if ( i1 >= 0 ) {
105  unsigned int ui1 = i1;
106  if ( ui1 < e1()->numData() )
107  return ObjId( e1()->id(), DataId( ui1 ));
108  }
109  }
110  return ObjId( 0, BADINDEX );
111 }
Element * e2() const
Definition: Msg.h:68
Definition: ObjId.h:20
Id id() const
Definition: Element.cpp:71
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
Element * e1() const
Definition: Msg.h:61
const unsigned int BADINDEX
Used by ObjId and Eref.
Definition: consts.cpp:25
unsigned int DataId
Definition: header.h:47
unsigned int dataIndex
Definition: ObjId.h:99

+ Here is the call graph for this function:

Eref DiagonalMsg::firstTgt ( const Eref src) const
virtual

Obtain the first target Eref for the specified Src Eref It is really meant only to work with messages with a single target ObjId for each given src, typically OneToOne.

Implements Msg.

Definition at line 37 of file DiagonalMsg.cpp.

References Eref::dataIndex(), Msg::e1_, Msg::e2_, Eref::element(), and stride_.

38 {
39  if ( src.element() == e1_ ) {
40  unsigned int nextData = src.dataIndex() + stride_;
41  return Eref( e2_, nextData );
42  }
43  else if ( src.element() == e2_ ) {
44  unsigned int nextData = src.dataIndex() - stride_;
45  return Eref( e1_, nextData );
46  }
47  return Eref( 0, 0 );
48 }
unsigned int dataIndex() const
Definition: Eref.h:50
Element * element() const
Definition: Eref.h:42
Definition: Eref.h:26
Element * e1_
Index of this Msg on the msg_ vector.
Definition: Msg.h:180
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181

+ Here is the call graph for this function:

int DiagonalMsg::getStride ( ) const

The stride is the increment to the src DataId that gives the dest DataId. It can be positive or negative, but bounds checking takes place and it does not wrap around. This function reads the stride.

Definition at line 88 of file DiagonalMsg.cpp.

References stride_.

Referenced by initCinfo().

89 {
90  return stride_;
91 }

+ Here is the caller graph for this function:

const Cinfo * DiagonalMsg::initCinfo ( )
static

Setup function for Element-style access to Msg fields.

Definition at line 154 of file DiagonalMsg.cpp.

References getStride(), Msg::initCinfo(), msgCinfo, and setStride().

Referenced by Msg::initMsgManagers().

155 {
157  // Field definitions.
159  static ValueFinfo< DiagonalMsg, int > stride(
160  "stride",
161  "The stride is the increment to the src DataId that gives the"
162  "dest DataId. "
163  "It can be positive or negative, but bounds checking"
164  "takes place and it does not wrap around.",
167  );
168 
169  static Finfo* msgFinfos[] = {
170  &stride, // value
171  };
172 
173  static Dinfo< short > dinfo;
174  static Cinfo msgCinfo (
175  "DiagonalMsg", // name
176  Msg::initCinfo(), // base class
177  msgFinfos,
178  sizeof( msgFinfos ) / sizeof( Finfo* ), // num Fields
179  &dinfo
180  );
181 
182  return &msgCinfo;
183 }
Definition: Dinfo.h:60
void setStride(int stride)
Definition: DiagonalMsg.cpp:81
static const Cinfo * msgCinfo
Definition: Msg.cpp:233
int getStride() const
Definition: DiagonalMsg.cpp:88
Definition: Cinfo.h:18
static const Cinfo * initCinfo()
Definition: Msg.cpp:165
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char * DiagonalMsg::lookupMsg ( unsigned int  index)
static

Static function for Msg access.

Definition at line 144 of file DiagonalMsg.cpp.

References msg_.

Referenced by Msg::clearAllMsgs(), and Msg::initMsgManagers().

145 {
146  assert( index < msg_.size() );
147  return reinterpret_cast< char* >( msg_[index] );
148 }
static vector< DiagonalMsg * > msg_
Definition: DiagonalMsg.h:72

+ Here is the caller graph for this function:

Id DiagonalMsg::managerId ( ) const

Definition at line 76 of file DiagonalMsg.cpp.

References managerId_.

77 {
79 }
static Id managerId_
Definition: DiagonalMsg.h:71
unsigned int DiagonalMsg::numMsg ( )
static

Msg lookup functions.

Static function for Msg access.

Definition at line 138 of file DiagonalMsg.cpp.

References msg_.

Referenced by Msg::clearAllMsgs(), and Msg::initMsgManagers().

139 {
140  return msg_.size();
141 }
static vector< DiagonalMsg * > msg_
Definition: DiagonalMsg.h:72

+ Here is the caller graph for this function:

void DiagonalMsg::setStride ( int  stride)

The stride is the increment to the src DataId that gives the dest DataId. It can be positive or negative, but bounds checking takes place and it does not wrap around. This function assigns the stride.

Definition at line 81 of file DiagonalMsg.cpp.

References Msg::e1(), Msg::e2(), Element::markRewired(), and stride_.

Referenced by copy(), initCinfo(), and testFibonacci().

82 {
83  stride_ = stride;
84  e1()->markRewired();
85  e2()->markRewired();
86 }
void markRewired()
Definition: Element.cpp:706
Element * e2() const
Definition: Msg.h:68
Element * e1() const
Definition: Msg.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DiagonalMsg::sources ( vector< vector< Eref > > &  v) const
virtual

Return all the sources of e2 from e1, that is, all the msgs coming into specified entries on e2 from e1.

ALLDATA used when the sources include all data entries on a source. Indexing is v[dataId in range e2.numData][src list]

Implements Msg.

Definition at line 50 of file DiagonalMsg.cpp.

References Msg::e1_, Msg::e2_, Element::numData(), and stride_.

51 {
52  v.clear();
53  v.resize( e2_->numData() );
54  int j = -stride_;
55  int numData1 = e1_->numData();
56  for ( unsigned int i = 0; i < e2_->numData(); ++i ) {
57  if ( j >= 0 && j < numData1 )
58  v[i].resize( 1, Eref( e1_, j ) );
59  j++;
60  }
61 }
Definition: Eref.h:26
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
Element * e1_
Index of this Msg on the msg_ vector.
Definition: Msg.h:180
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181

+ Here is the call graph for this function:

void DiagonalMsg::targets ( vector< vector< Eref > > &  v) const
virtual

Return all the targets of e1 on e2, that is, all the msgs going from specified entries on e1 to e2. ALLDATA used when the targets include all data entries on a target. Indexing is v[dataId in range e1.numData][tgt list]

Implements Msg.

Definition at line 63 of file DiagonalMsg.cpp.

References Msg::e1_, Msg::e2_, Element::numData(), and stride_.

64 {
65  v.clear();
66  v.resize( e1_->numData() );
67  int j = stride_;
68  int numData2 = e2_->numData();
69  for ( unsigned int i = 0; i < e1_->numData(); ++i ) {
70  if ( j >= 0 && j < numData2 )
71  v[i].resize( 1, Eref( e2_, j ) );
72  j++;
73  }
74 }
Definition: Eref.h:26
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
Element * e1_
Index of this Msg on the msg_ vector.
Definition: Msg.h:180
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181

+ Here is the call graph for this function:

Friends And Related Function Documentation

unsigned int Msg::initMsgManagers ( )
friend

Member Data Documentation

Id DiagonalMsg::managerId_
staticprivate

Definition at line 71 of file DiagonalMsg.h.

Referenced by Msg::initMsgManagers(), and managerId().

vector< DiagonalMsg * > DiagonalMsg::msg_
staticprivate

Definition at line 72 of file DiagonalMsg.h.

Referenced by DiagonalMsg(), lookupMsg(), numMsg(), and ~DiagonalMsg().

int DiagonalMsg::stride_
private

Definition at line 70 of file DiagonalMsg.h.

Referenced by copy(), findOtherEnd(), firstTgt(), getStride(), setStride(), sources(), and targets().


The documentation for this class was generated from the following files: