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)); |
55 |
|
|
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 |
– |
|
56 |
|
Globals::Globals(){ |
57 |
|
|
58 |
|
DefineParameter(ForceField, "forceField") |
107 |
|
DefineOptionalParameter(SurfaceTension, "surfaceTension"); |
108 |
|
DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); |
109 |
|
DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); |
110 |
+ |
DefineOptionalParameter(ElectrostaticScreeningMethod, "electrostaticScreeningMethod"); |
111 |
|
DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); |
112 |
< |
DefineOptionalParameter(StatFileFormat, "statFileFormat"); |
127 |
< |
|
112 |
> |
DefineOptionalParameter(SwitchingFunctionType, "switchingFunctionType"); |
113 |
|
DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); |
114 |
|
DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); |
115 |
|
DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false); |
120 |
|
DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0); |
121 |
|
DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5); |
122 |
|
DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.5); |
123 |
< |
DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5); |
123 |
> |
DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 0.2); |
124 |
|
DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0); |
125 |
+ |
DefineOptionalParameterWithDefaultValue(OutputForceVector, "outputForceVector", 0); |
126 |
|
DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0); |
127 |
+ |
DefineOptionalParameterWithDefaultValue(StatFileFormat, "statFileFormat", "TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|PRESSURE|VOLUME|CONSERVED_QUANTITY"); |
128 |
+ |
|
129 |
|
|
130 |
|
} |
131 |
|
|
132 |
|
int Globals::globalAssign( event* the_event ){ |
133 |
< |
|
133 |
> |
char errorMessage[65535]; |
134 |
|
int key; |
147 |
– |
int token; |
135 |
|
interface_assign_type the_type = the_event->evt.asmt.asmt_type; |
136 |
|
char* lhs = the_event->evt.asmt.lhs; |
137 |
|
std::string keyword(lhs); |
138 |
|
|
139 |
< |
bool result; |
139 |
> |
bool result = false; |
140 |
|
|
141 |
< |
|
141 |
> |
/**@todo fix memory leak */ |
142 |
|
ParamMap::iterator i =parameters_.find(keyword); |
143 |
|
if (i != parameters_.end()) { |
144 |
|
if( the_type == STRING ){ |
145 |
|
result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval)); |
146 |
|
if (!result ) { |
147 |
< |
sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a string.\n", keyword.c_str() ); |
147 |
> |
sprintf(errorMessage, "Error in parsing %s: expect %s, but get a string \"%s\".\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.sval); |
148 |
> |
the_event->err_msg = strdup(errorMessage); |
149 |
|
} |
150 |
|
} else if( the_type == DOUBLE ){ |
151 |
|
result = i->second->setData(the_event->evt.asmt.rhs.dval); |
152 |
|
if (!result ) |
153 |
< |
sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a double.\n", keyword.c_str() ); |
153 |
> |
sprintf(errorMessage, "Error in parsing %s: expect %s, but get a double %f.\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.dval ); |
154 |
> |
the_event->err_msg = strdup(errorMessage); |
155 |
|
} |
156 |
|
else if (the_type == INT ){ |
157 |
|
result = i->second->setData(the_event->evt.asmt.rhs.ival); |
158 |
|
if (!result ) |
159 |
< |
sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be an int.\n", keyword.c_str() ); |
159 |
> |
sprintf(errorMessage, "Error in parsing %s: expect %s, but get an int %d.\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.ival ); |
160 |
> |
the_event->err_msg = strdup(errorMessage); |
161 |
|
|
162 |
|
} else { |
163 |
< |
|
163 |
> |
sprintf(errorMessage, "Internal error of parser\n"); |
164 |
> |
the_event->err_msg = strdup(errorMessage); |
165 |
|
} |
166 |
+ |
} else { |
167 |
+ |
sprintf(errorMessage, "%s is an unrecognized keyword\n", keyword.c_str() ); |
168 |
+ |
the_event->err_msg = strdup(errorMessage); |
169 |
|
} |
170 |
|
|
171 |
|
if (keyword == "nComponents" && getNComponents() > 0) { |
327 |
|
CheckParameter(ForceField, isNotEmpty()); |
328 |
|
CheckParameter(NComponents,isPositive()); |
329 |
|
CheckParameter(TargetTemp, isPositive()); |
330 |
< |
CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || isEqualIgnoreCase(std::string("NVT")) || |
331 |
< |
isEqualIgnoreCase(std::string("NPTi")) || isEqualIgnoreCase(std::string("NPTf"))|| |
332 |
< |
isEqualIgnoreCase(std::string("NPTxyz")) ); |
333 |
< |
|
330 |
> |
CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || |
331 |
> |
isEqualIgnoreCase(std::string("NVT")) || |
332 |
> |
isEqualIgnoreCase(std::string("NPTi")) || |
333 |
> |
isEqualIgnoreCase(std::string("NPTf")) || |
334 |
> |
isEqualIgnoreCase(std::string("NPTxyz")) ); |
335 |
|
CheckParameter(Dt, isPositive()); |
336 |
|
CheckParameter(RunTime, isPositive()); |
337 |
|
CheckParameter(InitialConfig, isNotEmpty()); |
357 |
|
CheckParameter(ZconsTol, isPositive()); |
358 |
|
//CheckParameter(ZconsForcePolicy,); |
359 |
|
CheckParameter(Seed, isPositive()); |
360 |
< |
CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || isEqualIgnoreCase(std::string("CG"))); |
360 |
> |
CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || |
361 |
> |
isEqualIgnoreCase(std::string("CG"))); |
362 |
|
CheckParameter(MinimizerMaxIter, isPositive()); |
363 |
|
CheckParameter(MinimizerWriteFrq, isPositive()); |
364 |
|
CheckParameter(MinimizerStepSize, isPositive()); |
376 |
|
CheckParameter(ThermIntThetaSpringConst, isPositive()); |
377 |
|
CheckParameter(ThermIntOmegaSpringConst, isPositive()); |
378 |
|
CheckParameter(SurfaceTension, isPositive()); |
379 |
< |
CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("UNDAMPED_WOLF")) || isEqualIgnoreCase(std::string("DAMPED_WOLF")) || isEqualIgnoreCase(std::string("REACTION_FIELD")) ); |
380 |
< |
CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || isEqualIgnoreCase(std::string("MAX")) || isEqualIgnoreCase(std::string("TRADITIONAL"))); |
379 |
> |
CheckParameter(ElectrostaticSummationMethod, |
380 |
> |
isEqualIgnoreCase(std::string("NONE")) || |
381 |
> |
isEqualIgnoreCase(std::string("SHIFTED_POTENTIAL")) || |
382 |
> |
isEqualIgnoreCase(std::string("SHIFTED_FORCE")) || |
383 |
> |
isEqualIgnoreCase(std::string("REACTION_FIELD"))); |
384 |
> |
CheckParameter(ElectrostaticScreeningMethod, |
385 |
> |
isEqualIgnoreCase(std::string("UNDAMPED")) || |
386 |
> |
isEqualIgnoreCase(std::string("DAMPED"))); |
387 |
> |
CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || |
388 |
> |
isEqualIgnoreCase(std::string("MAX")) || |
389 |
> |
isEqualIgnoreCase(std::string("TRADITIONAL"))); |
390 |
> |
CheckParameter(SwitchingFunctionType, |
391 |
> |
isEqualIgnoreCase(std::string("CUBIC")) || |
392 |
> |
isEqualIgnoreCase(std::string("FIFTH_ORDER_POLYNOMIAL"))); |
393 |
|
//CheckParameter(StatFileFormat,); |
394 |
|
//CheckParameter(MixingRule,); |
395 |
|
CheckParameter(OrthoBoxTolerance, isPositive()); |
396 |
|
CheckParameter(ThermIntDistSpringConst, isPositive()); |
397 |
|
CheckParameter(ThermIntThetaSpringConst, isPositive()); |
398 |
|
CheckParameter(ThermIntOmegaSpringConst, isPositive()); |
399 |
< |
CheckParameter(DampingAlpha,isPositive()); |
399 |
> |
CheckParameter(DampingAlpha,isNonNegative()); |
400 |
|
CheckParameter(SkinThickness, isPositive()); |
401 |
|
|
402 |
|
//@todo memory leak |