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: 1883
Committed: Mon Dec 13 22:30:27 2004 UTC (19 years, 9 months ago) by tim
File size: 4833 byte(s)
Log Message:
MPI version is 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 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     ident = tokenizer1.nextTokenAsInt();
79    
80     if (tokenizer1.countTokens() >= 4) {
81     junk = tokenizer1.nextTokenAsInt();
82     mass = tokenizer1.nextTokenAsDouble();
83     latticeConstant = tokenizer1.nextTokenAsDouble();
84     lattice = tokenizer1.nextToken();
85     }else {
86     std::cerr << "Not enought tokens" << std::endl;
87     }
88     } else {
89    
90     }
91    
92     // The third line is nrho, drho, nr, dr and rcut
93     EAMParam eamParam;
94     eamParam.latticeConstant = latticeConstant;
95    
96     if (ppfStream->getline(buffer, bufferSize)) {
97     StringTokenizer tokenizer2(buffer);
98    
99     if (tokenizer2.countTokens() >= 5){
100     eamParam.nrho = tokenizer2.nextTokenAsInt();
101     eamParam.drho = tokenizer2.nextTokenAsDouble();
102     eamParam.nr = tokenizer2.nextTokenAsInt();
103     eamParam.dr = tokenizer2.nextTokenAsDouble();
104     eamParam.rcut = tokenizer2.nextTokenAsDouble();
105     }else {
106     std::cerr << "Not enought tokens" << std::endl;
107     }
108     } else {
109    
110     }
111    
112 tim 1789 parseEAMArray(*ppfStream, eamParam.rvals, eamParam.nr);
113     parseEAMArray(*ppfStream, eamParam.rhovals, eamParam.nr);
114     parseEAMArray(*ppfStream, eamParam.Frhovals, eamParam.nrho);
115 tim 1769
116 tim 1789 atomType->addProperty(new EAMParamGenericData("EAM", eamParam));
117 tim 1769 }
118    
119 tim 1789 void EAMAtomTypesSectionParser::parseEAMArray(std::istream& input,
120 tim 1769 std::vector<double>& array, int num) {
121    
122     const int dataPerLine = 5;
123     if (num % dataPerLine != 0) {
124    
125     }
126    
127     const int bufferSize = 65535;
128     char buffer[bufferSize];
129     std::string line;
130     int readLines = num/dataPerLine;
131     int lineCount = 0;
132 tim 1789 while(input.getline(buffer, bufferSize) && lineCount < num){
133 tim 1769
134     StringTokenizer tokenizer(buffer);
135     if (tokenizer.countTokens() >= dataPerLine) {
136 tim 1770 for (int i = 0; i < dataPerLine; ++i) {
137 tim 1789 array.push_back(tokenizer.nextTokenAsDouble());
138 tim 1769 }
139     } else {
140    
141     }
142     ++lineCount;
143     }
144    
145     if (lineCount < num) {
146    
147     }
148    
149     }
150    
151    
152     } //end namespace oopse
153