00001 /* 00002 00003 Copyright (c) 2005-2015, University of Oxford. 00004 All rights reserved. 00005 00006 University of Oxford means the Chancellor, Masters and Scholars of the 00007 University of Oxford, having an administrative office at Wellington 00008 Square, Oxford OX1 2JD, UK. 00009 00010 This file is part of Chaste. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright notice, 00017 this list of conditions and the following disclaimer in the documentation 00018 and/or other materials provided with the distribution. 00019 * Neither the name of the University of Oxford nor the names of its 00020 contributors may be used to endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 */ 00035 00036 #include "OnLatticeSimulation.hpp" 00037 #include "PottsBasedCellPopulation.hpp" 00038 #include "CellBasedEventHandler.hpp" 00039 #include "LogFile.hpp" 00040 #include "Version.hpp" 00041 #include "ExecutableSupport.hpp" 00042 #include "CaBasedCellPopulation.hpp" 00043 00044 template<unsigned DIM> 00045 OnLatticeSimulation<DIM>::OnLatticeSimulation(AbstractCellPopulation<DIM>& rCellPopulation, 00046 bool deleteCellPopulationInDestructor, 00047 bool initialiseCells) 00048 : AbstractCellBasedSimulation<DIM>(rCellPopulation, 00049 deleteCellPopulationInDestructor, 00050 initialiseCells) 00051 { 00052 if (!dynamic_cast<AbstractOnLatticeCellPopulation<DIM>*>(&rCellPopulation)) 00053 { 00054 EXCEPTION("OnLatticeSimulations require a subclass of AbstractOnLatticeCellPopulation."); 00055 } 00056 00057 this->mDt = 0.1; // 6 minutes 00058 } 00059 00060 template<unsigned DIM> 00061 void OnLatticeSimulation<DIM>::AddCaUpdateRule(boost::shared_ptr<AbstractCaUpdateRule<DIM> > pUpdateRule) 00062 { 00063 if (dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))) 00064 { 00065 static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->AddUpdateRule(pUpdateRule); 00066 } 00067 } 00068 00069 template<unsigned DIM> 00070 void OnLatticeSimulation<DIM>::RemoveAllCaUpdateRules() 00071 { 00072 if (dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))) 00073 { 00074 static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->RemoveAllUpdateRules(); 00075 } 00076 } 00077 00078 template<unsigned DIM> 00079 void OnLatticeSimulation<DIM>::AddPottsUpdateRule(boost::shared_ptr<AbstractPottsUpdateRule<DIM> > pUpdateRule) 00080 { 00081 if (dynamic_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))) 00082 { 00083 static_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->AddUpdateRule(pUpdateRule); 00084 } 00085 } 00086 00087 template<unsigned DIM> 00088 void OnLatticeSimulation<DIM>::RemoveAllPottsUpdateRules() 00089 { 00090 if (dynamic_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))) 00091 { 00092 static_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->RemoveAllUpdateRules(); 00093 } 00094 } 00095 00096 template<unsigned DIM> 00097 c_vector<double, DIM> OnLatticeSimulation<DIM>::CalculateCellDivisionVector(CellPtr pParentCell) 00098 { 00100 return zero_vector<double>(DIM); 00101 } 00102 00103 template<unsigned DIM> 00104 void OnLatticeSimulation<DIM>::WriteVisualizerSetupFile() 00105 { 00106 if (dynamic_cast<PottsBasedCellPopulation<DIM>*>(&this->mrCellPopulation)) 00107 { 00108 *this->mpVizSetupFile << "PottsSimulation\n"; 00109 } 00110 } 00111 00112 template<unsigned DIM> 00113 void OnLatticeSimulation<DIM>::UpdateCellLocationsAndTopology() 00114 { 00115 // Update cell locations 00116 CellBasedEventHandler::BeginEvent(CellBasedEventHandler::POSITION); 00117 static_cast<AbstractOnLatticeCellPopulation<DIM>*>(&(this->mrCellPopulation))->UpdateCellLocations(this->mDt); 00118 CellBasedEventHandler::EndEvent(CellBasedEventHandler::POSITION); 00119 } 00120 00121 template<unsigned DIM> 00122 void OnLatticeSimulation<DIM>::UpdateCellPopulation() 00123 { 00124 bool update_cell_population_this_timestep = true; 00125 if (dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))) 00126 { 00127 /* 00128 * If mInitialiseCells is false, then the simulation has been loaded from an archive. 00129 * In this case, we should not call UpdateCellPopulation() at the first time step. This is 00130 * because it will have already been called at the final time step prior to saving; 00131 * if we were to call it again now, then we would have introduced an extra call to 00132 * the random number generator compared to if we had not saved and loaded the simulation, 00133 * thus affecting results. This would be bad - we don't want saving and loading to have 00134 * any effect on the course of a simulation! See #1445. 00135 */ 00136 if (!this->mInitialiseCells && (SimulationTime::Instance()->GetTimeStepsElapsed() == 0)) 00137 { 00138 NEVER_REACHED; 00140 // update_cell_population_this_timestep = false; 00141 } 00142 } 00143 00144 if (update_cell_population_this_timestep) 00145 { 00146 AbstractCellBasedSimulation<DIM>::UpdateCellPopulation(); 00147 } 00148 } 00149 00150 template<unsigned DIM> 00151 void OnLatticeSimulation<DIM>::OutputAdditionalSimulationSetup(out_stream& rParamsFile) 00152 { 00153 // Loop over the collection of update rules and output info for each 00154 *rParamsFile << "\n\t<UpdateRules>\n"; 00155 if (dynamic_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))) 00156 { 00157 std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > > collection = 00158 static_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->rGetUpdateRuleCollection(); 00159 00160 for (typename std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > >::iterator iter = collection.begin(); 00161 iter != collection.end(); 00162 ++iter) 00163 { 00164 (*iter)->OutputUpdateRuleInfo(rParamsFile); 00165 } 00166 } 00167 else if (dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))) 00168 { 00169 std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > > collection = 00170 static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->rGetUpdateRuleCollection(); 00171 00172 for (typename std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > >::iterator iter = collection.begin(); 00173 iter != collection.end(); 00174 ++iter) 00175 { 00176 (*iter)->OutputUpdateRuleInfo(rParamsFile); 00177 } 00178 } 00179 else 00180 { 00181 //\todo define the method for `CaBasedCellPopulation` 00182 } 00183 *rParamsFile << "\t</UpdateRules>\n"; 00184 } 00185 00186 template<unsigned DIM> 00187 void OnLatticeSimulation<DIM>::OutputSimulationParameters(out_stream& rParamsFile) 00188 { 00189 // Call method on direct parent class 00190 AbstractCellBasedSimulation<DIM>::OutputSimulationParameters(rParamsFile); 00191 } 00192 00194 // Explicit instantiation 00196 00197 template class OnLatticeSimulation<1>; 00198 template class OnLatticeSimulation<2>; 00199 template class OnLatticeSimulation<3>; 00200 00201 // Serialization for Boost >= 1.36 00202 #include "SerializationExportWrapperForCpp.hpp" 00203 EXPORT_TEMPLATE_CLASS_SAME_DIMS(OnLatticeSimulation)