1 |
/* |
2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
* |
4 |
* The University of Notre Dame grants you ("Licensee") a |
5 |
* non-exclusive, royalty free, license to use, modify and |
6 |
* redistribute this software in source and binary code form, provided |
7 |
* that the following conditions are met: |
8 |
* |
9 |
* 1. Acknowledgement of the program authors must be made in any |
10 |
* publication of scientific results based in part on use of the |
11 |
* program. An acceptable form of acknowledgement is citation of |
12 |
* the article in which the program was described (Matthew |
13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
* |
18 |
* 2. Redistributions of source code must retain the above copyright |
19 |
* notice, this list of conditions and the following disclaimer. |
20 |
* |
21 |
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
* notice, this list of conditions and the following disclaimer in the |
23 |
* documentation and/or other materials provided with the |
24 |
* distribution. |
25 |
* |
26 |
* This software is provided "AS IS," without a warranty of any |
27 |
* kind. All express or implied conditions, representations and |
28 |
* warranties, including any implied warranty of merchantability, |
29 |
* fitness for a particular purpose or non-infringement, are hereby |
30 |
* excluded. The University of Notre Dame and its licensors shall not |
31 |
* be liable for any damages suffered by licensee as a result of |
32 |
* using, modifying or distributing the software or its |
33 |
* derivatives. In no event will the University of Notre Dame or its |
34 |
* licensors be liable for any lost revenue, profit or data, or for |
35 |
* direct, indirect, special, consequential, incidental or punitive |
36 |
* damages, however caused and regardless of the theory of liability, |
37 |
* arising out of the use of or inability to use software, even if the |
38 |
* University of Notre Dame has been advised of the possibility of |
39 |
* such damages. |
40 |
*/ |
41 |
|
42 |
#include <stdlib.h> |
43 |
#include <stdio.h> |
44 |
#include <string.h> |
45 |
#include <string> |
46 |
|
47 |
#include "io/Globals.hpp" |
48 |
#include "utils/simError.h" |
49 |
#ifdef IS_MPI |
50 |
#include "io/mpiBASS.h" |
51 |
#endif // is_mpi |
52 |
|
53 |
|
54 |
#define DefineParameter(NAME,KEYWORD) \ |
55 |
NAME.setKeyword(KEYWORD); \ |
56 |
parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
57 |
|
58 |
#define DefineOptionalParameter(NAME,KEYWORD) \ |
59 |
NAME.setKeyword(KEYWORD); NAME.setOptional(true); \ |
60 |
parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
61 |
|
62 |
#define DefineOptionalParameterWithDefaultValue(NAME,KEYWORD, DEFAULTVALUE) \ |
63 |
NAME.setKeyword(KEYWORD); NAME.setOptional(true); NAME.setDefaultValue(DEFAULTVALUE); \ |
64 |
parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
65 |
|
66 |
Globals::Globals(){ |
67 |
|
68 |
DefineParameter(ForceField, "forceField") |
69 |
DefineParameter(NComponents, "nComponents") |
70 |
|
71 |
DefineOptionalParameter(TargetTemp, "targetTemp"); |
72 |
DefineOptionalParameter(Ensemble, "ensemble"); |
73 |
DefineOptionalParameter(Dt, "dt"); |
74 |
DefineOptionalParameter(RunTime, "runTime"); |
75 |
DefineOptionalParameter(InitialConfig, "initialConfig"); |
76 |
DefineOptionalParameter(FinalConfig, "finalConfig"); |
77 |
DefineOptionalParameter(NMol, "nMol"); |
78 |
DefineOptionalParameter(Density, "density"); |
79 |
DefineOptionalParameter(Box, "box"); |
80 |
DefineOptionalParameter(BoxX, "boxX"); |
81 |
DefineOptionalParameter(BoxY, "boxY"); |
82 |
DefineOptionalParameter(BoxZ, "boxZ"); |
83 |
DefineOptionalParameter(SampleTime, "sampleTime"); |
84 |
DefineOptionalParameter(ResetTime, "resetTime"); |
85 |
DefineOptionalParameter(StatusTime, "statusTime"); |
86 |
DefineOptionalParameter(CutoffRadius, "cutoffRadius"); |
87 |
DefineOptionalParameter(SwitchingRadius, "switchingRadius"); |
88 |
DefineOptionalParameter(Dielectric, "dielectric"); |
89 |
DefineOptionalParameter(TempSet, "tempSet"); |
90 |
DefineOptionalParameter(ThermalTime, "thermalTime"); |
91 |
DefineOptionalParameter(TargetPressure, "targetPressure"); |
92 |
DefineOptionalParameter(TauThermostat, "tauThermostat"); |
93 |
DefineOptionalParameter(TauBarostat, "tauBarostat"); |
94 |
DefineOptionalParameter(ZconsTime, "zconsTime"); |
95 |
DefineOptionalParameter(NZconstraints, "nZconstraints"); |
96 |
DefineOptionalParameter(ZconsTol, "zconsTol"); |
97 |
DefineOptionalParameter(ZconsForcePolicy, "zconsForcePolicy"); |
98 |
DefineOptionalParameter(Seed, "seed"); |
99 |
DefineOptionalParameter(Minimizer, "minimizer"); |
100 |
DefineOptionalParameter(MinimizerMaxIter,"minimizerMaxIter"); |
101 |
DefineOptionalParameter(MinimizerWriteFrq, "minimizerWriteFrq"); |
102 |
DefineOptionalParameter(MinimizerStepSize, "minimizerStepSize"); |
103 |
DefineOptionalParameter(MinimizerFTol, "minimizerFTol"); |
104 |
DefineOptionalParameter(MinimizerGTol, "minimizerGTol"); |
105 |
DefineOptionalParameter(MinimizerLSTol, "minimizerLSTol"); |
106 |
DefineOptionalParameter(MinimizerLSMaxIter, "minimizerLSMaxIter"); |
107 |
DefineOptionalParameter(ZconsGap, "zconsGap"); |
108 |
DefineOptionalParameter(ZconsFixtime, "zconsFixtime"); |
109 |
DefineOptionalParameter(ZconsUsingSMD, "zconsUsingSMD"); |
110 |
DefineOptionalParameter(ThermodynamicIntegrationLambda, "thermodynamicIntegrationLambda"); |
111 |
DefineOptionalParameter(ThermodynamicIntegrationK, "thermodynamicIntegrationK"); |
112 |
DefineOptionalParameter(ForceFieldVariant, "forceFieldVariant"); |
113 |
DefineOptionalParameter(ForceFieldFileName, "forceFieldFileName"); |
114 |
DefineOptionalParameter(ThermIntDistSpringConst, "thermIntDistSpringConst"); |
115 |
DefineOptionalParameter(ThermIntThetaSpringConst, "thermIntThetaSpringConst"); |
116 |
DefineOptionalParameter(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst"); |
117 |
DefineOptionalParameter(SurfaceTension, "surfaceTension"); |
118 |
DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); |
119 |
DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); |
120 |
DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); |
121 |
DefineOptionalParameter(StatFileFormat, "statFileFormat"); |
122 |
|
123 |
DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); |
124 |
DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); |
125 |
DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false); |
126 |
DefineOptionalParameterWithDefaultValue(UseIntialExtendedSystemState, "useInitialExtendedSystemState", false); |
127 |
DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, "orthoBoxTolerance", 1E-6); |
128 |
DefineOptionalParameterWithDefaultValue(UseSolidThermInt, "useSolidThermInt", false); |
129 |
DefineOptionalParameterWithDefaultValue(UseLiquidThermInt, "useLiquidThermInt", false); |
130 |
DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0); |
131 |
DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5); |
132 |
DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.5); |
133 |
DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5); |
134 |
DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0); |
135 |
DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0); |
136 |
|
137 |
} |
138 |
|
139 |
int Globals::globalAssign( event* the_event ){ |
140 |
|
141 |
int key; |
142 |
int token; |
143 |
interface_assign_type the_type = the_event->evt.asmt.asmt_type; |
144 |
char* lhs = the_event->evt.asmt.lhs; |
145 |
std::string keyword(lhs); |
146 |
|
147 |
bool result; |
148 |
|
149 |
|
150 |
ParamMap::iterator i =parameters_.find(keyword); |
151 |
if (i != parameters_.end()) { |
152 |
if( the_type == STRING ){ |
153 |
result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval)); |
154 |
if (!result ) { |
155 |
sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a string.\n", keyword.c_str() ); |
156 |
} |
157 |
} else if( the_type == DOUBLE ){ |
158 |
result = i->second->setData(the_event->evt.asmt.rhs.dval); |
159 |
if (!result ) |
160 |
sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a double.\n", keyword.c_str() ); |
161 |
} |
162 |
else if (the_type == INT ){ |
163 |
result = i->second->setData(the_event->evt.asmt.rhs.ival); |
164 |
if (!result ) |
165 |
sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be an int.\n", keyword.c_str() ); |
166 |
|
167 |
} else { |
168 |
|
169 |
} |
170 |
} |
171 |
|
172 |
if (keyword == "nComponents" && getNComponents() > 0) { |
173 |
components = new Component*[getNComponents()]; |
174 |
}else if (keyword == "nZconstraints" && getNZconstraints() > 0) { |
175 |
zConstraints = new ZconStamp*[getNZconstraints()]; |
176 |
} |
177 |
|
178 |
return result; |
179 |
} |
180 |
|
181 |
int Globals::newComponent( event* the_event ){ |
182 |
|
183 |
current_component = new Component; |
184 |
int index = the_event->evt.blk_index; |
185 |
char err[200]; |
186 |
|
187 |
if( haveNComponents() && index < getNComponents() ) |
188 |
components[index] = current_component; |
189 |
else{ |
190 |
if( haveNComponents() ){ |
191 |
sprintf( err, "meta-data parsing error: %d out of nComponents range", |
192 |
index ); |
193 |
the_event->err_msg = strdup( err ); |
194 |
return 0; |
195 |
} |
196 |
else{ |
197 |
the_event->err_msg = strdup("meta-data parsing error: nComponents not given before" |
198 |
" first component declaration." ); |
199 |
return 0; |
200 |
} |
201 |
} |
202 |
|
203 |
return 1; |
204 |
} |
205 |
|
206 |
|
207 |
|
208 |
int Globals::componentAssign( event* the_event ){ |
209 |
|
210 |
switch( the_event->evt.asmt.asmt_type ){ |
211 |
|
212 |
case STRING: |
213 |
return current_component->assignString( the_event->evt.asmt.lhs, |
214 |
the_event->evt.asmt.rhs.sval, |
215 |
&(the_event->err_msg)); |
216 |
break; |
217 |
|
218 |
case DOUBLE: |
219 |
return current_component->assignDouble( the_event->evt.asmt.lhs, |
220 |
the_event->evt.asmt.rhs.dval, |
221 |
&(the_event->err_msg)); |
222 |
break; |
223 |
|
224 |
case INT: |
225 |
return current_component->assignInt( the_event->evt.asmt.lhs, |
226 |
the_event->evt.asmt.rhs.ival, |
227 |
&(the_event->err_msg)); |
228 |
break; |
229 |
|
230 |
default: |
231 |
the_event->err_msg = strdup( "Globals error. Invalid component" |
232 |
" assignment type" ); |
233 |
return 0; |
234 |
break; |
235 |
} |
236 |
return 0; |
237 |
} |
238 |
|
239 |
int Globals::componentEnd( event* the_event ){ |
240 |
|
241 |
the_event->err_msg = current_component->checkMe(); |
242 |
if( the_event->err_msg != NULL ) return 0; |
243 |
|
244 |
return 1; |
245 |
} |
246 |
|
247 |
int Globals::newZconstraint( event* the_event ){ |
248 |
|
249 |
|
250 |
int index = the_event->evt.blk_index; |
251 |
char err[200]; |
252 |
current_zConstraint = new ZconStamp( index ); |
253 |
|
254 |
if( haveNZconstraints() && index < getNZconstraints() ) |
255 |
zConstraints[index] = current_zConstraint; |
256 |
else{ |
257 |
if( haveNZconstraints() ){ |
258 |
sprintf( err, "meta-data parsing error: %d out of nZconstraints range", |
259 |
index ); |
260 |
the_event->err_msg = strdup( err ); |
261 |
return 0; |
262 |
} |
263 |
else{ |
264 |
the_event->err_msg = strdup("meta-data parsing error: nZconstraints" |
265 |
" not given before" |
266 |
" first zConstraint declaration." ); |
267 |
return 0; |
268 |
} |
269 |
} |
270 |
|
271 |
return 1; |
272 |
} |
273 |
|
274 |
|
275 |
|
276 |
int Globals::zConstraintAssign( event* the_event ){ |
277 |
|
278 |
switch( the_event->evt.asmt.asmt_type ){ |
279 |
|
280 |
case STRING: |
281 |
return current_zConstraint->assignString( the_event->evt.asmt.lhs, |
282 |
the_event->evt.asmt.rhs.sval, |
283 |
&(the_event->err_msg)); |
284 |
break; |
285 |
|
286 |
case DOUBLE: |
287 |
return current_zConstraint->assignDouble( the_event->evt.asmt.lhs, |
288 |
the_event->evt.asmt.rhs.dval, |
289 |
&(the_event->err_msg)); |
290 |
break; |
291 |
|
292 |
case INT: |
293 |
return current_zConstraint->assignInt( the_event->evt.asmt.lhs, |
294 |
the_event->evt.asmt.rhs.ival, |
295 |
&(the_event->err_msg)); |
296 |
break; |
297 |
|
298 |
default: |
299 |
the_event->err_msg = strdup( "Globals error. Invalid zConstraint" |
300 |
" assignment type" ); |
301 |
return 0; |
302 |
break; |
303 |
} |
304 |
return 0; |
305 |
} |
306 |
|
307 |
int Globals::zConstraintEnd( event* the_event ){ |
308 |
|
309 |
the_event->err_msg = current_zConstraint->checkMe(); |
310 |
if( the_event->err_msg != NULL ) return 0; |
311 |
|
312 |
return 1; |
313 |
} |
314 |
|
315 |
char* Globals::checkMe( void ){ |
316 |
|
317 |
|
318 |
std::string err("The following required keywords are missing:\n"); |
319 |
short int have_err = 0; |
320 |
|
321 |
ParamMap::iterator i; |
322 |
for (i = parameters_.begin(); i != parameters_.end(); ++i) { |
323 |
if (!i->second->isOptional() && i->second->empty()) { |
324 |
err += i->second->getKeyword() + "\n"; |
325 |
} |
326 |
} |
327 |
|
328 |
//@todo memory leak |
329 |
if( have_err ) |
330 |
return strdup( err.c_str() ); |
331 |
|
332 |
return NULL; |
333 |
|
334 |
|
335 |
} |
336 |
|
337 |
int Globals::globalEnd( event* the_event ){ |
338 |
|
339 |
the_event->err_msg = checkMe(); |
340 |
if( the_event->err_msg != NULL ) return 0; |
341 |
|
342 |
return 1; |
343 |
} |