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 |
#include "io/ParamConstraint.hpp" |
54 |
|
55 |
#define DefineParameter(NAME,KEYWORD) \ |
56 |
NAME.setKeyword(KEYWORD); \ |
57 |
parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
58 |
|
59 |
#define DefineOptionalParameter(NAME,KEYWORD) \ |
60 |
NAME.setKeyword(KEYWORD); NAME.setOptional(true); \ |
61 |
parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
62 |
|
63 |
#define DefineOptionalParameterWithDefaultValue(NAME,KEYWORD, DEFAULTVALUE) \ |
64 |
NAME.setKeyword(KEYWORD); NAME.setOptional(true); NAME.setDefaultValue(DEFAULTVALUE); \ |
65 |
parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
66 |
|
67 |
#define CheckParameter(NAME, CONSTRAINT) \ |
68 |
if (!NAME.empty()) { if (!(CONSTRAINT)(NAME.getData())) std::cout <<"Error in parsing " << NAME.getKeyword() << " : "<< (CONSTRAINT).getConstraintDescription() << std::endl; } |
69 |
|
70 |
|
71 |
Globals::Globals(){ |
72 |
|
73 |
DefineParameter(ForceField, "forceField") |
74 |
DefineParameter(NComponents, "nComponents") |
75 |
|
76 |
DefineOptionalParameter(TargetTemp, "targetTemp"); |
77 |
DefineOptionalParameter(Ensemble, "ensemble"); |
78 |
DefineOptionalParameter(Dt, "dt"); |
79 |
DefineOptionalParameter(RunTime, "runTime"); |
80 |
DefineOptionalParameter(InitialConfig, "initialConfig"); |
81 |
DefineOptionalParameter(FinalConfig, "finalConfig"); |
82 |
DefineOptionalParameter(NMol, "nMol"); |
83 |
DefineOptionalParameter(Density, "density"); |
84 |
DefineOptionalParameter(Box, "box"); |
85 |
DefineOptionalParameter(BoxX, "boxX"); |
86 |
DefineOptionalParameter(BoxY, "boxY"); |
87 |
DefineOptionalParameter(BoxZ, "boxZ"); |
88 |
DefineOptionalParameter(SampleTime, "sampleTime"); |
89 |
DefineOptionalParameter(ResetTime, "resetTime"); |
90 |
DefineOptionalParameter(StatusTime, "statusTime"); |
91 |
DefineOptionalParameter(CutoffRadius, "cutoffRadius"); |
92 |
DefineOptionalParameter(SwitchingRadius, "switchingRadius"); |
93 |
DefineOptionalParameter(Dielectric, "dielectric"); |
94 |
DefineOptionalParameter(TempSet, "tempSet"); |
95 |
DefineOptionalParameter(ThermalTime, "thermalTime"); |
96 |
DefineOptionalParameter(TargetPressure, "targetPressure"); |
97 |
DefineOptionalParameter(TauThermostat, "tauThermostat"); |
98 |
DefineOptionalParameter(TauBarostat, "tauBarostat"); |
99 |
DefineOptionalParameter(ZconsTime, "zconsTime"); |
100 |
DefineOptionalParameter(NZconstraints, "nZconstraints"); |
101 |
DefineOptionalParameter(ZconsTol, "zconsTol"); |
102 |
DefineOptionalParameter(ZconsForcePolicy, "zconsForcePolicy"); |
103 |
DefineOptionalParameter(Seed, "seed"); |
104 |
DefineOptionalParameter(Minimizer, "minimizer"); |
105 |
DefineOptionalParameter(MinimizerMaxIter,"minimizerMaxIter"); |
106 |
DefineOptionalParameter(MinimizerWriteFrq, "minimizerWriteFrq"); |
107 |
DefineOptionalParameter(MinimizerStepSize, "minimizerStepSize"); |
108 |
DefineOptionalParameter(MinimizerFTol, "minimizerFTol"); |
109 |
DefineOptionalParameter(MinimizerGTol, "minimizerGTol"); |
110 |
DefineOptionalParameter(MinimizerLSTol, "minimizerLSTol"); |
111 |
DefineOptionalParameter(MinimizerLSMaxIter, "minimizerLSMaxIter"); |
112 |
DefineOptionalParameter(ZconsGap, "zconsGap"); |
113 |
DefineOptionalParameter(ZconsFixtime, "zconsFixtime"); |
114 |
DefineOptionalParameter(ZconsUsingSMD, "zconsUsingSMD"); |
115 |
DefineOptionalParameter(ThermodynamicIntegrationLambda, "thermodynamicIntegrationLambda"); |
116 |
DefineOptionalParameter(ThermodynamicIntegrationK, "thermodynamicIntegrationK"); |
117 |
DefineOptionalParameter(ForceFieldVariant, "forceFieldVariant"); |
118 |
DefineOptionalParameter(ForceFieldFileName, "forceFieldFileName"); |
119 |
DefineOptionalParameter(ThermIntDistSpringConst, "thermIntDistSpringConst"); |
120 |
DefineOptionalParameter(ThermIntThetaSpringConst, "thermIntThetaSpringConst"); |
121 |
DefineOptionalParameter(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst"); |
122 |
DefineOptionalParameter(SurfaceTension, "surfaceTension"); |
123 |
DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); |
124 |
DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); |
125 |
DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); |
126 |
DefineOptionalParameter(StatFileFormat, "statFileFormat"); |
127 |
|
128 |
DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); |
129 |
DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); |
130 |
DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false); |
131 |
DefineOptionalParameterWithDefaultValue(UseIntialExtendedSystemState, "useInitialExtendedSystemState", false); |
132 |
DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, "orthoBoxTolerance", 1E-6); |
133 |
DefineOptionalParameterWithDefaultValue(UseSolidThermInt, "useSolidThermInt", false); |
134 |
DefineOptionalParameterWithDefaultValue(UseLiquidThermInt, "useLiquidThermInt", false); |
135 |
DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0); |
136 |
DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5); |
137 |
DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.5); |
138 |
DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5); |
139 |
DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0); |
140 |
DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0); |
141 |
|
142 |
} |
143 |
|
144 |
int Globals::globalAssign( event* the_event ){ |
145 |
|
146 |
int key; |
147 |
interface_assign_type the_type = the_event->evt.asmt.asmt_type; |
148 |
char* lhs = the_event->evt.asmt.lhs; |
149 |
std::string keyword(lhs); |
150 |
|
151 |
bool result = false; |
152 |
|
153 |
ParamMap::iterator i =parameters_.find(keyword); |
154 |
if (i != parameters_.end()) { |
155 |
if( the_type == STRING ){ |
156 |
result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval)); |
157 |
if (!result ) { |
158 |
sprintf(the_event->err_msg, "Error in parsing %s: expect %s, but get %s.\n", keyword.c_str(), i->second->getParamType(), the_event->evt.asmt.rhs.sval); |
159 |
} |
160 |
} else if( the_type == DOUBLE ){ |
161 |
result = i->second->setData(the_event->evt.asmt.rhs.dval); |
162 |
if (!result ) |
163 |
sprintf(the_event->err_msg, "Error in parsing %s: expect %s, but get %f.\n", keyword.c_str(), i->second->getParamType(), the_event->evt.asmt.rhs.dval ); |
164 |
} |
165 |
else if (the_type == INT ){ |
166 |
result = i->second->setData(the_event->evt.asmt.rhs.ival); |
167 |
if (!result ) |
168 |
sprintf(the_event->err_msg, "Error in parsing %s: expect %s, but get %d.\n", keyword.c_str(), i->second->getParamType(), the_event->evt.asmt.rhs.ival ); |
169 |
|
170 |
} else { |
171 |
sprintf(the_event->err_msg, "%s is an unrecognized keyword\n", keyword.c_str() ); |
172 |
} |
173 |
} |
174 |
|
175 |
if (keyword == "nComponents" && getNComponents() > 0) { |
176 |
components = new Component*[getNComponents()]; |
177 |
}else if (keyword == "nZconstraints" && getNZconstraints() > 0) { |
178 |
zConstraints = new ZconStamp*[getNZconstraints()]; |
179 |
} |
180 |
|
181 |
return result; |
182 |
} |
183 |
|
184 |
int Globals::newComponent( event* the_event ){ |
185 |
|
186 |
current_component = new Component; |
187 |
int index = the_event->evt.blk_index; |
188 |
char err[200]; |
189 |
|
190 |
if( haveNComponents() && index < getNComponents() ) |
191 |
components[index] = current_component; |
192 |
else{ |
193 |
if( haveNComponents() ){ |
194 |
sprintf( err, "meta-data parsing error: %d out of nComponents range", |
195 |
index ); |
196 |
the_event->err_msg = strdup( err ); |
197 |
return 0; |
198 |
} |
199 |
else{ |
200 |
the_event->err_msg = strdup("meta-data parsing error: nComponents not given before" |
201 |
" first component declaration." ); |
202 |
return 0; |
203 |
} |
204 |
} |
205 |
|
206 |
return 1; |
207 |
} |
208 |
|
209 |
|
210 |
|
211 |
int Globals::componentAssign( event* the_event ){ |
212 |
|
213 |
switch( the_event->evt.asmt.asmt_type ){ |
214 |
|
215 |
case STRING: |
216 |
return current_component->assignString( the_event->evt.asmt.lhs, |
217 |
the_event->evt.asmt.rhs.sval, |
218 |
&(the_event->err_msg)); |
219 |
break; |
220 |
|
221 |
case DOUBLE: |
222 |
return current_component->assignDouble( the_event->evt.asmt.lhs, |
223 |
the_event->evt.asmt.rhs.dval, |
224 |
&(the_event->err_msg)); |
225 |
break; |
226 |
|
227 |
case INT: |
228 |
return current_component->assignInt( the_event->evt.asmt.lhs, |
229 |
the_event->evt.asmt.rhs.ival, |
230 |
&(the_event->err_msg)); |
231 |
break; |
232 |
|
233 |
default: |
234 |
the_event->err_msg = strdup( "Globals error. Invalid component" |
235 |
" assignment type" ); |
236 |
return 0; |
237 |
break; |
238 |
} |
239 |
return 0; |
240 |
} |
241 |
|
242 |
int Globals::componentEnd( event* the_event ){ |
243 |
|
244 |
the_event->err_msg = current_component->checkMe(); |
245 |
if( the_event->err_msg != NULL ) return 0; |
246 |
|
247 |
return 1; |
248 |
} |
249 |
|
250 |
int Globals::newZconstraint( event* the_event ){ |
251 |
|
252 |
|
253 |
int index = the_event->evt.blk_index; |
254 |
char err[200]; |
255 |
current_zConstraint = new ZconStamp( index ); |
256 |
|
257 |
if( haveNZconstraints() && index < getNZconstraints() ) |
258 |
zConstraints[index] = current_zConstraint; |
259 |
else{ |
260 |
if( haveNZconstraints() ){ |
261 |
sprintf( err, "meta-data parsing error: %d out of nZconstraints range", |
262 |
index ); |
263 |
the_event->err_msg = strdup( err ); |
264 |
return 0; |
265 |
} |
266 |
else{ |
267 |
the_event->err_msg = strdup("meta-data parsing error: nZconstraints" |
268 |
" not given before" |
269 |
" first zConstraint declaration." ); |
270 |
return 0; |
271 |
} |
272 |
} |
273 |
|
274 |
return 1; |
275 |
} |
276 |
|
277 |
|
278 |
|
279 |
int Globals::zConstraintAssign( event* the_event ){ |
280 |
|
281 |
switch( the_event->evt.asmt.asmt_type ){ |
282 |
|
283 |
case STRING: |
284 |
return current_zConstraint->assignString( the_event->evt.asmt.lhs, |
285 |
the_event->evt.asmt.rhs.sval, |
286 |
&(the_event->err_msg)); |
287 |
break; |
288 |
|
289 |
case DOUBLE: |
290 |
return current_zConstraint->assignDouble( the_event->evt.asmt.lhs, |
291 |
the_event->evt.asmt.rhs.dval, |
292 |
&(the_event->err_msg)); |
293 |
break; |
294 |
|
295 |
case INT: |
296 |
return current_zConstraint->assignInt( the_event->evt.asmt.lhs, |
297 |
the_event->evt.asmt.rhs.ival, |
298 |
&(the_event->err_msg)); |
299 |
break; |
300 |
|
301 |
default: |
302 |
the_event->err_msg = strdup( "Globals error. Invalid zConstraint" |
303 |
" assignment type" ); |
304 |
return 0; |
305 |
break; |
306 |
} |
307 |
return 0; |
308 |
} |
309 |
|
310 |
int Globals::zConstraintEnd( event* the_event ){ |
311 |
|
312 |
the_event->err_msg = current_zConstraint->checkMe(); |
313 |
if( the_event->err_msg != NULL ) return 0; |
314 |
|
315 |
return 1; |
316 |
} |
317 |
|
318 |
char* Globals::checkMe( void ){ |
319 |
|
320 |
|
321 |
std::string err("The following required keywords are missing:\n"); |
322 |
short int have_err = 0; |
323 |
|
324 |
ParamMap::iterator i; |
325 |
for (i = parameters_.begin(); i != parameters_.end(); ++i) { |
326 |
if (!i->second->isOptional() && i->second->empty()) { |
327 |
err += i->second->getKeyword() + "\n"; |
328 |
} |
329 |
} |
330 |
|
331 |
CheckParameter(ForceField, isNotEmpty()); |
332 |
CheckParameter(NComponents,isPositive()); |
333 |
CheckParameter(TargetTemp, isPositive()); |
334 |
CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || isEqualIgnoreCase(std::string("NVT")) || |
335 |
isEqualIgnoreCase(std::string("NPTi")) || isEqualIgnoreCase(std::string("NPTf"))|| |
336 |
isEqualIgnoreCase(std::string("NPTxyz")) ); |
337 |
|
338 |
CheckParameter(Dt, isPositive()); |
339 |
CheckParameter(RunTime, isPositive()); |
340 |
CheckParameter(InitialConfig, isNotEmpty()); |
341 |
CheckParameter(FinalConfig, isNotEmpty()); |
342 |
CheckParameter(NMol, isPositive()); |
343 |
CheckParameter(Density, isPositive()); |
344 |
CheckParameter(Box, isPositive()); |
345 |
CheckParameter(BoxX, isPositive()); |
346 |
CheckParameter(BoxY, isPositive()); |
347 |
CheckParameter(BoxZ, isPositive()); |
348 |
CheckParameter(SampleTime, isNonNegative()); |
349 |
CheckParameter(ResetTime, isNonNegative()); |
350 |
CheckParameter(StatusTime, isNonNegative()); |
351 |
CheckParameter(CutoffRadius, isPositive()); |
352 |
CheckParameter(SwitchingRadius, isNonNegative()); |
353 |
CheckParameter(Dielectric, isPositive()); |
354 |
CheckParameter(ThermalTime, isNonNegative()); |
355 |
CheckParameter(TargetPressure, isPositive()); |
356 |
CheckParameter(TauThermostat, isPositive()); |
357 |
CheckParameter(TauBarostat, isPositive()); |
358 |
CheckParameter(ZconsTime, isPositive()); |
359 |
CheckParameter(NZconstraints, isPositive()); |
360 |
CheckParameter(ZconsTol, isPositive()); |
361 |
//CheckParameter(ZconsForcePolicy,); |
362 |
CheckParameter(Seed, isPositive()); |
363 |
CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || isEqualIgnoreCase(std::string("CG"))); |
364 |
CheckParameter(MinimizerMaxIter, isPositive()); |
365 |
CheckParameter(MinimizerWriteFrq, isPositive()); |
366 |
CheckParameter(MinimizerStepSize, isPositive()); |
367 |
CheckParameter(MinimizerFTol, isPositive()); |
368 |
CheckParameter(MinimizerGTol, isPositive()); |
369 |
CheckParameter(MinimizerLSTol, isPositive()); |
370 |
CheckParameter(MinimizerLSMaxIter, isPositive()); |
371 |
CheckParameter(ZconsGap, isPositive()); |
372 |
CheckParameter(ZconsFixtime, isPositive()); |
373 |
CheckParameter(ThermodynamicIntegrationLambda, isPositive()); |
374 |
CheckParameter(ThermodynamicIntegrationK, isPositive()); |
375 |
CheckParameter(ForceFieldVariant, isNotEmpty()); |
376 |
CheckParameter(ForceFieldFileName, isNotEmpty()); |
377 |
CheckParameter(ThermIntDistSpringConst, isPositive()); |
378 |
CheckParameter(ThermIntThetaSpringConst, isPositive()); |
379 |
CheckParameter(ThermIntOmegaSpringConst, isPositive()); |
380 |
CheckParameter(SurfaceTension, isPositive()); |
381 |
CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("UNDAMPED_WOLF")) || isEqualIgnoreCase(std::string("DAMPED_WOLF")) || isEqualIgnoreCase(std::string("REACTION_FIELD")) ); |
382 |
CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || isEqualIgnoreCase(std::string("MAX")) || isEqualIgnoreCase(std::string("TRADITIONAL"))); |
383 |
//CheckParameter(StatFileFormat,); |
384 |
//CheckParameter(MixingRule,); |
385 |
CheckParameter(OrthoBoxTolerance, isPositive()); |
386 |
CheckParameter(ThermIntDistSpringConst, isPositive()); |
387 |
CheckParameter(ThermIntThetaSpringConst, isPositive()); |
388 |
CheckParameter(ThermIntOmegaSpringConst, isPositive()); |
389 |
CheckParameter(DampingAlpha,isPositive()); |
390 |
CheckParameter(SkinThickness, isPositive()); |
391 |
|
392 |
//@todo memory leak |
393 |
if( have_err ) |
394 |
return strdup( err.c_str() ); |
395 |
|
396 |
return NULL; |
397 |
|
398 |
|
399 |
} |
400 |
|
401 |
int Globals::globalEnd( event* the_event ){ |
402 |
|
403 |
the_event->err_msg = checkMe(); |
404 |
if( the_event->err_msg != NULL ) return 0; |
405 |
|
406 |
return 1; |
407 |
} |