--- trunk/src/io/Globals.cpp 2005/10/13 22:26:47 665 +++ trunk/src/io/Globals.cpp 2005/11/16 23:10:02 749 @@ -50,19 +50,10 @@ #include "io/mpiBASS.h" #endif // is_mpi +#include "io/ParamConstraint.hpp" -#define DefineParameter(NAME,KEYWORD) \ - NAME.setKeyword(KEYWORD); \ - parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); +using namespace oopse; -#define DefineOptionalParameter(NAME,KEYWORD) \ - NAME.setKeyword(KEYWORD); NAME.setOptional(true); \ - parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); - -#define DefineOptionalParameterWithDefaultValue(NAME,KEYWORD, DEFAULTVALUE) \ - NAME.setKeyword(KEYWORD); NAME.setOptional(true); NAME.setDefaultValue(DEFAULTVALUE); \ - parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); - Globals::Globals(){ DefineParameter(ForceField, "forceField") @@ -117,9 +108,9 @@ Globals::Globals(){ DefineOptionalParameter(SurfaceTension, "surfaceTension"); DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); + DefineOptionalParameter(ElectrostaticScreeningMethod, "electrostaticScreeningMethod"); DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); - DefineOptionalParameter(StatFileFormat, "statFileFormat"); - + DefineOptionalParameter(SwitchingFunctionType, "switchingFunctionType"); DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false); @@ -127,43 +118,69 @@ Globals::Globals(){ DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, "orthoBoxTolerance", 1E-6); DefineOptionalParameterWithDefaultValue(UseSolidThermInt, "useSolidThermInt", false); DefineOptionalParameterWithDefaultValue(UseLiquidThermInt, "useLiquidThermInt", false); - DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5); + DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0); + DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5); + DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.5); + DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 0.2); DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0); + DefineOptionalParameterWithDefaultValue(OutputForceVector, "outputForceVector", 0); DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0); + DefineOptionalParameterWithDefaultValue(StatFileFormat, "statFileFormat", "TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|PRESSURE|VOLUME|CONSERVED_QUANTITY"); + } -int Globals::globalAssign( event* the_event ){ +Globals::~Globals(){ + int i; + if( components != NULL ){ + for( i=0; i< getNComponents(); i++ ) delete components[i]; + delete[] components; + } + + if( zConstraints != NULL ){ + for( i=0; i< getNZconstraints(); i++ ) delete zConstraints[i]; + delete[] zConstraints; + } +} + +int Globals::globalAssign( event* the_event ){ + char errorMessage[65535]; int key; - int token; interface_assign_type the_type = the_event->evt.asmt.asmt_type; char* lhs = the_event->evt.asmt.lhs; std::string keyword(lhs); - bool result; + bool result = false; - + /**@todo fix memory leak */ ParamMap::iterator i =parameters_.find(keyword); if (i != parameters_.end()) { if( the_type == STRING ){ result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval)); if (!result ) { - sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a string.\n", keyword.c_str() ); + 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); + the_event->err_msg = strdup(errorMessage); } } else if( the_type == DOUBLE ){ result = i->second->setData(the_event->evt.asmt.rhs.dval); if (!result ) - sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a double.\n", keyword.c_str() ); + 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 ); + the_event->err_msg = strdup(errorMessage); } else if (the_type == INT ){ result = i->second->setData(the_event->evt.asmt.rhs.ival); if (!result ) - sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be an int.\n", keyword.c_str() ); + 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 ); + the_event->err_msg = strdup(errorMessage); } else { - + sprintf(errorMessage, "Internal error of parser\n"); + the_event->err_msg = strdup(errorMessage); } + } else { + sprintf(errorMessage, "%s is an unrecognized keyword\n", keyword.c_str() ); + the_event->err_msg = strdup(errorMessage); } if (keyword == "nComponents" && getNComponents() > 0) { @@ -322,6 +339,81 @@ char* Globals::checkMe( void ){ } } + CheckParameter(ForceField, isNotEmpty()); + CheckParameter(NComponents,isPositive()); + CheckParameter(TargetTemp, isPositive()); + CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || + isEqualIgnoreCase(std::string("NVT")) || + isEqualIgnoreCase(std::string("NPTi")) || + isEqualIgnoreCase(std::string("NPTf")) || + isEqualIgnoreCase(std::string("NPTxyz")) ); + CheckParameter(Dt, isPositive()); + CheckParameter(RunTime, isPositive()); + CheckParameter(InitialConfig, isNotEmpty()); + CheckParameter(FinalConfig, isNotEmpty()); + CheckParameter(NMol, isPositive()); + CheckParameter(Density, isPositive()); + CheckParameter(Box, isPositive()); + CheckParameter(BoxX, isPositive()); + CheckParameter(BoxY, isPositive()); + CheckParameter(BoxZ, isPositive()); + CheckParameter(SampleTime, isNonNegative()); + CheckParameter(ResetTime, isNonNegative()); + CheckParameter(StatusTime, isNonNegative()); + CheckParameter(CutoffRadius, isPositive()); + CheckParameter(SwitchingRadius, isNonNegative()); + CheckParameter(Dielectric, isPositive()); + CheckParameter(ThermalTime, isNonNegative()); + CheckParameter(TargetPressure, isPositive()); + CheckParameter(TauThermostat, isPositive()); + CheckParameter(TauBarostat, isPositive()); + CheckParameter(ZconsTime, isPositive()); + CheckParameter(NZconstraints, isPositive()); + CheckParameter(ZconsTol, isPositive()); + //CheckParameter(ZconsForcePolicy,); + CheckParameter(Seed, isPositive()); + CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || + isEqualIgnoreCase(std::string("CG"))); + CheckParameter(MinimizerMaxIter, isPositive()); + CheckParameter(MinimizerWriteFrq, isPositive()); + CheckParameter(MinimizerStepSize, isPositive()); + CheckParameter(MinimizerFTol, isPositive()); + CheckParameter(MinimizerGTol, isPositive()); + CheckParameter(MinimizerLSTol, isPositive()); + CheckParameter(MinimizerLSMaxIter, isPositive()); + CheckParameter(ZconsGap, isPositive()); + CheckParameter(ZconsFixtime, isPositive()); + CheckParameter(ThermodynamicIntegrationLambda, isPositive()); + CheckParameter(ThermodynamicIntegrationK, isPositive()); + CheckParameter(ForceFieldVariant, isNotEmpty()); + CheckParameter(ForceFieldFileName, isNotEmpty()); + CheckParameter(ThermIntDistSpringConst, isPositive()); + CheckParameter(ThermIntThetaSpringConst, isPositive()); + CheckParameter(ThermIntOmegaSpringConst, isPositive()); + CheckParameter(SurfaceTension, isPositive()); + CheckParameter(ElectrostaticSummationMethod, + isEqualIgnoreCase(std::string("NONE")) || + isEqualIgnoreCase(std::string("SHIFTED_POTENTIAL")) || + isEqualIgnoreCase(std::string("SHIFTED_FORCE")) || + isEqualIgnoreCase(std::string("REACTION_FIELD"))); + CheckParameter(ElectrostaticScreeningMethod, + isEqualIgnoreCase(std::string("UNDAMPED")) || + isEqualIgnoreCase(std::string("DAMPED"))); + CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || + isEqualIgnoreCase(std::string("MAX")) || + isEqualIgnoreCase(std::string("TRADITIONAL"))); + CheckParameter(SwitchingFunctionType, + isEqualIgnoreCase(std::string("CUBIC")) || + isEqualIgnoreCase(std::string("FIFTH_ORDER_POLYNOMIAL"))); + //CheckParameter(StatFileFormat,); + //CheckParameter(MixingRule,); + CheckParameter(OrthoBoxTolerance, isPositive()); + CheckParameter(ThermIntDistSpringConst, isPositive()); + CheckParameter(ThermIntThetaSpringConst, isPositive()); + CheckParameter(ThermIntOmegaSpringConst, isPositive()); + CheckParameter(DampingAlpha,isNonNegative()); + CheckParameter(SkinThickness, isPositive()); + //@todo memory leak if( have_err ) return strdup( err.c_str() );