| 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 | < | }; | 
| 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 | < |  | 
| 91 | < | //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 | < |  | 
| 100 | < | //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 | < |  | 
| 110 | < |  | 
| 111 | < | 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 | < |  | 
| 132 | < | 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 | < |  | 
| 139 | < | 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 | < |  | 
| 150 | < | 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 { | 
| 57 | > | namespace oopse { | 
| 58 | > | class Globals : public DataHolder { | 
| 59 |  | public: | 
| 60 |  | Globals(); | 
| 61 | + | virtual ~Globals(); | 
| 62 |  |  | 
| 63 |  | DeclareParameter(ForceField, std::string); | 
| 179 | – | 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); | 
| 186 | – | DeclareParameter(NMol, int); | 
| 187 | – | DeclareParameter(Density, double); | 
| 188 | – | DeclareParameter(Box, double); | 
| 189 | – | DeclareParameter(BoxX, double); | 
| 190 | – | DeclareParameter(BoxY, double); | 
| 191 | – | DeclareParameter(BoxZ, double); | 
| 70 |  | DeclareParameter(SampleTime, double); | 
| 71 |  | DeclareParameter(ResetTime, double); | 
| 72 |  | DeclareParameter(StatusTime, double); | 
| 81 |  | DeclareParameter(TauThermostat, double); | 
| 82 |  | DeclareParameter(TauBarostat, double); | 
| 83 |  | DeclareParameter(ZconsTime, double); | 
| 206 | – | DeclareParameter(NZconstraints, int); | 
| 84 |  | DeclareParameter(ZconsTol, double); | 
| 85 |  | DeclareParameter(ZconsForcePolicy, std::string); | 
| 86 |  | DeclareParameter(Seed, int); | 
| 110 |  | DeclareParameter(SurfaceTension, double); | 
| 111 |  | DeclareParameter(PrintPressureTensor, bool); | 
| 112 |  | DeclareParameter(ElectrostaticSummationMethod, std::string); | 
| 113 | + | DeclareParameter(ElectrostaticScreeningMethod, std::string); | 
| 114 |  | DeclareParameter(DampingAlpha, double); | 
| 115 |  | DeclareParameter(CutoffPolicy, std::string); | 
| 116 | + | DeclareParameter(SwitchingFunctionType, std::string); | 
| 117 |  | DeclareParameter(CompressDumpFile, bool); | 
| 118 | + | DeclareParameter(OutputForceVector, bool); | 
| 119 |  | DeclareParameter(SkinThickness, double); | 
| 120 |  | DeclareParameter(StatFileFormat, std::string); | 
| 121 |  |  | 
| 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 | – |  | 
| 122 |  | public: | 
| 123 | < | int newComponent( event* the_event ); | 
| 124 | < | int componentAssign( event* the_event ); | 
| 125 | < | int componentEnd( event* the_event ); | 
| 123 | > | bool addComponent(Component* comp); | 
| 124 | > | bool addZConsStamp(ZConsStamp* zcons); | 
| 125 | > | bool addMoleculeStamp(MoleculeStamp* molStamp); | 
| 126 | > | int getNComponents() {return components_.size();} | 
| 127 | > | std::vector<Component*> getComponents() {return components_;} | 
| 128 | > | Component* getComponentAt(int index) {return components_.at(index);} | 
| 129 |  |  | 
| 130 | < | int newZconstraint( event* the_event ); | 
| 131 | < | int zConstraintAssign( event* the_event ); | 
| 132 | < | int zConstraintEnd( event* the_event ); | 
| 262 | < |  | 
| 263 | < | int globalAssign( event* the_event ); | 
| 264 | < | int globalEnd( event* the_event ); | 
| 130 | > | int getNZconsStamps() {return zconstraints_.size();} | 
| 131 | > | std::vector<ZConsStamp*> getZconsStamps() {return zconstraints_;} | 
| 132 | > | ZConsStamp* getZconsStampAt(int index) {return zconstraints_.at(index);} | 
| 133 |  |  | 
| 134 | < | ZconStamp** getZconStamp() {return zConstraints;} | 
| 135 | < | Component** getComponents() {return components;} | 
| 134 | > | virtual void validate(); | 
| 135 | > | private: | 
| 136 | > | std::vector<Component*> components_; | 
| 137 | > | std::vector<ZConsStamp*> zconstraints_; | 
| 138 | > | std::map<std::string, MoleculeStamp*> moleculeStamps_; | 
| 139 | > |  | 
| 140 |  | }; | 
| 141 | + | } | 
| 142 |  | #endif | 
| 143 |  |  |