ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/EAM_FF.cpp
Revision: 631
Committed: Thu Jul 17 19:25:51 2003 UTC (20 years, 11 months ago) by chuckv
File size: 25492 byte(s)
Log Message:
Added massive changes for eam....

File Contents

# Content
1 #include <cstdlib>
2 #include <cstdio>
3 #include <cstring>
4
5 #include <iostream>
6 using namespace std;
7
8 #ifdef IS_MPI
9 #include <mpi.h>
10 #endif //is_mpi
11
12 #include "ForceFields.hpp"
13 #include "SRI.hpp"
14 #include "simError.h"
15
16 #include "fortranWrappers.hpp"
17
18 #ifdef IS_MPI
19 #include "mpiForceField.h"
20 #endif // is_mpi
21
22
23
24 namespace EAM_NS{
25
26 // Declare the structures that will be passed by the parser and MPI
27
28 typedef struct{
29 char name[15];
30 double mass;
31 double lattice_constant;
32 double eam_drho; // The distance between each of the points indexed by rho.
33 double eam_dr; // The distance between each of the rho points.
34 int eam_nrho; // Number of points indexed by rho
35 int eam_nr; // The number of points based on r (Both Phi(r) and Rho(r)).
36 double eam_rcut; // The cutoff radius for eam.
37 int eam_ident; // Atomic number
38 int ident;
39 int last; // 0 -> default
40 // 1 -> in MPI: tells nodes to stop listening
41 } atomStruct;
42
43 int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile );
44 int parseEAM( atomStruct &info, char *eamPotFile, double **eam_rvals,
45 double **eam_rhovals, double **eam_Frhovals);
46 #ifdef IS_MPI
47
48 MPI_Datatype mpiAtomStructType;
49
50 #endif
51
52 class LinkedAtomType {
53 public:
54 LinkedAtomType(){
55 next = NULL;
56 name[0] = '\0';
57 eam_rvals = NULL;
58 eam_rhovals = NULL;
59 eam_Frhovals = NULL;
60 }
61
62 ~LinkedAtomType(){
63 if( next != NULL ) delete next;
64 if( eam_rvals != NULL ) delete[] eam_rvals;
65 if( eam_rhovals != NULL ) delete[] eam_rhovals;
66 if( eam_Frhovals != NULL ) delete[] eam_Frhovals;
67 }
68
69 LinkedAtomType* find(char* key){
70 if( !strcmp(name, key) ) return this;
71 if( next != NULL ) return next->find(key);
72 return NULL;
73 }
74
75
76 void add( atomStruct &info, double *the_eam_rvals,
77 double *the_eam_rhovals,double *the_eam_Frhovals ){
78
79 int i;
80
81 // check for duplicates
82
83 if( !strcmp( info.name, name ) ){
84 sprintf( painCave.errMsg,
85 "Duplicate LJ atom type \"%s\" found in "
86 "the LJ_FF param file./n",
87 name );
88 painCave.isFatal = 1;
89 simError();
90 }
91
92 if( next != NULL ) next->add(info, the_eam_rvals, the_eam_rhovals, the_eam_Frhovals);
93 else{
94 next = new LinkedAtomType();
95 strcpy(next->name, info.name);
96 next->mass = info.mass;
97 next->lattice_constant = info.lattice_constant;
98 next->eam_nrho = info.eam_nrho;
99 next->eam_drho = info.eam_drho;
100 next->eam_nr = info.eam_nr;
101 next->eam_dr = info.eam_dr;
102 next->eam_rcut = info.eam_rcut;
103 next->eam_ident = info.eam_ident;
104 next->ident = info.ident;
105
106 next->eam_rvals = the_eam_rvals;
107 next->eam_rhovals = the_eam_rhovals;
108 next->eam_Frhovals = the_eam_Frhovals;
109 }
110 }
111
112
113 #ifdef IS_MPI
114
115 void duplicate( atomStruct &info ){
116 strcpy(info.name, name);
117 info.mass = mass;
118 info.lattice_constant = lattice_constant;
119 info.eam_nrho = eam_nrho;
120 info.eam_drho = eam_drho;
121 info.eam_nr = eam_nr;
122 info.eam_dr = eam_dr;
123 info.eam_rcut = eam_rcut;
124 info.eam_ident = eam_ident;
125 info.ident = ident;
126 info.last = 0;
127 }
128
129
130 #endif
131
132 char name[15];
133 double mass;
134 double lattice_constant;
135 int eam_nrho; // Number of points indexed by rho
136 double eam_drho; // The distance between each of the points indexed by rho.
137 int eam_nr; // The number of points based on r (Both Phi(r) and Rho(r)).
138 double eam_dr; // The distance between each of the rho points.
139 double eam_rcut; // The cutoff radius for eam.
140
141 double *eam_rvals; // Z of r values
142 double *eam_rhovals; // rho of r values
143 double *eam_Frhovals; // F of rho values
144 int eam_ident; // eam identity (atomic number)
145 int ident;
146 LinkedAtomType* next;
147 };
148
149 LinkedAtomType* headAtomType;
150 LinkedAtomType* currentAtomType;
151
152 }
153
154 using namespace EAM_NS;
155
156 //****************************************************************
157 // begins the actual forcefield stuff.
158 //****************************************************************
159
160
161 EAM_FF::EAM_FF(){
162
163 char fileName[200];
164 char* ffPath_env = "FORCE_PARAM_PATH";
165 char* ffPath;
166 char temp[200];
167 char errMsg[1000];
168
169 headAtomType = NULL;
170 currentAtomType = NULL;
171
172 // do the funtion wrapping
173 wrapMeFF( this );
174
175 #ifdef IS_MPI
176 int i;
177
178 // **********************************************************************
179 // Init the atomStruct mpi type
180
181 atomStruct atomProto; // mpiPrototype
182 int atomBC[3] = {15,4,6}; // block counts
183 MPI_Aint atomDspls[3]; // displacements
184 MPI_Datatype atomMbrTypes[3]; // member mpi types
185
186 MPI_Address(&atomProto.name, &atomDspls[0]);
187 MPI_Address(&atomProto.mass, &atomDspls[1]);
188 MPI_Address(&atomProto.eam_nrho, &atomDspls[2]);
189
190 atomMbrTypes[0] = MPI_CHAR;
191 atomMbrTypes[1] = MPI_DOUBLE;
192 atomMbrTypes[2] = MPI_INT;
193
194 for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0];
195
196 MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType);
197 MPI_Type_commit(&mpiAtomStructType);
198
199 // ***********************************************************************
200
201 if( worldRank == 0 ){
202 #endif
203
204 // generate the force file name
205
206 strcpy( fileName, "EAM_FF.frc" );
207 // fprintf( stderr,"Trying to open %s\n", fileName );
208
209 // attempt to open the file in the current directory first.
210
211 frcFile = fopen( fileName, "r" );
212
213 if( frcFile == NULL ){
214
215 // next see if the force path enviorment variable is set
216
217 ffPath = getenv( ffPath_env );
218 if( ffPath == NULL ) {
219 STR_DEFINE(ffPath, FRC_PATH );
220 }
221
222
223 strcpy( temp, ffPath );
224 strcat( temp, "/" );
225 strcat( temp, fileName );
226 strcpy( fileName, temp );
227
228 frcFile = fopen( fileName, "r" );
229
230 if( frcFile == NULL ){
231
232 sprintf( painCave.errMsg,
233 "Error opening the force field parameter file: %s\n"
234 "Have you tried setting the FORCE_PARAM_PATH environment "
235 "vairable?\n",
236 fileName );
237 painCave.isFatal = 1;
238 simError();
239 }
240 }
241
242 #ifdef IS_MPI
243 }
244
245 sprintf( checkPointMsg, "EAM_FF file opened sucessfully." );
246 MPIcheckPoint();
247
248 #endif // is_mpi
249 }
250
251
252 EAM_FF::~EAM_FF(){
253
254 if( headAtomType != NULL ) delete headAtomType;
255
256 #ifdef IS_MPI
257 if( worldRank == 0 ){
258 #endif // is_mpi
259
260 fclose( frcFile );
261
262 #ifdef IS_MPI
263 }
264 #endif // is_mpi
265 }
266
267 void EAM_FF::initForceField( int ljMixRule ){
268
269 initFortran( ljMixRule, 0 );
270 }
271
272 void EAM_FF::cleanMe( void ){
273
274 #ifdef IS_MPI
275
276 // keep the linked list in the mpi version
277
278 #else // is_mpi
279
280 // delete the linked list in the single processor version
281
282 if( headAtomType != NULL ) delete headAtomType;
283
284 #endif // is_mpi
285 }
286
287 void EAM_FF::readParams( void ){
288
289 atomStruct info;
290 info.last = 1; // initialize last to have the last set.
291 // if things go well, last will be set to 0
292
293 int i;
294 int identNum;
295 double *eam_rvals; // Z of r values
296 double *eam_rhovals; // rho of r values
297 double *eam_Frhovals; // F of rho values
298 char eamPotFile[1000];
299
300
301 bigSigma = 0.0;
302 #ifdef IS_MPI
303 if( worldRank == 0 ){
304 #endif
305
306 // read in the atom types.
307
308 headAtomType = new LinkedAtomType;
309
310 fastForward( "AtomTypes", "eam atom readParams" );
311
312 // we are now at the AtomTypes section.
313
314 eof_test = fgets( readLine, sizeof(readLine), frcFile );
315 lineNum++;
316
317
318 // read a line, and start parseing out the atom types
319
320 if( eof_test == NULL ){
321 sprintf( painCave.errMsg,
322 "Error in reading Atoms from force file at line %d.\n",
323 lineNum );
324 painCave.isFatal = 1;
325 simError();
326 }
327
328 identNum = 1;
329 // stop reading at end of file, or at next section
330
331 while( readLine[0] != '#' && eof_test != NULL ){
332
333 // toss comment lines
334 if( readLine[0] != '!' ){
335
336 // the parser returns 0 if the line was blank
337 if( parseAtom( readLine, lineNum, info, eamPotFile ) ){
338 parseEAM(info,eamPotFile, &eam_rvals,
339 &eam_rhovals, &eam_Frhovals);
340 info.ident = identNum;
341 headAtomType->add( info, eam_rvals,
342 eam_rhovals,eam_Frhovals );
343 identNum++;
344 }
345 }
346 eof_test = fgets( readLine, sizeof(readLine), frcFile );
347 lineNum++;
348 }
349
350
351
352 #ifdef IS_MPI
353
354
355 // send out the linked list to all the other processes
356
357 sprintf( checkPointMsg,
358 "EAM_FF atom structures read successfully." );
359 MPIcheckPoint();
360
361 currentAtomType = headAtomType->next; //skip the first element who is a place holder.
362 while( currentAtomType != NULL ){
363 currentAtomType->duplicate( info );
364
365
366
367 sendFrcStruct( &info, mpiAtomStructType );
368
369 // We have to now broadcast the Arrays
370 MPI_Bcast(currentAtomType->eam_rvals,
371 currentAtomType->eam_nr,
372 MPI_DOUBLE,0,MPI_COMM_WORLD);
373 MPI_Bcast(currentAtomType->eam_rhovals,
374 currentAtomType->eam_nr,
375 MPI_DOUBLE,0,MPI_COMM_WORLD);
376 MPI_Bcast(currentAtomType->eam_Frhovals,
377 currentAtomType->eam_nrho,
378 MPI_DOUBLE,0,MPI_COMM_WORLD);
379
380 sprintf( checkPointMsg,
381 "successfully sent EAM force type: \"%s\"\n",
382 info.name );
383 MPIcheckPoint();
384
385 currentAtomType = currentAtomType->next;
386 }
387 info.last = 1;
388 sendFrcStruct( &info, mpiAtomStructType );
389
390 }
391
392 else{
393
394 // listen for node 0 to send out the force params
395
396 MPIcheckPoint();
397
398 headAtomType = new LinkedAtomType;
399 recieveFrcStruct( &info, mpiAtomStructType );
400
401 while( !info.last ){
402
403 // allocate the arrays
404
405 eam_rvals = new double[info.eam_nr];
406 eam_rhovals = new double[info.eam_nr];
407 eam_Frhovals = new double[info.eam_nrho];
408
409 // We have to now broadcast the Arrays
410 MPI_Bcast(eam_rvals,
411 info.eam_nr,
412 MPI_DOUBLE,0,MPI_COMM_WORLD);
413 MPI_Bcast(eam_rhovals,
414 info.eam_nr,
415 MPI_DOUBLE,0,MPI_COMM_WORLD);
416 MPI_Bcast(eam_Frhovals,
417 info.eam_nrho,
418 MPI_DOUBLE,0,MPI_COMM_WORLD);
419
420
421 headAtomType->add( info, eam_rvals, eam_rhovals, eam_Frhovals );
422
423 MPIcheckPoint();
424
425 recieveFrcStruct( &info, mpiAtomStructType );
426
427
428 }
429 }
430 #endif // is_mpi
431
432 // call new A_types in fortran
433
434 int isError;
435
436 // dummy variables
437 int isLJ = 0;
438 int isDipole = 0;
439 int isSSD = 0;
440 int isGB = 0;
441 int isEAM= 1;
442 double dipole = 0.0;
443 double eamSigma = 0.0;
444 double eamEpslon = 0.0;
445
446 currentAtomType = headAtomType->next;
447 while( currentAtomType != NULL ){
448
449 if( currentAtomType->name[0] != '\0' ){
450 isError = 0;
451 makeAtype( &(currentAtomType->ident),
452 &isLJ,
453 &isSSD,
454 &isDipole,
455 &isGB,
456 &isEAM,
457 &eamEpslon,
458 &eamSigma,
459 &dipole,
460 &isError );
461 if( isError ){
462 sprintf( painCave.errMsg,
463 "Error initializing the \"%s\" atom type in fortran\n",
464 currentAtomType->name );
465 painCave.isFatal = 1;
466 simError();
467 }
468 }
469 currentAtomType = currentAtomType->next;
470 }
471
472 entry_plug->useLJ = 0;
473
474 // Walk down again and send out EAM type
475 currentAtomType = headAtomType->next;
476 while( currentAtomType != NULL ){
477
478 if( currentAtomType->name[0] != '\0' ){
479 isError = 0;
480 newEAMtype( &(currentAtomType->lattice_constant),
481 &(currentAtomType->eam_nrho),
482 &(currentAtomType->eam_drho),
483 &(currentAtomType->eam_nr),
484 &(currentAtomType->eam_dr),
485 &(currentAtomType->eam_rcut),
486 currentAtomType->eam_rvals,
487 currentAtomType->eam_rhovals,
488 currentAtomType->eam_Frhovals,
489 &(currentAtomType->eam_ident),
490 &isError);
491 if( isError ){
492 sprintf( painCave.errMsg,
493 "Error initializing the \"%s\" atom type in fortran EAM\n",
494 currentAtomType->name );
495 painCave.isFatal = 1;
496 simError();
497 }
498 }
499 currentAtomType = currentAtomType->next;
500 }
501
502
503
504 #ifdef IS_MPI
505 sprintf( checkPointMsg,
506 "EAM_FF atom structures successfully sent to fortran\n" );
507 MPIcheckPoint();
508 #endif // is_mpi
509
510 }
511
512
513 void EAM_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){
514
515 int i;
516
517 // initialize the atoms
518
519
520 Atom* thisAtom;
521
522 for( i=0; i<nAtoms; i++ ){
523
524 currentAtomType = headAtomType->find( the_atoms[i]->getType() );
525 if( currentAtomType == NULL ){
526 sprintf( painCave.errMsg,
527 "AtomType error, %s not found in force file.\n",
528 the_atoms[i]->getType() );
529 painCave.isFatal = 1;
530 simError();
531 }
532
533 the_atoms[i]->setMass( currentAtomType->mass );
534 the_atoms[i]->setIdent( currentAtomType->ident );
535 the_atoms[i]->setEAM();
536
537 }
538 }
539
540 void EAM_FF::initializeBonds( int nBonds, Bond** BondArray,
541 bond_pair* the_bonds ){
542
543 if( nBonds ){
544 sprintf( painCave.errMsg,
545 "LJ_FF does not support bonds.\n" );
546 painCave.isFatal = 1;
547 simError();
548 }
549 }
550
551 void EAM_FF::initializeBends( int nBends, Bend** bendArray,
552 bend_set* the_bends ){
553
554 if( nBends ){
555 sprintf( painCave.errMsg,
556 "LJ_FF does not support bends.\n" );
557 painCave.isFatal = 1;
558 simError();
559 }
560 }
561
562 void EAM_FF::initializeTorsions( int nTorsions, Torsion** torsionArray,
563 torsion_set* the_torsions ){
564
565 if( nTorsions ){
566 sprintf( painCave.errMsg,
567 "LJ_FF does not support torsions.\n" );
568 painCave.isFatal = 1;
569 simError();
570 }
571 }
572
573 void EAM_FF::fastForward( char* stopText, char* searchOwner ){
574
575 int foundText = 0;
576 char* the_token;
577
578 rewind( frcFile );
579 lineNum = 0;
580
581 eof_test = fgets( readLine, sizeof(readLine), frcFile );
582 lineNum++;
583 if( eof_test == NULL ){
584 sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
585 " file is empty.\n",
586 searchOwner );
587 painCave.isFatal = 1;
588 simError();
589 }
590
591
592 while( !foundText ){
593 while( eof_test != NULL && readLine[0] != '#' ){
594 eof_test = fgets( readLine, sizeof(readLine), frcFile );
595 lineNum++;
596 }
597 if( eof_test == NULL ){
598 sprintf( painCave.errMsg,
599 "Error fast forwarding force file for %s at "
600 "line %d: file ended unexpectedly.\n",
601 searchOwner,
602 lineNum );
603 painCave.isFatal = 1;
604 simError();
605 }
606
607 the_token = strtok( readLine, " ,;\t#\n" );
608 foundText = !strcmp( stopText, the_token );
609
610 if( !foundText ){
611 eof_test = fgets( readLine, sizeof(readLine), frcFile );
612 lineNum++;
613
614 if( eof_test == NULL ){
615 sprintf( painCave.errMsg,
616 "Error fast forwarding force file for %s at "
617 "line %d: file ended unexpectedly.\n",
618 searchOwner,
619 lineNum );
620 painCave.isFatal = 1;
621 simError();
622 }
623 }
624 }
625 }
626
627
628
629 int EAM_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile ){
630
631 char* the_token;
632
633 the_token = strtok( lineBuffer, " \n\t,;" );
634 if( the_token != NULL ){
635
636 strcpy( info.name, the_token );
637
638 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
639 sprintf( painCave.errMsg,
640 "Error parseing AtomTypes: line %d\n", lineNum );
641 painCave.isFatal = 1;
642 simError();
643 }
644
645 info.mass = atof( the_token );
646
647 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
648 sprintf( painCave.errMsg,
649 "Error parseing AtomTypes: line %d\n", lineNum );
650 painCave.isFatal = 1;
651 simError();
652 }
653
654 strcpy( eamPotFile, the_token );
655 return 1;
656 }
657 else return 0;
658 }
659
660 int EAM_NS::parseEAM(atomStruct &info, char *eamPotFile,
661 double **eam_rvals,
662 double **eam_rhovals,
663 double **eam_Frhovals){
664
665 char* ffPath_env = "FORCE_PARAM_PATH";
666 char* ffPath;
667 char* the_token;
668 char* eam_eof_test;
669 FILE *eamFile;
670 const int BUFFERSIZE = 2000;
671
672 char temp[200];
673 int linenumber;
674 int nReadLines;
675 char eam_read_buffer[BUFFERSIZE];
676
677 int i,j;
678
679 linenumber = 0;
680
681 // Open eam file
682 eamFile = fopen( eamPotFile, "r" );
683
684
685 if( eamFile == NULL ){
686
687 // next see if the force path enviorment variable is set
688
689 ffPath = getenv( ffPath_env );
690 if( ffPath == NULL ) {
691 STR_DEFINE(ffPath, FRC_PATH );
692 }
693
694
695 strcpy( temp, ffPath );
696 strcat( temp, "/" );
697 strcat( temp, eamPotFile );
698 strcpy( eamPotFile, temp );
699
700 eamFile = fopen( eamPotFile, "r" );
701
702
703
704 if( eamFile == NULL ){
705
706 sprintf( painCave.errMsg,
707 "Error opening the EAM force parameter file: %s\n"
708 "Have you tried setting the FORCE_PARAM_PATH environment "
709 "vairable?\n",
710 eamPotFile );
711 painCave.isFatal = 1;
712 simError();
713 }
714 }
715
716 // First line is a comment line, read and toss it....
717 eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
718 linenumber++;
719 if(eam_eof_test == NULL){
720 sprintf( painCave.errMsg,
721 "error in reading commment in %s\n", eamPotFile);
722 painCave.isFatal = 1;
723 simError();
724 }
725
726
727
728 // The Second line contains atomic number, atomic mass and a lattice constant
729 eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
730 linenumber++;
731 if(eam_eof_test == NULL){
732 sprintf( painCave.errMsg,
733 "error in reading Identifier line in %s\n", eamPotFile);
734 painCave.isFatal = 1;
735 simError();
736 }
737
738
739
740
741 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
742 sprintf( painCave.errMsg,
743 "Error parseing EAM ident line in %s\n", eamPotFile );
744 painCave.isFatal = 1;
745 simError();
746 }
747
748 info.eam_ident = atoi( the_token );
749
750 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
751 sprintf( painCave.errMsg,
752 "Error parseing EAM mass in %s\n", eamPotFile );
753 painCave.isFatal = 1;
754 simError();
755 }
756 info.mass = atof( the_token);
757
758 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
759 sprintf( painCave.errMsg,
760 "Error parseing EAM Lattice Constant %s\n", eamPotFile );
761 painCave.isFatal = 1;
762 simError();
763 }
764 info.lattice_constant = atof( the_token);
765
766 // Next line is nrho, drho, nr, dr and rcut
767 eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
768 if(eam_eof_test == NULL){
769 sprintf( painCave.errMsg,
770 "error in reading number of points line in %s\n", eamPotFile);
771 painCave.isFatal = 1;
772 simError();
773 }
774
775 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
776 sprintf( painCave.errMsg,
777 "Error parseing EAM nrho: line in %s\n", eamPotFile );
778 painCave.isFatal = 1;
779 simError();
780 }
781
782 info.eam_nrho = atoi( the_token );
783
784 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
785 sprintf( painCave.errMsg,
786 "Error parseing EAM drho in %s\n", eamPotFile );
787 painCave.isFatal = 1;
788 simError();
789 }
790 info.eam_drho = atof( the_token);
791
792 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
793 sprintf( painCave.errMsg,
794 "Error parseing EAM # r in %s\n", eamPotFile );
795 painCave.isFatal = 1;
796 simError();
797 }
798 info.eam_nr = atoi( the_token);
799
800 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
801 sprintf( painCave.errMsg,
802 "Error parseing EAM dr in %s\n", eamPotFile );
803 painCave.isFatal = 1;
804 simError();
805 }
806 info.eam_dr = atof( the_token);
807
808 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
809 sprintf( painCave.errMsg,
810 "Error parseing EAM rcut in %s\n", eamPotFile );
811 painCave.isFatal = 1;
812 simError();
813 }
814 info.eam_rcut = atof( the_token);
815
816
817 // Ok now we have to allocate point arrays and read in number of points
818 // Index the arrays for fortran, starting at 1
819 *eam_Frhovals = new double[info.eam_nrho];
820 *eam_rvals = new double[info.eam_nr];
821 *eam_rhovals = new double[info.eam_nr];
822
823 // Parse F of rho vals.
824
825 // Assume for now that we have a complete number of lines
826 nReadLines = int(info.eam_nrho/5);
827
828 for (i=0;i<nReadLines;i++){
829 j = i*5;
830
831 // Read next line
832 eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
833 linenumber++;
834 if(eam_eof_test == NULL){
835 sprintf( painCave.errMsg,
836 "error in reading EAM file %s at line %d\n",
837 eamPotFile,linenumber);
838 painCave.isFatal = 1;
839 simError();
840 }
841
842 // Parse 5 values on each line into array
843 // Value 1
844 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
845 sprintf( painCave.errMsg,
846 "Error parseing EAM nrho: line in %s\n", eamPotFile );
847 painCave.isFatal = 1;
848 simError();
849 }
850
851 *eam_Frhovals[j+0] = atof( the_token );
852
853 // Value 2
854 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
855 sprintf( painCave.errMsg,
856 "Error parseing EAM nrho: line in %s\n", eamPotFile );
857 painCave.isFatal = 1;
858 simError();
859 }
860
861 *eam_Frhovals[j+1] = atof( the_token );
862
863 // Value 3
864 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
865 sprintf( painCave.errMsg,
866 "Error parseing EAM nrho: line in %s\n", eamPotFile );
867 painCave.isFatal = 1;
868 simError();
869 }
870
871 *eam_Frhovals[j+2] = atof( the_token );
872
873 // Value 4
874 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
875 sprintf( painCave.errMsg,
876 "Error parseing EAM nrho: line in %s\n", eamPotFile );
877 painCave.isFatal = 1;
878 simError();
879 }
880
881 *eam_Frhovals[j+3] = atof( the_token );
882
883 // Value 5
884 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
885 sprintf( painCave.errMsg,
886 "Error parseing EAM nrho: line in %s\n", eamPotFile );
887 painCave.isFatal = 1;
888 simError();
889 }
890
891 *eam_Frhovals[j+4] = atof( the_token );
892
893 }
894 // Parse Z of r vals
895
896 // Assume for now that we have a complete number of lines
897 nReadLines = int(info.eam_nr/5);
898
899 for (i=0;i<nReadLines;i++){
900 j = i*5;
901
902 // Read next line
903 eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
904 linenumber++;
905 if(eam_eof_test == NULL){
906 sprintf( painCave.errMsg,
907 "error in reading EAM file %s at line %d\n",
908 eamPotFile,linenumber);
909 painCave.isFatal = 1;
910 simError();
911 }
912
913 // Parse 5 values on each line into array
914 // Value 1
915 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
916 sprintf( painCave.errMsg,
917 "Error parseing EAM nrho: line in %s\n", eamPotFile );
918 painCave.isFatal = 1;
919 simError();
920 }
921
922 *eam_rvals[j+0] = atof( the_token );
923
924 // Value 2
925 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
926 sprintf( painCave.errMsg,
927 "Error parseing EAM nrho: line in %s\n", eamPotFile );
928 painCave.isFatal = 1;
929 simError();
930 }
931
932 *eam_rvals[j+1] = atof( the_token );
933
934 // Value 3
935 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
936 sprintf( painCave.errMsg,
937 "Error parseing EAM nrho: line in %s\n", eamPotFile );
938 painCave.isFatal = 1;
939 simError();
940 }
941
942 *eam_rvals[j+2] = atof( the_token );
943
944 // Value 4
945 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
946 sprintf( painCave.errMsg,
947 "Error parseing EAM nrho: line in %s\n", eamPotFile );
948 painCave.isFatal = 1;
949 simError();
950 }
951
952 *eam_rvals[j+3] = atof( the_token );
953
954 // Value 5
955 if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
956 sprintf( painCave.errMsg,
957 "Error parseing EAM nrho: line in %s\n", eamPotFile );
958 painCave.isFatal = 1;
959 simError();
960 }
961
962 *eam_rvals[j+4] = atof( the_token );
963
964 }
965 // Parse rho of r vals
966
967 // Assume for now that we have a complete number of lines
968
969 for (i=0;i<nReadLines;i++){
970 j = i*5;
971
972 // Read next line
973 eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
974 linenumber++;
975 if(eam_eof_test == NULL){
976 sprintf( painCave.errMsg,
977 "error in reading EAM file %s at line %d\n",
978 eamPotFile,linenumber);
979 painCave.isFatal = 1;
980 simError();
981 }
982
983 // Parse 5 values on each line into array
984 // Value 1
985 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
986 sprintf( painCave.errMsg,
987 "Error parseing EAM nrho: line in %s\n", eamPotFile );
988 painCave.isFatal = 1;
989 simError();
990 }
991
992 *eam_rhovals[j+0] = atof( the_token );
993
994 // Value 2
995 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
996 sprintf( painCave.errMsg,
997 "Error parseing EAM nrho: line in %s\n", eamPotFile );
998 painCave.isFatal = 1;
999 simError();
1000 }
1001
1002 *eam_rhovals[j+1] = atof( the_token );
1003
1004 // Value 3
1005 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1006 sprintf( painCave.errMsg,
1007 "Error parseing EAM nrho: line in %s\n", eamPotFile );
1008 painCave.isFatal = 1;
1009 simError();
1010 }
1011
1012 *eam_rhovals[j+2] = atof( the_token );
1013
1014 // Value 4
1015 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1016 sprintf( painCave.errMsg,
1017 "Error parseing EAM nrho: line in %s\n", eamPotFile );
1018 painCave.isFatal = 1;
1019 simError();
1020 }
1021
1022 *eam_rhovals[j+3] = atof( the_token );
1023
1024 // Value 5
1025 if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1026 sprintf( painCave.errMsg,
1027 "Error parseing EAM nrho: line in %s\n", eamPotFile );
1028 painCave.isFatal = 1;
1029 simError();
1030 }
1031
1032 *eam_rhovals[j+4] = atof( the_token );
1033
1034 }
1035
1036 fclose(eamFile);
1037 return 0;
1038 }