-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCellMilieuChemicalSystem.cpp
More file actions
224 lines (179 loc) · 6.61 KB
/
CellMilieuChemicalSystem.cpp
File metadata and controls
224 lines (179 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/***************************************************************************//**
* Project: Colony
*
* \file CellMilieuChemicalSystem.cpp
* \author Marc Weber\n
* The SiMBioSys group (CosmoLab)\n
* Parc Científic de Barcelona\n
* Barcelona, Spain.\n
* http://www.thesimbiosys.com
* \version 1.0
* \date 11/2009
*
* Copyright 2009 by Marc Weber
******************************************************************************/
#include "CellMilieuChemicalSystem.h"
//------------------------------------------------------------------------------
CellMilieuChemicalSystem::CellMilieuChemicalSystem()
: milieuPtr_(0),
cellPtr_(0),
nTotalSpecies_(0),
nSpeciesCell_(0),
nSpeciesMilieu_(0),
nChannels_(0),
stoichMatrix_(), //Rem: the Array is 0-initialized, its data cannot be accessed
computePropensitiesInterCellularPtr_(0),
computeTimeDependentPropensitiesInterCellularPtr_(0),
propensities_() //Rem: the Array is 0-initialized, its data cannot be accessed
{}
//------------------------------------------------------------------------------
CellMilieuChemicalSystem::~CellMilieuChemicalSystem()
{
stoichMatrix_.free();
propensities_.free();
}
//------------------------------------------------------------------------------
void CellMilieuChemicalSystem::initialize
(
const CellMilieuChemicalSystemInitParam& p
)
{
milieuPtr_ = p.milieuPtr_;
cellPtr_ = p.cellPtr_;
nSpeciesMilieu_ = milieuPtr_->getNSpecies();
nSpeciesCell_ = cellPtr_->getNSpecies();
nTotalSpecies_ = nSpeciesMilieu_ + nSpeciesCell_;
nChannels_ = p.nChannelsCellMilieu_;
int nrows = p.stoichMatrixCellMilieu_.rows();
int ncols = p.stoichMatrixCellMilieu_.cols();
if (nrows != nChannels_ || ncols != nTotalSpecies_)
{
cout << "ERROR: class CellMilieuChemicalSystem initialize(),"
" stoichMatrix array does not have the correct size:\n";
cout << "nChannels x nSpecies = " << nChannels_ << " x "
<< nTotalSpecies_ << "\n";
cout << "dim(stoichMatrix) = " << nrows << " x " << ncols << endl;
exit(1);
}
stoichMatrix_.resize(nrows,ncols);
stoichMatrix_ = p.stoichMatrixCellMilieu_;
propensities_.resize(nChannels_);
propensities_ = 0.0;
#ifndef TIME_DEPENDENT_PROPENSITIES
computePropensitiesInterCellularPtr_ = p.computePropensitiesInterCellularPtr_;
#else
computeTimeDependentPropensitiesInterCellularPtr_ =
p.computeTimeDependentPropensitiesInterCellularPtr_;
#endif // TIME_DEPENDENT_PROPENSITIES
}
//------------------------------------------------------------------------------
void CellMilieuChemicalSystem::setReferencePropensities(Array<double,1> refArray)
{
Array<double,1> arrayCopy( propensities_.copy() );
propensities_.reference(refArray);
propensities_ = arrayCopy;
}
//------------------------------------------------------------------------------
void CellMilieuChemicalSystem::computePropensities()
{
computePropensitiesInterCellularPtr_
(
cellPtr_->getX(),
milieuPtr_->getX(),
cellPtr_->getVolume0(),
milieuPtr_->getTimeDependentVolume(0.0),
propensities_
);
}
//------------------------------------------------------------------------------
void CellMilieuChemicalSystem::computePropensities(const double time)
{
// UPDATE: We changed the definition of the volume of the milieu, but this is kind of
// confusing because we have to use the getTimeDependentVolume(time) method to get
// the value of the milieu volume, even in the case of time independent propensities.
// TODO: find a better scheme for definition of the volumes of cells and milieu
// that is compatible with both time dependent and time independent propensities.
computeTimeDependentPropensitiesInterCellularPtr_
(
cellPtr_->getX(),
milieuPtr_->getX(),
cellPtr_->getTimeDependentVolume(time),
cellPtr_->getVolume0(),
milieuPtr_->getTimeDependentVolume(time),
propensities_
);
}
//------------------------------------------------------------------------------
void CellMilieuChemicalSystem::applyReaction(int mu)
{
cellPtr_->applyInterCellularReaction(
stoichMatrix_( mu, Range( 0, nSpeciesCell_ - 1 ) )
);
milieuPtr_->applyInterCellularReaction(
stoichMatrix_( mu, Range( nSpeciesCell_, nTotalSpecies_ - 1 ) )
);
#ifdef X_POSITIVITY_CHECK
checkPositivity();
#endif // X_POSITIVITY_CHECK
}
//------------------------------------------------------------------------------
#ifdef X_POSITIVITY_CHECK
void CellMilieuChemicalSystem::checkPositivity() const
{
int i;
for (i=0; i<nSpeciesCell_; i++)
{
if ( (cellPtr_->getX())(i) < 0)
{
cout << "WARNING: class CellMilieuChemicalSystem, function checkPositivity(),"
" state vector x_ of cell contains a negative number of molecules: "
"x(" << i << ") = " << (cellPtr_->getX())(i) << endl;
}
}
for (i=0; i<nSpeciesMilieu_; i++)
{
if ( (milieuPtr_->getX())(i) < 0)
{
cout << "WARNING: class CellMilieuChemicalSystem, function checkPositivity(),"
" state vector x_ of milieu contains a negative number of molecules: "
"x(" << i << ") = " << (milieuPtr_->getX())(i) << endl;
}
}
}
#endif //X_POSITIVITY_CHECK
//------------------------------------------------------------------------------
CellMilieuChemicalSystem& CellMilieuChemicalSystem::operator =
(
const CellMilieuChemicalSystem& b
)
{
// Test for self-assignment
if (&b == this)
{
// Do nothing and just return myself.
return *this;
}
copy(b);
return *this;
}
//------------------------------------------------------------------------------
void CellMilieuChemicalSystem::copy(const CellMilieuChemicalSystem& b)
{
milieuPtr_ = b.milieuPtr_;
// Warning: We don't want to make the cellMilieu object point to the same cell!!!
// cellPtr_ = b.cellPtr_;
nSpeciesMilieu_ = b.nSpeciesMilieu_;
nSpeciesCell_ = b.nSpeciesCell_;
nTotalSpecies_ = b.nTotalSpecies_;
nChannels_ = b.nChannels_;
int nrows = b.stoichMatrix_.rows();
int ncols = b.stoichMatrix_.cols();
stoichMatrix_.resize(nrows,ncols);
stoichMatrix_ = b.stoichMatrix_;
propensities_.resize(b.propensities_.size());
propensities_ = b.propensities_;
computePropensitiesInterCellularPtr_ = b.computePropensitiesInterCellularPtr_;
computeTimeDependentPropensitiesInterCellularPtr_ =
b.computeTimeDependentPropensitiesInterCellularPtr_;
}
//------------------------------------------------------------------------------