ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/io/BondTypesSectionParser.cpp
Revision: 1801
Committed: Tue Nov 30 04:43:29 2004 UTC (19 years, 9 months ago) by tim
File size: 4683 byte(s)
Log Message:
Section Parsers get compiled

File Contents

# User Rev Content
1 tim 1768 /*
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/BondTypesSectionParser.hpp"
27 tim 1784 #include "types/FixedBondType.hpp"
28     #include "types/HarmonicBondType.hpp"
29     #include "types/CubicBondType.hpp"
30 tim 1790 #include "types/QuarticBondType.hpp"
31 tim 1784 #include "types/PolynomialBondType.hpp"
32 tim 1800 #include "UseTheForce/ForceField.hpp"
33 tim 1768 namespace oopse {
34    
35     BondTypesSectionParser::BondTypesSectionParser() {
36     setSectionName("BondTypes");
37 tim 1800
38     stringToEnumMap_["Fixed"] = btFixed;
39     stringToEnumMap_["Harmonic"] = btHarmonic;
40     stringToEnumMap_["Cubic"] = btCubic;
41     stringToEnumMap_["Quartic"] = btQuartic;
42     stringToEnumMap_["Polynomial"] = btPolynomial;
43 tim 1768 }
44    
45     void BondTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
46     StringTokenizer tokenizer(line);
47     BondType* bondType = NULL;
48     int nTokens = tokenizer.countTokens();
49    
50     if (nTokens < 4) {
51    
52     return;
53     }
54    
55 tim 1801 std::string at1 = tokenizer.nextToken();
56     std::string at2 = tokenizer.nextToken();
57     BondTypeEnum bt = getBondTypeEnum(tokenizer.nextToken());
58     double b0 = tokenizer.nextTokenAsDouble();
59 tim 1768 nTokens -= 4;
60    
61     //switch is a maintain nightmare
62     switch(bt) {
63 tim 1800 case btFixed :
64 tim 1801 bondType = new FixedBondType(b0);
65 tim 1768 break;
66    
67 tim 1800 case btHarmonic :
68 tim 1768 if (nTokens < 1) {
69    
70     } else {
71    
72     double kb = tokenizer.nextTokenAsDouble();
73     bondType = new HarmonicBondType(b0, kb);
74     }
75    
76     break;
77    
78 tim 1800 case btCubic :
79 tim 1768 if (nTokens < 4) {
80    
81     } else {
82    
83     double k3 = tokenizer.nextTokenAsDouble();
84     double k2 = tokenizer.nextTokenAsDouble();
85     double k1 = tokenizer.nextTokenAsDouble();
86     double k0 = tokenizer.nextTokenAsDouble();
87    
88     bondType = new CubicBondType(b0, k3, k2, k1, k0);
89     }
90     break;
91    
92 tim 1800 case btQuartic :
93 tim 1768 if (nTokens < 5) {
94    
95     } else {
96    
97     b0 = tokenizer.nextTokenAsDouble();
98     double k4 = tokenizer.nextTokenAsDouble();
99     double k3 = tokenizer.nextTokenAsDouble();
100     double k2 = tokenizer.nextTokenAsDouble();
101     double k1 = tokenizer.nextTokenAsDouble();
102     double k0 = tokenizer.nextTokenAsDouble();
103    
104 tim 1785 bondType = new QuarticBondType(b0, k4, k3, k2, k1, k0);
105 tim 1768 }
106     break;
107    
108 tim 1800 case btPolynomial :
109 tim 1768 if (nTokens < 2 || nTokens % 2 != 0) {
110    
111     } else {
112     int nPairs = nTokens / 2;
113     int power;
114     double coefficient;
115 tim 1801 PolynomialBondType* pbt = new PolynomialBondType(b0);
116 tim 1768
117     for (int i = 0; i < nPairs; ++i) {
118     power = tokenizer.nextTokenAsInt();
119     coefficient = tokenizer.nextTokenAsDouble();
120     pbt->setCoefficient(power, coefficient);
121     }
122     }
123    
124     break;
125    
126 tim 1801 case btUnknown :
127 tim 1768 default:
128 tim 1801 break;
129 tim 1768
130     }
131    
132     if (bondType != NULL) {
133     ff.addBondType(at1, at2, bondType);
134     }
135    
136     }
137    
138 tim 1801 BondTypesSectionParser::BondTypeEnum BondTypesSectionParser::getBondTypeEnum(const std::string& str) {
139 tim 1800 std::map<std::string, BondTypeEnum>::iterator i;
140     i = stringToEnumMap_.find(str);
141    
142 tim 1801 return i == stringToEnumMap_.end() ? btUnknown : i->second;
143 tim 1800 }
144    
145 tim 1768 } //end namespace oopse
146