# | Line 50 | Line 50 | |
---|---|---|
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); \ | |
# | Line 63 | Line 64 | |
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") | |
# | Line 117 | Line 121 | Globals::Globals(){ | |
121 | DefineOptionalParameter(SurfaceTension, "surfaceTension"); | |
122 | DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); | |
123 | DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); | |
124 | + | DefineOptionalParameter(ElectrostaticScreeningMethod, "electrostaticScreeningMethod"); |
125 | DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); | |
126 | < | DefineOptionalParameter(StatFileFormat, "statFileFormat"); |
122 | < | |
126 | > | DefineOptionalParameter(SwitchingFunctionType, "switchingFunctionType"); |
127 | DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); | |
128 | DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); | |
129 | DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false); | |
# | Line 127 | Line 131 | Globals::Globals(){ | |
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(OutputForceVector, "outputForceVector", 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) { | |
# | Line 322 | Line 338 | char* Globals::checkMe( void ){ | |
338 | } | |
339 | } | |
340 | ||
341 | + | CheckParameter(ForceField, isNotEmpty()); |
342 | + | CheckParameter(NComponents,isPositive()); |
343 | + | CheckParameter(TargetTemp, isPositive()); |
344 | + | CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || |
345 | + | isEqualIgnoreCase(std::string("NVT")) || |
346 | + | isEqualIgnoreCase(std::string("NPTi")) || |
347 | + | isEqualIgnoreCase(std::string("NPTf")) || |
348 | + | isEqualIgnoreCase(std::string("NPTxyz")) ); |
349 | + | CheckParameter(Dt, isPositive()); |
350 | + | CheckParameter(RunTime, isPositive()); |
351 | + | CheckParameter(InitialConfig, isNotEmpty()); |
352 | + | CheckParameter(FinalConfig, isNotEmpty()); |
353 | + | CheckParameter(NMol, isPositive()); |
354 | + | CheckParameter(Density, isPositive()); |
355 | + | CheckParameter(Box, isPositive()); |
356 | + | CheckParameter(BoxX, isPositive()); |
357 | + | CheckParameter(BoxY, isPositive()); |
358 | + | CheckParameter(BoxZ, isPositive()); |
359 | + | CheckParameter(SampleTime, isNonNegative()); |
360 | + | CheckParameter(ResetTime, isNonNegative()); |
361 | + | CheckParameter(StatusTime, isNonNegative()); |
362 | + | CheckParameter(CutoffRadius, isPositive()); |
363 | + | CheckParameter(SwitchingRadius, isNonNegative()); |
364 | + | CheckParameter(Dielectric, isPositive()); |
365 | + | CheckParameter(ThermalTime, isNonNegative()); |
366 | + | CheckParameter(TargetPressure, isPositive()); |
367 | + | CheckParameter(TauThermostat, isPositive()); |
368 | + | CheckParameter(TauBarostat, isPositive()); |
369 | + | CheckParameter(ZconsTime, isPositive()); |
370 | + | CheckParameter(NZconstraints, isPositive()); |
371 | + | CheckParameter(ZconsTol, isPositive()); |
372 | + | //CheckParameter(ZconsForcePolicy,); |
373 | + | CheckParameter(Seed, isPositive()); |
374 | + | CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || |
375 | + | isEqualIgnoreCase(std::string("CG"))); |
376 | + | CheckParameter(MinimizerMaxIter, isPositive()); |
377 | + | CheckParameter(MinimizerWriteFrq, isPositive()); |
378 | + | CheckParameter(MinimizerStepSize, isPositive()); |
379 | + | CheckParameter(MinimizerFTol, isPositive()); |
380 | + | CheckParameter(MinimizerGTol, isPositive()); |
381 | + | CheckParameter(MinimizerLSTol, isPositive()); |
382 | + | CheckParameter(MinimizerLSMaxIter, isPositive()); |
383 | + | CheckParameter(ZconsGap, isPositive()); |
384 | + | CheckParameter(ZconsFixtime, isPositive()); |
385 | + | CheckParameter(ThermodynamicIntegrationLambda, isPositive()); |
386 | + | CheckParameter(ThermodynamicIntegrationK, isPositive()); |
387 | + | CheckParameter(ForceFieldVariant, isNotEmpty()); |
388 | + | CheckParameter(ForceFieldFileName, isNotEmpty()); |
389 | + | CheckParameter(ThermIntDistSpringConst, isPositive()); |
390 | + | CheckParameter(ThermIntThetaSpringConst, isPositive()); |
391 | + | CheckParameter(ThermIntOmegaSpringConst, isPositive()); |
392 | + | CheckParameter(SurfaceTension, isPositive()); |
393 | + | CheckParameter(ElectrostaticSummationMethod, |
394 | + | isEqualIgnoreCase(std::string("NONE")) || |
395 | + | isEqualIgnoreCase(std::string("SHIFTED_POTENTIAL")) || |
396 | + | isEqualIgnoreCase(std::string("SHIFTED_FORCE")) || |
397 | + | isEqualIgnoreCase(std::string("REACTION_FIELD"))); |
398 | + | CheckParameter(ElectrostaticScreeningMethod, |
399 | + | isEqualIgnoreCase(std::string("UNDAMPED")) || |
400 | + | isEqualIgnoreCase(std::string("DAMPED"))); |
401 | + | CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || |
402 | + | isEqualIgnoreCase(std::string("MAX")) || |
403 | + | isEqualIgnoreCase(std::string("TRADITIONAL"))); |
404 | + | CheckParameter(SwitchingFunctionType, |
405 | + | isEqualIgnoreCase(std::string("CUBIC")) || |
406 | + | isEqualIgnoreCase(std::string("FIFTH_ORDER_POLYNOMIAL"))); |
407 | + | //CheckParameter(StatFileFormat,); |
408 | + | //CheckParameter(MixingRule,); |
409 | + | CheckParameter(OrthoBoxTolerance, isPositive()); |
410 | + | CheckParameter(ThermIntDistSpringConst, isPositive()); |
411 | + | CheckParameter(ThermIntThetaSpringConst, isPositive()); |
412 | + | CheckParameter(ThermIntOmegaSpringConst, isPositive()); |
413 | + | CheckParameter(DampingAlpha,isNonNegative()); |
414 | + | CheckParameter(SkinThickness, isPositive()); |
415 | + | |
416 | //@todo memory leak | |
417 | if( have_err ) | |
418 | return strdup( err.c_str() ); |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |