--- trunk/src/io/Globals.cpp 2005/10/13 22:26:47 665 +++ trunk/src/io/Globals.cpp 2006/01/12 14:31:33 850 @@ -45,28 +45,13 @@ #include #include "io/Globals.hpp" +#include "io/ParamConstraint.hpp" +#include "utils/MemoryUtils.hpp" #include "utils/simError.h" -#ifdef IS_MPI -#include "io/mpiBASS.h" -#endif // is_mpi - -#define DefineParameter(NAME,KEYWORD) \ - NAME.setKeyword(KEYWORD); \ - parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); - -#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(){ - +namespace oopse { +Globals::Globals() { DefineParameter(ForceField, "forceField") - DefineParameter(NComponents, "nComponents") DefineOptionalParameter(TargetTemp, "targetTemp"); DefineOptionalParameter(Ensemble, "ensemble"); @@ -74,12 +59,6 @@ Globals::Globals(){ DefineOptionalParameter(RunTime, "runTime"); DefineOptionalParameter(InitialConfig, "initialConfig"); DefineOptionalParameter(FinalConfig, "finalConfig"); - DefineOptionalParameter(NMol, "nMol"); - DefineOptionalParameter(Density, "density"); - DefineOptionalParameter(Box, "box"); - DefineOptionalParameter(BoxX, "boxX"); - DefineOptionalParameter(BoxY, "boxY"); - DefineOptionalParameter(BoxZ, "boxZ"); DefineOptionalParameter(SampleTime, "sampleTime"); DefineOptionalParameter(ResetTime, "resetTime"); DefineOptionalParameter(StatusTime, "statusTime"); @@ -92,7 +71,6 @@ Globals::Globals(){ DefineOptionalParameter(TauThermostat, "tauThermostat"); DefineOptionalParameter(TauBarostat, "tauBarostat"); DefineOptionalParameter(ZconsTime, "zconsTime"); - DefineOptionalParameter(NZconstraints, "nZconstraints"); DefineOptionalParameter(ZconsTol, "zconsTol"); DefineOptionalParameter(ZconsForcePolicy, "zconsForcePolicy"); DefineOptionalParameter(Seed, "seed"); @@ -117,9 +95,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,214 +105,114 @@ 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 ){ - - 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; - - - 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() ); - } - } 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() ); - } - 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() ); - - } else { + deprecatedKeywords_.insert("nComponents"); + deprecatedKeywords_.insert("nZconstraints"); - } - } - - if (keyword == "nComponents" && getNComponents() > 0) { - components = new Component*[getNComponents()]; - }else if (keyword == "nZconstraints" && getNZconstraints() > 0) { - zConstraints = new ZconStamp*[getNZconstraints()]; - } - - return result; } -int Globals::newComponent( event* the_event ){ - - current_component = new Component; - int index = the_event->evt.blk_index; - char err[200]; - - if( haveNComponents() && index < getNComponents() ) - components[index] = current_component; - else{ - if( haveNComponents() ){ - sprintf( err, "meta-data parsing error: %d out of nComponents range", - index ); - the_event->err_msg = strdup( err ); - return 0; - } - else{ - the_event->err_msg = strdup("meta-data parsing error: nComponents not given before" - " first component declaration." ); - return 0; - } - } - - return 1; -} - - - -int Globals::componentAssign( event* the_event ){ - - switch( the_event->evt.asmt.asmt_type ){ - - case STRING: - return current_component->assignString( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.sval, - &(the_event->err_msg)); - break; - - case DOUBLE: - return current_component->assignDouble( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.dval, - &(the_event->err_msg)); - break; - - case INT: - return current_component->assignInt( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.ival, - &(the_event->err_msg)); - break; - - default: - the_event->err_msg = strdup( "Globals error. Invalid component" - " assignment type" ); - return 0; - break; - } - return 0; -} - -int Globals::componentEnd( event* the_event ){ - - the_event->err_msg = current_component->checkMe(); - if( the_event->err_msg != NULL ) return 0; - - return 1; -} - -int Globals::newZconstraint( event* the_event ){ - - - int index = the_event->evt.blk_index; - char err[200]; - current_zConstraint = new ZconStamp( index ); - - if( haveNZconstraints() && index < getNZconstraints() ) - zConstraints[index] = current_zConstraint; - else{ - if( haveNZconstraints() ){ - sprintf( err, "meta-data parsing error: %d out of nZconstraints range", - index ); - the_event->err_msg = strdup( err ); - return 0; - } - else{ - the_event->err_msg = strdup("meta-data parsing error: nZconstraints" - " not given before" - " first zConstraint declaration." ); - return 0; - } - } - - return 1; +Globals::~Globals() { + MemoryUtils::deletePointers(components_); + MemoryUtils::deletePointers(zconstraints_); } +void Globals::validate() { + DataHolder::validate(); + CheckParameter(ForceField, isNotEmpty()); + CheckParameter(TargetTemp, isPositive()); + CheckParameter(Ensemble, isEqualIgnoreCase("NVE") || isEqualIgnoreCase("NVT") || isEqualIgnoreCase("NPTi") || isEqualIgnoreCase("NPTf") || isEqualIgnoreCase("NPTxyz") ); + CheckParameter(Dt, isPositive()); + CheckParameter(RunTime, isPositive()); + CheckParameter(InitialConfig, isNotEmpty()); + CheckParameter(FinalConfig, isNotEmpty()); + 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(ZconsTol, isPositive()); + CheckParameter(Seed, isPositive()); + CheckParameter(Minimizer, isEqualIgnoreCase("SD") || isEqualIgnoreCase("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("NONE") || isEqualIgnoreCase("SHIFTED_POTENTIAL") || isEqualIgnoreCase("SHIFTED_FORCE") || isEqualIgnoreCase("REACTION_FIELD")); + CheckParameter(ElectrostaticScreeningMethod, isEqualIgnoreCase("UNDAMPED") || isEqualIgnoreCase("DAMPED")); + CheckParameter(CutoffPolicy, isEqualIgnoreCase("MIX") || isEqualIgnoreCase("MAX") || isEqualIgnoreCase("TRADITIONAL")); + CheckParameter(SwitchingFunctionType, isEqualIgnoreCase("CUBIC") || isEqualIgnoreCase("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()); -int Globals::zConstraintAssign( event* the_event ){ - - switch( the_event->evt.asmt.asmt_type ){ - - case STRING: - return current_zConstraint->assignString( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.sval, - &(the_event->err_msg)); - break; - - case DOUBLE: - return current_zConstraint->assignDouble( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.dval, - &(the_event->err_msg)); - break; - - case INT: - return current_zConstraint->assignInt( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.ival, - &(the_event->err_msg)); - break; - - default: - the_event->err_msg = strdup( "Globals error. Invalid zConstraint" - " assignment type" ); - return 0; - break; + for(std::vector::iterator i = components_.begin(); i != components_.end(); ++i) { + if (!(*i)->findMoleculeStamp(moleculeStamps_)) { + std::ostringstream oss; + oss << "Globals Error: can not find molecule stamp for component " << (*i)->getType() << std::endl; + throw OOPSEException(oss.str()); + } } - return 0; } + +bool Globals::addComponent(Component* comp) { + components_.push_back(comp); + return true; +} -int Globals::zConstraintEnd( event* the_event ){ - - the_event->err_msg = current_zConstraint->checkMe(); - if( the_event->err_msg != NULL ) return 0; - - return 1; +bool Globals::addZConsStamp(ZConsStamp* zcons) { + zconstraints_.push_back(zcons); + return true; } -char* Globals::checkMe( void ){ - - - std::string err("The following required keywords are missing:\n"); - short int have_err = 0; - - ParamMap::iterator i; - for (i = parameters_.begin(); i != parameters_.end(); ++i) { - if (!i->second->isOptional() && i->second->empty()) { - err += i->second->getKeyword() + "\n"; +bool Globals::addMoleculeStamp(MoleculeStamp* molStamp) { + std::string molStampName = molStamp->getName(); + std::map::iterator i; + bool ret = false; + i = moleculeStamps_.find(molStampName); + if (i == moleculeStamps_.end()) { + moleculeStamps_.insert(std::map::value_type(molStampName, molStamp)); + ret = true; + } else { + std::ostringstream oss; + oss << "Globals Error: Molecule Stamp " << molStamp->getName() << "appears multiple times\n"; + throw OOPSEException(oss.str()); } - } - - //@todo memory leak - if( have_err ) - return strdup( err.c_str() ); - - return NULL; - - + return ret; } + -int Globals::globalEnd( event* the_event ){ - - the_event->err_msg = checkMe(); - if( the_event->err_msg != NULL ) return 0; - - return 1; }