1 |
#define _FILE_OFFSET_BITS 64 |
2 |
|
3 |
#include <stdio.h> |
4 |
#include <stdlib.h> |
5 |
#include <math.h> |
6 |
#include <mkl_lapack64.h> |
7 |
|
8 |
|
9 |
#include "params.h" |
10 |
#include "tcProps.h" |
11 |
#include "readWrite.h" |
12 |
#include "directorHead.h" |
13 |
|
14 |
|
15 |
|
16 |
struct directStr{ |
17 |
double uTop[3]; |
18 |
double uBottom[3]; |
19 |
double orderTop; |
20 |
double orderBottom; |
21 |
double time; |
22 |
}; |
23 |
|
24 |
struct directStr* directorHead; |
25 |
|
26 |
|
27 |
void accumDHFrame( int index, struct atomCoord *atoms ); |
28 |
|
29 |
void calcDirHeadCorr(double startTime, struct atomCoord* atoms, |
30 |
char* outPrefix ){ |
31 |
|
32 |
// list of 'a priori' constants |
33 |
|
34 |
const int nLipAtoms = NL_ATOMS; |
35 |
const int nBonds = NBONDS; |
36 |
const int nLipids = NLIPIDS; |
37 |
const int nSSD = NSSD; |
38 |
const int nAtoms = nLipAtoms * nLipids + nSSD; |
39 |
|
40 |
// variables |
41 |
|
42 |
char outName[500]; |
43 |
FILE* outFile; |
44 |
int i, j, k; |
45 |
int startFrame, corrFrames, framesFinished; |
46 |
int startFound, percentComplete; |
47 |
|
48 |
double Hmat[3][3]; |
49 |
|
50 |
framesFinished = 0; |
51 |
|
52 |
startFound = 0; |
53 |
startFrame = -1; |
54 |
while( !startFound ){ |
55 |
|
56 |
startFrame++; |
57 |
|
58 |
if(startFrame >= nFrames){ |
59 |
|
60 |
fprintf( stderr, |
61 |
"Start Time, %G, was not found in the dump file.\n", |
62 |
startTime ); |
63 |
exit(0); |
64 |
} |
65 |
|
66 |
if(startTime <= frameTimes[startFrame]) |
67 |
startFound = 1; |
68 |
|
69 |
|
70 |
} |
71 |
|
72 |
corrFrames = nFrames - startFrame; |
73 |
directorHead = (struct directStr*)calloc(corrFrames, |
74 |
sizeof(struct directStr)); |
75 |
|
76 |
for(i=startFrame; i<nFrames; i++){ |
77 |
|
78 |
percentComplete = |
79 |
(int)( 100.0 * (double)framesFinished / (double) corrFrames ); |
80 |
|
81 |
fprintf( stdout, |
82 |
"\rDirector head corr %3d%% complete.", |
83 |
percentComplete ); |
84 |
fflush( stdout ); |
85 |
|
86 |
readFrame( i, atoms, Hmat ); |
87 |
|
88 |
accumDHFrame( i-startFrame, atoms ); |
89 |
|
90 |
framesFinished++; |
91 |
} |
92 |
|
93 |
sprintf( outName, "%s.dirHeadTop", outPrefix ); |
94 |
outFile = fopen( outName, "w" ); |
95 |
fprintf( outFile, |
96 |
"#time\torderParam\tx\ty\tz\n"); |
97 |
|
98 |
for(i=0;i<corrFrames;i++){ |
99 |
fprintf( outFile, |
100 |
"%6G\t%6G\t%6G\t%6G\t%6G\n", |
101 |
directorHead[i].time, |
102 |
directorHead[i].orderTop, |
103 |
directorHead[i].uTop[0], |
104 |
directorHead[i].uTop[1], |
105 |
directorHead[i].uTop[2]); |
106 |
} |
107 |
fflush(outFile); |
108 |
fclose(outFile); |
109 |
|
110 |
sprintf( outName, "%s.dirHeadBottom", outPrefix ); |
111 |
outFile = fopen( outName, "w" ); |
112 |
fprintf( outFile, |
113 |
"#time\torderParam\tx\ty\tz\n"); |
114 |
|
115 |
for(i=0;i<corrFrames;i++){ |
116 |
fprintf( outFile, |
117 |
"%6G\t%6G\t%6G\t%6G\t%6G\n", |
118 |
directorHead[i].time, |
119 |
directorHead[i].orderBottom, |
120 |
directorHead[i].uBottom[0], |
121 |
directorHead[i].uBottom[1], |
122 |
directorHead[i].uBottom[2]); |
123 |
} |
124 |
fflush(outFile); |
125 |
fclose(outFile); |
126 |
|
127 |
|
128 |
percentComplete = |
129 |
(int)( 100.0 * (double)framesFinished / (double) corrFrames ); |
130 |
|
131 |
fprintf( stdout, |
132 |
"\rDirector head corr %3d%% complete.\n" |
133 |
"done.\n", |
134 |
percentComplete ); |
135 |
fflush( stdout ); |
136 |
|
137 |
free( directorHead ); |
138 |
directorHead = NULL; |
139 |
} |
140 |
|
141 |
|
142 |
void accumDHFrame( int index, struct atomCoord *atoms ){ |
143 |
|
144 |
// list of 'a priori' constants |
145 |
|
146 |
const int nLipAtoms = NL_ATOMS; |
147 |
const int nBonds = NBONDS; |
148 |
const int nLipids = NLIPIDS; |
149 |
const int nSSD = NSSD; |
150 |
const int nAtoms = nLipAtoms * nLipids + nSSD; |
151 |
const double oneThird = 1.0 / 3.0; |
152 |
|
153 |
int i,j,k,l,m; |
154 |
int nTop; |
155 |
int nBot; |
156 |
int lWork; |
157 |
int nfilled; |
158 |
int ndiag; |
159 |
int ifail; |
160 |
|
161 |
double oTop[3][3]; |
162 |
double oBottom[3][3]; |
163 |
double matWrap[9]; |
164 |
double evals[3]; |
165 |
double work[9]; |
166 |
double *u; |
167 |
double max; |
168 |
int which; |
169 |
|
170 |
char job, uplo; |
171 |
|
172 |
job = 'V'; |
173 |
uplo = 'U'; |
174 |
nfilled = 3; |
175 |
ndiag = 3; |
176 |
lWork = 9; |
177 |
|
178 |
for(i=0;i<3;i++){ |
179 |
for(j=0;j<3;j++){ |
180 |
oTop[i][j] = 0.0; |
181 |
oBottom[i][j] = 0.0; |
182 |
} |
183 |
} |
184 |
|
185 |
nTop = 0; |
186 |
nBot = 0; |
187 |
for(i=0;i<nLipids;i++){ |
188 |
|
189 |
k = i*nLipAtoms; |
190 |
u = atoms[k].u; |
191 |
if(atoms[k].pos[2] > 0){ |
192 |
|
193 |
oTop[0][0] += u[0] * u[0] - oneThird; |
194 |
oTop[0][1] += u[0] * u[1]; |
195 |
oTop[0][2] += u[0] * u[2]; |
196 |
|
197 |
oTop[1][0] += u[1] * u[0]; |
198 |
oTop[1][1] += u[1] * u[1] - oneThird; |
199 |
oTop[1][2] += u[1] * u[2]; |
200 |
|
201 |
oTop[2][0] += u[2] * u[0]; |
202 |
oTop[2][1] += u[2] * u[1]; |
203 |
oTop[2][2] += u[2] * u[2] - oneThird; |
204 |
|
205 |
nTop++; |
206 |
} |
207 |
else{ |
208 |
|
209 |
oBottom[0][0] += u[0] * u[0] - oneThird; |
210 |
oBottom[0][1] += u[0] * u[1]; |
211 |
oBottom[0][2] += u[0] * u[2]; |
212 |
|
213 |
oBottom[1][0] += u[1] * u[0]; |
214 |
oBottom[1][1] += u[1] * u[1] - oneThird; |
215 |
oBottom[1][2] += u[1] * u[2]; |
216 |
|
217 |
oBottom[2][0] += u[2] * u[0]; |
218 |
oBottom[2][1] += u[2] * u[1]; |
219 |
oBottom[2][2] += u[2] * u[2] - oneThird; |
220 |
|
221 |
nBot++; |
222 |
} |
223 |
} |
224 |
|
225 |
for(i=0;i<3;i++){ |
226 |
for(j=0;j<3;j++){ |
227 |
oTop[i][j] /= (double)nTop; |
228 |
oBottom[i][j] /= (double)nBot; |
229 |
} |
230 |
} |
231 |
|
232 |
// matWrap to fortran convention |
233 |
|
234 |
for(j=0;j<3;j++) |
235 |
for(l=0;l<3;l++) |
236 |
matWrap[l+3*j] = oTop[l][j]; |
237 |
|
238 |
ifail = 0; |
239 |
|
240 |
dsyev(&job, &uplo, &nfilled, matWrap, &ndiag, evals, work, &lWork, &ifail); |
241 |
|
242 |
if (ifail) { |
243 |
fprintf(stderr, "dsyev screwed something up!\n"); |
244 |
exit(0); |
245 |
} |
246 |
|
247 |
// matWrap from fortran convention |
248 |
|
249 |
for(j=0;j<3;j++) |
250 |
for(l=0;l<3;l++) |
251 |
oTop[l][j] = matWrap[l+3*j]; |
252 |
|
253 |
max = 0.0; |
254 |
for (i=0; i<3;i++) { |
255 |
if (fabs(evals[i]) > max) { |
256 |
which = i; |
257 |
max = fabs(evals[i]); |
258 |
} |
259 |
} |
260 |
|
261 |
for (i = 0; i < 3; i++) { |
262 |
directorHead[index].uTop[i] = oTop[i][which]; |
263 |
} |
264 |
|
265 |
directorHead[index].orderTop = 1.5 * max; |
266 |
|
267 |
// matWrap to fortran convention |
268 |
|
269 |
for(j=0;j<3;j++) |
270 |
for(l=0;l<3;l++) |
271 |
matWrap[l+3*j] = oBottom[l][j]; |
272 |
|
273 |
ifail = 0; |
274 |
dsyev(&job, &uplo, &nfilled, matWrap, &ndiag, evals, work, &lWork, &ifail); |
275 |
|
276 |
if (ifail) { |
277 |
fprintf(stderr, "dsyev screwed something up!\n"); |
278 |
exit(0); |
279 |
} |
280 |
|
281 |
// matWrap from fortran convention |
282 |
|
283 |
for(j=0;j<3;j++) |
284 |
for(l=0;l<3;l++) |
285 |
oBottom[l][j] = matWrap[l+3*j]; |
286 |
|
287 |
max = 0.0; |
288 |
for (i=0; i<3;i++) { |
289 |
if (fabs(evals[i]) > max) { |
290 |
which = i; |
291 |
max = fabs(evals[i]); |
292 |
} |
293 |
} |
294 |
|
295 |
for (i = 0; i < 3; i++) { |
296 |
directorHead[index].uBottom[i] = oBottom[i][which]; |
297 |
} |
298 |
|
299 |
directorHead[index].orderBottom = 1.5 * max; |
300 |
|
301 |
directorHead[index].time = frameTimes[index]; |
302 |
|
303 |
// fprintf(stderr, |
304 |
// "frame[%d] => orderTop = %6G; < %6G, %6G, %6G >\n" |
305 |
// " orderBottom = %6G; < %6G, %6G, %6G >\n\n", |
306 |
// index, |
307 |
// directorHead[index].orderTop, |
308 |
// directorHead[index].uTop[0], |
309 |
// directorHead[index].uTop[1], |
310 |
// directorHead[index].uTop[2], |
311 |
// directorHead[index].orderBottom, |
312 |
// directorHead[index].uBottom[0], |
313 |
// directorHead[index].uBottom[1], |
314 |
// directorHead[index].uBottom[2] ); |
315 |
} |
316 |
|