/home/msneddon/eclipse/galileoSR1_cpp/workspace/NFsim/src/NFfunction/NFfunction.hh

Go to the documentation of this file.
00001 #ifndef NFFUNCTION_HH_
00002 #define NFFUNCTION_HH_
00003 
00004 
00005 #include "muParser/muParser.h"
00006 #include "../NFcore/NFcore.hh"
00007 
00008 
00009 using namespace std;
00010 
00011 
00012 namespace NFcore {
00013 
00014         class System;
00015         class ReactionClass;
00016         class Observable;
00017 
00019 
00073         class FuncFactory {
00074                 public:
00075 
00084                         static mu::Parser * create(string function, vector <string> & variableNames, vector <double *> & variablePtrs);
00085 
00086 
00092                         static mu::Parser * create();
00093 
00099                         static double Eval(mu::Parser *p);
00100 
00105                         static void test();
00106 
00107         };
00108 
00109 
00110 
00112 
00118         class GlobalFunction {
00119 
00120                 public:
00127                         GlobalFunction(string name,
00128                                         string funcExpression,
00129                                         vector <string> &varRefNames,
00130                                         vector <string> &varRefTypes,
00131                                         vector <string> &paramNames,
00132                                         System *s);
00133 
00137                         ~GlobalFunction();
00138 
00142                         void prepareForSimulation(System *s);
00143 
00144                         void updateParameters(System *s);
00145 
00146 
00147 
00151                         string getNiceName() const {return name+"()";};
00152 
00156                         string getName() const {return name;};
00157 
00162                         void printDetails();
00163                         void printDetails(System *s);
00164 
00165 
00170                         void attatchRxn(ReactionClass *r);
00171 
00172 
00173                         int getNumOfVarRefs() const { return (int) n_varRefs; };
00174                         string getVarRefName(int varRefIndex) const {
00175                                 return varRefNames[varRefIndex];
00176                         }
00177                         string getVarRefType(int varRefIndex) const {
00178                                 return varRefTypes[varRefIndex];
00179                         }
00180 
00186                         mu::Parser *p;
00187 
00188                 protected:
00189 
00190                         string name;
00191                         string funcExpression;
00192 
00193                         unsigned int n_varRefs;
00194                         string *varRefNames;
00195                         string *varRefTypes;
00196 
00197                         unsigned int n_params;
00198                         string *paramNames;
00199         };
00200 
00201 
00202 
00203         class FunctionReference
00204         {
00205 
00206                 public:
00207                         FunctionReference(string name, string expression, string referencedFuncName) {
00208                                 this->name = name;
00209                                 this->expression=expression;
00210                                 this->referencedFuncName=referencedFuncName;
00211                         };
00212                         ~FunctionReference() {};
00213 
00214                         string name;
00215                         string expression;
00216                         string referencedFuncName;
00217 
00218         };
00219 
00220 
00221 
00222 
00223         class StateCounter {
00224                 public:
00225                         StateCounter(string name, MoleculeType *mt, string stateName);
00226                         ~StateCounter();
00227 
00228                         void add(Molecule *m);
00229                         void reset() { value=0; };
00230                         int getValue() const { return (int)value; };
00231 
00232 
00233                         string name;
00234                         MoleculeType *mt;
00235                         int stateIndex;
00236                         double value;
00237         };
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247         class LocalFunction {
00248 
00249                 public:
00250 
00251                         LocalFunction(System *s,
00252                                                                 string name,
00253                                                                 string originalExpression,
00254                                                                 string parsedExpression,
00255                                                                 vector <string> &args,
00256                                                                 vector <string> &varRefNames,
00257                                                                 vector <string> &varObservableNames,
00258                                                                 vector <Observable *> & varObservables,
00259                                                                 vector <int> &varRefScope,
00260                                                                 vector <string> paramNames);
00261                         ~LocalFunction();
00262 
00263 
00264                         string getName() const;
00265                         string getNiceName() const;
00266                         string getExpression() const;
00267                         string getParsedExpression() const;
00268 
00269 
00270                         void printDetails(System *s);
00271 
00272                         void prepareForSimulation(System *s);
00273 
00274 
00275                         double getValue(Molecule *m, int scope);
00276                         double evaluateOn(Molecule *m, int scope);
00277 
00278 
00279                         void addTypeIMoleculeDependency(MoleculeType *mt);
00280                         void updateParameters(System *s);
00281 
00282                         static const int SPECIES = 0;
00283                         static const int MOLECULE = 1;
00284 
00285                         mu::Parser *p;
00286                 protected:
00287 
00288 
00289                         string name;
00290                         string nicename;
00291                         string originalExpression;
00292                         string parsedExpression;
00293 
00294                         unsigned int n_args;
00295                         string *argNames;
00296 
00297 
00298                         unsigned int n_params;
00299                         string *paramNames;
00300 
00301                         unsigned int n_varRefs;
00302                         string *varRefNames;
00303                         string *varObservableNames;
00304                         int *varRefScope;
00305                         Observable **varLocalObservables;
00306 
00307 
00308                         static list <Molecule *> molList;
00309                         static list <Molecule *>::iterator molIter;
00310 
00311                         //Here we store back pointers into both type I and type II molecules
00312                         //Remember that type I molecules must store the value of this function
00313                         //locally so that it can be used in DOR reactions.  Type II molecules
00314                         //do not have the local value explicitly, but local functions should still
00315                         //know 'of' them in case of future speedups that might use this information
00316 
00317                         //@todo : change these to arrays from vectors!!!
00318 
00319                         vector <MoleculeType *> typeI_mol;
00320                         vector <int> typeI_localFunctionIndex;
00321                         int n_typeIImolecules;
00322                         MoleculeType ** typeII_mol;
00323                         //vector <MoleculeType *> typeII_mol;
00324                         vector <int> typeII_localFunctionIndex;
00325 
00326 
00327         };
00328 
00329 
00330 
00331         class CompositeFunction {
00332                         public:
00333                                 CompositeFunction(System *s,
00334                                                 string name,
00335                                                 string expression,
00336                                                 vector <string> &functions,
00337                                                 vector <string> & argNames,
00338                                                 vector <string> &paramNames);
00339                                 ~CompositeFunction();
00340 
00341 
00342                                 string getName() const {return name;};
00343 
00344                                 void updateParameters(System *s);
00345 
00346                                 void finalizeInitialization(System *s);
00347 
00348                                 void prepareForSimulation(System *s);
00349 
00350 
00351                                 void setGlobalObservableDependency(ReactionClass *r, System *s);
00352 
00353                                 double evaluateOn(Molecule **molList, int *scope, int *curReactantCounts, int n_reactants);
00354 
00355                                 void printDetails(System *s);
00356 
00357                                 int getNumOfArgs() const;
00358                                 string getArgName(int aIndex) const;
00359 
00360                                 void addTypeIMoleculeDependency(MoleculeType *mt);
00361 
00362 
00363                         protected:
00364 
00365                                 string name;
00366                                 string originalExpression;
00367                                 string parsedExpression;
00368 
00369 
00370                                 unsigned int n_allFuncs;
00371                                 string * allFuncNames;
00372 
00373 
00374                                 unsigned int n_args;
00375                                 string * argNames;
00376 
00377                                 unsigned int n_params;
00378                                 string *paramNames;
00379 
00380                                 //here are the referenced global functions
00381                                 int n_gfs;
00382                                 string * gfNames;
00383                                 GlobalFunction ** gfs;
00384                                 double * gfValues;
00385 
00386                                 //stores list of all local functions
00387                                 int n_lfs;
00388                                 string * lfNames;
00389                                 LocalFunction ** lfs;
00390 
00391 
00392                                 int n_reactantCounts;
00393                                 double * reactantCount;
00394 
00395                                 //stores list of all local functions and how they are referenced
00396                                 int n_refLfs;
00397                                 int *refLfInds;
00398                                 string *refLfRefNames;
00399                                 int *refLfScopes;
00400                                 double * refLfValues;
00401 
00402                                 mu::Parser *p;
00403                 };
00404 
00405 
00406 
00407 
00408 
00409 }
00410 
00411 
00412 
00413 
00414 
00415 
00416 
00417 
00418 
00419 
00420 
00421 
00422 
00423 
00424 #endif /*NFFUNCTION_HH_*/

Generated on Thu Dec 9 11:02:48 2010 for NFsim by  doxygen 1.5.4