-
Notifications
You must be signed in to change notification settings - Fork 1
/
boundaryFunction.cpp
211 lines (209 loc) · 9.79 KB
/
boundaryFunction.cpp
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
#include "spatialsim/boundaryFunction.h"
#include "spatialsim/mystruct.h"
#include "spatialsim/searchFunction.h"
#include "sbml/SBMLTypes.h"
#include <vector>
using namespace std;
LIBSBML_CPP_NAMESPACE_USE
void setBoundaryType(Model *model, vector<variableInfo*> &varInfoList, vector<GeometryInfo*> &geoInfoList, int Xindex, int Yindex, int Zindex, unsigned int dimension)
{
ListOfSpecies *los = model->getListOfSpecies();
unsigned int i;
int X, Y, Z, index;
unsigned int numOfSpecies = static_cast<unsigned int>(model->getNumSpecies());
int Xplus1 = 0, Xminus1 = 0, Yplus1 = 0, Yminus1 = 0, Zplus1 = 0, Zminus1 = 0;
int Xplus2 = 0, Xminus2 = 0, Yplus2 = 0, Yminus2 = 0, Zplus2 = 0, Zminus2 = 0;
for (i = 0; i < numOfSpecies; i++) {
Species *s = los->get(i);
variableInfo *sInfo = searchInfoById(varInfoList, s->getId().c_str());
if (sInfo != 0 && searchAvolInfoByCompartment(geoInfoList, s->getCompartment().c_str()) != 0) {
sInfo->geoi = searchAvolInfoByCompartment(geoInfoList, s->getCompartment().c_str());
int *isD = sInfo->geoi->isDomain;
int *isB = sInfo->geoi->isBoundary;
switch (dimension) {
case 1:
if (sInfo->geoi->isVol == true) {
for (X = 0; X < Xindex; X += 2) {
if (isD[X] == 0) sInfo->value[X] = 0.0;
if (isD[X] == 1 && isB[X] == 1) {
//image edge
if (X == Xindex - 1 || X == 0) {
if (X == 0) sInfo->geoi->bType[X].isBofXm = true;
if (X == Xindex - 1) sInfo->geoi->bType[X].isBofXp = true;
} else {//not the edge of simulation area
if (isD[X - 2] == 0) sInfo->geoi->bType[X].isBofXm = true;
if (isD[X + 2] == 0) sInfo->geoi->bType[X].isBofXp = true;
}
}
}
} else {//membrane
for (X = 0; X < Xindex; X++) {
Xplus1 = X + 1;
Xminus1 = X - 1;
if (isD[X] == 0) sInfo->value[X] = 0.0;
if (X % 2 != 0) {
if (isD[X] == 2 && isD[Xplus1] == 1 && isD[Xminus1] == 1) {
sInfo->value[X] = min(sInfo->value[Xplus1], sInfo->value[Xminus1]);
}
}
}
}
break;
case 2:
if (sInfo->geoi->isVol == true) {//volume
for (Y = 0; Y < Yindex; Y += 2) {
for (X = 0; X < Xindex; X += 2) {
index = Y * Xindex + X;
Xplus2 = Y * Xindex + (X + 2);
Xminus2 = Y * Xindex + (X - 2);
Yplus2 = (Y + 2) * Xindex + X;
Yminus2 = (Y - 2) * Xindex + X;
Xplus1 = Y * Xindex + (X + 1);
Xminus1 = Y * Xindex + (X - 1);
Yplus1 = (Y + 1) * Xindex + X;
Yminus1 = (Y - 1) * Xindex + X;
if (isD[index] == 0) sInfo->value[index] = 0.0;
if (isD[index] == 1 && isB[index] == 1) {
if (X == Xindex - 1 || X == 0 || Y == Yindex - 1 || Y == 0) {
if (X == 0) sInfo->geoi->bType[index].isBofXm = true;
if (X == Xindex - 1) sInfo->geoi->bType[index].isBofXp = true;
if (Y == 0) sInfo->geoi->bType[index].isBofYm = true;
if (Y == Yindex - 1) sInfo->geoi->bType[index].isBofYp = true;
} else {//not the edge of simulation area
if (isD[Xminus2] == 0) sInfo->geoi->bType[index].isBofXm = true;
if (isD[Xplus2] == 0) sInfo->geoi->bType[index].isBofXp = true;
if (isD[Yminus2] == 0) sInfo->geoi->bType[index].isBofYm = true;
if (isD[Yplus2] == 0) sInfo->geoi->bType[index].isBofYp = true;
}
}
}
}
} else {//membrane(角の値を補完)
for (Y = 0; Y < Yindex; Y++) {
for (X = 0; X < Xindex; X++) {
index = Y * Xindex + X;
Xplus1 = Y * Xindex + (X + 1);
Xminus1 = Y * Xindex + (X - 1);
Yplus1 = (Y + 1) * Xindex + X;
Yminus1 = (Y - 1) * Xindex + X;
if (isD[index] == 0) sInfo->value[index] = 0.0;
if (X % 2 != 0 && Y % 2 != 0) {
//values at pseudo membrane
if (isD[index] == 2) {
if (isD[Xplus1] == 1 && isD[Xminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xplus1], sInfo->value[Xminus1]);
} else if (isD[Yplus1] == 1 && isD[Yminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Yplus1], sInfo->value[Yminus1]);
} else if (isD[Xplus1] == 1 && isD[Yplus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xplus1], sInfo->value[Yplus1]);
} else if (isD[Xplus1] == 1 && isD[Yminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xplus1], sInfo->value[Yminus1]);
} else if (isD[Xminus1] == 1 && isD[Yplus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xminus1], sInfo->value[Yplus1]);
} else if (isD[Xminus1] == 1 && isD[Yminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xminus1], sInfo->value[Yminus1]);
}
}
}
}
}
}
break;
case 3:
if (sInfo->geoi->isVol == true) {//volume
for (Z = 0; Z < Zindex; Z += 2) {
for (Y = 0; Y < Yindex; Y += 2) {
for (X = 0; X < Xindex; X += 2) {
index = Z * Yindex * Xindex + Y * Xindex + X;
Xplus2 = Z * Yindex * Xindex + Y * Xindex + (X + 2);
Xminus2 = Z * Yindex * Xindex + Y * Xindex + (X - 2);
Yplus2 = Z * Yindex * Xindex + (Y + 2) * Xindex + X;
Yminus2 = Z * Yindex * Xindex + (Y - 2) * Xindex + X;
Zplus2 = (Z + 2) * Yindex * Xindex + Y * Xindex + X;
Zminus2 = (Z - 2) * Yindex * Xindex + Y * Xindex + X;
Xplus1 = Z * Yindex * Xindex + Y * Xindex + (X + 1);
Xminus1 = Z * Yindex * Xindex + Y * Xindex + (X - 1);
Yplus1 = Z * Yindex * Xindex + (Y + 1) * Xindex + X;
Yminus1 = Z * Yindex * Xindex + (Y - 1) * Xindex + X;
Zplus1 = (Z + 1) * Yindex * Xindex + Y * Xindex + X;
Zminus1 = (Z - 1) * Yindex * Xindex + Y * Xindex + X;
if (isD[index] == 0) sInfo->value[index] = 0.0;
if (isD[index] == 1 && isB[index] == 1) {
if (X == Xindex - 1 || X == 0 || Y == Yindex - 1 || Y == 0 || Z == Zindex - 1 || Z == 0) {
if (X == 0) sInfo->geoi->bType[index].isBofXm = true;
if (X == Xindex - 1) sInfo->geoi->bType[index].isBofXp = true;
if (Y == 0) sInfo->geoi->bType[index].isBofYm = true;
if (Y == Yindex - 1) sInfo->geoi->bType[index].isBofYp = true;
if (Z == 0) sInfo->geoi->bType[index].isBofZm = true;
if (Z == Zindex - 1) sInfo->geoi->bType[index].isBofZp = true;
} else {//not the edge of simulation area
if (isD[Xminus2] == 0) sInfo->geoi->bType[index].isBofXm = true;
if (isD[Xplus2] == 0) sInfo->geoi->bType[index].isBofXp = true;
if (isD[Yminus2] == 0) sInfo->geoi->bType[index].isBofYm = true;
if (isD[Yplus2] == 0) sInfo->geoi->bType[index].isBofYp = true;
if (isD[Zminus2] == 0) sInfo->geoi->bType[index].isBofZm = true;
if (isD[Zplus2] == 0) sInfo->geoi->bType[index].isBofZp = true;
}
}
}
}
}
} else {//membrane
for (Z = 0; Z < Zindex; Z++) {
for (Y = 0; Y < Yindex; Y++) {
for (X = 0; X < Xindex; X++) {
index = Z * Yindex * Xindex + Y * Xindex + X;
Xplus1 = Z * Yindex * Xindex + Y * Xindex + (X + 1);
Xminus1 = Z * Yindex * Xindex + Y * Xindex + (X - 1);
Yplus1 = Z * Yindex * Xindex + (Y + 1) * Xindex + X;
Yminus1 = Z * Yindex * Xindex + (Y - 1) * Xindex + X;
Zplus1 = (Z + 1) * Yindex * Xindex + Y * Xindex + X;
Zminus1 = (Z - 1) * Yindex * Xindex + Y * Xindex + X;
if (isD[index] == 0) sInfo->value[index] = 0.0;
if ((X % 2 != 0 && Y % 2 != 0) || (Y % 2 != 0 && Z % 2 != 0) || (Z % 2 != 0 && X % 2 != 0)) {
//values at pseudo membrane
if (isD[index] == 2) {
if (isD[Xplus1] == 1 && isD[Xminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xplus1], sInfo->value[Xminus1]);
} else if (isD[Yplus1] == 1 && isD[Yminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Yplus1], sInfo->value[Yminus1]);
} else if (isD[Zplus1] == 1 && isD[Zminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Zplus1], sInfo->value[Zminus1]);
} else if (isD[Xplus1] == 1 && isD[Yplus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xplus1], sInfo->value[Yplus1]);
} else if (isD[Xplus1] == 1 && isD[Yminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xplus1], sInfo->value[Yminus1]);
} else if (isD[Xplus1] == 1 && isD[Zplus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xplus1], sInfo->value[Zplus1]);
} else if (isD[Xplus1] == 1 && isD[Zminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xplus1], sInfo->value[Zminus1]);
} else if (isD[Xminus1] == 1 && isD[Yplus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xminus1], sInfo->value[Yplus1]);
} else if (isD[Xminus1] == 1 && isD[Yminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xminus1], sInfo->value[Yminus1]);
} else if (isD[Xminus1] == 1 && isD[Zplus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xminus1], sInfo->value[Zplus1]);
} else if (isD[Xminus1] == 1 && isD[Zminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Xminus1], sInfo->value[Zminus1]);
} else if (isD[Yplus1] == 1 && isD[Zplus1] == 1) {
sInfo->value[index] = min(sInfo->value[Yplus1], sInfo->value[Zplus1]);
} else if (isD[Yplus1] == 1 && isD[Zminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Yplus1], sInfo->value[Zminus1]);
} else if (isD[Yminus1] == 1 && isD[Zplus1] == 1) {
sInfo->value[index] = min(sInfo->value[Yminus1], sInfo->value[Zplus1]);
} else if (isD[Yminus1] == 1 && isD[Zminus1] == 1) {
sInfo->value[index] = min(sInfo->value[Yminus1], sInfo->value[Zminus1]);
}
}
}
}
}
}
}
break;
default:
break;
}
}
}
}