ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/io/Globals.cpp
(Generate patch)

Comparing trunk/src/io/Globals.cpp (file contents):
Revision 665 by tim, Thu Oct 13 22:26:47 2005 UTC vs.
Revision 748 by chuckv, Wed Nov 16 21:37:45 2005 UTC

# Line 50 | Line 50
50   #include "io/mpiBASS.h"
51   #endif // is_mpi
52  
53 + #include "io/ParamConstraint.hpp"
54  
54 #define DefineParameter(NAME,KEYWORD)                              \
55  NAME.setKeyword(KEYWORD);                  \
56  parameters_.insert(std::make_pair(std::string(KEYWORD),  &NAME));
55  
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
56   Globals::Globals(){
57  
58    DefineParameter(ForceField, "forceField")
# Line 117 | Line 107 | Globals::Globals(){
107    DefineOptionalParameter(SurfaceTension, "surfaceTension");
108    DefineOptionalParameter(PrintPressureTensor, "printPressureTensor");
109    DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod");
110 +  DefineOptionalParameter(ElectrostaticScreeningMethod, "electrostaticScreeningMethod");
111    DefineOptionalParameter(CutoffPolicy, "cutoffPolicy");
112 <  DefineOptionalParameter(StatFileFormat, "statFileFormat");    
122 <  
112 >  DefineOptionalParameter(SwitchingFunctionType, "switchingFunctionType");
113    DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard");
114    DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true);
115    DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false);
# Line 127 | Line 117 | Globals::Globals(){
117    DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, "orthoBoxTolerance", 1E-6);  
118    DefineOptionalParameterWithDefaultValue(UseSolidThermInt, "useSolidThermInt", false);
119    DefineOptionalParameterWithDefaultValue(UseLiquidThermInt, "useLiquidThermInt", false);
120 <  DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5);
120 >  DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0);
121 >  DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5);
122 >  DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.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;
139  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) {
# Line 322 | Line 324 | char* Globals::checkMe( void ){
324      }
325    }
326  
327 +  CheckParameter(ForceField, isNotEmpty());
328 +  CheckParameter(NComponents,isPositive());
329 +  CheckParameter(TargetTemp, isPositive());
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());
338 +  CheckParameter(FinalConfig, isNotEmpty());
339 +  CheckParameter(NMol, isPositive());
340 +  CheckParameter(Density, isPositive());
341 +  CheckParameter(Box, isPositive());
342 +  CheckParameter(BoxX, isPositive());
343 +  CheckParameter(BoxY, isPositive());
344 +  CheckParameter(BoxZ, isPositive());
345 +  CheckParameter(SampleTime, isNonNegative());
346 +  CheckParameter(ResetTime, isNonNegative());
347 +  CheckParameter(StatusTime, isNonNegative());
348 +  CheckParameter(CutoffRadius, isPositive());
349 +  CheckParameter(SwitchingRadius, isNonNegative());
350 +  CheckParameter(Dielectric, isPositive());
351 +  CheckParameter(ThermalTime,  isNonNegative());
352 +  CheckParameter(TargetPressure,  isPositive());
353 +  CheckParameter(TauThermostat, isPositive());
354 +  CheckParameter(TauBarostat, isPositive());
355 +  CheckParameter(ZconsTime, isPositive());
356 +  CheckParameter(NZconstraints, isPositive());  
357 +  CheckParameter(ZconsTol, isPositive());
358 +  //CheckParameter(ZconsForcePolicy,);
359 +  CheckParameter(Seed, isPositive());
360 +  CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) ||
361 +                 isEqualIgnoreCase(std::string("CG")));
362 +  CheckParameter(MinimizerMaxIter, isPositive());
363 +  CheckParameter(MinimizerWriteFrq, isPositive());
364 +  CheckParameter(MinimizerStepSize, isPositive());
365 +  CheckParameter(MinimizerFTol, isPositive());
366 +  CheckParameter(MinimizerGTol, isPositive());
367 +  CheckParameter(MinimizerLSTol, isPositive());
368 +  CheckParameter(MinimizerLSMaxIter, isPositive());
369 +  CheckParameter(ZconsGap, isPositive());
370 +  CheckParameter(ZconsFixtime, isPositive());
371 +  CheckParameter(ThermodynamicIntegrationLambda, isPositive());
372 +  CheckParameter(ThermodynamicIntegrationK, isPositive());
373 +  CheckParameter(ForceFieldVariant, isNotEmpty());
374 +  CheckParameter(ForceFieldFileName, isNotEmpty());
375 +  CheckParameter(ThermIntDistSpringConst, isPositive());
376 +  CheckParameter(ThermIntThetaSpringConst, isPositive());
377 +  CheckParameter(ThermIntOmegaSpringConst, isPositive());
378 +  CheckParameter(SurfaceTension, isPositive());
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,isNonNegative());
400 +  CheckParameter(SkinThickness, isPositive());
401 +  
402    //@todo memory leak
403    if( have_err )
404      return strdup( err.c_str() );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines