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

Comparing trunk/src/io/Globals.hpp (file contents):
Revision 726 by chrisfen, Fri Nov 11 15:22:11 2005 UTC vs.
Revision 906 by tim, Fri Mar 17 23:20:35 2006 UTC

# Line 49 | Line 49
49   #include <string>
50   #include <map>
51  
52 #include "io/BASS_interface.h"
52   #include "types/Component.hpp"
53 < #include "types/MakeStamps.hpp"
54 < #include "types/ZconStamp.hpp"
55 < #include "utils/CaseConversion.hpp"
53 > #include "types/ZconsStamp.hpp"
54 > #include "types/MoleculeStamp.hpp"
55 > #include "utils/ParameterManager.hpp"
56  
57 < template<typename T>
58 < struct ParameterTraits;
60 <
61 < //string
62 < template<>                    
63 < struct ParameterTraits<std::string>{
64 <  typedef std::string RepType;       // Representation type of the value
65 <
66 < 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 <  static std::string getParamType() { return "string";}  
70 < };
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 <  static std::string getParamType() { return "bool";}  
91 < };
92 <
93 < //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 <    static std::string getParamType() { return "int";}  
101 < };
102 <
103 < //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 <    static std::string getParamType() { return "double";}    
112 < };
113 <
114 <
115 < class ParameterBase {
116 <  public:    
117 <    ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {}
118 <    virtual ~ParameterBase() {}
119 <    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 <    virtual std::string getParamType() = 0;
130 <  protected:
131 <    std::string keyword_;
132 <    bool optional_;
133 <    bool defaultValue_;
134 <    bool empty_;
135 < };
136 <
137 < 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 <
144 <    virtual bool setData(std::string sval) {
145 <        return internalSetData<std::string>(sval);
146 <    }
147 <    virtual bool setData(int ival) {
148 <        return internalSetData<int>(ival);
149 <    }
150 <    
151 <    virtual bool setData(double dval) {
152 <        return internalSetData<double>(dval);
153 <    }
154 <
155 <    virtual std::string getParamType() { return ParameterTraits<ParamType>::getParamType();}
156 <   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 {
57 > namespace oopse {
58 > class Globals : public DataHolder {
59    public:
60      Globals();
61 +    virtual ~Globals();
62      
63    DeclareParameter(ForceField, std::string);
185  DeclareParameter(NComponents, int);  
64    DeclareParameter(TargetTemp, double);
65    DeclareParameter(Ensemble, std::string);
66    DeclareParameter(Dt, double);
67    DeclareParameter(RunTime, double);
68    DeclareParameter(InitialConfig, std::string);
69    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);
70    DeclareParameter(SampleTime, double);
71    DeclareParameter(ResetTime, double);
72    DeclareParameter(StatusTime, double);
# Line 203 | Line 75 | class Globals {
75    DeclareParameter(Dielectric, double);
76    DeclareParameter(TempSet, bool);
77    DeclareParameter(ThermalTime, double);
206  DeclareParameter(MixingRule, std::string);
78    DeclareParameter(UsePeriodicBoundaryConditions, bool);
79    DeclareParameter(TargetPressure, double);
80    DeclareParameter(TauThermostat, double);
81    DeclareParameter(TauBarostat, double);
82    DeclareParameter(ZconsTime, double);
212  DeclareParameter(NZconstraints, int);
83    DeclareParameter(ZconsTol, double);
84    DeclareParameter(ZconsForcePolicy, std::string);
85    DeclareParameter(Seed, int);
# Line 247 | Line 117 | class Globals {
117    DeclareParameter(OutputForceVector, bool);
118    DeclareParameter(SkinThickness, double);
119    DeclareParameter(StatFileFormat, std::string);    
120 +  DeclareParameter(HydroPropFile, std::string);
121 +  DeclareParameter(Viscosity, double);
122 +  DeclareParameter(BeadSize, double);  
123 +  
124 +  public:
125 +    bool addComponent(Component* comp);
126 +    bool addZConsStamp(ZConsStamp* zcons);
127 +    bool addMoleculeStamp(MoleculeStamp* molStamp);
128 +    int getNComponents() {return components_.size();}
129 +    std::vector<Component*> getComponents() {return components_;}
130 +    Component* getComponentAt(int index) {return components_.at(index);}    
131  
132 +    int getNZconsStamps() {return zconstraints_.size();}
133 +    std::vector<ZConsStamp*> getZconsStamps() {return zconstraints_;}
134 +    ZConsStamp* getZconsStampAt(int index) {return zconstraints_.at(index);}    
135 +
136 +    virtual void validate();
137    private:
138 <    typedef std::map<std::string, ParameterBase*> ParamMap;
139 <    ParamMap parameters_;
138 >
139 >    void parseHydroPropFile(const std::string& filename);
140      
141 <    Component* current_component;
142 <    Component** components; // the array of components
141 >    std::vector<Component*> components_;
142 >    std::vector<ZConsStamp*> zconstraints_;    
143 >    std::map<std::string, MoleculeStamp*> moleculeStamps_;
144  
258    ZconStamp* current_zConstraint;
259    ZconStamp** zConstraints; // the array of zConstraints
260
261    char* checkMe();
262
263  public:
264    int newComponent( event* the_event );
265    int componentAssign( event* the_event );
266    int componentEnd( event* the_event );
267
268    int newZconstraint( event* the_event );
269    int zConstraintAssign( event* the_event );
270    int zConstraintEnd( event* the_event );
271  
272    int globalAssign( event* the_event );
273    int globalEnd( event* the_event );    
274
275    ZconStamp** getZconStamp() {return zConstraints;}
276    Component** getComponents() {return components;}
145   };
146 + }
147   #endif
148  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines