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