commit | author | age
|
7958e9
|
1 |
#include<stdlib.h> |
SP |
2 |
#include<math.h> |
|
3 |
#include<stdio.h> |
|
4 |
#include "general.h" |
|
5 |
#include "vertex.h" |
|
6 |
#include "bond.h" |
|
7 |
#include "vesicle.h" |
|
8 |
#include "vertex.h" |
|
9 |
#include "triangle.h" |
|
10 |
#include "initial_distribution.h" |
f74313
|
11 |
#include "energy.h" |
1ab449
|
12 |
#include "poly.h" |
8a6614
|
13 |
#include "io.h" |
7958e9
|
14 |
|
SP |
15 |
ts_vesicle *initial_distribution_dipyramid(ts_uint nshell, ts_uint ncmax1, ts_uint ncmax2, ts_uint ncmax3, ts_double stepsize){ |
1ab449
|
16 |
ts_fprintf(stdout,"Starting initial_distribution on vesicle with %u shells!...\n",nshell); |
7958e9
|
17 |
ts_bool retval; |
1ab449
|
18 |
ts_uint no_vertices=5*nshell*nshell+2; |
SP |
19 |
ts_vesicle *vesicle=init_vesicle(no_vertices,ncmax1,ncmax2,ncmax3,stepsize); |
|
20 |
vesicle->nshell=nshell; |
|
21 |
//retval = vtx_set_global_values(vesicle); |
|
22 |
retval = pentagonal_dipyramid_vertex_distribution(vesicle->vlist); |
|
23 |
retval = init_vertex_neighbours(vesicle->vlist); |
|
24 |
vesicle->vlist = init_sort_neighbours(vesicle->blist,vesicle->vlist); |
b01cc1
|
25 |
// retval = init_vesicle_bonds(vesicle); // bonds are created in sort_neigh |
1ab449
|
26 |
retval = init_triangles(vesicle); |
SP |
27 |
retval = init_triangle_neighbours(vesicle); |
|
28 |
retval = init_common_vertex_triangle_neighbours(vesicle); |
|
29 |
retval = init_normal_vectors(vesicle->tlist); |
|
30 |
retval = mean_curvature_and_energy(vesicle); |
|
31 |
ts_fprintf(stdout,"initial_distribution finished!\n"); |
41a035
|
32 |
if(retval); |
7958e9
|
33 |
return vesicle; |
SP |
34 |
} |
|
35 |
|
|
36 |
|
1ab449
|
37 |
|
SP |
38 |
ts_vesicle *create_vesicle_from_tape(ts_tape *tape){ |
|
39 |
ts_vesicle *vesicle; |
bcf455
|
40 |
ts_vertex *vtx; |
M |
41 |
|
1ab449
|
42 |
vesicle=initial_distribution_dipyramid(tape->nshell,tape->ncxmax,tape->ncymax,tape->nczmax,tape->stepsize); |
58230a
|
43 |
// Nucleus: |
fe24d2
|
44 |
vesicle->R_nucleus=tape->R_nucleus*tape->R_nucleus; |
M |
45 |
|
|
46 |
vesicle->clist->dmin_interspecies = tape->dmin_interspecies*tape->dmin_interspecies; |
bcf455
|
47 |
|
58230a
|
48 |
//Initialize grafted polymers (brush): |
624f81
|
49 |
vesicle->poly_list=init_poly_list(tape->npoly,tape->nmono, vesicle->vlist, vesicle); |
1ab449
|
50 |
vesicle->spring_constant=tape->kspring; |
SP |
51 |
poly_assign_spring_const(vesicle); |
bcf455
|
52 |
|
58230a
|
53 |
//Initialize filaments (polymers inside the vesicle): |
M |
54 |
vesicle->filament_list=init_poly_list(tape->nfil,tape->nfono, NULL, vesicle); |
bcf455
|
55 |
poly_assign_filament_xi(vesicle,tape); |
58230a
|
56 |
|
bcf455
|
57 |
ts_uint i,j; |
M |
58 |
for(i=0;i<vesicle->filament_list->n;i++){ |
|
59 |
for(j=0;j<vesicle->filament_list->poly[i]->blist->n;j++){ |
|
60 |
bond_vector(vesicle->filament_list->poly[i]->blist->bond[j]); |
|
61 |
vesicle->filament_list->poly[i]->blist->bond[j]->bond_length = sqrt(vtx_distance_sq(vesicle->filament_list->poly[i]->blist->bond[j]->vtx1,vesicle->filament_list->poly[i]->blist->bond[j]->vtx2)); |
|
62 |
} |
58230a
|
63 |
} |
bcf455
|
64 |
|
M |
65 |
for(i=0;i<vesicle->filament_list->n;i++){ |
|
66 |
for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){ |
|
67 |
vtx = vesicle->filament_list->poly[i]->vlist->vtx[j]; |
|
68 |
if(vtx->bond_no == 2){ |
|
69 |
vtx->energy = -(vtx->bond[0]->x*vtx->bond[1]->x + vtx->bond[0]->y*vtx->bond[1]->y + vtx->bond[0]->z*vtx->bond[1]->z)/vtx->bond[0]->bond_length/vtx->bond[1]->bond_length; |
|
70 |
} |
|
71 |
} |
58230a
|
72 |
} |
bcf455
|
73 |
|
ea1cce
|
74 |
for(i=0;i<vesicle->filament_list->n;i++){ |
M |
75 |
vertex_list_assign_id(vesicle->filament_list->poly[i]->vlist,TS_ID_FILAMENT); |
|
76 |
} |
bcf455
|
77 |
|
58230a
|
78 |
// vesicle->spring_constant=tape->kspring; |
M |
79 |
// poly_assign_spring_const(vesicle); |
|
80 |
|
1ab449
|
81 |
|
SP |
82 |
vesicle->nshell=tape->nshell; |
|
83 |
vesicle->dmax=tape->dmax*tape->dmax; /* dmax^2 in the vesicle dmax variable */ |
|
84 |
vesicle->bending_rigidity=tape->xk0; |
|
85 |
vtx_set_global_values(vesicle); /* make xk0 default value for every vertex */ |
|
86 |
ts_fprintf(stdout, "Tape setting: xk0=%e\n",tape->xk0); |
|
87 |
vesicle->stepsize=tape->stepsize; |
|
88 |
vesicle->clist->ncmax[0]=tape->ncxmax; |
|
89 |
vesicle->clist->ncmax[1]=tape->ncymax; |
|
90 |
vesicle->clist->ncmax[2]=tape->nczmax; |
|
91 |
vesicle->clist->max_occupancy=8; /* hard coded max occupancy? */ |
|
92 |
|
|
93 |
vesicle->pressure= tape->pressure; |
|
94 |
vesicle->pswitch=tape->pswitch; |
|
95 |
|
|
96 |
return vesicle; |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
7958e9
|
104 |
ts_bool pentagonal_dipyramid_vertex_distribution(ts_vertex_list *vlist){ |
SP |
105 |
/* Some often used relations */ |
|
106 |
const ts_double s1= sin(2.0*M_PI/5.0); |
|
107 |
const ts_double s2= sin(4.0*M_PI/5.0); |
|
108 |
const ts_double c1= cos(2.0*M_PI/5.0); |
|
109 |
const ts_double c2= cos(4.0*M_PI/5.0); |
|
110 |
|
|
111 |
/* Calculates projection lenght of an edge bond to pentagram plane */ |
|
112 |
const ts_double xl0=A0/(2.0*sin(M_PI/5.0)); |
|
113 |
#ifdef TS_DOUBLE_DOUBLE |
|
114 |
const ts_double z0=sqrt(pow(A0,2)-pow(xl0,2)); |
|
115 |
#endif |
|
116 |
#ifdef TS_DOUBLE_FLOAT |
|
117 |
const ts_double z0=sqrtf(powf(A0,2)-powf(xl0,2)); |
|
118 |
#endif |
|
119 |
#ifdef TS_DOUBLE_LONGDOUBLE |
|
120 |
const ts_double z0=sqrtl(powl(A0,2)-powl(xl0,2)); |
|
121 |
#endif |
|
122 |
// const z0=sqrt(A0*A0 -xl0*xl0); /* I could use pow function but if pow is used make a check on the float type. If float then powf, if long double use powl */ |
|
123 |
|
|
124 |
/*placeholder for the pointer to vertex datastructure list... DIRTY: actual pointer points towards invalid address, one position before actual beginning of the list... This is to solve the difference between 1 based indexing in original program in fortran and 0 based indexing in C. All algorithms remain unchanged because of this!*/ |
|
125 |
ts_vertex **vtx=vlist->vtx -1 ; |
|
126 |
|
|
127 |
|
|
128 |
ts_uint nshell=(ts_uint)( sqrt((ts_double)(vlist->n-2)/5)); |
|
129 |
// printf("nshell=%u\n",nshell); |
|
130 |
ts_uint i,n0; // some for loop prereq |
|
131 |
ts_int j,k; |
|
132 |
ts_double dx,dy; // end loop prereq |
|
133 |
|
|
134 |
/* topmost vertex */ |
8f6a69
|
135 |
vtx[1]->x=0.0; |
SP |
136 |
vtx[1]->y=0.0; |
|
137 |
vtx[1]->z=z0*(ts_double)nshell; |
7958e9
|
138 |
|
SP |
139 |
/* starting from to in circular order on pentagrams */ |
|
140 |
for(i=1;i<=nshell;i++){ |
|
141 |
n0=2+5*i*(i-1)/2; //-1 would be for the reason that C index starts from 0 |
8f6a69
|
142 |
vtx[n0]->x=0.0; |
SP |
143 |
vtx[n0]->y=(ts_double)i*xl0; |
|
144 |
vtx[n0+i]->x=vtx[n0]->y*s1; |
|
145 |
vtx[n0+i]->y=vtx[n0]->y*c1; |
|
146 |
vtx[n0+2*i]->x=vtx[n0]->y*s2; |
|
147 |
vtx[n0+2*i]->y=vtx[n0]->y*c2; |
|
148 |
vtx[n0+3*i]->x=-vtx[n0+2*i]->x; |
|
149 |
vtx[n0+3*i]->y=vtx[n0+2*i]->y; |
|
150 |
vtx[n0+4*i]->x=-vtx[n0+i]->x; |
|
151 |
vtx[n0+4*i]->y=vtx[n0+i]->y; |
7958e9
|
152 |
} |
SP |
153 |
|
|
154 |
/* vertexes on the faces of the dipyramid */ |
|
155 |
for(i=1;i<=nshell;i++){ |
|
156 |
n0=2+5*i*(i-1)/2; // -1 would be because of C! |
|
157 |
for(j=1;j<=i-1;j++){ |
8f6a69
|
158 |
dx=(vtx[n0]->x-vtx[n0+4*i]->x)/(ts_double)i; |
SP |
159 |
dy=(vtx[n0]->y-vtx[n0+4*i]->y)/(ts_double)i; |
|
160 |
vtx[n0+4*i+j]->x=(ts_double)j*dx+vtx[n0+4*i]->x; |
|
161 |
vtx[n0+4*i+j]->y=(ts_double)j*dy+vtx[n0+4*i]->y; |
7958e9
|
162 |
} |
SP |
163 |
for(k=0;k<=3;k++){ // I would be worried about zero starting of for |
8f6a69
|
164 |
dx=(vtx[n0+(k+1)*i]->x - vtx[n0+k*i]->x)/(ts_double) i; |
SP |
165 |
dy=(vtx[n0+(k+1)*i]->y - vtx[n0+k*i]->y)/(ts_double) i; |
7958e9
|
166 |
for(j=1; j<=i-1;j++){ |
8f6a69
|
167 |
vtx[n0+k*i+j]->x= (ts_double)j*dx+vtx[n0+k*i]->x; |
SP |
168 |
vtx[n0+k*i+j]->y= (ts_double)j*dy+vtx[n0+k*i]->y; |
7958e9
|
169 |
} |
SP |
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
for(i=1;i<=nshell;i++){ |
|
174 |
n0= 2+ 5*i*(i-1)/2; |
|
175 |
for(j=0;j<=5*i-1;j++){ |
8f6a69
|
176 |
vtx[n0+j]->z= z0*(ts_double)(nshell-i); // I would be worried about zero starting of for |
7958e9
|
177 |
} |
SP |
178 |
} |
|
179 |
|
|
180 |
/* for botom part of dipyramide we calculate the positions of vertices */ |
|
181 |
for(i=2+5*nshell*(nshell+1)/2;i<=vlist->n;i++){ |
8f6a69
|
182 |
vtx[i]->x=vtx[vlist->n - i +1]->x; |
SP |
183 |
vtx[i]->y=vtx[vlist->n - i +1]->y; |
|
184 |
vtx[i]->z=-vtx[vlist->n - i +1]->z; |
7958e9
|
185 |
} |
SP |
186 |
|
|
187 |
for(i=1;i<=vlist->n;i++){ |
|
188 |
for(j=1;j<=vlist->n;j++){ |
|
189 |
if(i!=j && vtx_distance_sq(vtx[i],vtx[j])<0.001){ |
|
190 |
printf("Vertices %u and %u are the same!\n",i,j); |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 |
return TS_SUCCESS; |
|
195 |
} |
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
ts_bool init_vertex_neighbours(ts_vertex_list *vlist){ |
|
200 |
ts_vertex **vtx=vlist->vtx -1; // take a look at dipyramid function for comment. |
|
201 |
const ts_double eps=0.001; //TODO: find out if you can use EPS from math.h |
|
202 |
ts_uint i,j; |
|
203 |
ts_double dist2; // Square of distance of neighbours |
|
204 |
/*this is not required if we zero all data in vertex structure at initialization */ |
|
205 |
/*if we force zeroing at initialization this for loop can safely be deleted */ |
|
206 |
//for(i=1;i<=vlist->n;i++){ |
|
207 |
// vtx[i].neigh_no=0; |
|
208 |
//} |
|
209 |
for(i=1;i<=vlist->n;i++){ |
|
210 |
for(j=1;j<=vlist->n;j++){ |
|
211 |
dist2=vtx_distance_sq(vtx[i],vtx[j]); |
|
212 |
if( (dist2>eps) && (dist2<(A0*A0+eps))){ |
|
213 |
//if it is close enough, but not too much close (solves problem of comparing when i==j) |
|
214 |
vtx_add_neighbour(vtx[i],vtx[j]); |
|
215 |
} |
|
216 |
} |
|
217 |
// printf ("vertex %u ima %u sosedov!\n",i,vtx[i]->data->neigh_no); |
|
218 |
} |
|
219 |
|
|
220 |
return TS_SUCCESS; |
|
221 |
} |
|
222 |
|
b01cc1
|
223 |
// TODO: with new datastructure can be rewritten. Partially it is done, but it is complicated. |
SP |
224 |
ts_vertex_list *init_sort_neighbours(ts_bond_list *blist,ts_vertex_list *vlist){ |
7958e9
|
225 |
ts_vertex **vtx=vlist->vtx -1; // take a look at dipyramid function for comment. |
SP |
226 |
ts_uint i,l,j,jj,jjj,k=0; |
|
227 |
ts_double eps=0.001; // Take a look if EPS from math.h can be used |
|
228 |
|
|
229 |
/*lets initialize memory for temporary vertex_list. Should we write a function instead */ |
b01cc1
|
230 |
ts_vertex_list *tvlist=vertex_list_copy(vlist); |
7958e9
|
231 |
ts_vertex **tvtx=tvlist->vtx -1; /* again to compensate for 0-indexing */ |
SP |
232 |
|
|
233 |
ts_double dist2; // Square of distance of neighbours |
|
234 |
ts_double direct; // Something, dont know what, but could be normal of some kind |
|
235 |
for(i=1;i<=vlist->n;i++){ |
|
236 |
k++; // WHY i IS NOT GOOD?? |
8f6a69
|
237 |
vtx_add_cneighbour(blist,tvtx[k], tvtx[vtx[i]->neigh[0]->idx+1]); //always add 1st |
7958e9
|
238 |
jjj=1; |
SP |
239 |
jj=1; |
8f6a69
|
240 |
for(l=2;l<=vtx[i]->neigh_no;l++){ |
SP |
241 |
for(j=2;j<=vtx[i]->neigh_no;j++){ |
|
242 |
dist2=vtx_distance_sq(vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]); |
|
243 |
direct=vtx_direct(vtx[i],vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]); |
|
244 |
// TODO: check if fabs can be used with all floating point types!! |
7958e9
|
245 |
if( (fabs(dist2-A0*A0)<=eps) && (direct>0.0) && (j!=jjj) ){ |
8f6a69
|
246 |
vtx_add_cneighbour(blist,tvtx[k],tvtx[vtx[i]->neigh[j-1]->idx+1]); |
7958e9
|
247 |
jjj=jj; |
SP |
248 |
jj=j; |
|
249 |
break; |
|
250 |
} |
|
251 |
} |
|
252 |
} |
|
253 |
} |
b01cc1
|
254 |
/* We use the temporary vertex for our main vertices and we abandon main |
SP |
255 |
* vertices, because their neighbours are not correctly ordered */ |
|
256 |
// tvtx=vlist->vtx; |
|
257 |
// vlist->vtx=tvtx; |
|
258 |
// tvlist->vtx=vtx; |
|
259 |
vtx_list_free(vlist); |
|
260 |
/* Let's make a check if the number of bonds is correct */ |
|
261 |
if((blist->n)!=3*(tvlist->n-2)){ |
|
262 |
ts_fprintf(stderr,"Number of bonds is %u should be %u!\n", blist->n, 3*(tvlist->n-2)); |
|
263 |
fatal("Number of bonds is not 3*(no_vertex-2).",4); |
7958e9
|
264 |
} |
SP |
265 |
|
b01cc1
|
266 |
return tvlist; |
7958e9
|
267 |
} |
SP |
268 |
|
|
269 |
|
|
270 |
ts_bool init_vesicle_bonds(ts_vesicle *vesicle){ |
|
271 |
ts_vertex_list *vlist=vesicle->vlist; |
|
272 |
ts_bond_list *blist=vesicle->blist; |
|
273 |
ts_vertex **vtx=vesicle->vlist->vtx - 1; // Because of 0 indexing |
|
274 |
/* lets make correct clockwise ordering of in nearest neighbour list */ |
|
275 |
ts_uint i,j,k; |
|
276 |
for(i=1;i<=vlist->n;i++){ |
|
277 |
for(j=i+1;j<=vlist->n;j++){ |
8f6a69
|
278 |
for(k=0;k<vtx[i]->neigh_no;k++){ // has changed 0 to < instead of 1 and <= |
SP |
279 |
if(vtx[i]->neigh[k]==vtx[j]){ //if addresses matches it is the same |
7958e9
|
280 |
bond_add(blist,vtx[i],vtx[j]); |
SP |
281 |
break; |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
285 |
} |
|
286 |
/* Let's make a check if the number of bonds is correct */ |
|
287 |
if((blist->n)!=3*(vlist->n-2)){ |
|
288 |
ts_fprintf(stderr,"Number of bonds is %u should be %u!\n", blist->n, 3*(vlist->n-2)); |
|
289 |
fatal("Number of bonds is not 3*(no_vertex-2).",4); |
|
290 |
} |
|
291 |
return TS_SUCCESS; |
|
292 |
} |
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
ts_bool init_triangles(ts_vesicle *vesicle){ |
|
297 |
ts_uint i,j,jj,k; |
|
298 |
ts_vertex **vtx=vesicle->vlist->vtx -1; // difference between 0 indexing and 1 indexing |
|
299 |
ts_triangle_list *tlist=vesicle->tlist; |
|
300 |
ts_double dist, direct; |
|
301 |
ts_double eps=0.001; // can we use EPS from math.h? |
|
302 |
k=0; |
|
303 |
for(i=1;i<=vesicle->vlist->n;i++){ |
8f6a69
|
304 |
for(j=1;j<=vtx[i]->neigh_no;j++){ |
SP |
305 |
for(jj=1;jj<=vtx[i]->neigh_no;jj++){ |
7958e9
|
306 |
// ts_fprintf(stderr,"%u: (%u,%u) neigh_no=%u ",i,j,jj,vtx[i].neigh_no); |
SP |
307 |
// ts_fprintf(stderr,"%e, %e",vtx[i].neigh[j-1]->x,vtx[i].neigh[jj-1]->x); |
8f6a69
|
308 |
dist=vtx_distance_sq(vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]); |
SP |
309 |
direct=vtx_direct(vtx[i],vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]); |
|
310 |
// TODO: same as above |
|
311 |
if(fabs(dist-A0*A0)<=eps && direct < 0.0 && vtx[i]->neigh[j-1]->idx+1 > i && vtx[i]->neigh[jj-1]->idx+1 >i){ |
|
312 |
triangle_add(tlist,vtx[i],vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]); |
7958e9
|
313 |
} |
SP |
314 |
} |
|
315 |
} |
|
316 |
} |
|
317 |
/* We check if all triangles have 3 vertices and if the number of triangles |
|
318 |
* matches the theoretical value. |
|
319 |
*/ |
|
320 |
for(i=0;i<tlist->n;i++){ |
|
321 |
k=0; |
|
322 |
for(j=0;j<3;j++){ |
41a035
|
323 |
if(tlist->tria[i]->vertex[j]!=NULL) |
7958e9
|
324 |
k++; |
SP |
325 |
} |
|
326 |
if(k!=3){ |
8f6a69
|
327 |
fatal("Some triangles have less than 3 vertices..",4); |
7958e9
|
328 |
} |
SP |
329 |
} |
|
330 |
if(tlist->n!=2*(vesicle->vlist->n -2)){ |
|
331 |
ts_fprintf(stderr,"The number of triangles is %u but should be %u!\n",tlist->n,2*(vesicle->vlist->n -2)); |
|
332 |
fatal("The number of triangles doesn't match 2*(no_vertex -2).",4); |
|
333 |
} |
|
334 |
return TS_SUCCESS; |
|
335 |
} |
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
ts_bool init_triangle_neighbours(ts_vesicle *vesicle){ |
|
340 |
ts_uint i,j,nobo; |
|
341 |
ts_vertex *i1,*i2,*i3,*j1,*j2,*j3; |
|
342 |
// ts_vertex **vtx=vesicle->vlist->vtx -1; // difference between 0 indexing and 1 indexing |
|
343 |
ts_triangle_list *tlist=vesicle->tlist; |
|
344 |
ts_triangle **tria=tlist->tria -1; |
|
345 |
nobo=0; |
|
346 |
for(i=1;i<=tlist->n;i++){ |
41a035
|
347 |
i1=tria[i]->vertex[0]; |
SP |
348 |
i2=tria[i]->vertex[1]; |
|
349 |
i3=tria[i]->vertex[2]; |
7958e9
|
350 |
for(j=1;j<=tlist->n;j++){ |
SP |
351 |
if(j==i) continue; |
41a035
|
352 |
j1=tria[j]->vertex[0]; |
SP |
353 |
j2=tria[j]->vertex[1]; |
|
354 |
j3=tria[j]->vertex[2]; |
7958e9
|
355 |
if((i1==j1 && i3==j2) || (i1==j2 && i3==j3) || (i1==j3 && i3==j1)){ |
SP |
356 |
triangle_add_neighbour(tria[i],tria[j]); |
|
357 |
nobo++; |
|
358 |
} |
|
359 |
} |
|
360 |
} |
|
361 |
for(i=1;i<=tlist->n;i++){ |
41a035
|
362 |
i1=tria[i]->vertex[0]; |
SP |
363 |
i2=tria[i]->vertex[1]; |
|
364 |
i3=tria[i]->vertex[2]; |
7958e9
|
365 |
for(j=1;j<=tlist->n;j++){ |
SP |
366 |
if(j==i) continue; |
41a035
|
367 |
j1=tria[j]->vertex[0]; |
SP |
368 |
j2=tria[j]->vertex[1]; |
|
369 |
j3=tria[j]->vertex[2]; |
7958e9
|
370 |
if((i1==j1 && i2==j3) || (i1==j3 && i2==j2) || (i1==j2 && i2==j1)){ |
SP |
371 |
triangle_add_neighbour(tria[i],tria[j]); |
|
372 |
nobo++; |
|
373 |
} |
|
374 |
} |
|
375 |
} |
|
376 |
for(i=1;i<=tlist->n;i++){ |
41a035
|
377 |
i1=tria[i]->vertex[0]; |
SP |
378 |
i2=tria[i]->vertex[1]; |
|
379 |
i3=tria[i]->vertex[2]; |
7958e9
|
380 |
for(j=1;j<=tlist->n;j++){ |
SP |
381 |
if(j==i) continue; |
41a035
|
382 |
j1=tria[j]->vertex[0]; |
SP |
383 |
j2=tria[j]->vertex[1]; |
|
384 |
j3=tria[j]->vertex[2]; |
7958e9
|
385 |
if((i2==j1 && i3==j3) || (i2==j3 && i3==j2) || (i2==j2 && i3==j1)){ |
SP |
386 |
triangle_add_neighbour(tria[i],tria[j]); |
|
387 |
nobo++; |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
if(nobo != vesicle->blist->n*2) { |
|
392 |
ts_fprintf(stderr,"Number of triangles= %u, number of bonds= %u\n",nobo/2, vesicle->blist->n); |
|
393 |
fatal("Number of triangle neighbour pairs differs from double the number of bonds!",4); |
|
394 |
} |
|
395 |
return TS_SUCCESS; |
|
396 |
} |
|
397 |
|
|
398 |
|
|
399 |
ts_bool init_common_vertex_triangle_neighbours(ts_vesicle *vesicle){ |
|
400 |
ts_uint i,j,jp,k; |
|
401 |
ts_vertex *k1,*k2,*k3,*k4,*k5; |
|
402 |
ts_vertex **vtx=vesicle->vlist->vtx -1; // difference between 0 indexing and 1 indexing |
|
403 |
ts_triangle_list *tlist=vesicle->tlist; |
|
404 |
ts_triangle **tria=tlist->tria -1; |
|
405 |
|
|
406 |
for(i=1;i<=vesicle->vlist->n;i++){ |
8f6a69
|
407 |
for(j=1;j<=vtx[i]->neigh_no;j++){ |
SP |
408 |
k1=vtx[i]->neigh[j-1]; |
7958e9
|
409 |
jp=j+1; |
8f6a69
|
410 |
if(j == vtx[i]->neigh_no) jp=1; |
SP |
411 |
k2=vtx[i]->neigh[jp-1]; |
7958e9
|
412 |
for(k=1;k<=tlist->n;k++){ // VERY NON-OPTIMAL!!! too many loops (vlist.n * vtx.neigh * tlist.n )! |
41a035
|
413 |
k3=tria[k]->vertex[0]; |
SP |
414 |
k4=tria[k]->vertex[1]; |
|
415 |
k5=tria[k]->vertex[2]; |
7958e9
|
416 |
// ts_fprintf(stderr,"%u %u: k=(%u %u %u)\n",k1,k2,k3,k4,k5); |
SP |
417 |
if((vtx[i]==k3 && k1==k4 && k2==k5) || |
|
418 |
(vtx[i]==k4 && k1==k5 && k2==k3) || |
|
419 |
(vtx[i]==k5 && k1==k3 && k2==k4)){ |
b01cc1
|
420 |
|
SP |
421 |
//TODO: probably something wrong with neighbour distribution. |
|
422 |
// if(vtx[i]==k3 || vtx[i]==k4 || vtx[i]==k5){ |
dac2e5
|
423 |
// if(i==6) ts_fprintf(stdout, "Vtx[%u] > Added to tristar!\n",i); |
7958e9
|
424 |
vertex_add_tristar(vtx[i],tria[k]); |
SP |
425 |
} |
|
426 |
} |
|
427 |
} |
|
428 |
/* ts_fprintf(stderr,"TRISTAR for %u (%u):",i-1,vtx[i].tristar_no); |
|
429 |
for(j=0;j<vtx[i].tristar_no;j++){ |
|
430 |
ts_fprintf(stderr," %u,",vtx[i].tristar[j]->idx); |
|
431 |
} |
|
432 |
ts_fprintf(stderr,"\n"); */ |
|
433 |
} |
|
434 |
return TS_SUCCESS; |
|
435 |
} |
|
436 |
|
|
437 |
|
|
438 |
ts_bool init_normal_vectors(ts_triangle_list *tlist){ |
|
439 |
/* Normals point INSIDE vesicle */ |
|
440 |
ts_uint k; |
|
441 |
ts_triangle **tria=tlist->tria -1; //for 0 indexing |
|
442 |
for(k=1;k<=tlist->n;k++){ |
|
443 |
triangle_normal_vector(tria[k]); |
|
444 |
} |
|
445 |
return TS_SUCCESS; |
|
446 |
} |