ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/Globals.cpp
Revision: 2364
Committed: Thu Oct 13 22:26:47 2005 UTC (18 years, 9 months ago) by tim
File size: 12033 byte(s)
Log Message:
rewrite Globals

File Contents

# Content
1 /*
2 * 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 #include <stdlib.h>
43 #include <stdio.h>
44 #include <string.h>
45 #include <string>
46
47 #include "io/Globals.hpp"
48 #include "utils/simError.h"
49 #ifdef IS_MPI
50 #include "io/mpiBASS.h"
51 #endif // is_mpi
52
53
54 #define DefineParameter(NAME,KEYWORD) \
55 NAME.setKeyword(KEYWORD); \
56 parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME));
57
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
66 Globals::Globals(){
67
68 DefineParameter(ForceField, "forceField")
69 DefineParameter(NComponents, "nComponents")
70
71 DefineOptionalParameter(TargetTemp, "targetTemp");
72 DefineOptionalParameter(Ensemble, "ensemble");
73 DefineOptionalParameter(Dt, "dt");
74 DefineOptionalParameter(RunTime, "runTime");
75 DefineOptionalParameter(InitialConfig, "initialConfig");
76 DefineOptionalParameter(FinalConfig, "finalConfig");
77 DefineOptionalParameter(NMol, "nMol");
78 DefineOptionalParameter(Density, "density");
79 DefineOptionalParameter(Box, "box");
80 DefineOptionalParameter(BoxX, "boxX");
81 DefineOptionalParameter(BoxY, "boxY");
82 DefineOptionalParameter(BoxZ, "boxZ");
83 DefineOptionalParameter(SampleTime, "sampleTime");
84 DefineOptionalParameter(ResetTime, "resetTime");
85 DefineOptionalParameter(StatusTime, "statusTime");
86 DefineOptionalParameter(CutoffRadius, "cutoffRadius");
87 DefineOptionalParameter(SwitchingRadius, "switchingRadius");
88 DefineOptionalParameter(Dielectric, "dielectric");
89 DefineOptionalParameter(TempSet, "tempSet");
90 DefineOptionalParameter(ThermalTime, "thermalTime");
91 DefineOptionalParameter(TargetPressure, "targetPressure");
92 DefineOptionalParameter(TauThermostat, "tauThermostat");
93 DefineOptionalParameter(TauBarostat, "tauBarostat");
94 DefineOptionalParameter(ZconsTime, "zconsTime");
95 DefineOptionalParameter(NZconstraints, "nZconstraints");
96 DefineOptionalParameter(ZconsTol, "zconsTol");
97 DefineOptionalParameter(ZconsForcePolicy, "zconsForcePolicy");
98 DefineOptionalParameter(Seed, "seed");
99 DefineOptionalParameter(Minimizer, "minimizer");
100 DefineOptionalParameter(MinimizerMaxIter,"minimizerMaxIter");
101 DefineOptionalParameter(MinimizerWriteFrq, "minimizerWriteFrq");
102 DefineOptionalParameter(MinimizerStepSize, "minimizerStepSize");
103 DefineOptionalParameter(MinimizerFTol, "minimizerFTol");
104 DefineOptionalParameter(MinimizerGTol, "minimizerGTol");
105 DefineOptionalParameter(MinimizerLSTol, "minimizerLSTol");
106 DefineOptionalParameter(MinimizerLSMaxIter, "minimizerLSMaxIter");
107 DefineOptionalParameter(ZconsGap, "zconsGap");
108 DefineOptionalParameter(ZconsFixtime, "zconsFixtime");
109 DefineOptionalParameter(ZconsUsingSMD, "zconsUsingSMD");
110 DefineOptionalParameter(ThermodynamicIntegrationLambda, "thermodynamicIntegrationLambda");
111 DefineOptionalParameter(ThermodynamicIntegrationK, "thermodynamicIntegrationK");
112 DefineOptionalParameter(ForceFieldVariant, "forceFieldVariant");
113 DefineOptionalParameter(ForceFieldFileName, "forceFieldFileName");
114 DefineOptionalParameter(ThermIntDistSpringConst, "thermIntDistSpringConst");
115 DefineOptionalParameter(ThermIntThetaSpringConst, "thermIntThetaSpringConst");
116 DefineOptionalParameter(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst");
117 DefineOptionalParameter(SurfaceTension, "surfaceTension");
118 DefineOptionalParameter(PrintPressureTensor, "printPressureTensor");
119 DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod");
120 DefineOptionalParameter(CutoffPolicy, "cutoffPolicy");
121 DefineOptionalParameter(StatFileFormat, "statFileFormat");
122
123 DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard");
124 DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true);
125 DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false);
126 DefineOptionalParameterWithDefaultValue(UseIntialExtendedSystemState, "useInitialExtendedSystemState", false);
127 DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, "orthoBoxTolerance", 1E-6);
128 DefineOptionalParameterWithDefaultValue(UseSolidThermInt, "useSolidThermInt", false);
129 DefineOptionalParameterWithDefaultValue(UseLiquidThermInt, "useLiquidThermInt", false);
130 DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5);
131 DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0);
132 DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0);
133
134 }
135
136 int Globals::globalAssign( event* the_event ){
137
138 int key;
139 int token;
140 interface_assign_type the_type = the_event->evt.asmt.asmt_type;
141 char* lhs = the_event->evt.asmt.lhs;
142 std::string keyword(lhs);
143
144 bool result;
145
146
147 ParamMap::iterator i =parameters_.find(keyword);
148 if (i != parameters_.end()) {
149 if( the_type == STRING ){
150 result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval));
151 if (!result ) {
152 sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a string.\n", keyword.c_str() );
153 }
154 } else if( the_type == DOUBLE ){
155 result = i->second->setData(the_event->evt.asmt.rhs.dval);
156 if (!result )
157 sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a double.\n", keyword.c_str() );
158 }
159 else if (the_type == INT ){
160 result = i->second->setData(the_event->evt.asmt.rhs.ival);
161 if (!result )
162 sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be an int.\n", keyword.c_str() );
163
164 } else {
165
166 }
167 }
168
169 if (keyword == "nComponents" && getNComponents() > 0) {
170 components = new Component*[getNComponents()];
171 }else if (keyword == "nZconstraints" && getNZconstraints() > 0) {
172 zConstraints = new ZconStamp*[getNZconstraints()];
173 }
174
175 return result;
176 }
177
178 int Globals::newComponent( event* the_event ){
179
180 current_component = new Component;
181 int index = the_event->evt.blk_index;
182 char err[200];
183
184 if( haveNComponents() && index < getNComponents() )
185 components[index] = current_component;
186 else{
187 if( haveNComponents() ){
188 sprintf( err, "meta-data parsing error: %d out of nComponents range",
189 index );
190 the_event->err_msg = strdup( err );
191 return 0;
192 }
193 else{
194 the_event->err_msg = strdup("meta-data parsing error: nComponents not given before"
195 " first component declaration." );
196 return 0;
197 }
198 }
199
200 return 1;
201 }
202
203
204
205 int Globals::componentAssign( event* the_event ){
206
207 switch( the_event->evt.asmt.asmt_type ){
208
209 case STRING:
210 return current_component->assignString( the_event->evt.asmt.lhs,
211 the_event->evt.asmt.rhs.sval,
212 &(the_event->err_msg));
213 break;
214
215 case DOUBLE:
216 return current_component->assignDouble( the_event->evt.asmt.lhs,
217 the_event->evt.asmt.rhs.dval,
218 &(the_event->err_msg));
219 break;
220
221 case INT:
222 return current_component->assignInt( the_event->evt.asmt.lhs,
223 the_event->evt.asmt.rhs.ival,
224 &(the_event->err_msg));
225 break;
226
227 default:
228 the_event->err_msg = strdup( "Globals error. Invalid component"
229 " assignment type" );
230 return 0;
231 break;
232 }
233 return 0;
234 }
235
236 int Globals::componentEnd( event* the_event ){
237
238 the_event->err_msg = current_component->checkMe();
239 if( the_event->err_msg != NULL ) return 0;
240
241 return 1;
242 }
243
244 int Globals::newZconstraint( event* the_event ){
245
246
247 int index = the_event->evt.blk_index;
248 char err[200];
249 current_zConstraint = new ZconStamp( index );
250
251 if( haveNZconstraints() && index < getNZconstraints() )
252 zConstraints[index] = current_zConstraint;
253 else{
254 if( haveNZconstraints() ){
255 sprintf( err, "meta-data parsing error: %d out of nZconstraints range",
256 index );
257 the_event->err_msg = strdup( err );
258 return 0;
259 }
260 else{
261 the_event->err_msg = strdup("meta-data parsing error: nZconstraints"
262 " not given before"
263 " first zConstraint declaration." );
264 return 0;
265 }
266 }
267
268 return 1;
269 }
270
271
272
273 int Globals::zConstraintAssign( event* the_event ){
274
275 switch( the_event->evt.asmt.asmt_type ){
276
277 case STRING:
278 return current_zConstraint->assignString( the_event->evt.asmt.lhs,
279 the_event->evt.asmt.rhs.sval,
280 &(the_event->err_msg));
281 break;
282
283 case DOUBLE:
284 return current_zConstraint->assignDouble( the_event->evt.asmt.lhs,
285 the_event->evt.asmt.rhs.dval,
286 &(the_event->err_msg));
287 break;
288
289 case INT:
290 return current_zConstraint->assignInt( the_event->evt.asmt.lhs,
291 the_event->evt.asmt.rhs.ival,
292 &(the_event->err_msg));
293 break;
294
295 default:
296 the_event->err_msg = strdup( "Globals error. Invalid zConstraint"
297 " assignment type" );
298 return 0;
299 break;
300 }
301 return 0;
302 }
303
304 int Globals::zConstraintEnd( event* the_event ){
305
306 the_event->err_msg = current_zConstraint->checkMe();
307 if( the_event->err_msg != NULL ) return 0;
308
309 return 1;
310 }
311
312 char* Globals::checkMe( void ){
313
314
315 std::string err("The following required keywords are missing:\n");
316 short int have_err = 0;
317
318 ParamMap::iterator i;
319 for (i = parameters_.begin(); i != parameters_.end(); ++i) {
320 if (!i->second->isOptional() && i->second->empty()) {
321 err += i->second->getKeyword() + "\n";
322 }
323 }
324
325 //@todo memory leak
326 if( have_err )
327 return strdup( err.c_str() );
328
329 return NULL;
330
331
332 }
333
334 int Globals::globalEnd( event* the_event ){
335
336 the_event->err_msg = checkMe();
337 if( the_event->err_msg != NULL ) return 0;
338
339 return 1;
340 }