ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/Globals.hpp
Revision: 2376
Committed: Mon Oct 17 19:22:31 2005 UTC (18 years, 8 months ago) by tim
File size: 10108 byte(s)
Log Message:
fix some namespace issues in Globals

File Contents

# User Rev Content
1 gezelter 2204 /*
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     #ifndef IO_GLOBALS_HPP
43     #define IO_GLOBALS_HPP
44 gezelter 1490
45     #include <iostream>
46    
47     #include <stdlib.h>
48     #include <vector>
49 tim 2109 #include <string>
50     #include <map>
51 gezelter 1490
52 tim 1492 #include "io/BASS_interface.h"
53     #include "types/Component.hpp"
54     #include "types/MakeStamps.hpp"
55     #include "types/ZconStamp.hpp"
56 tim 2364 #include "utils/CaseConversion.hpp"
57 gezelter 1490
58 tim 2364 template<typename T>
59     struct ParameterTraits;
60 gezelter 1490
61 tim 2364 //string
62     template<>
63     struct ParameterTraits<std::string>{
64     typedef std::string RepType; // Representation type of the value
65 gezelter 1930
66 tim 2364 template<typename T> static bool convert(T v, RepType& r){return false;} // !NB everything is ok
67     template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;}
68     static bool convert(RepType v, RepType& r) { r = v; return true;}
69 tim 2373 static std::string getParamType() { return "string";}
70 tim 2364 };
71     //bool
72     template<>
73     struct ParameterTraits<bool>{
74     typedef bool RepType;
75     template<typename T> static bool convert(T, RepType&){return false;}
76     template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;}
77     static bool convert(std::string v, RepType& r) {
78     oopse::toLower(v);
79     bool result = false;
80     if (v == "true") {
81     r = true;
82     result = true;
83     } else if (v == "false") {
84     r = false;
85     result = true;
86     }
87    
88     return result;
89     }
90 tim 2373 static std::string getParamType() { return "bool";}
91 tim 2364 };
92 gezelter 1490
93 tim 2364 //int
94     template<>
95     struct ParameterTraits<int>{
96     typedef int RepType;
97     template<typename T> static bool convert(T, RepType&){return false;}
98     template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;}
99     static bool convert(RepType v, RepType& r) { r=v; return true;}
100 tim 2373 static std::string getParamType() { return "int";}
101 tim 2364 };
102 gezelter 1490
103 tim 2364 //double
104     template<>
105     struct ParameterTraits<double>{
106     typedef double RepType;
107     template<typename T> static bool convert(T, RepType&){return false;}
108     template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;}
109     static bool convert(RepType v, RepType& r) {r=v; return true;}
110     static bool convert(int v, RepType& r) {r = static_cast<double>(v); return true;}
111 tim 2373 static std::string getParamType() { return "double";}
112 tim 2364 };
113 gezelter 2285
114 tim 2109
115 tim 2364 class ParameterBase {
116     public:
117     ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {}
118 tim 2376 virtual ~ParameterBase() {}
119 tim 2364 bool isOptional() {return optional_;}
120     void setOptional(bool optional) {optional_ = optional;}
121     bool hasDefaultValue() {return defaultValue_;}
122     virtual bool isValid() { return true;}
123     const std::string& getKeyword() {return keyword_;}
124     void setKeyword(const std::string& keyword) { keyword_ = keyword;}
125     bool empty() {return empty_;}
126     virtual bool setData(std::string) = 0;
127     virtual bool setData(int) = 0;
128     virtual bool setData(double) = 0;
129 tim 2373 virtual std::string getParamType() = 0;
130 tim 2364 protected:
131     std::string keyword_;
132     bool optional_;
133     bool defaultValue_;
134     bool empty_;
135     };
136 tim 2109
137 tim 2364 template<class ParamType>
138     class Parameter : public ParameterBase{
139     public:
140     typedef ParameterTraits<ParamType> ValueType;
141     void setDefaultValue(const ParamType& value) {data_ = value; defaultValue_ = true;}
142     ParamType getData() { return data_;}
143 gezelter 1490
144 tim 2364 virtual bool setData(std::string sval) {
145     return internalSetData<std::string>(sval);
146     }
147 tim 2372 virtual bool setData(int ival) {
148     return internalSetData<int>(ival);
149 tim 2364 }
150    
151     virtual bool setData(double dval) {
152     return internalSetData<double>(dval);
153     }
154 gezelter 1490
155 tim 2373 virtual std::string getParamType() { return ParameterTraits<ParamType>::getParamType();}
156 tim 2364 private:
157     template<class T> bool internalSetData(T data) {
158     ParamType tmp;
159     bool result = ValueType::convert(data, tmp);
160     if (result) {
161     empty_ = false;
162     data_ = tmp;
163     }
164     return result;
165     }
166    
167     private:
168     ParamType data_;
169    
170     };
171    
172     #define DeclareParameter(NAME, TYPE) \
173     private: \
174     Parameter<TYPE> NAME; \
175     public: \
176     bool have##NAME() { return !NAME.empty();} \
177     TYPE get##NAME() { return NAME.getData();}
178    
179    
180     class Globals {
181     public:
182     Globals();
183    
184     DeclareParameter(ForceField, std::string);
185     DeclareParameter(NComponents, int);
186     DeclareParameter(TargetTemp, double);
187     DeclareParameter(Ensemble, std::string);
188     DeclareParameter(Dt, double);
189     DeclareParameter(RunTime, double);
190     DeclareParameter(InitialConfig, std::string);
191     DeclareParameter(FinalConfig, std::string);
192     DeclareParameter(NMol, int);
193     DeclareParameter(Density, double);
194     DeclareParameter(Box, double);
195     DeclareParameter(BoxX, double);
196     DeclareParameter(BoxY, double);
197     DeclareParameter(BoxZ, double);
198     DeclareParameter(SampleTime, double);
199     DeclareParameter(ResetTime, double);
200     DeclareParameter(StatusTime, double);
201     DeclareParameter(CutoffRadius, double);
202     DeclareParameter(SwitchingRadius, double);
203     DeclareParameter(Dielectric, double);
204     DeclareParameter(TempSet, bool);
205     DeclareParameter(ThermalTime, double);
206     DeclareParameter(MixingRule, std::string);
207     DeclareParameter(UsePeriodicBoundaryConditions, bool);
208     DeclareParameter(TargetPressure, double);
209     DeclareParameter(TauThermostat, double);
210     DeclareParameter(TauBarostat, double);
211     DeclareParameter(ZconsTime, double);
212     DeclareParameter(NZconstraints, int);
213     DeclareParameter(ZconsTol, double);
214     DeclareParameter(ZconsForcePolicy, std::string);
215     DeclareParameter(Seed, int);
216     DeclareParameter(UseInitalTime, bool);
217     DeclareParameter(UseIntialExtendedSystemState, bool);
218     DeclareParameter(OrthoBoxTolerance, double);
219     DeclareParameter(Minimizer, std::string);
220     DeclareParameter(MinimizerMaxIter, double);
221     DeclareParameter(MinimizerWriteFrq, int);
222     DeclareParameter(MinimizerStepSize, double);
223     DeclareParameter(MinimizerFTol, double);
224     DeclareParameter(MinimizerGTol, double);
225     DeclareParameter(MinimizerLSTol, double);
226     DeclareParameter(MinimizerLSMaxIter, int);
227     DeclareParameter(ZconsGap, double);
228     DeclareParameter(ZconsFixtime, double);
229     DeclareParameter(ZconsUsingSMD, bool);
230     DeclareParameter(UseSolidThermInt, bool);
231     DeclareParameter(UseLiquidThermInt, bool);
232     DeclareParameter(ThermodynamicIntegrationLambda, double);
233     DeclareParameter(ThermodynamicIntegrationK, double);
234     DeclareParameter(ForceFieldVariant, std::string);
235     DeclareParameter(ForceFieldFileName, std::string);
236     DeclareParameter(ThermIntDistSpringConst, double);
237     DeclareParameter(ThermIntThetaSpringConst, double);
238     DeclareParameter(ThermIntOmegaSpringConst, double);
239     DeclareParameter(SurfaceTension, double);
240     DeclareParameter(PrintPressureTensor, bool);
241     DeclareParameter(ElectrostaticSummationMethod, std::string);
242     DeclareParameter(DampingAlpha, double);
243     DeclareParameter(CutoffPolicy, std::string);
244     DeclareParameter(CompressDumpFile, bool);
245     DeclareParameter(SkinThickness, double);
246     DeclareParameter(StatFileFormat, std::string);
247    
248     private:
249     typedef std::map<std::string, ParameterBase*> ParamMap;
250     ParamMap parameters_;
251    
252     Component* current_component;
253     Component** components; // the array of components
254    
255     ZconStamp* current_zConstraint;
256     ZconStamp** zConstraints; // the array of zConstraints
257    
258     char* checkMe();
259    
260     public:
261     int newComponent( event* the_event );
262     int componentAssign( event* the_event );
263     int componentEnd( event* the_event );
264    
265     int newZconstraint( event* the_event );
266     int zConstraintAssign( event* the_event );
267     int zConstraintEnd( event* the_event );
268 gezelter 1490
269 tim 2364 int globalAssign( event* the_event );
270     int globalEnd( event* the_event );
271    
272     ZconStamp** getZconStamp() {return zConstraints;}
273     Component** getComponents() {return components;}
274 gezelter 1490 };
275 tim 2364 #endif
276 gezelter 1490