ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/utils/ParameterManager.hpp
(Generate patch)

Comparing:
trunk/src/utils/ParameterManager.hpp (file contents), Revision 1313 by gezelter, Wed Oct 22 20:01:49 2008 UTC vs.
branches/development/src/utils/ParameterManager.hpp (file contents), Revision 1700 by gezelter, Mon Mar 26 15:27:16 2012 UTC

# Line 6 | Line 6
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
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 38 | Line 29
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31   *
32 < *
32 > * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 > * research, please cite the appropriate papers when you publish your
34 > * work.  Good starting points are:
35 > *                                                                      
36 > * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 > * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 > * [4] Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 > * [4] , Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). *
41   *  ParameterManager.hpp
43 *  OOPSE-2.0
42   *
43   *  Created by Charles F. Vardeman II on 11/16/05.
44   *  @author  Charles F. Vardeman II
45 < *  @version $Id: ParameterManager.hpp,v 1.5 2008-10-22 20:01:49 gezelter Exp $
45 > *  @version $Id$
46   *
47   */
48  
# Line 52 | Line 50
50   #define UTILS_PARAMETERMANAGER_HPP
51  
52   #include <iostream>
53 + #include <cstdio>
54  
55   #include <stdlib.h>
56   #include <vector>
# Line 85 | Line 84 | struct ParameterTraits<bool>{
84    template<typename T> static bool    convert(T, RepType&){return false;}
85    template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}
86    static bool convert(std::string v, RepType& r) {
87 <    oopse::toLower(v);
87 >    OpenMD::toLower(v);
88      bool result = false;
89      if (v == "true") {
90        r = true;
# Line 141 | Line 140 | struct ParameterTraits<std::pair<int, int> >{
140    template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}
141    static bool convert(RepType v, RepType& r)            {r=v; return true;}
142    static bool convert(std::string v, RepType& r) {
143 <    oopse::StringTokenizer tokenizer(v," ;,\t\n\r");
143 >    OpenMD::StringTokenizer tokenizer(v," ;,\t\n\r");
144      if (tokenizer.countTokens() == 2) {
145        int atom1 = tokenizer.nextTokenAsInt();
146        int atom2 = tokenizer.nextTokenAsInt();
# Line 151 | Line 150 | struct ParameterTraits<std::pair<int, int> >{
150        sprintf(painCave.errMsg,
151                "ParameterManager Error: "
152                "Not enough tokens to make pair!\n");
153 <      painCave.severity = OOPSE_ERROR;
153 >      painCave.severity = OPENMD_ERROR;
154        painCave.isFatal = 1;
155        simError();    
156      }
# Line 160 | Line 159 | struct ParameterTraits<std::pair<int, int> >{
159    static std::string getParamType() { return "std::pair<int, int>";}    
160   };
161  
162 + //OpenMD's internal Vector3d
163 + template<>                    
164 + struct ParameterTraits<OpenMD::Vector3d >{
165 +  typedef OpenMD::Vector3d  RepType;
166 +  template<typename T> static bool    convert(T, RepType&){return false;}
167 +  template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}
168 +  static bool convert(RepType v, RepType& r)            {r=v; return true;}
169 +  static bool convert(std::string v, RepType& r) {
170 +    OpenMD::StringTokenizer tokenizer(v," ();,\t\n\r");
171 +    if (tokenizer.countTokens() == 3) {
172 +      RealType v1 = tokenizer.nextTokenAsDouble();
173 +      RealType v2 = tokenizer.nextTokenAsDouble();
174 +      RealType v3 = tokenizer.nextTokenAsDouble();
175 +      r = OpenMD::Vector3d(v1, v2, v3);
176 +      return true;
177 +    } else {
178 +      sprintf(painCave.errMsg,
179 +              "ParameterManager Error: "
180 +              "Incorrect number of tokens to make a Vector3!\n");
181 +      painCave.severity = OPENMD_ERROR;
182 +      painCave.isFatal = 1;
183 +      simError();    
184 +    }
185 +    return false;
186 +  }
187 +  static std::string getParamType() { return "OpenMD::Vector3d";}    
188 + };
189  
190 +
191   class ParameterBase {
192   public:    
193    ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {}
# Line 177 | Line 204 | class ParameterBase { (public)
204    virtual bool setData(unsigned long int) = 0;
205    virtual bool setData(RealType) = 0;
206    virtual bool setData(std::pair<int, int>) = 0;
207 +  virtual bool setData(OpenMD::Vector3d) = 0;
208    virtual std::string getParamType() = 0;
209   protected:
210    std::string keyword_;
# Line 211 | Line 239 | class Parameter : public ParameterBase{ (public)
239    virtual bool setData(std::pair<int, int> pval) {
240      return internalSetData<std::pair<int, int> >(pval);
241    }
242 +  virtual bool setData(OpenMD::Vector3d pval) {
243 +    return internalSetData<OpenMD::Vector3d >(pval);
244 +  }
245    
246    virtual std::string getParamType() { return ParameterTraits<ParamType>::getParamType();}
247   private:
# Line 236 | Line 267 | TYPE get##NAME() { return NAME.getData();}
267   bool have##NAME() { return !NAME.empty();}  \
268   TYPE get##NAME() { return NAME.getData();}
269  
270 + #define DeclareAlterableParameter(NAME, TYPE)         \
271 + private:                                                   \
272 + Parameter<TYPE> NAME;                                     \
273 + public:                                                      \
274 + bool have##NAME() { return !NAME.empty();}  \
275 + TYPE get##NAME() { return NAME.getData();}  \
276 + bool set##NAME(TYPE s) { return NAME.setData(s);}  \
277  
278  
279 +
280   #define DefineParameter(NAME,KEYWORD)                              \
281   NAME.setKeyword(KEYWORD);                  \
282   parameters_.insert(std::map<std::string, ParameterBase*>::value_type(std::string(KEYWORD), static_cast<ParameterBase*>(&NAME)));
# Line 251 | Line 290 | parameters_.insert(std::map<std::string, ParameterBase
290   parameters_.insert(std::map<std::string, ParameterBase*>::value_type(std::string(KEYWORD), static_cast<ParameterBase*>(&NAME)));
291  
292   #define CheckParameter(NAME, CONSTRAINT)                              \
293 < if (!NAME.empty()) { if (!(CONSTRAINT)(NAME.getData())) { sprintf(painCave.errMsg,"Error in checking %s : should be %s\n",NAME.getKeyword().c_str(),(CONSTRAINT).getConstraintDescription().c_str()); painCave.isFatal = 1; painCave.severity = OOPSE_ERROR; simError();} }                
293 > if (!NAME.empty()) { if (!(CONSTRAINT)(NAME.getData())) { sprintf(painCave.errMsg,"Error in checking %s : should be %s\n",NAME.getKeyword().c_str(),(CONSTRAINT).getConstraintDescription().c_str()); painCave.isFatal = 1; painCave.severity = OPENMD_ERROR; simError();} }                
294  
295  
296  

Comparing:
trunk/src/utils/ParameterManager.hpp (property svn:keywords), Revision 1313 by gezelter, Wed Oct 22 20:01:49 2008 UTC vs.
branches/development/src/utils/ParameterManager.hpp (property svn:keywords), Revision 1700 by gezelter, Mon Mar 26 15:27:16 2012 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines