-
Notifications
You must be signed in to change notification settings - Fork 1
/
mesh.hoc
346 lines (313 loc) · 5.93 KB
/
mesh.hoc
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// Mesh for NEURON
// (c) Maciej Lazarewicz ([email protected]) (2001) v1.1
strdef maxsec,maxdifsec
objref imp1
// This routine mash the cell that each segment has length smaller then $2*(length constant lambda_f)
// for frequency $1 (Hines M.L., Carnavale N.T. Neuroscientist, 7(2):123-135, 2001 )
func lambdaf() {
if($2>0) {
return 1e5*sqrt(diam($1)/(4*PI*$2*Ra*cm))
} else {
return 1e2*sqrt(diam($1)/(4*Ra*g_pas))
}
}
//If you use pt3d structures, before you want to calculate lambda_100, you have to set up nseg for desire value, becauce diam can depend on nseg
func mesh() {
nr=0
max=0
forall nseg=1
finitialize()
forall {
while(1) {
maxl=0
finitialize()
for (x) {
el=L/(nseg*lambdaf(x,$1))
if(maxl<el) {
maxl=el
}
}
if(maxl<=$2)break
nseg+=1
}
if(maxl>max) {
max=maxl
maxsec=secname()
}
nr+=nseg
}
finitialize()
print "Max l100 =",maxsec,max,"#comp:",nr
return nr
}
func ratio_mesh() {
imp1=new Impedance()
nr=0
maxdif=0
forall nseg=1
finitialize()
forall {
while(1) {
if(issection("soma"))break
maxl=0
finitialize()
imp1.loc(0)
imp1.compute($1)
tra=imp1.ratio(1/nseg)
if(abs(1-tra)<$2)break
nseg+=1
}
if(maxdif<tra) {
maxdif=tra
maxdifsec=secname()
}
nr+=nseg
print secname(), " ",nseg
}
print "Maxdif =",maxdifsec,maxdif,"#comp:",nr
finitialize()
return nr
}
func transfer_mesh_2() {
imp1=new Impedance()
nr=0
maxdif=0
forall nseg=1
finitialize()
forall {
prev=0
while(1) {
xopen("Hoc/utilities.hoc")maxl=0
finitialize()
imp1.loc(0.5)
imp1.compute($1)
tra=imp1.input(0.5)
dif=abs(tra-prev)
// print nseg,tra
if(dif<$2 && prev!=0)break
prev=tra
nseg+=2
}
if(maxdif<dif) {
maxdif=dif
maxdifsec=secname()
}
nr+=nseg
print secname(), " ",nseg
}
print "Maxdif =",maxdifsec,maxdif,"#comp:",nr
finitialize()
return nr
}
objref diff,maxx
proc make_table() {
diff=new Vector(10000)
maxx=new Vector(10000)
forall nseg=9
finitialize()
init()
print "Start:",t,tstop
while(t<tstop){
step()
ii=0
forall {
diff.x[ii]=abs(v(0)-v(1))
if(diff.x[ii]>maxx.x[ii])maxx.x[ii]=diff.x[ii]
ii+=1
}
}
print "Stop"
ii=0
forall {
print maxx.x[ii]
ii+=1
}
}
func drop_mesh() {
nr=0
ii=0
forall {
nseg=int(maxx.x[ii]/$1)+1
nr+=nseg
ii+=1
}
print "# comp: ",nr
finitialize()
return nr-soma.nseg+1
}
func length_mesh() { local nr
print "I started meshing"
nr=0
forall {
nseg=int(L/$2)+1
nr+=nseg
}
finitialize()
print "#comp:",nr
return nr
}
objref onseg
func fast_mesh() { local nr,max,el,i
print "I started meshing"
nr=0
onseg=new Vector(10000)
i=0
max=0
forall {
onseg.x[i]=nseg
i+=1
}
forall nseg=1
finitialize()
i=0
forall {
el=L/(lambdaf(0.5,$1))
nseg=int(el/$2)+1
if(max<el/nseg) {
max=el/nseg
maxsec=secname()
}
// if(onseg.x[i]!=nseg)printf("I changed segmend %s from %d to %d\n",secname(),onseg.x[i],nseg)
i+=1
nr+=nseg
}
finitialize()
print "Max l100 =",maxsec,max,"#comp:",nr
return nr
}
func fast_mesh_one() {
nr=0
max=0
nseg=1
finitialize()
el=L/(lambdaf(0.5,$1))
nseg=int(el/$2)+1
if(max<el/nseg) {
max=el/nseg
maxsec=secname()
}
nr+=nseg
finitialize()
print "Max l100 =",maxsec,max,"#comp:",nr
return nr
}
func uniform_mesh() {
forall nseg=$1
soma.nseg=1
finitialize()
return 210*$1+1
}
objref inj2,imp,eir,elc,f22
strdef n1
proc comp() {local th11,i
eir=new Vector(1000)
elc=new Vector(1000)
f22=new File()
sprint(n1,"%s.dat",$s1)
f22.wopen(n1)
xl=0.5
inj2 = new IClamp(0.5)
inj2.del=10 //10
inj2.dur=3 //3
inj2.amp=1
soma {
imp=new Impedance()
max_nr_comp=6000
i=1
make_table()
inj2.amp=0
while(elc.x[i-1]<max_nr_comp) {
th11=100/i
print "Th: ",th11
// nr=0
// forall {
// nseg=i
// nr+=nseg
// }
// elc.x[i]=nr+1-i
// print elc.x[i]
elc.x[i]=drop_mesh(th11)
// elc.x[i]=fast_mesh(0,th11)
// forall nseg=3^(i-1)
// elc.x[i]=0
// forall elc.x[i]+=nseg
soma.nseg=1
soma distance()
// ins_active()
// elc.x[i]=uniform_mesh(i)
// elc.x[i]=fast_mesh_one(100,th11)
// elc.x[i]=ratio_mesh(100,th11)
// elc.x[i]=transfer_mesh_2(100,th11)
init()
f22.printf("%d %d ",i,elc.x[i])
for(k=0;k<=20;k+=1) {
soma imp.loc(xl)
soma imp.compute(10*k)
soma eir.x[i]=imp.input(xl)
f22.printf("%10.1000g ",eir.x[i])
}
f22.printf("\n")
i+=1
}
f22.close()
}
}
objref w11,w22,file123
strdef name
proc comp2() {local th11,i,j
file123=new File()
for(i=0;i<1;i+=1) {
if(i>0)th11=1/i else th11=0.04
print "Th: ",th11
el1=fast_mesh(100,th11)
soma.nseg=1
// el1=uniform_mesh(i)
// el1=fast_mesh_one(100,th11)
// el1=ratio_mesh(100,th11)
// el1=transfer_mesh_2(100,th11)
w11=new Vector(30000)
w22=new Vector(30000)
cvode.record(&soma.v(0.5),w22,w11)
soma distance()
ins_active()
init()
while(t<tstop) step()
sprint(name,"Data1/%s_%0.6d_%0.5d.dat",$s1,el1,i)
file123.wopen(name)
for(j=0;j<w11.size();j+=1)file123.printf("%10.100g %10.100g\n",w11.x[j],w22.x[j])
file123.close()
}
}
objectvar rvp,yrvp,xrvp,file12,fdx,fdy
proc save_spatial() {
init()
while(t<tstop) {
step()
file12 = new File()
xrvp = new Vector()
yrvp = new Vector()
fdx = new Vector()
fdy = new Vector()
fdx = fdx.indgen(-265,804,1)
rvp = new RangeVarPlot("v")
dend8[10] rvp.begin(1)
dend3[83] rvp.end(1)
rvp.to_vector(yrvp,xrvp)
fdy = yrvp.c.interpolate(fdx,xrvp)
sprint(name,"Images/%f.ms",t)
file12.wopen(name)
for(j=0;j<fdy.size();j+=1)file12.printf("%g %10.100g %10.100g\n",t,fdx.x[j],fdy.x[j])
file12.close()
}
}
proc disc() {
forall {
if ((distance(0)>100 || distance(1)>100 ) && !issection("axon")) for (x) {
disconnect()
// v=Vrest
// ina=0
// ik=0
// ica=0
}
}
}