MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Arith.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 <queue>
11 #include "header.h"
12 #include "Arith.h"
13 
16  "output",
17  "Sends out the computed value"
18  );
19  return &output;
20 }
21 
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 }
113 
115 
117  : function_( "sum" ),
118  output_( 0.0 ),
119  arg1_( 0.0 ), arg2_( 0.0 ), arg3_( 0.0 )
120 {
121  ;
122 }
123 
124 static bool doReport = 0;
125 void Arith::process( const Eref& e, ProcPtr p )
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 }
137 
138 void Arith::reinit( const Eref& e, ProcPtr p )
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 }
146 
147 void Arith::arg1( const double arg )
148 {
149  arg1_ = arg;
150 }
151 
152 void Arith::arg2( const double arg )
153 {
154  arg2_ = arg;
155 }
156 
157 void Arith::arg3( const double arg )
158 {
159  if ( doReport )
160  cout << arg << " " << &arg3_ << endl;
161  arg3_ += arg;
162 }
163 
164 void Arith::arg1x2( double a1, double a2 )
165 {
166  output_ = a1 * a2;
167 }
168 
169 
170 void Arith::setFunction( const string v )
171 {
172  function_ = v;
173 }
174 
175 string Arith::getFunction() const
176 {
177  return function_;
178 }
179 
180 void Arith::setOutput( double v )
181 {
182  output_ = v;
183 }
184 
185 double Arith::getOutput() const
186 {
187  return output_;
188 }
189 
190 double Arith::getArg1() const
191 {
192  return arg1_;
193 }
194 
195 double Arith::getIdentifiedArg( unsigned int i ) const
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 }
207 
208 void Arith::setIdentifiedArg( unsigned int i, double val )
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 }
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
double arg1_
Definition: Arith.h:60
Definition: Dinfo.h:60
Element * element() const
Definition: Eref.h:42
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
double arg3_
Definition: Arith.h:62
void process(const Eref &e, ProcPtr p)
Definition: Arith.cpp:125
string function_
Definition: Arith.h:58
double arg2_
Definition: Arith.h:61
void arg1x2(double arg1, double arg2)
Definition: Arith.cpp:164
void setIdentifiedArg(unsigned int i, double val)
Definition: Arith.cpp:208
static bool doReport
Definition: Arith.cpp:124
ObjId objId() const
Definition: Eref.cpp:57
Definition: OpFunc.h:27
Definition: Eref.h:26
void arg2(double v)
Definition: Arith.cpp:152
double output_
Definition: Arith.h:59
Arith()
Definition: Arith.cpp:116
string getFunction() const
Definition: Arith.cpp:175
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
void arg1(double v)
Definition: Arith.cpp:147
double getArg1() const
Definition: Arith.cpp:190
const string & getName() const
Definition: Element.cpp:56
Definition: Cinfo.h:18
static const Cinfo * arithCinfo
Definition: Arith.cpp:114
Definition: Finfo.h:12