Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
CellSrnModel.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 "CellSrnModel.hpp"
37
39 : AbstractSrnModel(rModel),
40 mpInteriorSrnModel(nullptr)
41{
42 /*
43 * Edge SRN vector should be empty in the newly created cell. They are added in
44 * VertexBasedPopulation::UpdateSrnAfterBirthOrDeath().
45 *
46 * Copy interior SRN to the new cell. Interior SRN should have custom implementation
47 * of a new interior SRN creation after cell division.
48 */
49 if (rModel.mpInteriorSrnModel != nullptr)
50 {
51 this->SetInteriorSrnModel(boost::shared_ptr<AbstractSrnModel>(rModel.GetInteriorSrn()->CreateSrnModel()));
52 }
54 for (auto iter : rModel.mEdgeSrnModels)
55 {
56 mEdgeSrnModels.push_back(boost::shared_ptr<AbstractSrnModel>(iter->CreateSrnModel()));
57 }
58}
59
64
68
70{
71 for (auto iter : mEdgeSrnModels)
72 {
73 iter->Initialise();
74 }
75
76 if (mpInteriorSrnModel != nullptr)
77 {
78 mpInteriorSrnModel->Initialise();
79 }
80}
81
83{
84 /*
85 * Making sure that we are at the current time.
86 * SimulateToCurrentTime() MUST have been called before in Cell::ReadyToDivide() method
87 * so that SRN models should already be simulated up to the current time.
88 */
89 assert(mSimulatedToTime == SimulationTime::Instance()->GetTime());
90
91 /*
92 * Note that edge models follow different rules since the number and the state of edge SRNs
93 * after cell divisions depends on local topology. That is custom behavior of edge SRN models
94 * is important to implement correctly.
95 */
96 for (auto iter : mEdgeSrnModels)
97 {
98 iter->ResetForDivision();
99 }
100
101 if (mpInteriorSrnModel != nullptr)
102 {
103 mpInteriorSrnModel->ResetForDivision();
104 }
105}
106
108{
109 for (auto iter : mEdgeSrnModels)
110 {
111 iter->SimulateToCurrentTime();
112 }
113 if (mpInteriorSrnModel != nullptr)
114 {
115 mpInteriorSrnModel->SimulateToCurrentTime();
116 }
117
118 mSimulatedToTime = mEdgeSrnModels[0]->GetSimulatedToTime();
119}
120
125
126void CellSrnModel::AddEdgeSrn(std::vector<AbstractSrnModelPtr> edgeSrns)
127{
128 mIsEdgeBasedModel = true;
129 mEdgeSrnModels.clear();
130 for (unsigned i=0; i<edgeSrns.size(); ++i)
131 {
132 edgeSrns[i]->SetEdgeModelIndicator(true);
133 }
134 mEdgeSrnModels = edgeSrns;
135}
136
137void CellSrnModel::AddEdgeSrnModel(AbstractSrnModelPtr pEdgeSrn)
138{
139 mIsEdgeBasedModel = true;
140 pEdgeSrn->SetEdgeModelIndicator(true);
141 pEdgeSrn->SetEdgeLocalIndex(mEdgeSrnModels.size());
142 mEdgeSrnModels.push_back(pEdgeSrn);
143}
144
146{
147 return mEdgeSrnModels.size();
148}
149
150AbstractSrnModelPtr CellSrnModel::GetEdgeSrn(unsigned index) const
151{
152 assert(index < mEdgeSrnModels.size());
153 return mEdgeSrnModels[index];
154}
155
156const std::vector<AbstractSrnModelPtr>& CellSrnModel::GetEdges() const
157{
158 return mEdgeSrnModels;
159}
160
161void CellSrnModel::SetInteriorSrnModel(AbstractSrnModelPtr pInteriorSrn)
162{
163 mpInteriorSrnModel = pInteriorSrn;
164}
165
166AbstractSrnModelPtr CellSrnModel::GetInteriorSrn() const
167{
168 return mpInteriorSrnModel;
169}
170
171void CellSrnModel::SetCell(CellPtr pCell)
172{
174
175 // Make a copy of all SRN models inside the system
176 for (auto iter : mEdgeSrnModels)
177 {
178 iter->SetCell(pCell);
179 }
180
181 if (mpInteriorSrnModel != nullptr)
182 {
183 mpInteriorSrnModel->SetCell(pCell);
184 }
185}
186
187// Declare identifier for the serializer
#define CHASTE_CLASS_EXPORT(T)
virtual void SetCell(CellPtr pCell)
bool HasEdgeModel() const
void AddEdgeSrn(std::vector< AbstractSrnModelPtr > edgeSrns)
unsigned GetNumEdgeSrn() const
AbstractSrnModelPtr GetEdgeSrn(unsigned index) const
virtual void Initialise()
virtual AbstractSrnModel * CreateSrnModel()
virtual void SetCell(CellPtr pCell)
virtual void ResetForDivision()
const std::vector< AbstractSrnModelPtr > & GetEdges() const
std::vector< boost::shared_ptr< AbstractSrnModel > > mEdgeSrnModels
void AddEdgeSrnModel(AbstractSrnModelPtr pEdgeSrn)
void SetInteriorSrnModel(AbstractSrnModelPtr pInteriorSrn)
boost::shared_ptr< AbstractSrnModel > mpInteriorSrnModel
AbstractSrnModelPtr GetInteriorSrn() const
virtual void SimulateToCurrentTime()
static SimulationTime * Instance()