ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/io/BendTypesSectionParser.cpp
Revision: 1801
Committed: Tue Nov 30 04:43:29 2004 UTC (19 years, 7 months ago) by tim
File size: 5431 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/BendTypesSectionParser.hpp"
27 tim 1784 #include "types/HarmonicBendType.hpp"
28     #include "types/UreyBradleyBendType.hpp"
29     #include "types/CubicBendType.hpp"
30 tim 1789 #include "types/QuarticBendType.hpp"
31 tim 1784 #include "types/PolynomialBendType.hpp"
32 tim 1800 #include "UseTheForce/ForceField.hpp"
33 tim 1768 namespace oopse {
34    
35     BendTypesSectionParser::BendTypesSectionParser() {
36     setSectionName("BendTypes");
37 tim 1800
38     stringToEnumMap_["Harmonic"] = btHarmonic;
39     stringToEnumMap_["GhostBend"] = btGhostBend;
40     stringToEnumMap_["UreyBradley"] = btUreyBradley;
41     stringToEnumMap_["Cubic"] = btCubic;
42     stringToEnumMap_["Quartic"] = btQuartic;
43     stringToEnumMap_["Polynomial"] = btPolynomial;
44 tim 1768 }
45    
46     void BendTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
47     StringTokenizer tokenizer(line);
48     BendType* bendType = NULL;
49    
50     int nTokens = tokenizer.countTokens();
51    
52     if (nTokens < 5) {
53    
54     return;
55     }
56    
57 tim 1801 std::string at1 = tokenizer.nextToken();
58     std::string at2 = tokenizer.nextToken();
59     std::string at3 = tokenizer.nextToken();
60     BendTypeEnum bt = getBendTypeEnum(tokenizer.nextToken());
61     double theta0 = tokenizer.nextTokenAsDouble();
62 tim 1768 nTokens -= 5;
63    
64     //switch is a maintain nightmare
65     switch(bt) {
66    
67 tim 1800 case btHarmonic :
68 tim 1768
69     if (nTokens < 1) {
70    
71     } else {
72    
73     double ktheta = tokenizer.nextTokenAsDouble();
74     bendType = new HarmonicBendType(theta0, ktheta);
75     }
76     break;
77 tim 1800 case btGhostBend :
78 tim 1768 if (nTokens < 1) {
79    
80     } else {
81     double ktheta = tokenizer.nextTokenAsDouble();
82     bendType = new HarmonicBendType(theta0, ktheta);
83     }
84     break;
85    
86 tim 1800 case btUreyBradley :
87 tim 1768 if (nTokens < 3) {
88    
89     } else {
90     double ktheta = tokenizer.nextTokenAsDouble();
91     double s0 = tokenizer.nextTokenAsDouble();
92     double kub = tokenizer.nextTokenAsDouble();
93     bendType = new UreyBradleyBendType(theta0, ktheta, s0, kub);
94     }
95     break;
96    
97 tim 1800 case btCubic :
98 tim 1768 if (nTokens < 4) {
99    
100     } else {
101    
102     double k3 = tokenizer.nextTokenAsDouble();
103     double k2 = tokenizer.nextTokenAsDouble();
104     double k1 = tokenizer.nextTokenAsDouble();
105     double k0 = tokenizer.nextTokenAsDouble();
106    
107     bendType = new CubicBendType(theta0, k3, k2, k1, k0);
108     }
109     break;
110    
111 tim 1800 case btQuartic :
112 tim 1768 if (nTokens < 5) {
113    
114     } else {
115    
116     theta0 = tokenizer.nextTokenAsDouble();
117     double k4 = tokenizer.nextTokenAsDouble();
118     double k3 = tokenizer.nextTokenAsDouble();
119     double k2 = tokenizer.nextTokenAsDouble();
120     double k1 = tokenizer.nextTokenAsDouble();
121     double k0 = tokenizer.nextTokenAsDouble();
122    
123 tim 1789 bendType = new QuarticBendType(theta0, k4, k3, k2, k1, k0);
124 tim 1768 }
125     break;
126    
127 tim 1800 case btPolynomial :
128 tim 1768 if (nTokens < 2 || nTokens % 2 != 0) {
129    
130     } else {
131     int nPairs = nTokens / 2;
132     int power;
133     double coefficient;
134 tim 1801 PolynomialBendType* pbt = new PolynomialBendType(theta0);
135 tim 1768
136     for (int i = 0; i < nPairs; ++i) {
137     power = tokenizer.nextTokenAsInt();
138     coefficient = tokenizer.nextTokenAsDouble();
139     pbt->setCoefficient(power, coefficient);
140     }
141     }
142    
143     break;
144    
145 tim 1801 case btUnknown :
146 tim 1768 default:
147 tim 1801 break;
148 tim 1768
149     }
150    
151     if (bendType != NULL) {
152     ff.addBendType(at1, at2, at3, bendType);
153     }
154     }
155    
156 tim 1801 BendTypesSectionParser::BendTypeEnum BendTypesSectionParser::getBendTypeEnum(const std::string& str) {
157     std::map<std::string, BendTypeEnum>::iterator i;
158 tim 1800 i = stringToEnumMap_.find(str);
159    
160 tim 1801 return i == stringToEnumMap_.end() ? btUnknown : i->second;
161 tim 1800 }
162    
163 tim 1768 } //end namespace oopse
164    
165