ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/io/Globals.cpp
Revision: 2371
Committed: Fri Oct 14 21:43:13 2005 UTC (18 years, 8 months ago) by tim
File size: 15964 byte(s)
Log Message:
Constraints for parameters are working now

File Contents

# User Rev Content
1 gezelter 2088 /*
2 gezelter 1930 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9     * 1. Acknowledgement of the program authors must be made in any
10     * publication of scientific results based in part on use of the
11     * program. An acceptable form of acknowledgement is citation of
12     * the article in which the program was described (Matthew
13     * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14     * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15     * Parallel Simulation Engine for Molecular Dynamics,"
16     * J. Comput. Chem. 26, pp. 252-271 (2005))
17     *
18     * 2. Redistributions of source code must retain the above copyright
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41    
42 gezelter 1490 #include <stdlib.h>
43     #include <stdio.h>
44     #include <string.h>
45 tim 2364 #include <string>
46 gezelter 1490
47 tim 1492 #include "io/Globals.hpp"
48     #include "utils/simError.h"
49 gezelter 1490 #ifdef IS_MPI
50 tim 1492 #include "io/mpiBASS.h"
51 gezelter 1490 #endif // is_mpi
52    
53 tim 2371 #include "io/ParamConstraint.hpp"
54 gezelter 1490
55 tim 2364 #define DefineParameter(NAME,KEYWORD) \
56     NAME.setKeyword(KEYWORD); \
57     parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME));
58 gezelter 1490
59 tim 2364 #define DefineOptionalParameter(NAME,KEYWORD) \
60     NAME.setKeyword(KEYWORD); NAME.setOptional(true); \
61     parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME));
62 chrisfen 2101
63 tim 2364 #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 tim 2371 #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    
71 gezelter 1490 Globals::Globals(){
72 tim 2364
73     DefineParameter(ForceField, "forceField")
74     DefineParameter(NComponents, "nComponents")
75    
76     DefineOptionalParameter(TargetTemp, "targetTemp");
77     DefineOptionalParameter(Ensemble, "ensemble");
78     DefineOptionalParameter(Dt, "dt");
79     DefineOptionalParameter(RunTime, "runTime");
80     DefineOptionalParameter(InitialConfig, "initialConfig");
81     DefineOptionalParameter(FinalConfig, "finalConfig");
82     DefineOptionalParameter(NMol, "nMol");
83     DefineOptionalParameter(Density, "density");
84     DefineOptionalParameter(Box, "box");
85     DefineOptionalParameter(BoxX, "boxX");
86     DefineOptionalParameter(BoxY, "boxY");
87     DefineOptionalParameter(BoxZ, "boxZ");
88     DefineOptionalParameter(SampleTime, "sampleTime");
89     DefineOptionalParameter(ResetTime, "resetTime");
90     DefineOptionalParameter(StatusTime, "statusTime");
91     DefineOptionalParameter(CutoffRadius, "cutoffRadius");
92     DefineOptionalParameter(SwitchingRadius, "switchingRadius");
93     DefineOptionalParameter(Dielectric, "dielectric");
94     DefineOptionalParameter(TempSet, "tempSet");
95     DefineOptionalParameter(ThermalTime, "thermalTime");
96     DefineOptionalParameter(TargetPressure, "targetPressure");
97     DefineOptionalParameter(TauThermostat, "tauThermostat");
98     DefineOptionalParameter(TauBarostat, "tauBarostat");
99     DefineOptionalParameter(ZconsTime, "zconsTime");
100     DefineOptionalParameter(NZconstraints, "nZconstraints");
101     DefineOptionalParameter(ZconsTol, "zconsTol");
102     DefineOptionalParameter(ZconsForcePolicy, "zconsForcePolicy");
103     DefineOptionalParameter(Seed, "seed");
104     DefineOptionalParameter(Minimizer, "minimizer");
105     DefineOptionalParameter(MinimizerMaxIter,"minimizerMaxIter");
106     DefineOptionalParameter(MinimizerWriteFrq, "minimizerWriteFrq");
107     DefineOptionalParameter(MinimizerStepSize, "minimizerStepSize");
108     DefineOptionalParameter(MinimizerFTol, "minimizerFTol");
109     DefineOptionalParameter(MinimizerGTol, "minimizerGTol");
110     DefineOptionalParameter(MinimizerLSTol, "minimizerLSTol");
111     DefineOptionalParameter(MinimizerLSMaxIter, "minimizerLSMaxIter");
112     DefineOptionalParameter(ZconsGap, "zconsGap");
113     DefineOptionalParameter(ZconsFixtime, "zconsFixtime");
114     DefineOptionalParameter(ZconsUsingSMD, "zconsUsingSMD");
115     DefineOptionalParameter(ThermodynamicIntegrationLambda, "thermodynamicIntegrationLambda");
116     DefineOptionalParameter(ThermodynamicIntegrationK, "thermodynamicIntegrationK");
117     DefineOptionalParameter(ForceFieldVariant, "forceFieldVariant");
118     DefineOptionalParameter(ForceFieldFileName, "forceFieldFileName");
119     DefineOptionalParameter(ThermIntDistSpringConst, "thermIntDistSpringConst");
120     DefineOptionalParameter(ThermIntThetaSpringConst, "thermIntThetaSpringConst");
121     DefineOptionalParameter(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst");
122     DefineOptionalParameter(SurfaceTension, "surfaceTension");
123     DefineOptionalParameter(PrintPressureTensor, "printPressureTensor");
124     DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod");
125     DefineOptionalParameter(CutoffPolicy, "cutoffPolicy");
126     DefineOptionalParameter(StatFileFormat, "statFileFormat");
127    
128     DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard");
129     DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true);
130     DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false);
131     DefineOptionalParameterWithDefaultValue(UseIntialExtendedSystemState, "useInitialExtendedSystemState", false);
132     DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, "orthoBoxTolerance", 1E-6);
133     DefineOptionalParameterWithDefaultValue(UseSolidThermInt, "useSolidThermInt", false);
134     DefineOptionalParameterWithDefaultValue(UseLiquidThermInt, "useLiquidThermInt", false);
135 chrisfen 2365 DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0);
136     DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5);
137     DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.5);
138 tim 2364 DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5);
139     DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0);
140     DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0);
141    
142 gezelter 1490 }
143    
144 tim 2364 int Globals::globalAssign( event* the_event ){
145 gezelter 1490
146 tim 2364 int key;
147     int token;
148     interface_assign_type the_type = the_event->evt.asmt.asmt_type;
149     char* lhs = the_event->evt.asmt.lhs;
150     std::string keyword(lhs);
151 chrisfen 2101
152 tim 2364 bool result;
153 gezelter 1490
154 tim 2364
155     ParamMap::iterator i =parameters_.find(keyword);
156     if (i != parameters_.end()) {
157     if( the_type == STRING ){
158     result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval));
159     if (!result ) {
160     sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a string.\n", keyword.c_str() );
161     }
162     } else if( the_type == DOUBLE ){
163     result = i->second->setData(the_event->evt.asmt.rhs.dval);
164     if (!result )
165     sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a double.\n", keyword.c_str() );
166     }
167     else if (the_type == INT ){
168     result = i->second->setData(the_event->evt.asmt.rhs.ival);
169     if (!result )
170     sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be an int.\n", keyword.c_str() );
171    
172     } else {
173    
174     }
175     }
176    
177     if (keyword == "nComponents" && getNComponents() > 0) {
178     components = new Component*[getNComponents()];
179     }else if (keyword == "nZconstraints" && getNZconstraints() > 0) {
180     zConstraints = new ZconStamp*[getNZconstraints()];
181     }
182 gezelter 1490
183 tim 2364 return result;
184 gezelter 1490 }
185    
186     int Globals::newComponent( event* the_event ){
187    
188     current_component = new Component;
189     int index = the_event->evt.blk_index;
190     char err[200];
191    
192 tim 2364 if( haveNComponents() && index < getNComponents() )
193 gezelter 1490 components[index] = current_component;
194     else{
195 tim 2364 if( haveNComponents() ){
196 gezelter 1490 sprintf( err, "meta-data parsing error: %d out of nComponents range",
197     index );
198     the_event->err_msg = strdup( err );
199     return 0;
200     }
201     else{
202     the_event->err_msg = strdup("meta-data parsing error: nComponents not given before"
203     " first component declaration." );
204     return 0;
205     }
206     }
207    
208     return 1;
209     }
210    
211    
212    
213     int Globals::componentAssign( event* the_event ){
214    
215     switch( the_event->evt.asmt.asmt_type ){
216    
217     case STRING:
218     return current_component->assignString( the_event->evt.asmt.lhs,
219     the_event->evt.asmt.rhs.sval,
220     &(the_event->err_msg));
221     break;
222    
223     case DOUBLE:
224     return current_component->assignDouble( the_event->evt.asmt.lhs,
225     the_event->evt.asmt.rhs.dval,
226     &(the_event->err_msg));
227     break;
228    
229     case INT:
230     return current_component->assignInt( the_event->evt.asmt.lhs,
231     the_event->evt.asmt.rhs.ival,
232     &(the_event->err_msg));
233     break;
234    
235     default:
236     the_event->err_msg = strdup( "Globals error. Invalid component"
237     " assignment type" );
238     return 0;
239     break;
240     }
241     return 0;
242     }
243    
244     int Globals::componentEnd( event* the_event ){
245    
246     the_event->err_msg = current_component->checkMe();
247     if( the_event->err_msg != NULL ) return 0;
248    
249     return 1;
250     }
251    
252     int Globals::newZconstraint( event* the_event ){
253    
254    
255     int index = the_event->evt.blk_index;
256     char err[200];
257     current_zConstraint = new ZconStamp( index );
258    
259 tim 2364 if( haveNZconstraints() && index < getNZconstraints() )
260 gezelter 1490 zConstraints[index] = current_zConstraint;
261     else{
262 tim 2364 if( haveNZconstraints() ){
263 gezelter 1490 sprintf( err, "meta-data parsing error: %d out of nZconstraints range",
264     index );
265     the_event->err_msg = strdup( err );
266     return 0;
267     }
268     else{
269     the_event->err_msg = strdup("meta-data parsing error: nZconstraints"
270     " not given before"
271     " first zConstraint declaration." );
272     return 0;
273     }
274     }
275 tim 2364
276 gezelter 1490 return 1;
277     }
278    
279    
280    
281     int Globals::zConstraintAssign( event* the_event ){
282    
283     switch( the_event->evt.asmt.asmt_type ){
284    
285     case STRING:
286     return current_zConstraint->assignString( the_event->evt.asmt.lhs,
287     the_event->evt.asmt.rhs.sval,
288     &(the_event->err_msg));
289     break;
290    
291     case DOUBLE:
292     return current_zConstraint->assignDouble( the_event->evt.asmt.lhs,
293     the_event->evt.asmt.rhs.dval,
294     &(the_event->err_msg));
295     break;
296    
297     case INT:
298     return current_zConstraint->assignInt( the_event->evt.asmt.lhs,
299     the_event->evt.asmt.rhs.ival,
300     &(the_event->err_msg));
301     break;
302    
303     default:
304     the_event->err_msg = strdup( "Globals error. Invalid zConstraint"
305     " assignment type" );
306     return 0;
307     break;
308     }
309     return 0;
310     }
311    
312     int Globals::zConstraintEnd( event* the_event ){
313    
314     the_event->err_msg = current_zConstraint->checkMe();
315     if( the_event->err_msg != NULL ) return 0;
316    
317     return 1;
318     }
319    
320 tim 2364 char* Globals::checkMe( void ){
321 tim 2109
322 gezelter 1490
323 tim 2364 std::string err("The following required keywords are missing:\n");
324     short int have_err = 0;
325 gezelter 1490
326 tim 2364 ParamMap::iterator i;
327     for (i = parameters_.begin(); i != parameters_.end(); ++i) {
328     if (!i->second->isOptional() && i->second->empty()) {
329     err += i->second->getKeyword() + "\n";
330 gezelter 1490 }
331     }
332    
333 tim 2371 CheckParameter(ForceField, isNotEmpty());
334     CheckParameter(NComponents,isPositive());
335     CheckParameter(TargetTemp, isPositive());
336     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    
340     CheckParameter(Dt, isPositive());
341     CheckParameter(RunTime, isPositive());
342     CheckParameter(InitialConfig, isNotEmpty());
343     CheckParameter(FinalConfig, isNotEmpty());
344     CheckParameter(NMol, isPositive());
345     CheckParameter(Density, isPositive());
346     CheckParameter(Box, isPositive());
347     CheckParameter(BoxX, isPositive());
348     CheckParameter(BoxY, isPositive());
349     CheckParameter(BoxZ, isPositive());
350     CheckParameter(SampleTime, isNonNegative());
351     CheckParameter(ResetTime, isNonNegative());
352     CheckParameter(StatusTime, isNonNegative());
353     CheckParameter(CutoffRadius, isPositive());
354     CheckParameter(SwitchingRadius, isNonNegative());
355     CheckParameter(Dielectric, isPositive());
356     CheckParameter(ThermalTime, isNonNegative());
357     CheckParameter(TargetPressure, isPositive());
358     CheckParameter(TauThermostat, isPositive());
359     CheckParameter(TauBarostat, isPositive());
360     CheckParameter(ZconsTime, isPositive());
361     CheckParameter(NZconstraints, isPositive());
362     CheckParameter(ZconsTol, isPositive());
363     //CheckParameter(ZconsForcePolicy,);
364     CheckParameter(Seed, isPositive());
365     CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || isEqualIgnoreCase(std::string("CG")));
366     CheckParameter(MinimizerMaxIter, isPositive());
367     CheckParameter(MinimizerWriteFrq, isPositive());
368     CheckParameter(MinimizerStepSize, isPositive());
369     CheckParameter(MinimizerFTol, isPositive());
370     CheckParameter(MinimizerGTol, isPositive());
371     CheckParameter(MinimizerLSTol, isPositive());
372     CheckParameter(MinimizerLSMaxIter, isPositive());
373     CheckParameter(ZconsGap, isPositive());
374     CheckParameter(ZconsFixtime, isPositive());
375     CheckParameter(ThermodynamicIntegrationLambda, isPositive());
376     CheckParameter(ThermodynamicIntegrationK, isPositive());
377     CheckParameter(ForceFieldVariant, isNotEmpty());
378     CheckParameter(ForceFieldFileName, isNotEmpty());
379     CheckParameter(ThermIntDistSpringConst, isPositive());
380     CheckParameter(ThermIntThetaSpringConst, isPositive());
381     CheckParameter(ThermIntOmegaSpringConst, isPositive());
382     CheckParameter(SurfaceTension, isPositive());
383     CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("UNDAMPED_WOLF")) || isEqualIgnoreCase(std::string("DAMPED_WOLF")) || isEqualIgnoreCase(std::string("REACTION_FIELD")) );
384     CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || isEqualIgnoreCase(std::string("MAX")) || isEqualIgnoreCase(std::string("TRADITIONAL")));
385     //CheckParameter(StatFileFormat,);
386     //CheckParameter(MixingRule,);
387     CheckParameter(OrthoBoxTolerance, isPositive());
388     CheckParameter(ThermIntDistSpringConst, isPositive());
389     CheckParameter(ThermIntThetaSpringConst, isPositive());
390     CheckParameter(ThermIntOmegaSpringConst, isPositive());
391     CheckParameter(DampingAlpha,isPositive());
392     CheckParameter(SkinThickness, isPositive());
393    
394 tim 2364 //@todo memory leak
395     if( have_err )
396     return strdup( err.c_str() );
397 gezelter 1490
398 tim 2364 return NULL;
399 gezelter 1490
400    
401     }
402    
403     int Globals::globalEnd( event* the_event ){
404    
405     the_event->err_msg = checkMe();
406     if( the_event->err_msg != NULL ) return 0;
407    
408     return 1;
409     }