| 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);                  \ | 
| 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())) { sprintf(painCave.errMsg,"Error in checking %s : should be %s\n",NAME.getKeyword().c_str(),(CONSTRAINT).getConstraintDescription().c_str()); painCave.isFatal = 1; painCave.severity = OOPSE_ERROR; simError();} } | 
| 69 | + |  | 
| 70 |  | Globals::Globals(){ | 
| 71 |  |  | 
| 72 |  | DefineParameter(ForceField, "forceField") | 
| 121 |  | DefineOptionalParameter(SurfaceTension, "surfaceTension"); | 
| 122 |  | DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); | 
| 123 |  | DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); | 
| 124 | + | DefineOptionalParameter(ElectrostaticScreeningMethod, "electrostaticScreeningMethod"); | 
| 125 |  | DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); | 
| 121 | – | DefineOptionalParameter(StatFileFormat, "statFileFormat"); | 
| 126 |  |  | 
| 127 |  | DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); | 
| 128 |  | DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); | 
| 131 |  | DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, "orthoBoxTolerance", 1E-6); | 
| 132 |  | DefineOptionalParameterWithDefaultValue(UseSolidThermInt, "useSolidThermInt", false); | 
| 133 |  | DefineOptionalParameterWithDefaultValue(UseLiquidThermInt, "useLiquidThermInt", false); | 
| 134 | < | DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5); | 
| 134 | > | DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0); | 
| 135 | > | DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5); | 
| 136 | > | DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.5); | 
| 137 | > | DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 0.2); | 
| 138 |  | DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0); | 
| 139 | + | DefineOptionalParameterWithDefaultValue(DumpForceVector, "dumpForceVector", 0); | 
| 140 |  | DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0); | 
| 141 | + | DefineOptionalParameterWithDefaultValue(StatFileFormat, "statFileFormat", "TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|PRESSURE|VOLUME|CONSERVED_QUANTITY"); | 
| 142 | + |  | 
| 143 |  |  | 
| 144 |  | } | 
| 145 |  |  | 
| 146 |  | int Globals::globalAssign( event* the_event ){ | 
| 147 | < |  | 
| 147 | > | char errorMessage[65535]; | 
| 148 |  | int key; | 
| 139 | – | int token; | 
| 149 |  | interface_assign_type the_type =  the_event->evt.asmt.asmt_type; | 
| 150 |  | char* lhs = the_event->evt.asmt.lhs; | 
| 151 |  | std::string keyword(lhs); | 
| 152 |  |  | 
| 153 | < | bool result; | 
| 153 | > | bool result = false; | 
| 154 |  |  | 
| 155 | < |  | 
| 155 | > | /**@todo fix memory leak */ | 
| 156 |  | ParamMap::iterator i =parameters_.find(keyword); | 
| 157 |  | if (i != parameters_.end()) { | 
| 158 |  | if( the_type == STRING ){ | 
| 159 |  | result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval)); | 
| 160 |  | if (!result ) { | 
| 161 | < | sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a string.\n", keyword.c_str() ); | 
| 161 | > | 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); | 
| 162 | > | the_event->err_msg = strdup(errorMessage); | 
| 163 |  | } | 
| 164 |  | } else if( the_type == DOUBLE ){ | 
| 165 |  | result = i->second->setData(the_event->evt.asmt.rhs.dval); | 
| 166 |  | if (!result ) | 
| 167 | < | sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a double.\n", keyword.c_str() ); | 
| 167 | > | 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 ); | 
| 168 | > | the_event->err_msg = strdup(errorMessage); | 
| 169 |  | } | 
| 170 |  | else if (the_type == INT ){ | 
| 171 |  | result = i->second->setData(the_event->evt.asmt.rhs.ival); | 
| 172 |  | if (!result ) | 
| 173 | < | sprintf(the_event->err_msg,  "Error in parsing meta-data file!\n\t%s must be an int.\n", keyword.c_str() ); | 
| 173 | > | 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 ); | 
| 174 | > | the_event->err_msg = strdup(errorMessage); | 
| 175 |  |  | 
| 176 |  | } else { | 
| 177 | < |  | 
| 177 | > | sprintf(errorMessage,  "Internal error of parser\n"); | 
| 178 | > | the_event->err_msg = strdup(errorMessage); | 
| 179 |  | } | 
| 180 | + | } else { | 
| 181 | + | sprintf(errorMessage,  "%s is an unrecognized keyword\n", keyword.c_str() ); | 
| 182 | + | the_event->err_msg = strdup(errorMessage); | 
| 183 |  | } | 
| 184 |  |  | 
| 185 |  | if (keyword == "nComponents" && getNComponents() > 0) { | 
| 338 |  | } | 
| 339 |  | } | 
| 340 |  |  | 
| 341 | + | CheckParameter(ForceField, isNotEmpty()); | 
| 342 | + | CheckParameter(NComponents,isPositive()); | 
| 343 | + | CheckParameter(TargetTemp, isPositive()); | 
| 344 | + | CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || isEqualIgnoreCase(std::string("NVT")) || | 
| 345 | + | isEqualIgnoreCase(std::string("NPTi")) || isEqualIgnoreCase(std::string("NPTf"))|| | 
| 346 | + | isEqualIgnoreCase(std::string("NPTxyz")) ); | 
| 347 | + | CheckParameter(Dt, isPositive()); | 
| 348 | + | CheckParameter(RunTime, isPositive()); | 
| 349 | + | CheckParameter(InitialConfig, isNotEmpty()); | 
| 350 | + | CheckParameter(FinalConfig, isNotEmpty()); | 
| 351 | + | CheckParameter(NMol, isPositive()); | 
| 352 | + | CheckParameter(Density, isPositive()); | 
| 353 | + | CheckParameter(Box, isPositive()); | 
| 354 | + | CheckParameter(BoxX, isPositive()); | 
| 355 | + | CheckParameter(BoxY, isPositive()); | 
| 356 | + | CheckParameter(BoxZ, isPositive()); | 
| 357 | + | CheckParameter(SampleTime, isNonNegative()); | 
| 358 | + | CheckParameter(ResetTime, isNonNegative()); | 
| 359 | + | CheckParameter(StatusTime, isNonNegative()); | 
| 360 | + | CheckParameter(CutoffRadius, isPositive()); | 
| 361 | + | CheckParameter(SwitchingRadius, isNonNegative()); | 
| 362 | + | CheckParameter(Dielectric, isPositive()); | 
| 363 | + | CheckParameter(ThermalTime,  isNonNegative()); | 
| 364 | + | CheckParameter(TargetPressure,  isPositive()); | 
| 365 | + | CheckParameter(TauThermostat, isPositive()); | 
| 366 | + | CheckParameter(TauBarostat, isPositive()); | 
| 367 | + | CheckParameter(ZconsTime, isPositive()); | 
| 368 | + | CheckParameter(NZconstraints, isPositive()); | 
| 369 | + | CheckParameter(ZconsTol, isPositive()); | 
| 370 | + | //CheckParameter(ZconsForcePolicy,); | 
| 371 | + | CheckParameter(Seed, isPositive()); | 
| 372 | + | CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || isEqualIgnoreCase(std::string("CG"))); | 
| 373 | + | CheckParameter(MinimizerMaxIter, isPositive()); | 
| 374 | + | CheckParameter(MinimizerWriteFrq, isPositive()); | 
| 375 | + | CheckParameter(MinimizerStepSize, isPositive()); | 
| 376 | + | CheckParameter(MinimizerFTol, isPositive()); | 
| 377 | + | CheckParameter(MinimizerGTol, isPositive()); | 
| 378 | + | CheckParameter(MinimizerLSTol, isPositive()); | 
| 379 | + | CheckParameter(MinimizerLSMaxIter, isPositive()); | 
| 380 | + | CheckParameter(ZconsGap, isPositive()); | 
| 381 | + | CheckParameter(ZconsFixtime, isPositive()); | 
| 382 | + | CheckParameter(ThermodynamicIntegrationLambda, isPositive()); | 
| 383 | + | CheckParameter(ThermodynamicIntegrationK, isPositive()); | 
| 384 | + | CheckParameter(ForceFieldVariant, isNotEmpty()); | 
| 385 | + | CheckParameter(ForceFieldFileName, isNotEmpty()); | 
| 386 | + | CheckParameter(ThermIntDistSpringConst, isPositive()); | 
| 387 | + | CheckParameter(ThermIntThetaSpringConst, isPositive()); | 
| 388 | + | CheckParameter(ThermIntOmegaSpringConst, isPositive()); | 
| 389 | + | CheckParameter(SurfaceTension, isPositive()); | 
| 390 | + | CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("SHIFTED_POTENTIAL")) || isEqualIgnoreCase(std::string("SHIFTED_FORCE"))  || isEqualIgnoreCase(std::string("REACTION_FIELD"))); | 
| 391 | + | CheckParameter(ElectrostaticScreeningMethod, isEqualIgnoreCase(std::string("UNDAMPED")) || isEqualIgnoreCase(std::string("DAMPED"))); | 
| 392 | + | CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || isEqualIgnoreCase(std::string("MAX")) || isEqualIgnoreCase(std::string("TRADITIONAL"))); | 
| 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,isNonNegative()); | 
| 400 | + | CheckParameter(SkinThickness, isPositive()); | 
| 401 | + |  | 
| 402 |  | //@todo memory leak | 
| 403 |  | if( have_err ) | 
| 404 |  | return strdup( err.c_str() ); |