Chaste  Release::3.4
OnLatticeSimulation.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "OnLatticeSimulation.hpp"
37 #include "PottsBasedCellPopulation.hpp"
38 #include "CellBasedEventHandler.hpp"
39 #include "LogFile.hpp"
40 #include "Version.hpp"
41 #include "ExecutableSupport.hpp"
42 #include "CaBasedCellPopulation.hpp"
43 
44 template<unsigned DIM>
46  bool deleteCellPopulationInDestructor,
47  bool initialiseCells)
48  : AbstractCellBasedSimulation<DIM>(rCellPopulation,
49  deleteCellPopulationInDestructor,
50  initialiseCells)
51 {
52  if (!dynamic_cast<AbstractOnLatticeCellPopulation<DIM>*>(&rCellPopulation))
53  {
54  EXCEPTION("OnLatticeSimulations require a subclass of AbstractOnLatticeCellPopulation.");
55  }
56 
57  this->mDt = 0.1; // 6 minutes
58 }
59 
60 template<unsigned DIM>
62 {
63  if (bool(dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
64  {
65  static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->AddUpdateRule(pUpdateRule);
66  }
67 }
68 
69 template<unsigned DIM>
71 {
72  if (bool(dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
73  {
74  static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->RemoveAllUpdateRules();
75  }
76 }
77 
78 
79 template<unsigned DIM>
81 {
82  if (bool(dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
83  {
84  static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->AddSwitchingUpdateRule(pUpdateRule);
85  }
86 }
87 
88 template<unsigned DIM>
90 {
91  if (bool(dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
92  {
93  static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->RemoveAllSwitchingUpdateRules();
94  }
95 }
96 
97 template<unsigned DIM>
99 {
100  if (bool(dynamic_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
101  {
102  static_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->AddUpdateRule(pUpdateRule);
103  }
104 }
105 
106 template<unsigned DIM>
108 {
109  if (bool(dynamic_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
110  {
111  static_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->RemoveAllUpdateRules();
112  }
113 }
114 
115 template<unsigned DIM>
116 c_vector<double, DIM> OnLatticeSimulation<DIM>::CalculateCellDivisionVector(CellPtr pParentCell)
117 {
119  return zero_vector<double>(DIM);
120 }
121 
122 template<unsigned DIM>
124 {
125  if (bool(dynamic_cast<PottsBasedCellPopulation<DIM>*>(&this->mrCellPopulation)))
126  {
127  *this->mpVizSetupFile << "PottsSimulation\n";
128  }
129 }
130 
131 template<unsigned DIM>
133 {
134  // Update cell locations
135  CellBasedEventHandler::BeginEvent(CellBasedEventHandler::POSITION);
136  static_cast<AbstractOnLatticeCellPopulation<DIM>*>(&(this->mrCellPopulation))->UpdateCellLocations(this->mDt);
137  CellBasedEventHandler::EndEvent(CellBasedEventHandler::POSITION);
138 }
139 
140 template<unsigned DIM>
142 {
143  bool update_cell_population_this_timestep = true;
144  if (bool(dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
145  {
146  /*
147  * If mInitialiseCells is false, then the simulation has been loaded from an archive.
148  * In this case, we should not call UpdateCellPopulation() at the first time step. This is
149  * because it will have already been called at the final time step prior to saving;
150  * if we were to call it again now, then we would have introduced an extra call to
151  * the random number generator compared to if we had not saved and loaded the simulation,
152  * thus affecting results. This would be bad - we don't want saving and loading to have
153  * any effect on the course of a simulation! See #1445.
154  */
155  if (!this->mInitialiseCells && (SimulationTime::Instance()->GetTimeStepsElapsed() == 0))
156  {
159 // update_cell_population_this_timestep = false;
160  }
161  }
162 
163  if (update_cell_population_this_timestep)
164  {
166  }
167 }
168 
169 template<unsigned DIM>
171 {
172  // Loop over the collection of update rules and output info for each
173  *rParamsFile << "\n\t<UpdateRules>\n";
174  if (bool(dynamic_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
175  {
176  std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > > collection =
177  static_cast<PottsBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->rGetUpdateRuleCollection();
178 
179  for (typename std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > >::iterator iter = collection.begin();
180  iter != collection.end();
181  ++iter)
182  {
183  (*iter)->OutputUpdateRuleInfo(rParamsFile);
184  }
185  }
186  else if (bool(dynamic_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))))
187  {
188  std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > > collection =
189  static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->rGetUpdateRuleCollection();
190 
191  for (typename std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > >::iterator iter = collection.begin();
192  iter != collection.end();
193  ++iter)
194  {
195  (*iter)->OutputUpdateRuleInfo(rParamsFile);
196  }
197 
198  std::vector<boost::shared_ptr<AbstractCaSwitchingUpdateRule<DIM> > > switching_collection =
199  static_cast<CaBasedCellPopulation<DIM>*>(&(this->mrCellPopulation))->rGetSwitchingUpdateRuleCollection();
200 
201  for (typename std::vector<boost::shared_ptr<AbstractCaSwitchingUpdateRule<DIM> > >::iterator iter = switching_collection.begin();
202  iter != switching_collection.end();
203  ++iter)
204  {
205  (*iter)->OutputUpdateRuleInfo(rParamsFile);
206  }
207 
208  }
209  else
210  {
212  }
213  *rParamsFile << "\t</UpdateRules>\n";
214 }
215 
216 template<unsigned DIM>
218 {
219  // Call method on direct parent class
221 }
222 
224 template class OnLatticeSimulation<1>;
225 template class OnLatticeSimulation<2>;
226 template class OnLatticeSimulation<3>;
227 
228 // Serialization for Boost >= 1.36
void AddCaSwitchingUpdateRule(boost::shared_ptr< AbstractCaSwitchingUpdateRule< DIM > > pUpdateRule)
#define EXCEPTION(message)
Definition: Exception.hpp:143
static SimulationTime * Instance()
const std::vector< boost::shared_ptr< AbstractPottsUpdateRule< DIM > > > & rGetUpdateRuleCollection() const
virtual c_vector< double, DIM > CalculateCellDivisionVector(CellPtr pParentCell)
const std::vector< boost::shared_ptr< AbstractCaUpdateRule< DIM > > > & rGetUpdateRuleCollection() const
#define NEVER_REACHED
Definition: Exception.hpp:206
void AddPottsUpdateRule(boost::shared_ptr< AbstractPottsUpdateRule< DIM > > pUpdateRule)
virtual void WriteVisualizerSetupFile()
virtual void UpdateCellLocations(double dt)=0
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual void OutputSimulationParameters(out_stream &rParamsFile)=0
void OutputSimulationParameters(out_stream &rParamsFile)
void AddUpdateRule(boost::shared_ptr< AbstractPottsUpdateRule< DIM > > pUpdateRule)
const std::vector< boost::shared_ptr< AbstractCaSwitchingUpdateRule< DIM > > > & rGetSwitchingUpdateRuleCollection() const
void AddSwitchingUpdateRule(boost::shared_ptr< AbstractCaSwitchingUpdateRule< DIM > > pUpdateRule)
void AddUpdateRule(boost::shared_ptr< AbstractCaUpdateRule< DIM > > pUpdateRule)
OnLatticeSimulation(AbstractCellPopulation< DIM > &rCellPopulation, bool deleteCellPopulationInDestructor=false, bool initialiseCells=true)
void OutputAdditionalSimulationSetup(out_stream &rParamsFile)
void AddCaUpdateRule(boost::shared_ptr< AbstractCaUpdateRule< DIM > > pUpdateRule)