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 673 by tim, Mon Oct 17 00:51:16 2005 UTC vs.
Revision 895 by tim, Mon Mar 13 22:42:40 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 char* getParamType() { return "std::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 char* 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 char* 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 char* getParamType() { return "double";}    
112 < };
113 <
114 <
115 < class ParameterBase {
116 <  public:    
117 <    ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {}
118 <    bool isOptional() {return optional_;}
119 <    void setOptional(bool optional) {optional_ = optional;}
120 <    bool hasDefaultValue() {return defaultValue_;}
121 <    virtual bool isValid() { return true;}
122 <    const std::string& getKeyword() {return keyword_;}
123 <    void setKeyword(const std::string& keyword) { keyword_ = keyword;}
124 <    bool empty() {return empty_;}
125 <    virtual bool setData(std::string) = 0;
126 <    virtual bool setData(int) = 0;
127 <    virtual bool setData(double) = 0;
128 <    virtual char* getParamType() = 0;
129 <  protected:
130 <    std::string keyword_;
131 <    bool optional_;
132 <    bool defaultValue_;
133 <    bool empty_;
134 < };
135 <
136 < template<class ParamType>
137 < class Parameter : public ParameterBase{
138 <   public:    
139 <    typedef ParameterTraits<ParamType> ValueType;
140 <     void setDefaultValue(const ParamType& value) {data_ = value; defaultValue_ = true;}
141 <     ParamType getData() { return data_;}
142 <
143 <    virtual bool setData(std::string sval) {
144 <        return internalSetData<std::string>(sval);
145 <    }
146 <    virtual bool setData(int ival) {
147 <        return internalSetData<int>(ival);
148 <    }
149 <    
150 <    virtual bool setData(double dval) {
151 <        return internalSetData<double>(dval);
152 <    }
153 <
154 <    virtual char* getParamType() { return ParameterTraits<ParamType>::getParamType();}
155 <   private:
156 <     template<class T> bool internalSetData(T data) {
157 <        ParamType tmp;
158 <        bool result = ValueType::convert(data, tmp);
159 <        if (result) {
160 <            empty_ = false;
161 <            data_ = tmp;
162 <        }
163 <        return result;
164 <     }
165 <    
166 <   private:
167 <     ParamType data_;
168 <      
169 < };
170 <
171 < #define DeclareParameter(NAME, TYPE)         \
172 <    private:                                                   \
173 <      Parameter<TYPE> NAME;                                     \
174 <    public:                                                      \
175 <      bool have##NAME() { return !NAME.empty();}  \
176 <      TYPE get##NAME() { return NAME.getData();}
177 <
178 <
179 < class Globals {
57 > namespace oopse {
58 > class Globals : public DataHolder {
59    public:
60      Globals();
61 +    virtual ~Globals();
62      
63    DeclareParameter(ForceField, std::string);
184  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);
191  DeclareParameter(NMol, int);
192  DeclareParameter(Density, double);
193  DeclareParameter(Box, double);
194  DeclareParameter(BoxX, double);
195  DeclareParameter(BoxY, double);
196  DeclareParameter(BoxZ, double);
70    DeclareParameter(SampleTime, double);
71    DeclareParameter(ResetTime, double);
72    DeclareParameter(StatusTime, double);
# Line 202 | Line 75 | class Globals {
75    DeclareParameter(Dielectric, double);
76    DeclareParameter(TempSet, bool);
77    DeclareParameter(ThermalTime, double);
205  DeclareParameter(MixingRule, std::string);
78    DeclareParameter(UsePeriodicBoundaryConditions, bool);
79    DeclareParameter(TargetPressure, double);
80    DeclareParameter(TauThermostat, double);
81    DeclareParameter(TauBarostat, double);
82    DeclareParameter(ZconsTime, double);
211  DeclareParameter(NZconstraints, int);
83    DeclareParameter(ZconsTol, double);
84    DeclareParameter(ZconsForcePolicy, std::string);
85    DeclareParameter(Seed, int);
# Line 238 | Line 109 | class Globals {
109    DeclareParameter(SurfaceTension, double);
110    DeclareParameter(PrintPressureTensor, bool);
111    DeclareParameter(ElectrostaticSummationMethod, std::string);
112 +  DeclareParameter(ElectrostaticScreeningMethod, std::string);
113    DeclareParameter(DampingAlpha, double);
114    DeclareParameter(CutoffPolicy, std::string);
115 +  DeclareParameter(SwitchingFunctionType, std::string);
116    DeclareParameter(CompressDumpFile, bool);
117 +  DeclareParameter(OutputForceVector, bool);
118    DeclareParameter(SkinThickness, double);
119    DeclareParameter(StatFileFormat, std::string);    
120 +  DeclareParameter(HydroPropFile, std::string);
121 +  public:
122 +    bool addComponent(Component* comp);
123 +    bool addZConsStamp(ZConsStamp* zcons);
124 +    bool addMoleculeStamp(MoleculeStamp* molStamp);
125 +    int getNComponents() {return components_.size();}
126 +    std::vector<Component*> getComponents() {return components_;}
127 +    Component* getComponentAt(int index) {return components_.at(index);}    
128  
129 +    int getNZconsStamps() {return zconstraints_.size();}
130 +    std::vector<ZConsStamp*> getZconsStamps() {return zconstraints_;}
131 +    ZConsStamp* getZconsStampAt(int index) {return zconstraints_.at(index);}    
132 +
133 +    virtual void validate();
134    private:
135 <    typedef std::map<std::string, ParameterBase*> ParamMap;
136 <    ParamMap parameters_;
135 >
136 >    void parseHydroPropFile(const std::string& filename);
137      
138 <    Component* current_component;
139 <    Component** components; // the array of components
138 >    std::vector<Component*> components_;
139 >    std::vector<ZConsStamp*> zconstraints_;    
140 >    std::map<std::string, MoleculeStamp*> moleculeStamps_;
141  
254    ZconStamp* current_zConstraint;
255    ZconStamp** zConstraints; // the array of zConstraints
256
257    char* checkMe();
258
259  public:
260    int newComponent( event* the_event );
261    int componentAssign( event* the_event );
262    int componentEnd( event* the_event );
263
264    int newZconstraint( event* the_event );
265    int zConstraintAssign( event* the_event );
266    int zConstraintEnd( event* the_event );
267  
268    int globalAssign( event* the_event );
269    int globalEnd( event* the_event );    
270
271    ZconStamp** getZconStamp() {return zConstraints;}
272    Component** getComponents() {return components;}
142   };
143 + }
144   #endif
145  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines