50 |
|
#include "io/mpiBASS.h" |
51 |
|
#endif // is_mpi |
52 |
|
|
53 |
+ |
#include "io/ParamConstraint.hpp" |
54 |
|
|
55 |
< |
#define DefineParameter(NAME,KEYWORD) \ |
55 |
< |
NAME.setKeyword(KEYWORD); \ |
56 |
< |
parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); |
55 |
> |
using namespace oopse; |
56 |
|
|
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 |
– |
|
57 |
|
Globals::Globals(){ |
58 |
|
|
59 |
|
DefineParameter(ForceField, "forceField") |
108 |
|
DefineOptionalParameter(SurfaceTension, "surfaceTension"); |
109 |
|
DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); |
110 |
|
DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); |
111 |
+ |
DefineOptionalParameter(ElectrostaticScreeningMethod, "electrostaticScreeningMethod"); |
112 |
|
DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); |
113 |
< |
DefineOptionalParameter(StatFileFormat, "statFileFormat"); |
122 |
< |
|
113 |
> |
DefineOptionalParameter(SwitchingFunctionType, "switchingFunctionType"); |
114 |
|
DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); |
115 |
|
DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); |
116 |
|
DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false); |
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; |
142 |
– |
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) { |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
+ |
CheckParameter(ForceField, isNotEmpty()); |
343 |
+ |
CheckParameter(NComponents,isPositive()); |
344 |
+ |
CheckParameter(TargetTemp, isPositive()); |
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()); |
349 |
+ |
CheckParameter(FinalConfig, isNotEmpty()); |
350 |
+ |
CheckParameter(NMol, isPositive()); |
351 |
+ |
CheckParameter(Density, isPositive()); |
352 |
+ |
CheckParameter(Box, isPositive()); |
353 |
+ |
CheckParameter(BoxX, isPositive()); |
354 |
+ |
CheckParameter(BoxY, isPositive()); |
355 |
+ |
CheckParameter(BoxZ, isPositive()); |
356 |
+ |
CheckParameter(SampleTime, isNonNegative()); |
357 |
+ |
CheckParameter(ResetTime, isNonNegative()); |
358 |
+ |
CheckParameter(StatusTime, isNonNegative()); |
359 |
+ |
CheckParameter(CutoffRadius, isPositive()); |
360 |
+ |
CheckParameter(SwitchingRadius, isNonNegative()); |
361 |
+ |
CheckParameter(Dielectric, isPositive()); |
362 |
+ |
CheckParameter(ThermalTime, isNonNegative()); |
363 |
+ |
CheckParameter(TargetPressure, isPositive()); |
364 |
+ |
CheckParameter(TauThermostat, isPositive()); |
365 |
+ |
CheckParameter(TauBarostat, isPositive()); |
366 |
+ |
CheckParameter(ZconsTime, isPositive()); |
367 |
+ |
CheckParameter(NZconstraints, isPositive()); |
368 |
+ |
CheckParameter(ZconsTol, isPositive()); |
369 |
+ |
//CheckParameter(ZconsForcePolicy,); |
370 |
+ |
CheckParameter(Seed, isPositive()); |
371 |
+ |
CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || isEqualIgnoreCase(std::string("CG"))); |
372 |
+ |
CheckParameter(MinimizerMaxIter, isPositive()); |
373 |
+ |
CheckParameter(MinimizerWriteFrq, isPositive()); |
374 |
+ |
CheckParameter(MinimizerStepSize, isPositive()); |
375 |
+ |
CheckParameter(MinimizerFTol, isPositive()); |
376 |
+ |
CheckParameter(MinimizerGTol, isPositive()); |
377 |
+ |
CheckParameter(MinimizerLSTol, isPositive()); |
378 |
+ |
CheckParameter(MinimizerLSMaxIter, isPositive()); |
379 |
+ |
CheckParameter(ZconsGap, isPositive()); |
380 |
+ |
CheckParameter(ZconsFixtime, isPositive()); |
381 |
+ |
CheckParameter(ThermodynamicIntegrationLambda, isPositive()); |
382 |
+ |
CheckParameter(ThermodynamicIntegrationK, isPositive()); |
383 |
+ |
CheckParameter(ForceFieldVariant, isNotEmpty()); |
384 |
+ |
CheckParameter(ForceFieldFileName, isNotEmpty()); |
385 |
+ |
CheckParameter(ThermIntDistSpringConst, isPositive()); |
386 |
+ |
CheckParameter(ThermIntThetaSpringConst, isPositive()); |
387 |
+ |
CheckParameter(ThermIntOmegaSpringConst, isPositive()); |
388 |
+ |
CheckParameter(SurfaceTension, isPositive()); |
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,isNonNegative()); |
400 |
+ |
CheckParameter(SkinThickness, isPositive()); |
401 |
+ |
|
402 |
|
//@todo memory leak |
403 |
|
if( have_err ) |
404 |
|
return strdup( err.c_str() ); |