41 #include "AbstractCellBasedSimulation.hpp" 42 #include "CellBasedEventHandler.hpp" 43 #include "LogFile.hpp" 44 #include "ExecutableSupport.hpp" 45 #include "AbstractPdeModifier.hpp" 47 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
49 bool deleteCellPopulationInDestructor,
53 mrCellPopulation(rCellPopulation),
54 mDeleteCellPopulationInDestructor(deleteCellPopulationInDestructor),
55 mInitialiseCells(initialiseCells),
57 mUpdateCellPopulation(true),
59 mSimulationOutputDirectory(mOutputDirectory),
62 mOutputDivisionLocations(false),
63 mOutputCellVelocities(false),
64 mSamplingTimestepMultiple(1)
81 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
90 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
98 unsigned num_births_this_step = 0;
106 double cell_age = cell_iter->GetAge();
109 if (cell_iter->ReadyToDivide())
115 unsigned parent_cell_id = cell_iter->GetCellId();
118 CellPtr p_new_cell = cell_iter->Divide();
140 c_vector<double, SPACE_DIM> cell_location =
mrCellPopulation.GetLocationOfCellCentre(*cell_iter);
143 for (
unsigned i=0; i<SPACE_DIM; i++)
147 *
mpDivisionLocationFile <<
"\t" << cell_age <<
"\t" << parent_cell_id <<
"\t" << cell_iter->GetCellId() <<
"\t" << p_new_cell->GetCellId() <<
"\n";
154 num_births_this_step++;
159 return num_births_this_step;
162 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
165 unsigned num_deaths_this_step = 0;
175 (*killer_iter)->CheckAndLabelCellsForApoptosisOrDeath();
180 return num_deaths_this_step;
183 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
190 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
196 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
202 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
208 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
215 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
222 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
228 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
231 assert(samplingTimestepMultiple > 0);
235 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
241 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
247 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
253 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
259 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
265 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
271 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
277 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
283 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
289 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
292 std::vector<double> location;
293 for (
unsigned i=0; i<SPACE_DIM; i++)
295 location.push_back(
mrCellPopulation.GetNode(rNodeIndex)->rGetLocation()[i]);
300 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
308 double current_time = p_simulation_time->
GetTime();
314 EXCEPTION(
"SetEndTime has not yet been called.");
325 if (current_time > 0)
333 EXCEPTION(
"End time and number of timesteps already setup. You should not use SimulationTime::SetEndTimeAndNumberOfTimeSteps in cell-based tests.");
346 double time_now = p_simulation_time->
GetTime();
347 std::ostringstream time_string;
348 time_string << time_now;
350 std::string results_directory =
mOutputDirectory +
"/results_from_time_" + time_string.str();
401 LOG(1,
"Setting up cells...");
410 cell_iter->ReadyToDivide();
430 LOG(1,
"--TIME = " << p_simulation_time->
GetTime() <<
"\n");
446 std::map<CellPtr, c_vector<double, SPACE_DIM> > old_cell_locations;
453 old_cell_locations[*cell_iter] =
mrCellPopulation.GetLocationOfCellCentre(*cell_iter);
471 const c_vector<double,SPACE_DIM>& position =
mrCellPopulation.GetLocationOfCellCentre(*cell_iter);
473 c_vector<double, SPACE_DIM> velocity;
474 velocity = (position - old_cell_locations[*cell_iter])/
mDt;
477 for (
unsigned i=0; i<SPACE_DIM; i++)
482 for (
unsigned i=0; i<SPACE_DIM; i++)
523 LOG(1,
"--END TIME = " << p_simulation_time->
GetTime() <<
"\n");
565 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
571 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
578 LOG(1,
"\tNum deaths = " <<
mNumDeaths <<
"\n");
585 LOG(1,
"\tNum births = " <<
mNumBirths <<
"\n");
589 bool births_or_death_occurred = ((births_this_step>0) || (deaths_this_step>0));
595 LOG(1,
"\tUpdating cell population...");
599 else if (births_or_death_occurred)
601 EXCEPTION(
"CellPopulation has had births or deaths but mUpdateCellPopulation is set to false, please set it to true.");
606 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
612 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
618 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
624 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
630 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
642 out_stream build_info_file = output_file_handler.
OpenOutputFile(
"build.info");
643 std::string build_info;
645 *build_info_file << build_info;
646 build_info_file->close();
649 out_stream parameter_file = output_file_handler.
OpenOutputFile(
"results.parameters");
654 *parameter_file <<
"<Chaste>\n";
655 *parameter_file <<
"\n\t<" << simulation_type <<
">\n";
657 *parameter_file <<
"\t</" << simulation_type <<
">\n";
658 *parameter_file <<
"\n";
664 *parameter_file <<
"\n\t<CellKillers>\n";
670 (*iter)->OutputCellKillerInfo(parameter_file);
672 *parameter_file <<
"\t</CellKillers>\n";
675 *parameter_file <<
"\n\t<SimulationModifiers>\n";
681 (*iter)->OutputSimulationModifierInfo(parameter_file);
683 *parameter_file <<
"\t</SimulationModifiers>\n";
688 *parameter_file <<
"\n</Chaste>\n";
689 parameter_file->close();
693 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
696 *rParamsFile <<
"\t\t<Dt>" <<
mDt <<
"</Dt>\n";
697 *rParamsFile <<
"\t\t<EndTime>" <<
mEndTime <<
"</EndTime>\n";
700 *rParamsFile <<
"\t\t<OutputCellVelocities>" <<
mOutputCellVelocities <<
"</OutputCellVelocities>\n";
std::string mSimulationOutputDirectory
bool mUpdateCellPopulation
virtual unsigned DoCellBirth()
virtual ~AbstractCellBasedSimulation()
virtual bool StoppingEventHasOccurred()
void AddCellKiller(boost::shared_ptr< AbstractCellKiller< SPACE_DIM > > pCellKiller)
bool mDeleteCellPopulationInDestructor
bool IsEndTimeAndNumberOfTimeStepsSetUp() const
std::string mOutputDirectory
#define EXCEPTION(message)
static void BeginEvent(unsigned event)
static SimulationTime * Instance()
AbstractCellBasedSimulation(AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation, bool deleteCellPopulationInDestructor=false, bool initialiseCells=true)
bool GetOutputDivisionLocations()
void OutputSimulationSetup()
AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > & rGetCellPopulation()
unsigned GetTimeStepsElapsed() const
void SetOutputCellVelocities(bool outputCellVelocities)
std::string GetOutputDirectoryFullPath() const
void SetNoBirth(bool noBirth)
std::string GetOutputDirectory()
out_stream mpVizSetupFile
const double DOUBLE_UNSET
virtual void OutputAdditionalSimulationSetup(out_stream &rParamsFile)=0
bool GetOutputCellVelocities()
void SetUpdateCellPopulationRule(bool updateCellPopulation)
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
virtual void WriteVisualizerSetupFile()
out_stream mpCellVelocitiesFile
void SetEndTime(double endTime)
std::vector< boost::shared_ptr< AbstractCellKiller< SPACE_DIM > > > mCellKillers
bool GetUpdateCellPopulationRule()
void SetOutputDivisionLocations(bool outputDivisionLocations)
virtual void OutputSimulationParameters(out_stream &rParamsFile)=0
void RemoveAllCellKillers()
virtual void UpdateCellLocationsAndTopology()=0
virtual void UpdateCellPopulation()
void SetOutputDirectory(std::string outputDirectory)
void SetEndTimeAndNumberOfTimeSteps(double endTime, unsigned totalTimeStepsInSimulation)
static RandomNumberGenerator * Instance()
bool mOutputCellVelocities
std::vector< double > GetNodeLocation(const unsigned &rNodeIndex)
void AddSimulationModifier(boost::shared_ptr< AbstractCellBasedSimulationModifier< ELEMENT_DIM, SPACE_DIM > > pSimulationModifier)
static void GetBuildInfo(std::string &rInfo)
std::string GetIdentifier() const
out_stream mpDivisionLocationFile
unsigned mSamplingTimestepMultiple
virtual double GetDefaultTimeStep()=0
bool mOutputDivisionLocations
std::vector< boost::shared_ptr< AbstractCellBasedSimulationModifier< ELEMENT_DIM, SPACE_DIM > > > mSimulationModifiers
static void EndEvent(unsigned event)
void IncrementTimeOneStep()
static void WriteMachineInfoFile(std::string fileBaseName)
virtual void SetupSolve()
std::vector< boost::shared_ptr< AbstractCellBasedSimulationModifier< ELEMENT_DIM, SPACE_DIM > > > * GetSimulationModifiers()
void ResetEndTimeAndNumberOfTimeSteps(const double &rEndTime, const unsigned &rNumberOfTimeStepsInThisRun)
static void SetOutputDirectory(const std::string &rOutputDirectory)
void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple)
AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > & mrCellPopulation