commit | author | age
|
7f6076
|
1 |
/* vim: set ts=4 sts=4 sw=4 noet : */ |
d7639a
|
2 |
#include<stdlib.h> |
SP |
3 |
#include "general.h" |
|
4 |
#include "energy.h" |
|
5 |
#include "vertex.h" |
7d84ef
|
6 |
#include "bond.h" |
d7639a
|
7 |
#include<math.h> |
SP |
8 |
#include<stdio.h> |
384af9
|
9 |
#include <gsl/gsl_vector_complex.h> |
SP |
10 |
#include <gsl/gsl_matrix.h> |
|
11 |
#include <gsl/gsl_eigen.h> |
17fe35
|
12 |
|
SP |
13 |
|
|
14 |
|
|
15 |
int cmpfunc(const void *x, const void *y) |
|
16 |
{ |
|
17 |
double diff= fabs(*(double*)x) - fabs(*(double*)y); |
|
18 |
if(diff<0) return 1; |
|
19 |
else return -1; |
|
20 |
} |
|
21 |
|
|
22 |
|
|
23 |
|
a00f10
|
24 |
/** @brief Wrapper that calculates energy of every vertex in vesicle |
SP |
25 |
* |
|
26 |
* Function calculated energy of every vertex in vesicle. It can be used in |
|
27 |
* initialization procedure or in recalculation of the energy after non-MCsweep * operations. However, when random move of vertex or flip of random bond occur * call to this function is not necessary nor recommended. |
|
28 |
* @param *vesicle is a pointer to vesicle. |
|
29 |
* @returns TS_SUCCESS on success. |
|
30 |
*/ |
d7639a
|
31 |
ts_bool mean_curvature_and_energy(ts_vesicle *vesicle){ |
SP |
32 |
|
f74313
|
33 |
ts_uint i; |
d7639a
|
34 |
|
f74313
|
35 |
ts_vertex_list *vlist=vesicle->vlist; |
SP |
36 |
ts_vertex **vtx=vlist->vtx; |
d7639a
|
37 |
|
SP |
38 |
for(i=0;i<vlist->n;i++){ |
f74313
|
39 |
energy_vertex(vtx[i]); |
b01cc1
|
40 |
|
d7639a
|
41 |
} |
SP |
42 |
|
|
43 |
return TS_SUCCESS; |
|
44 |
} |
|
45 |
|
a00f10
|
46 |
/** @brief Calculate energy of a bond (in models where energy is bond related) |
SP |
47 |
* |
|
48 |
* This function is experimental and currently only used in polymeres calculation (PEGs or polymeres inside the vesicle). |
|
49 |
* |
|
50 |
* @param *bond is a pointer to a bond between two vertices in polymere |
|
51 |
* @param *poly is a pointer to polymere in which we calculate te energy of the bond |
|
52 |
* @returns TS_SUCCESS on successful calculation |
|
53 |
*/ |
fedf2b
|
54 |
inline ts_bool bond_energy(ts_bond *bond,ts_poly *poly){ |
304510
|
55 |
//TODO: This value to be changed and implemented in data structure: |
M |
56 |
ts_double d_relaxed=1.0; |
|
57 |
bond->energy=poly->k*pow(bond->bond_length-d_relaxed,2); |
fedf2b
|
58 |
return TS_SUCCESS; |
M |
59 |
}; |
|
60 |
|
e6efc6
|
61 |
/** @brief Calculation of the bending energy of the vertex. |
a00f10
|
62 |
* |
e6efc6
|
63 |
* Main function that calculates energy of the vertex \f$i\f$. Function returns \f$\frac{1}{2}(c_1+c_2-c)^2 s\f$, where \f$(c_1+c_2)/2\f$ is mean curvature, |
SP |
64 |
* \f$c/2\f$ is spontaneous curvature and \f$s\f$ is area per vertex \f$i\f$. |
|
65 |
* |
|
66 |
* Nearest neighbors (NN) must be ordered in counterclockwise direction for this function to work. |
a00f10
|
67 |
* Firstly NNs that form two neighboring triangles are found (\f$j_m\f$, \f$j_p\f$ and common \f$j\f$). Later, the scalar product of vectors \f$x_1=(\mathbf{i}-\mathbf{j_p})\cdot (\mathbf{i}-\mathbf{j_p})(\mathbf{i}-\mathbf{j_p})\f$, \f$x_2=(\mathbf{j}-\mathbf{j_p})\cdot (\mathbf{j}-\mathbf{j_p})\f$ and \f$x_3=(\mathbf{j}-\mathbf{j_p})\cdot (\mathbf{i}-\mathbf{j_p})\f$ are calculated. From these three vectors the \f$c_{tp}=\frac{1}{\tan(\varphi_p)}\f$ is calculated, where \f$\varphi_p\f$ is the inner angle at vertex \f$j_p\f$. The procedure is repeated for \f$j_m\f$ instead of \f$j_p\f$ resulting in \f$c_{tn}\f$. |
SP |
68 |
* |
854cb6
|
69 |
\begin{tikzpicture}{ |
a00f10
|
70 |
\coordinate[label=below:$i$] (i) at (2,0); |
SP |
71 |
\coordinate[label=left:$j_m$] (jm) at (0,3.7); |
|
72 |
\coordinate[label=above:$j$] (j) at (2.5,6.4); |
|
73 |
\coordinate[label=right:$j_p$] (jp) at (4,2.7); |
d7639a
|
74 |
|
a00f10
|
75 |
\draw (i) -- (jm) -- (j) -- (jp) -- (i) -- (j); |
SP |
76 |
|
|
77 |
\begin{scope} |
|
78 |
\path[clip] (jm)--(i)--(j); |
|
79 |
\draw (jm) circle (0.8); |
|
80 |
\node[right] at (jm) {$\varphi_m$}; |
|
81 |
\end{scope} |
|
82 |
|
|
83 |
\begin{scope} |
|
84 |
\path[clip] (jp)--(i)--(j); |
|
85 |
\draw (jp) circle (0.8); |
|
86 |
\node[left] at (jp) {$\varphi_p$}; |
|
87 |
\end{scope} |
|
88 |
|
|
89 |
%%vertices |
|
90 |
\draw [fill=gray] (i) circle (0.1); |
|
91 |
\draw [fill=white] (j) circle (0.1); |
|
92 |
\draw [fill=white] (jp) circle (0.1); |
|
93 |
\draw [fill=white] (jm) circle (0.1); |
|
94 |
%\node[draw,circle,fill=white] at (i) {}; |
854cb6
|
95 |
\end{tikzpicture} |
a00f10
|
96 |
|
SP |
97 |
* The curvature is then calculated as \f$\mathbf{h}=\frac{1}{2}\Sigma_{k=0}^{\mathrm{neigh\_no}} c_{tp}^{(k)}+c_{tm}^{(k)} (\mathbf{j_k}-\mathbf{i})\f$, where \f$c_{tp}^{(k)}+c_{tm}^k=2\sigma^{(k)}\f$ (length in dual lattice?) and the previous equation can be written as \f$\mathbf{h}=\Sigma_{k=0}^{\mathrm{neigh\_no}}\sigma^{(k)}\cdot(\mathbf{j}-\mathbf{i})\f$ (See Kroll, p. 384, eq 70). |
|
98 |
* |
|
99 |
* From the curvature the enery is calculated by equation \f$E=\frac{1}{2}\mathbf{h}\cdot\mathbf{h}\f$. |
|
100 |
* @param *vtx is a pointer to vertex at which we want to calculate the energy |
|
101 |
* @returns TS_SUCCESS on successful calculation. |
|
102 |
*/ |
d7639a
|
103 |
inline ts_bool energy_vertex(ts_vertex *vtx){ |
608cbe
|
104 |
ts_uint jj, i, j; |
7d84ef
|
105 |
ts_double edge_vector_x[7]={0,0,0,0,0,0,0}; |
SP |
106 |
ts_double edge_vector_y[7]={0,0,0,0,0,0,0}; |
|
107 |
ts_double edge_vector_z[7]={0,0,0,0,0,0,0}; |
|
108 |
ts_double edge_normal_x[7]={0,0,0,0,0,0,0}; |
|
109 |
ts_double edge_normal_y[7]={0,0,0,0,0,0,0}; |
|
110 |
ts_double edge_normal_z[7]={0,0,0,0,0,0,0}; |
|
111 |
ts_double edge_binormal_x[7]={0,0,0,0,0,0,0}; |
|
112 |
ts_double edge_binormal_y[7]={0,0,0,0,0,0,0}; |
|
113 |
ts_double edge_binormal_z[7]={0,0,0,0,0,0,0}; |
|
114 |
ts_double vertex_normal_x=0.0; |
|
115 |
ts_double vertex_normal_y=0.0; |
|
116 |
ts_double vertex_normal_z=0.0; |
608cbe
|
117 |
// ts_triangle *triedge[2]={NULL,NULL}; |
a63f17
|
118 |
|
608cbe
|
119 |
ts_uint nei,neip,neim; |
SP |
120 |
ts_vertex *it, *k, *kp,*km; |
|
121 |
ts_triangle *lm=NULL, *lp=NULL; |
7d84ef
|
122 |
ts_double sumnorm; |
8493be
|
123 |
ts_double temp_length; |
d7639a
|
124 |
|
384af9
|
125 |
|
SP |
126 |
ts_double Se11, Se21, Se22, Se31, Se32, Se33; |
|
127 |
ts_double Pv11, Pv21, Pv22, Pv31, Pv32, Pv33; |
|
128 |
ts_double We; |
|
129 |
ts_double Av, We_Av; |
|
130 |
|
17fe35
|
131 |
ts_double eigenval[3]; |
SP |
132 |
|
384af9
|
133 |
gsl_matrix *gsl_Sv=gsl_matrix_alloc(3,3); |
17fe35
|
134 |
gsl_vector *Sv_eigen=gsl_vector_alloc(3); |
SP |
135 |
gsl_eigen_symm_workspace *workspace=gsl_eigen_symm_alloc(3); |
384af9
|
136 |
|
SP |
137 |
ts_double mprod[7], phi[7], he[7]; |
|
138 |
ts_double Sv[3][3]={{0,0,0},{0,0,0},{0,0,0}}; |
7d84ef
|
139 |
// Here edge vector is calculated |
SP |
140 |
// fprintf(stderr, "Vertex has neighbours=%d\n", vtx->neigh_no); |
8493be
|
141 |
|
SP |
142 |
|
|
143 |
|
|
144 |
|
384af9
|
145 |
Av=0; |
SP |
146 |
for(i=0; i<vtx->tristar_no; i++){ |
efb615
|
147 |
vertex_normal_x=(vertex_normal_x - vtx->tristar[i]->xnorm*vtx->tristar[i]->area); |
SP |
148 |
vertex_normal_y=(vertex_normal_y - vtx->tristar[i]->ynorm*vtx->tristar[i]->area); |
|
149 |
vertex_normal_z=(vertex_normal_z - vtx->tristar[i]->znorm*vtx->tristar[i]->area); |
384af9
|
150 |
Av+=vtx->tristar[i]->area/3; |
SP |
151 |
} |
8493be
|
152 |
temp_length=sqrt(pow(vertex_normal_x,2)+pow(vertex_normal_y,2)+pow(vertex_normal_z,2)); |
SP |
153 |
vertex_normal_x=vertex_normal_x/temp_length; |
|
154 |
vertex_normal_y=vertex_normal_y/temp_length; |
|
155 |
vertex_normal_z=vertex_normal_z/temp_length; |
384af9
|
156 |
|
SP |
157 |
Pv11=1-vertex_normal_x*vertex_normal_x; |
|
158 |
Pv22=1-vertex_normal_y*vertex_normal_y; |
|
159 |
Pv33=1-vertex_normal_z*vertex_normal_z; |
|
160 |
Pv21=vertex_normal_x*vertex_normal_y; |
|
161 |
Pv31=vertex_normal_x*vertex_normal_z; |
|
162 |
Pv32=vertex_normal_y*vertex_normal_z; |
|
163 |
|
efb615
|
164 |
/* if(vtx->idx==0){ |
SP |
165 |
printf("Vertex normal for vertex %d: %f, %f, %f\n",vtx->idx,vertex_normal_x, vertex_normal_y, vertex_normal_z); |
|
166 |
} |
|
167 |
*/ |
8493be
|
168 |
for(jj=0;jj<vtx->neigh_no;jj++){ |
SP |
169 |
edge_vector_x[jj]=vtx->neigh[jj]->x-vtx->x; |
|
170 |
edge_vector_y[jj]=vtx->neigh[jj]->y-vtx->y; |
|
171 |
edge_vector_z[jj]=vtx->neigh[jj]->z-vtx->z; |
|
172 |
|
|
173 |
//Here we calculate normalized edge vector |
|
174 |
|
|
175 |
temp_length=sqrt(edge_vector_x[jj]*edge_vector_x[jj]+edge_vector_y[jj]*edge_vector_y[jj]+edge_vector_z[jj]*edge_vector_z[jj]); |
|
176 |
edge_vector_x[jj]=edge_vector_x[jj]/temp_length; |
|
177 |
edge_vector_y[jj]=edge_vector_y[jj]/temp_length; |
|
178 |
edge_vector_z[jj]=edge_vector_z[jj]/temp_length; |
|
179 |
|
|
180 |
//end normalization |
384af9
|
181 |
// printf("(%f %f %f)\n", vertex_normal_x, vertex_normal_y, vertex_normal_z); |
efb615
|
182 |
/* |
SP |
183 |
if(vtx->idx==0){ |
|
184 |
printf("Edge vector for vertex %d (vector %d): %f, %f, %f\n",vtx->idx,jj,edge_vector_x[jj], edge_vector_y[jj], edge_vector_z[jj]); |
|
185 |
} |
|
186 |
*/ |
608cbe
|
187 |
it=vtx; |
SP |
188 |
k=vtx->neigh[jj]; |
|
189 |
nei=0; |
|
190 |
for(i=0;i<it->neigh_no;i++){ // Finds the nn of it, that is k |
|
191 |
if(it->neigh[i]==k){ |
|
192 |
nei=i; |
|
193 |
break; |
|
194 |
} |
|
195 |
} |
|
196 |
neip=nei+1; // I don't like it.. Smells like I must have it in correct order |
|
197 |
neim=nei-1; |
|
198 |
if(neip>=it->neigh_no) neip=0; |
|
199 |
if((ts_int)neim<0) neim=it->neigh_no-1; /* casting is essential... If not |
|
200 |
there the neim is never <0 !!! */ |
|
201 |
// fprintf(stderr,"The numbers are: %u %u\n",neip, neim); |
|
202 |
km=it->neigh[neim]; // We located km and kp |
|
203 |
kp=it->neigh[neip]; |
|
204 |
|
|
205 |
if(km==NULL || kp==NULL){ |
384af9
|
206 |
fatal("energy_vertex: cannot determine km and kp!",233); |
608cbe
|
207 |
} |
SP |
208 |
|
|
209 |
for(i=0;i<it->tristar_no;i++){ |
|
210 |
for(j=0;j<k->tristar_no;j++){ |
|
211 |
if((it->tristar[i] == k->tristar[j])){ //ce gre za skupen trikotnik |
|
212 |
if((it->tristar[i]->vertex[0] == km || it->tristar[i]->vertex[1] |
|
213 |
== km || it->tristar[i]->vertex[2]== km )){ |
|
214 |
lm=it->tristar[i]; |
|
215 |
// lmidx=i; |
|
216 |
} |
|
217 |
else |
|
218 |
{ |
|
219 |
lp=it->tristar[i]; |
|
220 |
// lpidx=i; |
|
221 |
} |
|
222 |
|
|
223 |
} |
|
224 |
} |
|
225 |
} |
384af9
|
226 |
if(lm==NULL || lp==NULL) fatal("energy_vertex: Cannot find triangles lm and lp!",233); |
d7639a
|
227 |
|
8493be
|
228 |
//Triangle normals are NORMALIZED! |
SP |
229 |
|
608cbe
|
230 |
sumnorm=sqrt( pow((lm->xnorm + lp->xnorm),2) + pow((lm->ynorm + lp->ynorm), 2) + pow((lm->znorm + lp->znorm), 2)); |
SP |
231 |
|
|
232 |
edge_normal_x[jj]=(lm->xnorm+ lp->xnorm)/sumnorm; |
|
233 |
edge_normal_y[jj]=(lm->ynorm+ lp->ynorm)/sumnorm; |
|
234 |
edge_normal_z[jj]=(lm->znorm+ lp->znorm)/sumnorm; |
7d84ef
|
235 |
|
SP |
236 |
|
|
237 |
edge_binormal_x[jj]=(edge_normal_y[jj]*edge_vector_z[jj])-(edge_normal_z[jj]*edge_vector_y[jj]); |
|
238 |
edge_binormal_y[jj]=-(edge_normal_x[jj]*edge_vector_z[jj])+(edge_normal_z[jj]*edge_vector_x[jj]); |
|
239 |
edge_binormal_z[jj]=(edge_normal_x[jj]*edge_vector_y[jj])-(edge_normal_y[jj]*edge_vector_x[jj]); |
|
240 |
|
384af9
|
241 |
|
efb615
|
242 |
//mprod[jj]=it->x*(k->y*edge_vector_z[jj]-edge_vector_y[jj]*k->z)-it->y*(k->x*edge_vector_z[jj]-k->z*edge_vector_x[jj])+it->z*(k->x*edge_vector_y[jj]-k->y*edge_vector_x[jj]); |
SP |
243 |
mprod[jj]=lm->xnorm*(lp->ynorm*edge_vector_z[jj]-lp->znorm*edge_vector_y[jj]) - lm->ynorm*(lp->xnorm*edge_vector_z[jj]-lp->znorm*edge_vector_z[jj])+ lm->znorm*(lp->xnorm*edge_vector_y[jj]-lp->ynorm*edge_vector_x[jj]); |
|
244 |
|
|
245 |
phi[jj]=copysign(acos(lm->xnorm*lp->xnorm+lm->ynorm*lp->ynorm+lm->znorm*lp->znorm-1e-10),-mprod[jj])+M_PI; |
|
246 |
/* if(vtx->idx==0){ |
|
247 |
printf("Angle PHI vertex %d (angle %d): %f\n",vtx->idx,jj,phi[jj]); |
|
248 |
} |
|
249 |
*/ |
8493be
|
250 |
// printf("ACOS arg=%e\n", lm->xnorm*lp->xnorm+lm->ynorm*lp->ynorm+lm->znorm*lp->znorm); |
SP |
251 |
//he was multiplied with 2 before... |
efb615
|
252 |
// he[jj]=sqrt( pow((edge_vector_x[jj]),2) + pow((edge_vector_y[jj]), 2) + pow((edge_vector_z[jj]), 2))*cos(phi[jj]/2.0); |
SP |
253 |
he[jj]=temp_length*cos(phi[jj]/2.0); |
8493be
|
254 |
// printf("phi[%d]=%f\n", jj,phi[jj]); |
efb615
|
255 |
/* |
SP |
256 |
if(vtx->idx==0){ |
|
257 |
printf("H operator of edge vertex %d (edge %d): %f\n",vtx->idx,jj,he[jj]); |
|
258 |
} |
|
259 |
*/ |
|
260 |
Se11=-edge_binormal_x[jj]*edge_binormal_x[jj]*he[jj]; |
|
261 |
Se21=-edge_binormal_x[jj]*edge_binormal_y[jj]*he[jj]; |
|
262 |
Se22=-edge_binormal_y[jj]*edge_binormal_y[jj]*he[jj]; |
|
263 |
Se31=-edge_binormal_x[jj]*edge_binormal_z[jj]*he[jj]; |
|
264 |
Se32=-edge_binormal_y[jj]*edge_binormal_z[jj]*he[jj]; |
|
265 |
Se33=-edge_binormal_z[jj]*edge_binormal_z[jj]*he[jj]; |
384af9
|
266 |
|
SP |
267 |
We=vertex_normal_x*edge_normal_x[jj]+vertex_normal_y*edge_normal_y[jj]+vertex_normal_z*edge_normal_z[jj]; |
|
268 |
We_Av=We/Av; |
|
269 |
|
|
270 |
Sv[0][0]+=We_Av* ( Pv11*(Pv11*Se11+Pv21*Se21+Pv31*Se31)+Pv21*(Pv11*Se21+Pv21*Se22+Pv31*Se32)+Pv31*(Pv11*Se31+Pv21*Se32+Pv31*Se33) ); |
|
271 |
Sv[0][1]+=We_Av* (Pv21*(Pv11*Se11+Pv21*Se21+Pv31*Se31)+Pv22*(Pv11*Se21+Pv21*Se22+Pv31*Se32)+Pv32*(Pv11*Se31+Pv21*Se32+Pv31*Se33)); |
|
272 |
Sv[0][2]+=We_Av* (Pv31*(Pv11*Se11+Pv21*Se21+Pv31*Se31)+Pv32*(Pv11*Se21+Pv21*Se22+Pv31*Se32)+Pv33*(Pv11*Se31+Pv21*Se32+Pv31*Se33)); |
|
273 |
|
|
274 |
Sv[1][0]+=We_Av* (Pv11*(Pv21*Se11+Pv22*Se21+Pv32*Se31)+Pv21*(Pv21*Se21+Pv22*Se22+Pv32*Se32)+Pv31*(Pv21*Se31+Pv22*Se32+Pv32*Se33)); |
|
275 |
Sv[1][1]+=We_Av* (Pv21*(Pv21*Se11+Pv22*Se21+Pv32*Se31)+Pv22*(Pv21*Se21+Pv22*Se22+Pv32*Se32)+Pv32*(Pv21*Se31+Pv22*Se32+Pv32*Se33)); |
|
276 |
Sv[1][2]+=We_Av* (Pv31*(Pv21*Se11+Pv22*Se21+Pv32*Se31)+Pv32*(Pv21*Se21+Pv22*Se22+Pv32*Se32)+Pv33*(Pv21*Se31+Pv22*Se32+Pv32*Se33)); |
|
277 |
|
|
278 |
Sv[2][0]+=We_Av* (Pv11*(Pv31*Se11+Pv32*Se21+Pv33*Se31)+Pv21*(Pv31*Se21+Pv32*Se22+Pv33*Se32)+Pv31*(Pv31*Se31+Pv32*Se32+Pv33*Se33)); |
|
279 |
Sv[2][1]+=We_Av* (Pv21*(Pv31*Se11+Pv32*Se21+Pv33*Se31)+Pv22*(Pv31*Se21+Pv32*Se22+Pv33*Se32)+Pv32*(Pv31*Se31+Pv32*Se32+Pv33*Se33)); |
|
280 |
Sv[2][2]+=We_Av* (Pv31*(Pv31*Se11+Pv32*Se21+Pv33*Se31)+Pv32*(Pv31*Se21+Pv32*Se22+Pv33*Se32)+Pv33*(Pv31*Se31+Pv32*Se32+Pv33*Se33)); |
|
281 |
// printf("(%f %f %f); (%f %f %f); (%f %f %f)\n", edge_vector_x[jj], edge_vector_y[jj], edge_vector_z[jj], edge_normal_x[jj], edge_normal_y[jj], edge_normal_z[jj], edge_binormal_x[jj], edge_binormal_y[jj], edge_binormal_z[jj]); |
7d84ef
|
282 |
|
8493be
|
283 |
} // END FOR JJ |
384af9
|
284 |
gsl_matrix_set(gsl_Sv, 0,0, Sv[0][0]); |
SP |
285 |
gsl_matrix_set(gsl_Sv, 0,1, Sv[0][1]); |
|
286 |
gsl_matrix_set(gsl_Sv, 0,2, Sv[0][2]); |
|
287 |
gsl_matrix_set(gsl_Sv, 1,0, Sv[1][0]); |
|
288 |
gsl_matrix_set(gsl_Sv, 1,1, Sv[1][1]); |
|
289 |
gsl_matrix_set(gsl_Sv, 1,2, Sv[1][2]); |
|
290 |
gsl_matrix_set(gsl_Sv, 2,0, Sv[2][0]); |
|
291 |
gsl_matrix_set(gsl_Sv, 2,1, Sv[2][1]); |
|
292 |
gsl_matrix_set(gsl_Sv, 2,2, Sv[2][2]); |
|
293 |
|
8493be
|
294 |
// printf("Se= %f, %f, %f\n %f, %f, %f\n %f, %f, %f\n", Se11, Se21, Se31, Se21, Se22, Se32, Se31, Se32, Se33); |
SP |
295 |
// printf("Pv= %f, %f, %f\n %f, %f, %f\n %f, %f, %f\n", Pv11, Pv21, Pv31, Pv21, Pv22, Pv32, Pv31, Pv32, Pv33); |
17fe35
|
296 |
// printf("Sv= %f, %f, %f\n %f, %f, %f\n %f, %f, %f\n", Sv[0][0], Sv[0][1], Sv[0][2], Sv[1][0], Sv[1][1], Sv[1][2], Sv[2][0], Sv[2][1], Sv[2][2]); |
8493be
|
297 |
|
384af9
|
298 |
|
17fe35
|
299 |
gsl_eigen_symm(gsl_Sv, Sv_eigen, workspace); |
SP |
300 |
|
|
301 |
// printf("Eigenvalues: %f, %f, %f\n", gsl_vector_get(Sv_eigen, 0),gsl_vector_get(Sv_eigen, 1), gsl_vector_get(Sv_eigen, 2) ); |
|
302 |
// printf("Eigenvalues: %f, %f, %f\n", gsl_matrix_get(evec, 0,0),gsl_matrix_get(evec, 0,1), gsl_matrix_get(evec, 0,2) ); |
|
303 |
|
|
304 |
|
|
305 |
eigenval[0]= gsl_vector_get(Sv_eigen, 0); |
|
306 |
eigenval[1]= gsl_vector_get(Sv_eigen, 1); |
|
307 |
eigenval[2]= gsl_vector_get(Sv_eigen, 2); |
|
308 |
|
|
309 |
qsort(eigenval, 3, sizeof(ts_double), cmpfunc); |
51f7fd
|
310 |
if(vtx->idx==1){ |
efb615
|
311 |
printf("Eigenvalues: %f, %f, %f\n", eigenval[0], eigenval[1], eigenval[2] ); |
51f7fd
|
312 |
exit(0); |
efb615
|
313 |
} |
17fe35
|
314 |
|
SP |
315 |
vtx->energy=(pow(eigenval[0]+eigenval[1],2))*Av; |
384af9
|
316 |
|
SP |
317 |
gsl_matrix_free(gsl_Sv); |
17fe35
|
318 |
gsl_vector_free(Sv_eigen); |
SP |
319 |
// gsl_matrix_free(evec); |
|
320 |
gsl_eigen_symm_free(workspace); |
7d84ef
|
321 |
return TS_SUCCESS; |
d7639a
|
322 |
} |
e5858f
|
323 |
|
SP |
324 |
ts_bool sweep_attraction_bond_energy(ts_vesicle *vesicle){ |
|
325 |
int i; |
|
326 |
for(i=0;i<vesicle->blist->n;i++){ |
|
327 |
attraction_bond_energy(vesicle->blist->bond[i], vesicle->tape->w); |
|
328 |
} |
|
329 |
return TS_SUCCESS; |
|
330 |
} |
|
331 |
|
|
332 |
|
|
333 |
inline ts_bool attraction_bond_energy(ts_bond *bond, ts_double w){ |
|
334 |
|
|
335 |
if(fabs(bond->vtx1->c)>1e-16 && fabs(bond->vtx2->c)>1e-16){ |
032273
|
336 |
bond->energy=-w; |
e5858f
|
337 |
} |
SP |
338 |
else { |
|
339 |
bond->energy=0.0; |
|
340 |
} |
|
341 |
return TS_SUCCESS; |
|
342 |
} |
250de4
|
343 |
|
SP |
344 |
ts_double direct_force_energy(ts_vesicle *vesicle, ts_vertex *vtx, ts_vertex *vtx_old){ |
|
345 |
if(fabs(vtx->c)<1e-15) return 0.0; |
|
346 |
// printf("was here"); |
|
347 |
if(fabs(vesicle->tape->F)<1e-15) return 0.0; |
|
348 |
|
|
349 |
ts_double norml,ddp=0.0; |
|
350 |
ts_uint i; |
|
351 |
ts_double xnorm=0.0,ynorm=0.0,znorm=0.0; |
02d65c
|
352 |
/*find normal of the vertex as sum of all the normals of the triangles surrounding it. */ |
250de4
|
353 |
for(i=0;i<vtx->tristar_no;i++){ |
02d65c
|
354 |
xnorm+=vtx->tristar[i]->xnorm; |
MF |
355 |
ynorm+=vtx->tristar[i]->ynorm; |
|
356 |
znorm+=vtx->tristar[i]->znorm; |
250de4
|
357 |
} |
SP |
358 |
/*normalize*/ |
|
359 |
norml=sqrt(xnorm*xnorm+ynorm*ynorm+znorm*znorm); |
|
360 |
xnorm/=norml; |
|
361 |
ynorm/=norml; |
|
362 |
znorm/=norml; |
|
363 |
/*calculate ddp, perpendicular displacement*/ |
c372c1
|
364 |
ddp=xnorm*(vtx->x-vtx_old->x)+ynorm*(vtx->y-vtx_old->y)+znorm*(vtx->z-vtx_old->z); |
250de4
|
365 |
/*calculate dE*/ |
SP |
366 |
// printf("ddp=%e",ddp); |
|
367 |
return vesicle->tape->F*ddp; |
|
368 |
|
|
369 |
} |
7ec6fb
|
370 |
|
SP |
371 |
void stretchenergy(ts_vesicle *vesicle, ts_triangle *triangle){ |
04694f
|
372 |
triangle->energy=vesicle->tape->xkA0/2.0*pow((triangle->area/vesicle->tlist->a0-1.0),2); |
7ec6fb
|
373 |
} |