00001 #include "CellVelocity.h"
00002 #include <CompuCell3D/Potts3D/CellInventory.h>
00003 #include <XMLCereal/XMLPullParser.h>
00004 #include <XMLCereal/XMLSerializer.h>
00005 #include <BasicUtils/BasicString.h>
00006 #include <BasicUtils/BasicException.h>
00007
00008 #include <CompuCell3D/Simulator.h>
00009 #include <iostream>
00010 #include <string>
00011 #include <CompuCell3D/plugins/CellVelocity/CellVelocityPlugin.h>
00012 #include <CompuCell3D/plugins/CellVelocity/CellInstantVelocityPlugin.h>
00013 #include <CompuCell3D/plugins/CellVelocity/CellVelocityData.h>
00014 #include <BasicUtils/BasicClassAccessor.h>
00015 #include <PublicUtilities/NumericalUtils.h>
00016 #include <sstream>
00017
00018
00019 using namespace std;
00020
00021 namespace CompuCell3D {
00023 CellVelocity::CellVelocity()
00024 : Steppable()
00025 {
00026 updateFrequency=1;
00027 }
00029
00030 CellVelocity::~CellVelocity()
00031 {
00032 }
00034 void CellVelocity::init(Simulator *simulator){
00035
00036
00037
00038 potts = simulator->getPotts();
00040 cellInventoryPtr=& potts->getCellInventory();
00041
00042
00043
00044 }
00046 void CellVelocity::extraInit(Simulator *simulator){
00047
00048 CellVelocityPlugin * cellVelocityPlugin=0;
00049 cellVelocityPlugin=(CellVelocityPlugin*)(Simulator::pluginManager.get("CellVelocity"));
00050
00051 ASSERT_OR_THROW("CellVelocity plugin not initialized!", cellVelocityPlugin);
00052 cellVelocityDataAccessorPtr = cellVelocityPlugin->getCellVelocityDataAccessorPtr();
00053
00054
00055 fieldDim=potts->getCellFieldG()->getDim();
00056
00057 potts->getBoundaryXName()=="Periodic" ? boundaryConditionIndicator.x=1 : boundaryConditionIndicator.x=0 ;
00058 potts->getBoundaryYName()=="Periodic" ? boundaryConditionIndicator.y=1 : boundaryConditionIndicator.y=0;
00059 potts->getBoundaryZName()=="Periodic" ? boundaryConditionIndicator.z=1 : boundaryConditionIndicator.z=0;
00060 cerr<<"boundaryConditionIndicator="<<boundaryConditionIndicator<<endl;
00061
00062
00063
00064 }
00065
00067 void CellVelocity::start(){
00068 zeroCellVelocities();
00069 updateCOMList();
00070
00071 }
00073 void CellVelocity::updateCOMList(){
00074
00075 CellInventory::cellInventoryIterator cInvItr;
00077 float xCom;
00078 float yCom;
00079 float zCom;
00080
00081 Coordinates3D<float> oldCM,newCM,v;
00082 CellG * cell;
00083
00084
00085
00086 for(cInvItr=cellInventoryPtr->cellInventoryBegin() ; cInvItr !=cellInventoryPtr->cellInventoryEnd() ;++cInvItr ){
00087
00088 cell=*cInvItr;
00089
00090 newCM.XRef()=cell->xCM/(float)cell->volume ;
00091 newCM.YRef()=cell->yCM/(float)cell->volume;
00092 newCM.ZRef()=cell->zCM/(float)cell->volume;
00093
00094
00095 oldCM=cellVelocityDataAccessorPtr -> get(cell->extraAttribPtr) -> getLastCM();
00096
00097 if(cellVelocityDataAccessorPtr -> get(cell->extraAttribPtr)->enoughData){
00098 v.XRef()=findMin(newCM.X()-oldCM.X(), boundaryConditionIndicator.x ? fieldDim.x : 0 );
00099 v.YRef()=findMin(newCM.Y()-oldCM.Y(), boundaryConditionIndicator.y ? fieldDim.y : 0 );
00100 v.ZRef()=findMin(newCM.Z()-oldCM.Z(), boundaryConditionIndicator.z ? fieldDim.z : 0 );
00101
00102 v.XRef()/=(float)updateFrequency;
00103 v.YRef()/=(float)updateFrequency;
00104 v.ZRef()/=(float)updateFrequency;
00105
00106 cellVelocityDataAccessorPtr -> get(cell->extraAttribPtr) -> push_front(newCM.X() , newCM.Y() , newCM.Z());
00107 cellVelocityDataAccessorPtr -> get(cell->extraAttribPtr) -> setAverageVelocity(v);
00108
00109 }else{
00110 v.XRef()=0.;
00111 v.YRef()=0.;
00112 v.ZRef()=0.;
00113 cellVelocityDataAccessorPtr -> get(cell->extraAttribPtr) -> push_front(newCM.X() , newCM.Y() , newCM.Z());
00114 cellVelocityDataAccessorPtr -> get(cell->extraAttribPtr) -> setAverageVelocity(v);
00115
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 }
00127
00128 }
00130 void CellVelocity::zeroCellVelocities(){
00131
00132 CellInventory::cellInventoryIterator cInvItr;
00134 float xCom;
00135 float yCom;
00136 float zCom;
00137
00138 CellG * cell;
00139
00140
00141 cerr<<"ACCESSOR"<<cellVelocityDataAccessorPtr<<endl;
00142
00143 for(cInvItr=cellInventoryPtr->cellInventoryBegin() ; cInvItr != cellInventoryPtr->cellInventoryEnd() ;++cInvItr ){
00144
00145 cell=*cInvItr;
00146
00147
00148
00149
00150
00151
00152 }
00153
00154 }
00155
00156
00158 void CellVelocity::step(const unsigned int currentStep){
00159
00160 if(!(currentStep % updateFrequency)){
00161 updateCOMList();
00162 }
00163
00164 }
00166 void CellVelocity::resizeCellVelocityData(){
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 }
00183 void CellVelocity::readXML(XMLPullParser &in){
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 in.skip(TEXT);
00217
00218
00219 while (in.check(START_ELEMENT)) {
00220 string attributeName=in.getName();
00221 if (attributeName == "UpdateFrequency") {
00222
00223 updateFrequency = BasicString::parseUInteger(in.matchSimple());
00224 }
00225 else {
00226 throw BasicException(string("Unexpected element '") + in.getName() +
00227 "'!", in.getLocation());
00228 }
00229
00230 in.skip(TEXT);
00231 }
00232
00233
00234
00235 }
00236
00237
00239
00240 };