1 |
+ |
#define _FILE_OFFSET_BITS 64 |
2 |
|
#include <iostream> |
3 |
< |
#include <cmath> |
3 |
> |
#include <math.h> |
4 |
|
|
5 |
|
#include <stdio.h> |
6 |
|
#include <stdlib.h> |
11 |
|
|
12 |
|
#include "ReadWrite.hpp" |
13 |
|
#include "simError.h" |
14 |
+ |
#include "GenericData.hpp" |
15 |
|
|
16 |
|
#ifdef IS_MPI |
17 |
|
#include <mpi.h> |
28 |
|
|
29 |
|
#endif // is_mpi |
30 |
|
|
31 |
< |
InitializeFromFile :: InitializeFromFile( char *in_name ){ |
31 |
> |
InitializeFromFile::InitializeFromFile( char *in_name ){ |
32 |
> |
|
33 |
|
#ifdef IS_MPI |
34 |
|
if (worldRank == 0) { |
35 |
|
#endif |
41 |
|
painCave.isFatal = 1; |
42 |
|
simError(); |
43 |
|
} |
44 |
< |
|
44 |
> |
|
45 |
|
strcpy( c_in_name, in_name); |
46 |
|
#ifdef IS_MPI |
47 |
|
} |
48 |
< |
strcpy( checkPointMsg, "Infile opened for reading successfully." ); |
48 |
> |
else{ |
49 |
> |
sprintf( c_in_name, "mpiNodeParser_%d", worldRank ); |
50 |
> |
} |
51 |
> |
|
52 |
> |
strcpy( checkPointMsg, "Infile opened for reading successfully." ); |
53 |
|
MPIcheckPoint(); |
54 |
|
#endif |
55 |
< |
return; |
55 |
> |
return; |
56 |
|
} |
57 |
|
|
58 |
< |
InitializeFromFile :: ~InitializeFromFile( ){ |
58 |
> |
InitializeFromFile::~InitializeFromFile( ){ |
59 |
|
#ifdef IS_MPI |
60 |
|
if (worldRank == 0) { |
61 |
|
#endif |
78 |
|
|
79 |
|
void InitializeFromFile :: readInit( SimInfo* the_simnfo ){ |
80 |
|
|
81 |
< |
int i, j, done, which_node, which_atom; // loop counter |
81 |
> |
int i, j; |
82 |
|
|
76 |
– |
const int BUFFERSIZE = 2000; // size of the read buffer |
77 |
– |
int n_atoms; // the number of atoms |
78 |
– |
char read_buffer[BUFFERSIZE]; //the line buffer for reading |
83 |
|
#ifdef IS_MPI |
84 |
< |
char send_buffer[BUFFERSIZE]; |
85 |
< |
#endif |
84 |
> |
int done, which_node, which_atom; // loop counter |
85 |
> |
#endif //is_mpi |
86 |
|
|
87 |
< |
char *eof_test; // ptr to see when we reach the end of the file |
87 |
> |
const int BUFFERSIZE = 2000; // size of the read buffer |
88 |
> |
int nTotObjs; // the number of atoms |
89 |
> |
char read_buffer[BUFFERSIZE]; //the line buffer for reading |
90 |
> |
|
91 |
> |
char *eof_test; // ptr to see when we reach the end of the file |
92 |
|
char *parseErr; |
85 |
– |
int procIndex; |
86 |
– |
double currTime; |
87 |
– |
double boxMat[9]; |
88 |
– |
double theBoxMat3[3][3]; |
93 |
|
|
94 |
+ |
vector<StuntDouble*> integrableObjects; |
95 |
+ |
vector<StuntDouble*>::iterator iter; |
96 |
+ |
|
97 |
|
simnfo = the_simnfo; |
98 |
|
|
99 |
|
|
107 |
|
simError(); |
108 |
|
} |
109 |
|
|
110 |
< |
n_atoms = atoi( read_buffer ); |
110 |
> |
nTotObjs = atoi( read_buffer ); |
111 |
|
|
112 |
< |
Atom **atoms = simnfo->atoms; |
106 |
< |
DirectionalAtom* dAtom; |
107 |
< |
|
108 |
< |
if( n_atoms != simnfo->n_atoms ){ |
112 |
> |
if( nTotObjs != simnfo->getTotIntegrableObjects() ){ |
113 |
|
sprintf( painCave.errMsg, |
114 |
|
"Initialize from File error. %s n_atoms, %d, " |
115 |
|
"does not match the BASS file's n_atoms, %d.\n", |
116 |
< |
c_in_name, n_atoms, simnfo->n_atoms ); |
116 |
> |
c_in_name, nTotObjs, simnfo->getTotIntegrableObjects()); |
117 |
|
painCave.isFatal = 1; |
118 |
|
simError(); |
119 |
|
} |
120 |
< |
|
121 |
< |
//read the box mat from the comment line |
122 |
< |
|
120 |
> |
|
121 |
> |
//read the box mat from the comment line |
122 |
> |
|
123 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
124 |
|
if(eof_test == NULL){ |
125 |
|
sprintf( painCave.errMsg, |
128 |
|
simError(); |
129 |
|
} |
130 |
|
|
131 |
< |
parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
131 |
> |
parseErr = parseCommentLine( read_buffer, simnfo); |
132 |
|
if( parseErr != NULL ){ |
133 |
|
strcpy( painCave.errMsg, parseErr ); |
134 |
|
painCave.isFatal = 1; |
135 |
|
simError(); |
136 |
|
} |
137 |
|
|
138 |
< |
for(i=0;i<3;i++) |
135 |
< |
for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
138 |
> |
//parse dump lines |
139 |
|
|
140 |
< |
simnfo->setBoxM( theBoxMat3 ); |
138 |
< |
simnfo->setTime( currTime ); |
140 |
> |
for( i=0; i < simnfo->n_mol; i++){ |
141 |
|
|
142 |
+ |
integrableObjects = (simnfo->molecules[i]).getIntegrableObjects(); |
143 |
|
|
144 |
< |
for( i=0; i < n_atoms; i++){ |
142 |
< |
|
143 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
144 |
< |
if(eof_test == NULL){ |
145 |
< |
sprintf(painCave.errMsg, |
146 |
< |
"error in reading file %s\n" |
147 |
< |
"natoms = %d; index = %d\n" |
148 |
< |
"error reading the line from the file.\n", |
149 |
< |
c_in_name, n_atoms, i ); |
150 |
< |
painCave.isFatal = 1; |
151 |
< |
simError(); |
152 |
< |
} |
144 |
> |
for(iter = integrableObjects.begin(); iter!= integrableObjects.end(); iter++) |
145 |
|
|
146 |
< |
|
147 |
< |
parseErr = parseDumpLine( read_buffer, i ); |
148 |
< |
if( parseErr != NULL ){ |
149 |
< |
strcpy( painCave.errMsg, parseErr ); |
150 |
< |
painCave.isFatal = 1; |
151 |
< |
simError(); |
152 |
< |
} |
146 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
147 |
> |
if(eof_test == NULL){ |
148 |
> |
sprintf(painCave.errMsg, |
149 |
> |
"error in reading file %s\n" |
150 |
> |
"natoms = %d; index = %d\n" |
151 |
> |
"error reading the line from the file.\n", |
152 |
> |
c_in_name, nTotObjs, i ); |
153 |
> |
painCave.isFatal = 1; |
154 |
> |
simError(); |
155 |
> |
} |
156 |
> |
|
157 |
> |
parseErr = parseDumpLine( read_buffer, *iter); |
158 |
> |
if( parseErr != NULL ){ |
159 |
> |
strcpy( painCave.errMsg, parseErr ); |
160 |
> |
painCave.isFatal = 1; |
161 |
> |
simError(); |
162 |
> |
} |
163 |
|
} |
164 |
|
|
165 |
|
|
171 |
|
|
172 |
|
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
173 |
|
int haveError; |
174 |
< |
|
174 |
> |
|
175 |
|
MPI_Status istatus; |
176 |
< |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
176 |
> |
int *MolToProcMap = mpiSim->getMolToProcMap(); |
177 |
> |
int localIndex; |
178 |
> |
int nCurObj; |
179 |
|
|
176 |
– |
|
180 |
|
haveError = 0; |
181 |
|
if (worldRank == 0) { |
182 |
|
|
183 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
184 |
|
if( eof_test == NULL ){ |
185 |
|
sprintf( painCave.errMsg, |
186 |
< |
"Error reading 1st line of %d \n ",c_in_name); |
186 |
> |
"Error reading 1st line of %s \n ",c_in_name); |
187 |
|
haveError = 1; |
188 |
|
simError(); |
189 |
|
} |
190 |
< |
|
191 |
< |
n_atoms = atoi( read_buffer ); |
192 |
< |
|
193 |
< |
Atom **atoms = simnfo->atoms; |
191 |
< |
DirectionalAtom* dAtom; |
192 |
< |
|
193 |
< |
// Check to see that the number of atoms in the intial configuration file is the |
190 |
> |
|
191 |
> |
nTotObjs = atoi( read_buffer ); |
192 |
> |
|
193 |
> |
// Check to see that the number of integrable objects in the intial configuration file is the |
194 |
|
// same as declared in simBass. |
195 |
< |
|
196 |
< |
if( n_atoms != mpiSim->getTotAtoms() ){ |
195 |
> |
|
196 |
> |
if( nTotObjs != simnfo->getTotIntegrableObjects()){ |
197 |
|
sprintf( painCave.errMsg, |
198 |
|
"Initialize from File error. %s n_atoms, %d, " |
199 |
|
"does not match the BASS file's n_atoms, %d.\n", |
200 |
< |
c_in_name, n_atoms, simnfo->n_atoms ); |
200 |
> |
c_in_name, nTotObjs, simnfo->getTotIntegrableObjects()); |
201 |
|
haveError= 1; |
202 |
|
simError(); |
203 |
|
} |
204 |
< |
|
205 |
< |
//read the boxMat from the comment line |
206 |
< |
|
204 |
> |
|
205 |
> |
//read the boxMat from the comment line |
206 |
> |
|
207 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
208 |
|
if(eof_test == NULL){ |
209 |
|
sprintf( painCave.errMsg, |
211 |
|
haveError = 1; |
212 |
|
simError(); |
213 |
|
} |
214 |
< |
|
215 |
< |
parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
214 |
> |
|
215 |
> |
//Every single processor will parse the comment line by itself |
216 |
> |
//By using this way, we might lose some efficiency, but if we want to add |
217 |
> |
//more parameters into comment line, we only need to modify function |
218 |
> |
//parseCommentLine |
219 |
> |
|
220 |
> |
MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD); |
221 |
> |
|
222 |
> |
parseErr = parseCommentLine( read_buffer, simnfo); |
223 |
> |
|
224 |
|
if( parseErr != NULL ){ |
225 |
|
strcpy( painCave.errMsg, parseErr ); |
226 |
|
haveError = 1; |
227 |
|
simError(); |
228 |
|
} |
229 |
|
|
230 |
< |
MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
231 |
< |
MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
232 |
< |
|
233 |
< |
if(haveError) nodeZeroError(); |
230 |
> |
for (i=0 ; i < mpiSim->getTotNmol(); i++) { |
231 |
> |
which_node = MolToProcMap[i]; |
232 |
> |
if(which_node == 0){ |
233 |
> |
//molecules belong to master node |
234 |
|
|
235 |
< |
for (i=0 ; i < mpiSim->getTotAtoms(); i++) { |
236 |
< |
|
237 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
238 |
< |
if(eof_test == NULL){ |
239 |
< |
sprintf(painCave.errMsg, |
240 |
< |
"error in reading file %s\n" |
233 |
< |
"natoms = %d; index = %d\n" |
234 |
< |
"error reading the line from the file.\n", |
235 |
< |
c_in_name, n_atoms, i ); |
236 |
< |
haveError= 1; |
237 |
< |
simError(); |
235 |
> |
localIndex = mpiSim->getGlobalToLocalMol(i); |
236 |
> |
|
237 |
> |
if(localIndex == -1) { |
238 |
> |
strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
239 |
> |
haveError = 1; |
240 |
> |
simError(); |
241 |
|
} |
239 |
– |
|
240 |
– |
if(haveError) nodeZeroError(); |
242 |
|
|
243 |
< |
// Get the Node number which wants this atom: |
244 |
< |
which_node = AtomToProcMap[i]; |
245 |
< |
if (which_node == 0) { |
246 |
< |
parseErr = parseDumpLine( read_buffer, i ); |
247 |
< |
if( parseErr != NULL ){ |
248 |
< |
strcpy( painCave.errMsg, parseErr ); |
249 |
< |
haveError = 1; |
250 |
< |
simError(); |
251 |
< |
} |
252 |
< |
if(haveError) nodeZeroError(); |
253 |
< |
} |
254 |
< |
|
255 |
< |
else { |
256 |
< |
|
257 |
< |
myStatus = 1; |
257 |
< |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
258 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
259 |
< |
MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
260 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
261 |
< |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
262 |
< |
MPI_COMM_WORLD); |
263 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
264 |
< |
MPI_COMM_WORLD, &istatus); |
265 |
< |
|
266 |
< |
if(!myStatus) nodeZeroError(); |
267 |
< |
} |
268 |
< |
} |
269 |
< |
myStatus = -1; |
270 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
271 |
< |
MPI_Send( &myStatus, 1, MPI_INT, j, |
272 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
273 |
< |
} |
274 |
< |
|
275 |
< |
} else { |
276 |
< |
|
277 |
< |
MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
278 |
< |
MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
243 |
> |
integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); |
244 |
> |
for(j=0; j < integrableObjects.size(); j++){ |
245 |
> |
|
246 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
247 |
> |
if(eof_test == NULL){ |
248 |
> |
sprintf(painCave.errMsg, |
249 |
> |
"error in reading file %s\n" |
250 |
> |
"natoms = %d; index = %d\n" |
251 |
> |
"error reading the line from the file.\n", |
252 |
> |
c_in_name, nTotObjs, i ); |
253 |
> |
haveError= 1; |
254 |
> |
simError(); |
255 |
> |
} |
256 |
> |
|
257 |
> |
if(haveError) nodeZeroError(); |
258 |
|
|
259 |
< |
done = 0; |
260 |
< |
while (!done) { |
259 |
> |
parseDumpLine(read_buffer, integrableObjects[i]); |
260 |
> |
|
261 |
> |
} |
262 |
|
|
283 |
– |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
284 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
285 |
– |
|
286 |
– |
if(!myStatus) anonymousNodeDie(); |
287 |
– |
|
288 |
– |
if(myStatus < 0) break; |
263 |
|
|
264 |
< |
MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
265 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
266 |
< |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
264 |
> |
} |
265 |
> |
else{ |
266 |
> |
//molecule belongs to slave nodes |
267 |
> |
|
268 |
> |
MPI_Recv(&nCurObj, 1, MPI_INT, 0, |
269 |
|
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
270 |
|
|
271 |
< |
myStatus = 1; |
272 |
< |
parseErr = parseDumpLine( read_buffer, which_atom ); |
273 |
< |
if( parseErr != NULL ){ |
274 |
< |
strcpy( painCave.errMsg, parseErr ); |
275 |
< |
myStatus = 0;; |
276 |
< |
simError(); |
271 |
> |
for(j=0; j < integrableObjects.size(); j++){ |
272 |
> |
|
273 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
274 |
> |
if(eof_test == NULL){ |
275 |
> |
sprintf(painCave.errMsg, |
276 |
> |
"error in reading file %s\n" |
277 |
> |
"natoms = %d; index = %d\n" |
278 |
> |
"error reading the line from the file.\n", |
279 |
> |
c_in_name, nTotObjs, i ); |
280 |
> |
haveError= 1; |
281 |
> |
simError(); |
282 |
> |
} |
283 |
> |
|
284 |
> |
if(haveError) nodeZeroError(); |
285 |
> |
|
286 |
> |
MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
287 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
288 |
> |
|
289 |
> |
} |
290 |
> |
|
291 |
|
} |
292 |
|
|
303 |
– |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
304 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
305 |
– |
|
293 |
|
} |
294 |
+ |
|
295 |
|
} |
296 |
< |
|
297 |
< |
// last thing last, enable fatalities. |
298 |
< |
painCave.isEventLoop = 0; |
296 |
> |
else{ |
297 |
> |
//actions taken at slave nodes |
298 |
> |
for (i=0 ; i < mpiSim->getTotNmol(); i++) { |
299 |
> |
which_node = MolToProcMap[i]; |
300 |
> |
|
301 |
> |
if(which_node == worldRank){ |
302 |
> |
//molecule with global index i belongs to this processor |
303 |
> |
|
304 |
> |
localIndex = mpiSim->getGlobalToLocalMol(i); |
305 |
|
|
306 |
< |
for(i=0;i<3;i++) |
307 |
< |
for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
306 |
> |
if(localIndex == -1) { |
307 |
> |
sprintf(painCave.errMsg, "Molecule not found on node %d\n", worldRank); |
308 |
> |
haveError = 1; |
309 |
> |
simError(); |
310 |
> |
} |
311 |
|
|
312 |
< |
simnfo->setBoxM( theBoxMat3 ); |
316 |
< |
simnfo->setTime( currTime ); |
312 |
> |
integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); |
313 |
|
|
314 |
< |
|
314 |
> |
nCurObj = integrableObjects.size(); |
315 |
> |
|
316 |
> |
MPI_Recv(&nCurObj, 1, MPI_INT, 0, |
317 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
318 |
> |
|
319 |
> |
for(j = 0; j < integrableObjects.size(); j++){ |
320 |
> |
|
321 |
> |
MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
322 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
323 |
> |
|
324 |
> |
parseErr = parseDumpLine(read_buffer, integrableObjects[j]); |
325 |
> |
|
326 |
> |
if( parseErr != NULL ){ |
327 |
> |
strcpy( painCave.errMsg, parseErr ); |
328 |
> |
simError(); |
329 |
> |
} |
330 |
> |
|
331 |
> |
} |
332 |
> |
|
333 |
> |
} |
334 |
> |
|
335 |
> |
} |
336 |
> |
|
337 |
> |
} |
338 |
|
#endif |
339 |
|
} |
340 |
|
|
341 |
< |
char* InitializeFromFile::parseDumpLine(char* readLine, int globalIndex){ |
341 |
> |
char* InitializeFromFile::parseDumpLine(char* readLine, StuntDouble* sd){ |
342 |
|
|
343 |
< |
char *foo; // the pointer to the current string token |
344 |
< |
|
345 |
< |
double rx, ry, rz; // position place holders |
346 |
< |
double vx, vy, vz; // velocity placeholders |
343 |
> |
char *foo; // the pointer to the current string token |
344 |
> |
|
345 |
> |
double pos[3]; // position place holders |
346 |
> |
double vel[3]; // velocity placeholders |
347 |
|
double q[4]; // the quaternions |
348 |
< |
double jx, jy, jz; // angular velocity placeholders; |
348 |
> |
double ji[3]; // angular velocity placeholders; |
349 |
|
double qSqr, qLength; // needed to normalize the quaternion vector. |
331 |
– |
|
332 |
– |
Atom **atoms = simnfo->atoms; |
333 |
– |
DirectionalAtom* dAtom; |
334 |
– |
|
335 |
– |
int j, n_atoms, atomIndex; |
350 |
|
|
337 |
– |
#ifdef IS_MPI |
338 |
– |
n_atoms = mpiSim->getTotAtoms(); |
339 |
– |
atomIndex=-1; |
340 |
– |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
341 |
– |
if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j; |
342 |
– |
} |
343 |
– |
if (atomIndex == -1) { |
344 |
– |
sprintf( painCave.errMsg, |
345 |
– |
"Initialize from file error. Atom at index %d " |
346 |
– |
"in file %s does not exist on processor %d .\n", |
347 |
– |
globalIndex, c_in_name, mpiSim->getMyNode() ); |
348 |
– |
return strdup( painCave.errMsg ); |
349 |
– |
} |
350 |
– |
#else |
351 |
– |
n_atoms = simnfo->n_atoms; |
352 |
– |
atomIndex = globalIndex; |
353 |
– |
#endif // is_mpi |
351 |
|
|
352 |
|
// set the string tokenizer |
353 |
< |
|
353 |
> |
|
354 |
|
foo = strtok(readLine, " ,;\t"); |
355 |
< |
|
355 |
> |
|
356 |
|
// check the atom name to the current atom |
357 |
< |
|
358 |
< |
if( strcmp( foo, atoms[atomIndex]->getType() ) ){ |
357 |
> |
|
358 |
> |
if( strcmp( foo, sd->getType() ) ){ |
359 |
|
sprintf( painCave.errMsg, |
360 |
< |
"Initialize from file error. Atom %s at index %d " |
364 |
< |
"in file %s does not" |
360 |
> |
"Initialize from file error. Does not" |
361 |
|
" match the BASS atom %s.\n", |
362 |
< |
foo, atomIndex, c_in_name, atoms[atomIndex]->getType() ); |
362 |
> |
sd->getType() ); |
363 |
|
return strdup( painCave.errMsg ); |
364 |
|
} |
365 |
< |
|
365 |
> |
|
366 |
|
// get the positions |
367 |
|
|
368 |
|
foo = strtok(NULL, " ,;\t"); |
369 |
|
if(foo == NULL){ |
370 |
|
sprintf( painCave.errMsg, |
371 |
< |
"error in reading postition x from %s\n" |
372 |
< |
"natoms = %d, index = %d\n", |
377 |
< |
c_in_name, n_atoms, atomIndex ); |
371 |
> |
"error in reading postition x from %s\n", |
372 |
> |
c_in_name); |
373 |
|
return strdup( painCave.errMsg ); |
374 |
|
} |
375 |
< |
rx = atof( foo ); |
376 |
< |
|
375 |
> |
pos[0] = atof( foo ); |
376 |
> |
|
377 |
|
foo = strtok(NULL, " ,;\t"); |
378 |
|
if(foo == NULL){ |
379 |
|
sprintf( painCave.errMsg, |
380 |
< |
"error in reading postition y from %s\n" |
381 |
< |
"natoms = %d, index = %d\n", |
387 |
< |
c_in_name, n_atoms, atomIndex ); |
380 |
> |
"error in reading postition y from %s\n", |
381 |
> |
c_in_name); |
382 |
|
return strdup( painCave.errMsg ); |
383 |
|
} |
384 |
< |
ry = atof( foo ); |
385 |
< |
|
384 |
> |
pos[1] = atof( foo ); |
385 |
> |
|
386 |
|
foo = strtok(NULL, " ,;\t"); |
387 |
|
if(foo == NULL){ |
388 |
|
sprintf( painCave.errMsg, |
389 |
< |
"error in reading postition z from %s\n" |
390 |
< |
"natoms = %d, index = %d\n", |
397 |
< |
c_in_name, n_atoms, atomIndex ); |
389 |
> |
"error in reading postition z from %s\n", |
390 |
> |
c_in_name); |
391 |
|
return strdup( painCave.errMsg ); |
392 |
|
} |
393 |
< |
rz = atof( foo ); |
393 |
> |
pos[2] = atof( foo ); |
394 |
|
|
395 |
|
|
396 |
|
// get the velocities |
398 |
|
foo = strtok(NULL, " ,;\t"); |
399 |
|
if(foo == NULL){ |
400 |
|
sprintf( painCave.errMsg, |
401 |
< |
"error in reading velocity x from %s\n" |
402 |
< |
"natoms = %d, index = %d\n", |
410 |
< |
c_in_name, n_atoms, atomIndex ); |
401 |
> |
"error in reading velocity x from %s\n", |
402 |
> |
c_in_name ); |
403 |
|
return strdup( painCave.errMsg ); |
404 |
|
} |
405 |
< |
vx = atof( foo ); |
406 |
< |
|
405 |
> |
vel[0] = atof( foo ); |
406 |
> |
|
407 |
|
foo = strtok(NULL, " ,;\t"); |
408 |
|
if(foo == NULL){ |
409 |
|
sprintf( painCave.errMsg, |
410 |
< |
"error in reading velocity y from %s\n" |
411 |
< |
"natoms = %d, index = %d\n", |
420 |
< |
c_in_name, n_atoms, atomIndex ); |
410 |
> |
"error in reading velocity x from %s\n", |
411 |
> |
c_in_name ); |
412 |
|
return strdup( painCave.errMsg ); |
413 |
|
} |
414 |
< |
vy = atof( foo ); |
415 |
< |
|
414 |
> |
vel[1] = atof( foo ); |
415 |
> |
|
416 |
|
foo = strtok(NULL, " ,;\t"); |
417 |
|
if(foo == NULL){ |
418 |
|
sprintf( painCave.errMsg, |
419 |
< |
"error in reading velocity z from %s\n" |
420 |
< |
"natoms = %d, index = %d\n", |
430 |
< |
c_in_name, n_atoms, atomIndex ); |
419 |
> |
"error in reading velocity x from %s\n", |
420 |
> |
c_in_name ); |
421 |
|
return strdup( painCave.errMsg ); |
422 |
|
} |
423 |
< |
vz = atof( foo ); |
424 |
< |
|
425 |
< |
|
423 |
> |
vel[2] = atof( foo ); |
424 |
> |
|
425 |
> |
|
426 |
> |
// add the positions and velocities to the atom |
427 |
> |
|
428 |
> |
sd->setPos( pos ); |
429 |
> |
sd->setVel( vel ); |
430 |
> |
|
431 |
> |
if (!sd->isDirectional()) |
432 |
> |
return NULL; |
433 |
> |
|
434 |
|
// get the quaternions |
435 |
< |
|
436 |
< |
if( atoms[atomIndex]->isDirectional() ){ |
437 |
< |
|
435 |
> |
|
436 |
> |
if( sd->isDirectional() ){ |
437 |
> |
|
438 |
|
foo = strtok(NULL, " ,;\t"); |
439 |
|
if(foo == NULL){ |
440 |
< |
sprintf(painCave.errMsg, |
441 |
< |
"error in reading quaternion 0 from %s\n" |
442 |
< |
"natoms = %d, index = %d\n", |
445 |
< |
c_in_name, n_atoms, atomIndex ); |
440 |
> |
sprintf( painCave.errMsg, |
441 |
> |
"error in reading velocity x from %s\n", |
442 |
> |
c_in_name ); |
443 |
|
return strdup( painCave.errMsg ); |
444 |
|
} |
445 |
|
q[0] = atof( foo ); |
446 |
< |
|
446 |
> |
|
447 |
|
foo = strtok(NULL, " ,;\t"); |
448 |
|
if(foo == NULL){ |
449 |
|
sprintf( painCave.errMsg, |
450 |
< |
"error in reading quaternion 1 from %s\n" |
451 |
< |
"natoms = %d, index = %d\n", |
455 |
< |
c_in_name, n_atoms, atomIndex ); |
450 |
> |
"error in reading velocity x from %s\n", |
451 |
> |
c_in_name ); |
452 |
|
return strdup( painCave.errMsg ); |
453 |
|
} |
454 |
|
q[1] = atof( foo ); |
455 |
< |
|
455 |
> |
|
456 |
|
foo = strtok(NULL, " ,;\t"); |
457 |
|
if(foo == NULL){ |
458 |
|
sprintf( painCave.errMsg, |
459 |
< |
"error in reading quaternion 2 from %s\n" |
460 |
< |
"natoms = %d, index = %d\n", |
465 |
< |
c_in_name, n_atoms, atomIndex ); |
459 |
> |
"error in reading velocity x from %s\n", |
460 |
> |
c_in_name ); |
461 |
|
return strdup( painCave.errMsg ); |
462 |
|
} |
463 |
|
q[2] = atof( foo ); |
464 |
< |
|
464 |
> |
|
465 |
|
foo = strtok(NULL, " ,;\t"); |
466 |
|
if(foo == NULL){ |
467 |
|
sprintf( painCave.errMsg, |
468 |
< |
"error in reading quaternion 3 from %s\n" |
469 |
< |
"natoms = %d, index = %d\n", |
475 |
< |
c_in_name, n_atoms, atomIndex ); |
468 |
> |
"error in reading velocity x from %s\n", |
469 |
> |
c_in_name ); |
470 |
|
return strdup( painCave.errMsg ); |
471 |
|
} |
472 |
|
q[3] = atof( foo ); |
473 |
< |
|
473 |
> |
|
474 |
|
// get the angular velocities |
475 |
< |
|
475 |
> |
|
476 |
|
foo = strtok(NULL, " ,;\t"); |
477 |
|
if(foo == NULL){ |
478 |
|
sprintf( painCave.errMsg, |
479 |
< |
"error in reading angular momentum jx from %s\n" |
480 |
< |
"natoms = %d, index = %d\n", |
487 |
< |
c_in_name, n_atoms, atomIndex ); |
479 |
> |
"error in reading velocity x from %s\n", |
480 |
> |
c_in_name ); |
481 |
|
return strdup( painCave.errMsg ); |
482 |
|
} |
483 |
< |
jx = atof( foo ); |
484 |
< |
|
483 |
> |
ji[0] = atof( foo ); |
484 |
> |
|
485 |
|
foo = strtok(NULL, " ,;\t"); |
486 |
|
if(foo == NULL){ |
487 |
|
sprintf( painCave.errMsg, |
488 |
< |
"error in reading angular momentum jy from %s\n" |
489 |
< |
"natoms = %d, index = %d\n", |
497 |
< |
c_in_name, n_atoms, atomIndex ); |
488 |
> |
"error in reading velocity x from %s\n", |
489 |
> |
c_in_name ); |
490 |
|
return strdup( painCave.errMsg ); |
491 |
|
} |
492 |
< |
jy = atof(foo ); |
493 |
< |
|
492 |
> |
ji[1] = atof(foo ); |
493 |
> |
|
494 |
|
foo = strtok(NULL, " ,;\t"); |
495 |
|
if(foo == NULL){ |
496 |
|
sprintf( painCave.errMsg, |
497 |
< |
"error in reading angular momentum jz from %s\n" |
498 |
< |
"natoms = %d, index = %d\n", |
507 |
< |
c_in_name, n_atoms, atomIndex ); |
497 |
> |
"error in reading velocity x from %s\n", |
498 |
> |
c_in_name ); |
499 |
|
return strdup( painCave.errMsg ); |
500 |
|
} |
501 |
< |
jz = atof( foo ); |
511 |
< |
|
512 |
< |
dAtom = ( DirectionalAtom* )atoms[atomIndex]; |
501 |
> |
ji[2] = atof( foo ); |
502 |
|
|
503 |
+ |
|
504 |
|
// check that the quaternion vector is normalized |
505 |
|
|
506 |
|
qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); |
507 |
< |
|
507 |
> |
|
508 |
|
qLength = sqrt( qSqr ); |
509 |
|
q[0] = q[0] / qLength; |
510 |
|
q[1] = q[1] / qLength; |
511 |
|
q[2] = q[2] / qLength; |
512 |
|
q[3] = q[3] / qLength; |
523 |
– |
|
524 |
– |
dAtom->setQ( q ); |
525 |
– |
|
526 |
– |
// add the angular velocities |
513 |
|
|
514 |
< |
dAtom->setJx( jx ); |
515 |
< |
dAtom->setJy( jy ); |
516 |
< |
dAtom->setJz( jz ); |
514 |
> |
// add quaternion and angular velocities |
515 |
> |
|
516 |
> |
sd->setQ( q ); |
517 |
> |
sd->setJ( ji ); |
518 |
|
} |
532 |
– |
|
533 |
– |
// add the positions and velocities to the atom |
534 |
– |
|
535 |
– |
atoms[atomIndex]->setX( rx ); |
536 |
– |
atoms[atomIndex]->setY( ry ); |
537 |
– |
atoms[atomIndex]->setZ( rz ); |
538 |
– |
|
539 |
– |
atoms[atomIndex]->set_vx( vx ); |
540 |
– |
atoms[atomIndex]->set_vy( vy ); |
541 |
– |
atoms[atomIndex]->set_vz( vz ); |
519 |
|
|
520 |
+ |
|
521 |
+ |
|
522 |
|
return NULL; |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
< |
char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9], |
548 |
< |
double &time ){ |
526 |
> |
char* InitializeFromFile::parseCommentLine(char* readLine, SimInfo* entry_plug){ |
527 |
|
|
528 |
< |
char *foo; // the pointer to the current string token |
529 |
< |
int j; |
528 |
> |
double currTime; |
529 |
> |
double boxMat[9]; |
530 |
> |
double theBoxMat3[3][3]; |
531 |
> |
double chi; |
532 |
> |
double integralOfChidt; |
533 |
> |
double eta[9]; |
534 |
|
|
535 |
+ |
char *foo; // the pointer to the current string token |
536 |
+ |
|
537 |
|
// set the string tokenizer |
538 |
< |
|
538 |
> |
|
539 |
|
foo = strtok(readLine, " ,;\t"); |
540 |
|
// set the timeToken. |
541 |
|
|
545 |
|
c_in_name ); |
546 |
|
return strdup( painCave.errMsg ); |
547 |
|
} |
564 |
– |
time = atof( foo ); |
548 |
|
|
549 |
< |
// get the Hx vector |
549 |
> |
currTime = atof( foo ); |
550 |
> |
entry_plug->setTime( currTime ); |
551 |
|
|
552 |
< |
foo = strtok(NULL, " ,;\t"); |
553 |
< |
if(foo == NULL){ |
554 |
< |
sprintf( painCave.errMsg, |
555 |
< |
"error in reading Hx[0] from %s\n", |
556 |
< |
c_in_name ); |
557 |
< |
return strdup( painCave.errMsg ); |
552 |
> |
//get H-Matrix |
553 |
> |
|
554 |
> |
for(int i = 0 ; i < 9; i++){ |
555 |
> |
foo = strtok(NULL, " ,;\t"); |
556 |
> |
if(foo == NULL){ |
557 |
> |
sprintf( painCave.errMsg, |
558 |
> |
"error in reading H[%d] from %s\n", i, c_in_name ); |
559 |
> |
return strdup( painCave.errMsg ); |
560 |
> |
} |
561 |
> |
boxMat[i] = atof( foo ); |
562 |
|
} |
575 |
– |
boxMat[0] = atof( foo ); |
576 |
– |
|
577 |
– |
foo = strtok(NULL, " ,;\t"); |
578 |
– |
if(foo == NULL){ |
579 |
– |
sprintf( painCave.errMsg, |
580 |
– |
"error in reading Hx[1] from %s\n", |
581 |
– |
c_in_name ); |
582 |
– |
return strdup( painCave.errMsg ); |
583 |
– |
} |
584 |
– |
boxMat[1] = atof( foo ); |
585 |
– |
|
586 |
– |
foo = strtok(NULL, " ,;\t"); |
587 |
– |
if(foo == NULL){ |
588 |
– |
sprintf( painCave.errMsg, |
589 |
– |
"error in reading Hx[2] from %s\n", |
590 |
– |
c_in_name ); |
591 |
– |
return strdup( painCave.errMsg ); |
592 |
– |
} |
593 |
– |
boxMat[2] = atof( foo ); |
563 |
|
|
564 |
< |
// get the Hy vector |
564 |
> |
for(int i=0;i<3;i++) |
565 |
> |
for(int j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
566 |
|
|
567 |
< |
foo = strtok(NULL, " ,;\t"); |
568 |
< |
if(foo == NULL){ |
599 |
< |
sprintf( painCave.errMsg, |
600 |
< |
"error in reading Hy[0] from %s\n", |
601 |
< |
c_in_name ); |
602 |
< |
return strdup( painCave.errMsg ); |
603 |
< |
} |
604 |
< |
boxMat[3] = atof( foo ); |
605 |
< |
|
606 |
< |
foo = strtok(NULL, " ,;\t"); |
607 |
< |
if(foo == NULL){ |
608 |
< |
sprintf( painCave.errMsg, |
609 |
< |
"error in reading Hy[1] from %s\n", |
610 |
< |
c_in_name ); |
611 |
< |
return strdup( painCave.errMsg ); |
612 |
< |
} |
613 |
< |
boxMat[4] = atof( foo ); |
614 |
< |
|
615 |
< |
foo = strtok(NULL, " ,;\t"); |
616 |
< |
if(foo == NULL){ |
617 |
< |
sprintf( painCave.errMsg, |
618 |
< |
"error in reading Hy[2] from %s\n", |
619 |
< |
c_in_name ); |
620 |
< |
return strdup( painCave.errMsg ); |
621 |
< |
} |
622 |
< |
boxMat[5] = atof( foo ); |
567 |
> |
//set H-Matrix |
568 |
> |
entry_plug->setBoxM( theBoxMat3 ); |
569 |
|
|
570 |
< |
// get the Hz vector |
570 |
> |
//get chi and integralOfChidt, they should appear by pair |
571 |
|
|
572 |
< |
foo = strtok(NULL, " ,;\t"); |
573 |
< |
if(foo == NULL){ |
574 |
< |
sprintf( painCave.errMsg, |
575 |
< |
"error in reading Hz[0] from %s\n", |
576 |
< |
c_in_name ); |
577 |
< |
return strdup( painCave.errMsg ); |
572 |
> |
if( entry_plug->useInitXSstate ){ |
573 |
> |
foo = strtok(NULL, " ,;\t\n"); |
574 |
> |
if(foo != NULL){ |
575 |
> |
chi = atof(foo); |
576 |
> |
|
577 |
> |
foo = strtok(NULL, " ,;\t\n"); |
578 |
> |
if(foo == NULL){ |
579 |
> |
sprintf( painCave.errMsg, |
580 |
> |
"chi and integralOfChidt should appear by pair in %s\n", c_in_name ); |
581 |
> |
return strdup( painCave.errMsg ); |
582 |
> |
} |
583 |
> |
integralOfChidt = atof( foo ); |
584 |
> |
|
585 |
> |
//push chi and integralOfChidt into SimInfo::properties which can be |
586 |
> |
//retrieved by integrator later |
587 |
> |
DoubleData* chiValue = new DoubleData(); |
588 |
> |
chiValue->setID(CHIVALUE_ID); |
589 |
> |
chiValue->setData(chi); |
590 |
> |
entry_plug->addProperty(chiValue); |
591 |
> |
|
592 |
> |
DoubleData* integralOfChidtValue = new DoubleData(); |
593 |
> |
integralOfChidtValue->setID(INTEGRALOFCHIDT_ID); |
594 |
> |
integralOfChidtValue->setData(integralOfChidt); |
595 |
> |
entry_plug->addProperty(integralOfChidtValue); |
596 |
> |
|
597 |
> |
} |
598 |
> |
else |
599 |
> |
return NULL; |
600 |
> |
|
601 |
> |
//get eta |
602 |
> |
foo = strtok(NULL, " ,;\t\n"); |
603 |
> |
if(foo != NULL ){ |
604 |
> |
|
605 |
> |
for(int i = 0 ; i < 9; i++){ |
606 |
> |
|
607 |
> |
if(foo == NULL){ |
608 |
> |
sprintf( painCave.errMsg, |
609 |
> |
"error in reading eta[%d] from %s\n", i, c_in_name ); |
610 |
> |
return strdup( painCave.errMsg ); |
611 |
> |
} |
612 |
> |
eta[i] = atof( foo ); |
613 |
> |
foo = strtok(NULL, " ,;\t\n"); |
614 |
> |
} |
615 |
> |
} |
616 |
> |
else |
617 |
> |
return NULL; |
618 |
> |
|
619 |
> |
//push eta into SimInfo::properties which can be |
620 |
> |
//retrieved by integrator later |
621 |
> |
//entry_plug->setBoxM( theBoxMat3 ); |
622 |
> |
DoubleArrayData* etaValue = new DoubleArrayData(); |
623 |
> |
etaValue->setID(ETAVALUE_ID); |
624 |
> |
etaValue->setData(eta, 9); |
625 |
> |
entry_plug->addProperty(etaValue); |
626 |
|
} |
633 |
– |
boxMat[6] = atof( foo ); |
634 |
– |
|
635 |
– |
foo = strtok(NULL, " ,;\t"); |
636 |
– |
if(foo == NULL){ |
637 |
– |
sprintf( painCave.errMsg, |
638 |
– |
"error in reading Hz[1] from %s\n", |
639 |
– |
c_in_name ); |
640 |
– |
return strdup( painCave.errMsg ); |
641 |
– |
} |
642 |
– |
boxMat[7] = atof( foo ); |
643 |
– |
|
644 |
– |
foo = strtok(NULL, " ,;\t"); |
645 |
– |
if(foo == NULL){ |
646 |
– |
sprintf( painCave.errMsg, |
647 |
– |
"error in reading Hz[2] from %s\n", |
648 |
– |
c_in_name ); |
649 |
– |
return strdup( painCave.errMsg ); |
650 |
– |
} |
651 |
– |
boxMat[8] = atof( foo ); |
627 |
|
|
628 |
|
return NULL; |
629 |
|
} |
630 |
|
|
656 |
– |
|
631 |
|
#ifdef IS_MPI |
632 |
|
|
633 |
|
// a couple of functions to let us escape the read loop |
634 |
|
|
635 |
|
void initFile::nodeZeroError( void ){ |
636 |
|
int j, myStatus; |
637 |
< |
|
637 |
> |
|
638 |
|
myStatus = 0; |
639 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
640 |
< |
MPI_Send( &myStatus, 1, MPI_INT, j, |
639 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
640 |
> |
MPI_Send( &myStatus, 1, MPI_INT, j, |
641 |
|
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
642 |
< |
} |
669 |
< |
|
642 |
> |
} |
643 |
|
|
644 |
+ |
|
645 |
|
MPI_Finalize(); |
646 |
|
exit (0); |
647 |
< |
|
647 |
> |
|
648 |
|
} |
649 |
|
|
650 |
|
void initFile::anonymousNodeDie( void ){ |