-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflatcoor.cpp
More file actions
136 lines (110 loc) · 4.07 KB
/
flatcoor.cpp
File metadata and controls
136 lines (110 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************
*
* DESCRIPTION: class FlatCoordinator
*
* AUTHOR: Amir Barylko & Jorge Beyoglonian
* Version 2: Daniel Rodriguez.
*
* EMAIL: mailto://amir@dc.uba.ar
* mailto://jbeyoglo@dc.uba.ar
* mailto://drodrigu@dc.uba.ar
*
* DATE: 27/06/1998
* DATE: 11/04/1999 (v2)
*
*******************************************************************/
// ** include files **//
#include "flatcoor.h" //headers
#include "flatcoup.h" // class FlatCoupledCell
#include "msgadm.h" // SingleMessageAdm
#include "cellstate.h"
using namespace std;
/*******************************************************************
* Method: receive
* Description: InitMessage
********************************************************************/
Processor &FlatCoordinator::receive( const InitMessage &msg )
{
FlatCoupledCell &coupled( static_cast< FlatCoupledCell & >( model() ) ) ;
coupled.initFunction();
lastChange( msg.time() ) ;
if( coupled.nextEventList().empty() )
nextChange( VTime::Inf );
else
nextChange( coupled.nextEventList().front().time );
DoneMessage doneMsg( msg.time(), this->Processor::id(), coupled.nextChange(), false ) ;
SingleMsgAdm::Instance().send( doneMsg, coupled.parentId() ) ;
return *this;
}
/*******************************************************************
* Method: receive
* Description: ExternalMessage
********************************************************************/
Processor &FlatCoordinator::receive( const ExternalMessage &msg )
{
FlatCoupledCell &coupled( static_cast< FlatCoupledCell & >( model() ) );
VirtualPortList *xList( coupled.externalList() );
CellPosition counter( coupled.dimension().dimension(), 0 );
register bool overflow = false;
receivedX++;
while (!overflow){
for (VirtualPortList::iterator cursor = xList[ counter.calculateIndex( coupled.dimension() )].begin(); cursor != xList[ counter.calculateIndex( coupled.dimension() ) ].end(); cursor++)
if ( *(cursor->second) == msg.port() )
coupled.externalFunction( msg.time(), *(const CellPosition *) &counter, true, msg.value(), cursor->first );
overflow = counter.next( coupled.dimension() );
}
lastChange( msg.time() ) ;
if( coupled.nextEventList().empty() )
nextChange( VTime::Inf );
else
nextChange( coupled.nextEventList().front().time - lastChange() );
DoneMessage doneMsg( msg.time(), this->Processor::id(), coupled.nextChange(), false ) ;
for (long i = 1; i <= receivedX; i++)
SingleMsgAdm::Instance().send( doneMsg, coupled.parentId() );
receivedX = 0;
if ( FlatDebug().Active() )
{
FlatDebug().Stream() << "VTime: " << msg.time() << endl;
coupled.cellState()->print( FlatDebug().Stream() ) ;
}
return *this;
}
/*******************************************************************
* Method: receive
* Description: IneternalMessage
********************************************************************/
Processor &FlatCoordinator::receive( const InternalMessage &msg )
{
FlatCoupledCell &coupled( static_cast< FlatCoupledCell & >( model() ) ) ;
coupled.internalFunction( msg.time() );
lastChange( msg.time() ) ;
if( coupled.nextEventList().empty() )
nextChange( VTime::Inf );
else
nextChange( coupled.nextEventList().front().time - lastChange() );
DoneMessage doneMsg( msg.time(), this->Processor::id(), coupled.nextChange(), false ) ;
SingleMsgAdm::Instance().send( doneMsg, coupled.parentId() ) ;
if ( FlatDebug().Active() )
{
FlatDebug().Stream() << "VTime: " << msg.time() << endl;
coupled.cellState()->print( FlatDebug().Stream() ) ;
}
return *this;
}
/*******************************************************************
* Method: receive
* Description: OutputMessage
********************************************************************/
Processor &FlatCoordinator::receive( const OutputMessage & )
{
MASSERT( false );
return *this;
}
/*******************************************************************
* Method: receive
********************************************************************/
Processor &FlatCoordinator::receive( const DoneMessage & )
{
MASSERT( false );
return *this;
}