# | Line 52 | Line 52 | |
---|---|---|
52 | ||
53 | #include "io/ParamConstraint.hpp" | |
54 | ||
55 | < | #define DefineParameter(NAME,KEYWORD) \ |
56 | < | NAME.setKeyword(KEYWORD); \ |
57 | < | parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
55 | > | using namespace oopse; |
56 | ||
59 | – | #define DefineOptionalParameter(NAME,KEYWORD) \ |
60 | – | NAME.setKeyword(KEYWORD); NAME.setOptional(true); \ |
61 | – | parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
62 | – | |
63 | – | #define DefineOptionalParameterWithDefaultValue(NAME,KEYWORD, DEFAULTVALUE) \ |
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())) std::cout <<"Error in parsing " << NAME.getKeyword() << " : "<< (CONSTRAINT).getConstraintDescription() << std::endl; } |
69 | – | |
70 | – | |
57 | Globals::Globals(){ | |
58 | ||
59 | DefineParameter(ForceField, "forceField") | |
# | Line 122 | Line 108 | Globals::Globals(){ | |
108 | DefineOptionalParameter(SurfaceTension, "surfaceTension"); | |
109 | DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); | |
110 | DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); | |
111 | + | DefineOptionalParameter(ElectrostaticScreeningMethod, "electrostaticScreeningMethod"); |
112 | DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); | |
113 | < | DefineOptionalParameter(StatFileFormat, "statFileFormat"); |
127 | < | |
113 | > | DefineOptionalParameter(SwitchingFunctionType, "switchingFunctionType"); |
114 | DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); | |
115 | DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); | |
116 | DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false); | |
# | Line 135 | Line 121 | Globals::Globals(){ | |
121 | DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0); | |
122 | DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5); | |
123 | DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.5); | |
124 | < | DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5); |
124 | > | DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 0.2); |
125 | DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0); | |
126 | + | DefineOptionalParameterWithDefaultValue(OutputForceVector, "outputForceVector", 0); |
127 | DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0); | |
128 | + | DefineOptionalParameterWithDefaultValue(StatFileFormat, "statFileFormat", "TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|PRESSURE|VOLUME|CONSERVED_QUANTITY"); |
129 | + | |
130 | ||
131 | } | |
132 | ||
133 | < | int Globals::globalAssign( event* the_event ){ |
133 | > | Globals::~Globals(){ |
134 | > | int i; |
135 | > | if( components != NULL ){ |
136 | > | for( i=0; i< getNComponents(); i++ ) delete components[i]; |
137 | > | delete[] components; |
138 | > | } |
139 | ||
140 | + | if( zConstraints != NULL ){ |
141 | + | for( i=0; i< getNZconstraints(); i++ ) delete zConstraints[i]; |
142 | + | delete[] zConstraints; |
143 | + | } |
144 | + | |
145 | + | } |
146 | + | |
147 | + | int Globals::globalAssign( event* the_event ){ |
148 | + | char errorMessage[65535]; |
149 | int key; | |
147 | – | int token; |
150 | interface_assign_type the_type = the_event->evt.asmt.asmt_type; | |
151 | char* lhs = the_event->evt.asmt.lhs; | |
152 | std::string keyword(lhs); | |
153 | ||
154 | < | bool result; |
154 | > | bool result = false; |
155 | ||
156 | < | |
156 | > | /**@todo fix memory leak */ |
157 | ParamMap::iterator i =parameters_.find(keyword); | |
158 | if (i != parameters_.end()) { | |
159 | if( the_type == STRING ){ | |
160 | result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval)); | |
161 | if (!result ) { | |
162 | < | sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a string.\n", keyword.c_str() ); |
162 | > | 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); |
163 | > | the_event->err_msg = strdup(errorMessage); |
164 | } | |
165 | } else if( the_type == DOUBLE ){ | |
166 | result = i->second->setData(the_event->evt.asmt.rhs.dval); | |
167 | if (!result ) | |
168 | < | sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a double.\n", keyword.c_str() ); |
168 | > | 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 ); |
169 | > | the_event->err_msg = strdup(errorMessage); |
170 | } | |
171 | else if (the_type == INT ){ | |
172 | result = i->second->setData(the_event->evt.asmt.rhs.ival); | |
173 | if (!result ) | |
174 | < | sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be an int.\n", keyword.c_str() ); |
174 | > | 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 ); |
175 | > | the_event->err_msg = strdup(errorMessage); |
176 | ||
177 | } else { | |
178 | < | |
178 | > | sprintf(errorMessage, "Internal error of parser\n"); |
179 | > | the_event->err_msg = strdup(errorMessage); |
180 | } | |
181 | + | } else { |
182 | + | sprintf(errorMessage, "%s is an unrecognized keyword\n", keyword.c_str() ); |
183 | + | the_event->err_msg = strdup(errorMessage); |
184 | } | |
185 | ||
186 | if (keyword == "nComponents" && getNComponents() > 0) { | |
# | Line 333 | Line 342 | char* Globals::checkMe( void ){ | |
342 | CheckParameter(ForceField, isNotEmpty()); | |
343 | CheckParameter(NComponents,isPositive()); | |
344 | CheckParameter(TargetTemp, isPositive()); | |
345 | < | CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || isEqualIgnoreCase(std::string("NVT")) || |
337 | < | isEqualIgnoreCase(std::string("NPTi")) || isEqualIgnoreCase(std::string("NPTf"))|| |
338 | < | isEqualIgnoreCase(std::string("NPTxyz")) ); |
339 | < | |
345 | > | CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || isEqualIgnoreCase(std::string("NVT")) || isEqualIgnoreCase(std::string("NPTi")) || isEqualIgnoreCase(std::string("NPTf")) || isEqualIgnoreCase(std::string("NPTxyz")) ); |
346 | CheckParameter(Dt, isPositive()); | |
347 | CheckParameter(RunTime, isPositive()); | |
348 | CheckParameter(InitialConfig, isNotEmpty()); | |
# | Line 380 | Line 386 | char* Globals::checkMe( void ){ | |
386 | CheckParameter(ThermIntThetaSpringConst, isPositive()); | |
387 | CheckParameter(ThermIntOmegaSpringConst, isPositive()); | |
388 | CheckParameter(SurfaceTension, isPositive()); | |
389 | < | CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("UNDAMPED_WOLF")) || isEqualIgnoreCase(std::string("DAMPED_WOLF")) || isEqualIgnoreCase(std::string("REACTION_FIELD")) ); |
389 | > | CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("SHIFTED_POTENTIAL")) || isEqualIgnoreCase(std::string("SHIFTED_FORCE")) || isEqualIgnoreCase(std::string("REACTION_FIELD"))); |
390 | > | CheckParameter(ElectrostaticScreeningMethod, isEqualIgnoreCase(std::string("UNDAMPED")) || isEqualIgnoreCase(std::string("DAMPED"))); |
391 | CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || isEqualIgnoreCase(std::string("MAX")) || isEqualIgnoreCase(std::string("TRADITIONAL"))); | |
392 | + | CheckParameter(SwitchingFunctionType, isEqualIgnoreCase(std::string("CUBIC")) || 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,isPositive()); |
399 | > | CheckParameter(DampingAlpha,isNonNegative()); |
400 | CheckParameter(SkinThickness, isPositive()); | |
401 | ||
402 | //@todo memory leak |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |