ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/Globals.hpp
Revision: 2364
Committed: Thu Oct 13 22:26:47 2005 UTC (18 years, 9 months ago) by tim
File size: 9709 byte(s)
Log Message:
rewrite 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     };
70     //bool
71     template<>
72     struct ParameterTraits<bool>{
73     typedef bool RepType;
74     template<typename T> static bool convert(T, RepType&){return false;}
75     template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;}
76     static bool convert(std::string v, RepType& r) {
77     oopse::toLower(v);
78     bool result = false;
79     if (v == "true") {
80     r = true;
81     result = true;
82     } else if (v == "false") {
83     r = false;
84     result = true;
85     }
86    
87     return result;
88     }
89     };
90 gezelter 1490
91 tim 2364 //int
92     template<>
93     struct ParameterTraits<int>{
94     typedef int RepType;
95     template<typename T> static bool convert(T, RepType&){return false;}
96     template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;}
97     static bool convert(RepType v, RepType& r) { r=v; return true;}
98     };
99 gezelter 1490
100 tim 2364 //double
101     template<>
102     struct ParameterTraits<double>{
103     typedef double RepType;
104     template<typename T> static bool convert(T, RepType&){return false;}
105     template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;}
106     static bool convert(RepType v, RepType& r) {r=v; return true;}
107     static bool convert(int v, RepType& r) {r = static_cast<double>(v); return true;}
108     };
109 gezelter 2285
110 tim 2109
111 tim 2364 class ParameterBase {
112     public:
113     ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {}
114     bool isOptional() {return optional_;}
115     void setOptional(bool optional) {optional_ = optional;}
116     bool hasDefaultValue() {return defaultValue_;}
117     virtual bool isValid() { return true;}
118     const std::string& getKeyword() {return keyword_;}
119     void setKeyword(const std::string& keyword) { keyword_ = keyword;}
120     bool empty() {return empty_;}
121     virtual bool setData(std::string) = 0;
122     virtual bool setData(int) = 0;
123     virtual bool setData(double) = 0;
124    
125     protected:
126     std::string keyword_;
127     bool optional_;
128     bool defaultValue_;
129     bool empty_;
130     };
131 tim 2109
132 tim 2364 template<class ParamType>
133     class Parameter : public ParameterBase{
134     public:
135     typedef ParameterTraits<ParamType> ValueType;
136     void setDefaultValue(const ParamType& value) {data_ = value; defaultValue_ = true;}
137     ParamType getData() { return data_;}
138 gezelter 1490
139 tim 2364 virtual bool setData(std::string sval) {
140     return internalSetData<std::string>(sval);
141     }
142     virtual bool setData(int ial) {
143     return internalSetData<int>(ial);
144     }
145    
146     virtual bool setData(double dval) {
147     return internalSetData<double>(dval);
148     }
149 gezelter 1490
150 tim 2364 private:
151     template<class T> bool internalSetData(T data) {
152     ParamType tmp;
153     bool result = ValueType::convert(data, tmp);
154     if (result) {
155     empty_ = false;
156     data_ = tmp;
157     }
158     return result;
159     }
160    
161     private:
162     ParamType data_;
163    
164     };
165    
166     #define DeclareParameter(NAME, TYPE) \
167     private: \
168     Parameter<TYPE> NAME; \
169     public: \
170     bool have##NAME() { return !NAME.empty();} \
171     TYPE get##NAME() { return NAME.getData();}
172    
173    
174     class Globals {
175     public:
176     Globals();
177    
178     DeclareParameter(ForceField, std::string);
179     DeclareParameter(NComponents, int);
180     DeclareParameter(TargetTemp, double);
181     DeclareParameter(Ensemble, std::string);
182     DeclareParameter(Dt, double);
183     DeclareParameter(RunTime, double);
184     DeclareParameter(InitialConfig, std::string);
185     DeclareParameter(FinalConfig, std::string);
186     DeclareParameter(NMol, int);
187     DeclareParameter(Density, double);
188     DeclareParameter(Box, double);
189     DeclareParameter(BoxX, double);
190     DeclareParameter(BoxY, double);
191     DeclareParameter(BoxZ, double);
192     DeclareParameter(SampleTime, double);
193     DeclareParameter(ResetTime, double);
194     DeclareParameter(StatusTime, double);
195     DeclareParameter(CutoffRadius, double);
196     DeclareParameter(SwitchingRadius, double);
197     DeclareParameter(Dielectric, double);
198     DeclareParameter(TempSet, bool);
199     DeclareParameter(ThermalTime, double);
200     DeclareParameter(MixingRule, std::string);
201     DeclareParameter(UsePeriodicBoundaryConditions, bool);
202     DeclareParameter(TargetPressure, double);
203     DeclareParameter(TauThermostat, double);
204     DeclareParameter(TauBarostat, double);
205     DeclareParameter(ZconsTime, double);
206     DeclareParameter(NZconstraints, int);
207     DeclareParameter(ZconsTol, double);
208     DeclareParameter(ZconsForcePolicy, std::string);
209     DeclareParameter(Seed, int);
210     DeclareParameter(UseInitalTime, bool);
211     DeclareParameter(UseIntialExtendedSystemState, bool);
212     DeclareParameter(OrthoBoxTolerance, double);
213     DeclareParameter(Minimizer, std::string);
214     DeclareParameter(MinimizerMaxIter, double);
215     DeclareParameter(MinimizerWriteFrq, int);
216     DeclareParameter(MinimizerStepSize, double);
217     DeclareParameter(MinimizerFTol, double);
218     DeclareParameter(MinimizerGTol, double);
219     DeclareParameter(MinimizerLSTol, double);
220     DeclareParameter(MinimizerLSMaxIter, int);
221     DeclareParameter(ZconsGap, double);
222     DeclareParameter(ZconsFixtime, double);
223     DeclareParameter(ZconsUsingSMD, bool);
224     DeclareParameter(UseSolidThermInt, bool);
225     DeclareParameter(UseLiquidThermInt, bool);
226     DeclareParameter(ThermodynamicIntegrationLambda, double);
227     DeclareParameter(ThermodynamicIntegrationK, double);
228     DeclareParameter(ForceFieldVariant, std::string);
229     DeclareParameter(ForceFieldFileName, std::string);
230     DeclareParameter(ThermIntDistSpringConst, double);
231     DeclareParameter(ThermIntThetaSpringConst, double);
232     DeclareParameter(ThermIntOmegaSpringConst, double);
233     DeclareParameter(SurfaceTension, double);
234     DeclareParameter(PrintPressureTensor, bool);
235     DeclareParameter(ElectrostaticSummationMethod, std::string);
236     DeclareParameter(DampingAlpha, double);
237     DeclareParameter(CutoffPolicy, std::string);
238     DeclareParameter(CompressDumpFile, bool);
239     DeclareParameter(SkinThickness, double);
240     DeclareParameter(StatFileFormat, std::string);
241    
242     private:
243     typedef std::map<std::string, ParameterBase*> ParamMap;
244     ParamMap parameters_;
245    
246     Component* current_component;
247     Component** components; // the array of components
248    
249     ZconStamp* current_zConstraint;
250     ZconStamp** zConstraints; // the array of zConstraints
251    
252     char* checkMe();
253    
254     public:
255     int newComponent( event* the_event );
256     int componentAssign( event* the_event );
257     int componentEnd( event* the_event );
258    
259     int newZconstraint( event* the_event );
260     int zConstraintAssign( event* the_event );
261     int zConstraintEnd( event* the_event );
262 gezelter 1490
263 tim 2364 int globalAssign( event* the_event );
264     int globalEnd( event* the_event );
265    
266     ZconStamp** getZconStamp() {return zConstraints;}
267     Component** getComponents() {return components;}
268 gezelter 1490 };
269 tim 2364 #endif
270 gezelter 1490