commit | author | age
|
ee84bd
|
1 |
#include <string.h> |
SP |
2 |
#include "general.h" |
|
3 |
#include <stdio.h> |
|
4 |
#include "initial_distribution.h" |
|
5 |
#include "vesicle.h" |
|
6 |
#include "dumpstate.h" |
|
7 |
#include <libxml/parser.h> |
|
8 |
#include <libxml/tree.h> |
43e534
|
9 |
#include "vertex.h" |
SP |
10 |
#include "energy.h" |
fda1ab
|
11 |
#include "sh.h" |
SP |
12 |
#include "cell.h" |
|
13 |
#include "frame.h" |
ee84bd
|
14 |
ts_vesicle *vtk2vesicle(char *filename, ts_tape *tape){ |
SP |
15 |
|
|
16 |
ts_uint nshell=tape->nshell; |
|
17 |
ts_uint ncmax1=tape->ncxmax; |
|
18 |
ts_uint ncmax2=tape->ncymax; |
|
19 |
ts_uint ncmax3=tape->nczmax; |
|
20 |
ts_double stepsize=tape->stepsize; |
|
21 |
|
|
22 |
ts_uint no_vertices=5*nshell*nshell+2; |
|
23 |
ts_vesicle *vesicle=init_vesicle(no_vertices,ncmax1,ncmax2,ncmax3,stepsize); |
|
24 |
vesicle->nshell=nshell; |
|
25 |
parse_vtk(filename, vesicle); |
fda1ab
|
26 |
|
SP |
27 |
//we have vertices and neighbour relations all set, but unordered. Let's do bonds, ordering, triangles... |
|
28 |
vesicle->vlist = vtk_sort_neighbours(vesicle->blist,vesicle->vlist); |
|
29 |
init_triangles(vesicle); |
|
30 |
init_triangle_neighbours(vesicle); |
|
31 |
init_common_vertex_triangle_neighbours(vesicle); |
|
32 |
init_normal_vectors(vesicle->tlist); |
|
33 |
mean_curvature_and_energy(vesicle); |
|
34 |
|
|
35 |
|
|
36 |
//preliminaries for spherical harmonics... |
|
37 |
centermass(vesicle); |
|
38 |
cell_occupation(vesicle); |
|
39 |
vesicle_volume(vesicle); //needed for constant volume at this moment |
|
40 |
vesicle_area(vesicle); //needed for constant area at this moment |
|
41 |
ts_double v0=vesicle->volume; |
|
42 |
ts_double a0=vesicle->area; |
|
43 |
ts_double r0=getR0(vesicle); |
|
44 |
if(r0&&v0&&a0); |
ee84bd
|
45 |
exit(1); |
SP |
46 |
return vesicle; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
ts_bool parse_vtk(char *filename, ts_vesicle *vesicle){ |
|
51 |
xmlDoc *doc; |
|
52 |
xmlNode *root_element=NULL; |
|
53 |
xmlNode *cur_node = NULL; |
|
54 |
doc = xmlReadFile(filename, NULL, 0); |
|
55 |
root_element=xmlDocGetRootElement(doc); |
|
56 |
cur_node=root_element->children; |
|
57 |
while(cur_node!=NULL){ |
|
58 |
// fprintf(stderr,"Node name is: %s\n",cur_node->name); |
|
59 |
if(strcmp((char *)cur_node->name,"UnstructuredGrid")==0) break; |
|
60 |
cur_node=cur_node->next; |
|
61 |
} |
|
62 |
|
|
63 |
cur_node=cur_node->children; |
|
64 |
while(cur_node!=NULL){ |
|
65 |
// fprintf(stderr,"Node name is: %s\n",cur_node->name); |
|
66 |
cur_node=cur_node->next; |
|
67 |
if(strcmp((char *)cur_node->name,"Piece")==0) break; |
|
68 |
} |
|
69 |
|
|
70 |
cur_node=cur_node->children; |
|
71 |
while(cur_node!=NULL){ |
43e534
|
72 |
//fprintf(stderr,"Node name is: %s\n",cur_node->name); |
ee84bd
|
73 |
cur_node=cur_node->next; |
SP |
74 |
if(strcmp((char *)cur_node->name,"PointData")==0) vtk_index2vesicle(cur_node->children->next->children, vesicle); |
43e534
|
75 |
if(strcmp((char *)cur_node->name,"Points")==0) vtk_coordinates(cur_node->children->next->children,vesicle); |
SP |
76 |
if(strcmp((char *)cur_node->name,"Cells")==0) { |
|
77 |
vtk_neighbours(cur_node->children->next->children,vesicle); |
|
78 |
break; //segfaults, because it finds another cells. Why? |
|
79 |
} |
ee84bd
|
80 |
} |
43e534
|
81 |
ts_fprintf(stdout,"restoring from vtk dump finished!\n"); |
ee84bd
|
82 |
return TS_SUCCESS; |
SP |
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
ts_bool vtk_index2vesicle(xmlNode *node, ts_vesicle *vesicle){ |
|
87 |
//fprintf(stderr, "vsebina: %s\n",node->content); |
|
88 |
ts_uint i; |
|
89 |
char *token; |
|
90 |
token = strtok((char *)node->content, " "); |
|
91 |
for(i=0;i<vesicle->vlist->n;i++){ |
|
92 |
vesicle->vlist->vtx[i]->idx=atoi(token); |
|
93 |
token=strtok(NULL," "); |
|
94 |
} |
|
95 |
//fprintf(stderr,"idx[11]=%d\n",vesicle->vlist->vtx[11]->idx); |
|
96 |
return TS_SUCCESS; |
|
97 |
} |
43e534
|
98 |
|
SP |
99 |
ts_bool vtk_coordinates(xmlNode *node, ts_vesicle *vesicle){ |
|
100 |
//fprintf(stderr, "vsebina: %s\n",node->content); |
|
101 |
ts_uint i; |
|
102 |
char *token; |
|
103 |
token = strtok((char *)node->content, " "); |
|
104 |
for(i=0;i<vesicle->vlist->n;i++){ |
|
105 |
vesicle->vlist->vtx[i]->x=atof(token); |
|
106 |
// fprintf(stderr,"%e, ",atof(token)); |
|
107 |
token=strtok(NULL," "); |
|
108 |
vesicle->vlist->vtx[i]->y=atof(token); |
|
109 |
token=strtok(NULL,"\n"); |
|
110 |
vesicle->vlist->vtx[i]->z=atof(token); |
|
111 |
if(i>0) token=strtok(NULL," "); |
|
112 |
} |
|
113 |
return TS_SUCCESS; |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
ts_bool vtk_neighbours(xmlNode *node, ts_vesicle *vesicle){ |
|
118 |
// fprintf(stderr, "vsebina: %s\n",node->content); |
|
119 |
ts_uint i; |
|
120 |
ts_uint idx1, idx2; |
|
121 |
char *token; |
|
122 |
token = strtok((char *)node->content, " "); |
|
123 |
for(i=0;i<3*(vesicle->vlist->n-2);i++){ |
|
124 |
idx1=atoi(token); |
|
125 |
token=strtok(NULL,"\n"); |
|
126 |
idx2=atoi(token); |
|
127 |
vtx_add_neighbour(vesicle->vlist->vtx[idx1], vesicle->vlist->vtx[idx2]); |
|
128 |
vtx_add_neighbour(vesicle->vlist->vtx[idx2], vesicle->vlist->vtx[idx1]); |
|
129 |
fprintf(stderr, "%d. povezujem %d in %d\n",i,idx1,idx2); |
|
130 |
if(i>0) token=strtok(NULL," "); |
|
131 |
} |
|
132 |
return TS_SUCCESS; |
|
133 |
} |
|
134 |
|
|
135 |
/* this is almost exact copy of init_sort_neighbours */ |
|
136 |
ts_vertex_list *vtk_sort_neighbours(ts_bond_list *blist,ts_vertex_list *vlist){ |
|
137 |
ts_vertex **vtx=vlist->vtx -1; // take a look at dipyramid function for comment. |
|
138 |
ts_uint i,l,j,jj,jjj,k=0; |
|
139 |
ts_double eps=0.001; // Take a look if EPS from math.h can be used |
|
140 |
|
|
141 |
/*lets initialize memory for temporary vertex_list. Should we write a function instead */ |
|
142 |
ts_vertex_list *tvlist=vertex_list_copy(vlist); |
|
143 |
ts_vertex **tvtx=tvlist->vtx -1; /* again to compensate for 0-indexing */ |
|
144 |
|
|
145 |
ts_double dist2; // Square of distance of neighbours |
|
146 |
ts_double direct; // Something, dont know what, but could be normal of some kind |
|
147 |
for(i=1;i<=vlist->n;i++){ |
|
148 |
k++; // WHY i IS NOT GOOD?? |
|
149 |
vtx_add_cneighbour(blist,tvtx[k], tvtx[vtx[i]->neigh[0]->idx+1]); //always add 1st |
|
150 |
jjj=1; |
|
151 |
jj=1; |
|
152 |
for(l=2;l<=vtx[i]->neigh_no;l++){ |
|
153 |
for(j=2;j<=vtx[i]->neigh_no;j++){ |
|
154 |
dist2=vtx_distance_sq(vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]); |
|
155 |
direct=vtx_direct(vtx[i],vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]); |
|
156 |
// TODO: check if fabs can be used with all floating point types!! |
|
157 |
if( (direct>0.0) && (j!=jjj) ){ |
|
158 |
vtx_add_cneighbour(blist,tvtx[k],tvtx[vtx[i]->neigh[j-1]->idx+1]); |
|
159 |
jjj=jj; |
|
160 |
jj=j; |
|
161 |
// break; |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
if(vtx[i]->neigh_no!=tvtx[i]->neigh_no){ |
|
166 |
fprintf(stderr,"Hej! pri vtx=%d se razikuje stevilo sosedov (prej=%d, potem=%d)\n",i, vtx[i]->neigh_no, tvtx[i]->neigh_no); |
|
167 |
} |
|
168 |
} |
|
169 |
if(eps>dist2); |
|
170 |
/* We use the temporary vertex for our main vertices and we abandon main |
|
171 |
* vertices, because their neighbours are not correctly ordered */ |
|
172 |
// tvtx=vlist->vtx; |
|
173 |
// vlist->vtx=tvtx; |
|
174 |
// tvlist->vtx=vtx; |
|
175 |
vtx_list_free(vlist); |
|
176 |
/* Let's make a check if the number of bonds is correct */ |
|
177 |
if((blist->n)!=3*(tvlist->n-2)){ |
|
178 |
ts_fprintf(stderr,"Number of bonds is %u should be %u!\n", blist->n, 3*(tvlist->n-2)); |
|
179 |
fatal("Number of bonds is not 3*(no_vertex-2).",4); |
|
180 |
} |
|
181 |
|
|
182 |
return tvlist; |
|
183 |
} |
|
184 |
|
|
185 |
|