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