ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/io/BendTypesSectionParser.cpp
Revision: 1768
Committed: Tue Nov 23 04:35:55 2004 UTC (19 years, 9 months ago) by tim
File size: 4587 byte(s)
Log Message:
add BondTypesSectionParser, BendTypesSectionParser and TorsionTypeSectionParser

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    
28     namespace oopse {
29    
30     BendTypesSectionParser::BendTypesSectionParser() {
31     setSectionName("BendTypes");
32     }
33    
34     void BendTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
35     StringTokenizer tokenizer(line);
36     std::string at1;
37     std::string at2;
38     std::string at3;
39     std::string bt;
40     double theta0;
41     BendType* bendType = NULL;
42    
43     int nTokens = tokenizer.countTokens();
44    
45     if (nTokens < 5) {
46    
47     return;
48     }
49    
50     at1 = tokenizer.nextToken();
51     at2 = tokenizer.nextToken();
52     at3 = tokenizer.nextToken();
53     bt = tokenizer.nextToken();
54     theta0 = tokenizer.nextTokenAsDouble();
55     nTokens -= 5;
56    
57     //switch is a maintain nightmare
58     switch(bt) {
59    
60     case "Harmonic" :
61    
62     if (nTokens < 1) {
63    
64     } else {
65    
66     double ktheta = tokenizer.nextTokenAsDouble();
67     bendType = new HarmonicBendType(theta0, ktheta);
68     }
69     break;
70     case "GhostBend" :
71     if (nTokens < 1) {
72    
73     } else {
74     double ktheta = tokenizer.nextTokenAsDouble();
75     bendType = new HarmonicBendType(theta0, ktheta);
76     }
77     break;
78    
79     case "UreyBradley" :
80     if (nTokens < 3) {
81    
82     } else {
83     double ktheta = tokenizer.nextTokenAsDouble();
84     double s0 = tokenizer.nextTokenAsDouble();
85     double kub = tokenizer.nextTokenAsDouble();
86     bendType = new UreyBradleyBendType(theta0, ktheta, s0, kub);
87     }
88     break;
89    
90     case "Cubic" :
91     if (nTokens < 4) {
92    
93     } else {
94    
95     double k3 = tokenizer.nextTokenAsDouble();
96     double k2 = tokenizer.nextTokenAsDouble();
97     double k1 = tokenizer.nextTokenAsDouble();
98     double k0 = tokenizer.nextTokenAsDouble();
99    
100     bendType = new CubicBendType(theta0, k3, k2, k1, k0);
101     }
102     break;
103    
104     case "Quartic" :
105     if (nTokens < 5) {
106    
107     } else {
108    
109     theta0 = tokenizer.nextTokenAsDouble();
110     double k4 = tokenizer.nextTokenAsDouble();
111     double k3 = tokenizer.nextTokenAsDouble();
112     double k2 = tokenizer.nextTokenAsDouble();
113     double k1 = tokenizer.nextTokenAsDouble();
114     double k0 = tokenizer.nextTokenAsDouble();
115    
116     bendType = new QuadraticBendType(theta0, k4, k3, k2, k1, k0);
117     }
118     break;
119    
120     case "Polynomial" :
121     if (nTokens < 2 || nTokens % 2 != 0) {
122    
123     } else {
124     int nPairs = nTokens / 2;
125     int power;
126     double coefficient;
127     PolynomialBendType* pbt = new PolynomialBendType();
128    
129     for (int i = 0; i < nPairs; ++i) {
130     power = tokenizer.nextTokenAsInt();
131     coefficient = tokenizer.nextTokenAsDouble();
132     pbt->setCoefficient(power, coefficient);
133     }
134     }
135    
136     break;
137    
138     default:
139    
140     }
141    
142     if (bendType != NULL) {
143     ff.addBendType(at1, at2, at3, bendType);
144     }
145     }
146    
147     } //end namespace oopse
148    
149