| [6efcae] | 1 | /* | 
|---|
|  | 2 | * SerializablePotential.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: 23.11.2012 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef SERIALIZABLEPOTENTIAL_HPP_ | 
|---|
|  | 9 | #define SERIALIZABLEPOTENTIAL_HPP_ | 
|---|
|  | 10 |  | 
|---|
|  | 11 | // include config.h | 
|---|
|  | 12 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 13 | #include <config.h> | 
|---|
|  | 14 | #endif | 
|---|
|  | 15 |  | 
|---|
| [72b6d7] | 16 | #include "FunctionApproximation/FunctionModel.hpp" | 
|---|
|  | 17 |  | 
|---|
| [6efcae] | 18 | #include <iosfwd> | 
|---|
|  | 19 | #include <vector> | 
|---|
|  | 20 |  | 
|---|
|  | 21 | /** SerializablePotential is a potential that can be parsed from and stored to | 
|---|
|  | 22 | * a .potentials file. | 
|---|
|  | 23 | * | 
|---|
|  | 24 | * All required functionality for printing and parsing the set of parameters | 
|---|
|  | 25 | * is set as virtual functions and have to be implemented specifically, e.g. | 
|---|
|  | 26 | * -# ParameterNames: Should be static instance as are the same over each | 
|---|
|  | 27 | *    potential type despite although there may be more than one instance. | 
|---|
|  | 28 | *    \note If the parameter name is left empty, the value is neither printed | 
|---|
|  | 29 | *    nor parsed. This may be issued to skip internal parameters (e.g. offset). | 
|---|
|  | 30 | * -# ParticleTypes: has been implemented here, as is different per instance. | 
|---|
|  | 31 | * | 
|---|
|  | 32 | * Specifically, what you need to do when inheriting is: | 
|---|
|  | 33 | * -# implement getParameters() and setParameters() | 
|---|
|  | 34 | * -# have some static const ParameterNames_t in your class and implement | 
|---|
|  | 35 | *    getParameterNames() as a getter for it (or any other way you prefer). | 
|---|
|  | 36 | *    The static instance can be easily initialized via boost::assign::list_of. | 
|---|
|  | 37 | * | 
|---|
|  | 38 | */ | 
|---|
|  | 39 | class SerializablePotential | 
|---|
|  | 40 | { | 
|---|
|  | 41 | public: | 
|---|
|  | 42 | //!> typedef for particle designation | 
|---|
| [c5e75f3] | 43 | typedef unsigned int ParticleType_t; | 
|---|
| [6efcae] | 44 | //!> typedef for a vector of particle designations | 
|---|
|  | 45 | typedef std::vector<ParticleType_t> ParticleTypes_t; | 
|---|
|  | 46 | //!> typedef for a vector of parameter names | 
|---|
|  | 47 | typedef std::vector<std::string> ParameterNames_t; | 
|---|
|  | 48 |  | 
|---|
|  | 49 | public: | 
|---|
|  | 50 | SerializablePotential(const ParticleTypes_t &_ParticleTypes) : | 
|---|
|  | 51 | ParticleTypes(_ParticleTypes) | 
|---|
|  | 52 | {} | 
|---|
| [96c7d2] | 53 | virtual ~SerializablePotential() {} | 
|---|
| [6efcae] | 54 |  | 
|---|
|  | 55 | /** Return the token name of this specific potential. | 
|---|
|  | 56 | * | 
|---|
|  | 57 | * \return token name of the potential | 
|---|
|  | 58 | */ | 
|---|
|  | 59 | virtual const std::string& getToken() const=0; | 
|---|
|  | 60 |  | 
|---|
|  | 61 | /** Return the name of this specific potential. | 
|---|
|  | 62 | * | 
|---|
|  | 63 | * This is required for storage in a Registry. The name is the token name | 
|---|
|  | 64 | * followed by "_" and the particle types to make it unique. | 
|---|
|  | 65 | * | 
|---|
|  | 66 | * \return name of the potential | 
|---|
|  | 67 | */ | 
|---|
|  | 68 | const std::string getName() const; | 
|---|
|  | 69 |  | 
|---|
|  | 70 |  | 
|---|
|  | 71 | /** Getter for the parameters of this model function. | 
|---|
|  | 72 | * | 
|---|
|  | 73 | * \return current set of parameters of the model function | 
|---|
|  | 74 | */ | 
|---|
| [72b6d7] | 75 | virtual FunctionModel::parameters_t getParameters() const=0; | 
|---|
| [6efcae] | 76 |  | 
|---|
|  | 77 | /** Getter for the number of parameters of this model function. | 
|---|
|  | 78 | * | 
|---|
|  | 79 | * \return number of parameters | 
|---|
|  | 80 | */ | 
|---|
|  | 81 | virtual size_t getParameterDimension() const=0; | 
|---|
|  | 82 |  | 
|---|
|  | 83 | /** Returns a vector of particle designations. | 
|---|
|  | 84 | * | 
|---|
|  | 85 | * These designations denote the particle types for which this potential | 
|---|
|  | 86 | * has been parametrized. | 
|---|
|  | 87 | * | 
|---|
|  | 88 | * \return vector of particle type | 
|---|
|  | 89 | */ | 
|---|
|  | 90 | const ParticleTypes_t& getParticleTypes() const | 
|---|
|  | 91 | { return ParticleTypes; } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | /** Returns a vector of parameter names. | 
|---|
|  | 94 | * | 
|---|
|  | 95 | * This is required from the specific implementation | 
|---|
|  | 96 | * | 
|---|
|  | 97 | * \return vector of strings containing parameter names | 
|---|
|  | 98 | */ | 
|---|
|  | 99 | virtual const ParameterNames_t& getParameterNames() const=0; | 
|---|
|  | 100 |  | 
|---|
|  | 101 | /** Returns the index associated to a specific parameter \a _name. | 
|---|
|  | 102 | * | 
|---|
|  | 103 | * \param _name parameter name to look up index for | 
|---|
|  | 104 | * \return index to the given \a _name or (size_t)-1 if none found | 
|---|
|  | 105 | */ | 
|---|
|  | 106 | const size_t getParameterIndex(const std::string &_name) const; | 
|---|
|  | 107 |  | 
|---|
| [3d2559] | 108 | /** Print parameters to given stream \a ost. | 
|---|
|  | 109 | * | 
|---|
|  | 110 | * These are virtual functions to allow for overriding and hence | 
|---|
|  | 111 | * changing the default behavior. | 
|---|
|  | 112 | * | 
|---|
|  | 113 | * @param ost stream to print to | 
|---|
|  | 114 | */ | 
|---|
|  | 115 | virtual void stream_to(std::ostream &ost) const; | 
|---|
|  | 116 |  | 
|---|
|  | 117 | /** Parse parameters from given stream \a ist. | 
|---|
|  | 118 | * | 
|---|
|  | 119 | * These are virtual functions to allow for overriding and hence | 
|---|
|  | 120 | * changing the default behavior. | 
|---|
|  | 121 | * | 
|---|
|  | 122 | * @param ist stream to parse from | 
|---|
|  | 123 | */ | 
|---|
|  | 124 | virtual void stream_from(std::istream &ist); | 
|---|
|  | 125 |  | 
|---|
| [6efcae] | 126 | protected: | 
|---|
|  | 127 |  | 
|---|
|  | 128 | /** Setter for the parameters of the model function. | 
|---|
|  | 129 | * | 
|---|
|  | 130 | * \param params set of parameters to set | 
|---|
|  | 131 | */ | 
|---|
| [72b6d7] | 132 | virtual void setParameters(const FunctionModel::parameters_t ¶ms)=0; | 
|---|
| [6efcae] | 133 |  | 
|---|
|  | 134 | /** Setter for a given particle type. | 
|---|
|  | 135 | * | 
|---|
|  | 136 | * \param index index of type to set | 
|---|
|  | 137 | * \param _designation type to set to | 
|---|
|  | 138 | */ | 
|---|
|  | 139 | void setParticleType(const size_t index, const ParticleType_t& _designation) | 
|---|
|  | 140 | { | 
|---|
| [5f0c60] | 141 | if (ParticleTypes.size() <= index) | 
|---|
|  | 142 | const_cast<ParticleTypes_t &>(ParticleTypes).resize(index+1); | 
|---|
| [6efcae] | 143 | const_cast<ParticleTypes_t &>(ParticleTypes)[index] = _designation; | 
|---|
|  | 144 | } | 
|---|
|  | 145 |  | 
|---|
| [713888] | 146 | protected: | 
|---|
|  | 147 | /** Default constructor for class EmpiricalPotential. | 
|---|
|  | 148 | * | 
|---|
|  | 149 | * Callable only by derived functions. | 
|---|
|  | 150 | * | 
|---|
|  | 151 | */ | 
|---|
|  | 152 | SerializablePotential(); | 
|---|
|  | 153 |  | 
|---|
| [6efcae] | 154 | private: | 
|---|
|  | 155 |  | 
|---|
|  | 156 | //!> static definition of the particle types for this potential | 
|---|
|  | 157 | const ParticleTypes_t ParticleTypes; | 
|---|
|  | 158 | }; | 
|---|
|  | 159 |  | 
|---|
|  | 160 | /** Output operations stores .potentials line containing these parameters | 
|---|
|  | 161 | * coefficients and designations. | 
|---|
|  | 162 | * | 
|---|
|  | 163 | * \param ost output stream to print to | 
|---|
|  | 164 | * \param potential potential whose coefficients to print | 
|---|
|  | 165 | * \return output stream for concatenation | 
|---|
|  | 166 | */ | 
|---|
|  | 167 | std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential); | 
|---|
|  | 168 |  | 
|---|
|  | 169 | /** Input operation parses coefficients from a given line of a .potentials | 
|---|
|  | 170 | * file. | 
|---|
|  | 171 | * | 
|---|
|  | 172 | * \param ist input stream to parse from | 
|---|
|  | 173 | * \param potential potential to set | 
|---|
|  | 174 | * \return input stream for concatenation | 
|---|
|  | 175 | */ | 
|---|
|  | 176 | std::istream& operator>>(std::istream &ist, SerializablePotential &potential); | 
|---|
|  | 177 |  | 
|---|
|  | 178 |  | 
|---|
|  | 179 | #endif /* SERIALIZABLEPOTENTIAL_HPP_ */ | 
|---|