ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/io/BondTypesSectionParser.cpp
Revision: 1790
Committed: Mon Nov 29 15:50:05 2004 UTC (19 years, 7 months ago) by tim
File size: 4082 byte(s)
Log Message:
more files get fixed

File Contents

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