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

#include <Arith.h>

+ Collaboration diagram for Arith:

Public Member Functions

void addSpike (unsigned int synIndex, const double time)
 
void arg1 (double v)
 
void arg1x2 (double arg1, double arg2)
 
void arg2 (double v)
 
void arg3 (double v)
 
 Arith ()
 
double getArg1 () const
 
string getFunction () const
 
double getIdentifiedArg (unsigned int i) const
 
double getOutput () const
 
void process (const Eref &e, ProcPtr p)
 
void reinit (const Eref &e, ProcPtr p)
 
void setFunction (string v)
 
void setIdentifiedArg (unsigned int i, double val)
 
void setOutput (double v)
 

Static Public Member Functions

static const CinfoinitCinfo ()
 

Private Attributes

double arg1_
 
double arg2_
 
double arg3_
 
string function_
 
double output_
 

Friends

void testCopyMsgOps ()
 
void testTicks ()
 

Detailed Description

Definition at line 12 of file Arith.h.

Constructor & Destructor Documentation

Arith::Arith ( )

Definition at line 116 of file Arith.cpp.

117  : function_( "sum" ),
118  output_( 0.0 ),
119  arg1_( 0.0 ), arg2_( 0.0 ), arg3_( 0.0 )
120 {
121  ;
122 }
double arg1_
Definition: Arith.h:60
double arg3_
Definition: Arith.h:62
string function_
Definition: Arith.h:58
double arg2_
Definition: Arith.h:61
double output_
Definition: Arith.h:59

Member Function Documentation

void Arith::addSpike ( unsigned int  synIndex,
const double  time 
)

Inserts an event into the pendingEvents queue for spikes.

void Arith::arg1 ( double  v)

Definition at line 147 of file Arith.cpp.

References arg1_.

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

148 {
149  arg1_ = arg;
150 }
double arg1_
Definition: Arith.h:60

+ Here is the caller graph for this function:

void Arith::arg1x2 ( double  arg1,
double  arg2 
)

Definition at line 164 of file Arith.cpp.

References output_.

Referenced by initCinfo().

165 {
166  output_ = a1 * a2;
167 }
double output_
Definition: Arith.h:59

+ Here is the caller graph for this function:

void Arith::arg2 ( double  v)

Definition at line 152 of file Arith.cpp.

References arg2_.

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

153 {
154  arg2_ = arg;
155 }
double arg2_
Definition: Arith.h:61

+ Here is the caller graph for this function:

void Arith::arg3 ( double  v)

Definition at line 157 of file Arith.cpp.

References arg3_, and doReport.

Referenced by initCinfo().

158 {
159  if ( doReport )
160  cout << arg << " " << &arg3_ << endl;
161  arg3_ += arg;
162 }
double arg3_
Definition: Arith.h:62
static bool doReport
Definition: Arith.cpp:124

+ Here is the caller graph for this function:

double Arith::getArg1 ( ) const

Definition at line 190 of file Arith.cpp.

References arg1_.

Referenced by initCinfo(), and testLookupSetGet().

191 {
192  return arg1_;
193 }
double arg1_
Definition: Arith.h:60

+ Here is the caller graph for this function:

string Arith::getFunction ( ) const

Definition at line 175 of file Arith.cpp.

References function_.

Referenced by initCinfo().

176 {
177  return function_;
178 }
string function_
Definition: Arith.h:58

+ Here is the caller graph for this function:

double Arith::getIdentifiedArg ( unsigned int  i) const

Definition at line 195 of file Arith.cpp.

References arg1_, arg2_, arg3_, and output_.

Referenced by initCinfo(), and testLookupSetGet().

196 {
197  if ( i == 0 )
198  return output_;
199  if ( i == 1 )
200  return arg1_;
201  if ( i == 2 )
202  return arg2_;
203  if ( i == 3 )
204  return arg3_;
205  return 0;
206 }
double arg1_
Definition: Arith.h:60
double arg3_
Definition: Arith.h:62
double arg2_
Definition: Arith.h:61
double output_
Definition: Arith.h:59

+ Here is the caller graph for this function:

double Arith::getOutput ( ) const

Definition at line 185 of file Arith.cpp.

References output_.

Referenced by initCinfo(), testArith(), testFibonacci(), and testLookupSetGet().

186 {
187  return output_;
188 }
double output_
Definition: Arith.h:59

+ Here is the caller graph for this function:

const Cinfo * Arith::initCinfo ( )
static

Definition at line 22 of file Arith.cpp.

References arg1(), arg1x2(), arg2(), arg3(), arithCinfo, getArg1(), getFunction(), getIdentifiedArg(), getOutput(), Neutral::initCinfo(), output(), process(), reinit(), setFunction(), setIdentifiedArg(), and setOutput().

Referenced by test2ArgSetVec(), testArith(), testAssortedMsg(), testCreateMsg(), testFibonacci(), testGet(), testIsA(), testLookupSetGet(), testMsgField(), testSendMsg(), testSetGet(), testSetGetExtField(), testStrGet(), and testStrSet().

23 {
25  // Field Definitions
27  static ValueFinfo< Arith, string > function(
28  "function",
29  "Arithmetic function to perform on inputs.",
32  );
33  static ValueFinfo< Arith, double > outputValue(
34  "outputValue",
35  "Value of output as computed last timestep.",
38  );
39  static ReadOnlyValueFinfo< Arith, double > arg1Value(
40  "arg1Value",
41  "Value of arg1 as computed last timestep.",
43  );
44 
46  "anyValue",
47  "Value of any of the internal fields, output, arg1, arg2, arg3,"
48  "as specified by the index argument from 0 to 3.",
51  );
53  // MsgDest Definitions
55  static DestFinfo arg1( "arg1",
56  "Handles argument 1. This just assigns it",
58 
59  static DestFinfo arg2( "arg2",
60  "Handles argument 2. This just assigns it",
62 
63  static DestFinfo arg3( "arg3",
64  "Handles argument 3. This sums in each input, and clears each clock tick.",
66 
67  static DestFinfo arg1x2( "arg1x2",
68  "Store the product of the two arguments in output_",
70 
71  static DestFinfo process( "process",
72  "Handles process call",
74  static DestFinfo reinit( "reinit",
75  "Handles reinit call",
77 
79  // SharedFinfo Definitions
81  static Finfo* procShared[] = {
82  &process, &reinit
83  };
84  static SharedFinfo proc( "proc",
85  "Shared message for process and reinit",
86  procShared, sizeof( procShared ) / sizeof( const Finfo* )
87  );
88 
89  static Finfo* arithFinfos[] = {
90  &function, // Value
91  &outputValue, // Value
92  &arg1Value, // ReadOnly value
93  &anyValue, // LookupValue
94  &arg1, // DestFinfo
95  &arg2, // DestFinfo
96  &arg3, // DestFinfo
97  &arg1x2, // DestFinfo
98  output(), // SrcFinfo
99  &proc // SharedFinfo
100  };
101 
102  static Dinfo< Arith > dinfo;
103  static Cinfo arithCinfo (
104  "Arith",
106  arithFinfos,
107  sizeof( arithFinfos ) / sizeof ( Finfo* ),
108  &dinfo
109  );
110 
111  return &arithCinfo;
112 }
void setFunction(string v)
Definition: Arith.cpp:170
void reinit(const Eref &e, ProcPtr p)
Definition: Arith.cpp:138
double getIdentifiedArg(unsigned int i) const
Definition: Arith.cpp:195
void setOutput(double v)
Definition: Arith.cpp:180
Definition: Dinfo.h:60
void arg3(double v)
Definition: Arith.cpp:157
Definition: OpFunc.h:40
static SrcFinfo1< double > * output()
Definition: Arith.cpp:14
double getOutput() const
Definition: Arith.cpp:185
void process(const Eref &e, ProcPtr p)
Definition: Arith.cpp:125
void arg1x2(double arg1, double arg2)
Definition: Arith.cpp:164
void setIdentifiedArg(unsigned int i, double val)
Definition: Arith.cpp:208
Definition: OpFunc.h:27
void arg2(double v)
Definition: Arith.cpp:152
string getFunction() const
Definition: Arith.cpp:175
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
void arg1(double v)
Definition: Arith.cpp:147
double getArg1() const
Definition: Arith.cpp:190
Definition: Cinfo.h:18
static const Cinfo * arithCinfo
Definition: Arith.cpp:114
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Arith::process ( const Eref e,
ProcPtr  p 
)

Definition at line 125 of file Arith.cpp.

References arg1_, arg2_, arg3_, doReport, Eref::element(), Element::getName(), Eref::objId(), output(), and output_.

Referenced by initCinfo(), and testArith().

126 {
127  output_ = arg1_ + arg2_ + arg3_; // Doing a hard-coded function.
128  // cout << "process: " << e.element()->getName() << ", " << e.objId() << arg3_ << ", " << &arg3_ << endl;
129  if ( doReport ) {
130  cout <<
131  e.element()->getName() << ", " << e.objId() << " " <<
132  arg3_ << " " << &arg3_ << endl;
133  }
134  output()->send( e, output_ );
135  arg3_ = 0.0;
136 }
double arg1_
Definition: Arith.h:60
Element * element() const
Definition: Eref.h:42
static SrcFinfo1< double > * output()
Definition: Arith.cpp:14
double arg3_
Definition: Arith.h:62
double arg2_
Definition: Arith.h:61
static bool doReport
Definition: Arith.cpp:124
ObjId objId() const
Definition: Eref.cpp:57
double output_
Definition: Arith.h:59
const string & getName() const
Definition: Element.cpp:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Arith::reinit ( const Eref e,
ProcPtr  p 
)

Definition at line 138 of file Arith.cpp.

References arg1_, arg2_, arg3_, and output_.

Referenced by initCinfo().

139 {
140  // cout << "reinit: " << e.element()->getName() << ", " << e.objId() << arg3_ << endl;
141  arg1_ = 0.0;
142  arg2_ = 0.0;
143  arg3_ = 0.0;
144  output_ = 0.0;
145 }
double arg1_
Definition: Arith.h:60
double arg3_
Definition: Arith.h:62
double arg2_
Definition: Arith.h:61
double output_
Definition: Arith.h:59

+ Here is the caller graph for this function:

void Arith::setFunction ( string  v)

Definition at line 170 of file Arith.cpp.

References function_.

Referenced by initCinfo().

171 {
172  function_ = v;
173 }
string function_
Definition: Arith.h:58

+ Here is the caller graph for this function:

void Arith::setIdentifiedArg ( unsigned int  i,
double  val 
)

Definition at line 208 of file Arith.cpp.

References arg1_, arg2_, arg3_, and output_.

Referenced by initCinfo(), and testLookupSetGet().

209 {
210  if ( i == 0 )
211  output_ = val;
212  if ( i == 1 )
213  arg1_ = val;
214  if ( i == 2 )
215  arg2_ = val;
216  if ( i == 3 )
217  arg3_ = val;
218 }
double arg1_
Definition: Arith.h:60
double arg3_
Definition: Arith.h:62
double arg2_
Definition: Arith.h:61
double output_
Definition: Arith.h:59

+ Here is the caller graph for this function:

void Arith::setOutput ( double  v)

Definition at line 180 of file Arith.cpp.

References output_.

Referenced by initCinfo().

181 {
182  output_ = v;
183 }
double output_
Definition: Arith.h:59

+ Here is the caller graph for this function:

Friends And Related Function Documentation

void testCopyMsgOps ( )
friend

Definition at line 1083 of file testShell.cpp.

1084 {
1085  Eref sheller = Id().eref();
1086  Shell* shell = reinterpret_cast< Shell* >( sheller.data() );
1087  Id pa = shell->doCreate( "Neutral", Id(), "pa", 1, MooseGlobal );
1088  unsigned int size = 5;
1089 
1090 
1092  // Set up the objects.
1094  Id a1 = shell->doCreate( "Arith", pa, "a1", size, MooseGlobal );
1095  Id a2 = shell->doCreate( "Arith", pa, "a2", size, MooseGlobal );
1096 
1097  Id b1 = shell->doCreate( "Arith", pa, "b1", size, MooseGlobal );
1098  Id b2 = shell->doCreate( "Arith", pa, "b2", size, MooseGlobal );
1099 
1100  Id c1 = shell->doCreate( "Arith", pa, "c1", size, MooseGlobal );
1101  Id c2 = shell->doCreate( "Arith", pa, "c2", size, MooseGlobal );
1102 
1103  Id d1 = shell->doCreate( "Arith", pa, "d1", size, MooseGlobal );
1104  Id d2 = shell->doCreate( "Arith", pa, "d2", size, MooseGlobal );
1105 
1106  Id e1 = shell->doCreate( "Arith", pa, "e1", size, MooseGlobal );
1107  Id e2 = shell->doCreate( "Arith", pa, "e2", size, MooseGlobal );
1108 
1110  // Set up initial conditions and some scheduling.
1112  shell->doSetClock( 0, 1.0 );
1113  shell->doReinit();
1114  bool ret = 0;
1115  vector< double > init; // 12345
1116  for ( unsigned int i = 1; i < 6; ++i )
1117  init.push_back( i );
1118  ret = SetGet1< double >::setVec( a1, "arg1", init ); // 12345
1119  assert( ret );
1120  ret = SetGet1< double >::setVec( b1, "arg1", init ); // 12345
1121  assert( ret );
1122  ret = SetGet1< double >::setVec( c1, "arg1", init ); // 12345
1123  assert( ret );
1124  ret = SetGet1< double >::setVec( d1, "arg1", init ); // 12345
1125  assert( ret );
1126  ret = SetGet1< double >::setVec( e1, "arg1", init ); // 12345
1127  assert( ret );
1128 
1129 
1131  // Set up messaging
1133  // Should give 04000
1134  ObjId m1 = shell->doAddMsg( "Single",
1135  ObjId( a1, 3 ), "output", ObjId( a2, 1 ), "arg1" );
1136  assert( m1 != ObjId() );
1137 
1138  // Should give 33333
1139  ObjId m2 = shell->doAddMsg( "OneToAll",
1140  ObjId( b1, 2 ), "output", ObjId( b2, 0 ), "arg1" );
1141  assert( m2 != ObjId() );
1142 
1143  // Should give 12345
1144  ObjId m3 = shell->doAddMsg( "OneToOne",
1145  ObjId( c1, 0 ), "output", ObjId( c2, 0 ), "arg1" );
1146  assert( m3 != ObjId() );
1147 
1148  // Should give 01234
1149  ObjId m4 = shell->doAddMsg( "Diagonal",
1150  ObjId( d1, 0 ), "output", ObjId( d2, 0 ), "arg1" );
1151  assert( m4 != ObjId() );
1152 
1153  // Should give 54321
1154  ObjId m5 = shell->doAddMsg( "Sparse",
1155  ObjId( e1, 0 ), "output", ObjId( e2, 0 ), "arg1" );
1156  assert( m5 != ObjId() );
1157 
1159  m5, "setEntry", 0, 4, 0 );
1160  assert( ret );
1162  m5, "setEntry", 1, 3, 0 );
1163  assert( ret );
1165  m5, "setEntry", 2, 2, 0 );
1166  assert( ret );
1168  m5, "setEntry", 3, 1, 0 );
1169  assert( ret );
1171  m5, "setEntry", 4, 0, 0 );
1172  assert( ret );
1173 
1174  assert( ret );
1175 
1176  // ObjId clock( Id( 1 ), 0 );
1177 
1179  // Copy it
1181 
1182  Id pa2 = shell->doCopy( pa, Id(), "pa2", 1, false, false );
1183 
1185  // Pull out the child Ids.
1187  vector< Id > kids = Field< vector< Id > >::get( pa2, "children");
1188  assert ( kids.size() == 10 );
1189  shell->doUseClock( "/pa2/#", "process", 0 );
1190 
1191  unsigned int j = 0;
1192  assert( kids[j].element()->getName() == "a1" ); ++j;
1193  assert( kids[j].element()->getName() == "a2" ); ++j;
1194  assert( kids[j].element()->getName() == "b1" ); ++j;
1195  assert( kids[j].element()->getName() == "b2" ); ++j;
1196  assert( kids[j].element()->getName() == "c1" ); ++j;
1197  assert( kids[j].element()->getName() == "c2" ); ++j;
1198  assert( kids[j].element()->getName() == "d1" ); ++j;
1199  assert( kids[j].element()->getName() == "d2" ); ++j;
1200  assert( kids[j].element()->getName() == "e1" ); ++j;
1201  assert( kids[j].element()->getName() == "e2" ); ++j;
1202 
1203  /*
1204  vector< double > retVec;
1205  Field< double >::getVec( kids[0], "arg1Value", retVec );
1206  assert( retVec.size() == 5 );
1207  assert( doubleEq( retVec[i], init[i] ) );
1208  */
1209  for (unsigned int i = 0; i < 5; ++i ) {
1210  double x = Field< double >::get( ObjId( kids[0], i ), "arg1Value");
1211  assert( doubleEq( x, init[i] ) );
1212  }
1213 
1215  // Run it
1217 
1218  shell->doStart( 2 );
1219 
1221  // Check output.
1223 
1224  ret = checkOutput( kids[1], 0, 4, 0, 0, 0 );
1225  assert( ret );
1226  ret = checkOutput( kids[2], 1, 2, 3, 4, 5 );
1227  assert( ret );
1228  ret = checkOutput( kids[3], 3, 3, 3, 3, 3 );
1229  assert( ret );
1230  ret = checkOutput( kids[5], 1, 2, 3, 4, 5 );
1231  assert( ret );
1232  ret = checkOutput( kids[7], 0, 1, 2, 3, 4 );
1233  assert( ret );
1234  ret = checkOutput( kids[9], 5, 4, 3, 2, 1 );
1235  assert( ret );
1236 
1238  // Clean up.
1240  shell->doDelete( pa );
1241  shell->doDelete( pa2 );
1242 
1243  cout << "." << flush;
1244 }
Id init(int argc, char **argv, bool &doUnitTests, bool &doRegressionTests, unsigned int &benchmark)
Definition: main.cpp:150
void doStart(double runtime, bool notify=false)
Definition: Shell.cpp:332
char * data() const
Definition: Eref.cpp:41
bool checkOutput(Id e, double v0, double v1, double v2, double v3, double v4)
Definition: testShell.cpp:795
void doSetClock(unsigned int tickNum, double dt)
Definition: Shell.cpp:377
Definition: SetGet.h:236
Id doCopy(Id orig, ObjId newParent, string newName, unsigned int n, bool toGlobal, bool copyExtMsgs)
Returns the Id of the root of the copied tree upon success.
Definition: ShellCopy.cpp:16
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
Definition: Eref.h:26
void doReinit()
Definition: Shell.cpp:362
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2, A3 arg3)
Definition: SetGet.h:626
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
void doUseClock(string path, string field, unsigned int tick)
Definition: Shell.cpp:382
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
static bool setVec(ObjId destId, const string &field, const vector< A > &arg)
Definition: SetGet.h:188
Definition: Shell.h:43
void testTicks ( )
friend

Member Data Documentation

double Arith::arg1_
private

Definition at line 60 of file Arith.h.

Referenced by arg1(), getArg1(), getIdentifiedArg(), process(), reinit(), and setIdentifiedArg().

double Arith::arg2_
private

Definition at line 61 of file Arith.h.

Referenced by arg2(), getIdentifiedArg(), process(), reinit(), and setIdentifiedArg().

double Arith::arg3_
private

Definition at line 62 of file Arith.h.

Referenced by arg3(), getIdentifiedArg(), process(), reinit(), and setIdentifiedArg().

string Arith::function_
private

Definition at line 58 of file Arith.h.

Referenced by getFunction(), and setFunction().

double Arith::output_
private

Definition at line 59 of file Arith.h.

Referenced by arg1x2(), getIdentifiedArg(), getOutput(), process(), reinit(), setIdentifiedArg(), and setOutput().


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