00001 #ifndef NG_CELL_HH_ 00002 #define NG_CELL_HH_ 00003 00004 #include <math.h> 00005 #include <fstream> 00006 00007 #include "../../../NFcore/NFcore.hh" 00008 #include "../../../NFutil/NFutil.hh" 00009 #include "util.hh" 00010 00011 #include "environment.hh" 00012 00013 00014 00015 using namespace std; 00016 using namespace NFcore; 00017 00018 00019 class Environment; 00020 00029 class AgentCell 00030 { 00031 public: 00032 00033 AgentCell( 00034 System *s, 00035 Environment *e, 00036 double speed, 00037 double rotDiffusionConstant, 00038 double cheYpThreshold, 00039 double startTime, 00040 string outputDirectoryPath 00041 ); 00042 00043 ~AgentCell(); 00044 00045 double stepTo(double endTime, double dt); 00046 void equilibriate(double duration, double dt); 00047 00048 //Functions to get current position and direction 00049 double getXposition() const { return pos[X]; }; 00050 double getYposition() const { return pos[Y]; }; 00051 double getZposition() const { return pos[Z]; }; 00052 double getXdirection() const { return dir[X]; }; 00053 double getYdirection() const { return dir[Y]; }; 00054 double getZdirection() const { return dir[Z]; }; 00055 00056 //Constants that can be used 00057 static const int X = 0; 00058 static const int Y = 1; 00059 static const int Z = 2; 00060 00061 static const int TUMBLE = 0; 00062 static const int SWIM = 1; 00063 00064 static const int APART = 0; 00065 static const int BUNDLED = 1; 00066 00067 void swimToNewPosition(double elapsedTime); 00068 00069 00070 void outputCellValues(); 00071 00072 protected: 00073 00074 00075 void changeDirRandom(); 00076 void changeDirDistribution(); 00077 void changeDirRotDiffusion(double elapsedTime); 00078 void moveToNewPosition(double elapsedTime); 00079 00080 double speed; 00081 double rotDiffusionConstant; 00082 00083 00084 00085 00086 double * cheYhistory; 00087 int cheYhisPos; 00088 00089 int cheYpThreshold;// = 1795; 00090 int motorState;// = this->CCW; 00091 int flagellaState;// = this->APART; 00092 int lastFlagellaState; 00093 double apartDuration;// = 0; 00094 bool droppingTumble;// = false; 00095 00096 double boxcarTimeWidth;// = 0.3; 00097 int cheYhistorySize;// = (int)round(boxcarTimeWidth/dt); 00098 00099 double meanCheYp;// = 0; 00100 double cheYhistorySum;// = 0; 00101 00102 00103 00104 00105 //Identify the cell with a number 00106 int cellId; 00107 00108 //Keep track of current 3d position, direction, and local orientation 00109 // (could use a quanternion and save less numbers, but I like my intuitive vectors...) 00110 // also, I ran a test using double values on a 64bit linux machine to test the error 00111 // that develops between the orthogonality between the up and dir vectors. Running 00112 // 10 million random rotations on dir and up, I get only a ~.005 error in the degree (meaning 00113 // the degree between the two vectors was ~90.005 instead of 90 exactly). I believe this to 00114 // be a reasonable error, as if we apply a new rotation every .01 seconds in the simulation, 00115 // we only get an error that is greater than about 0.005 degrees after 27.7 simulation hours, 00116 // which is ok for me... (note, in the same test, the magnitude of the vectors changes by 00117 // less than 0.00001 (they were 0.999991 instead of exactly 1) 00118 double pos[3]; 00119 double dir[3]; 00120 double up[3]; 00121 double rotMat[3][3]; 00122 00123 double lastPos[3]; 00124 double lastDir[3]; 00125 double lastUp[3]; 00126 00127 00128 //Cell properties 00129 double currentTime; 00130 int currentMovement; 00131 int lastMovement; 00132 double currentLigConc; 00133 00134 00135 //Distribution of new swim direction angles, matched to experimental observations 00136 // With shape = 4, scale = 18.32045567939674, location = -4.606176605609249 00137 // These variables are now initialized in cell.cpp 00138 static const double DefaultGammaAlpha;// = 4.; 00139 static const double DefaultGammaBeta;// = 1./18.32045567939674; 00140 static const double DefaultGammaOffset;// = -4.606176605609249; 00141 00142 static const double DefaultSpeed;// = 20; //uM per second 00143 static const double DefaultRotDifConst;// = 0.06205; // rad^2/s 00144 00145 00146 00147 //Keep a copy of the chemotaxis system and environment 00148 System * system; 00149 Environment *env; 00150 00151 //Also keep track of the output stream for the cell properties 00152 ofstream motorFileStream; 00153 ofstream outputFileStream; 00154 void outputCellHeader(); 00155 00156 double runTimeSpent; 00157 00158 00159 string fileName; 00160 unsigned int binaryFileOutputCounter; 00161 00162 static const int CW = 1; 00163 static const int CCW = 0; 00164 00165 00166 00167 private: 00168 static unsigned int cellIdCounter; 00169 ChemotaxisUtil::GammaSampler *gs; 00170 00171 }; 00172 00173 00174 #endif /*NG_CELL_HH_*/ 00175