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: 1892
Committed: Thu Dec 16 17:27:47 2004 UTC (19 years, 9 months ago) by tim
File size: 4851 byte(s)
Log Message:
add getMaxRcutFromAtomType into EAM

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 1789 #include "UseTheForce/ForceField.hpp"
29     #include "utils/simError.h"
30 tim 1769 namespace oopse {
31    
32     EAMAtomTypesSectionParser::EAMAtomTypesSectionParser() {
33     setSectionName("EAMAtomTypes");
34     }
35    
36     void EAMAtomTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
37    
38 tim 1883 StringTokenizer tokenizer(line);
39 tim 1769
40 tim 1883 if (tokenizer.countTokens() >= 2) {
41     std::string atomTypeName = tokenizer.nextToken();
42     std::string potentialParamFile = tokenizer.nextToken();
43    
44     AtomType* atomType = ff.getAtomType(atomTypeName);
45     if (atomType != NULL) {
46     atomType->setEAM();
47     parseEAMParamFile(ff, atomType, potentialParamFile, atomType->getIdent());
48     } else {
49    
50     }
51    
52     } else {
53    
54     }
55 tim 1769
56    
57     }
58    
59 tim 1789 void EAMAtomTypesSectionParser::parseEAMParamFile(ForceField& ff, AtomType* atomType,
60 tim 1769 const std::string& potentialParamFile, int ident) {
61    
62 tim 1789 ifstrstream* ppfStream = ff.openForceFieldFile(potentialParamFile);
63 tim 1769 const int bufferSize = 65535;
64     char buffer[bufferSize];
65     std::string line;
66    
67     //skip first line
68     ppfStream->getline(buffer, bufferSize);
69    
70    
71     //The Second line contains atomic number, atomic mass, a lattice constant and lattic type
72     int junk;
73     double mass;
74     double latticeConstant;
75     std::string lattice;
76     if (ppfStream->getline(buffer, bufferSize)) {
77     StringTokenizer tokenizer1(buffer);
78    
79     if (tokenizer1.countTokens() >= 4) {
80     junk = tokenizer1.nextTokenAsInt();
81     mass = tokenizer1.nextTokenAsDouble();
82     latticeConstant = tokenizer1.nextTokenAsDouble();
83     lattice = tokenizer1.nextToken();
84     }else {
85     std::cerr << "Not enought tokens" << std::endl;
86     }
87     } else {
88    
89     }
90    
91     // The third line is nrho, drho, nr, dr and rcut
92     EAMParam eamParam;
93     eamParam.latticeConstant = latticeConstant;
94    
95     if (ppfStream->getline(buffer, bufferSize)) {
96     StringTokenizer tokenizer2(buffer);
97    
98     if (tokenizer2.countTokens() >= 5){
99     eamParam.nrho = tokenizer2.nextTokenAsInt();
100     eamParam.drho = tokenizer2.nextTokenAsDouble();
101     eamParam.nr = tokenizer2.nextTokenAsInt();
102     eamParam.dr = tokenizer2.nextTokenAsDouble();
103     eamParam.rcut = tokenizer2.nextTokenAsDouble();
104     }else {
105     std::cerr << "Not enought tokens" << std::endl;
106     }
107     } else {
108    
109     }
110    
111 tim 1789 parseEAMArray(*ppfStream, eamParam.rvals, eamParam.nr);
112     parseEAMArray(*ppfStream, eamParam.rhovals, eamParam.nr);
113     parseEAMArray(*ppfStream, eamParam.Frhovals, eamParam.nrho);
114 tim 1769
115 tim 1789 atomType->addProperty(new EAMParamGenericData("EAM", eamParam));
116 tim 1769 }
117    
118 tim 1789 void EAMAtomTypesSectionParser::parseEAMArray(std::istream& input,
119 tim 1769 std::vector<double>& array, int num) {
120    
121     const int dataPerLine = 5;
122     if (num % dataPerLine != 0) {
123    
124     }
125 tim 1892
126     int nlinesToRead = num / dataPerLine;
127 tim 1769
128     const int bufferSize = 65535;
129     char buffer[bufferSize];
130     std::string line;
131     int readLines = num/dataPerLine;
132     int lineCount = 0;
133    
134 tim 1892 while(lineCount < nlinesToRead && input.getline(buffer, bufferSize) ){
135    
136 tim 1769 StringTokenizer tokenizer(buffer);
137     if (tokenizer.countTokens() >= dataPerLine) {
138 tim 1770 for (int i = 0; i < dataPerLine; ++i) {
139 tim 1789 array.push_back(tokenizer.nextTokenAsDouble());
140 tim 1769 }
141     } else {
142    
143     }
144     ++lineCount;
145     }
146    
147 tim 1892 if (lineCount < nlinesToRead) {
148 tim 1769
149     }
150    
151     }
152    
153    
154     } //end namespace oopse
155