Chaste Commit::8b5d759ac2eb95e67ae57699734101efccb0a0a9
CellCycleTimesGenerator.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "Exception.hpp"
37#include "CellCycleTimesGenerator.hpp"
38
40
42 : mRandomSeed(0u),
43 mCurrentIndex(0u),
44 mRate(1.0/2.0),
45 mVectorCreated(false)
46{
47 assert(mpInstance == NULL); // Ensure correct serialization
48}
49
58
60{
61 if (mpInstance)
62 {
63 delete mpInstance;
64 mpInstance = NULL;
65 }
66}
67
69{
70 mRandomSeed = randomSeed;
71}
72
77
79{
81 {
82 EXCEPTION("Trying to generate the cell cycle times twice. Need to call CellCycleTimesGenerator::Destroy() first.");
83 }
84 else
85 {
86 unsigned number_stored_times = 15000u;
87 mCellCycleTimes.reserve(number_stored_times);
88
89 RandomNumberGenerator* p_random_number_generator = RandomNumberGenerator::Instance();
90 p_random_number_generator->Reseed(mRandomSeed);
91
92 for (unsigned index = 0; index < 15000u; index++)
93 {
94 mCellCycleTimes.push_back( p_random_number_generator->ExponentialRandomDeviate(mRate) );
95 }
96
97 mCurrentIndex = 0;
98 mVectorCreated = true;
99 }
100}
101
103{
104 if (mVectorCreated)
105 {
106 EXCEPTION("You cannot reset the rate after cell cycle times are created.");
107 }
108 else
109 {
110 mRate = rate;
111 }
112}
113
115{
116 return mRate;
117}
118
120{
121 if (!mVectorCreated)
122 {
123 EXCEPTION("When using FixedSequenceCellCycleModel one must call CellCycleTimesGenerator::Instance()->GenerateCellCycleTimeSequence()"
124 " before the start of the simulation.");
125 }
126 else
127 {
128 double new_cell_cycle_time = mCellCycleTimes[mCurrentIndex];
129 mCurrentIndex += 1u;
130 return new_cell_cycle_time;
131 }
132}
#define EXCEPTION(message)
std::vector< double > mCellCycleTimes
void SetRandomSeed(unsigned randomSeed)
static CellCycleTimesGenerator * mpInstance
static CellCycleTimesGenerator * Instance()
static RandomNumberGenerator * Instance()
double ExponentialRandomDeviate(double scale)