ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/io/EAMAtomTypesSectionParser.cpp
Revision: 1784
Committed: Wed Nov 24 22:12:12 2004 UTC (19 years, 9 months ago) by tim
File size: 5311 byte(s)
Log Message:
more get built

File Contents

# User Rev Content
1 tim 1769 /*
2     * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project
3     *
4     * Contact: oopse@oopse.org
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU Lesser General Public License
8     * as published by the Free Software Foundation; either version 2.1
9     * of the License, or (at your option) any later version.
10     * All we ask is that proper credit is given for our work, which includes
11     * - but is not limited to - adding the above copyright notice to the beginning
12     * of your source code files, and to any copyright notice that you may distribute
13     * with programs based on this work.
14     *
15     * This program is distributed in the hope that it will be useful,
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     * GNU Lesser General Public License for more details.
19     *
20     * You should have received a copy of the GNU Lesser General Public License
21     * along with this program; if not, write to the Free Software
22     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23     *
24     */
25    
26     #include "io/EAMAtomTypesSectionParser.hpp"
27 tim 1784 #include "types/AtomType.hpp"
28 tim 1769
29     namespace oopse {
30    
31     EAMAtomTypesSectionParser::EAMAtomTypesSectionParser() {
32     setSectionName("EAMAtomTypes");
33     }
34    
35     void EAMAtomTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
36     AtomType* atomType;
37     std::string atomTypeName;
38     double mass;
39     StringTokenizer tokenizer(line);
40    
41     if (tokenizer.countTokens() >= 2) {
42     atomTypeName = tokenizer.nextToken();
43     std::string potentialParamFile = tokenizer.nextToken();
44    
45     AtomType* atomType = ff.getAtomType(atomTypeName);
46     if (atomType != NULL) {
47     atomType->setEAM();
48     parseEAMParamFile(atomType, potentialParamFile, atomType->getIdent());
49     } else {
50    
51     }
52    
53     } else {
54     sprintf( painCave.errMsg,
55     "Not enough tokens when parsing EAM Force Field : %s\n"
56     "in line %d : %s\n",
57     filename.c_str(), lineNo, line);
58     painCave.severity = OOPSE_ERROR;
59     painCave.isFatal = 1;
60     simError();
61     }
62    
63    
64     }
65    
66     void EAMAtomTypesSectionParser::parseEAMParamFile(AtomType* atomType,
67     const std::string& potentialParamFile, int ident) {
68    
69     ifstrstream* ppfStream;
70 tim 1784 ppfStream = openForceFieldFile(potentialParamFile);
71 tim 1769 const int bufferSize = 65535;
72     char buffer[bufferSize];
73     std::string line;
74    
75     //skip first line
76     ppfStream->getline(buffer, bufferSize);
77    
78    
79     //The Second line contains atomic number, atomic mass, a lattice constant and lattic type
80     int junk;
81     double mass;
82     double latticeConstant;
83     std::string lattice;
84     if (ppfStream->getline(buffer, bufferSize)) {
85     StringTokenizer tokenizer1(buffer);
86     ident = tokenizer1.nextTokenAsInt();
87    
88     if (tokenizer1.countTokens() >= 4) {
89     junk = tokenizer1.nextTokenAsInt();
90     mass = tokenizer1.nextTokenAsDouble();
91     latticeConstant = tokenizer1.nextTokenAsDouble();
92     lattice = tokenizer1.nextToken();
93     }else {
94     std::cerr << "Not enought tokens" << std::endl;
95     }
96     } else {
97    
98     }
99    
100     // The third line is nrho, drho, nr, dr and rcut
101     EAMParam eamParam;
102     eamParam.latticeConstant = latticeConstant;
103    
104     if (ppfStream->getline(buffer, bufferSize)) {
105     StringTokenizer tokenizer2(buffer);
106    
107     if (tokenizer2.countTokens() >= 5){
108     eamParam.nrho = tokenizer2.nextTokenAsInt();
109     eamParam.drho = tokenizer2.nextTokenAsDouble();
110     eamParam.nr = tokenizer2.nextTokenAsInt();
111     eamParam.dr = tokenizer2.nextTokenAsDouble();
112     eamParam.rcut = tokenizer2.nextTokenAsDouble();
113     }else {
114     std::cerr << "Not enought tokens" << std::endl;
115     }
116     } else {
117    
118     }
119    
120     parseEAMArray(ppfStream, eamParam.rvals, eamParam.nr);
121     parseEAMArray(ppfStream, eamParam.rhovals, eamParam.nr);
122     parseEAMArray(ppfStream, eamParam.Frhovals, eamParam.nrho);
123    
124     atomType->addProperty(EAMParamGenericData("EAM", eamParam));
125     }
126    
127     void EAMAtomTypesSectionParser::parseEAMArray(ifstrstream* ppfStream,
128     std::vector<double>& array, int num) {
129    
130     const int dataPerLine = 5;
131     if (num % dataPerLine != 0) {
132    
133     }
134    
135     const int bufferSize = 65535;
136     char buffer[bufferSize];
137     std::string line;
138     int readLines = num/dataPerLine;
139     int lineCount = 0;
140     while(ffStream.getline(buffer, bufferSize) && lineCount < num){
141    
142     StringTokenizer tokenizer(buffer);
143     if (tokenizer.countTokens() >= dataPerLine) {
144 tim 1770 for (int i = 0; i < dataPerLine; ++i) {
145 tim 1769 array.push_back(tokenizer.nextTokenAsDouble()));
146     }
147     } else {
148    
149     }
150     ++lineCount;
151     }
152    
153     if (lineCount < num) {
154    
155     }
156    
157     }
158    
159    
160     } //end namespace oopse
161