commit | author | age
|
d7639a
|
1 |
#include<stdlib.h> |
SP |
2 |
#include<math.h> |
|
3 |
#include<string.h> |
|
4 |
#include "general.h" |
|
5 |
#include "vertex.h" |
a10dd5
|
6 |
#include "bond.h" |
d7639a
|
7 |
#include<stdio.h> |
SP |
8 |
|
73f967
|
9 |
ts_vertex_list *init_vertex_list(ts_uint N){ |
d7639a
|
10 |
ts_int i; |
a10dd5
|
11 |
ts_vertex *tlist; |
SP |
12 |
ts_vertex_list *vlist=(ts_vertex_list *)malloc(sizeof(ts_vertex_list)); |
73f967
|
13 |
|
d7639a
|
14 |
if(N==0){ |
SP |
15 |
err("Initialized vertex list with zero elements. Pointer set to NULL"); |
73f967
|
16 |
vlist->n=0; |
SP |
17 |
vlist->vtx=NULL; |
|
18 |
return vlist; |
d7639a
|
19 |
} |
73f967
|
20 |
|
a10dd5
|
21 |
vlist->vtx=(ts_vertex **)malloc(N*sizeof(ts_vertex *)); |
SP |
22 |
tlist=(ts_vertex *)malloc(N*sizeof(ts_vertex)); |
|
23 |
if(vlist->vtx==NULL || tlist==NULL) |
73f967
|
24 |
fatal("Fatal error reserving memory space for vertex list! Could number of requsted vertices be too large?", 100); |
a10dd5
|
25 |
for(i=0;i<N;i++) { |
SP |
26 |
vlist->vtx[i]=&tlist[i]; |
|
27 |
vlist->vtx[i]->data=init_vertex_data(); |
|
28 |
vlist->vtx[i]->idx=i; |
|
29 |
} |
73f967
|
30 |
vlist->n=N; |
d7639a
|
31 |
return vlist; |
SP |
32 |
} |
|
33 |
|
737714
|
34 |
ts_vertex_data *init_vertex_data(){ |
SP |
35 |
ts_vertex_data *data; |
a10dd5
|
36 |
data=(ts_vertex_data *)calloc(1,sizeof(ts_vertex_data)); |
737714
|
37 |
if(data==NULL) |
d7639a
|
38 |
fatal("Fatal error reserving memory space for ts_vertex! Memory full?", 100); |
737714
|
39 |
return data; |
d7639a
|
40 |
} |
SP |
41 |
|
|
42 |
/* |
|
43 |
ts_bool vtx_set_global_values(ts_vertex **vlist, ts_vesicle *vesicle){ |
|
44 |
ts_double xk=vesicle->bending_rigidity; |
|
45 |
ts_uint i; |
|
46 |
for(i=0;i<vesicle->vlist.n;i++){ |
|
47 |
vlist[i]->xk=xk; |
|
48 |
} |
|
49 |
return TS_SUCCESS; |
|
50 |
} |
|
51 |
*/ |
|
52 |
|
|
53 |
|
|
54 |
|
737714
|
55 |
ts_bool vtx_add_neighbour(ts_vertex *vtx, ts_vertex *nvtx){ |
d7639a
|
56 |
ts_uint i; |
SP |
57 |
/* no neighbour can be null! */ |
|
58 |
if(vtx==NULL || nvtx==NULL) return TS_FAIL; |
|
59 |
|
|
60 |
/*if it is already a neighbour don't add it to the list */ |
737714
|
61 |
for(i=0; i<vtx->data->neigh_no;i++){ |
SP |
62 |
if(vtx->data->neigh[i]==nvtx) return TS_FAIL; |
d7639a
|
63 |
} |
a10dd5
|
64 |
ts_uint nn=++vtx->data->neigh_no; |
737714
|
65 |
vtx->data->neigh=(ts_vertex **)realloc(vtx->data->neigh, nn*sizeof(ts_vertex *)); |
a10dd5
|
66 |
vtx->data->neigh[nn-1]=nvtx; |
d7639a
|
67 |
|
SP |
68 |
/* pa se sosedu dodamo vertex */ |
|
69 |
/*if it is already a neighbour don't add it to the list */ |
737714
|
70 |
for(i=0; i<nvtx->data->neigh_no;i++){ |
SP |
71 |
if(nvtx->data->neigh[i]==vtx) return TS_FAIL; |
d7639a
|
72 |
} |
a10dd5
|
73 |
nn=++nvtx->data->neigh_no; |
737714
|
74 |
nvtx->data->neigh=(ts_vertex **)realloc(nvtx->data->neigh, nn*sizeof(ts_vertex *)); |
a10dd5
|
75 |
nvtx->data->neigh[nn-1]=vtx; |
d7639a
|
76 |
|
SP |
77 |
|
|
78 |
return TS_SUCCESS; |
|
79 |
} |
a10dd5
|
80 |
|
SP |
81 |
ts_bool vtx_add_bond(ts_bond_list *blist,ts_vertex *vtx1,ts_vertex *vtx2){ |
|
82 |
ts_bond *bond; |
|
83 |
bond=bond_add(blist,vtx1,vtx2); |
|
84 |
if(bond==NULL) return TS_FAIL; |
|
85 |
vtx1->data->bond_no++; |
|
86 |
vtx2->data->bond_no++; |
|
87 |
|
|
88 |
vtx1->data->bond=(ts_bond **)realloc(vtx1->data->bond, vtx1->data->bond_no*sizeof(ts_bond *)); |
|
89 |
vtx2->data->bond=(ts_bond **)realloc(vtx2->data->bond, vtx2->data->bond_no*sizeof(ts_bond *)); |
|
90 |
vtx1->data->bond[vtx1->data->bond_no-1]=bond; |
|
91 |
vtx2->data->bond[vtx2->data->bond_no-1]=bond; |
|
92 |
return TS_SUCCESS; |
|
93 |
} |
|
94 |
|
|
95 |
ts_bool vtx_add_cneighbour(ts_bond_list *blist, ts_vertex *vtx1, ts_vertex *vtx2){ |
|
96 |
ts_bool retval; |
|
97 |
retval=vtx_add_neighbour(vtx1,vtx2); |
|
98 |
if(retval==TS_SUCCESS) |
|
99 |
retval=vtx_add_bond(blist,vtx1,vtx2); |
|
100 |
return retval; |
|
101 |
} |
|
102 |
|
|
103 |
|
d7639a
|
104 |
|
SP |
105 |
|
737714
|
106 |
ts_bool vtx_data_free(ts_vertex_data *data){ |
SP |
107 |
if(data->neigh!=NULL) free(data->neigh); |
|
108 |
if(data->tristar!=NULL) free(data->tristar); |
|
109 |
if(data->bond!=NULL) free(data->bond); |
|
110 |
if(data->cell!=NULL) free(data->cell); |
|
111 |
free(data); |
|
112 |
return TS_SUCCESS; |
|
113 |
} |
|
114 |
|
a10dd5
|
115 |
/*not usable. can be deleted */ |
737714
|
116 |
ts_bool vtx_free(ts_vertex *vtx){ |
SP |
117 |
vtx_data_free(vtx->data); |
|
118 |
free(vtx); |
d7639a
|
119 |
return TS_SUCCESS; |
SP |
120 |
} |
|
121 |
|
73f967
|
122 |
ts_bool vtx_list_free(ts_vertex_list *vlist){ |
SP |
123 |
int i; |
|
124 |
for(i=0;i<vlist->n;i++){ |
a10dd5
|
125 |
vtx_data_free(vlist->vtx[i]->data); |
73f967
|
126 |
} |
a10dd5
|
127 |
free(*(vlist->vtx)); |
737714
|
128 |
free(vlist->vtx); |
73f967
|
129 |
free(vlist); |
SP |
130 |
return TS_SUCCESS; |
|
131 |
} |
d7639a
|
132 |
|
73f967
|
133 |
|
SP |
134 |
|
737714
|
135 |
/* rewrite for additional structure in chain */ |
SP |
136 |
/*inline ts_double vtx_distance_sq(ts_vertex *vtx1, ts_vertex *vtx2){ |
d7639a
|
137 |
ts_double dist; |
SP |
138 |
#ifdef TS_DOUBLE_DOUBLE |
|
139 |
dist=pow((*vtx1)->x-(*vtx2)->x,2) + pow((*vtx1)->y-(*vtx2)->y,2) + pow((*vtx1)->z-(*vtx2)->z,2); |
|
140 |
#endif |
|
141 |
#ifdef TS_DOUBLE_LONGDOUBLE |
|
142 |
dist=powl((*vtx1)->x-(*vtx2)->x,2) + powl((*vtx1)->y-(*vtx2)->y,2) + powl((*vtx1)->z-(*vtx2)->z,2); |
|
143 |
#endif |
|
144 |
#ifdef TS_DOUBLE_FLOAT |
|
145 |
dist=powf((*vtx1)->x-(*vtx2)->x,2) + powf((*vtx1)->y-(*vtx2)->y,2) + powf((*vtx1)->z-(*vtx2)->z,2); |
|
146 |
#endif |
|
147 |
return(dist); |
|
148 |
} |
737714
|
149 |
*/ |