00001 /* 00002 * reactionSelector.hh 00003 * 00004 * Created on: Jul 23, 2009 00005 * Author: msneddon 00006 */ 00007 00008 #ifndef REACTIONSELECTOR_HH_ 00009 #define REACTIONSELECTOR_HH_ 00010 00011 00012 00013 #include "../NFcore.hh" 00014 //#include <vector> 00015 00016 00017 using namespace std; 00018 00019 00020 namespace NFcore 00021 { 00022 //Forward Declarations 00023 class ReactionClass; 00024 00025 00026 // Abstract Interface Class for the Reaction Selection Algorithm 00027 class ReactionSelector { 00028 00029 public: 00030 00031 //Initializations and basic functionality 00032 ReactionSelector() {}; 00033 virtual ~ReactionSelector() {}; 00034 00035 virtual double refactorPropensities() = 0; 00036 00037 00038 virtual double update(ReactionClass *r,double oldA, double newA) = 0; 00039 virtual double getNextReactionClass(ReactionClass *&rc) = 0; 00040 virtual double getAtot() = 0; 00041 00042 }; 00043 00044 00045 class DirectSelector : public ReactionSelector { 00046 00047 public: 00048 //Initializations and basic functionality 00049 DirectSelector(vector <ReactionClass *> &rxns); 00050 virtual ~DirectSelector(); 00051 00052 virtual double refactorPropensities(); 00053 00054 00055 virtual double update(ReactionClass *r,double oldA, double newA); 00056 virtual double getNextReactionClass(ReactionClass *&rc); 00057 virtual double getAtot(); 00058 00059 00060 protected: 00061 double Atot; 00062 int n_reactions; 00063 ReactionClass ** reactionClassList; 00064 00065 }; 00066 00067 00068 class LogClassSelector : public ReactionSelector { 00069 00070 public: 00071 //Initializations and basic functionality 00072 LogClassSelector(vector <ReactionClass *> &rxns); 00073 virtual ~LogClassSelector(); 00074 00075 virtual double refactorPropensities(); 00076 00077 00078 virtual double update(ReactionClass *r,double oldA, double newA); 00079 virtual double getNextReactionClass(ReactionClass *&rc); 00080 virtual double getAtot(); 00081 00082 00083 protected: 00084 00085 int calculateClass(double a); 00086 00087 void place(ReactionClass *r,int logClass,double a); 00088 00089 void setLogClassToActive(int logClass); 00090 void setLogClassToInactive(int logClass); 00091 00092 00093 // The absolute maximum log class 00094 int maxClassLimit; 00095 int minClassLimit; 00096 int totalLogClassCount; 00097 00098 //the current range of log classes that we have to loop over 00099 int currentHighClass; 00100 int currentLowClass; 00101 00102 00103 // A 2d array of the logClasses 00104 ReactionClass *** logClassList; 00105 00106 // A 1d array of the logClasses sizes 00107 int *logClassSize; 00108 int *logClassCapacity; 00109 00110 00111 //An array to keep track of the log classes with positive values 00112 int *activeLogClasses; 00113 bool *isLogClassActive; 00114 int n_activeLogClasses; 00115 00116 00117 00118 // A 1d array of the propensity sum of the logClass 00119 double *logClassPropensity; 00120 00121 00122 00123 int *mapRxnIdToLogClass; 00124 int *mapRxnIdToLogClassPosition; 00125 00126 00127 00128 00129 double Atot; 00130 int n_reactions; 00131 ReactionClass ** reactionClassList; 00132 00133 }; 00134 00135 00136 00137 } 00138 00139 00140 00141 00142 00143 00144 00145 00146 #endif /* REACTIONSELECTOR_HH_ */